Added tests for output half of IO IMP.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 5 Jul 2019 21:22:10 +0000 (14:22 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 5 Jul 2019 21:22:10 +0000 (14:22 -0700)
tests/5001_io_output_character.pvvs [new file with mode: 0644]
tests/5002_io_output_digit.pvvs [new file with mode: 0644]
vv_interpreter.c
vv_test.py

diff --git a/tests/5001_io_output_character.pvvs b/tests/5001_io_output_character.pvvs
new file mode 100644 (file)
index 0000000..1fefcd4
--- /dev/null
@@ -0,0 +1,5 @@
+# This test verifies the input/output IMP output character.
+
+SSSTSSSSSTN     | ST: Push +65 (ASCII A)
+TNSS            | IO: Output character
+NNN             | FC: Terminate program
diff --git a/tests/5002_io_output_digit.pvvs b/tests/5002_io_output_digit.pvvs
new file mode 100644 (file)
index 0000000..653a720
--- /dev/null
@@ -0,0 +1,5 @@
+# This test verifies the input/output IMP output digit.
+
+SSSTSN          | ST: Push +2
+TNST            | IO: Output digit
+NNN             | FC: Terminate program
index aa88505..be52497 100644 (file)
@@ -232,7 +232,7 @@ process_imp_flowcontrol(uint8_t * code, size_t * pc, int32_t ** sp, uint32_t * l
                         if (next_code_byte(code,pc) != '\v') ws_die(pc,"expected vtab, "
                                 "perhaps a whitespace program, rather than vvhitespace?");
                         /* Jump to next instruction since labels were parsed during startup. */
-                        parse_label( code, pc);
+                        parse_label(code, pc);
                         break;
                     case '\t':
                         /* Call a subroutine. */
@@ -311,8 +311,8 @@ process_imp_io(uint8_t * code, size_t * pc, int32_t ** sp, int32_t ** hp)
             /* Output */
             {
                 switch (next_code_byte(code,pc)) {
-                    case ' ' : /* Output character from TOS */ printf("%c", stack_pop(sp)); break;
-                    case '\t': /* Output number from TOS    */ printf("%d", stack_pop(sp)); break;
+                    case ' ' : /* Output char from TOS  */ printf("%c", stack_pop(sp));     break;
+                    case '\t': /* Output digit from TOS */ printf("%c", stack_pop(sp)+'0'); break;
                     default  : ws_die(pc, "malformed output IMP");                          break;
                 }
                 fflush(stdout);
index 68b4db8..829e891 100755 (executable)
@@ -31,6 +31,8 @@ tests = [
         ['4004_flowcontrol_jump_if_tos_is_negative', 'A'],
         ['4005_flowcontrol_jump_to_subroutine', 'A'],
         ['4006_flowcontrol_return_from_subroutine', 'A'],
+        ['5001_io_output_character', 'A'],
+        ['5002_io_output_digit', '2'],
         ] 
 
 for test in tests: