Konarak
b7dee58454
- 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
42 lines
613 B
OCaml
42 lines
613 B
OCaml
type arithmetic_command =
|
|
| Add
|
|
| Sub
|
|
| Neg
|
|
| Eq
|
|
| Gt
|
|
| Lt
|
|
| And
|
|
| Or
|
|
| Not
|
|
|
|
type memory_segment =
|
|
| Argument
|
|
| Local
|
|
| Static
|
|
| Constant
|
|
| This
|
|
| That
|
|
| Pointer
|
|
| Temp
|
|
|
|
type memory_command =
|
|
| Push
|
|
| Pop
|
|
|
|
type branching_command =
|
|
| Label
|
|
| Goto
|
|
| Ifgoto
|
|
|
|
type function_command =
|
|
| Function
|
|
| Call
|
|
|
|
type expr =
|
|
| Comment of string
|
|
| ArithmeticCommand of arithmetic_command
|
|
| MemoryAccessCommand of memory_command * memory_segment * int
|
|
| ProgramFlowCommand of branching_command * string
|
|
| FunctionCallCommand of function_command * string * int
|
|
| Return
|