nand2tetris/compiler/backend/lib/programflow.ml
Konarak b7dee58454
finish project eight backend compiler
- modify existing implementation to use variant types for a more
  accurate representation of the vm byte code
- switch to fold from recursion for the main translate function
- use separate modules for translating different vm commands
- move static arithmetic command translations to a map
2024-09-13 17:03:52 -04:00

13 lines
253 B
OCaml

open! Ast
open! Base
let addr a = "@" ^ a
let label name = "(" ^ name ^ ")"
let translate command name =
match command with
| Label -> [ label name ]
| Goto -> [ addr name; "0;JMP" ]
| Ifgoto -> [ "@SP"; "AM=M-1"; "D=M"; addr name; "D;JNE" ]