2018-02-20 01:28:29 +03:00
|
|
|
open GT
|
|
|
|
|
|
|
|
|
|
(* The type for the stack machine instructions *)
|
|
|
|
|
@type insn =
|
|
|
|
|
(* binary operator *) | BINOP of string
|
2018-02-21 19:49:18 +03:00
|
|
|
(* put a constant on the stack *) | CONST of int
|
2018-02-20 01:28:29 +03:00
|
|
|
(* 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 * Syntax.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"
|
|
|
|
|
|
|
|
|
|
(* Stack machine compiler
|
|
|
|
|
|
|
|
|
|
val compile : Syntax.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"
|