|
1 | 1 | #include <stdio.h> |
2 | 2 | #include <stdlib.h> |
| 3 | +#include <inttypes.h> |
3 | 4 | #include "values.h" |
4 | 5 | #include "print.h" |
5 | 6 | #include "runtime.h" |
@@ -38,3 +39,39 @@ int main(int argc, char** argv) |
38 | 39 | free(heap); |
39 | 40 | return 0; |
40 | 41 | } |
| 42 | + |
| 43 | +const char* val_typeof_string(int64_t t) { |
| 44 | + switch (val_typeof(t)) { |
| 45 | + case T_INT: return "INT"; |
| 46 | + case T_BOOL: return "BOOL"; |
| 47 | + case T_CHAR: return "CHAR"; |
| 48 | + case T_EOF: return "EOF"; |
| 49 | + case T_VOID: return "VOID"; |
| 50 | + case T_EMPTY: return "EMPTY"; |
| 51 | + case T_BOX: return "BOX"; |
| 52 | + case T_CONS: return "CONS"; |
| 53 | + case T_VECT: return "VECT"; |
| 54 | + case T_STR: return "STR"; |
| 55 | + default: return "UNKNOWN"; |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +void print_memory(int64_t* rsp, int64_t rbp, int64_t rbx) { |
| 62 | + int stack_count = (rbp-(int64_t)rsp) / 8; |
| 63 | + int heap_count = (rbx-(int64_t)heap) / 8; |
| 64 | + |
| 65 | + printf("----------------------------------------------------------------\n"); |
| 66 | + // printf("rsp: %" PRIx64 ", rbp: %" PRIx64 ", stack count: %d, heap count: %d\n", (int64_t)rsp, rbp, stack_count, heap_count); |
| 67 | + int i; |
| 68 | + |
| 69 | + printf("STACK:\n"); |
| 70 | + for (i = 0; i < stack_count; i++) { |
| 71 | + printf("[%" PRIx64 "] = %016" PRIx64 ", %s\n", (int64_t)rsp + i, rsp[i], val_typeof_string(rsp[i])); |
| 72 | + } |
| 73 | + printf("HEAP:\n"); |
| 74 | + for (i = 0; i < heap_count; i++) { |
| 75 | + printf("[%" PRIx64 "] = %016" PRIx64 ", %s\n", (int64_t)heap + i, heap[i], val_typeof_string(heap[i])); |
| 76 | + } |
| 77 | +} |
0 commit comments