diff --git a/src/interpreter.c b/src/interpreter.c index 2f9ae76..7255a4c 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -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; diff --git a/src/program.c b/src/program.c index 79ab0ea..aa113b6 100644 --- a/src/program.c +++ b/src/program.c @@ -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) {