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
32 lines
791 B
OCaml
32 lines
791 B
OCaml
open OUnit2
|
|
open Backend.Ast
|
|
open Backend.Translate
|
|
|
|
let peq case value = assert_equal value (parse case)
|
|
|
|
let test_parse_a_command _ =
|
|
peq "add" (ArithmeticCommand Add);
|
|
peq "sub" (ArithmeticCommand Sub);
|
|
peq "neg" (ArithmeticCommand Neg);
|
|
peq "eq" (ArithmeticCommand Eq);
|
|
peq "gt" (ArithmeticCommand Gt);
|
|
peq "lt" (ArithmeticCommand Lt);
|
|
peq "and" (ArithmeticCommand And);
|
|
peq "or" (ArithmeticCommand Or);
|
|
peq "not" (ArithmeticCommand Not)
|
|
;;
|
|
|
|
let test_parse_m_command _ =
|
|
peq "pop local 12" (MemoryAccessCommand (Pop, Local, 12));
|
|
peq "push argument 4" (MemoryAccessCommand (Push, Argument, 4))
|
|
;;
|
|
|
|
let suite =
|
|
"suite"
|
|
>::: [ "A Instruction" >:: test_parse_a_command
|
|
; "M Instruction" >:: test_parse_m_command
|
|
]
|
|
;;
|
|
|
|
let () = run_test_tt_main suite
|