mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 06:48:48 +00:00
Intermediate
This commit is contained in:
parent
f4ee6c5c5e
commit
4847ee60fb
3 changed files with 8 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ module Stmt =
|
|||
|
||||
(* Statement evaluator
|
||||
|
||||
val eval : config -> t -> config
|
||||
val eval : config -> t -> config
|
||||
|
||||
Takes a configuration and a statement, and returns another configuration
|
||||
*)
|
||||
|
|
|
|||
10
src/SM.ml
10
src/SM.ml
|
|
@ -1,5 +1,5 @@
|
|||
open GT
|
||||
open Syntax
|
||||
open Language
|
||||
|
||||
(* The type for the stack machine instructions *)
|
||||
@type insn =
|
||||
|
|
@ -39,11 +39,11 @@ let rec eval ((stack, ((st, i, o) as c)) as conf) = function
|
|||
|
||||
(* Top-level evaluation
|
||||
|
||||
val run : int list -> prg -> int list
|
||||
val run : prg -> int list -> int list
|
||||
|
||||
Takes an input stream, a program, and returns an output stream this program calculates
|
||||
*)
|
||||
let run i p = let (_, (_, _, o)) = eval ([], (Expr.empty, i, [])) p in o
|
||||
*)
|
||||
let run p i = let (_, (_, _, o)) = eval ([], (Expr.empty, i, [])) p in o
|
||||
|
||||
(* Stack machine compiler
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ let run i p = let (_, (_, _, o)) = eval ([], (Expr.empty, i, [])) p in o
|
|||
|
||||
Takes a program in the source language and returns an equivalent program for the
|
||||
stack machine
|
||||
*)
|
||||
*)
|
||||
|
||||
let rec compile =
|
||||
let rec expr = function
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue