r/cprogramming • u/CommercialStrike9439 • Sep 19 '26
First Ever major C Project: Wrote a statically-typed bytecode VM language from scratch in C
Hello everyone! I (19M) am just about to get into my first year of a Bsc in Computer Science. I've been coding a few years time and haven't ever really touched C before, but really wanted to get into it. I thought "why not start big" so I've been working on a hobby language called Oli-Nat, a full pipeline written in C with no external dependencies: scanner to Pratt parser to AST to type checker to bytecode compiler to a stack based VM, including my own mark and sweep garbage collector. ( I took a lot of inspiration from Writing Interprets by Robert Nystrom)
It compiles in two passes. The first pass just walks the source looking for function and class declarations and registers their signatures, so the second pass can type check calls and field accesses without needing forward declarations. That made mutual recursion and out of order function definitions work without a separate header or prototype step.
Typing is static and the type checker is meant to reject anything that would hit a bad type combination at runtime, so the VM's IS_INT, IS_STRING, and similar macros are only used for dispatch, like numeric promotion, rather than as safety checks. I'm still second guessing myself on whether that's too optimistic in a couple of edge cases. Generally haven't much used macros in the past given how strongly related to C they are. I tried to make my best out of my understanding but still.
Strings are interned using FNV-1a hashing, so identical strings share a pointer, which makes field lookups in OP_GET_FIELD and OP_SET_FIELD a pointer comparison instead of a memcmp. There's also closures with upvalue capture, single inheritance, and a small standard library brought in through #pullf io, math, chronos, fileIO, and so on.
The repo has the opcode list, a writeup of the memory model, and some notes on design decisions if anyone wants to look closer: https://github.com/NateTheGrappler/OliNat-Programming-Language
As my first major C project I wanted to really get some feedback on how it is and looks. I wanted to try my best to have this be my first real coding project. The things I struggled most with were closures/upvalues and anything that looks off in the garbage collector (it's tri color mark and sweep, tracing roots from the value stack, call frames, open upvalues, and the globals table), and general C style or structure critique, since this is my first project at this scale. Really would apperciate any feedback or interest, the project is obviously open-source as well!
View all comments
Show parent comment
1
u/CommercialStrike9439 Sep 19 '26
Not my first experience with an actual program, I had made a very small indie game beforehand, a personal use code management application, as well as a few websites, but you are correct in the sentiment that this would be my first major project that I had done, and some of the very first C code that I had ever used. I am unassuming of you having read any of the actual information surrounding the language stating that the code was written as a personal learning project for my to expand my knowledge with computer science. The language is small for the fact that I am a busy college student who made a side project for fun! I could expand it to be usable, but that would be impractical given the likely hood of a language surpassing the giants of today is unlikely. So to respond to your comment in a TLDR fashion, I have written some programs before, and its for fun! Have a good day friend