Find me on Codeberg

Review _2015 ( 2015-03-21 )

As before the original start of the project, i was 6 weeks on holiday. The distance and lack of computer really helps.

Review

So i printed most of the code and the book and went over it. And apart from abismal spelling i found especially one mistake.

I had been going at the thing from the angle of producing binaries. Wrong aproach.

Ruby is Dynamic

In fact ruby is so dynamic it is hard to think of anything that you need to do at compile time that you can’t do at runtime.

In other words, all functionality is available at run-time. Ie it needs to be available in ruby, and since it then is available in ruby, one should reuse it. I had just sort of tried to avoid this, as it seemed so big.

In fact it is quite easy to express what needs to happed for eg. a method call, in ruby. The hard thing is to use that code at compile time.

Inlining

When i say hard, i mean hard to code. Actually it is quite easy to understand. One “just” needs to inline the code, easy actually. Off course i had known that inlining would be neccessary in the end, i had just thought later would be fine. Well, it isn’t. Off course, is it ever!

Inlining is making the functionality happen, without initializing a method call and return. Off course this is only possible for known function calls, but that’s enough. The objects/classes we use during method dispatch are well known, so everything can be resolved at compile time. Hunky dory. Just how?

As a first step we change the self, while saving the old self to a tmp. Then we have to deal with how the called function accesses variables (arguments or locals). We know it does this through the Message and Frame objects. But since those are different for an inlined function, we have to make them explicit arguments. So instead of the normal eg. Message, we can create an InlineMessage for inlined function. When resolving a variable name, this InlinedMessage will look up in the parents variables and arrange access to that.

Changes

So some of the concrete changes that will come once i’ve done all cosmetic fixes:

  • much more parfait classes / functionality
  • remove all duplication in vm (that is now parfait)
  • change of compile, using explicit message/frames
  • explicit logic type (alongside integer + reference)

I also decided it would be cleaner to use the visitor pattern for compiling the ast to vm. In fact the directory should be named compile.

And i noticed that what i have called Builtin up to now is actually part of the Register machine layer (not vm), so it needs to move there.

Some publicity

I have now given lightning talk on Frozen Rails 2014 and Ruby Bath 2015. As 5 Minutes is clearly now enough i will work on a longer presentation.