Skip to content

Instantly share code, notes, and snippets.

@nahi
Created October 27, 2011 01:56
Show Gist options
  • Save nahi/1318576 to your computer and use it in GitHub Desktop.
Save nahi/1318576 to your computer and use it in GitHub Desktop.
% ruby -e 'p(begin; raise; rescue => e; end)'
nil
% ruby187 -e 'p(begin; raise; rescue => e; end)'
RuntimeError
% jruby --1.9 -e 'p(begin; raise; rescue => e; end)'
RuntimeError
% jruby --1.8 -e 'p(begin; raise; rescue => e; end)'
RuntimeError
% jruby -J-Xbootclasspath/a:$JRUBY_HOME/build_lib/jgrapht-jdk1.5.jar -X-CIR -e 'p(begin; raise; rescue => e; end)'
RuntimeError
% rbx -e 'p(begin; raise; rescue => e; end)'
nil
% ruby --dump=parsetree -e 'begin; raise; rescue => e; end'
###########################################################
## Do NOT use this node dump for any purpose other than ##
## debug and research. Compatibility is not guaranteed. ##
###########################################################
# @ NODE_SCOPE (line: 1)
# +- nd_tbl: :e
# +- nd_args:
# | (null node)
# +- nd_body:
# @ NODE_RESCUE (line: 1)
# +- nd_head:
# | @ NODE_BLOCK (line: 1)
# | +- nd_head:
# | | @ NODE_BEGIN (line: 1)
# | | +- nd_body:
# | | (null node)
# | +- nd_next:
# | @ NODE_BLOCK (line: 1)
# | +- nd_head:
# | | @ NODE_VCALL (line: 1)
# | | +- nd_mid: :raise
# | +- nd_next:
# | (null node)
# +- nd_resq:
# | @ NODE_RESBODY (line: 1)
# | +- nd_args:
# | | (null node)
# | +- nd_body:
# | | @ NODE_BLOCK (line: 1)
# | | +- nd_head:
# | | | @ NODE_DASGN_CURR (line: 1)
# | | | +- nd_vid: :e
# | | | +- nd_value:
# | | | @ NODE_ERRINFO (line: 1)
# | | +- nd_next:
# | | @ NODE_BLOCK (line: 1)
# | | +- nd_head:
# | | | @ NODE_BEGIN (line: 1)
# | | | +- nd_body:
# | | | (null node)
# | | +- nd_next:
# | | (null node)
# | +- nd_head:
# | (null node)
# +- nd_else:
# (null node)
% jruby -S ast -s -e 'begin; raise; rescue => e; end'
AST:
RootNode 0
NewlineNode 0
BeginNode 0
RescueNode 0
RescueBodyNode 0
LocalAsgnNode:e 0
GlobalVarNode:$! 0
NewlineNode 0
VCallNode:raise 0
SEXP:
(root (newline (begin (rescue (rescuebody (localasgn e (globalvar $!))) (newline (vcall raise))))))
% jruby -J-Xbootclasspath/a:$JRUBY_HOME/build_lib/jgrapht-jdk1.5.jar -X-CIR -Xir.debug=true -e 'begin; raise; rescue => e; end'
[snip]
Instructions:
BB [1:LBL_4]
BB [2:LBL_5]
%self = recv_self
%block(0:0) = recv_closure
file_name(-e)
line_num(0)
BB [3:LBL_0]
%v_1 = call(raise, %self, [])
%v_0 = copy(%v_1)
BB [4:LBL_2]
%v_2 = recv_exception
%v_3 = get_global_var($!)
e(0:1) = copy(%v_3)
%v_0 = copy(%v_3)
jump LBL_1
BB [5:LBL_1]
return(%v_0)
BB [6:LBL_6]
return(nil)
------ Rescue block map ------
BB 3 --> BB 4
------ Ensure block map ------
% rbx compile -SB -e 'begin; raise; rescue => e; end'
[:script,
[:rescue,
[:call, nil, :raise, nil],
[:resbody,
[:array, [:const, :StandardError], [:lasgn, :e, [:gvar, :$!]]],
[:nil]]]]
============= :__script__ ==============
Arguments: 0 required, 0 post, 0 total
Arity: 0
Locals: 1: e
Stack size: 6
Lines to IP: 1: 0..12, 0: 13..17, 1: 18..43, 0: 44..49
0000: push_exception_state
0001: set_stack_local 0
0003: pop
0004: setup_unwind 13, 0
0007: push_self
0008: send_method :raise
0010: pop_unwind
0011: goto 44
0013: push_exception_state
0014: set_stack_local 1
0016: pop
0017: push_current_exception
0018: dup_top
0019: push_const_fast :StandardError, 2
0022: swap_stack
0023: send_stack :===, 1
0026: goto_if_true 30
0028: goto 39
0030: pop
0031: push_current_exception
0032: set_local 0 # e
0034: pop
0035: push_nil
0036: clear_exception
0037: goto 44
0039: pop
0040: push_stack_local 1
0042: restore_exception_state
0043: reraise
0044: push_stack_local 0
0046: restore_exception_state
0047: pop
0048: push_true
0049: ret
----------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment