Seems to work
[rops.git] / interactive.ml
blob03a23b0a3c1747d418eb0e99046e59a71066c99e
1 open Types;;
2 open Evaluator;;
3 open Environment;;
4 open Lexer;;
5 open Parser;;
6 #load "types.cmo";;
7 #load "environment.cmo";;
8 #load "evaluator.cmo";;
9 #load "lexer.cmo";;
10 #load "parser.cmo";;
12 let (|>) (p : 'a) (f : 'a -> 'b) = f p;;
14 #untrace Evaluator.eval;;
15 #load "evaluator.cmo";;
17 let state = ref { Evaluator.env = Environment.initial_env;
18 Evaluator.cont=[];
19 Evaluator.pending_results=[[]] };;
20 let go exp =
21 state := Evaluator.eval {
22 !state with Evaluator.cont = [exp];
23 Evaluator.pending_results = [[]] };
24 state;;
25 #trace Evaluator.eval;;
27 let read s = Parser.main Lexer.token (Lexing.from_string s);;
28 let rev x = go (read x);;
30 (* "(+ 1 (+ 1 (call/cc (lambda (k) (k 3))) 5) 3)" |> rev;; *)
32 (* "(+ 1 1)" |> rev;; *)
33 (* "(define x 1)" |> rev;; *)
34 (* "(define add-x (lambda (y) (+ x y)))" |> rev;; *)
35 (* "(add-x 1)" |> rev;; *)