aboutsummaryrefslogtreecommitdiffstats
path: root/prism/templates/lib
diff options
context:
space:
mode:
authorMatt Valentine-House <matt@eightbitraptor.com>2023-09-29 10:17:10 +0100
committerMatt Valentine-House <matt@eightbitraptor.com>2023-10-02 12:31:34 +0100
commitb6390a21eb7f316341bb7bf669a15dc321aa5239 (patch)
tree2a4c0f6bca3ea3c64b60d6fc2c74d72384721424 /prism/templates/lib
parent4da04d5f43231d62c7c9fb93f3b610cef2086091 (diff)
downloadruby-b6390a21eb7f316341bb7bf669a15dc321aa5239.tar.gz
[ci skip] More docs for InstructionSequence.compile
This commit documents that you can also pass a `File` object to `RubyVM::InstructionSequence.compile`, instead of a string, and this will behave in a similar way to `RubyVM::InstructionSequence.compile_file` e.g. ``` ❯ ./ruby -e "puts RubyVM::InstructionSequence.compile(File.open('test.rb')).disasm" == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(2,21)> local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 1] name@0 0000 putstring "Ruby" ( 1)[Li] 0002 setlocal_WC_0 name@0 0004 putself ( 2)[Li] 0005 putobject "Hello, " 0007 getlocal_WC_0 name@0 0009 dup 0010 objtostring <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE> 0012 anytostring 0013 concatstrings 2 0015 opt_send_without_block <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE> 0017 leave ~/git/ruby master* ≡ ⇡ ❯ ./ruby -e "puts RubyVM::InstructionSequence.compile(File.open('test.rb').read).disasm" == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(2,21)> local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 1] name@0 0000 putstring "Ruby" ( 1)[Li] 0002 setlocal_WC_0 name@0 0004 putself ( 2)[Li] 0005 putobject "Hello, " 0007 getlocal_WC_0 name@0 0009 dup 0010 objtostring <calldata!mid:to_s, argc:0, FCALL|ARGS_SIMPLE> 0012 anytostring 0013 concatstrings 2 0015 opt_send_without_block <calldata!mid:puts, argc:1, FCALL|ARGS_SIMPLE> 0017 leave ``` This is explicitly allowed by this code path in `rb_iseq_compile_with_option` so we should document it. ``` if (RB_TYPE_P(src, T_FILE)) { parse = rb_parser_compile_file_path; } else { parse = rb_parser_compile_string_path; StringValue(src); } ```
Diffstat (limited to 'prism/templates/lib')
0 files changed, 0 insertions, 0 deletions