I wrote a Cozy Programming language
Published: 2021-11-08 22:10:39

When i started on writing [Paka](https://github.com/ShawSumma/paka) in March 2020 I had no idea what I was getting into.

I had only previously spent one month tops per project; Moving onto newer ideas and abandoning code was my modus operandi. I started new project, like the countless before, that was intended to be an interpreter for a new langugage called DEXT written in [The D Programming Language](https://dlang.org). As time passed and the code grew to about 3000 lines before the name change to Paka.

Paka was intended to be a lisp originally, but ended up a scripting language with a 'polite' syntax.

```ruby
# add two numbers
def add(x, y) {
    return x + y
}

println(add(x, y))
``` ​

It translated recursion into simple array pushes and pops. This allowed for recursion to one's heart's content. 

It supported freezing the entire running program, heap and all, to a JSON subset consisting of only objects and strings. Sadly this had to be removed for its performance penalty. This is a feature on the top of the list to bring back, and I have devised a system to keep performance up.

## Quest (October 2020)

In order to help others' languages that looked fun, I decided to implement a new language that works alongside Paka. A free little language called [Quest](https://github.com/sampersand/quest), made by a friend by the name of sampersand. It had more performance than the implementation they made, though had much head room to improve. It ended up not working out in the end, but it was a fun way to test my language's capability and try to improve quest as a language.

## Passerine (February 2021)

[Passerine](https://github.com/vrtbl/passerine) was the next language i decided to try to fit onto paka, but alas this one too was eventually put aside for the time being.

## MiniVM

One day in a discord call a twist of fate come. Someone asked how to implement a virtual machine in C. I, having learned much about virtual machines in the past 13 months, was asked how to write one. What was going to be a one-off example soon ballooned into a new runtime and virtual machine for Paka.

Performance was through the roof
```rb
def fib(n) {
    if n < 2 {
        return n
    } else {
        return fib(n-1) + fib(n-2)
    }
}

println(fib(35))
```
which ran in 850ms was now taking  500ms.

MiniVM was soon converted from a stack machine to a register machine. This came with another reduction, this time to 400ms, for the above program

## A Dream

One of my far-off seeming goals was to get Paka to the point where it could be used to write a compiler for itself in.
This dream manifested almost out of thin air, when i made a simple Paka file to evaluate expressions like `1 + 2 + 3`.

Then came the rest of the syntax to see how far i could get; It turns out it was less of an undertaking than i had expected.

## The state of it all

Paka is now a cozy little language with a 30kb vm and 20kb compiler.

It builds in less than a second for most folks with a computer from the last decade...

```sh
# build minivm and paka
git clone https://github.com/shawsumma/purr --recursive
cd purr
make -C minivm
make -C ./
``` 

```
# run a file
./minivm/minivm bin/stage3 lang/test/echo.paka -- hello world
```

## Call to Action

If you found any of this article interesting or helpful, it would be appreciated to give me a star over at [shawsumma/purr](https://github.com/shawsumma/purr) and/or [shawsumma/minivm](https://github.com/shawsumma/minivm).

And please be kind to me, this is my first time really writing about paka or minivm more than a paragraph.