nodewrap 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
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,519 @@
1
+ #include "nodeinfo.h"
2
+ #include "version.h"
3
+ #include "global_entry.h"
4
+ #include "builtins.h"
5
+
6
+ static int is_flip_state(ID id)
7
+ {
8
+ if(id == 0)
9
+ {
10
+ return 1;
11
+ }
12
+ #if RUBY_VERSION_CODE >= 180
13
+ if(!rb_is_local_id(id))
14
+ {
15
+ return 1;
16
+ }
17
+ #endif
18
+ return 0;
19
+ }
20
+
21
+ static VALUE variable_names(ID * tbl)
22
+ {
23
+ if(tbl)
24
+ {
25
+ size_t j;
26
+ VALUE arr = rb_ary_new();
27
+ /* A tbl contains the names of local variables. The first
28
+ * element is the size of the table. The next two elements
29
+ * are $_ and $~. The rest of the elements are the names of
30
+ * the variables themselves.
31
+ */
32
+ for(j = 3; j <= tbl[0]; ++j)
33
+ {
34
+ if(is_flip_state(tbl[j]))
35
+ {
36
+ /* flip state */
37
+ rb_ary_push(arr, Qnil);
38
+ }
39
+ else
40
+ {
41
+ rb_ary_push(arr, ID2SYM(tbl[j]));
42
+ }
43
+ }
44
+ return arr;
45
+ }
46
+ else
47
+ {
48
+ return Qnil;
49
+ }
50
+ }
51
+
52
+ /* Every node contains three elements. This function takes any one of
53
+ * those elements, converts it to a Ruby object that can be dumped
54
+ * (since nodes can't be dumped), and puts the resulting object into
55
+ * node_hash.
56
+ */
57
+ VALUE dump_node_elem(enum Node_Elem_Name nen, NODE * n, VALUE node_hash)
58
+ {
59
+ switch(nen)
60
+ {
61
+ case NEN_NONE:
62
+ return Qnil;
63
+ #ruby <<END
64
+ require 'read_node_h.rb'
65
+ require 'node_type_descrip.rb'
66
+
67
+ NODEINFO.sort.each do |node_elem_name, node_elem_ref|
68
+ puts <<-END
69
+ case NEN_#{node_elem_name.upcase}:
70
+ END
71
+
72
+ if node_elem_name == "noex" or node_elem_name == "cflag" then
73
+ # noex and cflag point to an id but are really a long
74
+ node_elem_ref.sub!('id', 'cnt')
75
+ end
76
+
77
+ if node_elem_name == "rval" then
78
+ # rval points to a value but is really a node
79
+ node_elem_ref.sub!('value', 'node')
80
+ node_elem_name = '2nd'
81
+ end
82
+
83
+ case node_elem_ref
84
+ when /\.node/
85
+ puts <<-END
86
+ if(n->nd_#{node_elem_name})
87
+ {
88
+ dump_node_or_iseq_to_hash((VALUE)n->nd_#{node_elem_name}, node_hash);
89
+ return node_id(n->nd_#{node_elem_name});
90
+ }
91
+ else
92
+ {
93
+ return Qnil;
94
+ }
95
+ END
96
+ when /\.value$/
97
+ puts <<-END
98
+ switch(TYPE(n->nd_#{node_elem_name}))
99
+ {
100
+ case T_CLASS:
101
+ case T_MODULE:
102
+ {
103
+ /* When dumping a class, we dump just the name (otherwise we'd
104
+ * get multiple copies of the class each time we load a method
105
+ * on the other side).
106
+ */
107
+ VALUE klass = (VALUE)n->nd_#{node_elem_name};
108
+ VALUE path;
109
+ if(FL_TEST(klass, FL_SINGLETON))
110
+ {
111
+ VALUE singleton = rb_iv_get(klass, "__attached__");
112
+ path = rb_class_path(singleton);
113
+ }
114
+ else
115
+ {
116
+ path = rb_class_path(klass);
117
+ if(STR2CSTR(path)[0] == '#')
118
+ {
119
+ rb_raise(rb_eArgError, "cannot dump anonymous class");
120
+ }
121
+ }
122
+ return rb_assoc_new(
123
+ INT2NUM(((struct RBasic *)(n->nd_#{node_elem_name}))->flags),
124
+ path);
125
+ }
126
+
127
+ default:
128
+ /* TODO: would like to dump flags, not type */
129
+ return rb_assoc_new(
130
+ INT2NUM(TYPE((VALUE)n->nd_#{node_elem_name})),
131
+ (VALUE)n->nd_#{node_elem_name});
132
+ }
133
+ END
134
+ when /\.id$/
135
+ puts <<-END
136
+ if(n->nd_#{node_elem_name} == 0)
137
+ {
138
+ return Qnil;
139
+ }
140
+ else
141
+ {
142
+ return ID2SYM(n->nd_#{node_elem_name});
143
+ }
144
+ END
145
+ when /\.(argc|state|cnt)$/
146
+ puts <<-END
147
+ {
148
+ return LONG2NUM((long)n->nd_#{node_elem_name});
149
+ }
150
+ END
151
+ when /\.(tbl)$/
152
+ puts <<-END
153
+ {
154
+ VALUE v = variable_names(n->nd_#{node_elem_name});
155
+ return v;
156
+ }
157
+ END
158
+ when /\.(entry)$/
159
+ puts <<-END
160
+ if(n->nd_#{node_elem_name}->id == 0)
161
+ {
162
+ rb_raise(
163
+ rb_eRuntimeError,
164
+ "Invalid ID for #{node_elem_name} (node type %d)",
165
+ nd_type(n));
166
+ }
167
+ return ID2SYM(n->nd_#{node_elem_name}->id);
168
+ END
169
+ when /\.(cfunc)$/
170
+ puts <<-END
171
+ /* rb_funcall(rb_cObject, rb_intern("pp"), wrap_node(n), 0); */
172
+ rb_raise(rb_eArgError, "Cannot dump #{$1}");
173
+ END
174
+ end
175
+ end
176
+ nil
177
+ END
178
+ }
179
+ rb_raise(rb_eArgError, "Invalid Node_Elem_Name %d", nen);
180
+ }
181
+
182
+ void load_node_elem(enum Node_Elem_Name nen, VALUE v, NODE * n, VALUE node_hash, VALUE id_hash)
183
+ {
184
+ switch(nen)
185
+ {
186
+ case NEN_NONE:
187
+ return;
188
+ #ruby <<END
189
+ NODEINFO.sort.each do |node_elem_name, node_elem_ref|
190
+ puts <<-END
191
+ case NEN_#{node_elem_name.upcase}:
192
+ {
193
+ END
194
+
195
+ if node_elem_name == "noex" or node_elem_name == "cflag" then
196
+ # noex and cflag point to an id but are really a long
197
+ node_elem_ref.sub!('id', 'cnt')
198
+ end
199
+
200
+ if node_elem_name == "rval" then
201
+ # rval points to a value but is really a node
202
+ node_elem_ref.sub!('value', 'node')
203
+ node_elem_name = '2nd'
204
+ end
205
+
206
+ case node_elem_ref
207
+ when /\.node$/
208
+ puts <<-END
209
+ if(v == Qnil)
210
+ {
211
+ n->nd_#{node_elem_name} = 0;
212
+ }
213
+ else
214
+ {
215
+ VALUE nid = rb_hash_aref(id_hash, v);
216
+ if(RTEST(nid))
217
+ {
218
+ n->nd_#{node_elem_name} = id_to_node(nid);
219
+ }
220
+ else
221
+ {
222
+ n->#{node_elem_ref} = (NODE *)load_node_or_iseq_from_hash(
223
+ v, node_hash, id_hash);
224
+ }
225
+ }
226
+ return;
227
+ END
228
+ when /\.value$/
229
+ puts <<-END
230
+ Check_Type(v, T_ARRAY);
231
+ if(RARRAY_LEN(v) != 2)
232
+ {
233
+ rb_raise(rb_eArgError, "wrong size for array");
234
+ }
235
+ int flags = NUM2INT(RARRAY_PTR(v)[0]);
236
+ switch(flags & T_MASK)
237
+ {
238
+ case T_CLASS:
239
+ case T_MODULE:
240
+ {
241
+ VALUE str = RARRAY_PTR(v)[1];
242
+ Check_Type(str, T_STRING);
243
+ VALUE klass = rb_path2class(STR2CSTR(str));
244
+ if(flags & FL_SINGLETON)
245
+ {
246
+ *(VALUE *)(&n->nd_#{node_elem_name}) =
247
+ rb_singleton_class(klass);
248
+ }
249
+ else
250
+ {
251
+ *(VALUE *)(&n->nd_#{node_elem_name}) =
252
+ klass;
253
+ }
254
+ break;
255
+ }
256
+ default:
257
+ *(VALUE *)(&n->nd_#{node_elem_name}) = RARRAY_PTR(v)[1];
258
+ break;
259
+ }
260
+ return;
261
+ END
262
+ when /\.id$/
263
+ puts <<-END
264
+ if(NIL_P(v))
265
+ {
266
+ n->nd_#{node_elem_name} = 0;
267
+ }
268
+ else
269
+ {
270
+ n->nd_#{node_elem_name} = SYM2ID(v);
271
+ }
272
+ return;
273
+ END
274
+ when /\.(argc|state|cnt)$/
275
+ puts <<-END
276
+ n->nd_#{node_elem_name} = NUM2LONG(v);
277
+ return;
278
+ END
279
+ when /\.(tbl)$/
280
+ puts <<-END
281
+ if(v == Qnil)
282
+ {
283
+ n->nd_#{node_elem_name} = 0;
284
+ }
285
+ else
286
+ {
287
+ size_t len, j;
288
+ ID * tmp_tbl;
289
+
290
+ Check_Type(v, T_ARRAY);
291
+ len = RARRAY_LEN(v);
292
+ tmp_tbl = ALLOCA_N(ID, len + 3);
293
+ tmp_tbl[0] = (ID)(len + 2);
294
+ tmp_tbl[1] = (ID)('_');
295
+ tmp_tbl[2] = (ID)('~');
296
+ for(j = 0; j < len; ++j)
297
+ {
298
+ VALUE e = RARRAY_PTR(v)[j];
299
+ if(e == Qnil)
300
+ {
301
+ /* flip state */
302
+ tmp_tbl[j + 3] = 0;
303
+ }
304
+ else
305
+ {
306
+ tmp_tbl[j + 3] = SYM2ID(e);
307
+ }
308
+ }
309
+ n->nd_#{node_elem_name} = ALLOC_N(ID, len + 3);
310
+ memcpy(n->nd_#{node_elem_name}, tmp_tbl, sizeof(ID) * (len + 3));
311
+ }
312
+ return;
313
+ END
314
+ when /\.(entry)$/
315
+ puts <<-END
316
+ n->nd_#{node_elem_name} = rb_global_entry(SYM2ID(v));
317
+ return;
318
+ END
319
+ when /\.(cfunc)$/
320
+ puts <<-END
321
+ rb_raise(rb_eRuntimeError, "Cannot load #{$1}");
322
+ END
323
+ end
324
+ puts <<-END
325
+ }
326
+ END
327
+ end
328
+ nil
329
+ END
330
+ }
331
+ rb_raise(rb_eRuntimeError, "Internal error: invalid Node_Elem_Name %d", nen);
332
+ }
333
+
334
+ #ruby <<END
335
+ NODEINFO.sort.each do |node_elem_name, node_elem_ref|
336
+ # get rid of warning about unused functions
337
+ nen = node_elem_name.upcase
338
+ next if NEN_TO_NODE_TYPE[nen].nil?
339
+
340
+ if node_elem_name == "noex" or node_elem_name == "cflag" then
341
+ # noex and cflag point to an id but are really a long
342
+ node_elem_ref.sub!('id', 'cnt')
343
+ end
344
+
345
+ case node_elem_ref
346
+ when /\.node$/, /\.value$/
347
+ puts <<-END
348
+ /*
349
+ * Return the Node's _#{node_elem_name}_ member. The return type is
350
+ * either a Node or an Object.
351
+ */
352
+ static VALUE node_#{node_elem_name}(VALUE self)
353
+ {
354
+ NODE * n;
355
+ Data_Get_Struct(self, NODE, n);
356
+
357
+ if(TYPE(n->nd_#{node_elem_name}) == T_NODE)
358
+ {
359
+ return wrap_node((NODE *)n->nd_#{node_elem_name});
360
+ }
361
+ else
362
+ {
363
+ return (VALUE)n->nd_#{node_elem_name};
364
+ }
365
+ }
366
+ END
367
+ when /\.id$/
368
+ puts <<-END
369
+ /*
370
+ * Return the Node's _#{node_elem_name}_ member. The return type is a
371
+ * Symbol.
372
+ */
373
+ static VALUE node_#{node_elem_name}(VALUE self)
374
+ {
375
+ NODE * n;
376
+ Data_Get_Struct(self, NODE, n);
377
+ if(n->nd_#{node_elem_name} == 0)
378
+ {
379
+ rb_raise(
380
+ rb_eRuntimeError,
381
+ "Invalid ID for #{node_elem_name} (node type=%d)",
382
+ nd_type(n));
383
+ }
384
+ return ID2SYM(n->nd_#{node_elem_name});
385
+ }
386
+ END
387
+ when /\.(argc|state|cnt)$/
388
+ puts <<-END
389
+ /*
390
+ * Return the Node's _#{node_elem_name}_ member. The return type is an
391
+ * Integer.
392
+ */
393
+ static VALUE node_#{node_elem_name}(VALUE self)
394
+ {
395
+ NODE * n;
396
+ Data_Get_Struct(self, NODE, n);
397
+ return LONG2NUM(n->nd_#{node_elem_name});
398
+ }
399
+ END
400
+ when /\.(tbl)$/
401
+ puts <<-END
402
+ /*
403
+ * Return the Node's _#{node_elem_name}_ member. The return value is an
404
+ * Array holding names of variables.
405
+ */
406
+ static VALUE node_#{node_elem_name}(VALUE self)
407
+ {
408
+ NODE * n;
409
+ Data_Get_Struct(self, NODE, n);
410
+ return variable_names(n->nd_#{node_elem_name});
411
+ }
412
+ END
413
+ when /\.(entry)$/
414
+ puts <<-END
415
+ /*
416
+ * Return the Node's _#{node_elem_name}_ member. The return type is
417
+ * either a Node or an Object.
418
+ */
419
+ static VALUE node_#{node_elem_name}(VALUE self)
420
+ {
421
+ NODE * n;
422
+ Data_Get_Struct(self, NODE, n);
423
+ if(n->nd_#{node_elem_name}->id == 0)
424
+ {
425
+ rb_raise(
426
+ rb_eRuntimeError,
427
+ "Invalid ID for #{node_elem_name} (node type %d)",
428
+ nd_type(n));
429
+ }
430
+ return ID2SYM(n->nd_#{node_elem_name}->id);
431
+ }
432
+ END
433
+ when /\.(cfunc)$/
434
+ puts <<-END
435
+ /*
436
+ * Return the Node's _#{node_elem_name}_ member. The return type is an
437
+ * integer representation of the #{node_elem_name}'s pointer.
438
+ */
439
+ static VALUE node_#{node_elem_name}(VALUE self)
440
+ {
441
+ NODE * n;
442
+ Data_Get_Struct(self, NODE, n);
443
+ return LONG2NUM((long)(n->nd_#{node_elem_name}));
444
+ }
445
+ END
446
+ end
447
+ end
448
+ nil
449
+ END
450
+
451
+ /*
452
+ * Return an array of strings containing the names of the node class's
453
+ * members.
454
+ */
455
+ VALUE node_s_members(VALUE klass)
456
+ {
457
+ return rb_iv_get(klass, "__member__");
458
+ }
459
+
460
+ void define_node_subclass_methods()
461
+ {
462
+ /* For rdoc: rb_cNode = rb_define_class("Node", rb_cObject); */
463
+ VALUE rb_cNode = rb_const_get(rb_cObject, rb_intern("Node"));
464
+ VALUE members;
465
+
466
+ #ruby <<END
467
+ NODE_TYPE_DESCRIPS.each do |descrip|
468
+
469
+ case descrip.name
470
+ when 'LAST'
471
+ next
472
+ when 'NIL', 'TRUE', 'FALSE'
473
+ name = "#{descrip.name}NODE"
474
+ else
475
+ name = descrip.name
476
+ end
477
+ node_type = "rb_c#{name}"
478
+
479
+ if name == 'ALLOCA' then
480
+ puts <<-END
481
+ #if defined(C_ALLOCA) || RUBY_VERSION_CODE >= 190
482
+ END
483
+ end
484
+
485
+ puts <<-END
486
+ {
487
+ VALUE #{node_type} = rb_define_class_under(rb_cNode, "#{name}", rb_cNode);
488
+ members = rb_ary_new();
489
+ rb_cNodeSubclass[NODE_#{descrip.name}] = #{node_type};
490
+ rb_iv_set(#{node_type}, "__member__", members);
491
+ rb_define_singleton_method(#{node_type}, "members", node_s_members, 0);
492
+ END
493
+ [descrip.node1, descrip.node2, descrip.node3].each do |nen|
494
+ next if nen == 'NONE'
495
+ nen = nen.downcase
496
+ mname = nen
497
+ mname = 'first' if nen == '1st'
498
+ mname = 'second' if nen == '2nd'
499
+ puts <<-END
500
+ rb_define_method(#{node_type}, "#{mname}", node_#{nen}, 0);
501
+ rb_ary_push(members, rb_str_new2("#{mname}"));
502
+ END
503
+ end
504
+ puts <<-END
505
+ }
506
+ END
507
+
508
+ if name == 'ALLOCA' then
509
+ puts <<-END
510
+ #endif
511
+ END
512
+ end
513
+
514
+ end
515
+ nil
516
+ END
517
+ }
518
+
519
+