mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-22 22:58:46 +00:00
x86 for the linear language
This commit is contained in:
parent
4ff1bf9858
commit
64172f66d3
9 changed files with 57 additions and 18 deletions
|
|
@ -19,23 +19,30 @@ let parse infile =
|
|||
let main =
|
||||
try
|
||||
let interpret = Sys.argv.(1) = "-i" in
|
||||
let infile = Sys.argv.(2) in
|
||||
let stack = Sys.argv.(1) = "-s" in
|
||||
let to_compile = not (interpret || stack) in
|
||||
let infile = Sys.argv.(if not to_compile then 2 else 1) in
|
||||
match parse infile with
|
||||
| `Ok prog ->
|
||||
let rec read acc =
|
||||
try
|
||||
let r = read_int () in
|
||||
Printf.printf "> ";
|
||||
read (acc @ [r])
|
||||
with End_of_file -> acc
|
||||
in
|
||||
let input = read [] in
|
||||
let output =
|
||||
if interpret
|
||||
then Language.eval prog input
|
||||
else SM.run (SM.compile prog) input
|
||||
in
|
||||
List.iter (fun i -> Printf.printf "%d\n" i) output
|
||||
if to_compile
|
||||
then
|
||||
let basename = Filename.chop_suffix infile ".expr" in
|
||||
ignore @@ X86.build prog basename
|
||||
else
|
||||
let rec read acc =
|
||||
try
|
||||
let r = read_int () in
|
||||
Printf.printf "> ";
|
||||
read (acc @ [r])
|
||||
with End_of_file -> acc
|
||||
in
|
||||
let input = read [] in
|
||||
let output =
|
||||
if interpret
|
||||
then Language.eval 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
|
||||
with Invalid_argument _ ->
|
||||
Printf.printf "Usage: rc [-i] <input file.expr>\n"
|
||||
Printf.printf "Usage: rc [-i | -s] <input file.expr>\n"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue