-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a new primitive function `Primitive.send_delegate!` which emits a send instruction based on the first two parameters. It forces the send instruction to be an FCALL, thereby passing visibility checks. This allows us to write `Class#new` in Ruby and have it work for both BasicObject and regular objects. Here are the instructions for `Class#new`: ``` $ ./miniruby -e'puts RubyVM::InstructionSequence.of(Class.method(:new)).disasm' == disasm: #<ISeq:new@<internal:class>:2 (2,2)-(6,5)> local table (size: 4, argc: 0 [opts: 0, rest: 0, post: 0, block: 1, kw: -1@-1, kwrest: -1]) [ 4] "*"@0<Rest>[ 3] "&"@1<Block>[ 2] "..."@2 [ 1] obj@3 0000 opt_invokebuiltin_delegate <builtin!rb_class_alloc2/0>, 0( 3)[LiCa] 0003 setlocal_WC_0 obj@3 0005 getlocal_WC_0 obj@3 ( 4)[Li] 0007 getlocal_WC_0 "*"@0 0009 splatarray false 0011 getblockparamproxy "&"@1, 0 0014 send <calldata!mid:initialize, argc:1, ARGS_SPLAT|ARGS_BLOCKARG|FCALL>, nil 0017 pop 0018 getlocal_WC_0 obj@3 ( 5)[Li] 0020 leave ( 6)[Re] ``` Co-authored-by: John Hawthorn <jhawthorn@github.com>
- Loading branch information
1 parent
f35fec7
commit 63434c3
Showing
7 changed files
with
85 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Class | ||
def new(...) | ||
obj = Primitive.rb_class_alloc2 | ||
Primitive.send_delegate!(obj, :initialize, ...) | ||
obj | ||
end | ||
end |
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
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