--- /dev/null
+# This test verifies the flow control IMP exit.
+
+NNN | FC: Terminate program
--- /dev/null
+# 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
--- /dev/null
+# 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
--- /dev/null
+# 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
--- /dev/null
+# 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
--- /dev/null
+# 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
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. */
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. */
+ /* TODO: Does WS pop or peek the TOS? */
if (stack_peek(sp,0) < 0) *pc = labels[parse_label(code, pc)];
break;
case '\n':
['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: