From dcc88bc8ca2d5354c750f59304db361edffb2535 Mon Sep 17 00:00:00 2001 From: Emin Arslan Date: Sun, 3 May 2026 22:38:29 +0300 Subject: [PATCH] feat: add portable panic, I/O hooks and configurable memory sizes Co-authored-by: aider (openrouter/moonshotai/kimi-k2.6) --- forth.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/forth.h b/forth.h index 608cbbc..dd781a0 100644 --- a/forth.h +++ b/forth.h @@ -11,6 +11,43 @@ // Configuration (all hard limits removed) #define MAX_NAME_LEN 31 +/* Portable panic hook. Override for bare-metal reset/handling. */ +#ifndef forth_panic +#define forth_panic() do { for (;;) ; } while (0) +#endif + +/* Portable I/O hooks. Define FORTH_CUSTOM_IO before including this header + * to provide bare-metal UART (or other) implementations. */ +#ifndef FORTH_CUSTOM_IO +#define forth_putchar(c) putchar(c) +#define forth_getchar() getchar() +#define forth_printf(...) printf(__VA_ARGS__) +#define forth_fflush() fflush(stdout) +#endif + +/* Static memory sizes (override before including forth.h) */ +#ifndef FORTH_DATA_STACK_SIZE +#define FORTH_DATA_STACK_SIZE 128 +#endif +#ifndef FORTH_RET_STACK_SIZE +#define FORTH_RET_STACK_SIZE 128 +#endif +#ifndef FORTH_COMPILE_STACK_SIZE +#define FORTH_COMPILE_STACK_SIZE 64 +#endif +#ifndef FORTH_COMPILE_BUF_SIZE +#define FORTH_COMPILE_BUF_SIZE 256 +#endif +#ifndef FORTH_USER_MEM_CELLS +#define FORTH_USER_MEM_CELLS (1024 * 1024) +#endif +#ifndef FORTH_MAX_WORDS +#define FORTH_MAX_WORDS 256 +#endif +#ifndef FORTH_MAX_WORD_BODY_CELLS +#define FORTH_MAX_WORD_BODY_CELLS 4096 +#endif + #define F_IMMEDIATE (1 << 7) #define F_HIDDEN (1 << 6)