forked from macournoyer/tinyrb
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement method_missing. Required a couple ugly tweaks in the byteco…
…de execution. I'm starting to hate the design for method lookup -> call... Need something better! LOOKUP instruction will now store the call site on the C stack, not in the regs. I'm not sure if this is bad or not, but since LOOKUP/CALL instructions are always next to each other there's no way this could not work, right, riiiight? Also, I found out that a CallSite was created on heap (and never freed) each time a polymorphic call is made, this is an important bug and will require rethinking the method lookup structure in the VM. RE method_missing, I got it to work by pading the arguments w/ an empty slot first. Normal call: reg value =========== 0 receiver 1 nil 2 arg macournoyer#1 3 arg macournoyer#2 Method missing call: reg value =========== 0 receiver 1 method name (replace by CALL instruction) 2 arg macournoyer#1 3 arg macournoyer#2 You see that most of the time, reg[1] is not used, that's not a big deal since we got plenty of registers left. The compiler needs to set the maximum number of register to be used so we have to set it to the max possible (+1, max number of args). That is all... w/ love, m-a
- Loading branch information
1 parent
74d7a3f
commit 4065c45
Showing
8 changed files
with
68 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
def twice(x) | ||
puts x + x | ||
puts x.to_s | ||
end | ||
|
||
# This caches the lookup for `Fixnum + Fixnum` | ||
twice 1 | ||
# => 2 | ||
# => 1 | ||
|
||
# This will skip the previous cache | ||
twice "yo" | ||
# => yoyo | ||
# => yo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
def method_missing(name, *args) | ||
puts "called method_missing" | ||
puts name | ||
end | ||
|
||
ohaie! | ||
# => called method_missing | ||
# => ohaie! | ||
|
||
def ohaie! | ||
puts "ok" | ||
end | ||
|
||
ohaie! | ||
# => ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters