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
This commit is contained in:
3
compiler/backend/test/dune
Normal file
3
compiler/backend/test/dune
Normal file
@@ -0,0 +1,3 @@
|
||||
(tests
|
||||
(names test_backend)
|
||||
(libraries backend ounit2))
|
31
compiler/backend/test/test_backend.ml
Normal file
31
compiler/backend/test/test_backend.ml
Normal file
@@ -0,0 +1,31 @@
|
||||
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
|
Reference in New Issue
Block a user