2024-09-13 20:37:20 +00:00
|
|
|
open! Ast
|
|
|
|
open! Base
|
|
|
|
|
|
|
|
let parse str =
|
|
|
|
let lexbuf = Lexing.from_string str in
|
|
|
|
Parser.prog Lexer.read lexbuf
|
|
|
|
|
|
|
|
let bootstrap =
|
|
|
|
[ "@256"; "D=A"; "@SP"; "M=D" ]
|
|
|
|
@ Functioncall.translate Call "Sys.init" 0
|
|
|
|
|
|
|
|
let translate class_name lines : string list =
|
|
|
|
lines
|
|
|
|
|> List.map ~f:parse
|
|
|
|
|> List.bind ~f:(function
|
2024-09-20 18:20:09 +00:00
|
|
|
| ArithmeticCommand command
|
|
|
|
-> Arithmetic.translate command
|
2024-09-13 20:37:20 +00:00
|
|
|
| MemoryAccessCommand (command, segment, offset)
|
|
|
|
-> Memoryaccess.translate command segment offset class_name
|
|
|
|
| ProgramFlowCommand (command, name)
|
|
|
|
-> Programflow.translate command name
|
|
|
|
| FunctionCallCommand (command, name, arg)
|
|
|
|
-> Functioncall.translate command name arg
|
|
|
|
| Return
|
|
|
|
-> Return.translate
|
|
|
|
)
|