1. You should add a URL when you you create a post on HN. You can indent code two spaces on HN, eg:
Stack s;
stack_init(&s);
dict_init();
exec(&s, "10 20 + ."); // Prints "30"
exec(&s, "1 2 3 4 .s"); // Shows stack contents
2. Your readme mentions a repl but I don't see it in the source code.
3. I'm not an expert in C but I thought header files shouldn't have code in them. The code should be in a .c file
4. Maybe move the code from USAGE into its own .c file.
#include "stacklib.h"
int main() {
Stack s;
stack_init(&s);
dict_init();
exec(&s, "10 20 + .");
printf("\n");
return 0;
}
technically, "header only libraries" can be exceptions to C code not being in header files. See STB as an example https://github.com/nothings/stb. The advantage theoretically is that you can #include this library and use its code and types from just one file, its a decent model IMHO, but it can be jarring to someone unfamiliar with header only libraries.
In particular learning about threaded interpreters, sub-routine interpreters, etc is very eye opening. That and really internalizing that everything, even code, is really just numbers.
Interesting. I am currently in the process of writing an interpreter for a similar stack based language. I already wrote a compiler for this language to x86 assembly that can be compiled to an ELF. The language is used as an intermediate language for a C compiler that I am writing. It is maybe less Forth-like than your language. For more information see: https://github.com/FransFaase/MES-replacement For the interpreter have a look at: stack_c_interpreter.c
At WHY2025, I gave a talk about the reasons why am working on this. See: https://www.youtube.com/watch?v=akzyyO5wvm0
Your experiment is certainly a good tool to grok stack mechanics, but that is only one element of what makes a Forth what it is. You're missing out on other crucial ingredients: colon definition and immediateness.
I wrote a series of articles that can help in that kind of discovery: http://tumbleforth.hardcoded.net/
I recently wrote one, in C, using tail calls to implement dispatch with CPS: https://tia.mat.br/posts/2025/08/30/forth-haiku.html
It's already pretty efficient but I'm working on it to make it even more efficient so I can use it as some sort of primitive fragment shader for an art project. This Forth variant is intended to execute Forth Haikus, as defined by the Forth Salon website.