ruby-internal 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +59 -0
- data/LGPL +515 -0
- data/LICENSE +9 -0
- data/README +31 -0
- data/Rakefile +20 -0
- data/TODO +9 -0
- data/example/README +5 -0
- data/example/simple_client.rb +12 -0
- data/example/simple_server.rb +11 -0
- data/example/triangle_client.rb +7 -0
- data/example/triangle_server.rb +24 -0
- data/ext/cached/ruby-1.8.0/internal/binding/block.h +37 -0
- data/ext/cached/ruby-1.8.0/internal/method/method.h +19 -0
- data/ext/cached/ruby-1.8.0/internal/module/classpath.c +27 -0
- data/ext/cached/ruby-1.8.0/internal/module/classpath.h +14 -0
- data/ext/cached/ruby-1.8.0/internal/node/block.h +37 -0
- data/ext/cached/ruby-1.8.0/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.0/internal/node/node_type_descrip.c +155 -0
- data/ext/cached/ruby-1.8.0/internal/node/nodeinfo.c +5741 -0
- data/ext/cached/ruby-1.8.0/internal/node/nodeinfo.h +69 -0
- data/ext/cached/ruby-1.8.0/internal/proc/block.h +37 -0
- data/ext/cached/ruby-1.8.0/internal/tag/tag.h +15 -0
- data/ext/cached/ruby-1.8.0/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.0/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.0/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.8.1/internal/binding/block.h +31 -0
- data/ext/cached/ruby-1.8.1/internal/method/method.h +19 -0
- data/ext/cached/ruby-1.8.1/internal/module/classpath.c +27 -0
- data/ext/cached/ruby-1.8.1/internal/module/classpath.h +14 -0
- data/ext/cached/ruby-1.8.1/internal/node/block.h +31 -0
- data/ext/cached/ruby-1.8.1/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.1/internal/node/node_type_descrip.c +154 -0
- data/ext/cached/ruby-1.8.1/internal/node/nodeinfo.c +5733 -0
- data/ext/cached/ruby-1.8.1/internal/node/nodeinfo.h +69 -0
- data/ext/cached/ruby-1.8.1/internal/proc/block.h +31 -0
- data/ext/cached/ruby-1.8.1/internal/tag/tag.h +16 -0
- data/ext/cached/ruby-1.8.1/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.1/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.1/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.8.2/internal/binding/block.h +32 -0
- data/ext/cached/ruby-1.8.2/internal/method/method.h +19 -0
- data/ext/cached/ruby-1.8.2/internal/module/classpath.c +45 -0
- data/ext/cached/ruby-1.8.2/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.8.2/internal/node/block.h +32 -0
- data/ext/cached/ruby-1.8.2/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.2/internal/node/node_type_descrip.c +154 -0
- data/ext/cached/ruby-1.8.2/internal/node/nodeinfo.c +5733 -0
- data/ext/cached/ruby-1.8.2/internal/node/nodeinfo.h +69 -0
- data/ext/cached/ruby-1.8.2/internal/proc/block.h +32 -0
- data/ext/cached/ruby-1.8.2/internal/tag/tag.h +16 -0
- data/ext/cached/ruby-1.8.2/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.2/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.2/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.8.3/internal/binding/block.h +32 -0
- data/ext/cached/ruby-1.8.3/internal/method/method.h +20 -0
- data/ext/cached/ruby-1.8.3/internal/module/classpath.c +45 -0
- data/ext/cached/ruby-1.8.3/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.8.3/internal/node/block.h +32 -0
- data/ext/cached/ruby-1.8.3/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.3/internal/node/node_type_descrip.c +154 -0
- data/ext/cached/ruby-1.8.3/internal/node/nodeinfo.c +5733 -0
- data/ext/cached/ruby-1.8.3/internal/node/nodeinfo.h +69 -0
- data/ext/cached/ruby-1.8.3/internal/proc/block.h +32 -0
- data/ext/cached/ruby-1.8.3/internal/tag/tag.h +16 -0
- data/ext/cached/ruby-1.8.3/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.3/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.3/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.8.4/internal/binding/block.h +32 -0
- data/ext/cached/ruby-1.8.4/internal/method/method.h +20 -0
- data/ext/cached/ruby-1.8.4/internal/module/classpath.c +45 -0
- data/ext/cached/ruby-1.8.4/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.8.4/internal/node/block.h +32 -0
- data/ext/cached/ruby-1.8.4/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.4/internal/node/node_type_descrip.c +154 -0
- data/ext/cached/ruby-1.8.4/internal/node/nodeinfo.c +5733 -0
- data/ext/cached/ruby-1.8.4/internal/node/nodeinfo.h +69 -0
- data/ext/cached/ruby-1.8.4/internal/proc/block.h +32 -0
- data/ext/cached/ruby-1.8.4/internal/tag/tag.h +16 -0
- data/ext/cached/ruby-1.8.4/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.4/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.4/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.8.5/internal/binding/block.h +32 -0
- data/ext/cached/ruby-1.8.5/internal/method/method.h +20 -0
- data/ext/cached/ruby-1.8.5/internal/module/classpath.c +45 -0
- data/ext/cached/ruby-1.8.5/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.8.5/internal/node/block.h +32 -0
- data/ext/cached/ruby-1.8.5/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.5/internal/node/node_type_descrip.c +154 -0
- data/ext/cached/ruby-1.8.5/internal/node/nodeinfo.c +5732 -0
- data/ext/cached/ruby-1.8.5/internal/node/nodeinfo.h +67 -0
- data/ext/cached/ruby-1.8.5/internal/proc/block.h +32 -0
- data/ext/cached/ruby-1.8.5/internal/tag/tag.h +16 -0
- data/ext/cached/ruby-1.8.5/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.5/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.5/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.8.6/internal/binding/block.h +32 -0
- data/ext/cached/ruby-1.8.6/internal/method/method.h +20 -0
- data/ext/cached/ruby-1.8.6/internal/module/classpath.c +45 -0
- data/ext/cached/ruby-1.8.6/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.8.6/internal/node/block.h +32 -0
- data/ext/cached/ruby-1.8.6/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.6/internal/node/node_type_descrip.c +154 -0
- data/ext/cached/ruby-1.8.6/internal/node/nodeinfo.c +5732 -0
- data/ext/cached/ruby-1.8.6/internal/node/nodeinfo.h +67 -0
- data/ext/cached/ruby-1.8.6/internal/proc/block.h +32 -0
- data/ext/cached/ruby-1.8.6/internal/tag/tag.h +16 -0
- data/ext/cached/ruby-1.8.6/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.6/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.6/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.8.7/internal/binding/block.h +32 -0
- data/ext/cached/ruby-1.8.7/internal/method/method.h +20 -0
- data/ext/cached/ruby-1.8.7/internal/module/classpath.c +45 -0
- data/ext/cached/ruby-1.8.7/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.8.7/internal/node/block.h +32 -0
- data/ext/cached/ruby-1.8.7/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.8.7/internal/node/node_type_descrip.c +154 -0
- data/ext/cached/ruby-1.8.7/internal/node/nodeinfo.c +5732 -0
- data/ext/cached/ruby-1.8.7/internal/node/nodeinfo.h +67 -0
- data/ext/cached/ruby-1.8.7/internal/proc/block.h +32 -0
- data/ext/cached/ruby-1.8.7/internal/tag/tag.h +16 -0
- data/ext/cached/ruby-1.8.7/internal/vm/instruction/insns_info.c +39 -0
- data/ext/cached/ruby-1.8.7/internal/vm/instruction/insns_info.h +21 -0
- data/ext/cached/ruby-1.8.7/internal/vm/iseq/insns_info.inc +12 -0
- data/ext/cached/ruby-1.9.0/internal/binding/block.h +12 -0
- data/ext/cached/ruby-1.9.0/internal/method/method.h +20 -0
- data/ext/cached/ruby-1.9.0/internal/module/classpath.c +42 -0
- data/ext/cached/ruby-1.9.0/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.9.0/internal/node/block.h +12 -0
- data/ext/cached/ruby-1.9.0/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.9.0/internal/node/node_type_descrip.c +149 -0
- data/ext/cached/ruby-1.9.0/internal/node/nodeinfo.c +5579 -0
- data/ext/cached/ruby-1.9.0/internal/node/nodeinfo.h +70 -0
- data/ext/cached/ruby-1.9.0/internal/proc/block.h +12 -0
- data/ext/cached/ruby-1.9.0/internal/tag/tag.h +6 -0
- data/ext/cached/ruby-1.9.0/internal/vm/instruction/insns_info.c +5936 -0
- data/ext/cached/ruby-1.9.0/internal/vm/instruction/insns_info.h +891 -0
- data/ext/cached/ruby-1.9.0/internal/vm/iseq/insns_info.inc +700 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/debug.h +36 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/dln.h +41 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/encdb.h +147 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/eval_intern.h +221 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/gc.h +75 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/id.h +83 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/iseq.h +94 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/node.h +516 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/parse.h +303 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/regenc.h +207 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/regint.h +842 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/regparse.h +351 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/revision.h +1 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/thread_pthread.h +24 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/thread_win32.h +33 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/transcode_data.h +99 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/transdb.h +67 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/version.h +57 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/vm_core.h +663 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/vm_exec.h +187 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/vm_insnhelper.h +191 -0
- data/ext/cached/ruby-1.9.0/internal/yarv-headers/vm_opts.h +51 -0
- data/ext/cached/ruby-1.9.1/internal/binding/block.h +12 -0
- data/ext/cached/ruby-1.9.1/internal/method/method.h +20 -0
- data/ext/cached/ruby-1.9.1/internal/module/classpath.c +42 -0
- data/ext/cached/ruby-1.9.1/internal/module/classpath.h +17 -0
- data/ext/cached/ruby-1.9.1/internal/node/block.h +12 -0
- data/ext/cached/ruby-1.9.1/internal/node/global_entry.h +10 -0
- data/ext/cached/ruby-1.9.1/internal/node/node_type_descrip.c +149 -0
- data/ext/cached/ruby-1.9.1/internal/node/nodeinfo.c +5579 -0
- data/ext/cached/ruby-1.9.1/internal/node/nodeinfo.h +70 -0
- data/ext/cached/ruby-1.9.1/internal/proc/block.h +12 -0
- data/ext/cached/ruby-1.9.1/internal/tag/tag.h +6 -0
- data/ext/cached/ruby-1.9.1/internal/vm/instruction/insns_info.c +5936 -0
- data/ext/cached/ruby-1.9.1/internal/vm/instruction/insns_info.h +891 -0
- data/ext/cached/ruby-1.9.1/internal/vm/iseq/insns_info.inc +700 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/debug.h +36 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/dln.h +41 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/encdb.h +147 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/eval_intern.h +209 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/gc.h +75 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/id.h +184 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/iseq.h +94 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/node.h +516 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/parse.h +303 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/regenc.h +207 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/regint.h +842 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/regparse.h +351 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/revision.h +1 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/thread_pthread.h +24 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/thread_win32.h +33 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/transcode_data.h +99 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/transdb.h +85 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/version.h +60 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/vm_core.h +655 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/vm_exec.h +187 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/vm_insnhelper.h +194 -0
- data/ext/cached/ruby-1.9.1/internal/yarv-headers/vm_opts.h +51 -0
- data/ext/internal/binding/binding.c +45 -0
- data/ext/internal/binding/block.h.rpp +44 -0
- data/ext/internal/binding/extconf.rb +6 -0
- data/ext/internal/method/extconf.rb +8 -0
- data/ext/internal/method/method.c +269 -0
- data/ext/internal/method/method.h.rpp +58 -0
- data/ext/internal/module/classpath.c.rpp +29 -0
- data/ext/internal/module/classpath.h.rpp +36 -0
- data/ext/internal/module/extconf.rb +11 -0
- data/ext/internal/module/module.c +797 -0
- data/ext/internal/module/module.h +7 -0
- data/ext/internal/node/block.h.rpp +44 -0
- data/ext/internal/node/builtins.h +41 -0
- data/ext/internal/node/extconf.rb +66 -0
- data/ext/internal/node/global_entry.h.rpp +26 -0
- data/ext/internal/node/node.c +1147 -0
- data/ext/internal/node/node_type_descrip.c.rpp +72 -0
- data/ext/internal/node/node_type_descrip.h +17 -0
- data/ext/internal/node/node_type_descrip.rb +39 -0
- data/ext/internal/node/nodeinfo.c.rpp +587 -0
- data/ext/internal/node/nodeinfo.h.rpp +30 -0
- data/ext/internal/node/nodes.rb +78 -0
- data/ext/internal/node/read_node_h.rb +34 -0
- data/ext/internal/node/ruby_internal_node.h +31 -0
- data/ext/internal/noex/extconf.rb +6 -0
- data/ext/internal/noex/noex.c +44 -0
- data/ext/internal/object/extconf.rb +4 -0
- data/ext/internal/object/object.c +75 -0
- data/ext/internal/proc/block.h.rpp +44 -0
- data/ext/internal/proc/extconf.rb +9 -0
- data/ext/internal/proc/proc.c +331 -0
- data/ext/internal/tag/extconf.rb +3 -0
- data/ext/internal/tag/tag.c +17 -0
- data/ext/internal/tag/tag.h.rpp +22 -0
- data/ext/internal/thread/extconf.rb +3 -0
- data/ext/internal/thread/thread.c +107 -0
- data/ext/internal/vm/constants/constants.c +33 -0
- data/ext/internal/vm/constants/extconf.rb +3 -0
- data/ext/internal/vm/control_frame/control_frame.c +185 -0
- data/ext/internal/vm/control_frame/control_frame.h +18 -0
- data/ext/internal/vm/control_frame/extconf.rb +3 -0
- data/ext/internal/vm/extconf.rb +3 -0
- data/ext/internal/vm/inline_cache/extconf.rb +6 -0
- data/ext/internal/vm/inline_cache/inline_cache.c +79 -0
- data/ext/internal/vm/instruction/extconf.rb +6 -0
- data/ext/internal/vm/instruction/insns_info.c.rpp +213 -0
- data/ext/internal/vm/instruction/insns_info.h.rpp +53 -0
- data/ext/internal/vm/instruction/instruction.c +78 -0
- data/ext/internal/vm/instruction/instruction.h +10 -0
- data/ext/internal/vm/iseq/extconf.rb +7 -0
- data/ext/internal/vm/iseq/insns_info.inc.rpp +30 -0
- data/ext/internal/vm/iseq/internal_iseq.h +9 -0
- data/ext/internal/vm/iseq/iseq.c +555 -0
- data/ext/internal/vm/vm.c +55 -0
- data/ext/mkmf-ruby-internal.rb +111 -0
- data/ext/ruby_source_dir.rb +24 -0
- data/ext/rubypp.rb +97 -0
- data/generate_rdoc.rb +33 -0
- data/lib/internal/binding.rb +1 -0
- data/lib/internal/classtree.rb +55 -0
- data/lib/internal/debug.rb +16 -0
- data/lib/internal/method.rb +1 -0
- data/lib/internal/method/as_code.rb +33 -0
- data/lib/internal/method/as_expression.rb +34 -0
- data/lib/internal/method/signature.rb +442 -0
- data/lib/internal/module.rb +1 -0
- data/lib/internal/module/as_code.rb +45 -0
- data/lib/internal/node.rb +3 -0
- data/lib/internal/node/as_code.rb +233 -0
- data/lib/internal/node/as_expression.rb +619 -0
- data/lib/internal/node/dump.rb +53 -0
- data/lib/internal/node/pp.rb +72 -0
- data/lib/internal/node/to_a.rb +52 -0
- data/lib/internal/noex.rb +1 -0
- data/lib/internal/obfusc.rb +57 -0
- data/lib/internal/object.rb +1 -0
- data/lib/internal/object/as_code.rb +10 -0
- data/lib/internal/proc.rb +1 -0
- data/lib/internal/proc/as_code.rb +21 -0
- data/lib/internal/proc/as_expression.rb +14 -0
- data/lib/internal/proc/signature.rb +184 -0
- data/lib/internal/tag.rb +1 -0
- data/lib/internal/thread.rb +1 -0
- data/lib/internal/vm.rb +1 -0
- data/lib/internal/vm/bytedecoder.rb +866 -0
- data/lib/internal/vm/constants.rb +1 -0
- data/lib/internal/vm/control_frame.rb +1 -0
- data/lib/internal/vm/inline_cache.rb +1 -0
- data/lib/internal/vm/instruction.rb +1 -0
- data/lib/internal/vm/iseq.rb +1 -0
- data/lib/internal/vm/iseq/as_code.rb +27 -0
- data/lib/internal/vm/iseq/as_expression.rb +26 -0
- data/metaconfig +19 -0
- data/post-config.rb +1 -0
- data/post-install.rb +4 -0
- data/post-setup.rb +7 -0
- data/pre-config.rb +96 -0
- data/pre-install.rb +13 -0
- data/pre-setup.rb +8 -0
- data/run_tests.rb +26 -0
- data/setup.rb +1599 -0
- data/test/expression_samples.rb +160 -0
- data/test/node_samples.rb +122 -0
- data/test/test_as_code.rb +261 -0
- data/test/test_as_expression.rb +229 -0
- data/test/test_dump_class.rb +187 -0
- data/test/test_dump_method.rb +144 -0
- data/test/test_dump_proc.rb +118 -0
- data/test/test_helpers.rb +61 -0
- data/test/test_method.rb +72 -0
- data/test/test_methodsig.rb +267 -0
- data/test/test_module.rb +49 -0
- data/test/test_node.rb +77 -0
- data/test/test_proc.rb +47 -0
- metadata +377 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
# This is a script similar to the Pragmatic Programmers' NodeDump.so.
|
2
|
+
# You can use it similarly, e.g.:
|
3
|
+
#
|
4
|
+
# $ cat test.rb
|
5
|
+
# def foo
|
6
|
+
# 1+1
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
# $ ruby -rinternal/node/dump test.rb
|
10
|
+
# NODE_NEWLINE at test.rb:1
|
11
|
+
# |-nth = 1
|
12
|
+
# +-next = NODE_DEFN at test.rb:1
|
13
|
+
# |-defn = NODE_SCOPE at test.rb:3
|
14
|
+
# | |-rval = false
|
15
|
+
# | |-tbl = nil
|
16
|
+
# | +-next = NODE_BLOCK at test.rb:1
|
17
|
+
# | |-next = NODE_BLOCK at test.rb:3
|
18
|
+
# | | |-next = false
|
19
|
+
# | | +-head = NODE_NEWLINE at test.rb:2
|
20
|
+
# | | |-nth = 2
|
21
|
+
# | | +-next = NODE_CALL at test.rb:2
|
22
|
+
# | | |-recv = NODE_LIT at test.rb:2
|
23
|
+
# | | | +-lit = 1
|
24
|
+
# | | |-args = NODE_ARRAY at test.rb:2
|
25
|
+
# | | | |-alen = 1
|
26
|
+
# | | | |-head = NODE_LIT at test.rb:2
|
27
|
+
# | | | | +-lit = 1
|
28
|
+
# | | | +-next = false
|
29
|
+
# | | +-mid = :+
|
30
|
+
# | +-head = NODE_ARGS at test.rb:1
|
31
|
+
# | |-cnt = 0
|
32
|
+
# | |-rest = -1
|
33
|
+
# | +-opt = false
|
34
|
+
# |-mid = :foo
|
35
|
+
# +-noex = PRIVATE
|
36
|
+
|
37
|
+
require 'internal/node/pp'
|
38
|
+
|
39
|
+
set_trace_func proc {
|
40
|
+
begin
|
41
|
+
n = $ruby_eval_tree
|
42
|
+
if defined?($ruby_eval_tree_begin) and $ruby_eval_tree_begin then
|
43
|
+
pp $ruby_eval_tree_begin, $stderr
|
44
|
+
end
|
45
|
+
if n then
|
46
|
+
PP.pp n, $stderr
|
47
|
+
exit!
|
48
|
+
end
|
49
|
+
rescue Exception
|
50
|
+
p $!, $!.backtrace
|
51
|
+
end
|
52
|
+
}
|
53
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Require this file to get a node pretty-printer.
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'internal/node'
|
5
|
+
require 'internal/vm'
|
6
|
+
require 'pp'
|
7
|
+
|
8
|
+
module Noex
|
9
|
+
# Return a string representing the given integer as a noex value.
|
10
|
+
#
|
11
|
+
def stringify(noex)
|
12
|
+
Noex.constants.each do |constant|
|
13
|
+
return constant.to_s if const_get(constant) == noex
|
14
|
+
end
|
15
|
+
return noex.to_s
|
16
|
+
end
|
17
|
+
module_function :stringify
|
18
|
+
end
|
19
|
+
|
20
|
+
class Node
|
21
|
+
# Return a string containing an ascii-art tree of the node's
|
22
|
+
# structure.
|
23
|
+
#
|
24
|
+
def tree(s = '', prefix = '')
|
25
|
+
s << "NODE_#{self.nd_type.to_s} at #{self.nd_file}:#{self.nd_line}\n"
|
26
|
+
self.members.each_with_index do |member, idx|
|
27
|
+
last = (idx == self.members.size-1)
|
28
|
+
s << "#{prefix}#{(last ? '+-' : '|-')}#{member} = "
|
29
|
+
value = self[member]
|
30
|
+
if Node === value then
|
31
|
+
value.tree(s, prefix + (last ? ' ' : '| '))
|
32
|
+
elsif defined?(RubyVM) and
|
33
|
+
defined?(RubyVM::InstructionSequence) and
|
34
|
+
RubyVM::InstructionSequence === value then
|
35
|
+
s << "<ISeq:#{value.self.name}@#{value.self.filename}>\n"
|
36
|
+
d = value.disasm
|
37
|
+
lines = d.split("\n")
|
38
|
+
lines.each_with_index do |line, line_idx|
|
39
|
+
if line =~ /^== disasm: (.*?)=/ then line = $1; end
|
40
|
+
if line =~ /(.*)\s+\(\s*\d+\)/ then line = $1; end
|
41
|
+
next if line =~ /^\|-----/
|
42
|
+
last_line = (line_idx == lines.size-1)
|
43
|
+
s << "#{prefix}#{last ? ' ' : '| '}#{(last_line ? '+-' : '|-')}#{line}\n"
|
44
|
+
end
|
45
|
+
# p value.local_table
|
46
|
+
elsif member == 'noex' then
|
47
|
+
s << Noex.stringify(value) + "\n"
|
48
|
+
else
|
49
|
+
s << value.inspect + "\n"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
return s
|
53
|
+
end
|
54
|
+
|
55
|
+
# Pretty-print node using Node#tree onto s, which can be a String or
|
56
|
+
# IO.
|
57
|
+
#
|
58
|
+
def pretty_print(pp)
|
59
|
+
pp.text(tree())
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
if __FILE__ == $0 then
|
64
|
+
def foo # :nodoc:
|
65
|
+
1 + 1
|
66
|
+
end
|
67
|
+
|
68
|
+
m = method(:foo)
|
69
|
+
n = m.body
|
70
|
+
puts n.pretty_print
|
71
|
+
end
|
72
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class Node
|
2
|
+
|
3
|
+
class ARRAY < Node
|
4
|
+
def to_a
|
5
|
+
a = []
|
6
|
+
e = self
|
7
|
+
while e do
|
8
|
+
a << e.head
|
9
|
+
e = e.next
|
10
|
+
end
|
11
|
+
a
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ZARRAY < Node
|
16
|
+
def to_a
|
17
|
+
[]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class BLOCK < Node
|
22
|
+
def to_a
|
23
|
+
a = []
|
24
|
+
e = self
|
25
|
+
while e do
|
26
|
+
a << e.head
|
27
|
+
e = e.next
|
28
|
+
end
|
29
|
+
a
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class LIT < Node
|
34
|
+
def to_a
|
35
|
+
return [ self ]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
if defined?(TO_ARY) then
|
40
|
+
class TO_ARY < Node
|
41
|
+
def to_a
|
42
|
+
return [ self.head ]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_a
|
48
|
+
raise NotImplementedError, "#to_a not defined for #{self.class}"
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'internal/noex/noex'
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# A code obfuscator for Ruby. It works by getting a dump of the node
|
2
|
+
# tree, then wrapping it with a lightweight loader.
|
3
|
+
#
|
4
|
+
# NOTE: This code is for demonstration purposes only! It has not been
|
5
|
+
# extensively tested, and I cannot guarantee that it works in all cases
|
6
|
+
# (I don't even know what the corner cases are). If you wish to use
|
7
|
+
# this in a commercial product, please verify that the code is correctly
|
8
|
+
# loaded.
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
#
|
12
|
+
# $ cat test.rb
|
13
|
+
# def foo
|
14
|
+
# 1+1
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# puts foo()
|
18
|
+
#
|
19
|
+
# $ ruby -rinternal/obfusc test.rb > test2.rb
|
20
|
+
# $ ruby test2.rb
|
21
|
+
# 2
|
22
|
+
|
23
|
+
require 'internal/node'
|
24
|
+
|
25
|
+
def obfusc(begin_nodes, n)
|
26
|
+
# The outputted code must do the following:
|
27
|
+
# 1. Evaluate each of the begin nodes (BEGIN {...}).
|
28
|
+
# 2. Evaluate the main node.
|
29
|
+
puts <<-END
|
30
|
+
require 'internal/node'
|
31
|
+
if RUBY_VERSION != "#{RUBY_VERSION}" then
|
32
|
+
$stderr.puts "Wrong Ruby version; please use #{RUBY_VERSION}"
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
begin_nodes = Marshal.load(#{Marshal.dump(begin_nodes).inspect})
|
36
|
+
n = Marshal.load(#{Marshal.dump(n).inspect})
|
37
|
+
begin_nodes.each do |node|
|
38
|
+
node.eval(self)
|
39
|
+
end
|
40
|
+
n.eval(self)
|
41
|
+
END
|
42
|
+
end
|
43
|
+
|
44
|
+
begin_nodes = []
|
45
|
+
set_trace_func proc {
|
46
|
+
n = $ruby_eval_tree
|
47
|
+
if defined?($ruby_eval_tree_begin) and $ruby_eval_tree_begin then
|
48
|
+
n.pretty_print($stderr)
|
49
|
+
begin_nodes << $ruby_eval_tree_begin
|
50
|
+
end
|
51
|
+
if n then
|
52
|
+
# TODO: Do I need to include ruby_dyna_vars?
|
53
|
+
obfusc(begin_nodes, n)
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
}
|
57
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'internal/object/object'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'internal/proc/proc'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'internal/node/as_code'
|
2
|
+
require 'internal/proc'
|
3
|
+
require 'internal/proc/signature'
|
4
|
+
|
5
|
+
class Proc
|
6
|
+
def as_code(indent=0)
|
7
|
+
sig = self.signature
|
8
|
+
body_expression = self.body ? self.body.as_code(indent+1) : nil
|
9
|
+
s = "#{' '*indent}proc do"
|
10
|
+
if not sig.args.unspecified then
|
11
|
+
s += " #{sig}"
|
12
|
+
end
|
13
|
+
s += "\n"
|
14
|
+
if body_expression then
|
15
|
+
s += "#{body_expression}\n"
|
16
|
+
end
|
17
|
+
s += "#{' '*indent}end"
|
18
|
+
return s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'internal/node/as_expression'
|
2
|
+
require 'internal/proc/signature'
|
3
|
+
require 'internal/proc'
|
4
|
+
|
5
|
+
class Proc
|
6
|
+
def as_expression
|
7
|
+
sig = self.signature
|
8
|
+
body_expression = self.body ? self.body.as_expression : nil
|
9
|
+
s = sig.args.unspecified ? "" : sig.to_s + ' '
|
10
|
+
b = body_expression ? body_expression + ' ' : ''
|
11
|
+
return "proc { #{s}#{b}}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'internal/node'
|
2
|
+
require 'internal/proc'
|
3
|
+
require 'internal/vm'
|
4
|
+
|
5
|
+
class Proc
|
6
|
+
class Arguments
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
def initialize(names, multiple_assignment, rest_arg)
|
10
|
+
@names = names
|
11
|
+
@multiple_assignment = multiple_assignment
|
12
|
+
@rest_arg = rest_arg
|
13
|
+
end
|
14
|
+
|
15
|
+
def unspecified
|
16
|
+
if defined?(RubyVM) and defined?(RubyVM::InstructionSequence) then
|
17
|
+
# YARV
|
18
|
+
return @names.length == 0
|
19
|
+
else
|
20
|
+
# pre-YARV
|
21
|
+
@names.nil?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def single_assignment
|
26
|
+
!@multiple_assignment
|
27
|
+
end
|
28
|
+
|
29
|
+
def multiple_assignment
|
30
|
+
@multiple_assignment
|
31
|
+
end
|
32
|
+
|
33
|
+
def names
|
34
|
+
@names
|
35
|
+
end
|
36
|
+
|
37
|
+
def [](idx)
|
38
|
+
@names[idx]
|
39
|
+
end
|
40
|
+
|
41
|
+
def each(&block)
|
42
|
+
(@names || []).each(&block)
|
43
|
+
end
|
44
|
+
|
45
|
+
def size
|
46
|
+
@names.size
|
47
|
+
end
|
48
|
+
|
49
|
+
def rest_arg
|
50
|
+
@rest_arg
|
51
|
+
end
|
52
|
+
|
53
|
+
def empty_last_arg
|
54
|
+
if defined?(VM) and defined?(VM::InstructionSequence) then
|
55
|
+
# YARV
|
56
|
+
return (@rest_arg and @names[-1] == nil)
|
57
|
+
else
|
58
|
+
# pre-YARV
|
59
|
+
return (@names.size == 1 and not @rest_arg)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Return an Arguments object representing the arguments in the order
|
65
|
+
# in which they appear in the argument list.
|
66
|
+
def arguments
|
67
|
+
has_rest_arg = self.has_rest_arg
|
68
|
+
|
69
|
+
if self.respond_to?(:var) then
|
70
|
+
# pre-YARV
|
71
|
+
case self.var
|
72
|
+
when Node::DASGN_CURR
|
73
|
+
return Arguments.new([ self.var.vid ], false, has_rest_arg ? 0 : nil)
|
74
|
+
when Node::MASGN
|
75
|
+
if self.var.head then
|
76
|
+
a = self.var.head.to_a
|
77
|
+
args = a.map { |n| n.vid }
|
78
|
+
else
|
79
|
+
args = []
|
80
|
+
end
|
81
|
+
if self.var.args then
|
82
|
+
args.push(self.var.args.vid)
|
83
|
+
end
|
84
|
+
return Arguments.new(args, true, has_rest_arg ? args.size - 1: nil)
|
85
|
+
when nil
|
86
|
+
return Arguments.new(nil, false, has_rest_arg ? 0 : nil)
|
87
|
+
when Fixnum
|
88
|
+
return Arguments.new([], false, has_rest_arg ? 0 : nil)
|
89
|
+
else
|
90
|
+
raise "Unexpected node type: #{self.var.class}"
|
91
|
+
end
|
92
|
+
elsif
|
93
|
+
# YARV
|
94
|
+
iseq = self.body
|
95
|
+
local_vars = iseq.local_table
|
96
|
+
has_rest_arg = iseq.arg_rest != -1
|
97
|
+
has_block_arg = iseq.arg_block != -1
|
98
|
+
num_args = \
|
99
|
+
iseq.argc + \
|
100
|
+
iseq.arg_opt_table.size + \
|
101
|
+
(has_rest_arg ? 1 : 0) + \
|
102
|
+
(has_block_arg ? 1 : 0)
|
103
|
+
names = local_vars[0...num_args]
|
104
|
+
# TODO: masgn
|
105
|
+
return Arguments.new(names, true, has_rest_arg ? -1 : nil)
|
106
|
+
else
|
107
|
+
return Arguments.new(nil, false, nil)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Return true if the proc has a rest arg
|
112
|
+
def has_rest_arg
|
113
|
+
if self.respond_to?(:var) then
|
114
|
+
# pre-YARV
|
115
|
+
has_rest_arg = false
|
116
|
+
if self.var then
|
117
|
+
if self.var.class == Node::MASGN then
|
118
|
+
if self.var.args then
|
119
|
+
has_rest_arg = true
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
else
|
124
|
+
# YARV
|
125
|
+
rest = self.body.arg_rest
|
126
|
+
has_rest_arg = (rest >= 0 ? rest - 1 : nil)
|
127
|
+
end
|
128
|
+
return has_rest_arg
|
129
|
+
end
|
130
|
+
|
131
|
+
# Return a hash mapping each argument name to a description of that
|
132
|
+
# argument.
|
133
|
+
def argument_info
|
134
|
+
args = self.arguments()
|
135
|
+
|
136
|
+
info = {}
|
137
|
+
args.each do |name|
|
138
|
+
info[name] = name.to_s
|
139
|
+
end
|
140
|
+
|
141
|
+
# Rest arg
|
142
|
+
if args.rest_arg then
|
143
|
+
rest_name = args[args.rest_arg]
|
144
|
+
if rest_name then
|
145
|
+
info[rest_name] = "*#{rest_name}"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
return info
|
150
|
+
end
|
151
|
+
|
152
|
+
class Signature
|
153
|
+
attr_reader :args, :arg_info
|
154
|
+
|
155
|
+
def initialize(args, arg_info)
|
156
|
+
@args = args
|
157
|
+
@arg_info = arg_info
|
158
|
+
end
|
159
|
+
|
160
|
+
def to_s
|
161
|
+
if @args.unspecified then
|
162
|
+
return ""
|
163
|
+
elsif @args.multiple_assignment then
|
164
|
+
if @args.empty_last_arg then
|
165
|
+
params = @args.map{ |n| arg_info[n] }
|
166
|
+
return "|#{@arg_info[@args[0]]},|"
|
167
|
+
else
|
168
|
+
params = @args.map{ |n| arg_info[n] }
|
169
|
+
return "|#{params.join(', ')}|"
|
170
|
+
end
|
171
|
+
else
|
172
|
+
return "|#{@arg_info[@args[0]]}|"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# Return a String representing the method's signature.
|
178
|
+
def signature
|
179
|
+
return Signature.new(
|
180
|
+
arguments(),
|
181
|
+
argument_info)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|