Fixed Driver and

SM
This commit is contained in:
Dmitry Boulytchev 2018-02-25 15:02:30 +03:00
parent 1996d0e0cb
commit 9e3803ce7b
2 changed files with 12 additions and 3 deletions

View file

@ -21,7 +21,7 @@ let main =
let stack = Sys.argv.(1) = "-s" in
let infile = Sys.argv.(2) in
match parse infile with
| `Ok ((_, stmt) as prog) ->
| `Ok prog ->
let rec read acc =
try
let r = read_int () in
@ -33,7 +33,7 @@ let main =
let output =
if interpret
then Language.eval prog input
else SM.eval (SM.compile prog) input
else SM.run (SM.compile prog) input
in
List.iter (fun i -> Printf.printf "%d\n" i) output
| `Fail er -> Printf.eprintf "Syntax error: %s\n" er

View file

@ -24,6 +24,14 @@ type config = int list * Language.Stmt.config
*)
let eval _ = failwith "Not yet implemented"
(* Top-level evaluation
val run : prg -> int list -> int list
Takes an input stream, a program, and returns an output stream this program calculates
*)
let run p i = let (_, (_, _, o)) = eval ([], (Expr.empty, i, [])) p in o
(* Stack machine compiler
val compile : Language.Stmt.t -> prg
@ -31,5 +39,6 @@ let eval _ = failwith "Not yet implemented"
Takes a program in the source language and returns an equivalent program for the
stack machine
*)
let compile _ = failwith "Not yet implemented"