OCaml: put macro flag in metadata rather than special type field
[jackhill/mal.git] / ps / step1_read_print.ps
index d08579c..858987c 100644 (file)
@@ -1,7 +1,11 @@
-(types.ps) run
-(reader.ps) run
+/runlibfile where { pop }{ /runlibfile { run } def } ifelse % 
+(types.ps) runlibfile
+(reader.ps) runlibfile
+(printer.ps) runlibfile
 
 % read
+/_readline { print flush (%stdin) (r) file 99 string readline } def
+
 /READ {
     /str exch def
     str read_str
 
 
 % eval
-/EVAL {
+/EVAL { 2 dict begin
     % just "return" the "ast"
     /env exch def
     /ast exch def
     ast
-} def
+end } def
 
 
 % print
 /PRINT {
-    /exp exch def
-    %(printing: ) print exp ==
-    exp pr_str
+    true _pr_str
 } def
 
 
 % repl
 /REP { READ (stub env) EVAL PRINT } def
 
-/stdin (%stdin) (r) file def 
-
-{ % loop
-    (user> ) print flush
-
-    %(%lineedit) (r) file 99 string readline
-    stdin 99 string readline
-
+% repl loop
+{ %loop
+    (user> ) _readline
     not { exit } if  % exit if EOF
 
-    %(\ngot line: ) print dup print (\n) print flush
-    REP print (\n) print
+    { %try
+        REP print (\n) print
+    } stopped {
+        (Error: ) print
+        get_error_data false _pr_str print (\n) print
+        $error /newerror false put
+        $error /errorinfo null put
+        clear
+        cleardictstack
+    } if
 } bind loop
 
 (\n) print  % final newline before exit for cleanliness