fix the thing with the thing

This commit is contained in:
Freya Murphy 2023-04-13 19:27:20 -04:00
parent 43e7f57fd0
commit b4b00cb6d2
2 changed files with 16 additions and 2 deletions

View file

@ -52,6 +52,20 @@ static void recurse_program(Program* program, Tape* tape) {
next:
program_next(program, &s);
// printf("[");
// for(uint32_t i = 0; i < tape->len; i++) {
// printf("0x%02x ", tape->data[i]);
// }
// printf("\b]\n ");
// for(uint32_t i = 0; i < tape->len; i++) {
// if (i == tape->index) {
// printf(" ^ ");
// } else {
// printf(" ");
// }
// }
// printf(" \ + tape->indexn");
switch (s) {
case MoveLeft:
tape_left(tape);
@ -85,7 +99,7 @@ next:
case Allocate: {
uint8_t len = tape_get(tape);
Tape* new = malloc(sizeof(Tape));
tape_init(len, tape);
tape_init(len, new);
void* ptr = (void*) tape_ptr(tape);
memcpy(ptr, &new, sizeof(Tape*));
break;

View file

@ -159,7 +159,7 @@ void tape_set(Tape* tape, uint8_t value) {
}
uint8_t* tape_ptr(Tape* tape) {
return tape->data;
return tape->data + tape->index;
}
void tape_free(Tape* tape) {