27 lines
749 B
OCaml
27 lines
749 B
OCaml
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
|
|
| ArithmeticCommand command
|
|
-> Arithmetic.translate command
|
|
| 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
|
|
)
|