ruby-internal 0.7.3 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/ruby-internal-node-dump +1 -1
- data/bin/ruby-internal-obfuscate +1 -1
- data/ext/cached/ruby-1.8.4/internal/method/{method.h → internal_method.h} +12 -0
- data/ext/cached/ruby-1.8.4/internal/module/getcfp.h +13 -0
- data/ext/cached/ruby-1.8.4/internal/node/global_entry.h +94 -0
- data/ext/cached/ruby-1.8.4/internal/node/node_type_descrip.c +41 -41
- data/ext/cached/ruby-1.8.4/internal/node/nodeinfo.c +288 -273
- data/ext/cached/ruby-1.8.4/internal/vm/instruction/insns_info.c +3 -0
- data/ext/cached/ruby-1.8.4/internal/vm/iseq/iseq_load.inc +21 -2
- data/ext/cached/{ruby-1.8.3/internal/method/method.h → ruby-1.8.5/internal/method/internal_method.h} +12 -0
- data/ext/cached/ruby-1.8.5/internal/module/getcfp.h +13 -0
- data/ext/cached/ruby-1.8.5/internal/node/global_entry.h +94 -0
- data/ext/cached/ruby-1.8.5/internal/node/node_type_descrip.c +45 -45
- data/ext/cached/ruby-1.8.5/internal/node/nodeinfo.c +310 -295
- data/ext/cached/ruby-1.8.5/internal/vm/instruction/insns_info.c +3 -0
- data/ext/cached/ruby-1.8.5/internal/vm/iseq/iseq_load.inc +21 -2
- data/ext/cached/{ruby-1.8.5/internal/method/method.h → ruby-1.8.6/internal/method/internal_method.h} +12 -0
- data/ext/cached/ruby-1.8.6/internal/module/getcfp.h +13 -0
- data/ext/cached/ruby-1.8.6/internal/node/global_entry.h +94 -0
- data/ext/cached/ruby-1.8.6/internal/node/node_type_descrip.c +48 -48
- data/ext/cached/ruby-1.8.6/internal/node/nodeinfo.c +323 -308
- data/ext/cached/ruby-1.8.6/internal/vm/instruction/insns_info.c +3 -0
- data/ext/cached/ruby-1.8.6/internal/vm/iseq/iseq_load.inc +21 -2
- data/ext/cached/{ruby-1.8.6/internal/method/method.h → ruby-1.8.7/internal/method/internal_method.h} +12 -0
- data/ext/cached/ruby-1.8.7/internal/module/getcfp.h +13 -0
- data/ext/cached/ruby-1.8.7/internal/node/global_entry.h +98 -0
- data/ext/cached/ruby-1.8.7/internal/node/node_type_descrip.c +42 -42
- data/ext/cached/ruby-1.8.7/internal/node/nodeinfo.c +276 -261
- data/ext/cached/ruby-1.8.7/internal/vm/instruction/insns_info.c +3 -0
- data/ext/cached/ruby-1.8.7/internal/vm/iseq/iseq_load.inc +21 -2
- data/ext/cached/{ruby-1.9.0/internal/method/method.h → ruby-1.9.1/internal/method/internal_method.h} +12 -0
- data/ext/cached/ruby-1.9.1/internal/module/classpath.c +12 -14
- data/ext/cached/ruby-1.9.1/internal/module/getcfp.h +25 -0
- data/ext/cached/ruby-1.9.1/internal/node/global_entry.h +86 -0
- data/ext/cached/ruby-1.9.1/internal/node/node_type_descrip.c +46 -48
- data/ext/cached/ruby-1.9.1/internal/node/nodeinfo.c +311 -412
- data/ext/cached/ruby-1.9.1/internal/vm/instruction/insns_info.c +3 -0
- data/ext/cached/ruby-1.9.1/internal/vm/iseq/iseq_load.inc +28 -6
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/iseq.h +1 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/parse.h +6 -6
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/revision.h +1 -1
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/version.h +6 -5
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/vm_core.h +3 -2
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/vm_insnhelper.h +1 -0
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/binding/block.h +0 -0
- data/ext/cached/{ruby-1.9.1/internal/method/method.h → ruby-1.9.2/internal/method/internal_method.h} +16 -5
- data/ext/cached/ruby-1.9.2/internal/module/classpath.c +40 -0
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/module/classpath.h +0 -0
- data/ext/cached/ruby-1.9.2/internal/module/getcfp.h +25 -0
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/node/block.h +0 -0
- data/ext/cached/ruby-1.9.2/internal/node/global_entry.h +93 -0
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/node/node_type_descrip.c +44 -48
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/node/nodeinfo.c +291 -439
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/node/nodeinfo.h +0 -0
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/proc/block.h +0 -0
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/tag/tag.h +0 -0
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/vm/instruction/insns_info.c +141 -64
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/vm/instruction/insns_info.h +88 -80
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/vm/iseq/insns_info.inc +77 -70
- data/ext/cached/ruby-1.9.2/internal/vm/iseq/iseq_load.inc +426 -0
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/debug.h +1 -1
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/dln.h +3 -3
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/encdb.h +18 -2
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/eval_intern.h +39 -28
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/gc.h +7 -5
- data/ext/cached/ruby-1.9.2/internal/yarv-headers/id.h +170 -0
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/iseq.h +20 -10
- data/ext/cached/ruby-1.9.2/internal/yarv-headers/method.h +103 -0
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/node.h +14 -47
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/parse.h +31 -148
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/regenc.h +7 -3
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/regint.h +16 -17
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/regparse.h +4 -1
- data/ext/cached/ruby-1.9.2/internal/yarv-headers/revision.h +1 -0
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/thread_pthread.h +4 -1
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/thread_win32.h +1 -1
- data/ext/cached/ruby-1.9.2/internal/yarv-headers/timev.h +21 -0
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/transcode_data.h +20 -10
- data/ext/cached/ruby-1.9.2/internal/yarv-headers/transdb.h +179 -0
- data/ext/cached/ruby-1.9.2/internal/yarv-headers/version.h +55 -0
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/vm_core.h +127 -84
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/vm_exec.h +4 -7
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/vm_insnhelper.h +53 -36
- data/ext/cached/{ruby-1.9.0 → ruby-1.9.2}/internal/yarv-headers/vm_opts.h +1 -1
- data/ext/cached/ruby-1.9.3/internal/binding/block.h +12 -0
- data/ext/cached/ruby-1.9.3/internal/method/internal_method.h +32 -0
- data/ext/cached/ruby-1.9.3/internal/module/classpath.c +40 -0
- data/ext/cached/{ruby-1.8.0 → ruby-1.9.3}/internal/module/classpath.h +5 -2
- data/ext/cached/ruby-1.9.3/internal/module/getcfp.h +25 -0
- data/ext/cached/ruby-1.9.3/internal/node/block.h +12 -0
- data/ext/cached/ruby-1.9.3/internal/node/global_entry.h +93 -0
- data/ext/cached/{ruby-1.8.3 → ruby-1.9.3}/internal/node/node_type_descrip.c +48 -57
- data/ext/cached/{ruby-1.6.8 → ruby-1.9.3}/internal/node/nodeinfo.c +589 -740
- data/ext/cached/{ruby-1.8.0 → ruby-1.9.3}/internal/node/nodeinfo.h +4 -3
- data/ext/cached/ruby-1.9.3/internal/proc/block.h +12 -0
- data/ext/cached/ruby-1.9.3/internal/tag/tag.h +6 -0
- data/ext/cached/ruby-1.9.3/internal/vm/instruction/insns_info.c +6013 -0
- data/ext/cached/ruby-1.9.3/internal/vm/instruction/insns_info.h +899 -0
- data/ext/cached/ruby-1.9.3/internal/vm/iseq/insns_info.inc +707 -0
- data/ext/cached/ruby-1.9.3/internal/vm/iseq/iseq_load.inc +423 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/addr2line.h +21 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/atomic.h +56 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/constant.h +34 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/debug.h +41 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/dln.h +50 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/encdb.h +167 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/eval_intern.h +234 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/gc.h +98 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/id.h +175 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/internal.h +232 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/iseq.h +125 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/method.h +105 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/node.h +503 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/parse.h +186 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/regenc.h +219 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/regint.h +850 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/regparse.h +362 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/revision.h +1 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/thread_pthread.h +51 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/thread_win32.h +40 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/timev.h +21 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/transcode_data.h +117 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/transdb.h +189 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/version.h +52 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/vm_core.h +756 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/vm_exec.h +184 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/vm_insnhelper.h +220 -0
- data/ext/cached/ruby-1.9.3/internal/yarv-headers/vm_opts.h +51 -0
- data/ext/internal/binding/block.h +20 -0
- data/ext/internal/method/internal_method.h +5 -38
- data/ext/internal/method/internal_method.h.rpp +0 -7
- data/ext/internal/method/method.c +52 -32
- data/ext/internal/module/classpath.c +18 -13
- data/ext/internal/module/classpath.h +3 -3
- data/ext/internal/module/extconf.rb +3 -2
- data/ext/internal/module/getcfp.h +13 -0
- data/ext/internal/module/getcfp.h.rpp +44 -0
- data/ext/internal/module/module.c +58 -21
- data/ext/internal/node/block.h +20 -0
- data/ext/internal/node/extconf.rb +2 -0
- data/ext/internal/node/global_entry.h +69 -13
- data/ext/internal/node/global_entry.h.rpp +11 -2
- data/ext/internal/node/node.c +30 -3
- data/ext/internal/node/node_type_descrip.c +47 -38
- data/ext/internal/node/nodeinfo.c +622 -306
- data/ext/internal/node/nodeinfo.h +1 -4
- data/ext/internal/proc/block.h +20 -0
- data/ext/internal/tag/tag.h +10 -0
- data/ext/internal/thread/thread.c +9 -3
- data/ext/internal/vm/extconf.rb +1 -0
- data/ext/internal/vm/instruction/insns_info.c +3 -5974
- data/ext/internal/vm/instruction/insns_info.h +0 -878
- data/ext/internal/vm/iseq/extconf.rb +1 -0
- data/ext/internal/vm/iseq/iseq.c +38 -4
- data/ext/internal/vm/iseq/iseq_load.inc.rpp +23 -5
- data/ext/internal/vm/vm.c +28 -0
- data/lib/internal/classtree.rb +28 -0
- data/lib/internal/debug.rb +10 -2
- data/lib/internal/method/as_code.rb +25 -0
- data/lib/internal/method/as_expression.rb +2 -3
- data/lib/internal/method/origin.rb +29 -0
- data/lib/internal/method/signature.rb +5 -300
- data/lib/internal/method/signature/argument.rb +102 -0
- data/lib/internal/method/signature/iseq.rb +52 -0
- data/lib/internal/method/signature/node.rb +160 -0
- data/lib/internal/method/signature/signature.rb +23 -0
- data/lib/internal/proc/as_code.rb +2 -0
- data/lib/internal/proc/as_expression.rb +2 -0
- data/lib/internal/vm/bytedecoder.rb +5 -5
- data/lib/internal/vm/iseq/as_code.rb +2 -2
- data/lib/internal/vm/iseq/as_expression.rb +2 -2
- data/test/test_dump_method.rb +1 -1
- data/test/test_method.rb +21 -3
- data/test/test_node.rb +20 -4
- metadata +152 -155
- data/ext/cached/ruby-1.6.8/internal/binding/block.h +0 -35
- data/ext/cached/ruby-1.6.8/internal/method/method.h +0 -19
- data/ext/cached/ruby-1.6.8/internal/module/classpath.c +0 -3
- data/ext/cached/ruby-1.6.8/internal/module/classpath.h +0 -8
- data/ext/cached/ruby-1.6.8/internal/node/block.h +0 -35
- data/ext/cached/ruby-1.6.8/internal/node/global_entry.h +0 -15
- data/ext/cached/ruby-1.6.8/internal/node/node_type_descrip.c +0 -149
- data/ext/cached/ruby-1.6.8/internal/node/nodeinfo.h +0 -69
- data/ext/cached/ruby-1.6.8/internal/proc/block.h +0 -35
- data/ext/cached/ruby-1.6.8/internal/tag/tag.h +0 -15
- data/ext/cached/ruby-1.6.8/internal/vm/instruction/insns_info.c +0 -39
- data/ext/cached/ruby-1.6.8/internal/vm/instruction/insns_info.h +0 -21
- data/ext/cached/ruby-1.6.8/internal/vm/iseq/insns_info.inc +0 -12
- data/ext/cached/ruby-1.6.8/internal/vm/iseq/iseq_load.inc +0 -9
- data/ext/cached/ruby-1.8.0/internal/binding/block.h +0 -37
- data/ext/cached/ruby-1.8.0/internal/method/method.h +0 -19
- data/ext/cached/ruby-1.8.0/internal/module/classpath.c +0 -27
- data/ext/cached/ruby-1.8.0/internal/node/block.h +0 -37
- data/ext/cached/ruby-1.8.0/internal/node/global_entry.h +0 -10
- data/ext/cached/ruby-1.8.0/internal/node/node_type_descrip.c +0 -155
- data/ext/cached/ruby-1.8.0/internal/node/nodeinfo.c +0 -5744
- data/ext/cached/ruby-1.8.0/internal/proc/block.h +0 -37
- data/ext/cached/ruby-1.8.0/internal/tag/tag.h +0 -15
- data/ext/cached/ruby-1.8.0/internal/vm/instruction/insns_info.c +0 -39
- data/ext/cached/ruby-1.8.0/internal/vm/instruction/insns_info.h +0 -21
- data/ext/cached/ruby-1.8.0/internal/vm/iseq/insns_info.inc +0 -12
- data/ext/cached/ruby-1.8.0/internal/vm/iseq/iseq_load.inc +0 -9
- data/ext/cached/ruby-1.8.1/internal/binding/block.h +0 -31
- data/ext/cached/ruby-1.8.1/internal/method/method.h +0 -19
- data/ext/cached/ruby-1.8.1/internal/module/classpath.c +0 -27
- data/ext/cached/ruby-1.8.1/internal/module/classpath.h +0 -14
- data/ext/cached/ruby-1.8.1/internal/node/block.h +0 -31
- data/ext/cached/ruby-1.8.1/internal/node/global_entry.h +0 -10
- data/ext/cached/ruby-1.8.1/internal/node/node_type_descrip.c +0 -154
- data/ext/cached/ruby-1.8.1/internal/node/nodeinfo.c +0 -5736
- data/ext/cached/ruby-1.8.1/internal/node/nodeinfo.h +0 -69
- data/ext/cached/ruby-1.8.1/internal/proc/block.h +0 -31
- data/ext/cached/ruby-1.8.1/internal/tag/tag.h +0 -16
- data/ext/cached/ruby-1.8.1/internal/vm/instruction/insns_info.c +0 -39
- data/ext/cached/ruby-1.8.1/internal/vm/instruction/insns_info.h +0 -21
- data/ext/cached/ruby-1.8.1/internal/vm/iseq/insns_info.inc +0 -12
- data/ext/cached/ruby-1.8.1/internal/vm/iseq/iseq_load.inc +0 -9
- data/ext/cached/ruby-1.8.2/internal/binding/block.h +0 -32
- data/ext/cached/ruby-1.8.2/internal/method/method.h +0 -19
- data/ext/cached/ruby-1.8.2/internal/module/classpath.c +0 -45
- data/ext/cached/ruby-1.8.2/internal/module/classpath.h +0 -17
- data/ext/cached/ruby-1.8.2/internal/node/block.h +0 -32
- data/ext/cached/ruby-1.8.2/internal/node/global_entry.h +0 -10
- data/ext/cached/ruby-1.8.2/internal/node/node_type_descrip.c +0 -154
- data/ext/cached/ruby-1.8.2/internal/node/nodeinfo.c +0 -5736
- data/ext/cached/ruby-1.8.2/internal/node/nodeinfo.h +0 -69
- data/ext/cached/ruby-1.8.2/internal/proc/block.h +0 -32
- data/ext/cached/ruby-1.8.2/internal/tag/tag.h +0 -16
- data/ext/cached/ruby-1.8.2/internal/vm/instruction/insns_info.c +0 -39
- data/ext/cached/ruby-1.8.2/internal/vm/instruction/insns_info.h +0 -21
- data/ext/cached/ruby-1.8.2/internal/vm/iseq/insns_info.inc +0 -12
- data/ext/cached/ruby-1.8.2/internal/vm/iseq/iseq_load.inc +0 -9
- data/ext/cached/ruby-1.8.3/internal/binding/block.h +0 -32
- data/ext/cached/ruby-1.8.3/internal/module/classpath.c +0 -45
- data/ext/cached/ruby-1.8.3/internal/module/classpath.h +0 -17
- data/ext/cached/ruby-1.8.3/internal/node/block.h +0 -32
- data/ext/cached/ruby-1.8.3/internal/node/global_entry.h +0 -10
- data/ext/cached/ruby-1.8.3/internal/node/nodeinfo.c +0 -5736
- data/ext/cached/ruby-1.8.3/internal/node/nodeinfo.h +0 -69
- data/ext/cached/ruby-1.8.3/internal/proc/block.h +0 -32
- data/ext/cached/ruby-1.8.3/internal/tag/tag.h +0 -16
- data/ext/cached/ruby-1.8.3/internal/vm/instruction/insns_info.c +0 -39
- data/ext/cached/ruby-1.8.3/internal/vm/instruction/insns_info.h +0 -21
- data/ext/cached/ruby-1.8.3/internal/vm/iseq/insns_info.inc +0 -12
- data/ext/cached/ruby-1.8.3/internal/vm/iseq/iseq_load.inc +0 -9
- data/ext/cached/ruby-1.8.7/internal/method/method.h +0 -20
- data/ext/cached/ruby-1.9.0/internal/module/classpath.c +0 -42
- data/ext/cached/ruby-1.9.0/internal/node/global_entry.h +0 -10
- data/ext/cached/ruby-1.9.0/internal/vm/iseq/iseq_load.inc +0 -13
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/id.h +0 -83
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/revision.h +0 -1
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/transdb.h +0 -67
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/version.h +0 -57
- data/ext/internal/module/cfp.h +0 -13
@@ -0,0 +1,102 @@
|
|
1
|
+
|
2
|
+
module MethodSig
|
3
|
+
class Argument
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
def required?
|
7
|
+
return !optional?
|
8
|
+
end
|
9
|
+
|
10
|
+
def optional?
|
11
|
+
return rest? || block?
|
12
|
+
end
|
13
|
+
|
14
|
+
def rest?
|
15
|
+
return @is_rest
|
16
|
+
end
|
17
|
+
|
18
|
+
def block?
|
19
|
+
return @is_block
|
20
|
+
end
|
21
|
+
|
22
|
+
def default
|
23
|
+
return nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(name, is_rest, is_block)
|
27
|
+
@name = name
|
28
|
+
@is_rest = is_rest
|
29
|
+
@is_block = is_block
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
if @is_rest then
|
34
|
+
prefix = "*"
|
35
|
+
elsif @is_block then
|
36
|
+
prefix = "&"
|
37
|
+
end
|
38
|
+
|
39
|
+
if self.default then
|
40
|
+
suffix = "=#{default()}"
|
41
|
+
end
|
42
|
+
|
43
|
+
return "#{prefix}#{@name}#{suffix}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class OptionalArgument < Argument
|
48
|
+
def optional?
|
49
|
+
return true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class NodeOptionalArgument < OptionalArgument
|
54
|
+
attr_reader :node_for_default
|
55
|
+
attr_reader :default
|
56
|
+
|
57
|
+
def initialize(name, default, node_for_default, is_rest, is_block)
|
58
|
+
super(name, is_rest, is_block)
|
59
|
+
@default = default
|
60
|
+
@node_for_default = node_for_default
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class YarvOptionalArgument < OptionalArgument
|
65
|
+
attr_reader :iseq
|
66
|
+
attr_reader :pc_start
|
67
|
+
attr_reader :local_idx
|
68
|
+
|
69
|
+
def initialize(name, iseq, pc_start, local_idx, is_rest, is_block)
|
70
|
+
super(name, is_rest, is_block)
|
71
|
+
@iseq = iseq
|
72
|
+
@pc_start = pc_start
|
73
|
+
@local_idx = local_idx
|
74
|
+
@default = nil
|
75
|
+
end
|
76
|
+
|
77
|
+
def inspect
|
78
|
+
default()
|
79
|
+
super
|
80
|
+
end
|
81
|
+
|
82
|
+
def default
|
83
|
+
return @default if @default
|
84
|
+
|
85
|
+
env = Internal::ByteDecoder::Environment.new(@iseq.local_table())
|
86
|
+
local_table_idx = local_table_idx()
|
87
|
+
@iseq.bytedecode(env, @pc_start) do |instr|
|
88
|
+
RubyVM::Instruction::SETLOCAL === instr &&
|
89
|
+
instr.operands[0] == local_table_idx
|
90
|
+
end
|
91
|
+
expressions = env.expressions + env.stack
|
92
|
+
|
93
|
+
@default = expressions[0].rhs.to_s
|
94
|
+
return @default
|
95
|
+
end
|
96
|
+
|
97
|
+
def local_table_idx
|
98
|
+
return @iseq.local_table.size - @local_idx + 1
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class RubyVM
|
2
|
+
# YARV 1.9.2 and later
|
3
|
+
class InstructionSequence
|
4
|
+
include MethodSig
|
5
|
+
|
6
|
+
def local_vars
|
7
|
+
local_vars = self.local_table
|
8
|
+
return local_vars
|
9
|
+
end
|
10
|
+
|
11
|
+
def argument_names
|
12
|
+
local_vars = self.local_vars
|
13
|
+
opt_args = self.arg_opt_table
|
14
|
+
opt_args.pop # last arg is a pointer to the start of the code
|
15
|
+
num_args = \
|
16
|
+
self.argc + \
|
17
|
+
opt_args.size + \
|
18
|
+
(rest_arg ? 1 : 0) + \
|
19
|
+
(block_arg ? 1 : 0)
|
20
|
+
return local_vars[0...num_args]
|
21
|
+
end
|
22
|
+
|
23
|
+
def args_node
|
24
|
+
return nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def rest_arg
|
28
|
+
arg_rest = self.arg_rest
|
29
|
+
return arg_rest >= 0 ? arg_rest : nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def block_arg
|
33
|
+
arg_block = self.arg_block
|
34
|
+
return arg_block >= 0 ? arg_block : nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_optional_args(args, args_node, names)
|
38
|
+
opt_table = self.arg_opt_table
|
39
|
+
opt_table.pop
|
40
|
+
first_opt_idx =
|
41
|
+
names.size -
|
42
|
+
opt_table.size -
|
43
|
+
(self.rest_arg ? 1 : 0) -
|
44
|
+
(self.block_arg ? 1 : 0)
|
45
|
+
opt_table.each_with_index do |pc, idx|
|
46
|
+
name = names[first_opt_idx + idx]
|
47
|
+
args[name] = YarvOptionalArgument.new(name, self, pc, idx, false, false)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,160 @@
|
|
1
|
+
class Node
|
2
|
+
# pre-YARV
|
3
|
+
class SCOPE
|
4
|
+
include MethodSig
|
5
|
+
|
6
|
+
def local_vars
|
7
|
+
return self.tbl || []
|
8
|
+
end
|
9
|
+
|
10
|
+
def argument_names
|
11
|
+
local_vars = self.local_vars
|
12
|
+
args = self.args_node
|
13
|
+
num_required_args = args.cnt
|
14
|
+
num_optional_args = 0
|
15
|
+
opt = args.opt
|
16
|
+
while opt do
|
17
|
+
num_optional_args += 1
|
18
|
+
opt = opt.next
|
19
|
+
end
|
20
|
+
num_args = \
|
21
|
+
num_required_args + \
|
22
|
+
num_optional_args + \
|
23
|
+
(rest_arg ? 1 : 0) + \
|
24
|
+
(block_arg ? 1 : 0)
|
25
|
+
return local_vars[0...num_args]
|
26
|
+
end
|
27
|
+
|
28
|
+
def args_node
|
29
|
+
if self.next.class == Node::ARGS then
|
30
|
+
return self.next
|
31
|
+
elsif self.next.head.class == Node::ARGS then
|
32
|
+
return self.next.head
|
33
|
+
else
|
34
|
+
raise "Could not find method arguments"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def rest_arg
|
39
|
+
args_node = args_node()
|
40
|
+
rest = args_node.rest()
|
41
|
+
if rest.class == Node::LASGN then
|
42
|
+
# subtract 2 to account for implicit vars
|
43
|
+
return rest.cnt - 2
|
44
|
+
elsif not rest
|
45
|
+
return nil
|
46
|
+
else
|
47
|
+
return rest > 0 ? rest - 2 : nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def block_arg
|
52
|
+
block = self.next
|
53
|
+
if block.class == Node::BLOCK and
|
54
|
+
block.next.head.class == Node::BLOCK_ARG then
|
55
|
+
# subtract 2 to account for implicit vars
|
56
|
+
return block.next.head.cnt - 2
|
57
|
+
else
|
58
|
+
return nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def set_optional_args(args, args_node, names)
|
63
|
+
opt = args_node.opt
|
64
|
+
while opt do
|
65
|
+
head = opt.head
|
66
|
+
if head.class == Node::LASGN then
|
67
|
+
args[head.vid] = NodeOptionalArgument.new(
|
68
|
+
head.vid, head.value.as_expression, head.value, false, false)
|
69
|
+
else
|
70
|
+
raise "Unexpected node type: #{opt.class}"
|
71
|
+
end
|
72
|
+
opt = opt.next
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Pre-YARV, I think
|
78
|
+
class BMETHOD
|
79
|
+
def local_vars
|
80
|
+
raise "TODO: Not implemented yet"
|
81
|
+
end
|
82
|
+
|
83
|
+
def argument_names
|
84
|
+
return self.cval.arguments.names
|
85
|
+
end
|
86
|
+
|
87
|
+
def arguments
|
88
|
+
return self.cval.arguments
|
89
|
+
end
|
90
|
+
|
91
|
+
def args_node
|
92
|
+
raise "TODO: Not implemented yet"
|
93
|
+
end
|
94
|
+
|
95
|
+
def rest_arg
|
96
|
+
raise "TODO: Not implemented yet"
|
97
|
+
end
|
98
|
+
|
99
|
+
def block_arg
|
100
|
+
raise "TODO: Not implemented yet"
|
101
|
+
end
|
102
|
+
|
103
|
+
def set_optional_args(args, args_node, names)
|
104
|
+
raise "TODO: Not implemented yet"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# YARV up to 1.9.1
|
109
|
+
class METHOD
|
110
|
+
include MethodSig
|
111
|
+
|
112
|
+
def local_vars
|
113
|
+
iseq = self.body
|
114
|
+
local_vars = iseq.local_table
|
115
|
+
return local_vars
|
116
|
+
end
|
117
|
+
|
118
|
+
def argument_names
|
119
|
+
local_vars = self.local_vars
|
120
|
+
iseq = self.body
|
121
|
+
opt_args = iseq.arg_opt_table
|
122
|
+
opt_args.pop # last arg is a pointer to the start of the code
|
123
|
+
num_args = \
|
124
|
+
iseq.argc + \
|
125
|
+
opt_args.size + \
|
126
|
+
(rest_arg ? 1 : 0) + \
|
127
|
+
(block_arg ? 1 : 0)
|
128
|
+
return local_vars[0...num_args]
|
129
|
+
end
|
130
|
+
|
131
|
+
def args_node
|
132
|
+
return nil
|
133
|
+
end
|
134
|
+
|
135
|
+
def rest_arg
|
136
|
+
arg_rest = self.body.arg_rest
|
137
|
+
return arg_rest >= 0 ? arg_rest : nil
|
138
|
+
end
|
139
|
+
|
140
|
+
def block_arg
|
141
|
+
arg_block = self.body.arg_block
|
142
|
+
return arg_block >= 0 ? arg_block : nil
|
143
|
+
end
|
144
|
+
|
145
|
+
def set_optional_args(args, args_node, names)
|
146
|
+
opt_table = self.body.arg_opt_table
|
147
|
+
opt_table.pop
|
148
|
+
first_opt_idx =
|
149
|
+
names.size -
|
150
|
+
opt_table.size -
|
151
|
+
(self.rest_arg ? 1 : 0) -
|
152
|
+
(self.block_arg ? 1 : 0)
|
153
|
+
opt_table.each_with_index do |pc, idx|
|
154
|
+
name = names[first_opt_idx + idx]
|
155
|
+
args[name] = YarvOptionalArgument.new(name, self.body, pc, idx, false, false)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MethodSig
|
2
|
+
# An abstraction for a method signature.
|
3
|
+
class Signature
|
4
|
+
attr_reader :origin_class, :name, :arg_names, :args
|
5
|
+
|
6
|
+
def initialize(origin_class, name, arg_names, args)
|
7
|
+
@origin_class = origin_class
|
8
|
+
@name = name
|
9
|
+
@arg_names = arg_names
|
10
|
+
@args = args
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
return "#{@origin_class}\##{@name}(#{param_list})"
|
15
|
+
end
|
16
|
+
|
17
|
+
def param_list
|
18
|
+
params = @arg_names.map{ |n| args[n].to_s }
|
19
|
+
return params.join(', ')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -3,6 +3,8 @@ require 'internal/proc'
|
|
3
3
|
require 'internal/proc/signature'
|
4
4
|
|
5
5
|
class Proc
|
6
|
+
# Return a string representation of a proc's definition/body,
|
7
|
+
# similarly to +Method#as_code+.
|
6
8
|
def as_code(indent=0)
|
7
9
|
sig = self.signature
|
8
10
|
body_expression = self.body ? self.body.as_code(indent+1) : nil
|
@@ -3,6 +3,8 @@ require 'internal/proc/signature'
|
|
3
3
|
require 'internal/proc'
|
4
4
|
|
5
5
|
class Proc
|
6
|
+
# Return a single-line string representation of a proc's
|
7
|
+
# definition/body, similarly to +Method#as_expression+.
|
6
8
|
def as_expression
|
7
9
|
sig = self.signature
|
8
10
|
body_expression = self.body ? self.body.as_expression : nil
|
@@ -3,7 +3,7 @@ require 'internal/vm/instruction'
|
|
3
3
|
require 'internal/vm/inline_cache'
|
4
4
|
require 'internal/vm/constants'
|
5
5
|
|
6
|
-
module
|
6
|
+
module Internal
|
7
7
|
|
8
8
|
# A module for decoding YARV bytecode.
|
9
9
|
#
|
@@ -13,7 +13,7 @@ module Nodewrap
|
|
13
13
|
# could use this as a base for building one.
|
14
14
|
#
|
15
15
|
# Example usage:
|
16
|
-
# env =
|
16
|
+
# env = Internal::ByteDecoder::Environment.new(is.local_table)
|
17
17
|
# is = RubyVM::InstructionSequence.new('1 + 1')
|
18
18
|
# is.bytedecode(env)
|
19
19
|
# env.expressions.each do |expr|
|
@@ -450,11 +450,11 @@ end
|
|
450
450
|
|
451
451
|
end # ByteDecoder
|
452
452
|
|
453
|
-
end #
|
453
|
+
end # Internal
|
454
454
|
|
455
455
|
class RubyVM
|
456
456
|
class Instruction
|
457
|
-
include
|
457
|
+
include Internal::ByteDecoder
|
458
458
|
|
459
459
|
class PUTOBJECT
|
460
460
|
def bytedecode(env)
|
@@ -839,7 +839,7 @@ if __FILE__ == $0 then
|
|
839
839
|
is = n.body
|
840
840
|
puts is.disasm
|
841
841
|
|
842
|
-
env =
|
842
|
+
env = Internal::ByteDecoder::Environment.new(is.local_table)
|
843
843
|
s = ''
|
844
844
|
# puts "local_table = #{is.local_table.inspect}"
|
845
845
|
is.each do |i|
|
@@ -6,14 +6,14 @@ if defined?(RubyVM::InstructionSequence) then
|
|
6
6
|
class RubyVM
|
7
7
|
class InstructionSequence
|
8
8
|
def as_code(indent=0)
|
9
|
-
env =
|
9
|
+
env = Internal::ByteDecoder::Environment.new(local_table())
|
10
10
|
opt_pc = self.opt_pc
|
11
11
|
self.bytedecode(env, opt_pc)
|
12
12
|
expressions = env.expressions + env.stack
|
13
13
|
if expressions.length == 0 then
|
14
14
|
return nil
|
15
15
|
elsif expressions.length == 1 and
|
16
|
-
expressions[0].is_a?(
|
16
|
+
expressions[0].is_a?(Internal::ByteDecoder::Expression::Literal) and
|
17
17
|
expressions[0].value == nil then
|
18
18
|
return nil
|
19
19
|
else
|
@@ -6,14 +6,14 @@ if defined?(RubyVM::InstructionSequence) then
|
|
6
6
|
class RubyVM
|
7
7
|
class InstructionSequence
|
8
8
|
def as_expression
|
9
|
-
env =
|
9
|
+
env = Internal::ByteDecoder::Environment.new(local_table())
|
10
10
|
opt_pc = self.opt_pc
|
11
11
|
self.bytedecode(env, opt_pc)
|
12
12
|
expressions = env.expressions + env.stack
|
13
13
|
if expressions.length == 0 then
|
14
14
|
return nil
|
15
15
|
elsif expressions.length == 1 and
|
16
|
-
expressions[0].is_a?(
|
16
|
+
expressions[0].is_a?(Internal::ByteDecoder::Expression::Literal) and
|
17
17
|
expressions[0].value == nil then
|
18
18
|
return nil
|
19
19
|
else
|