rubynode 0.1.1
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.
- data/Changelog +15 -0
- data/README +84 -0
- data/doc/api.html +434 -0
- data/doc/index.html +170 -0
- data/doc/style.css +27 -0
- data/ext/rubynode_ext/extconf.rb +132 -0
- data/ext/rubynode_ext/ruby_src/1.8.4_2005-12-24/eval.c +44 -0
- data/ext/rubynode_ext/ruby_src/1.8.4_2005-12-24/gc.c +272 -0
- data/ext/rubynode_ext/ruby_src/1.8.4_2005-12-24/node.h +381 -0
- data/ext/rubynode_ext/ruby_src/1.8.5_2006-08-25/eval.c +44 -0
- data/ext/rubynode_ext/ruby_src/1.8.5_2006-08-25/gc.c +272 -0
- data/ext/rubynode_ext/ruby_src/1.8.5_2006-08-25/node.h +378 -0
- data/ext/rubynode_ext/rubynode_ext.c +368 -0
- data/lib/rubynode.rb +206 -0
- metadata +63 -0
data/doc/index.html
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>RubyNode</title>
|
5
|
+
<link href="style.css" media="all" rel="Stylesheet" type="text/css">
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<h1>RubyNode</h1>
|
9
|
+
|
10
|
+
|
11
|
+
<p>RubyNode is a library that allows read only access to Ruby’s internal <span class="caps">NODE</span>
|
12
|
+
structure. It can retrieve the node trees of methods and procs and it can use
|
13
|
+
Ruby’s parser to parse Ruby source code strings to node trees.</p>
|
14
|
+
|
15
|
+
|
16
|
+
<p>It provides the class RubyNode, which wraps an internal <span class="caps">NODE</span>. Trees of RubyNode
|
17
|
+
instances can also be transformed into trees of arrays and hashes (similar to
|
18
|
+
s-expressions), which are easy to manipulate and work with.</p>
|
19
|
+
|
20
|
+
|
21
|
+
<p>Sections: <a href="#section1">Requirements</a>, <a href="#section2">Download</a>, <a href="#section3">Installation</a>, <a href="#section4">Usage</a>, <a href="#section5">Feedback</a>, <a href="#section6">Thanks</a>, <a href="#section7">License</a>.</p>
|
22
|
+
|
23
|
+
|
24
|
+
<h2 id="section1">Requirements</h2>
|
25
|
+
|
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>
|
30
|
+
|
31
|
+
|
32
|
+
<h2 id="section2">Download</h2>
|
33
|
+
|
34
|
+
|
35
|
+
<ul>
|
36
|
+
<li><a href="http://rubyforge.org/projects/rubynode/">Project page</a></li>
|
37
|
+
<li><a href="http://rubyforge.org/frs/?group_id=1771">Download</a></li>
|
38
|
+
</ul>
|
39
|
+
|
40
|
+
|
41
|
+
<h2 id="section3">Installation</h2>
|
42
|
+
|
43
|
+
|
44
|
+
<p>RubyNode generates some of its C source code from Ruby’s source code, because
|
45
|
+
the node types and other details differ between Ruby versions.</p>
|
46
|
+
|
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’s source tar ball extracted somewhere.</p>
|
51
|
+
|
52
|
+
|
53
|
+
<p>So, for <strong>Ruby 1.8.4</strong> and <strong>1.8.5</strong> just run (as root):</p>
|
54
|
+
|
55
|
+
|
56
|
+
<pre><code>gem install rubynode
|
57
|
+
</code></pre>
|
58
|
+
|
59
|
+
<p>Or if you do not use the gem:</p>
|
60
|
+
|
61
|
+
|
62
|
+
<pre><code>ruby setup.rb
|
63
|
+
</code></pre>
|
64
|
+
|
65
|
+
<p>That command will compile the C extension and install all files to their
|
66
|
+
default location (to customize the non-gem installation, please see
|
67
|
+
<code>"ruby setup.rb --help"</code>)</p>
|
68
|
+
|
69
|
+
|
70
|
+
<p>For <strong>other Ruby versions</strong> you need to provide the (absolute) path to the source
|
71
|
+
directory for that Ruby version in the enviroment variable <code>RUBY_SOURCE_DIR</code>.
|
72
|
+
Example (as root):</p>
|
73
|
+
|
74
|
+
|
75
|
+
<pre><code>RUBY_SOURCE_DIR="/path/to/ruby_source" gem install rubynode
|
76
|
+
</code></pre>
|
77
|
+
|
78
|
+
<p>Or if you do not use the gem:</p>
|
79
|
+
|
80
|
+
|
81
|
+
<pre><code>RUBY_SOURCE_DIR="/path/to/ruby_source" ruby setup.rb
|
82
|
+
</code></pre>
|
83
|
+
|
84
|
+
<h2 id="section4">Usage</h2>
|
85
|
+
|
86
|
+
|
87
|
+
<p>Just <code>require "rubynode"</code> and use it. Here is a short irb sessions that shows
|
88
|
+
some of the things you can do with RubyNode:</p>
|
89
|
+
|
90
|
+
|
91
|
+
<pre><code>>> require "rubynode"
|
92
|
+
=> true
|
93
|
+
</code></pre>
|
94
|
+
|
95
|
+
<p>Body node of a method:</p>
|
96
|
+
|
97
|
+
|
98
|
+
<pre><code>>> def plus_1(x)
|
99
|
+
>> x + 1
|
100
|
+
>> end
|
101
|
+
=> nil
|
102
|
+
>> pp method(:plus_1).body_node.transform
|
103
|
+
[:scope,
|
104
|
+
{:next=>
|
105
|
+
[:block,
|
106
|
+
[[:args, {:rest=>-1, :cnt=>1, :opt=>false}],
|
107
|
+
[:call,
|
108
|
+
{:args=>[:array, [[:lit, {:lit=>1}]]],
|
109
|
+
:mid=>:+,
|
110
|
+
:recv=>[:lvar, {:vid=>:x, :cnt=>2}]}]]],
|
111
|
+
:rval=>[:cref, {:next=>false, :clss=>Object}],
|
112
|
+
:tbl=>[:x]}]
|
113
|
+
=> nil
|
114
|
+
</code></pre>
|
115
|
+
|
116
|
+
<p>Body node and var node of a proc:</p>
|
117
|
+
|
118
|
+
|
119
|
+
<pre><code>>> add_2 = proc { |x| x + 2 }
|
120
|
+
=> #<Proc:0xb7f24c00@(irb):6>
|
121
|
+
>> pp add_2.body_node.transform
|
122
|
+
[:call,
|
123
|
+
{:args=>[:array, [[:lit, {:lit=>2}]]], :mid=>:+, :recv=>[:dvar, {:vid=>:x}]}]
|
124
|
+
=> nil
|
125
|
+
>> pp add_2.var_node.transform
|
126
|
+
[:dasgn_curr, {:vid=>:x, :value=>false}]
|
127
|
+
=> nil
|
128
|
+
</code></pre>
|
129
|
+
|
130
|
+
<p>Parse a string to nodes:</p>
|
131
|
+
|
132
|
+
|
133
|
+
<pre><code>>> pp "3.times { puts 'Ruby' }".parse_to_nodes.transform
|
134
|
+
[:iter,
|
135
|
+
{:var=>false,
|
136
|
+
:iter=>[:call, {:args=>false, :mid=>:times, :recv=>[:lit, {:lit=>3}]}],
|
137
|
+
:body=>[:fcall, {:args=>[:array, [[:str, {:lit=>"Ruby"}]]], :mid=>:puts}]}]
|
138
|
+
=> nil
|
139
|
+
</code></pre>
|
140
|
+
|
141
|
+
<p>For more details see <a href="api.html"><span class="caps">API</span></a>.</p>
|
142
|
+
|
143
|
+
|
144
|
+
<p>Have fun!</p>
|
145
|
+
|
146
|
+
|
147
|
+
<h2 id="section5">Feedback</h2>
|
148
|
+
|
149
|
+
|
150
|
+
<p>If you find a bug, think that something doesn’t work as it should or have
|
151
|
+
other suggestions, then please don’t hesitate to <a href="mailto:dbatml@remove_nospam.gmx.de">contact
|
152
|
+
me</a> and tell me about it.</p>
|
153
|
+
|
154
|
+
|
155
|
+
<h2 id="section6">Thanks</h2>
|
156
|
+
|
157
|
+
|
158
|
+
<p>I would like to thank Paul Brannan for writing Nodewrap, which inspired me to
|
159
|
+
write RubyNode and also gave me some ideas and code.</p>
|
160
|
+
|
161
|
+
|
162
|
+
<h2 id="section7">License</h2>
|
163
|
+
|
164
|
+
|
165
|
+
<p>Copyright 2006 <a href="mailto:dbatml@remove_nospam.gmx.de">Dominik Bathon</a>.</p>
|
166
|
+
|
167
|
+
|
168
|
+
<p>RubyNode is licensed under the same terms as Ruby.</p>
|
169
|
+
</body>
|
170
|
+
</html>
|
data/doc/style.css
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
body {
|
2
|
+
color: #333;
|
3
|
+
background-color: white;
|
4
|
+
margin: 0 2em;
|
5
|
+
min-width: 41em;
|
6
|
+
}
|
7
|
+
h1 {
|
8
|
+
color: black;
|
9
|
+
border-bottom: 2px solid red;
|
10
|
+
}
|
11
|
+
h2 {
|
12
|
+
color: black;
|
13
|
+
}
|
14
|
+
h3 {
|
15
|
+
color: black;
|
16
|
+
}
|
17
|
+
pre {
|
18
|
+
color: black;
|
19
|
+
background-color: #eee;
|
20
|
+
padding: 0.7em 1em;
|
21
|
+
margin: 0.8em 0;
|
22
|
+
border: 1px dotted #999;
|
23
|
+
}
|
24
|
+
code {
|
25
|
+
color: black;
|
26
|
+
background-color: #eee;
|
27
|
+
}
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require "mkmf"
|
2
|
+
|
3
|
+
begin
|
4
|
+
$rbsrcdir = File.join(File.dirname(__FILE__), "ruby_src/#{RUBY_VERSION}_#{RUBY_RELEASE_DATE}")
|
5
|
+
|
6
|
+
$rbsrcdir = ENV["RUBY_SOURCE_DIR"] unless File.directory? $rbsrcdir
|
7
|
+
|
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
|
11
|
+
end
|
12
|
+
|
13
|
+
node_h = IO.read(File.join($rbsrcdir, "node.h"))
|
14
|
+
gc_c = IO.read(File.join($rbsrcdir, "gc.c"))
|
15
|
+
eval_c = IO.read(File.join($rbsrcdir, "eval.c"))
|
16
|
+
# check if $hdrdir is "compatible" with $rbsrcdir
|
17
|
+
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
|
24
|
+
end
|
25
|
+
|
26
|
+
raise "node.h does not contain 'enum node_type'" unless node_h =~ /enum node_type \{(.*?)\};/m
|
27
|
+
typestr = $1
|
28
|
+
nd_types = typestr.scan(/NODE_(\w+)/).flatten
|
29
|
+
node_attrib_map = {}
|
30
|
+
node_h.scan(/^#define\s+(nd_\w+)\s+(u[123]\.(node|id|value|tbl|argc|state|cnt|cfunc))\s*$/) {
|
31
|
+
node_attrib_map[$1] = $2
|
32
|
+
}
|
33
|
+
%w[nd_noex nd_cflag].each { |nd|
|
34
|
+
# noex and cflag are id (because u1 doesn't have a long member),
|
35
|
+
# but they are used as long
|
36
|
+
if node_attrib_map.has_key?(nd)
|
37
|
+
node_attrib_map[nd] = node_attrib_map[nd].sub(".id", ".as_long")
|
38
|
+
end
|
39
|
+
}
|
40
|
+
|
41
|
+
raise "gc.c does not contain an expected line" unless gc_c =~ /^\s*marking:\s*$(.*?)ALLOCA/m
|
42
|
+
raise "gc.c does not contain an expected line" unless $1 =~ /switch\s*\(nd_type/
|
43
|
+
nd_type_gc_switch_str = $'
|
44
|
+
|
45
|
+
eval_c =~ /struct\s+BLOCK\s*\{.*?\};/m
|
46
|
+
struct_block = $& || ""
|
47
|
+
eval_c =~ /struct\s+METHOD\s*\{.*?\};/m
|
48
|
+
struct_method = $& || ""
|
49
|
+
|
50
|
+
File.open("node_type.h", "w") { |f|
|
51
|
+
f << "static VALUE node_type_sym_tbl[#{nd_types.size}];\n"
|
52
|
+
f << "static void init_node_type_sym_tbl() {\n"
|
53
|
+
nd_types.each_with_index { |t, i|
|
54
|
+
f << "node_type_sym_tbl[#{i}] = ID2SYM(rb_intern(\"#{t.downcase}\"));\n"
|
55
|
+
}
|
56
|
+
f << "}\n"
|
57
|
+
f << "static VALUE node_type_to_sym(enum node_type nd_type) {\n"
|
58
|
+
f << "switch(nd_type) {\n"
|
59
|
+
nd_types.each_with_index { |t, i|
|
60
|
+
f << "#ifdef C_ALLOCA\n" if t == "ALLOCA" && RUBY_VERSION < "1.9.0"
|
61
|
+
f << "#define HAVE_NODE_#{t}\n"
|
62
|
+
f << "case NODE_#{t}:\nreturn node_type_sym_tbl[#{i}];\n"
|
63
|
+
f << "#endif\n" if t == "ALLOCA" && RUBY_VERSION < "1.9.0"
|
64
|
+
}
|
65
|
+
f << "default:\nreturn Qnil;\n"
|
66
|
+
f << "}\nreturn Qnil;\n}\n"
|
67
|
+
|
68
|
+
f << "static VALUE node_type_attrib_is_value(enum node_type nd_type, int union_idx) {\n"
|
69
|
+
f << "switch(nd_type) {\n"
|
70
|
+
nd_type_gc_switch_str.each { |line|
|
71
|
+
case line
|
72
|
+
when /ALLOCA/
|
73
|
+
break
|
74
|
+
when /case\s+NODE_(\w+):/
|
75
|
+
f << "case NODE_#{$1}:\n"
|
76
|
+
when /break;/, /goto again;/
|
77
|
+
f << "break;\n"
|
78
|
+
when /as\.node\.u(\d)\.node/
|
79
|
+
f << "if (union_idx == #$1) return Qtrue;\n"
|
80
|
+
end
|
81
|
+
}
|
82
|
+
f << "default:\nreturn Qfalse;\n"
|
83
|
+
f << "}\nreturn Qfalse;\n}\n"
|
84
|
+
node_attrib_map.each { |k, v|
|
85
|
+
if v =~ /u(\d)\./
|
86
|
+
f << "#define #{k.upcase}_UIDX #{$1}\n"
|
87
|
+
end
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
File.open("node_nd_attribs.h", "w") { |f|
|
92
|
+
f << "static void define_nd_attribs() {\n"
|
93
|
+
node_attrib_map.each { |k, v|
|
94
|
+
fun =
|
95
|
+
case v
|
96
|
+
when /u(\d)\.(node|value)/
|
97
|
+
"rnode_u#{$1}_value_or_node"
|
98
|
+
when /u(\d)\.id/
|
99
|
+
"rnode_u#{$1}_id"
|
100
|
+
when "u1.tbl"
|
101
|
+
"rnode_u1_tbl"
|
102
|
+
when "u2.argc"
|
103
|
+
"rnode_u2_argc"
|
104
|
+
when "u3.state", "u3.cnt"
|
105
|
+
"rnode_u3_state_or_cnt"
|
106
|
+
when "u1.as_long"
|
107
|
+
"rnode_u1_as_long"
|
108
|
+
when "u2.as_long"
|
109
|
+
"rnode_u2_argc"
|
110
|
+
when "u1.cfunc"
|
111
|
+
"rnode_u1_cfunc"
|
112
|
+
else
|
113
|
+
raise "unexpected node member: #{v}"
|
114
|
+
end
|
115
|
+
f << "rb_define_method(cRubyNode, \"#{k}\", #{fun}, 0);\n"
|
116
|
+
}
|
117
|
+
f << "}\n"
|
118
|
+
}
|
119
|
+
|
120
|
+
File.open("eval_c_structs.h", "w") { |f|
|
121
|
+
f.puts struct_block
|
122
|
+
f.puts struct_method
|
123
|
+
}
|
124
|
+
rescue
|
125
|
+
warn "error: #$!"
|
126
|
+
exit! 1
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
$distcleanfiles = ["node_type.h", "node_nd_attribs.h", "eval_c_structs.h"]
|
131
|
+
|
132
|
+
create_makefile("rubynode_ext")
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/**********************************************************************
|
2
|
+
|
3
|
+
eval.c -
|
4
|
+
|
5
|
+
$Author: nobu $
|
6
|
+
$Date: 2005/12/20 13:41:47 $
|
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.4 */
|
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: akr $
|
6
|
+
$Date: 2005/12/16 04:58:51 $
|
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.4 */
|
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
|
+
gc_mark((VALUE)obj->as.node.u1.node, lev);
|
94
|
+
/* fall through */
|
95
|
+
case NODE_METHOD: /* 2 */
|
96
|
+
case NODE_NOT:
|
97
|
+
case NODE_GASGN:
|
98
|
+
case NODE_LASGN:
|
99
|
+
case NODE_DASGN:
|
100
|
+
case NODE_DASGN_CURR:
|
101
|
+
case NODE_IASGN:
|
102
|
+
case NODE_CVDECL:
|
103
|
+
case NODE_CVASGN:
|
104
|
+
case NODE_COLON3:
|
105
|
+
case NODE_OPT_N:
|
106
|
+
case NODE_EVSTR:
|
107
|
+
ptr = (VALUE)obj->as.node.u2.node;
|
108
|
+
goto again;
|
109
|
+
|
110
|
+
case NODE_HASH: /* 1 */
|
111
|
+
case NODE_LIT:
|
112
|
+
case NODE_STR:
|
113
|
+
case NODE_XSTR:
|
114
|
+
case NODE_DEFINED:
|
115
|
+
case NODE_MATCH:
|
116
|
+
case NODE_RETURN:
|
117
|
+
case NODE_BREAK:
|
118
|
+
case NODE_NEXT:
|
119
|
+
case NODE_YIELD:
|
120
|
+
case NODE_COLON2:
|
121
|
+
case NODE_ARGS:
|
122
|
+
case NODE_SPLAT:
|
123
|
+
case NODE_TO_ARY:
|
124
|
+
case NODE_SVALUE:
|
125
|
+
ptr = (VALUE)obj->as.node.u1.node;
|
126
|
+
goto again;
|
127
|
+
|
128
|
+
case NODE_SCOPE: /* 2,3 */
|
129
|
+
case NODE_BLOCK_PASS:
|
130
|
+
case NODE_CDECL:
|
131
|
+
gc_mark((VALUE)obj->as.node.u3.node, lev);
|
132
|
+
ptr = (VALUE)obj->as.node.u2.node;
|
133
|
+
goto again;
|
134
|
+
|
135
|
+
case NODE_ZARRAY: /* - */
|
136
|
+
case NODE_ZSUPER:
|
137
|
+
case NODE_CFUNC:
|
138
|
+
case NODE_VCALL:
|
139
|
+
case NODE_GVAR:
|
140
|
+
case NODE_LVAR:
|
141
|
+
case NODE_DVAR:
|
142
|
+
case NODE_IVAR:
|
143
|
+
case NODE_CVAR:
|
144
|
+
case NODE_NTH_REF:
|
145
|
+
case NODE_BACK_REF:
|
146
|
+
case NODE_ALIAS:
|
147
|
+
case NODE_VALIAS:
|
148
|
+
case NODE_REDO:
|
149
|
+
case NODE_RETRY:
|
150
|
+
case NODE_UNDEF:
|
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
|
+
|