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
+4 -4
View File
@@ -309,7 +309,7 @@ void do_zero_gt(Word* w) {
void do_dot(Word* w) {
(void)w;
if (data_sp < 0) return;
forth_printf("%" PRId64 " ", data_pop());
forth_printf("%lld ", (long long)data_pop());
forth_fflush();
}
@@ -329,7 +329,7 @@ void do_emit(Word* w) {
void do_key(Word* w) {
(void)w;
int c = forth_getchar();
data_push(c == EOF ? -1 : c);
data_push(c == FORTH_EOF ? -1 : c);
}
void do_dot_quote(Word* w) {
@@ -337,7 +337,7 @@ void do_dot_quote(Word* w) {
if (state == 0) {
// Interpret mode: print immediately
if (input_ptr == NULL) { forth_printf("Missing string\n"); return; }
while (*input_ptr && isspace((unsigned char)*input_ptr)) input_ptr++;
while (*input_ptr && forth_isspace((unsigned char)*input_ptr)) input_ptr++;
if (*input_ptr != '"') { forth_printf("Expected \" to start string\n"); return; }
input_ptr++;
char* start = input_ptr;
@@ -349,7 +349,7 @@ void do_dot_quote(Word* w) {
} else {
// Compile mode: compile string for runtime
if (input_ptr == NULL) { forth_printf("Missing string\n"); return; }
while (*input_ptr && isspace((unsigned char)*input_ptr)) input_ptr++;
while (*input_ptr && forth_isspace((unsigned char)*input_ptr)) input_ptr++;
if (*input_ptr != '"') { forth_printf("Expected \" to start string\n"); return; }
input_ptr++;
char* start = input_ptr;