From 1e574f5bec9163bff30341beb9a63c4f0056e659 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Fri, 5 Jul 2019 14:22:10 -0700 Subject: [PATCH] Added tests for output half of IO IMP. --- tests/5001_io_output_character.pvvs | 5 +++++ tests/5002_io_output_digit.pvvs | 5 +++++ vv_interpreter.c | 6 +++--- vv_test.py | 2 ++ 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 tests/5001_io_output_character.pvvs create mode 100644 tests/5002_io_output_digit.pvvs diff --git a/tests/5001_io_output_character.pvvs b/tests/5001_io_output_character.pvvs new file mode 100644 index 0000000..1fefcd4 --- /dev/null +++ b/tests/5001_io_output_character.pvvs @@ -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 index 0000000..653a720 --- /dev/null +++ b/tests/5002_io_output_digit.pvvs @@ -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 diff --git a/vv_interpreter.c b/vv_interpreter.c index aa88505..be52497 100644 --- a/vv_interpreter.c +++ b/vv_interpreter.c @@ -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); diff --git a/vv_test.py b/vv_test.py index 68b4db8..829e891 100755 --- a/vv_test.py +++ b/vv_test.py @@ -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: -- 2.20.1