--- /dev/null
+# 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
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;
}
}
['2003_arithmetic_multiplication', 'B'],
['2004_arithmetic_division', 'A'],
['2005_arithmetic_remainder', 'A'],
+ ['3001_heap', 'BCA'],
]
for test in tests: