r/ProgrammingLanguages • • Jan 03 '26

Help How to design Byte Code + VM for this abomination of a language :)

17 Upvotes

So, I announced Pie Lang a couple of weeks go. The language treats everything as an expression, but that's not what's crazy about it. The language allows you to assign ANYTHING to ANYTHING. Literally. To understand this, here is an example:

.: Scopes evaluate to the last expression inside then
a = {
    x = 1;
    y = 2;
    z = x + y;
};

.: a == 3
.: But since I can assign anything to anything
.: let's assign the scope to something

{
    x = 1;
    y = 2;
    z = x + y;
} = "Hi!";

.: Now if I do this:
a = {
    x = 1;
    y = 2;
    z = x + y;
};
.: a == "Hi!";

The language is currently implemented using a tree-walker interpreter. Here's a break-down of how it does this fuckery:

1- when assigning to anything, it takes he LHS and serializes it into a string and uses that as a variable name

2- whenever evaluating an expression, serialize first and check if it was ever used as a variable name

My main problem is that walking the tree is VERY SLOW. It took Pie 108 minutes to run Part 1 of Day 2 of AoC :). So I've been thinking of switching to a stack-based VM. The problem is, I'm not sure how to design this in a way that allows for what Pie lets you do.

Link to Pie's repo (with docs and binaries)