nodewrap 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. data/COPYING +59 -0
  2. data/LEGAL +6 -0
  3. data/LGPL +515 -0
  4. data/LICENSE +6 -0
  5. data/README +31 -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/MANIFEST +11 -0
  13. data/ext/builtins.h +25 -0
  14. data/ext/cached/ruby-1.6.3/COPYING +340 -0
  15. data/ext/cached/ruby-1.6.3/README +3 -0
  16. data/ext/cached/ruby-1.6.3/classpath.c +3 -0
  17. data/ext/cached/ruby-1.6.3/classpath.h +8 -0
  18. data/ext/cached/ruby-1.6.3/evalinfo.h +62 -0
  19. data/ext/cached/ruby-1.6.3/global_entry.h +15 -0
  20. data/ext/cached/ruby-1.6.3/insns_info.c +40 -0
  21. data/ext/cached/ruby-1.6.3/insns_info.h +19 -0
  22. data/ext/cached/ruby-1.6.3/node_type_descrip.c +150 -0
  23. data/ext/cached/ruby-1.6.3/nodeinfo.c +3182 -0
  24. data/ext/cached/ruby-1.6.3/nodeinfo.h +66 -0
  25. data/ext/cached/ruby-1.6.4/COPYING +340 -0
  26. data/ext/cached/ruby-1.6.4/README +3 -0
  27. data/ext/cached/ruby-1.6.4/classpath.c +3 -0
  28. data/ext/cached/ruby-1.6.4/classpath.h +8 -0
  29. data/ext/cached/ruby-1.6.4/evalinfo.h +62 -0
  30. data/ext/cached/ruby-1.6.4/global_entry.h +15 -0
  31. data/ext/cached/ruby-1.6.4/insns_info.c +40 -0
  32. data/ext/cached/ruby-1.6.4/insns_info.h +19 -0
  33. data/ext/cached/ruby-1.6.4/node_type_descrip.c +150 -0
  34. data/ext/cached/ruby-1.6.4/nodeinfo.c +3182 -0
  35. data/ext/cached/ruby-1.6.4/nodeinfo.h +66 -0
  36. data/ext/cached/ruby-1.6.5/COPYING +56 -0
  37. data/ext/cached/ruby-1.6.5/GPL +340 -0
  38. data/ext/cached/ruby-1.6.5/LEGAL +325 -0
  39. data/ext/cached/ruby-1.6.5/LGPL +504 -0
  40. data/ext/cached/ruby-1.6.5/README +3 -0
  41. data/ext/cached/ruby-1.6.5/classpath.c +3 -0
  42. data/ext/cached/ruby-1.6.5/classpath.h +8 -0
  43. data/ext/cached/ruby-1.6.5/evalinfo.h +63 -0
  44. data/ext/cached/ruby-1.6.5/global_entry.h +15 -0
  45. data/ext/cached/ruby-1.6.5/insns_info.c +40 -0
  46. data/ext/cached/ruby-1.6.5/insns_info.h +19 -0
  47. data/ext/cached/ruby-1.6.5/node_type_descrip.c +150 -0
  48. data/ext/cached/ruby-1.6.5/nodeinfo.c +3182 -0
  49. data/ext/cached/ruby-1.6.5/nodeinfo.h +66 -0
  50. data/ext/cached/ruby-1.6.7/COPYING +56 -0
  51. data/ext/cached/ruby-1.6.7/GPL +340 -0
  52. data/ext/cached/ruby-1.6.7/LEGAL +308 -0
  53. data/ext/cached/ruby-1.6.7/LGPL +504 -0
  54. data/ext/cached/ruby-1.6.7/README +3 -0
  55. data/ext/cached/ruby-1.6.7/classpath.c +3 -0
  56. data/ext/cached/ruby-1.6.7/classpath.h +8 -0
  57. data/ext/cached/ruby-1.6.7/evalinfo.h +63 -0
  58. data/ext/cached/ruby-1.6.7/global_entry.h +15 -0
  59. data/ext/cached/ruby-1.6.7/insns_info.c +40 -0
  60. data/ext/cached/ruby-1.6.7/insns_info.h +19 -0
  61. data/ext/cached/ruby-1.6.7/node_type_descrip.c +150 -0
  62. data/ext/cached/ruby-1.6.7/nodeinfo.c +3182 -0
  63. data/ext/cached/ruby-1.6.7/nodeinfo.h +66 -0
  64. data/ext/cached/ruby-1.6.8/COPYING +56 -0
  65. data/ext/cached/ruby-1.6.8/GPL +340 -0
  66. data/ext/cached/ruby-1.6.8/LEGAL +308 -0
  67. data/ext/cached/ruby-1.6.8/LGPL +504 -0
  68. data/ext/cached/ruby-1.6.8/README +3 -0
  69. data/ext/cached/ruby-1.6.8/classpath.c +3 -0
  70. data/ext/cached/ruby-1.6.8/classpath.h +8 -0
  71. data/ext/cached/ruby-1.6.8/evalinfo.h +63 -0
  72. data/ext/cached/ruby-1.6.8/global_entry.h +15 -0
  73. data/ext/cached/ruby-1.6.8/insns_info.c +40 -0
  74. data/ext/cached/ruby-1.6.8/insns_info.h +19 -0
  75. data/ext/cached/ruby-1.6.8/node_type_descrip.c +150 -0
  76. data/ext/cached/ruby-1.6.8/nodeinfo.c +3182 -0
  77. data/ext/cached/ruby-1.6.8/nodeinfo.h +66 -0
  78. data/ext/cached/ruby-1.8.0/COPYING +56 -0
  79. data/ext/cached/ruby-1.8.0/GPL +340 -0
  80. data/ext/cached/ruby-1.8.0/LEGAL +371 -0
  81. data/ext/cached/ruby-1.8.0/LGPL +504 -0
  82. data/ext/cached/ruby-1.8.0/README +3 -0
  83. data/ext/cached/ruby-1.8.0/classpath.c +27 -0
  84. data/ext/cached/ruby-1.8.0/classpath.h +14 -0
  85. data/ext/cached/ruby-1.8.0/evalinfo.h +65 -0
  86. data/ext/cached/ruby-1.8.0/global_entry.h +10 -0
  87. data/ext/cached/ruby-1.8.0/insns_info.c +40 -0
  88. data/ext/cached/ruby-1.8.0/insns_info.h +19 -0
  89. data/ext/cached/ruby-1.8.0/node_type_descrip.c +150 -0
  90. data/ext/cached/ruby-1.8.0/nodeinfo.c +3199 -0
  91. data/ext/cached/ruby-1.8.0/nodeinfo.h +66 -0
  92. data/ext/cached/ruby-1.8.1/COPYING +56 -0
  93. data/ext/cached/ruby-1.8.1/GPL +340 -0
  94. data/ext/cached/ruby-1.8.1/LEGAL +371 -0
  95. data/ext/cached/ruby-1.8.1/LGPL +504 -0
  96. data/ext/cached/ruby-1.8.1/README +3 -0
  97. data/ext/cached/ruby-1.8.1/classpath.c +27 -0
  98. data/ext/cached/ruby-1.8.1/classpath.h +14 -0
  99. data/ext/cached/ruby-1.8.1/evalinfo.h +59 -0
  100. data/ext/cached/ruby-1.8.1/global_entry.h +10 -0
  101. data/ext/cached/ruby-1.8.1/insns_info.c +40 -0
  102. data/ext/cached/ruby-1.8.1/insns_info.h +19 -0
  103. data/ext/cached/ruby-1.8.1/node_type_descrip.c +150 -0
  104. data/ext/cached/ruby-1.8.1/nodeinfo.c +3199 -0
  105. data/ext/cached/ruby-1.8.1/nodeinfo.h +66 -0
  106. data/ext/cached/ruby-1.8.2/COPYING +56 -0
  107. data/ext/cached/ruby-1.8.2/GPL +340 -0
  108. data/ext/cached/ruby-1.8.2/LEGAL +371 -0
  109. data/ext/cached/ruby-1.8.2/LGPL +504 -0
  110. data/ext/cached/ruby-1.8.2/README +3 -0
  111. data/ext/cached/ruby-1.8.2/classpath.c +45 -0
  112. data/ext/cached/ruby-1.8.2/classpath.h +17 -0
  113. data/ext/cached/ruby-1.8.2/evalinfo.h +60 -0
  114. data/ext/cached/ruby-1.8.2/global_entry.h +10 -0
  115. data/ext/cached/ruby-1.8.2/insns_info.c +40 -0
  116. data/ext/cached/ruby-1.8.2/insns_info.h +19 -0
  117. data/ext/cached/ruby-1.8.2/node_type_descrip.c +150 -0
  118. data/ext/cached/ruby-1.8.2/nodeinfo.c +3199 -0
  119. data/ext/cached/ruby-1.8.2/nodeinfo.h +66 -0
  120. data/ext/cached/ruby-1.8.3/COPYING +56 -0
  121. data/ext/cached/ruby-1.8.3/GPL +340 -0
  122. data/ext/cached/ruby-1.8.3/LEGAL +370 -0
  123. data/ext/cached/ruby-1.8.3/LGPL +504 -0
  124. data/ext/cached/ruby-1.8.3/README +3 -0
  125. data/ext/cached/ruby-1.8.3/classpath.c +45 -0
  126. data/ext/cached/ruby-1.8.3/classpath.h +17 -0
  127. data/ext/cached/ruby-1.8.3/evalinfo.h +61 -0
  128. data/ext/cached/ruby-1.8.3/global_entry.h +10 -0
  129. data/ext/cached/ruby-1.8.3/insns_info.c +40 -0
  130. data/ext/cached/ruby-1.8.3/insns_info.h +19 -0
  131. data/ext/cached/ruby-1.8.3/node_type_descrip.c +150 -0
  132. data/ext/cached/ruby-1.8.3/nodeinfo.c +3199 -0
  133. data/ext/cached/ruby-1.8.3/nodeinfo.h +66 -0
  134. data/ext/cached/ruby-1.8.4/COPYING +56 -0
  135. data/ext/cached/ruby-1.8.4/GPL +340 -0
  136. data/ext/cached/ruby-1.8.4/LEGAL +370 -0
  137. data/ext/cached/ruby-1.8.4/LGPL +504 -0
  138. data/ext/cached/ruby-1.8.4/README +3 -0
  139. data/ext/cached/ruby-1.8.4/classpath.c +45 -0
  140. data/ext/cached/ruby-1.8.4/classpath.h +17 -0
  141. data/ext/cached/ruby-1.8.4/evalinfo.h +61 -0
  142. data/ext/cached/ruby-1.8.4/global_entry.h +10 -0
  143. data/ext/cached/ruby-1.8.4/insns_info.c +40 -0
  144. data/ext/cached/ruby-1.8.4/insns_info.h +19 -0
  145. data/ext/cached/ruby-1.8.4/node_type_descrip.c +150 -0
  146. data/ext/cached/ruby-1.8.4/nodeinfo.c +3199 -0
  147. data/ext/cached/ruby-1.8.4/nodeinfo.h +66 -0
  148. data/ext/cached/ruby-1.8.5/COPYING +56 -0
  149. data/ext/cached/ruby-1.8.5/GPL +340 -0
  150. data/ext/cached/ruby-1.8.5/LEGAL +370 -0
  151. data/ext/cached/ruby-1.8.5/LGPL +504 -0
  152. data/ext/cached/ruby-1.8.5/README +3 -0
  153. data/ext/cached/ruby-1.8.5/classpath.c +45 -0
  154. data/ext/cached/ruby-1.8.5/classpath.h +17 -0
  155. data/ext/cached/ruby-1.8.5/evalinfo.h +61 -0
  156. data/ext/cached/ruby-1.8.5/global_entry.h +10 -0
  157. data/ext/cached/ruby-1.8.5/insns_info.c +40 -0
  158. data/ext/cached/ruby-1.8.5/insns_info.h +19 -0
  159. data/ext/cached/ruby-1.8.5/node_type_descrip.c +150 -0
  160. data/ext/cached/ruby-1.8.5/nodeinfo.c +3187 -0
  161. data/ext/cached/ruby-1.8.5/nodeinfo.h +64 -0
  162. data/ext/cached/ruby-1.8.6/COPYING +56 -0
  163. data/ext/cached/ruby-1.8.6/GPL +340 -0
  164. data/ext/cached/ruby-1.8.6/LEGAL +370 -0
  165. data/ext/cached/ruby-1.8.6/LGPL +504 -0
  166. data/ext/cached/ruby-1.8.6/README +3 -0
  167. data/ext/cached/ruby-1.8.6/classpath.c +45 -0
  168. data/ext/cached/ruby-1.8.6/classpath.h +17 -0
  169. data/ext/cached/ruby-1.8.6/evalinfo.h +61 -0
  170. data/ext/cached/ruby-1.8.6/global_entry.h +10 -0
  171. data/ext/cached/ruby-1.8.6/insns_info.c +40 -0
  172. data/ext/cached/ruby-1.8.6/insns_info.h +19 -0
  173. data/ext/cached/ruby-1.8.6/node_type_descrip.c +150 -0
  174. data/ext/cached/ruby-1.8.6/nodeinfo.c +3187 -0
  175. data/ext/cached/ruby-1.8.6/nodeinfo.h +64 -0
  176. data/ext/classpath.c +42 -0
  177. data/ext/classpath.c.rpp +28 -0
  178. data/ext/classpath.h +17 -0
  179. data/ext/classpath.h.rpp +35 -0
  180. data/ext/evalinfo.h +21 -0
  181. data/ext/evalinfo.h.rpp +49 -0
  182. data/ext/extconf.rb +68 -0
  183. data/ext/generate.rb +201 -0
  184. data/ext/generate_cached.rb +49 -0
  185. data/ext/global_entry.h +10 -0
  186. data/ext/global_entry.h.rpp +25 -0
  187. data/ext/insns_info.c +6079 -0
  188. data/ext/insns_info.c.rpp +210 -0
  189. data/ext/insns_info.h +819 -0
  190. data/ext/insns_info.h.rpp +50 -0
  191. data/ext/node_type_descrip.c +148 -0
  192. data/ext/node_type_descrip.c.rpp +72 -0
  193. data/ext/node_type_descrip.h +17 -0
  194. data/ext/node_type_descrip.rb +169 -0
  195. data/ext/nodeinfo.c +3164 -0
  196. data/ext/nodeinfo.c.rpp +519 -0
  197. data/ext/nodeinfo.h +67 -0
  198. data/ext/nodeinfo.h.rpp +27 -0
  199. data/ext/nodewrap.c +2576 -0
  200. data/ext/nodewrap.h +20 -0
  201. data/ext/read_node_h.rb +19 -0
  202. data/ext/ruby_source_dir.rb +15 -0
  203. data/ext/ruby_version.h +12 -0
  204. data/ext/ruby_version_code.rb +16 -0
  205. data/ext/rubypp.rb +97 -0
  206. data/ext/test.rb +15 -0
  207. data/generate_rdoc.rb +33 -0
  208. data/install.rb +1022 -0
  209. data/lib/as_code.rb +347 -0
  210. data/lib/as_expression.rb +657 -0
  211. data/lib/bytedecoder.rb +848 -0
  212. data/lib/classtree.rb +54 -0
  213. data/lib/methodsig.rb +266 -0
  214. data/lib/node_to_a.rb +34 -0
  215. data/lib/nodepp.rb +71 -0
  216. data/lib/nwdebug.rb +18 -0
  217. data/lib/nwdump.rb +53 -0
  218. data/lib/nwobfusc.rb +57 -0
  219. data/lib/procsig.rb +182 -0
  220. data/lib/test.rb +8 -0
  221. data/metaconfig +10 -0
  222. data/post-config.rb +53 -0
  223. data/post-setup.rb +9 -0
  224. data/pre-config.rb +1 -0
  225. data/run_tests.rb +48 -0
  226. data/test/expression_samples.rb +158 -0
  227. data/test/node_samples.rb +122 -0
  228. data/test/test.rb +39 -0
  229. data/test/test2.rb +7 -0
  230. data/test/test3.rb +5 -0
  231. data/test/test4.rb +5 -0
  232. data/test/test_as_code.rb +249 -0
  233. data/test/test_as_expression.rb +222 -0
  234. data/test/test_methodsig.rb +189 -0
  235. data/test/test_nodewrap.rb +369 -0
  236. metadata +286 -0
@@ -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 -rnwobfusc test.rb > test2.rb
20
+ # $ ruby test2.rb
21
+ # 2
22
+
23
+ require 'nodewrap'
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 'nodewrap'
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,182 @@
1
+ require 'node_to_a'
2
+
3
+ class Proc
4
+ class Arguments
5
+ include Enumerable
6
+
7
+ def initialize(names, multiple_assignment, rest_arg)
8
+ @names = names
9
+ @multiple_assignment = multiple_assignment
10
+ @rest_arg = rest_arg
11
+ end
12
+
13
+ def unspecified
14
+ if defined?(VM) and defined?(VM::InstructionSequence) then
15
+ # YARV
16
+ return @names.length == 0
17
+ else
18
+ # pre-YARV
19
+ @names.nil?
20
+ end
21
+ end
22
+
23
+ def single_assignment
24
+ !@multiple_assignment
25
+ end
26
+
27
+ def multiple_assignment
28
+ @multiple_assignment
29
+ end
30
+
31
+ def names
32
+ @names
33
+ end
34
+
35
+ def [](idx)
36
+ @names[idx]
37
+ end
38
+
39
+ def each(&block)
40
+ (@names || []).each(&block)
41
+ end
42
+
43
+ def size
44
+ @names.size
45
+ end
46
+
47
+ def rest_arg
48
+ @rest_arg
49
+ end
50
+
51
+ def empty_last_arg
52
+ if defined?(VM) and defined?(VM::InstructionSequence) then
53
+ # YARV
54
+ return (@rest_arg and @names[-1] == nil)
55
+ else
56
+ # pre-YARV
57
+ return (@names.size == 1 and not @rest_arg)
58
+ end
59
+ end
60
+ end
61
+
62
+ # Return an Arguments object representing the arguments in the order
63
+ # in which they appear in the argument list.
64
+ def arguments
65
+ has_rest_arg = self.has_rest_arg
66
+
67
+ if self.respond_to?(:var) and self.var then
68
+ # pre-YARV
69
+ case self.var
70
+ when Node::DASGN_CURR
71
+ return Arguments.new([ self.var.vid ], false, has_rest_arg ? 0 : nil)
72
+ when Node::MASGN
73
+ if self.var.head then
74
+ a = self.var.head.to_a
75
+ args = a.map { |n| n.vid }
76
+ else
77
+ args = []
78
+ end
79
+ if self.var.args then
80
+ args.push(self.var.args.vid)
81
+ end
82
+ return Arguments.new(args, true, has_rest_arg ? args.size - 1: nil)
83
+ when Fixnum
84
+ return Arguments.new([], false, has_rest_arg ? 0 : nil)
85
+ else
86
+ raise "Unexpected node type: #{self.var.class}"
87
+ end
88
+ elsif
89
+ # YARV
90
+ iseq = self.body
91
+ local_vars = iseq.local_table
92
+ has_rest_arg = iseq.arg_rest != -1
93
+ has_block_arg = iseq.arg_block != -1
94
+ num_args = \
95
+ iseq.argc + \
96
+ iseq.arg_opt_table.size + \
97
+ (has_rest_arg ? 1 : 0) + \
98
+ (has_block_arg ? 1 : 0)
99
+ puts "argc=#{iseq.argc}, opt_table.size=#{iseq.arg_opt_table.size}"
100
+ puts "has_rest_arg=#{has_rest_arg}, has_block_arg=#{has_block_arg}"
101
+ names = local_vars[0...num_args]
102
+ # TODO: masgn
103
+ return Arguments.new(names, true, has_rest_arg ? -1 : nil)
104
+ else
105
+ return Arguments.new(nil, false, nil)
106
+ end
107
+ end
108
+
109
+ # Return true if the proc has a rest arg
110
+ def has_rest_arg
111
+ if self.respond_to?(:var) then
112
+ # pre-YARV
113
+ has_rest_arg = false
114
+ if self.var then
115
+ if self.var.class == Node::MASGN then
116
+ if self.var.args then
117
+ has_rest_arg = true
118
+ end
119
+ end
120
+ end
121
+ else
122
+ # YARV
123
+ rest = self.body.arg_rest
124
+ has_rest_arg = (rest >= 0 ? rest - 1 : nil)
125
+ end
126
+ return has_rest_arg
127
+ end
128
+
129
+ # Return a hash mapping each argument name to a description of that
130
+ # argument.
131
+ def argument_info
132
+ args = self.arguments()
133
+
134
+ info = {}
135
+ args.each do |name|
136
+ info[name] = name.to_s
137
+ end
138
+
139
+ # Rest arg
140
+ if args.rest_arg then
141
+ rest_name = args[args.rest_arg]
142
+ if rest_name then
143
+ info[rest_name] = "*#{rest_name}"
144
+ end
145
+ end
146
+
147
+ return info
148
+ end
149
+
150
+ class Signature
151
+ attr_reader :args, :arg_info
152
+
153
+ def initialize(args, arg_info)
154
+ @args = args
155
+ @arg_info = arg_info
156
+ end
157
+
158
+ def to_s
159
+ if @args.unspecified then
160
+ return ""
161
+ elsif @args.multiple_assignment then
162
+ if @args.empty_last_arg then
163
+ params = @args.map{ |n| arg_info[n] }
164
+ return "|#{@arg_info[@args[0]]},|"
165
+ else
166
+ params = @args.map{ |n| arg_info[n] }
167
+ return "|#{params.join(', ')}|"
168
+ end
169
+ else
170
+ return "|#{@arg_info[@args[0]]}|"
171
+ end
172
+ end
173
+ end
174
+
175
+ # Return a String representing the method's signature.
176
+ def signature
177
+ return Signature.new(
178
+ arguments(),
179
+ argument_info)
180
+ end
181
+ end
182
+
@@ -0,0 +1,8 @@
1
+ class Foo
2
+ def bar=
3
+ return 1
4
+ end
5
+ end
6
+
7
+ f = Foo.new
8
+ f.bar = (1, 2)
@@ -0,0 +1,10 @@
1
+ add_path_config(
2
+ 'ruby-source-path',
3
+ nil,
4
+ 'path to the ruby source code')
5
+
6
+ add_config(
7
+ 'without-tests',
8
+ 'yes/no',
9
+ 'no',
10
+ 'does not run tests')
@@ -0,0 +1,53 @@
1
+ ruby_source_path = @config['ruby-source-path']
2
+
3
+ if ruby_source_path.nil? then
4
+
5
+ cached_dir = "ext/cached/ruby-#{RUBY_VERSION}"
6
+ if File.exist?(cached_dir) then
7
+ puts "Ruby source path not specified; using generated files from #{cached_dir}"
8
+ else
9
+ $stderr.puts "ERROR: Source code for the ruby interpreter could not be found (perhaps you forgot --ruby-source-path?)"
10
+ exit 1
11
+ end
12
+
13
+ else
14
+
15
+ ruby_h = File.join(ruby_source_path, 'ruby.h')
16
+ if not File.exist?(ruby_source_path) or
17
+ not File.directory?(ruby_source_path) or
18
+ not File.exist?(ruby_h) then
19
+ $stderr.puts "ERROR: Could not find the ruby source code at #{ruby_source_path}"
20
+ exit 1
21
+ end
22
+
23
+ version_h = File.join(ruby_source_path, 'version.h')
24
+ if not File.exist?(ruby_source_path) or
25
+ not File.directory?(ruby_source_path) or
26
+ not File.exist?(ruby_h) then
27
+ $stderr.puts "ERROR: Could not find version.h at #{ruby_source_path}"
28
+ exit 1
29
+ end
30
+
31
+ File.open(version_h) do |vh|
32
+ found_version = false
33
+ vh.each_line do |line|
34
+ if line =~ /#define\s+RUBY_VERSION\s+\"(.*?)\"/
35
+ found_version = true
36
+ if RUBY_VERSION != $1 then
37
+ $stderr.puts "Wrong version for source; expected #{RUBY_VERSION} but got #{$1}"
38
+ exit 1
39
+ end
40
+ end
41
+ end
42
+ if not found_version then
43
+ $stderr.puts "ERROR: Could not determine ruby version from version.h"
44
+ exit 1
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+ dive_into('ext') do
51
+ command('make clean')
52
+ end
53
+
@@ -0,0 +1,9 @@
1
+ require 'run_tests'
2
+ require 'generate_rdoc'
3
+
4
+ if @config['without-tests'] != 'yes' then
5
+ run_tests()
6
+ end
7
+
8
+ generate_rdoc()
9
+
@@ -0,0 +1 @@
1
+ @options['config-opt'] << "--ruby-source-path=#{@config['ruby-source-path']}"
@@ -0,0 +1,48 @@
1
+ def run_tests
2
+ begin
3
+ require 'test/unit'
4
+ rescue LoadError
5
+ puts "WARNING: Test::Unit not installed; skipping tests"
6
+ return
7
+ end
8
+
9
+ $:.unshift('ext')
10
+ $:.unshift('lib')
11
+ tests = Dir['test/test_*.rb']
12
+ tests.each do |test|
13
+ load test
14
+ end
15
+
16
+ verbose = nil
17
+ begin
18
+ verbose = Test::Unit::UI.const_get(:VERBOSE)
19
+ rescue NameError
20
+ verbose = Test::Unit::UI::Console::TestRunner.const_get(:VERBOSE)
21
+ end
22
+
23
+ tests = []
24
+ ObjectSpace.each_object do |o|
25
+ if Class === o and o < Test::Unit::TestCase then
26
+ tests << o
27
+ end
28
+ end
29
+
30
+ suite = Test::Unit::TestSuite.new("Nodewrap")
31
+ tests.each do |test|
32
+ test.suite.tests.each do |testcase|
33
+ suite << testcase
34
+ end
35
+ end
36
+
37
+ return Test::Unit::UI::Console::TestRunner.run(
38
+ suite,
39
+ verbose)
40
+ end
41
+
42
+ if __FILE__ == $0 then
43
+ require 'timeout'
44
+ result = nil
45
+ timeout(600) { result = run_tests() }
46
+ exit(result.error_count + result.failure_count)
47
+ end
48
+
@@ -0,0 +1,158 @@
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
+ # TODO: masgn
74
+ :cdecl => 'remove_foo; FOO = 1',
75
+ :cvdecl => '@@foo = 1',
76
+ # TODO: cvasgn
77
+ :attrasgn => 'h = {}; h.default = true; h',
78
+ :const => 'FOO',
79
+ :colon2 => 'self::FOO',
80
+ :colon3 => '::TEST_CLASS::FOO',
81
+ # TODO: lvar
82
+ # TODO: newline
83
+ :str => '"foo"',
84
+ :regx => '/foo/',
85
+ # TODO: :regx_cflag => '/foo/i',
86
+ :regx_once => '/foo/o',
87
+ # :regx_once_cflag => '/foo/oi',
88
+ # TODO: xstr
89
+ :dstr => 'a = 1; b = 2; "#{a}#{b}"',
90
+ :dregx => 'a = 1; b = 2; /#{a}#{b}/',
91
+ # :dregx_cflag => 'a = 1; b = 2; /#{a}#{b}/i',
92
+ :dregx_once => 'a = 1; b = 2; /#{a}#{b}/',
93
+ # :dregx_once_cflag => 'a = 1; b = 2; /#{a}#{b}/oi',
94
+ # TODO dregx with next set
95
+ # TODO: dxstr
96
+ # TODO: evstr
97
+ :iter => 'loop { break }',
98
+ :iter_x => 'loop { break 10 }',
99
+ :while_1 => 'while true; break; end',
100
+ :while_1_x => 'while true; break 7; end',
101
+ :while_1_do => 'while true do; break; end',
102
+ :while_1_do_x => 'while true do; break 7; end',
103
+ :while_0 => 'begin; break; end while true',
104
+ :while_0_x => 'begin; break 7; end while true',
105
+ :until_1 => 'until false; break; end',
106
+ :until_1_x => 'until false; break 7; end',
107
+ :until_1_do => 'until false do; break; end',
108
+ :until_1_do_x => 'until false do; break 7; end',
109
+ :until_0 => 'begin; break; end until false',
110
+ :until_0_x => 'begin; break 7; end until false',
111
+ :break => 'break',
112
+ :break_x => 'break 49',
113
+ :catch => 'catch(:foo) { throw :foo; 42 }',
114
+ # TODO: yield
115
+ :begin => 'begin; 42; end',
116
+ :begin_empty => 'begin; end',
117
+ :begin_ensure => 'begin; 7; ensure; 42; end',
118
+ :begin_ensure_empty_head => 'begin; ensure; 42; end',
119
+ :begin_ensure_empty_body => 'begin; ensure; end',
120
+ :rescue => 'raise "foo" rescue 7',
121
+ :rescue2 => 'raise "foo"; 42 rescue 7',
122
+ :begin_rescue => 'begin; raise "foo"; rescue; 42; end',
123
+ :begin_rescue_multi => 'begin; raise "foo"; 6; rescue; 42; end',
124
+ :begin_rescue_empty_head => 'begin; rescue; end',
125
+ :begin_rescue_empty_resq => 'begin; 42; rescue; end',
126
+ :resbody => 'begin; raise "foo"; rescue; 42; end',
127
+ :case_when => 'case 42; when TrueClass then 6; when Fixnum then 42; end',
128
+ :case_when_multi_arg => 'case 42; when TrueClass, Fixnum then 42; end',
129
+ :case_when_empty_body => 'case 42; when TrueClass; when Fixnum then 42; end',
130
+ # TODO: alias
131
+ # TODO: valias
132
+ # TODO: undef
133
+ # TODO: class
134
+ # TODO: sclass
135
+ # TODO: scope
136
+ # TODO: defn
137
+ # TODO: defs
138
+ :defined => 'defined?(NilClass)',
139
+ # TODO: match3
140
+ }
141
+
142
+
143
+ major = Config::CONFIG['MAJOR'].to_i
144
+ minor = Config::CONFIG['MINOR'].to_i
145
+ teeny = Config::CONFIG['TEENY'].to_i
146
+ ruby_version_code = major * 100 + minor * 10 + teeny
147
+
148
+ if ruby_version_code < 170 then
149
+ EXPRESSION_SAMPLES.delete(:break_x)
150
+ EXPRESSION_SAMPLES.delete(:iter_x)
151
+ EXPRESSION_SAMPLES.delete(:while_1_x)
152
+ EXPRESSION_SAMPLES.delete(:while_1_do_x)
153
+ EXPRESSION_SAMPLES.delete(:while_0_x)
154
+ EXPRESSION_SAMPLES.delete(:until_1_x)
155
+ EXPRESSION_SAMPLES.delete(:until_1_do_x)
156
+ EXPRESSION_SAMPLES.delete(:until_0_x)
157
+ end
158
+