ruby-x.github.io/app/views/posts/_2015-11-28-one-compiler-down-one-to-go.md
Torsten Ruger 5950fac3ce move posts
2018-04-10 19:11:06 +03:00

2.7 KiB

Ok, that was surprising: I just wrote a language in two months. Parser, compiler, working binaries and all.

Then i documented it , detailed the syntax and even did some benchmarking. Speed is luckily roughly where i wanted it. Mostly (only mostly?) slower than c, but only by about 50, very understandable percent. It is doing things in a more roundabout, and easier to understand way, and lacking any optimisation. It means you can do about a million fibonacci(20) in a second on a pi, and beat ruby at it by a about a factor of 20.

So, the good news: it it works

Working means: calling works, if, while, assignment, class and method definition. The benchmarks were hello world and fibonacci, both recursive and by looping.

I even updated the whole book to be up to date. Added a Soml section, updated parfait, rewrote the register level . . .

It all clicked into place

To be fair, i don't think anyone writes a language that isn't a toy in 2 months, and it was only possible because a lot of the stuff was there already.

  • Parfait was pretty much there. Just consolidated it as it is all just adapter.
  • The Register abstraction (bottom) was there.
  • Using the ast library made things easier.
  • A lot of the parser could be reused.

And off course the second time around everything is easier (aka hindsight is perfect).

One of the better movie lines comes to mind, (paraphrased) "We are all just one small adjustment away from making our code work". It was a step sideways in the head which brought a leap forward in terms of direction. Not where i was going but where i wanted to go.

Open issues

Clearly i had wobbled on the parfait front. Now it's clear it will have to be recoded in soml, and then re-translated into ruby. But it was good to have it there in ruby all the time for the concepts to solidify.

Typing is not completely done, and negative tests for types are non existant. Also exceptions and the machinery for the returns.

I did a nice framework for testing the binaries on a remote machine, would be nice to have it on travis. But my image is over 2Gb.

And onto the next compiler

The ideas about how to compile ruby into soml have been percolating and are waiting to be put to action. The theory looks good,but one has to see it to believe it.

The first steps are quite clear though. Get the ruby parser integrated, get the compiler up, start with small tests. Work the types at the same time.

And let the adventure continue.