feat: abstract I/O and strings for freestanding compilation

Co-authored-by: aider (openrouter/moonshotai/kimi-k2.6) <aider@aider.chat>
This commit is contained in:
2026-05-04 10:17:43 +03:00
parent 19c8608c76
commit dbf4eb5d0e
8 changed files with 216 additions and 42 deletions
+5 -5
View File
@@ -3,7 +3,7 @@
// Input tokenizer (unchanged)
char* next_token(void) {
if (input_ptr == NULL) return NULL;
while (*input_ptr != '\0' && isspace((unsigned char)*input_ptr)) {
while (*input_ptr != '\0' && forth_isspace((unsigned char)*input_ptr)) {
input_ptr++;
}
if (*input_ptr == '\0') return NULL;
@@ -63,10 +63,10 @@ void process_token(const char* token) {
}
} else { // Try to parse as number
char* end;
long long v = strtoll(token, &end, 10);
int64_t v = forth_strtoll(token, &end, 10);
if (end != token && *end == '\0') {
if (state == 0) {
data_push((int64_t)v);
data_push(v);
} else { // Compile lit + number
if (!w_lit) {
forth_printf("Fatal: lit word not found\n");
@@ -91,13 +91,13 @@ void outer_interpreter(void) {
int c;
while (i < sizeof(line_buf) - 1) {
c = forth_getchar();
if (c == EOF || c == '\n' || c == '\r') {
if (c == FORTH_EOF || c == '\n' || c == '\r') {
break;
}
line_buf[i++] = (char)c;
}
line_buf[i] = '\0';
if (i == 0 && c == EOF) {
if (i == 0 && c == FORTH_EOF) {
break;
}
input_buf = line_buf;