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
+38
View File
@@ -0,0 +1,38 @@
#include "forth.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
void forth_putchar(char c) {
putchar((unsigned char)c);
}
int forth_getchar(void) {
return getchar();
}
void forth_fflush(void) {
fflush(stdout);
}
void forth_panic(void) {
for (;;);
}
int64_t forth_strtoll(const char* str, char** endptr, int base) {
return (int64_t)strtoll(str, endptr, base);
}
void forth_printf(const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
}
int main(void) {
forth_run();
return 0;
}