fix: qdup/tuck/2swap bugs, getline, and cached word pointers

Co-authored-by: aider (openrouter/moonshotai/kimi-k2.6) <aider@aider.chat>
This commit is contained in:
2026-05-03 21:39:52 +03:00
parent bf3c15ec27
commit b115744991
7 changed files with 106 additions and 89 deletions
+7 -4
View File
@@ -73,13 +73,12 @@ void process_token(const char* token) {
if (state == 0) {
data_push((int64_t)v);
} else { // Compile lit + number
Word* lit_w = lookup_word_internal("lit");
if (!lit_w) {
if (!w_lit) {
fprintf(stderr, "Fatal: lit word not found\n");
return;
}
ensure_compile_cap(2);
compile_buf[compile_idx++] = (Cell){.word = lit_w};
compile_buf[compile_idx++] = (Cell){.word = w_lit};
compile_buf[compile_idx++] = (Cell){.num = (int64_t)v};
}
} else {
@@ -92,9 +91,13 @@ void outer_interpreter(void) {
while (1) {
printf("ok ");
fflush(stdout);
if (fgets(input_buf, sizeof(input_buf), stdin) == NULL) {
ssize_t n = getline(&input_buf, &input_buf_cap, stdin);
if (n < 0) {
break;
}
if (n > 0 && input_buf[n - 1] == '\n') {
input_buf[n - 1] = '\0';
}
input_ptr = input_buf;
char* tok;
while ((tok = next_token()) != NULL) {