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:
+7
-4
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user