Skip to content

Instantly share code, notes, and snippets.

@headius
Last active December 15, 2020 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/89053c3dda67380d2a59727d462f874e to your computer and use it in GitHub Desktop.
Save headius/89053c3dda67380d2a59727d462f874e to your computer and use it in GitHub Desktop.
$ rvm ruby-2.6.5 do ruby -e 'puts RubyVM::InstructionSequence.compile("print if 2..3").disasm'
<compiled>:1: warning: integer literal in conditional range
<compiled>:1: warning: integer literal in conditional range
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(1,13)> (catch: FALSE)
0000 getspecial 2, 0 ( 1)[Li]
0003 branchif 18
0005 putobject 2
0007 getglobal $.
0009 opt_eq <callinfo!mid:==, argc:1, ARGS_SIMPLE>, <callcache>
0012 branchunless 36
0014 putobject true
0016 setspecial 2
0018 putobject 3
0020 getglobal $.
0022 opt_eq <callinfo!mid:==, argc:1, ARGS_SIMPLE>, <callcache>
0025 branchunless 31
0027 putobject false
0029 setspecial 2
0031 putself
0032 opt_send_without_block <callinfo!mid:print, argc:0, FCALL|VCALL|ARGS_SIMPLE>, <callcache>
0035 leave
0036 putnil
0037 leave
$ jruby -Xir.print -e "print if 2..3"
2020-12-15T13:33:27.417-06:00 [main] INFO JVMVisitor : Printing JIT IR for -e:
begin SCRIPT_BODY<-e>
flags: [BINDING_HAS_ESCAPED, REQUIRES_DYNSCOPE, REQUIRES_LASTLINE, REQUIRES_BLOCK, FLAGS_COMPUTED]
signature(pre=0,opt=0,post=0,rest=NONE,kwargs=0,kwreq=0,kwrest=-1)
block #1 (out: 6,2): LBL_2:-1
0: push_method_frame(frameName: -e, visibility: PRIVATE)
1: push_method_binding
block #2 (out: 3,4,7): LBL_3:-1
0: %self := recv_self
1: line_num(lineNumber: 0, coverage: false, oneshot: false)
2: %v_2 := build_range(fix<2>, fix<3>, exclusive: false)
3: b_false(ipc<LBL_0:9>, %v_2, jumpTarget: LBL_0:9, value: %v_2)
block #3 (out: 6,7): LBL_4:-1
0: %v_3 := call_0o(self<%self>, callType: VARIABLE, name: print, potentiallyRefined: false)
1: pop_binding
2: pop_method_frame
3: return(%v_3)
block #7 (out: 6): _GLOBAL_ENSURE_BLOCK__0:-1
0: %v_4 := recv_jruby_exc
1: pop_binding
2: pop_method_frame
3: throw(%v_4)
block #6 (out: 7): LBL_5:-1
0: return(nil<>)
block #4 (out: 6,7): LBL_0:9
0: pop_binding
1: pop_method_frame
2: return(nil<>)
$ rvm ruby-2.6.5 do ruby -e 'puts RubyVM::InstructionSequence.compile("while 2..3; print; end").disasm'
<compiled>:1: warning: integer literal in conditional range
<compiled>:1: warning: integer literal in conditional range
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(1,22)> (catch: FALSE)
== catch table
| catch type: break st: 0006 ed: 0045 sp: 0000 cont: 0045
| catch type: next st: 0006 ed: 0045 sp: 0000 cont: 0003
| catch type: redo st: 0006 ed: 0045 sp: 0000 cont: 0006
|------------------------------------------------------------------------
0000 jump 11 ( 1)[Li]
0002 putnil
0003 pop
0004 jump 11
0006 putself
0007 opt_send_without_block <callinfo!mid:print, argc:0, FCALL|VCALL|ARGS_SIMPLE>, <callcache>
0010 pop
0011 getspecial 2, 0
0014 branchif 29
0016 putobject 2
0018 getglobal $.
0020 opt_eq <callinfo!mid:==, argc:1, ARGS_SIMPLE>, <callcache>
0023 branchunless 44
0025 putobject true
0027 setspecial 2
0029 putobject 3
0031 getglobal $.
0033 opt_eq <callinfo!mid:==, argc:1, ARGS_SIMPLE>, <callcache>
0036 branchunless 6
0038 putobject false
0040 setspecial 2
0042 jump 6
0044 putnil
0045 nop
0046 leave ( 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment