[WIP] initial compiler backend code

This commit is contained in:
2022-08-03 18:34:42 +05:30
parent 1570cf41f4
commit dae97b7a76
14 changed files with 273 additions and 0 deletions

3
compiler/test/dune Normal file
View File

@@ -0,0 +1,3 @@
(tests
(names test_backend)
(libraries backend ounit2))

View File

@@ -0,0 +1,31 @@
open OUnit2
open Backend.Be_ast
open Backend.Be_translate
let peq case value = assert_equal value (parse case)
let test_parse_a_command _ =
peq "add" (Acommand "add");
peq "sub" (Acommand "sub");
peq "neg" (Acommand "neg");
peq "eq" (Acommand "eq");
peq "gt" (Acommand "gt");
peq "lt" (Acommand "lt");
peq "and" (Acommand "and");
peq "or" (Acommand "or");
peq "not" (Acommand "not")
;;
let test_parse_m_command _ =
peq "pop local 12" (Mcommand ("pop", "local", "12"));
peq "push argument 4" (Mcommand ("push", "argument", "4"))
;;
let suite =
"suite"
>::: [ "A Instruction" >:: test_parse_a_command
; "M Instruction" >:: test_parse_m_command
]
;;
let () = run_test_tt_main suite