diff options
| author | 2023-02-09 16:16:41 +0000 | |
|---|---|---|
| committer | 2023-02-09 16:16:41 +0000 | |
| commit | c0770d8ece675f5e6f2249b331c7550933915829 (patch) | |
| tree | 49ed1779f0941a60ce2941c312d3f53f4ab81616 /asm/test.py | |
| parent | test refactoring (diff) | |
add compile t est
Diffstat (limited to 'asm/test.py')
| -rw-r--r-- | asm/test.py | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/asm/test.py b/asm/test.py index b9d6520..06a878f 100644 --- a/asm/test.py +++ b/asm/test.py @@ -7,25 +7,25 @@ class PushTest(unittest.TestCase): p = Program() p.parse_asm_line("push r5") b = p() - self.assertEqual(b, b'\x01\xC2\x80\x00') + self.assertEqual(b, b'\x01\xC2\x85\x00') ins = ffi.parse_line(b) self.assertEqual(ins[0], instructions["push"].opcode) self.assertEqual(ins[1][0], (1,5)) - def test_parse_push_catch_typecheck_push_imm(self): + def test_parse_push_imm(self): p = Program() - with self.assertRaises(TypecheckException) as cm: - p.parse_asm_line("push 0") - self.assertEqual(cm.exception.argtype, ArgType.REG) - self.assertEqual(cm.exception.sarg, '0') - self.assertEqual(cm.exception.i, 0) - self.assertEqual(cm.exception.opcode, 1) + p.parse_asm_line("push 5") + b = p() + self.assertEqual(b, b'\x01\xC0\x85\x00') + ins = ffi.parse_line(b) + self.assertEqual(ins[0], instructions["push"].opcode) + self.assertEqual(ins[1][0], (0,5)) def test_parse_push_catch_typecheck_push_lab(self): p = Program() with self.assertRaises(TypecheckException) as cm: p.parse_asm_line("push l0") - self.assertEqual(cm.exception.argtype, ArgType.REG) + self.assertEqual(cm.exception.argtype, ArgType.VAL) self.assertEqual(cm.exception.sarg, 'l0') self.assertEqual(cm.exception.i, 0) self.assertEqual(cm.exception.opcode, 1) @@ -52,6 +52,32 @@ class PushTest(unittest.TestCase): b = p() self.assertEqual(b, b'\x01\xFC\x87\xbf\xbf\xbf\xbf\x00') + def test_compile_push(self): + p = Program() + p.parse_asm_line("PUSH r0") + p.parse_asm_line("PUSH r6") + b = p() + + ex = ffi.ExecutionEnvironment() + self.assertEqual(ex.load(b), ffi.CompileRet.OK) + self.assertEqual(ex.cenv.prgend, 2) + + self.assertEqual(ex.cenv.prg[0].opcode, 1) + self.assertEqual(ex.cenv.prg[0].w_flags[0], 1) + self.assertEqual(ex.cenv.prg[0].w_flags[1], 0) + self.assertEqual(ex.cenv.prg[0].w_flags[2], 0) + self.assertEqual(ex.cenv.prg[0].w[0], 0) + self.assertEqual(ex.cenv.prg[0].w[1], 0) + self.assertEqual(ex.cenv.prg[0].w[2], 0) + + self.assertEqual(ex.cenv.prg[1].opcode, 1) + self.assertEqual(ex.cenv.prg[1].w_flags[0], 1) + self.assertEqual(ex.cenv.prg[1].w_flags[1], 0) + self.assertEqual(ex.cenv.prg[1].w_flags[2], 0) + self.assertEqual(ex.cenv.prg[1].w[0], 6) + self.assertEqual(ex.cenv.prg[1].w[1], 0) + self.assertEqual(ex.cenv.prg[1].w[2], 0) + class ProgramTest(unittest.TestCase): def test_two(self): p = Program() |
