summaryrefslogtreecommitdiff
path: root/main.ml
diff options
context:
space:
mode:
Diffstat (limited to 'main.ml')
-rw-r--r--main.ml46
1 files changed, 26 insertions, 20 deletions
diff --git a/main.ml b/main.ml
index a90de2c..bd67cb4 100644
--- a/main.ml
+++ b/main.ml
@@ -1,5 +1,7 @@
open Ast
+module Interpret = Interpret2.I
+
(* command line options *)
let dump = ref false
let dumprn = ref false
@@ -28,40 +30,44 @@ let () =
let prog = File_parser.parse_file !ifile in
if !dump then Ast_printer.print_prog Format.std_formatter prog;
- let prog = Sca.rename_prog prog in
+ let prog = Rename.rename_prog prog in
if !dumprn then Ast_printer.print_prog Format.std_formatter prog;
if !vtest then begin
- let s0 = Interpret.program_init_state prog "test" in
+ let s0 = Interpret.init_state prog "test" in
Format.printf "Init state:@.";
- Data.print_state s0;
+ Interpret.print_state Format.std_formatter s0;
let rec it i st =
- let st, outputs, next_st =
- Interpret.program_step prog st
- ["i", Data.VInt i] "test"
+ let next_st, out =
+ Interpret.step st
+ ["i", Interpret.int_value i]
in
Format.printf "@.> Step %d:@." i;
- Data.print_state st;
- match List.assoc "exit" outputs with
- | Data.VBool false -> it (i+1) next_st
- | _ -> ()
+ Interpret.print_state Format.std_formatter st;
+ Format.printf "Outputs:@.";
+ List.iter
+ (fun (k, v) -> Format.printf "%s = %s@."
+ k (Interpret.str_repr_of_val v))
+ out;
+ if not (Interpret.as_bool (List.assoc "exit" out)) then
+ it (i+1) next_st
in
it 0 s0
end;
+
if !test then begin
- let s0 = Interpret.program_init_state prog "test" in
+ let s0 = Interpret.init_state prog "test" in
let rec it i st =
- let st, outputs, next_st =
- Interpret.program_step prog st
- ["i", Data.VInt i] "test"
+ let next_st, outputs =
+ Interpret.step st
+ ["i", Interpret.int_value i]
in
Format.printf "%d. %s %s %s@." i
- (Data.str_of_value (List.assoc "a" outputs))
- (Data.str_of_value (List.assoc "b" outputs))
- (Data.str_of_value (List.assoc "c" outputs));
- match List.assoc "exit" outputs with
- | Data.VBool false -> it (i+1) next_st
- | _ -> ()
+ (Interpret.str_repr_of_val (List.assoc "a" outputs))
+ (Interpret.str_repr_of_val (List.assoc "b" outputs))
+ (Interpret.str_repr_of_val (List.assoc "c" outputs));
+ if not (Interpret.as_bool (List.assoc "exit" outputs)) then
+ it (i+1) next_st
in
it 0 s0
end