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,64 @@
1
+ #ifndef nodeinfo_h
2
+ #define nodeinfo_h
3
+
4
+ #include "ruby.h"
5
+ #include "node.h"
6
+ #include "nodewrap.h"
7
+
8
+ enum Node_Elem_Name
9
+ {
10
+ NEN_NONE,
11
+ NEN_1ST,
12
+ NEN_2ND,
13
+ NEN_AID,
14
+ NEN_ALEN,
15
+ NEN_ARGC,
16
+ NEN_ARGS,
17
+ NEN_BEG,
18
+ NEN_BODY,
19
+ NEN_CFLAG,
20
+ NEN_CFNC,
21
+ NEN_CLSS,
22
+ NEN_CNT,
23
+ NEN_COND,
24
+ NEN_CPATH,
25
+ NEN_CVAL,
26
+ NEN_DEFN,
27
+ NEN_ELSE,
28
+ NEN_END,
29
+ NEN_ENSR,
30
+ NEN_ENTRY,
31
+ NEN_FRML,
32
+ NEN_HEAD,
33
+ NEN_IBDY,
34
+ NEN_ITER,
35
+ NEN_LIT,
36
+ NEN_MID,
37
+ NEN_MODL,
38
+ NEN_NEXT,
39
+ NEN_NOEX,
40
+ NEN_NTH,
41
+ NEN_OPT,
42
+ NEN_ORIG,
43
+ NEN_RECV,
44
+ NEN_RESQ,
45
+ NEN_REST,
46
+ NEN_RVAL,
47
+ NEN_STATE,
48
+ NEN_STTS,
49
+ NEN_SUPER,
50
+ NEN_TAG,
51
+ NEN_TBL,
52
+ NEN_TVAL,
53
+ NEN_VALUE,
54
+ NEN_VAR,
55
+ NEN_VID,
56
+ };
57
+
58
+ VALUE dump_node_elem(enum Node_Elem_Name nen, NODE * n, VALUE node_hash);
59
+ void load_node_elem(enum Node_Elem_Name nen, VALUE v, NODE * n, VALUE node_hash, VALUE id_hash);
60
+ VALUE node_s_members(VALUE klass);
61
+ void define_node_subclass_methods();
62
+
63
+ #endif
64
+
@@ -0,0 +1,42 @@
1
+ #include "classpath.h"
2
+
3
+ VALUE
4
+ class2path(VALUE klass)
5
+ {
6
+ VALUE path = rb_class_path(klass);
7
+ char *n = RSTRING_PTR(path);
8
+
9
+ if (n[0] == '#') {
10
+ rb_raise(rb_eTypeError, "can't dump anonymous %s %s",
11
+ (TYPE(klass) == T_CLASS ? "class" : "module"),
12
+ n);
13
+ }
14
+ if (rb_path2class(n) != rb_class_real(klass)) {
15
+ rb_raise(rb_eTypeError, "%s can't be referred", n);
16
+ }
17
+ return path;
18
+ }
19
+
20
+ VALUE
21
+ path2class(const char *path)
22
+ {
23
+ VALUE v = rb_path2class(path);
24
+
25
+ if (TYPE(v) != T_CLASS) {
26
+ rb_raise(rb_eArgError, "%s does not refer class", path);
27
+ }
28
+ return v;
29
+ }
30
+
31
+ VALUE
32
+ path2module(const char *path)
33
+ {
34
+ VALUE v = rb_path2class(path);
35
+
36
+ if (TYPE(v) != T_MODULE) {
37
+ rb_raise(rb_eArgError, "%s does not refer module", path);
38
+ }
39
+ return v;
40
+ }
41
+
42
+
@@ -0,0 +1,28 @@
1
+ #include "classpath.h"
2
+
3
+ #ruby <<END
4
+ require 'ruby_source_dir'
5
+
6
+ marshal_c_location = "#{RUBY_SOURCE_DIR}/marshal.c"
7
+ File.open(marshal_c_location) do |marshal_c|
8
+ write = false
9
+ stopwrite = false
10
+ while (line = marshal_c.gets) != nil do
11
+ case line
12
+ when /^(path2class|path2module|class2path)/
13
+ puts "VALUE" if not write
14
+ write = true
15
+ stopwrite = false
16
+ when /^\}/
17
+ stopwrite = true if write
18
+ end
19
+ puts line if write
20
+ if stopwrite then
21
+ stopwrite = false
22
+ write = false
23
+ puts ''
24
+ end
25
+ end
26
+ end
27
+ END
28
+
@@ -0,0 +1,17 @@
1
+ #ifndef CLASSPATH_H
2
+ #define CLASSPATH_H
3
+
4
+ #include "ruby.h"
5
+
6
+ VALUE class2path(
7
+
8
+ );
9
+ VALUE path2class(
10
+
11
+ );
12
+ VALUE path2module(
13
+
14
+ );
15
+
16
+ #endif
17
+
@@ -0,0 +1,35 @@
1
+ #ifndef CLASSPATH_H
2
+ #define CLASSPATH_H
3
+
4
+ #include "ruby.h"
5
+
6
+ #ruby <<END
7
+ require 'ruby_source_dir'
8
+
9
+ defn = nil
10
+ marshal_c_location = "#{RUBY_SOURCE_DIR}/marshal.c"
11
+ File.open(marshal_c_location) do |marshal_c|
12
+ write = false
13
+ while (line = marshal_c.gets) != nil do
14
+ case line
15
+ when /^(path2class|path2module|class2path)/
16
+ record_defn = true
17
+ defn = []
18
+ when /^\{/
19
+ if record_defn then
20
+ record_defn = false
21
+ puts "VALUE #{defn[0].sub(/\(.*/, '')}("
22
+ vars = defn[1..-1].map { |d| d.sub(/;.*/, '') }
23
+ puts vars.join(",\n")
24
+ puts ");"
25
+ end
26
+ end
27
+ if record_defn then
28
+ defn << line.chomp
29
+ end
30
+ end
31
+ end
32
+ END
33
+
34
+ #endif
35
+
@@ -0,0 +1,21 @@
1
+ #ifndef evalinfo__h_
2
+ #define evalinfo__h_
3
+
4
+ #include "ruby_version.h"
5
+
6
+ #ifdef RUBY_HAS_YARV
7
+ #include "yarvcore.h"
8
+ #else
9
+ #include "env.h"
10
+ #endif
11
+
12
+ struct METHOD {
13
+ VALUE klass, rklass;
14
+ VALUE recv;
15
+ ID id, oid;
16
+ NODE *body;
17
+ };
18
+
19
+
20
+ #endif
21
+
@@ -0,0 +1,49 @@
1
+ #ifndef evalinfo__h_
2
+ #define evalinfo__h_
3
+
4
+ #include "ruby_version.h"
5
+
6
+ #ifdef RUBY_HAS_YARV
7
+ #include "yarvcore.h"
8
+ #else
9
+ #include "env.h"
10
+ #endif
11
+
12
+ #ruby <<END
13
+ require 'ruby_source_dir'
14
+ proc_c_location = "#{RUBY_SOURCE_DIR}/proc.c"
15
+ vm_c_location = "#{RUBY_SOURCE_DIR}/vm.c"
16
+ eval_c_location = "#{RUBY_SOURCE_DIR}/eval.c"
17
+
18
+ [ proc_c_location, vm_c_location, eval_c_location ].each do |file|
19
+ next if not File.exist?(file)
20
+
21
+ File.open(file) do |eval_c|
22
+ write = false
23
+ stopwrite = false
24
+ while (line = eval_c.gets) != nil do
25
+ case line
26
+ when /^struct (METHOD|BLOCK)/
27
+ write = true
28
+ stopwrite = false
29
+ when /^compile_error/
30
+ puts 'static void'
31
+ write = true
32
+ stopwrite = false
33
+ when /^\}/
34
+ stopwrite = true if write
35
+ end
36
+ puts line if write
37
+ if stopwrite then
38
+ stopwrite = false
39
+ write = false
40
+ puts ''
41
+ end
42
+ end
43
+ end
44
+ end
45
+ nil
46
+ END
47
+
48
+ #endif
49
+
@@ -0,0 +1,68 @@
1
+ require 'mkmf'
2
+
3
+ cmdline_ruby_source_path = arg_config('--ruby-source-path')
4
+ configured_ruby_source_dir = nil
5
+ begin
6
+ require 'ruby_source_dir'
7
+ configured_ruby_source_dir = RUBY_SOURCE_DIR
8
+ rescue InstallError
9
+ end
10
+
11
+ rb_files = Dir['*.rb']
12
+
13
+ rpp_files = Dir['*.rpp']
14
+ generated_files = rpp_files.map { |f| f.sub(/\.rpp$/, '') }
15
+
16
+ srcs = Dir['*.c']
17
+ generated_files.each do |f|
18
+ if f =~ /\.c$/ then
19
+ srcs << f
20
+ end
21
+ end
22
+ srcs.uniq!
23
+ $objs = srcs.map { |f| f.sub(/\.c$/, ".#{$OBJEXT}") }
24
+ $CFLAGS << ' -Wall -g'
25
+ create_makefile('nodewrap')
26
+
27
+ append_to_makefile = ''
28
+
29
+ # (nil and not configured => cached
30
+ # '' => cached
31
+ # not configured => cached
32
+
33
+ if (not cmdline_ruby_source_path and not configured_ruby_source_dir) or \
34
+ cmdline_ruby_source_path == '' then
35
+
36
+ rpp_files.each do |rpp_file|
37
+ dest_file = rpp_file.sub(/\.rpp$/, '')
38
+ append_to_makefile << <<END
39
+ #{dest_file}: #{rpp_file} #{rb_files.join(' ')}
40
+ @$(RUBY) -rftools -e 'File.copy("cached/ruby-#{RUBY_VERSION}/#{dest_file}", ".", true)'
41
+ END
42
+ end
43
+
44
+ else
45
+
46
+ rpp_files.each do |rpp_file|
47
+ dest_file = rpp_file.sub(/\.rpp$/, '')
48
+ append_to_makefile << <<END
49
+ #{dest_file}: #{rpp_file} #{rb_files.join(' ')}
50
+ $(RUBY) rubypp.rb #{rpp_file} #{dest_file}
51
+ END
52
+ end
53
+
54
+
55
+ end
56
+
57
+ generated_headers = generated_files.select { |x| x =~ /\.h$/ }
58
+ append_to_makefile << <<END
59
+ $(OBJS): #{generated_headers.join(' ')}
60
+ clean: clean_generated_files
61
+ clean_generated_files:
62
+ @$(RM) #{generated_files.join(' ')}
63
+ END
64
+
65
+ File.open('Makefile', 'a') do |makefile|
66
+ makefile.puts(append_to_makefile)
67
+ end
68
+
@@ -0,0 +1,201 @@
1
+ require 'rbconfig'
2
+ require 'ruby_source_dir'
3
+
4
+ class Pattern
5
+ attr_reader :search_files
6
+
7
+ def initialize(*search_files)
8
+ @search_files = search_files
9
+ end
10
+
11
+ def matches_start(str)
12
+ return false
13
+ end
14
+
15
+ def matches_end(str)
16
+ return true
17
+ end
18
+
19
+ def dump(captured, out)
20
+ captured.each do |line|
21
+ out.puts line
22
+ end
23
+ out.puts ''
24
+ end
25
+ end
26
+
27
+ class FunctionDefinitionPattern < Pattern
28
+ def initialize(return_type, name, *search_files)
29
+ @return_type = return_type
30
+ @name = name
31
+ super(*search_files)
32
+ end
33
+
34
+ def matches_start(str)
35
+ return str =~ /^#{@name}/
36
+ end
37
+
38
+ def matches_end(str)
39
+ return str =~ /^\}/
40
+ end
41
+
42
+ def dump(captured, out)
43
+ out.puts @return_type
44
+ super(captured, out)
45
+ end
46
+ end
47
+
48
+ def FunctionDefinition(return_type, name, *search_files)
49
+ return FunctionDefinitionPattern.new(return_type, name, *search_files)
50
+ end
51
+
52
+ class FunctionDeclarationPattern < Pattern
53
+ def initialize(name, *search_files)
54
+ @name = name
55
+ super(*search_files)
56
+ end
57
+ end
58
+
59
+ def FunctionDeclaration(name, *search_files)
60
+ return FunctionDeclarationPattern.new(name, *search_files)
61
+ end
62
+
63
+ class StructPattern < Pattern
64
+ def initialize(name, *search_files)
65
+ @name = name
66
+ super(*search_files)
67
+ end
68
+ end
69
+
70
+ def Struct(name, *search_files)
71
+ return StructPattern.new(name, *search_files)
72
+ end
73
+
74
+ class IncludePattern < Pattern
75
+ def initialize(name, use_quotes=false)
76
+ @name = name
77
+ @use_quotes = false
78
+ super()
79
+ end
80
+
81
+ def dump(captured, out)
82
+ if @use_quotes then
83
+ out.puts "#include \"#{@name}\""
84
+ else
85
+ out.puts "#include <#{@name}>"
86
+ end
87
+ end
88
+ end
89
+
90
+ def Include(name, use_quotes=false)
91
+ return IncludePattern.new(name, use_quotes)
92
+ end
93
+
94
+ class IfDefPattern
95
+ def initialize(name, iftrue, iffalse)
96
+ @name = name
97
+ @iftrue = iftrue
98
+ @iffalse = iffalse
99
+ super()
100
+ end
101
+
102
+ def matches_start(str)
103
+ return @iftrue.matches_start(str) || @iffalse.matches_start(str)
104
+ end
105
+
106
+ def matches_end(str)
107
+ return @iftrue.matches_end(str) || @iffalse.matches_end(str)
108
+ end
109
+
110
+ def dump(captured, out)
111
+ out.puts "#ifdef #{@name}"
112
+ @iftrue.dump(captured, out)
113
+ out.puts "#else"
114
+ @iffalse.dump(captured, out)
115
+ out.puts "#endif"
116
+ end
117
+ end
118
+
119
+ def IfDefined(name, iftrue, iffalse)
120
+ return IfDefPattern.new(name, iftrue, iffalse)
121
+ end
122
+
123
+ class BlankLinePattern < Pattern
124
+ def initialize()
125
+ super()
126
+ end
127
+
128
+ def dump(captured, out)
129
+ out.puts
130
+ end
131
+ end
132
+
133
+ def BlankLine
134
+ return BlankLinePattern.new
135
+ end
136
+
137
+
138
+ def generate(patterns, io, out)
139
+ found = {}
140
+ using = {}
141
+ captured = {}
142
+
143
+ while (line = io.gets) != nil do
144
+ patterns.each do |pattern|
145
+ if pattern.matches_start(line) then
146
+ found[pattern] = true
147
+ using[pattern] = true
148
+ end
149
+
150
+ if using[pattern] then
151
+ captured[pattern] ||= []
152
+ captured[pattern] << line
153
+ end
154
+
155
+ if using[pattern] and pattern.matches_end(line) then
156
+ using.delete(pattern)
157
+ end
158
+ end
159
+ end
160
+
161
+ patterns.each do |pattern|
162
+ pattern.dump(captured[pattern], out)
163
+ end
164
+ end
165
+
166
+
167
+
168
+ G = {
169
+ 'classpath.c' => [
170
+ Include('classpath.h', true),
171
+ BlankLine(),
172
+ FunctionDefinition('VALUE', 'path2class', 'marshal.c'),
173
+ FunctionDefinition('VALUE', 'path2module', 'marshal.c'),
174
+ FunctionDefinition('VALUE', 'class2path', 'marshal.c'),
175
+ ],
176
+ 'classpath.h' => [
177
+ Include('ruby.h'),
178
+ FunctionDeclaration('path2class', 'marshal.c'),
179
+ FunctionDeclaration('path2module', 'marshal.c'),
180
+ FunctionDeclaration('class2path', 'marshal.c'),
181
+ ],
182
+ 'global_entry.h' => [
183
+ Include('ruby.h'),
184
+ Struct('global_entry', 'variable.c'),
185
+ ],
186
+ 'evalinfo.h' => [
187
+ Include('ruby_version.h'),
188
+ IfDefined(
189
+ 'RUBY_HAS_YARV',
190
+ [ Include('yarvcore.h') ],
191
+ [ Include('env.h') ]
192
+ ),
193
+ Struct('METHOD', 'eval.c', 'proc.c'),
194
+ Struct('BLOCK', 'eval.c'),
195
+ ],
196
+ }
197
+
198
+ File.open("#{RUBY_SOURCE_DIR}/marshal.c") do |marshal_c|
199
+ generate(G['classpath.c'], marshal_c, $stdout)
200
+ end
201
+