open GT open Language (* The type for the stack machine instructions *) @type insn = (* binary operator *) | BINOP of string (* put a constant on the stack *) | CONST of int (* read to stack *) | READ (* write from stack *) | WRITE (* load a variable to the stack *) | LD of string (* store a variable from the stack *) | ST of string with show (* The type for the stack machine program *) type prg = insn list (* The type for the stack machine configuration: a stack and a configuration from statement interpreter *) type config = int list * Stmt.config (* Stack machine interpreter val eval : config -> prg -> config Takes a configuration and a program, and returns a configuration as a result *) let eval _ = failwith "Not yet implemented" (* Top-level evaluation val run : int list -> prg -> int list Takes an input stream, a program, and returns an output stream this program calculates *) let run i p = let (_, (_, _, o)) = eval ([], (Language.Expr.empty, i, [])) p in o (* Stack machine compiler val compile : Language.Stmt.t -> prg Takes a program in the source language and returns an equivalent program for the stack machine *) let compile _ = failwith "Not yet implemented"