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,160 @@
1
+ require 'rbconfig'
2
+
3
+ class TEST_CLASS
4
+ FOO = 10
5
+ end
6
+
7
+ EXPRESSION_SAMPLES = {
8
+ :lit => '42',
9
+ :vcall => 'foo',
10
+ :fcall => 'foo()',
11
+ :fcall_many => 'foo(1, 2, 3)',
12
+ :fcall_many2 => 'foo 1, 2, 3',
13
+ :fcall_splat => 'a = [2, 3]; foo(1, *a)',
14
+ :fcall_block => 'foo() { nil }',
15
+ :fcall_block_with_args => 'foo() { |x,y| [x, y] }',
16
+ :plus => '1+1',
17
+ :minus => '54-2',
18
+ :times => '12*6',
19
+ :div => '16/7',
20
+ :less => '8 < 5',
21
+ :less_eq => '8 <= 5',
22
+ :greater => '8 > 5',
23
+ :greater_eq => '8 >= 5',
24
+ :equal => '8 == 5',
25
+ :threequal => '8 === 5',
26
+ :spaceship => "8 <=\> 5", # the \> is for Align.vim
27
+ :lshift => '8 << 5 ',
28
+ :rshift => '8 >> 5',
29
+ :bit_and => '8 & 5',
30
+ :bit_or => '8 | 5',
31
+ :bit_xor => '8 ^ 5',
32
+ :mod => '8 % 5',
33
+ :not_equal => '8 != 5',
34
+ # TODO: :match => ''foo' =~ /foo|bar/',
35
+ # TODO: :not_match => ''foo' !~ /foo|bar/',
36
+ :call => 'self.foo',
37
+ # TODO: super
38
+ # TODO: zsuper
39
+ # TODO: redo
40
+ # TODO: retry
41
+ :sym_not => '!true',
42
+ :sym_and => 'true && false',
43
+ :sym_or => 'true || false',
44
+ :lit_not => 'not true',
45
+ :lit_and => 'true and false',
46
+ :lit_or => 'true or false',
47
+ :array => '[1, 2, 3]',
48
+ :zarray => '[]',
49
+ :array_splat => '[1, 2, *[3, 4]]',
50
+ :array_splat_var => 'a = [3, 4]; [1, 2, *a]',
51
+ # TODO: block
52
+ :hash => '{ 1 => 2, 2 => 3 }',
53
+ :zhash => '{}',
54
+ :ternary => 'true ? false : nil',
55
+ :if => 'if true then false; else nil; end',
56
+ :if2 => '42 if true',
57
+ :true => 'true',
58
+ :false => 'false',
59
+ :nil => 'nil',
60
+ :self => 'self',
61
+ :dot2 => '5..8',
62
+ :dot3 => '5...8',
63
+ :gvar => '$stdout',
64
+ :ivar => '@foo',
65
+ :cvar => '@@foo',
66
+ :dvar => 'foo = 1; foo',
67
+ :nth_ref => '$1',
68
+ :back_ref => '$`',
69
+ :dasgn_curr => 'foo = 1',
70
+ # TODO: dasgn
71
+ :iasgn => '@foo = 6',
72
+ # TODO: lasgn
73
+ :masgn => 'a, b = 1, 2',
74
+ :masgn_with_one_value => 'a, b = 1',
75
+ :cdecl => 'remove_foo; FOO = 1',
76
+ :cvdecl => '@@foo = 1',
77
+ # TODO: cvasgn
78
+ :attrasgn => 'h = {}; h.default = true; h',
79
+ :const => 'FOO',
80
+ :colon2 => 'self::FOO',
81
+ :colon3 => '::TEST_CLASS::FOO',
82
+ # TODO: lvar
83
+ # TODO: newline
84
+ :str => '"foo"',
85
+ :regx => '/foo/',
86
+ # TODO: :regx_cflag => '/foo/i',
87
+ :regx_once => '/foo/o',
88
+ # :regx_once_cflag => '/foo/oi',
89
+ # TODO: xstr
90
+ :dstr => 'a = 1; b = 2; "#{a}#{b}"',
91
+ :dregx => 'a = 1; b = 2; /#{a}#{b}/',
92
+ # :dregx_cflag => 'a = 1; b = 2; /#{a}#{b}/i',
93
+ :dregx_once => 'a = 1; b = 2; /#{a}#{b}/',
94
+ # :dregx_once_cflag => 'a = 1; b = 2; /#{a}#{b}/oi',
95
+ # TODO dregx with next set
96
+ # TODO: dxstr
97
+ # TODO: evstr
98
+ :iter => 'loop { break }',
99
+ :iter_x => 'loop { break 10 }',
100
+ :while_1 => 'while true; break; end',
101
+ :while_1_x => 'while true; break 7; end',
102
+ :while_1_do => 'while true do; break; end',
103
+ :while_1_do_x => 'while true do; break 7; end',
104
+ :while_0 => 'begin; break; end while true',
105
+ :while_0_x => 'begin; break 7; end while true',
106
+ :until_1 => 'until false; break; end',
107
+ :until_1_x => 'until false; break 7; end',
108
+ :until_1_do => 'until false do; break; end',
109
+ :until_1_do_x => 'until false do; break 7; end',
110
+ :until_0 => 'begin; break; end until false',
111
+ :until_0_x => 'begin; break 7; end until false',
112
+ :break => 'break',
113
+ :break_x => 'break 49',
114
+ :catch => 'catch(:foo) { throw :foo; 42 }',
115
+ # TODO: yield
116
+ :begin => 'begin; 42; end',
117
+ :begin_empty => 'begin; end',
118
+ :begin_ensure => 'begin; 7; ensure; 42; end',
119
+ :begin_ensure_empty_head => 'begin; ensure; 42; end',
120
+ :begin_ensure_empty_body => 'begin; ensure; end',
121
+ :rescue => 'raise "foo" rescue 7',
122
+ :rescue2 => 'raise "foo"; 42 rescue 7',
123
+ :begin_rescue => 'begin; raise "foo"; rescue; 42; end',
124
+ :begin_rescue_multi => 'begin; raise "foo"; 6; rescue; 42; end',
125
+ :begin_rescue_empty_head => 'begin; rescue; end',
126
+ :begin_rescue_empty_resq => 'begin; 42; rescue; end',
127
+ :resbody => 'begin; raise "foo"; rescue; 42; end',
128
+ :case_when => 'case 42; when TrueClass then 6; when Fixnum then 42; end',
129
+ :case_when_multi_arg => 'case 42; when TrueClass, Fixnum then 42; end',
130
+ :case_when_empty_body => 'case 42; when TrueClass; when Fixnum then 42; end',
131
+ # TODO: alias
132
+ # TODO: valias
133
+ :undef => 'define_method(:a) { }; undef :a',
134
+ # TODO: class
135
+ # TODO: sclass
136
+ # TODO: scope
137
+ # TODO: defn
138
+ # TODO: defs
139
+ :defined => 'defined?(NilClass)',
140
+ # TODO: match3
141
+ :op_asgn2 => 'OWFA.foo = 0; OWFA.foo += 1',
142
+ }
143
+
144
+
145
+ major = Config::CONFIG['MAJOR'].to_i
146
+ minor = Config::CONFIG['MINOR'].to_i
147
+ teeny = Config::CONFIG['TEENY'].to_i
148
+ ruby_version_code = major * 100 + minor * 10 + teeny
149
+
150
+ if ruby_version_code < 170 then
151
+ EXPRESSION_SAMPLES.delete(:break_x)
152
+ EXPRESSION_SAMPLES.delete(:iter_x)
153
+ EXPRESSION_SAMPLES.delete(:while_1_x)
154
+ EXPRESSION_SAMPLES.delete(:while_1_do_x)
155
+ EXPRESSION_SAMPLES.delete(:while_0_x)
156
+ EXPRESSION_SAMPLES.delete(:until_1_x)
157
+ EXPRESSION_SAMPLES.delete(:until_1_do_x)
158
+ EXPRESSION_SAMPLES.delete(:until_0_x)
159
+ end
160
+
@@ -0,0 +1,122 @@
1
+ Common_Node_Samples = {
2
+ :method => "",
3
+ :fbody => "",
4
+ # cfunc not dumpable
5
+ :ifunc => "",
6
+ :scope => "",
7
+ :block => "",
8
+ :if => "if true then 1 end",
9
+ :case => "case 1 when 1 then true end",
10
+ :when => "case 1 when 1 then true end",
11
+ :opt_n => "",
12
+ :while => "a = 0; while a != 1; a += 1; end",
13
+ :until => "a = 0; until a == 1; a += 1; end",
14
+ :iter => "loop { break }",
15
+ :for => "a = 0; for i in 1..42; a += 1; end; a",
16
+ :break => "a = 24; for i in 1..42; break if i == 24; a += 1; end; a",
17
+ :next => "[1].each { next }",
18
+ :redo => "a = false; [1].each { if not a; a = true; redo; end }",
19
+ :retry => "a = true; begin; raise 'foo' if a; rescue; a = false; retry; end",
20
+ :begin => "begin; rescue; end",
21
+ :rescue => "begin; raise 'foo'; rescue; end",
22
+ :resbody => "begin; raise 'foo'; rescue; end",
23
+ :ensure => "begin; ensure; 10; end",
24
+ :and => "true and false",
25
+ :or => "if 1 or 2 then 3; end",
26
+ :not => "not false",
27
+ :masgn => "a, b, c = 4, 5, 6",
28
+ :lasgn => "x = 1",
29
+ :dasgn => "",
30
+ :dasgn_curr => "",
31
+ :gasgn => "$a = 1",
32
+ :iasgn => "@a = 1",
33
+ :cdecl => "",
34
+ :op_asgn1 => "{}[10] = 1",
35
+ :op_asgn2 => "{}.default = 1",
36
+ :op_asgn_and => "",
37
+ :op_asgn_or => "",
38
+ :call => "$stdout.sync",
39
+ :fcall => "", # see iter
40
+ :vcall => "",
41
+ :array => "[1, 2, 3]",
42
+ :zarray => "[]",
43
+ :hash => "{ 1 => 2 }",
44
+ :lvar => "",
45
+ :dvar => "",
46
+ :gvar => "$a == 1",
47
+ :ivar => "@a == 42", # must be diff from iasgn
48
+ :const => "",
49
+ :cvar => "@@a == 42",
50
+ :cvar2 => "",
51
+ :nth_ref => "$1 == nil",
52
+ :back_ref => "$` == nil",
53
+ :match => "",
54
+ :match2 => "",
55
+ :match3 => "",
56
+ :lit => "17",
57
+ :str => "\"foo\"",
58
+ :dstr => "\"#{8}\"",
59
+ :xstr => "`ls` if false",
60
+ :dxstr => "`\#{foo}` if false",
61
+ :evstr => "",
62
+ :dregx => "/\#{42}/",
63
+ :dregx_i => "/\#{42}/i", # same node type as dregx
64
+ :dregx_once => "/\#{42}/o",
65
+ :args => "",
66
+ :argscat => "",
67
+ :argspush => "''[0,*[1]] = 'foo'",
68
+ :restargs => "",
69
+ :block_arg => "", # def foo(&block)
70
+ :block_pass => "",
71
+ :defn => "",
72
+ :defs => "",
73
+ :alias => "",
74
+ :valias => "",
75
+ :undef => "",
76
+ :class => "",
77
+ :module => "",
78
+ :sclass => "class << self; end",
79
+ :colon2 => "Object::Kernel",
80
+ :colon3 => "::Object",
81
+ :cref => "",
82
+ :dot2 => "1..2",
83
+ :dot3 => "2...3",
84
+ :flip2 => "if 'foo' =~ /foo/ .. /bar/; end", # TODO
85
+ :flip3 => "if 'foo' =~ /foo/ ... /bar/; end", # TODO
86
+ :attrset => "",
87
+ :self => "self.nil?",
88
+ :nil => "nil",
89
+ :true => "true",
90
+ :false => "false",
91
+ :defined => "a = 1; defined?(a)",
92
+ :newline => "\n",
93
+ :postexe => "", # END { }
94
+ :alloca => "",
95
+ :dmethod => "",
96
+ :bmethod => "",
97
+ :memo => "",
98
+ :attrasgn => "{}.default = 42",
99
+ # last is just a placeholder
100
+
101
+ :crash1 => "self.class.ancestors.include?(Object)",
102
+ :crash2 => "Object === self",
103
+ }
104
+
105
+ Method_Node_Samples = Common_Node_Samples.dup.update({
106
+ :cvasgn => "@@a = 42", #TODO: not sure which of these is the decl and which is the asgn
107
+ :cvdecl => "@@a = 42",
108
+ :super => "super()",
109
+ :zsuper => "super",
110
+ :return => "",
111
+ :yield => "yield",
112
+ })
113
+
114
+ Proc_Node_Samples = Common_Node_Samples.dup.update({
115
+ :cvasgn => "",
116
+ :cvdecl => "",
117
+ :super => "", # can't call super from proc
118
+ :zsuper => "", # can't call super from proc
119
+ :return => "", # can't return from proc
120
+ :yield => "",
121
+ })
122
+
@@ -0,0 +1,261 @@
1
+ require 'test/unit'
2
+ require 'timeout'
3
+
4
+ dir = File.dirname(__FILE__)
5
+ $:.unshift(dir) if not $:.include?(dir)
6
+ $:.unshift("#{dir}/../lib") if not $:.include?("#{dir}/../lib")
7
+ $:.unshift("#{dir}/../ext") if not $:.include?("#{dir}/../ext")
8
+
9
+ require 'internal/node/as_code'
10
+ require 'internal/method/as_code'
11
+ require 'internal/module/as_code'
12
+ require 'internal/proc/as_code'
13
+
14
+ require 'expression_samples'
15
+
16
+ $stdout.sync = true
17
+ $stderr.sync = true
18
+
19
+ class TC_As_Code < Test::Unit::TestCase
20
+ MAJOR = Config::CONFIG['MAJOR'].to_i
21
+ MINOR = Config::CONFIG['MINOR'].to_i
22
+ TEENY = Config::CONFIG['TEENY'].to_i
23
+ RUBY_VERSION_CODE = MAJOR * 100 + MINOR * 10 + TEENY
24
+
25
+ extend Test::Unit::Assertions
26
+
27
+ # Some of the samples use this
28
+ def foo(*a, &b)
29
+ return b.call(1, 2) if b
30
+ return a
31
+ end
32
+
33
+ EXPRESSION_SAMPLES.each do |name, code|
34
+ p = proc {
35
+ p_orig = eval("proc { #{code} }")
36
+ code_new = p_orig.body.as_code
37
+ # p code, code_new
38
+ p_new = eval("proc { #{code_new} }")
39
+ result_orig = result_new = nil
40
+ exc_orig = exc_new = nil
41
+ timeout(1) { begin; result_orig = p_orig.call; rescue; exc_orig = $!; end }
42
+ timeout(1) { begin; result_new = p_new.call; rescue; exc_new = $!; end }
43
+ assert_equal(
44
+ exc_orig.class,
45
+ exc_new.class,
46
+ "Expected #{exc_orig.inspect} but got #{exc_new.inspect} " + \
47
+ "(code_orig=#{code}, code_new=#{code_new})")
48
+ if exc_orig and exc_new then
49
+ assert_equal(exc_orig.message, exc_new.message)
50
+ end
51
+ assert_equal(result_orig, result_new)
52
+ }
53
+ define_method "test_#{name}", p
54
+ end
55
+
56
+ def initialize(test_method_name)
57
+ # TODO: This seems to be the only way to get tests defined with #
58
+ # define_method to run on 1.8.1 and earlier.
59
+ catch(:invalid_test) { super(test_method_name) }
60
+ end
61
+
62
+ def method_no_args
63
+ 42
64
+ end
65
+
66
+ def test_method_no_args_as_code
67
+ m = method(:method_no_args)
68
+ assert_equal "def method_no_args()\n 42\nend", m.as_code
69
+ end
70
+
71
+ def method_one_arg(a)
72
+ 42
73
+ end
74
+
75
+ def test_method_one_arg_as_code
76
+ m = method(:method_one_arg)
77
+ assert_equal "def method_one_arg(a)\n 42\nend", m.as_code
78
+ end
79
+
80
+ def method_two_args(a, b)
81
+ 42
82
+ end
83
+
84
+ def test_method_two_args_as_code
85
+ m = method(:method_two_args)
86
+ assert_equal "def method_two_args(a, b)\n 42\nend", m.as_code
87
+ end
88
+
89
+ def method_rest_arg(*rest)
90
+ 42
91
+ end
92
+
93
+ def test_method_rest_arg_as_code
94
+ m = method(:method_rest_arg)
95
+ assert_equal "def method_rest_arg(*rest)\n 42\nend", m.as_code
96
+ end
97
+
98
+ def method_block_arg(&block)
99
+ 42
100
+ end
101
+
102
+ def test_method_block_arg_as_code
103
+ m = method(:method_block_arg)
104
+ assert_equal "def method_block_arg(&block)\n 42\nend", m.as_code
105
+ end
106
+
107
+ def method_rest_and_block_arg(*rest, &block)
108
+ 42
109
+ end
110
+
111
+ def test_method_rest_and_block_arg_as_code
112
+ m = method(:method_rest_and_block_arg)
113
+ assert_equal "def method_rest_and_block_arg(*rest, &block)\n 42\nend", m.as_code
114
+ end
115
+
116
+ def method_two_args_and_rest_and_block_arg(a, b, *rest, &block)
117
+ 42
118
+ end
119
+
120
+ def test_method_two_args_and_rest_and_block_arg_as_code
121
+ m = method(:method_two_args_and_rest_and_block_arg)
122
+ assert_equal "def method_two_args_and_rest_and_block_arg(a, b, *rest, &block)\n 42\nend", m.as_code
123
+ end
124
+
125
+ def method_with_body(a, b)
126
+ a + b
127
+ end
128
+
129
+ def test_method_with_body_as_code
130
+ m = method(:method_with_body)
131
+ assert_equal "def method_with_body(a, b)\n a + b\nend", m.as_code
132
+ end
133
+
134
+ def method_begin_ensure_as_code(a, b, *rest, &block)
135
+ begin
136
+ if not a and not b then
137
+ raise "Need more input!"
138
+ end
139
+ return a + b
140
+ ensure
141
+ puts "In ensure block"
142
+ end
143
+ end
144
+
145
+ def test_method_begin_ensure_as_code
146
+ m = method(:method_begin_ensure_as_code)
147
+ if RUBY_VERSION_CODE >= 190 then
148
+ ret = ''
149
+ else
150
+ ret = 'return '
151
+ end
152
+
153
+ assert_equal <<-END.chomp, m.as_code(3)
154
+ def method_begin_ensure_as_code(a, b, *rest, &block)
155
+ begin
156
+ (raise("Need more input!")) if (not a and not b)
157
+ #{ret}a + b
158
+ ensure
159
+ puts("In ensure block")
160
+ end
161
+ end
162
+ END
163
+ end
164
+
165
+ def test_proc_no_args_as_code
166
+ p = proc { }
167
+ assert_equal "proc do\nend", p.as_code
168
+ end
169
+
170
+ def test_proc_empty_args_as_code
171
+ if not defined?(RubyVM) then
172
+ # indistinguishable from proc { } on YARV
173
+ p = proc { || }
174
+ assert_equal "proc do ||\nend", p.as_code
175
+ end
176
+ end
177
+
178
+ def test_proc_one_arg_as_code
179
+ p = proc { |a| }
180
+ assert_equal "proc do |a|\nend", p.as_code
181
+ end
182
+
183
+ def test_proc_one_array_arg_as_expression
184
+ p = proc { |a,| }
185
+ assert_equal "proc do |a,|\nend", p.as_code
186
+ end
187
+
188
+ def test_proc_two_args_as_code
189
+ p = proc { |a, b| }
190
+ assert_equal "proc do |a, b|\nend", p.as_code
191
+ end
192
+
193
+ def test_proc_rest_arg_as_code
194
+ p = proc { |*rest| }
195
+ assert_equal "proc do |*rest|\nend", p.as_code
196
+ end
197
+
198
+ def test_proc_two_args_and_rest_arg_as_code
199
+ p = proc { |a, b, *rest| }
200
+ assert_equal "proc do |a, b, *rest|\nend", p.as_code
201
+ end
202
+
203
+ def test_proc_with_body_as_code
204
+ p = proc { |a, b| a + b }
205
+ assert_equal "proc do |a, b|\n a + b\nend", p.as_code
206
+ end
207
+
208
+ def setup
209
+ @foo = 42
210
+ end
211
+
212
+ # 1.7 and later
213
+ def foo(*args)
214
+ return args
215
+ end
216
+
217
+ def remove_foo
218
+ self.class.remove_foo
219
+ end
220
+
221
+ # 1.6
222
+ def self.foo(*args)
223
+ return args
224
+ end
225
+
226
+ def self.remove_foo
227
+ self.class_eval { remove_const(:FOO) if const_defined?(:FOO) }
228
+ end
229
+
230
+ @@foo = 10
231
+
232
+ FOO = 57
233
+
234
+ class ObjectWithFooAccessor
235
+ attr_accessor :foo
236
+ end
237
+
238
+ OWFA = ObjectWithFooAccessor.new
239
+ end
240
+
241
+ if __FILE__ == $0 then
242
+ require 'test/unit/ui/console/testrunner'
243
+
244
+ if Test::Unit.const_defined?(:AutoRunner) then
245
+ exit Test::Unit::AutoRunner.run
246
+ else
247
+ if ARGV.empty? then
248
+ suite = TC_As_Code.suite
249
+ else
250
+ suite = Test::Unit::TestSuite.new('TC_As_Code')
251
+ TC_As_Code.suite.tests.each do |test|
252
+ ARGV.each do |arg|
253
+ suite << test if /#{arg}/ =~ test.name
254
+ end
255
+ end
256
+ end
257
+ result = Test::Unit::UI::Console::TestRunner.run(suite)
258
+ exit(result.error_count + result.failure_count)
259
+ end
260
+ end
261
+