Added tests for flow control IMP.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 5 Jul 2019 05:35:08 +0000 (22:35 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 5 Jul 2019 05:35:08 +0000 (22:35 -0700)
tests/4001_flowcontrol_exit.pvvs [new file with mode: 0644]
tests/4002_flowcontrol_unconditional_jump_to_label.pvvs [new file with mode: 0644]
tests/4003_flowcontrol_jump_if_tos_is_zero.pvvs [new file with mode: 0644]
tests/4004_flowcontrol_jump_if_tos_is_negative.pvvs [new file with mode: 0644]
tests/4005_flowcontrol_jump_to_subroutine.pvvs [new file with mode: 0644]
tests/4006_flowcontrol_return_from_subroutine.pvvs [new file with mode: 0644]
vv_interpreter.c
vv_test.py

diff --git a/tests/4001_flowcontrol_exit.pvvs b/tests/4001_flowcontrol_exit.pvvs
new file mode 100644 (file)
index 0000000..37ab178
--- /dev/null
@@ -0,0 +1,3 @@
+# This test verifies the flow control IMP exit.
+
+NNN             | FC: Terminate program
diff --git a/tests/4002_flowcontrol_unconditional_jump_to_label.pvvs b/tests/4002_flowcontrol_unconditional_jump_to_label.pvvs
new file mode 100644 (file)
index 0000000..8e0e6d9
--- /dev/null
@@ -0,0 +1,9 @@
+# This test verifies the flow control IMP for marking labels and
+# unconditionally jumping to them..
+
+SSSTSSSSSTN     | ST: Push +65 (ASCII A)
+NSNTSTSTSN      | FC: Unconditional jump -> '42'
+NNN             | FC: Terminate program
+NSSVTSTSTSN     | FC: Mark label '42'
+TNSS            | IO: Output character
+NNN             | FC: Terminate program
diff --git a/tests/4003_flowcontrol_jump_if_tos_is_zero.pvvs b/tests/4003_flowcontrol_jump_if_tos_is_zero.pvvs
new file mode 100644 (file)
index 0000000..42002b4
--- /dev/null
@@ -0,0 +1,10 @@
+# This test verifies the flow control IMP for jumping if TOS is zero.
+
+SSSTSSSSSTN     | ST: Push +65 (ASCII A)
+SSSSN           | ST: Push +0
+NTSTSTSTSN      | FC: BRZ -> '42'
+NNN             | FC: Terminate program
+NSSVTSTSTSN     | FC: Mark label '42'
+SNN             | ST: Drop TOS
+TNSS            | IO: Output character
+NNN             | FC: Terminate program
diff --git a/tests/4004_flowcontrol_jump_if_tos_is_negative.pvvs b/tests/4004_flowcontrol_jump_if_tos_is_negative.pvvs
new file mode 100644 (file)
index 0000000..8517cd6
--- /dev/null
@@ -0,0 +1,10 @@
+# This test verifies the flow control IMP for jumping if TOS is negative.
+
+SSSTSSSSSTN     | ST: Push +65 (ASCII A)
+SSTTN           | ST: Push -1
+NTTTSTSTSN      | FC: BLZ -> '42'
+NNN             | FC: Terminate program
+NSSVTSTSTSN     | FC: Mark label '42'
+SNN             | ST: Drop TOS
+TNSS            | IO: Output character
+NNN             | FC: Terminate program
diff --git a/tests/4005_flowcontrol_jump_to_subroutine.pvvs b/tests/4005_flowcontrol_jump_to_subroutine.pvvs
new file mode 100644 (file)
index 0000000..a33af59
--- /dev/null
@@ -0,0 +1,8 @@
+# This test verifies the flow control IMP jsr.
+
+NSTTSTSTSN      | FC: JSR -> '42'
+NNN             | FC: Terminate program
+NSSVTSTSTSN     | FC: Mark label '42'
+SSSTSSSSSTN     | ST: Push +65 (ASCII A)
+TNSS            | IO: Output character
+NNN             | FC: Terminate program
diff --git a/tests/4006_flowcontrol_return_from_subroutine.pvvs b/tests/4006_flowcontrol_return_from_subroutine.pvvs
new file mode 100644 (file)
index 0000000..749ca17
--- /dev/null
@@ -0,0 +1,8 @@
+# This test verifies the flow control IMP rts.
+
+NSTTSTSTSN      | FC: JSR -> '42'
+TNSS            | IO: Output character
+NNN             | FC: Terminate program
+NSSVTSTSTSN     | FC: Mark label '42'
+SSSTSSSSSTN     | ST: Push +65 (ASCII A)
+NTN             | FC: RTS
index 8fac7c2..aa88505 100644 (file)
@@ -236,8 +236,11 @@ process_imp_flowcontrol(uint8_t * code, size_t * pc, int32_t ** sp, uint32_t * l
                         break;
                     case '\t':
                         /* Call a subroutine. */
                         break;
                     case '\t':
                         /* Call a subroutine. */
-                        *((*rsp)++) = *pc;
-                        *pc = labels[parse_label(code, pc)];
+                        {
+                            size_t temp_pc = labels[parse_label(code, pc)];
+                            *((*rsp)++) = *pc;
+                            *pc = temp_pc;
+                        }
                         break;
                     case '\n':
                         /* Jump unconditionally to a label. */
                         break;
                     case '\n':
                         /* Jump unconditionally to a label. */
@@ -254,10 +257,12 @@ process_imp_flowcontrol(uint8_t * code, size_t * pc, int32_t ** sp, uint32_t * l
                 switch (next_code_byte(code,pc)) {
                     case ' ':
                         /* Jump to a label if TOS == 0 */
                 switch (next_code_byte(code,pc)) {
                     case ' ':
                         /* Jump to a label if TOS == 0 */
+                        /* TODO: Does WS pop or peek the TOS? */
                         if (stack_peek(sp,0) == 0) *pc = labels[parse_label(code, pc)];
                         break;
                     case '\t':
                         /* Jump to a label if TOS < 0. */
                         if (stack_peek(sp,0) == 0) *pc = labels[parse_label(code, pc)];
                         break;
                     case '\t':
                         /* Jump to a label if TOS < 0. */
+                        /* TODO: Does WS pop or peek the TOS? */
                         if (stack_peek(sp,0) < 0) *pc = labels[parse_label(code, pc)];
                         break;
                     case '\n':
                         if (stack_peek(sp,0) < 0) *pc = labels[parse_label(code, pc)];
                         break;
                     case '\n':
index 33a998b..68b4db8 100755 (executable)
@@ -25,6 +25,12 @@ tests = [
         ['2004_arithmetic_division', 'A'],
         ['2005_arithmetic_remainder', 'A'],
         ['3001_heap', 'BCA'],
         ['2004_arithmetic_division', 'A'],
         ['2005_arithmetic_remainder', 'A'],
         ['3001_heap', 'BCA'],
+        ['4001_flowcontrol_exit', ''],
+        ['4002_flowcontrol_unconditional_jump_to_label', 'A'],
+        ['4003_flowcontrol_jump_if_tos_is_zero', 'A'],
+        ['4004_flowcontrol_jump_if_tos_is_negative', 'A'],
+        ['4005_flowcontrol_jump_to_subroutine', 'A'],
+        ['4006_flowcontrol_return_from_subroutine', 'A'],
         ] 
 
 for test in tests:
         ] 
 
 for test in tests: