ruby-internal 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (310) hide show
  1. data/COPYING +59 -0
  2. data/LGPL +515 -0
  3. data/LICENSE +9 -0
  4. data/README +31 -0
  5. data/Rakefile +20 -0
  6. data/TODO +9 -0
  7. data/example/README +5 -0
  8. data/example/simple_client.rb +12 -0
  9. data/example/simple_server.rb +11 -0
  10. data/example/triangle_client.rb +7 -0
  11. data/example/triangle_server.rb +24 -0
  12. data/ext/cached/ruby-1.8.0/internal/binding/block.h +37 -0
  13. data/ext/cached/ruby-1.8.0/internal/method/method.h +19 -0
  14. data/ext/cached/ruby-1.8.0/internal/module/classpath.c +27 -0
  15. data/ext/cached/ruby-1.8.0/internal/module/classpath.h +14 -0
  16. data/ext/cached/ruby-1.8.0/internal/node/block.h +37 -0
  17. data/ext/cached/ruby-1.8.0/internal/node/global_entry.h +10 -0
  18. data/ext/cached/ruby-1.8.0/internal/node/node_type_descrip.c +155 -0
  19. data/ext/cached/ruby-1.8.0/internal/node/nodeinfo.c +5741 -0
  20. data/ext/cached/ruby-1.8.0/internal/node/nodeinfo.h +69 -0
  21. data/ext/cached/ruby-1.8.0/internal/proc/block.h +37 -0
  22. data/ext/cached/ruby-1.8.0/internal/tag/tag.h +15 -0
  23. data/ext/cached/ruby-1.8.0/internal/vm/instruction/insns_info.c +39 -0
  24. data/ext/cached/ruby-1.8.0/internal/vm/instruction/insns_info.h +21 -0
  25. data/ext/cached/ruby-1.8.0/internal/vm/iseq/insns_info.inc +12 -0
  26. data/ext/cached/ruby-1.8.1/internal/binding/block.h +31 -0
  27. data/ext/cached/ruby-1.8.1/internal/method/method.h +19 -0
  28. data/ext/cached/ruby-1.8.1/internal/module/classpath.c +27 -0
  29. data/ext/cached/ruby-1.8.1/internal/module/classpath.h +14 -0
  30. data/ext/cached/ruby-1.8.1/internal/node/block.h +31 -0
  31. data/ext/cached/ruby-1.8.1/internal/node/global_entry.h +10 -0
  32. data/ext/cached/ruby-1.8.1/internal/node/node_type_descrip.c +154 -0
  33. data/ext/cached/ruby-1.8.1/internal/node/nodeinfo.c +5733 -0
  34. data/ext/cached/ruby-1.8.1/internal/node/nodeinfo.h +69 -0
  35. data/ext/cached/ruby-1.8.1/internal/proc/block.h +31 -0
  36. data/ext/cached/ruby-1.8.1/internal/tag/tag.h +16 -0
  37. data/ext/cached/ruby-1.8.1/internal/vm/instruction/insns_info.c +39 -0
  38. data/ext/cached/ruby-1.8.1/internal/vm/instruction/insns_info.h +21 -0
  39. data/ext/cached/ruby-1.8.1/internal/vm/iseq/insns_info.inc +12 -0
  40. data/ext/cached/ruby-1.8.2/internal/binding/block.h +32 -0
  41. data/ext/cached/ruby-1.8.2/internal/method/method.h +19 -0
  42. data/ext/cached/ruby-1.8.2/internal/module/classpath.c +45 -0
  43. data/ext/cached/ruby-1.8.2/internal/module/classpath.h +17 -0
  44. data/ext/cached/ruby-1.8.2/internal/node/block.h +32 -0
  45. data/ext/cached/ruby-1.8.2/internal/node/global_entry.h +10 -0
  46. data/ext/cached/ruby-1.8.2/internal/node/node_type_descrip.c +154 -0
  47. data/ext/cached/ruby-1.8.2/internal/node/nodeinfo.c +5733 -0
  48. data/ext/cached/ruby-1.8.2/internal/node/nodeinfo.h +69 -0
  49. data/ext/cached/ruby-1.8.2/internal/proc/block.h +32 -0
  50. data/ext/cached/ruby-1.8.2/internal/tag/tag.h +16 -0
  51. data/ext/cached/ruby-1.8.2/internal/vm/instruction/insns_info.c +39 -0
  52. data/ext/cached/ruby-1.8.2/internal/vm/instruction/insns_info.h +21 -0
  53. data/ext/cached/ruby-1.8.2/internal/vm/iseq/insns_info.inc +12 -0
  54. data/ext/cached/ruby-1.8.3/internal/binding/block.h +32 -0
  55. data/ext/cached/ruby-1.8.3/internal/method/method.h +20 -0
  56. data/ext/cached/ruby-1.8.3/internal/module/classpath.c +45 -0
  57. data/ext/cached/ruby-1.8.3/internal/module/classpath.h +17 -0
  58. data/ext/cached/ruby-1.8.3/internal/node/block.h +32 -0
  59. data/ext/cached/ruby-1.8.3/internal/node/global_entry.h +10 -0
  60. data/ext/cached/ruby-1.8.3/internal/node/node_type_descrip.c +154 -0
  61. data/ext/cached/ruby-1.8.3/internal/node/nodeinfo.c +5733 -0
  62. data/ext/cached/ruby-1.8.3/internal/node/nodeinfo.h +69 -0
  63. data/ext/cached/ruby-1.8.3/internal/proc/block.h +32 -0
  64. data/ext/cached/ruby-1.8.3/internal/tag/tag.h +16 -0
  65. data/ext/cached/ruby-1.8.3/internal/vm/instruction/insns_info.c +39 -0
  66. data/ext/cached/ruby-1.8.3/internal/vm/instruction/insns_info.h +21 -0
  67. data/ext/cached/ruby-1.8.3/internal/vm/iseq/insns_info.inc +12 -0
  68. data/ext/cached/ruby-1.8.4/internal/binding/block.h +32 -0
  69. data/ext/cached/ruby-1.8.4/internal/method/method.h +20 -0
  70. data/ext/cached/ruby-1.8.4/internal/module/classpath.c +45 -0
  71. data/ext/cached/ruby-1.8.4/internal/module/classpath.h +17 -0
  72. data/ext/cached/ruby-1.8.4/internal/node/block.h +32 -0
  73. data/ext/cached/ruby-1.8.4/internal/node/global_entry.h +10 -0
  74. data/ext/cached/ruby-1.8.4/internal/node/node_type_descrip.c +154 -0
  75. data/ext/cached/ruby-1.8.4/internal/node/nodeinfo.c +5733 -0
  76. data/ext/cached/ruby-1.8.4/internal/node/nodeinfo.h +69 -0
  77. data/ext/cached/ruby-1.8.4/internal/proc/block.h +32 -0
  78. data/ext/cached/ruby-1.8.4/internal/tag/tag.h +16 -0
  79. data/ext/cached/ruby-1.8.4/internal/vm/instruction/insns_info.c +39 -0
  80. data/ext/cached/ruby-1.8.4/internal/vm/instruction/insns_info.h +21 -0
  81. data/ext/cached/ruby-1.8.4/internal/vm/iseq/insns_info.inc +12 -0
  82. data/ext/cached/ruby-1.8.5/internal/binding/block.h +32 -0
  83. data/ext/cached/ruby-1.8.5/internal/method/method.h +20 -0
  84. data/ext/cached/ruby-1.8.5/internal/module/classpath.c +45 -0
  85. data/ext/cached/ruby-1.8.5/internal/module/classpath.h +17 -0
  86. data/ext/cached/ruby-1.8.5/internal/node/block.h +32 -0
  87. data/ext/cached/ruby-1.8.5/internal/node/global_entry.h +10 -0
  88. data/ext/cached/ruby-1.8.5/internal/node/node_type_descrip.c +154 -0
  89. data/ext/cached/ruby-1.8.5/internal/node/nodeinfo.c +5732 -0
  90. data/ext/cached/ruby-1.8.5/internal/node/nodeinfo.h +67 -0
  91. data/ext/cached/ruby-1.8.5/internal/proc/block.h +32 -0
  92. data/ext/cached/ruby-1.8.5/internal/tag/tag.h +16 -0
  93. data/ext/cached/ruby-1.8.5/internal/vm/instruction/insns_info.c +39 -0
  94. data/ext/cached/ruby-1.8.5/internal/vm/instruction/insns_info.h +21 -0
  95. data/ext/cached/ruby-1.8.5/internal/vm/iseq/insns_info.inc +12 -0
  96. data/ext/cached/ruby-1.8.6/internal/binding/block.h +32 -0
  97. data/ext/cached/ruby-1.8.6/internal/method/method.h +20 -0
  98. data/ext/cached/ruby-1.8.6/internal/module/classpath.c +45 -0
  99. data/ext/cached/ruby-1.8.6/internal/module/classpath.h +17 -0
  100. data/ext/cached/ruby-1.8.6/internal/node/block.h +32 -0
  101. data/ext/cached/ruby-1.8.6/internal/node/global_entry.h +10 -0
  102. data/ext/cached/ruby-1.8.6/internal/node/node_type_descrip.c +154 -0
  103. data/ext/cached/ruby-1.8.6/internal/node/nodeinfo.c +5732 -0
  104. data/ext/cached/ruby-1.8.6/internal/node/nodeinfo.h +67 -0
  105. data/ext/cached/ruby-1.8.6/internal/proc/block.h +32 -0
  106. data/ext/cached/ruby-1.8.6/internal/tag/tag.h +16 -0
  107. data/ext/cached/ruby-1.8.6/internal/vm/instruction/insns_info.c +39 -0
  108. data/ext/cached/ruby-1.8.6/internal/vm/instruction/insns_info.h +21 -0
  109. data/ext/cached/ruby-1.8.6/internal/vm/iseq/insns_info.inc +12 -0
  110. data/ext/cached/ruby-1.8.7/internal/binding/block.h +32 -0
  111. data/ext/cached/ruby-1.8.7/internal/method/method.h +20 -0
  112. data/ext/cached/ruby-1.8.7/internal/module/classpath.c +45 -0
  113. data/ext/cached/ruby-1.8.7/internal/module/classpath.h +17 -0
  114. data/ext/cached/ruby-1.8.7/internal/node/block.h +32 -0
  115. data/ext/cached/ruby-1.8.7/internal/node/global_entry.h +10 -0
  116. data/ext/cached/ruby-1.8.7/internal/node/node_type_descrip.c +154 -0
  117. data/ext/cached/ruby-1.8.7/internal/node/nodeinfo.c +5732 -0
  118. data/ext/cached/ruby-1.8.7/internal/node/nodeinfo.h +67 -0
  119. data/ext/cached/ruby-1.8.7/internal/proc/block.h +32 -0
  120. data/ext/cached/ruby-1.8.7/internal/tag/tag.h +16 -0
  121. data/ext/cached/ruby-1.8.7/internal/vm/instruction/insns_info.c +39 -0
  122. data/ext/cached/ruby-1.8.7/internal/vm/instruction/insns_info.h +21 -0
  123. data/ext/cached/ruby-1.8.7/internal/vm/iseq/insns_info.inc +12 -0
  124. data/ext/cached/ruby-1.9.0/internal/binding/block.h +12 -0
  125. data/ext/cached/ruby-1.9.0/internal/method/method.h +20 -0
  126. data/ext/cached/ruby-1.9.0/internal/module/classpath.c +42 -0
  127. data/ext/cached/ruby-1.9.0/internal/module/classpath.h +17 -0
  128. data/ext/cached/ruby-1.9.0/internal/node/block.h +12 -0
  129. data/ext/cached/ruby-1.9.0/internal/node/global_entry.h +10 -0
  130. data/ext/cached/ruby-1.9.0/internal/node/node_type_descrip.c +149 -0
  131. data/ext/cached/ruby-1.9.0/internal/node/nodeinfo.c +5579 -0
  132. data/ext/cached/ruby-1.9.0/internal/node/nodeinfo.h +70 -0
  133. data/ext/cached/ruby-1.9.0/internal/proc/block.h +12 -0
  134. data/ext/cached/ruby-1.9.0/internal/tag/tag.h +6 -0
  135. data/ext/cached/ruby-1.9.0/internal/vm/instruction/insns_info.c +5936 -0
  136. data/ext/cached/ruby-1.9.0/internal/vm/instruction/insns_info.h +891 -0
  137. data/ext/cached/ruby-1.9.0/internal/vm/iseq/insns_info.inc +700 -0
  138. data/ext/cached/ruby-1.9.0/internal/yarv-headers/debug.h +36 -0
  139. data/ext/cached/ruby-1.9.0/internal/yarv-headers/dln.h +41 -0
  140. data/ext/cached/ruby-1.9.0/internal/yarv-headers/encdb.h +147 -0
  141. data/ext/cached/ruby-1.9.0/internal/yarv-headers/eval_intern.h +221 -0
  142. data/ext/cached/ruby-1.9.0/internal/yarv-headers/gc.h +75 -0
  143. data/ext/cached/ruby-1.9.0/internal/yarv-headers/id.h +83 -0
  144. data/ext/cached/ruby-1.9.0/internal/yarv-headers/iseq.h +94 -0
  145. data/ext/cached/ruby-1.9.0/internal/yarv-headers/node.h +516 -0
  146. data/ext/cached/ruby-1.9.0/internal/yarv-headers/parse.h +303 -0
  147. data/ext/cached/ruby-1.9.0/internal/yarv-headers/regenc.h +207 -0
  148. data/ext/cached/ruby-1.9.0/internal/yarv-headers/regint.h +842 -0
  149. data/ext/cached/ruby-1.9.0/internal/yarv-headers/regparse.h +351 -0
  150. data/ext/cached/ruby-1.9.0/internal/yarv-headers/revision.h +1 -0
  151. data/ext/cached/ruby-1.9.0/internal/yarv-headers/thread_pthread.h +24 -0
  152. data/ext/cached/ruby-1.9.0/internal/yarv-headers/thread_win32.h +33 -0
  153. data/ext/cached/ruby-1.9.0/internal/yarv-headers/transcode_data.h +99 -0
  154. data/ext/cached/ruby-1.9.0/internal/yarv-headers/transdb.h +67 -0
  155. data/ext/cached/ruby-1.9.0/internal/yarv-headers/version.h +57 -0
  156. data/ext/cached/ruby-1.9.0/internal/yarv-headers/vm_core.h +663 -0
  157. data/ext/cached/ruby-1.9.0/internal/yarv-headers/vm_exec.h +187 -0
  158. data/ext/cached/ruby-1.9.0/internal/yarv-headers/vm_insnhelper.h +191 -0
  159. data/ext/cached/ruby-1.9.0/internal/yarv-headers/vm_opts.h +51 -0
  160. data/ext/cached/ruby-1.9.1/internal/binding/block.h +12 -0
  161. data/ext/cached/ruby-1.9.1/internal/method/method.h +20 -0
  162. data/ext/cached/ruby-1.9.1/internal/module/classpath.c +42 -0
  163. data/ext/cached/ruby-1.9.1/internal/module/classpath.h +17 -0
  164. data/ext/cached/ruby-1.9.1/internal/node/block.h +12 -0
  165. data/ext/cached/ruby-1.9.1/internal/node/global_entry.h +10 -0
  166. data/ext/cached/ruby-1.9.1/internal/node/node_type_descrip.c +149 -0
  167. data/ext/cached/ruby-1.9.1/internal/node/nodeinfo.c +5579 -0
  168. data/ext/cached/ruby-1.9.1/internal/node/nodeinfo.h +70 -0
  169. data/ext/cached/ruby-1.9.1/internal/proc/block.h +12 -0
  170. data/ext/cached/ruby-1.9.1/internal/tag/tag.h +6 -0
  171. data/ext/cached/ruby-1.9.1/internal/vm/instruction/insns_info.c +5936 -0
  172. data/ext/cached/ruby-1.9.1/internal/vm/instruction/insns_info.h +891 -0
  173. data/ext/cached/ruby-1.9.1/internal/vm/iseq/insns_info.inc +700 -0
  174. data/ext/cached/ruby-1.9.1/internal/yarv-headers/debug.h +36 -0
  175. data/ext/cached/ruby-1.9.1/internal/yarv-headers/dln.h +41 -0
  176. data/ext/cached/ruby-1.9.1/internal/yarv-headers/encdb.h +147 -0
  177. data/ext/cached/ruby-1.9.1/internal/yarv-headers/eval_intern.h +209 -0
  178. data/ext/cached/ruby-1.9.1/internal/yarv-headers/gc.h +75 -0
  179. data/ext/cached/ruby-1.9.1/internal/yarv-headers/id.h +184 -0
  180. data/ext/cached/ruby-1.9.1/internal/yarv-headers/iseq.h +94 -0
  181. data/ext/cached/ruby-1.9.1/internal/yarv-headers/node.h +516 -0
  182. data/ext/cached/ruby-1.9.1/internal/yarv-headers/parse.h +303 -0
  183. data/ext/cached/ruby-1.9.1/internal/yarv-headers/regenc.h +207 -0
  184. data/ext/cached/ruby-1.9.1/internal/yarv-headers/regint.h +842 -0
  185. data/ext/cached/ruby-1.9.1/internal/yarv-headers/regparse.h +351 -0
  186. data/ext/cached/ruby-1.9.1/internal/yarv-headers/revision.h +1 -0
  187. data/ext/cached/ruby-1.9.1/internal/yarv-headers/thread_pthread.h +24 -0
  188. data/ext/cached/ruby-1.9.1/internal/yarv-headers/thread_win32.h +33 -0
  189. data/ext/cached/ruby-1.9.1/internal/yarv-headers/transcode_data.h +99 -0
  190. data/ext/cached/ruby-1.9.1/internal/yarv-headers/transdb.h +85 -0
  191. data/ext/cached/ruby-1.9.1/internal/yarv-headers/version.h +60 -0
  192. data/ext/cached/ruby-1.9.1/internal/yarv-headers/vm_core.h +655 -0
  193. data/ext/cached/ruby-1.9.1/internal/yarv-headers/vm_exec.h +187 -0
  194. data/ext/cached/ruby-1.9.1/internal/yarv-headers/vm_insnhelper.h +194 -0
  195. data/ext/cached/ruby-1.9.1/internal/yarv-headers/vm_opts.h +51 -0
  196. data/ext/internal/binding/binding.c +45 -0
  197. data/ext/internal/binding/block.h.rpp +44 -0
  198. data/ext/internal/binding/extconf.rb +6 -0
  199. data/ext/internal/method/extconf.rb +8 -0
  200. data/ext/internal/method/method.c +269 -0
  201. data/ext/internal/method/method.h.rpp +58 -0
  202. data/ext/internal/module/classpath.c.rpp +29 -0
  203. data/ext/internal/module/classpath.h.rpp +36 -0
  204. data/ext/internal/module/extconf.rb +11 -0
  205. data/ext/internal/module/module.c +797 -0
  206. data/ext/internal/module/module.h +7 -0
  207. data/ext/internal/node/block.h.rpp +44 -0
  208. data/ext/internal/node/builtins.h +41 -0
  209. data/ext/internal/node/extconf.rb +66 -0
  210. data/ext/internal/node/global_entry.h.rpp +26 -0
  211. data/ext/internal/node/node.c +1147 -0
  212. data/ext/internal/node/node_type_descrip.c.rpp +72 -0
  213. data/ext/internal/node/node_type_descrip.h +17 -0
  214. data/ext/internal/node/node_type_descrip.rb +39 -0
  215. data/ext/internal/node/nodeinfo.c.rpp +587 -0
  216. data/ext/internal/node/nodeinfo.h.rpp +30 -0
  217. data/ext/internal/node/nodes.rb +78 -0
  218. data/ext/internal/node/read_node_h.rb +34 -0
  219. data/ext/internal/node/ruby_internal_node.h +31 -0
  220. data/ext/internal/noex/extconf.rb +6 -0
  221. data/ext/internal/noex/noex.c +44 -0
  222. data/ext/internal/object/extconf.rb +4 -0
  223. data/ext/internal/object/object.c +75 -0
  224. data/ext/internal/proc/block.h.rpp +44 -0
  225. data/ext/internal/proc/extconf.rb +9 -0
  226. data/ext/internal/proc/proc.c +331 -0
  227. data/ext/internal/tag/extconf.rb +3 -0
  228. data/ext/internal/tag/tag.c +17 -0
  229. data/ext/internal/tag/tag.h.rpp +22 -0
  230. data/ext/internal/thread/extconf.rb +3 -0
  231. data/ext/internal/thread/thread.c +107 -0
  232. data/ext/internal/vm/constants/constants.c +33 -0
  233. data/ext/internal/vm/constants/extconf.rb +3 -0
  234. data/ext/internal/vm/control_frame/control_frame.c +185 -0
  235. data/ext/internal/vm/control_frame/control_frame.h +18 -0
  236. data/ext/internal/vm/control_frame/extconf.rb +3 -0
  237. data/ext/internal/vm/extconf.rb +3 -0
  238. data/ext/internal/vm/inline_cache/extconf.rb +6 -0
  239. data/ext/internal/vm/inline_cache/inline_cache.c +79 -0
  240. data/ext/internal/vm/instruction/extconf.rb +6 -0
  241. data/ext/internal/vm/instruction/insns_info.c.rpp +213 -0
  242. data/ext/internal/vm/instruction/insns_info.h.rpp +53 -0
  243. data/ext/internal/vm/instruction/instruction.c +78 -0
  244. data/ext/internal/vm/instruction/instruction.h +10 -0
  245. data/ext/internal/vm/iseq/extconf.rb +7 -0
  246. data/ext/internal/vm/iseq/insns_info.inc.rpp +30 -0
  247. data/ext/internal/vm/iseq/internal_iseq.h +9 -0
  248. data/ext/internal/vm/iseq/iseq.c +555 -0
  249. data/ext/internal/vm/vm.c +55 -0
  250. data/ext/mkmf-ruby-internal.rb +111 -0
  251. data/ext/ruby_source_dir.rb +24 -0
  252. data/ext/rubypp.rb +97 -0
  253. data/generate_rdoc.rb +33 -0
  254. data/lib/internal/binding.rb +1 -0
  255. data/lib/internal/classtree.rb +55 -0
  256. data/lib/internal/debug.rb +16 -0
  257. data/lib/internal/method.rb +1 -0
  258. data/lib/internal/method/as_code.rb +33 -0
  259. data/lib/internal/method/as_expression.rb +34 -0
  260. data/lib/internal/method/signature.rb +442 -0
  261. data/lib/internal/module.rb +1 -0
  262. data/lib/internal/module/as_code.rb +45 -0
  263. data/lib/internal/node.rb +3 -0
  264. data/lib/internal/node/as_code.rb +233 -0
  265. data/lib/internal/node/as_expression.rb +619 -0
  266. data/lib/internal/node/dump.rb +53 -0
  267. data/lib/internal/node/pp.rb +72 -0
  268. data/lib/internal/node/to_a.rb +52 -0
  269. data/lib/internal/noex.rb +1 -0
  270. data/lib/internal/obfusc.rb +57 -0
  271. data/lib/internal/object.rb +1 -0
  272. data/lib/internal/object/as_code.rb +10 -0
  273. data/lib/internal/proc.rb +1 -0
  274. data/lib/internal/proc/as_code.rb +21 -0
  275. data/lib/internal/proc/as_expression.rb +14 -0
  276. data/lib/internal/proc/signature.rb +184 -0
  277. data/lib/internal/tag.rb +1 -0
  278. data/lib/internal/thread.rb +1 -0
  279. data/lib/internal/vm.rb +1 -0
  280. data/lib/internal/vm/bytedecoder.rb +866 -0
  281. data/lib/internal/vm/constants.rb +1 -0
  282. data/lib/internal/vm/control_frame.rb +1 -0
  283. data/lib/internal/vm/inline_cache.rb +1 -0
  284. data/lib/internal/vm/instruction.rb +1 -0
  285. data/lib/internal/vm/iseq.rb +1 -0
  286. data/lib/internal/vm/iseq/as_code.rb +27 -0
  287. data/lib/internal/vm/iseq/as_expression.rb +26 -0
  288. data/metaconfig +19 -0
  289. data/post-config.rb +1 -0
  290. data/post-install.rb +4 -0
  291. data/post-setup.rb +7 -0
  292. data/pre-config.rb +96 -0
  293. data/pre-install.rb +13 -0
  294. data/pre-setup.rb +8 -0
  295. data/run_tests.rb +26 -0
  296. data/setup.rb +1599 -0
  297. data/test/expression_samples.rb +160 -0
  298. data/test/node_samples.rb +122 -0
  299. data/test/test_as_code.rb +261 -0
  300. data/test/test_as_expression.rb +229 -0
  301. data/test/test_dump_class.rb +187 -0
  302. data/test/test_dump_method.rb +144 -0
  303. data/test/test_dump_proc.rb +118 -0
  304. data/test/test_helpers.rb +61 -0
  305. data/test/test_method.rb +72 -0
  306. data/test/test_methodsig.rb +267 -0
  307. data/test/test_module.rb +49 -0
  308. data/test/test_node.rb +77 -0
  309. data/test/test_proc.rb +47 -0
  310. 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,10 @@
1
+ require 'internal/node/as_code'
2
+ require 'internal/object'
3
+
4
+ class Object
5
+ def as_code(indent=0)
6
+ # TODO: this won't work for many objects
7
+ "#{' '*indent}#{self.inspect}"
8
+ end
9
+ end
10
+
@@ -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
+