GitHub Repo
https://github.com/radian628/pointers
Inspiration
This project was inspired by years of watching CS students struggle with and misunderstand pointers.
What it does
Pointers VM is a virtual machine that runs an interpreted version of a C-like language (which I've called "Pointers"). It runs entirely inside of your browser. The key distinguishing feature of Pointers VM is that it keeps a precise record of memory, taking a snapshot after every operation. You can fast-forward and rewind a program to and from any point in time and view how the memory looked at that point. All memory locations are clearly labeled to aid in understanding of what variables they map to.
How we built it
I built the parser, type-checker, and interpreter for Pointers VM from the ground up in raw TypeScript using no external libraries. I decided to take a new approach with many of the parts of this project, representing state with immutable "snapshots," allowing me to easily keep references of past data without it getting stale and enabling the VM to achieve its rewinding/fast-forwarding behavior. The VM is modeled as a stack machine: Functions create stack frames and push their local variable bindings to them. Temporary values are pushed to the stack and later popped as operations operate on them. This provides access to all data via memory (aiding in understanding, hopefully).
Challenges we ran into
The biggest challenge for me was creating the virtual machine in the first place. I had to maintain a mapping between a contiguous block of physical memory (represented with a JS ArrayBuffer) and the nightmare of a tree-walking interpreter I had to cook up for this language in about a day. Figuring out all the arcane C casting rules and attempting to apply them was also quite frustrating.
Another challenge I had was finding a way to represent memory in a descriptive way that didn't look like an eyesore.
Accomplishments that we're proud of
This is by far the largest interpreter I've made to date and I'm happy that it actually works. This is also the first time I've made an actual full language toolchain, going all the way from the lexer and parser to the typechecker to the actual runtime itself.
What we learned
I learned a lot about how to properly use functional patterns (immutable data structures especially) to store the state of the project in a predictable manner. If I know that some data I store won't change after I create it, I can keep references to it forever and know it'll be valid. This is a powerful capability and can be exploited to do things like "accumulate" values in an otherwise seemingly stateless system.
I also learned that I should be more careful to avoid scope creep.
What's next for Pointers VM
here's a lot of features I want to add, including several quite important ones that one would really expect to have in a pointer-related project:
- Arrays
- Structure types
- Function pointers (possibly)
- A more fault-tolerant parser to more easily recover from errors instead of "giving up" and treating the rest of input as nonsense.
- A better memory display showing where pointers actually lead when you hover over them, along with actual variable values (instead of having users need to decode hex codes manually)
- Fix some of the random runtime errors I wasn't dilligent enough to find the first time around.
- No more infinite loops.


Log in or sign up for Devpost to join the conversation.