Added tests for heap IMP.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 5 Jul 2019 03:15:29 +0000 (20:15 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Fri, 5 Jul 2019 03:15:29 +0000 (20:15 -0700)
tests/3001_heap.pvvs [new file with mode: 0644]
vv_interpreter.c
vv_test.py

diff --git a/tests/3001_heap.pvvs b/tests/3001_heap.pvvs
new file mode 100644 (file)
index 0000000..0b572e8
--- /dev/null
@@ -0,0 +1,21 @@
+# This test verifies the heap IMP.
+
+SSSTSSSSSTN     | ST: Push +65 (ASCII A)
+SSSTN           | ST: Push +1 (used as an address)
+SSSTSSSSTSN     | ST: Push +66 (ASCII B)
+TTS             | HP: Store
+SSSTSSSSTTN     | ST: Push +67 (ASCII C)
+SSSTN           | ST: Push +1 (used as an address)
+TTT             | HP: Load
+
+
+TNSS
+TNSS
+TNSS
+NNN
+
+
+TNSS            | IO: Output character
+TNSS            | IO: Output character
+TNSS            | IO: Output character
+NNN             | FC: Terminate program
index 8d4db24..8fac7c2 100644 (file)
@@ -280,9 +280,21 @@ void
 process_imp_heap(uint8_t * code, size_t * pc, int32_t ** sp, int32_t ** hp)
 {
     switch (next_code_byte(code,pc)) {
 process_imp_heap(uint8_t * code, size_t * pc, int32_t ** sp, int32_t ** hp)
 {
     switch (next_code_byte(code,pc)) {
-        case ' ' : /* Store to heap      */ *(*hp + *((*sp)-1)) = **sp; *sp -= 2; break;
-        case '\t': /* Retrieve from heap */ **sp = *(*hp + **sp);                 break;
-        default  : ws_die(pc, "malformed heap IMP");                              break;
+        case ' ' :
+            /* Store to heap */
+            {
+                int32_t value = stack_pop(sp);
+                int32_t addr = stack_pop(sp);
+                *(*hp + addr) = value;
+            }
+            break;
+        case '\t':
+            /* Retrieve from heap */
+            stack_push(sp, *(*hp + stack_pop(sp)));
+            break;
+        default:
+            ws_die(pc, "malformed heap IMP");
+            break;
     }
 }
 
     }
 }
 
index 4a31280..33a998b 100755 (executable)
@@ -24,6 +24,7 @@ tests = [
         ['2003_arithmetic_multiplication', 'B'],
         ['2004_arithmetic_division', 'A'],
         ['2005_arithmetic_remainder', 'A'],
         ['2003_arithmetic_multiplication', 'B'],
         ['2004_arithmetic_division', 'A'],
         ['2005_arithmetic_remainder', 'A'],
+        ['3001_heap', 'BCA'],
         ] 
 
 for test in tests:
         ] 
 
 for test in tests: