lama_byterun/src/SM.ml

45 lines
1.4 KiB
OCaml
Raw Normal View History

2018-02-20 01:28:29 +03:00
open GT
2018-02-25 19:14:25 +03:00
open Language
2018-02-20 01:28:29 +03:00
(* The type for the stack machine instructions *)
@type insn =
(* binary operator *) | BINOP of string
2018-03-04 18:14:32 +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
*)
2018-02-25 19:14:25 +03:00
type config = int list * Stmt.config
2018-02-20 01:28:29 +03:00
(* 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"
2018-02-25 15:02:30 +03:00
(* Top-level evaluation
2018-02-25 21:10:09 +03:00
val run : int list -> prg -> int list
2018-02-25 15:02:30 +03:00
Takes an input stream, a program, and returns an output stream this program calculates
*)
2018-03-06 18:10:19 +03:00
let run i p = let (_, (_, _, o)) = eval ([], (Language.Expr.empty, i, [])) p in o
2018-02-25 15:02:30 +03:00
2018-02-20 01:28:29 +03:00
(* Stack machine compiler
2018-02-25 14:48:13 +03:00
val compile : Language.Stmt.t -> prg
2018-02-20 01:28:29 +03:00
Takes a program in the source language and returns an equivalent program for the
stack machine
*)
let compile _ = failwith "Not yet implemented"