rubynode 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -1,5 +1,9 @@
1
1
  Changelog
2
2
 
3
+ -- 0.1.2
4
+
5
+ * Out of the box 1.8.5-p2 and 1.8.5-p12 support
6
+
3
7
  -- 0.1.1
4
8
 
5
9
  * RubyNode is available as gem now
data/README CHANGED
@@ -14,9 +14,9 @@ s-expressions), which are easy to manipulate and work with.
14
14
  Requirements
15
15
  ------------
16
16
 
17
- RubyNode is tested with Ruby 1.8.4 and 1.8.5, but it should also work with
18
- other 1.8 versions and also with 1.9 (but there might be some node types that
19
- are not fully supported).
17
+ RubyNode is tested with Ruby 1.8.4 and 1.8.5 (including patchlevels 2 and 12),
18
+ but it should also work with other 1.8 versions and also with 1.9 (but there
19
+ might be some node types that are not fully supported).
20
20
 
21
21
 
22
22
  Installation
@@ -25,9 +25,10 @@ Installation
25
25
  RubyNode generates some of its C source code from Ruby's source code, because
26
26
  the node types and other details differ between Ruby versions.
27
27
 
28
- For the official releases of Ruby 1.8.4 and 1.8.5 the needed source files are
29
- included in the package. To compile RubyNode for any other Ruby version, you
30
- will need that version's source tar ball extracted somewhere.
28
+ For the official releases of Ruby 1.8.4 and 1.8.5 (including patchlevels 2 and
29
+ 12) the needed source files are included in the package. To compile RubyNode
30
+ for any other Ruby version, you will need that version's source tar ball
31
+ extracted somewhere.
31
32
 
32
33
  So, for Ruby 1.8.4 and 1.8.5 just run (as root):
33
34
 
data/doc/api.html CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
 
11
11
  <p>RubyNode consists of two parts: a C extension, which provides the core
12
- functionality and a Ruby library, which adds additional functionality.</p>
12
+ functionality, and a Ruby library, which adds additional functionality.</p>
13
13
 
14
14
 
15
15
  <p>To get only the C extension <code>require "rubynode_ext"</code>, to get the full
@@ -23,7 +23,7 @@ functionality (recommended) just <code>require "rubynode"</code>.</p>
23
23
 
24
24
 
25
25
  <p>Ruby mainly uses the NODEs to store the <span class="caps">AST</span> (abstract syntax tree) of parsed
26
- Ruby files, but they are also used for some other things. On the C side, <span class="caps">NODE</span>
26
+ Ruby files, but they are also used for some other things. On the C side <span class="caps">NODE</span>
27
27
  is a struct:</p>
28
28
 
29
29
 
@@ -135,11 +135,11 @@ interchangeably, they are just aliases.</p>
135
135
 
136
136
 
137
137
  <p><code>u1_as_long</code>, <code>u2_argc</code>, <code>u3_cnt</code> and <code>u3_state</code> always return the raw &#8220;long&#8221;,
138
- that is stored in the union as Integer.</p>
138
+ that is stored in the union, as Integer.</p>
139
139
 
140
140
 
141
141
  <p><code>u1_cfunc</code> returns the unsigned value of the function pointer, that is stored
142
- in the union as Integer.</p>
142
+ in the union, as Integer.</p>
143
143
 
144
144
 
145
145
  <p><code>u1_tbl</code> returns the local variable table for a scope node as an Array, for
@@ -147,7 +147,7 @@ all other node types it returns <code>nil</code>.</p>
147
147
 
148
148
 
149
149
  <p>All these methods never raise exceptions, they just return <code>nil</code>, if the
150
- value, that is stored in the union does not have the requested type.</p>
150
+ value that is stored in the union does not have the requested type.</p>
151
151
 
152
152
 
153
153
  <p><code>u3.entry</code> is not supported (for obvious reasons).</p>
@@ -216,7 +216,7 @@ Those nodes can be accessed using the methods <code>body_node</code>, <code>var_
216
216
 
217
217
  <p>RubyNode adds a <code>parse_to_nodes</code> method to String, which will parse the given
218
218
  string using Ruby&#8217;s parser. The parsing will be done in the current
219
- context/binding/scope, so it basically returns the <span class="caps">AST</span>, that eval would see,
219
+ context/binding/scope, so it basically returns the <span class="caps">AST</span> that eval would see,
220
220
  given this string.</p>
221
221
 
222
222
 
@@ -264,7 +264,7 @@ something like the following:</p>
264
264
  =&gt; {:lit=&gt;2}
265
265
  </code></pre>
266
266
 
267
- <p>So, there is an even nicer way: the method <code>transform</code>. It is basically a
267
+ <p>So, there is an even better way: the method <code>transform</code>. It is basically a
268
268
  recursive version of <code>attribs_hash</code>, it transforms a node tree into a tree of
269
269
  arrays and hashes. Example:</p>
270
270
 
data/doc/index.html CHANGED
@@ -24,9 +24,9 @@ s-expressions), which are easy to manipulate and work with.</p>
24
24
  <h2 id="section1">Requirements</h2>
25
25
 
26
26
 
27
- <p>RubyNode is tested with Ruby 1.8.4 and 1.8.5, but it should also work with
28
- other 1.8 versions and also with 1.9 (but there might be some node types that
29
- are not fully supported).</p>
27
+ <p>RubyNode is tested with Ruby 1.8.4 and 1.8.5 (including patchlevels 2 and 12),
28
+ but it should also work with other 1.8 versions and also with 1.9 (but there
29
+ might be some node types that are not fully supported).</p>
30
30
 
31
31
 
32
32
  <h2 id="section2">Download</h2>
@@ -45,9 +45,10 @@ are not fully supported).</p>
45
45
  the node types and other details differ between Ruby versions.</p>
46
46
 
47
47
 
48
- <p>For the official releases of Ruby 1.8.4 and 1.8.5 the needed source files are
49
- included in the package. To compile RubyNode for any other Ruby version, you
50
- will need that version&#8217;s source tar ball extracted somewhere.</p>
48
+ <p>For the official releases of Ruby 1.8.4 and 1.8.5 (including patchlevels 2 and
49
+ 12) the needed source files are included in the package. To compile RubyNode
50
+ for any other Ruby version, you will need that version&#8217;s source tar ball
51
+ extracted somewhere.</p>
51
52
 
52
53
 
53
54
  <p>So, for <strong>Ruby 1.8.4</strong> and <strong>1.8.5</strong> just run (as root):</p>
@@ -1,13 +1,21 @@
1
1
  require "mkmf"
2
2
 
3
- begin
4
- $rbsrcdir = File.join(File.dirname(__FILE__), "ruby_src/#{RUBY_VERSION}_#{RUBY_RELEASE_DATE}")
3
+ def ruby_source_dir_error(extra = nil)
4
+ warn "==================== ERROR ====================="
5
+ if extra
6
+ warn extra
7
+ warn ""
8
+ end
9
+ warn "Please set RUBY_SOURCE_DIR to the source path of ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE})!"
10
+ warn "================================================"
11
+ exit! 1
12
+ end
5
13
 
6
- $rbsrcdir = ENV["RUBY_SOURCE_DIR"] unless File.directory? $rbsrcdir
14
+ begin
15
+ $rbsrcdir = ENV["RUBY_SOURCE_DIR"] || File.join(File.dirname(__FILE__), "ruby_src/#{RUBY_VERSION}_#{RUBY_RELEASE_DATE}")
7
16
 
8
- unless $rbsrcdir
9
- warn "RUBY_SOURCE_DIR not set, please set it to the source path of ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE})!"
10
- exit! 1
17
+ unless File.directory? $rbsrcdir
18
+ ruby_source_dir_error
11
19
  end
12
20
 
13
21
  node_h = IO.read(File.join($rbsrcdir, "node.h"))
@@ -15,12 +23,8 @@ begin
15
23
  eval_c = IO.read(File.join($rbsrcdir, "eval.c"))
16
24
  # check if $hdrdir is "compatible" with $rbsrcdir
17
25
  unless node_h == IO.read(File.join($hdrdir, "node.h"))
18
- warn File.join($hdrdir, "node.h")
19
- warn "is different from"
20
- warn File.join($rbsrcdir, "node.h")
21
- warn ""
22
- warn "Please set RUBY_SOURCE_DIR to the source path of ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE})!"
23
- exit! 1
26
+ ruby_source_dir_error(File.join($hdrdir, "node.h") +
27
+ "\nis different from\n" + File.join($rbsrcdir, "node.h"))
24
28
  end
25
29
 
26
30
  raise "node.h does not contain 'enum node_type'" unless node_h =~ /enum node_type \{(.*?)\};/m
@@ -0,0 +1,44 @@
1
+ /**********************************************************************
2
+
3
+ eval.c -
4
+
5
+ $Author: matz $
6
+ $Date: 2006/08/07 03:43:39 $
7
+ created at: Thu Jun 10 14:22:17 JST 1993
8
+
9
+ Copyright (C) 1993-2003 Yukihiro Matsumoto
10
+ Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
11
+ Copyright (C) 2000 Information-technology Promotion Agency, Japan
12
+
13
+ **********************************************************************/
14
+
15
+ /* extract from eval.c from ruby 1.8.5 */
16
+
17
+ struct BLOCK {
18
+ NODE *var;
19
+ NODE *body;
20
+ VALUE self;
21
+ struct FRAME frame;
22
+ struct SCOPE *scope;
23
+ VALUE klass;
24
+ NODE *cref;
25
+ int iter;
26
+ int vmode;
27
+ int flags;
28
+ int uniq;
29
+ struct RVarmap *dyna_vars;
30
+ VALUE orig_thread;
31
+ VALUE wrapper;
32
+ VALUE block_obj;
33
+ struct BLOCK *outer;
34
+ struct BLOCK *prev;
35
+ };
36
+
37
+ struct METHOD {
38
+ VALUE klass, rklass;
39
+ VALUE recv;
40
+ ID id, oid;
41
+ int safe_level;
42
+ NODE *body;
43
+ };
44
+
@@ -0,0 +1,272 @@
1
+ /**********************************************************************
2
+
3
+ gc.c -
4
+
5
+ $Author: matz $
6
+ $Date: 2006/08/25 08:12:46 $
7
+ created at: Tue Oct 5 09:44:46 JST 1993
8
+
9
+ Copyright (C) 1993-2003 Yukihiro Matsumoto
10
+ Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
11
+ Copyright (C) 2000 Information-technology Promotion Agency, Japan
12
+
13
+ **********************************************************************/
14
+
15
+ /* extract from gc.c from ruby 1.8.5 */
16
+
17
+ static void
18
+ gc_mark_children(ptr, lev)
19
+ VALUE ptr;
20
+ int lev;
21
+ {
22
+ register RVALUE *obj = RANY(ptr);
23
+
24
+ goto marking; /* skip */
25
+
26
+ again:
27
+ obj = RANY(ptr);
28
+ if (rb_special_const_p(ptr)) return; /* special const not marked */
29
+ if (obj->as.basic.flags == 0) return; /* free cell */
30
+ if (obj->as.basic.flags & FL_MARK) return; /* already marked */
31
+ obj->as.basic.flags |= FL_MARK;
32
+
33
+ marking:
34
+ if (FL_TEST(obj, FL_EXIVAR)) {
35
+ rb_mark_generic_ivar(ptr);
36
+ }
37
+
38
+ switch (obj->as.basic.flags & T_MASK) {
39
+ case T_NIL:
40
+ case T_FIXNUM:
41
+ rb_bug("rb_gc_mark() called for broken object");
42
+ break;
43
+
44
+ case T_NODE:
45
+ mark_source_filename(obj->as.node.nd_file);
46
+ switch (nd_type(obj)) {
47
+ case NODE_IF: /* 1,2,3 */
48
+ case NODE_FOR:
49
+ case NODE_ITER:
50
+ case NODE_CREF:
51
+ case NODE_WHEN:
52
+ case NODE_MASGN:
53
+ case NODE_RESCUE:
54
+ case NODE_RESBODY:
55
+ case NODE_CLASS:
56
+ gc_mark((VALUE)obj->as.node.u2.node, lev);
57
+ /* fall through */
58
+ case NODE_BLOCK: /* 1,3 */
59
+ case NODE_ARRAY:
60
+ case NODE_DSTR:
61
+ case NODE_DXSTR:
62
+ case NODE_DREGX:
63
+ case NODE_DREGX_ONCE:
64
+ case NODE_FBODY:
65
+ case NODE_ENSURE:
66
+ case NODE_CALL:
67
+ case NODE_DEFS:
68
+ case NODE_OP_ASGN1:
69
+ gc_mark((VALUE)obj->as.node.u1.node, lev);
70
+ /* fall through */
71
+ case NODE_SUPER: /* 3 */
72
+ case NODE_FCALL:
73
+ case NODE_DEFN:
74
+ case NODE_NEWLINE:
75
+ ptr = (VALUE)obj->as.node.u3.node;
76
+ goto again;
77
+
78
+ case NODE_WHILE: /* 1,2 */
79
+ case NODE_UNTIL:
80
+ case NODE_AND:
81
+ case NODE_OR:
82
+ case NODE_CASE:
83
+ case NODE_SCLASS:
84
+ case NODE_DOT2:
85
+ case NODE_DOT3:
86
+ case NODE_FLIP2:
87
+ case NODE_FLIP3:
88
+ case NODE_MATCH2:
89
+ case NODE_MATCH3:
90
+ case NODE_OP_ASGN_OR:
91
+ case NODE_OP_ASGN_AND:
92
+ case NODE_MODULE:
93
+ case NODE_ALIAS:
94
+ case NODE_VALIAS:
95
+ case NODE_ARGS:
96
+ gc_mark((VALUE)obj->as.node.u1.node, lev);
97
+ /* fall through */
98
+ case NODE_METHOD: /* 2 */
99
+ case NODE_NOT:
100
+ case NODE_GASGN:
101
+ case NODE_LASGN:
102
+ case NODE_DASGN:
103
+ case NODE_DASGN_CURR:
104
+ case NODE_IASGN:
105
+ case NODE_CVDECL:
106
+ case NODE_CVASGN:
107
+ case NODE_COLON3:
108
+ case NODE_OPT_N:
109
+ case NODE_EVSTR:
110
+ case NODE_UNDEF:
111
+ ptr = (VALUE)obj->as.node.u2.node;
112
+ goto again;
113
+
114
+ case NODE_HASH: /* 1 */
115
+ case NODE_LIT:
116
+ case NODE_STR:
117
+ case NODE_XSTR:
118
+ case NODE_DEFINED:
119
+ case NODE_MATCH:
120
+ case NODE_RETURN:
121
+ case NODE_BREAK:
122
+ case NODE_NEXT:
123
+ case NODE_YIELD:
124
+ case NODE_COLON2:
125
+ case NODE_SPLAT:
126
+ case NODE_TO_ARY:
127
+ case NODE_SVALUE:
128
+ ptr = (VALUE)obj->as.node.u1.node;
129
+ goto again;
130
+
131
+ case NODE_SCOPE: /* 2,3 */
132
+ case NODE_BLOCK_PASS:
133
+ case NODE_CDECL:
134
+ gc_mark((VALUE)obj->as.node.u3.node, lev);
135
+ ptr = (VALUE)obj->as.node.u2.node;
136
+ goto again;
137
+
138
+ case NODE_ZARRAY: /* - */
139
+ case NODE_ZSUPER:
140
+ case NODE_CFUNC:
141
+ case NODE_VCALL:
142
+ case NODE_GVAR:
143
+ case NODE_LVAR:
144
+ case NODE_DVAR:
145
+ case NODE_IVAR:
146
+ case NODE_CVAR:
147
+ case NODE_NTH_REF:
148
+ case NODE_BACK_REF:
149
+ case NODE_REDO:
150
+ case NODE_RETRY:
151
+ case NODE_SELF:
152
+ case NODE_NIL:
153
+ case NODE_TRUE:
154
+ case NODE_FALSE:
155
+ case NODE_ATTRSET:
156
+ case NODE_BLOCK_ARG:
157
+ case NODE_POSTEXE:
158
+ break;
159
+ case NODE_ALLOCA:
160
+ mark_locations_array((VALUE*)obj->as.node.u1.value,
161
+ obj->as.node.u3.cnt);
162
+ ptr = (VALUE)obj->as.node.u2.node;
163
+ goto again;
164
+
165
+ default: /* unlisted NODE */
166
+ if (is_pointer_to_heap(obj->as.node.u1.node)) {
167
+ gc_mark((VALUE)obj->as.node.u1.node, lev);
168
+ }
169
+ if (is_pointer_to_heap(obj->as.node.u2.node)) {
170
+ gc_mark((VALUE)obj->as.node.u2.node, lev);
171
+ }
172
+ if (is_pointer_to_heap(obj->as.node.u3.node)) {
173
+ gc_mark((VALUE)obj->as.node.u3.node, lev);
174
+ }
175
+ }
176
+ return; /* no need to mark class. */
177
+ }
178
+
179
+ gc_mark(obj->as.basic.klass, lev);
180
+ switch (obj->as.basic.flags & T_MASK) {
181
+ case T_ICLASS:
182
+ case T_CLASS:
183
+ case T_MODULE:
184
+ mark_tbl(obj->as.klass.m_tbl, lev);
185
+ mark_tbl(obj->as.klass.iv_tbl, lev);
186
+ ptr = obj->as.klass.super;
187
+ goto again;
188
+
189
+ case T_ARRAY:
190
+ if (FL_TEST(obj, ELTS_SHARED)) {
191
+ ptr = obj->as.array.aux.shared;
192
+ goto again;
193
+ }
194
+ else {
195
+ long i, len = obj->as.array.len;
196
+ VALUE *ptr = obj->as.array.ptr;
197
+
198
+ for (i=0; i < len; i++) {
199
+ gc_mark(*ptr++, lev);
200
+ }
201
+ }
202
+ break;
203
+
204
+ case T_HASH:
205
+ mark_hash(obj->as.hash.tbl, lev);
206
+ ptr = obj->as.hash.ifnone;
207
+ goto again;
208
+
209
+ case T_STRING:
210
+ #define STR_ASSOC FL_USER3 /* copied from string.c */
211
+ if (FL_TEST(obj, ELTS_SHARED|STR_ASSOC)) {
212
+ ptr = obj->as.string.aux.shared;
213
+ goto again;
214
+ }
215
+ break;
216
+
217
+ case T_DATA:
218
+ if (obj->as.data.dmark) (*obj->as.data.dmark)(DATA_PTR(obj));
219
+ break;
220
+
221
+ case T_OBJECT:
222
+ mark_tbl(obj->as.object.iv_tbl, lev);
223
+ break;
224
+
225
+ case T_FILE:
226
+ case T_REGEXP:
227
+ case T_FLOAT:
228
+ case T_BIGNUM:
229
+ case T_BLKTAG:
230
+ break;
231
+
232
+ case T_MATCH:
233
+ if (obj->as.match.str) {
234
+ ptr = obj->as.match.str;
235
+ goto again;
236
+ }
237
+ break;
238
+
239
+ case T_VARMAP:
240
+ gc_mark(obj->as.varmap.val, lev);
241
+ ptr = (VALUE)obj->as.varmap.next;
242
+ goto again;
243
+
244
+ case T_SCOPE:
245
+ if (obj->as.scope.local_vars && (obj->as.scope.flags & SCOPE_MALLOC)) {
246
+ int n = obj->as.scope.local_tbl[0]+1;
247
+ VALUE *vars = &obj->as.scope.local_vars[-1];
248
+
249
+ while (n--) {
250
+ gc_mark(*vars++, lev);
251
+ }
252
+ }
253
+ break;
254
+
255
+ case T_STRUCT:
256
+ {
257
+ long len = obj->as.rstruct.len;
258
+ VALUE *ptr = obj->as.rstruct.ptr;
259
+
260
+ while (len--) {
261
+ gc_mark(*ptr++, lev);
262
+ }
263
+ }
264
+ break;
265
+
266
+ default:
267
+ rb_bug("rb_gc_mark(): unknown data type 0x%lx(0x%lx) %s",
268
+ obj->as.basic.flags & T_MASK, obj,
269
+ is_pointer_to_heap(obj) ? "corrupted object" : "non object");
270
+ }
271
+ }
272
+