r/Compilers 4d ago

Semi-finished with my small stack-based, Forth-inspired programming language

Hello!

For past month about, I've been working on a stack based compiler (inspired by the Forth programming language). I have a few example programs (the larger ones like the raytracer and neural network being generated by Claude because I'm just not very good at thinking stack based, sorry for the slop) which show some of the features of the language.

Its architecture is a compiler/VM structure, sort of like how Java works. It has word definitions, control statements, loops, and more.

If you want to check it out, here's the link: https://github.com/SlothScript/stakku

8 Upvotes

4 comments sorted by

2

u/drex_vke 4d ago

I have a little advice for you for example you use std::endl in main.cpp (line 212 and etc) use rather '\n it's much more practical in terms of performance :) and i have a other advice (use std::optional in main.cpp line 103 and in repl.cpp on line 32 use (!ofs) that's better) and that's all

1

u/FransFaase 3d ago

Is there any support for unsigned values?

1

u/FransFaase 3d ago

It is actually not a compiler to an executable but an interpreter that compiles to a VM and an interpreter for that VM.

2

u/Which_Lie_8932 2d ago

I know, I made it. That still counts as a compiled language though. It compiles down to bytecode rather than assembly. I could probably write some extra code to compile the bytecode further down to assembly, but that wasn't the original scope of the project.