Now that i have had time to write some more code (250 commits last month), here is the good news:
A dynamic language like ruby really has at it’s heart the dynamic method resolution. Without that we’d be writing C++. Not much can be done in ruby without looking up methods.
Yet all this time i have been running circles around this mother of a problem, because (after all) it is a BIG one. It must be the one single most important reason why dynamic languages are interpreted and not compiled.
Last year already i started on a rewrite. After hitting this exact same wall for the fourth time. I put in some more Layers, the way a good programmer fixes any daunting problem.
The Readme has quite a good summary on the new layers, and off course i’ll update the architecture soon. But in case you didn’t click, here is the very very short summary:
After having finished all this layering work, i was back to square resolve:
But off course when i got there i started thinking that the resolve method (in ruby) would need resolve itself. And after briefly considering cheating (hardcoding type information into this one method), i opted to write the code in Risc. Basically assembler.
And it was horrible. It worked, but it was completely unreadable. So then i wrote a dsl for generating risc instructions, using a combination of method_missing, instance_eval and operator overloading. The result is quite readable code, a mixture between assembler and a mathematical notation, where one can just freely name registers and move data around with [] and «.
By then resolving worked, but it was still a method. Since it was already in risc, i basically inlined the code by creating a new Mom instruction and moving the code to it’s to_risc.
A small bug in calling the resulting method was fixed, and voila,
Previous, static, Hello Worlds looked like this:
“Hello world”.putstring
Off course we can know the type that putstring applies to and so this does not involve any method resolution at runtime, only at compile time.
Todays step is thus:
a = “Hello World”
a.putstring
This does involve a run-time lookup of the putstring method. It being a method on String, it is indeed found and called.(1) Hurray.
And maths works too:
a = 150
a.div10
Does indeed result in 15. Also most operator (+,- <<) work. Even with the new integers. Part of the rewrite was to upgrade integers to first class objects.
PS(1): I know with more analysis the compiler could now that a is a String (or Integer), but just now it doesn’t. Take my word for it or even better, read the code.