Skip to content

Commit a2f1cf7

Browse files
committed
Draft the REPL module (contains refs configuring the REPL)
1 parent 45c6b2f commit a2f1cf7

File tree

6 files changed

+85
-0
lines changed

6 files changed

+85
-0
lines changed

compiler/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ The CakeML parser.
3636

3737
[proofs](proofs):
3838
Correctness proof for the CakeML compiler.
39+
40+
[repl](repl):
41+
Some definitions and proofs used in the proof of the CakeML
42+
and Candle read-eval-print loop (REPL).

compiler/repl/Holmakefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
INCLUDES = $(CAKEMLDIR)/candle/prover $(CAKEMLDIR)/basis $(CAKEMLDIR)/translator $(CAKEMLDIR)/characteristic
2+
3+
all: $(DEFAULT_TARGETS) README.md
4+
.PHONY: all
5+
6+
README_SOURCES = $(wildcard *Script.sml) $(wildcard *Lib.sml) $(wildcard *Syntax.sml)
7+
DIRS = $(wildcard */)
8+
README.md: $(CAKEMLDIR)/developers/readme_gen readmePrefix $(patsubst %,%readmePrefix,$(DIRS)) $(README_SOURCES)
9+
$(protect $(CAKEMLDIR)/developers/readme_gen) $(README_SOURCES)

compiler/repl/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Some definitions and proofs used in the proof of the CakeML
2+
and Candle read-eval-print loop (REPL).
3+
4+
[repl_moduleProgScript.sml](repl_moduleProgScript.sml):
5+
Module for the configurable part of the REPL. Note that this file
6+
does not contain the code for the main loop of the REPL (which is at
7+
the end of bootstrap translation).

compiler/repl/readmePrefix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Some definitions and proofs used in the proof of the CakeML
2+
and Candle read-eval-print loop (REPL).
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
(*
2+
Module for the configurable part of the REPL. Note that this file
3+
does not contain the code for the main loop of the REPL (which is at
4+
the end of bootstrap translation).
5+
6+
This REPL module defines some references:
7+
- REPL.prompt : Ref string
8+
-- the string that the default input function prints before reading
9+
user input (by default this is "> ")
10+
- REPL.isEOF : Ref bool
11+
-- true means that all user input has been read (e.g. if we have
12+
reached the end of stdin)
13+
- REPL.nextString : Ref string
14+
-- contains the next user input (if isEOF is false)
15+
- REPL.readNextString : Ref (unit -> unit)
16+
-- the function that the REPL uses to read user input; it is this
17+
function that assigns new values to REPL.isEOF and REPL.nextString.
18+
19+
At runtine, users are allowed (encouraged?) to change these references.
20+
*)
21+
open preamble
22+
ml_translatorTheory ml_translatorLib ml_progLib basisFunctionsLib
23+
candle_kernelProgTheory
24+
25+
val _ = new_theory"repl_moduleProg";
26+
27+
val _ = translation_extends "candle_kernelProg";
28+
29+
val _ = ml_prog_update (open_module "REPL");
30+
31+
val res = declare_new_ref "isEOF" “F”;
32+
val res = declare_new_ref "prompt" “strlit "> "”;
33+
val res = declare_new_ref "nextString" “strlit ""”;
34+
35+
val _ = ml_prog_update open_local_block;
36+
37+
val _ = (append_prog o process_topdecs) `
38+
fun default_readNextString () =
39+
(TextIO.print (!prompt);
40+
case TextIO.inputLine TextIO.stdIn of
41+
None => (isEOF := True; nextString := "")
42+
| Some line => (isEOF := False; nextString := line)); `
43+
44+
val _ = ml_prog_update open_local_in_block;
45+
46+
val _ = (append_prog o process_topdecs) `
47+
val readNextString = Ref default_readNextString; `
48+
49+
val _ = ml_prog_update close_local_blocks;
50+
val _ = ml_prog_update (close_module NONE);
51+
52+
(* --- *)
53+
54+
val repl_prog = get_ml_prog_state () |> remove_snocs |> ml_progLib.get_prog;
55+
56+
val repl_prog_def = Define `repl_prog = ^repl_prog`;
57+
58+
Theorem Decls_repl_prog =
59+
ml_progLib.get_Decls_thm (get_ml_prog_state ())
60+
|> REWRITE_RULE [GSYM repl_prog_def];
61+
62+
val _ = export_theory();

developers/build-sequence

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ compiler/parsing/tests
114114
compiler/inference/tests
115115

116116
# compiler translation
117+
compiler/repl
117118
compiler/bootstrap/translation
118119

119120
# compiler sexpr bootstrap

0 commit comments

Comments
 (0)