sydparse 1.0.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.
- data/Manifest.txt +26 -0
- data/Rakefile +34 -0
- data/bin/syd_pt_show +23 -0
- data/env.h +66 -0
- data/extconf.rb +12 -0
- data/internal.h +716 -0
- data/lex.c.tab +136 -0
- data/lib/sydparse.rb +247 -0
- data/node.h +365 -0
- data/parse_override.h +14 -0
- data/runtime.c +968 -0
- data/runtime.h +195 -0
- data/state.h +140 -0
- data/sydparse.c +10325 -0
- data/sydparse.y +6427 -0
- data/test/class.rb +7 -0
- data/test/pt.rb +19 -0
- data/test/show.rb +20 -0
- data/test/t.rb +53 -0
- data/test/t3.rb +6 -0
- data/test/t4.rb +4 -0
- data/test/test.rb +2 -0
- data/test/ubs.rb +1 -0
- metadata +70 -0
data/lex.c.tab
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
/* C code produced by gperf version 2.7.2 */
|
2
|
+
/* Command-line: gperf -p -j1 -i 1 -g -o -t -N rb_reserved_word -k'1,3,$' ./keywords */
|
3
|
+
struct kwtable {char *name; int id[2]; enum lex_state state;};
|
4
|
+
|
5
|
+
#define TOTAL_KEYWORDS 40
|
6
|
+
#define MIN_WORD_LENGTH 2
|
7
|
+
#define MAX_WORD_LENGTH 8
|
8
|
+
#define MIN_HASH_VALUE 6
|
9
|
+
#define MAX_HASH_VALUE 55
|
10
|
+
/* maximum key range = 50, duplicates = 0 */
|
11
|
+
|
12
|
+
#ifdef __GNUC__
|
13
|
+
__inline
|
14
|
+
#else
|
15
|
+
#ifdef __cplusplus
|
16
|
+
inline
|
17
|
+
#endif
|
18
|
+
#endif
|
19
|
+
static unsigned int
|
20
|
+
hash (str, len)
|
21
|
+
register const char *str;
|
22
|
+
register unsigned int len;
|
23
|
+
{
|
24
|
+
static unsigned char asso_values[] =
|
25
|
+
{
|
26
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
27
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
28
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
29
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
30
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
31
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
32
|
+
56, 56, 56, 11, 56, 56, 36, 56, 1, 37,
|
33
|
+
31, 1, 56, 56, 56, 56, 29, 56, 1, 56,
|
34
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
35
|
+
56, 56, 56, 56, 56, 1, 56, 32, 1, 2,
|
36
|
+
1, 1, 4, 23, 56, 17, 56, 20, 9, 2,
|
37
|
+
9, 26, 14, 56, 5, 1, 1, 16, 56, 21,
|
38
|
+
20, 9, 56, 56, 56, 56, 56, 56, 56, 56,
|
39
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
40
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
41
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
42
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
43
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
44
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
45
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
46
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
47
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
48
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
49
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
50
|
+
56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
|
51
|
+
56, 56, 56, 56, 56, 56
|
52
|
+
};
|
53
|
+
register int hval = len;
|
54
|
+
|
55
|
+
switch (hval)
|
56
|
+
{
|
57
|
+
default:
|
58
|
+
case 3:
|
59
|
+
hval += asso_values[(unsigned char)str[2]];
|
60
|
+
case 2:
|
61
|
+
case 1:
|
62
|
+
hval += asso_values[(unsigned char)str[0]];
|
63
|
+
break;
|
64
|
+
}
|
65
|
+
return hval + asso_values[(unsigned char)str[len - 1]];
|
66
|
+
}
|
67
|
+
|
68
|
+
#ifdef __GNUC__
|
69
|
+
__inline
|
70
|
+
#endif
|
71
|
+
struct kwtable *
|
72
|
+
syd_reserved_word (str, len)
|
73
|
+
register const char *str;
|
74
|
+
register unsigned int len;
|
75
|
+
{
|
76
|
+
static struct kwtable wordlist[] =
|
77
|
+
{
|
78
|
+
{""}, {""}, {""}, {""}, {""}, {""},
|
79
|
+
{"end", {kEND, kEND}, EXPR_END},
|
80
|
+
{"else", {kELSE, kELSE}, EXPR_BEG},
|
81
|
+
{"case", {kCASE, kCASE}, EXPR_BEG},
|
82
|
+
{"ensure", {kENSURE, kENSURE}, EXPR_BEG},
|
83
|
+
{"module", {kMODULE, kMODULE}, EXPR_BEG},
|
84
|
+
{"elsif", {kELSIF, kELSIF}, EXPR_BEG},
|
85
|
+
{"def", {kDEF, kDEF}, EXPR_FNAME},
|
86
|
+
{"rescue", {kRESCUE, kRESCUE_MOD}, EXPR_MID},
|
87
|
+
{"not", {kNOT, kNOT}, EXPR_BEG},
|
88
|
+
{"then", {kTHEN, kTHEN}, EXPR_BEG},
|
89
|
+
{"yield", {kYIELD, kYIELD}, EXPR_ARG},
|
90
|
+
{"for", {kFOR, kFOR}, EXPR_BEG},
|
91
|
+
{"self", {kSELF, kSELF}, EXPR_END},
|
92
|
+
{"false", {kFALSE, kFALSE}, EXPR_END},
|
93
|
+
{"retry", {kRETRY, kRETRY}, EXPR_END},
|
94
|
+
{"return", {kRETURN, kRETURN}, EXPR_MID},
|
95
|
+
{"true", {kTRUE, kTRUE}, EXPR_END},
|
96
|
+
{"if", {kIF, kIF_MOD}, EXPR_BEG},
|
97
|
+
{"defined?", {kDEFINED, kDEFINED}, EXPR_ARG},
|
98
|
+
{"super", {kSUPER, kSUPER}, EXPR_ARG},
|
99
|
+
{"undef", {kUNDEF, kUNDEF}, EXPR_FNAME},
|
100
|
+
{"break", {kBREAK, kBREAK}, EXPR_MID},
|
101
|
+
{"in", {kIN, kIN}, EXPR_BEG},
|
102
|
+
{"do", {kDO, kDO}, EXPR_BEG},
|
103
|
+
{"nil", {kNIL, kNIL}, EXPR_END},
|
104
|
+
{"until", {kUNTIL, kUNTIL_MOD}, EXPR_BEG},
|
105
|
+
{"unless", {kUNLESS, kUNLESS_MOD}, EXPR_BEG},
|
106
|
+
{"or", {kOR, kOR}, EXPR_BEG},
|
107
|
+
{"next", {kNEXT, kNEXT}, EXPR_MID},
|
108
|
+
{"when", {kWHEN, kWHEN}, EXPR_BEG},
|
109
|
+
{"redo", {kREDO, kREDO}, EXPR_END},
|
110
|
+
{"and", {kAND, kAND}, EXPR_BEG},
|
111
|
+
{"begin", {kBEGIN, kBEGIN}, EXPR_BEG},
|
112
|
+
{"__LINE__", {k__LINE__, k__LINE__}, EXPR_END},
|
113
|
+
{"class", {kCLASS, kCLASS}, EXPR_CLASS},
|
114
|
+
{"__FILE__", {k__FILE__, k__FILE__}, EXPR_END},
|
115
|
+
{"END", {klEND, klEND}, EXPR_END},
|
116
|
+
{"BEGIN", {klBEGIN, klBEGIN}, EXPR_END},
|
117
|
+
{"while", {kWHILE, kWHILE_MOD}, EXPR_BEG},
|
118
|
+
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
|
119
|
+
{""},
|
120
|
+
{"alias", {kALIAS, kALIAS}, EXPR_FNAME}
|
121
|
+
};
|
122
|
+
|
123
|
+
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
|
124
|
+
{
|
125
|
+
register int key = hash (str, len);
|
126
|
+
|
127
|
+
if (key <= MAX_HASH_VALUE && key >= 0)
|
128
|
+
{
|
129
|
+
register const char *s = wordlist[key].name;
|
130
|
+
|
131
|
+
if (*str == *s && !strcmp (str + 1, s + 1))
|
132
|
+
return &wordlist[key];
|
133
|
+
}
|
134
|
+
}
|
135
|
+
return 0;
|
136
|
+
}
|
data/lib/sydparse.rb
ADDED
@@ -0,0 +1,247 @@
|
|
1
|
+
require 'sydney_parser'
|
2
|
+
|
3
|
+
class SydneyParser
|
4
|
+
|
5
|
+
# Generate a sexp which includes comments from +var+. +var+ is either a String
|
6
|
+
# or something that can become an IO object.
|
7
|
+
def self.unified_sexp(var)
|
8
|
+
if String === var
|
9
|
+
syd = load_string var, true
|
10
|
+
else
|
11
|
+
syd = load_file var.to_io, false, true
|
12
|
+
end
|
13
|
+
|
14
|
+
return syd.unified_sexp
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
# Generate a sexp which includes comments from +var+.
|
19
|
+
def unified_sexp
|
20
|
+
comms = collapse_per_line comments()
|
21
|
+
x = sexp(true)
|
22
|
+
insert_comments(x, comms)
|
23
|
+
end
|
24
|
+
|
25
|
+
def insert_comments(x)
|
26
|
+
comms = collapse_per_line comments()
|
27
|
+
insert_comments(x, comms)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# Turn an array of comments into a hash on the line.
|
33
|
+
def collapse_per_line(comments)
|
34
|
+
out = Hash.new
|
35
|
+
comments.each do |line, column, text|
|
36
|
+
if ary = out[line]
|
37
|
+
ary << text
|
38
|
+
else
|
39
|
+
out[line] = [text]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
out
|
43
|
+
end
|
44
|
+
|
45
|
+
# Give +line+ find all the comments for it from +lines+ and +comments+.
|
46
|
+
# Note that this modifies +lines+ so future calls doen't return already
|
47
|
+
# used comments.
|
48
|
+
def find_comments(lines, comments, line)
|
49
|
+
found = []
|
50
|
+
lines.each do |l|
|
51
|
+
if l <= line
|
52
|
+
found << l
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
found_comments = found.sort.map do |l|
|
57
|
+
lines.delete(l)
|
58
|
+
comments[l]
|
59
|
+
end
|
60
|
+
|
61
|
+
# puts "Found #{found_comments.flatten.inspect} #{found.inspect} comments for line #{line}"
|
62
|
+
found_comments.flatten
|
63
|
+
end
|
64
|
+
|
65
|
+
# Recursively decend through sexp and insert :comment nodes from +comments+
|
66
|
+
def insert_comments(sexp, comments)
|
67
|
+
lines = comments.keys.sort
|
68
|
+
out = insert_comments_rec(sexp, lines, comments)
|
69
|
+
out[1]
|
70
|
+
end
|
71
|
+
|
72
|
+
# Recursive method that injects comments from +comments+ into +sexp+.
|
73
|
+
def insert_comments_rec(sexp, lines, comments)
|
74
|
+
# Dont let block or scope process comments so that we get the comment
|
75
|
+
# as close to the actual element the programmer typed as possible.
|
76
|
+
tag = sexp.first
|
77
|
+
if tag == :block
|
78
|
+
init_comments = nil
|
79
|
+
elsif tag == :scope
|
80
|
+
# Scope has a line number on it, but we dont want it there.
|
81
|
+
sexp.pop
|
82
|
+
init_comments = nil
|
83
|
+
else
|
84
|
+
line = sexp.last
|
85
|
+
if Fixnum === line
|
86
|
+
sexp.pop
|
87
|
+
init_comments = find_comments(lines, comments, line)
|
88
|
+
if init_comments.size > 0
|
89
|
+
init_comments.unshift :comment
|
90
|
+
else
|
91
|
+
init_comments = nil
|
92
|
+
end
|
93
|
+
else
|
94
|
+
init_comments = nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
out = []
|
99
|
+
sexp.each do |x|
|
100
|
+
if Array === x
|
101
|
+
outcom, sub = insert_comments_rec(x, lines, comments)
|
102
|
+
out << outcom if outcom
|
103
|
+
out << sub
|
104
|
+
else
|
105
|
+
out << x
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
[init_comments, out]
|
110
|
+
end
|
111
|
+
|
112
|
+
# NOTE the semantics of these methods are critical. Changing them
|
113
|
+
# can cause segfaults in the parser, so be careful!
|
114
|
+
|
115
|
+
# Initialize the local variable information.
|
116
|
+
def local_init
|
117
|
+
@current_table = []
|
118
|
+
@locals = [@current_table]
|
119
|
+
@current_dvars = nil
|
120
|
+
@dvars = []
|
121
|
+
end
|
122
|
+
|
123
|
+
# The 'special' globals that ruby stores in the local sope
|
124
|
+
BaseLocals = [:_, :~]
|
125
|
+
|
126
|
+
LocalsOffset = 2
|
127
|
+
|
128
|
+
@@testing = false
|
129
|
+
|
130
|
+
# Called when we are all done processing locals. (currently a noop)
|
131
|
+
def local_finish
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
# Indicates if +var+ is defined in the current locals table.
|
136
|
+
def local_defined?(var)
|
137
|
+
puts "Checking for local :#{var}" if @@testing
|
138
|
+
return @current_table.include?(var)
|
139
|
+
end
|
140
|
+
|
141
|
+
# Retrieve the index of +var+ in the locals table. If +var+ doesn't
|
142
|
+
# exist, it adds it to the locals table.
|
143
|
+
def local_cnt(var)
|
144
|
+
puts "Getting index of local :#{var}" if @@testing
|
145
|
+
if idx = BaseLocals.index(var)
|
146
|
+
return idx
|
147
|
+
end
|
148
|
+
|
149
|
+
if idx = @current_table.index(var)
|
150
|
+
return idx + LocalsOffset
|
151
|
+
else
|
152
|
+
local_append(var)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# Add +var+ to the current locals table.
|
157
|
+
def local_append(var)
|
158
|
+
puts "Adding index for :#{var}" if @@testing
|
159
|
+
idx = @current_table.size
|
160
|
+
@current_table << var
|
161
|
+
return idx + LocalsOffset
|
162
|
+
end
|
163
|
+
|
164
|
+
# Push the current locals table and get a new one.
|
165
|
+
def local_push(top)
|
166
|
+
puts "Pushing new locals #{@locals.inspect}" if @@testing
|
167
|
+
@current_table = []
|
168
|
+
@locals << @current_table
|
169
|
+
end
|
170
|
+
|
171
|
+
# Retrieve the current table of local variables.
|
172
|
+
def local_table
|
173
|
+
puts "Return local table. #{@current_table.inspect}" if @@testing
|
174
|
+
@current_table
|
175
|
+
end
|
176
|
+
|
177
|
+
# Make the current locals table table the last one used.
|
178
|
+
def local_pop
|
179
|
+
puts "Popping locals #{@locals.inspect}" if @@testing
|
180
|
+
return unless @locals
|
181
|
+
@locals.pop
|
182
|
+
@current_table = @locals.last
|
183
|
+
end
|
184
|
+
|
185
|
+
# Indicates if it's possible for there to be dynamic (block) variables
|
186
|
+
def dyna_in_block
|
187
|
+
ans = @dvars.size > 0
|
188
|
+
# puts "in_block? #{ans.inspect}"
|
189
|
+
return ans
|
190
|
+
end
|
191
|
+
|
192
|
+
# Allocate a new empty set of dynamic (block) variables, saving the old
|
193
|
+
# stack of dynamic variables and returns it.
|
194
|
+
def dyna_push
|
195
|
+
# puts "Pushing new dvars"
|
196
|
+
vars = Hash.new
|
197
|
+
@dvars << vars
|
198
|
+
@current_dvars = vars
|
199
|
+
return @dvars
|
200
|
+
end
|
201
|
+
|
202
|
+
# Make the current dynamic variable table the last one used from +var+.
|
203
|
+
def dyna_pop(vars)
|
204
|
+
# puts "popping dvars"
|
205
|
+
vars.pop
|
206
|
+
@dvars = vars
|
207
|
+
@current_dvars = @dvars.last
|
208
|
+
end
|
209
|
+
|
210
|
+
# Returns the current table of dynamic variables.
|
211
|
+
def dyna_vars
|
212
|
+
# puts "returning dvars #{@current_dvars.keys.inspect}"
|
213
|
+
@current_dvars.keys
|
214
|
+
end
|
215
|
+
|
216
|
+
# Retrieve the current table of unique dynamic variables that are not in +pre+.
|
217
|
+
def dyna_init(pre)
|
218
|
+
# puts "doing init"
|
219
|
+
# p @current_dvars
|
220
|
+
# p pre
|
221
|
+
return @current_dvars.keys - pre
|
222
|
+
end
|
223
|
+
|
224
|
+
# Indicates if +var+ is defined as a dynamic variable in any table of stack.
|
225
|
+
def dvar_defined(var)
|
226
|
+
@dvars.each do |vars|
|
227
|
+
ans = vars.key? var
|
228
|
+
return true if ans
|
229
|
+
end
|
230
|
+
return false
|
231
|
+
end
|
232
|
+
|
233
|
+
# Indicates if +var+ is a dynamic variable in only the current table.
|
234
|
+
def dvar_curr(var)
|
235
|
+
return false unless @current_dvars
|
236
|
+
|
237
|
+
ans = @current_dvars.key? var
|
238
|
+
# puts "checking for dvar #{var} #{ans.inspect}"
|
239
|
+
return ans
|
240
|
+
end
|
241
|
+
|
242
|
+
# Set the dynamic variable +sym+ the value +val+ in the current table.
|
243
|
+
def dvar_push(sym, val)
|
244
|
+
# puts "Adding dvar #{sym}"
|
245
|
+
@current_dvars[sym] = val
|
246
|
+
end
|
247
|
+
end
|
data/node.h
ADDED
@@ -0,0 +1,365 @@
|
|
1
|
+
/**********************************************************************
|
2
|
+
|
3
|
+
node.h -
|
4
|
+
|
5
|
+
$Author: nobu $
|
6
|
+
$Date: 2004/10/02 11:34:29 $
|
7
|
+
created at: Fri May 28 15:14:02 JST 1993
|
8
|
+
|
9
|
+
Copyright (C) 1993-2003 Yukihiro Matsumoto
|
10
|
+
|
11
|
+
**********************************************************************/
|
12
|
+
|
13
|
+
#ifndef NODE_H
|
14
|
+
#define NODE_H
|
15
|
+
|
16
|
+
#if defined(__cplusplus)
|
17
|
+
extern "C" {
|
18
|
+
#endif
|
19
|
+
|
20
|
+
enum node_type {
|
21
|
+
NODE_METHOD,
|
22
|
+
NODE_FBODY,
|
23
|
+
NODE_CFUNC,
|
24
|
+
NODE_SCOPE,
|
25
|
+
NODE_BLOCK,
|
26
|
+
NODE_IF,
|
27
|
+
NODE_CASE,
|
28
|
+
NODE_WHEN,
|
29
|
+
NODE_OPT_N,
|
30
|
+
NODE_WHILE,
|
31
|
+
NODE_UNTIL,
|
32
|
+
NODE_ITER,
|
33
|
+
NODE_FOR,
|
34
|
+
NODE_BREAK,
|
35
|
+
NODE_NEXT,
|
36
|
+
NODE_REDO,
|
37
|
+
NODE_RETRY,
|
38
|
+
NODE_BEGIN,
|
39
|
+
NODE_RESCUE,
|
40
|
+
NODE_RESBODY,
|
41
|
+
NODE_ENSURE,
|
42
|
+
NODE_AND,
|
43
|
+
NODE_OR,
|
44
|
+
NODE_NOT,
|
45
|
+
NODE_MASGN,
|
46
|
+
NODE_LASGN,
|
47
|
+
NODE_DASGN,
|
48
|
+
NODE_DASGN_CURR,
|
49
|
+
NODE_GASGN,
|
50
|
+
NODE_IASGN,
|
51
|
+
NODE_CDECL,
|
52
|
+
NODE_CVASGN,
|
53
|
+
NODE_CVDECL,
|
54
|
+
NODE_OP_ASGN1,
|
55
|
+
NODE_OP_ASGN2,
|
56
|
+
NODE_OP_ASGN_AND,
|
57
|
+
NODE_OP_ASGN_OR,
|
58
|
+
NODE_CALL,
|
59
|
+
NODE_FCALL,
|
60
|
+
NODE_VCALL,
|
61
|
+
NODE_SUPER,
|
62
|
+
NODE_ZSUPER,
|
63
|
+
NODE_ARRAY,
|
64
|
+
NODE_ZARRAY,
|
65
|
+
NODE_HASH,
|
66
|
+
NODE_RETURN,
|
67
|
+
NODE_YIELD,
|
68
|
+
NODE_LVAR,
|
69
|
+
NODE_DVAR,
|
70
|
+
NODE_GVAR,
|
71
|
+
NODE_IVAR,
|
72
|
+
NODE_CONST,
|
73
|
+
NODE_CVAR,
|
74
|
+
NODE_NTH_REF,
|
75
|
+
NODE_BACK_REF,
|
76
|
+
NODE_MATCH,
|
77
|
+
NODE_MATCH2,
|
78
|
+
NODE_MATCH3,
|
79
|
+
NODE_LIT,
|
80
|
+
NODE_STR,
|
81
|
+
NODE_DSTR,
|
82
|
+
NODE_XSTR,
|
83
|
+
NODE_DXSTR,
|
84
|
+
NODE_EVSTR,
|
85
|
+
NODE_DREGX,
|
86
|
+
NODE_DREGX_ONCE,
|
87
|
+
NODE_ARGS,
|
88
|
+
NODE_ARGSCAT,
|
89
|
+
NODE_ARGSPUSH,
|
90
|
+
NODE_SPLAT,
|
91
|
+
NODE_TO_ARY,
|
92
|
+
NODE_SVALUE,
|
93
|
+
NODE_BLOCK_ARG,
|
94
|
+
NODE_BLOCK_PASS,
|
95
|
+
NODE_DEFN,
|
96
|
+
NODE_DEFS,
|
97
|
+
NODE_ALIAS,
|
98
|
+
NODE_VALIAS,
|
99
|
+
NODE_UNDEF,
|
100
|
+
NODE_CLASS,
|
101
|
+
NODE_MODULE,
|
102
|
+
NODE_SCLASS,
|
103
|
+
NODE_COLON2,
|
104
|
+
NODE_COLON3,
|
105
|
+
NODE_CREF,
|
106
|
+
NODE_DOT2,
|
107
|
+
NODE_DOT3,
|
108
|
+
NODE_FLIP2,
|
109
|
+
NODE_FLIP3,
|
110
|
+
NODE_ATTRSET,
|
111
|
+
NODE_SELF,
|
112
|
+
NODE_NIL,
|
113
|
+
NODE_TRUE,
|
114
|
+
NODE_FALSE,
|
115
|
+
NODE_DEFINED,
|
116
|
+
NODE_NEWLINE,
|
117
|
+
NODE_POSTEXE,
|
118
|
+
#ifdef C_ALLOCA
|
119
|
+
NODE_ALLOCA,
|
120
|
+
#endif
|
121
|
+
NODE_DMETHOD,
|
122
|
+
NODE_BMETHOD,
|
123
|
+
NODE_MEMO,
|
124
|
+
NODE_IFUNC,
|
125
|
+
NODE_DSYM,
|
126
|
+
NODE_ATTRASGN,
|
127
|
+
NODE_LAST
|
128
|
+
};
|
129
|
+
|
130
|
+
typedef struct RNode {
|
131
|
+
unsigned long flags;
|
132
|
+
char *nd_file;
|
133
|
+
union {
|
134
|
+
struct RNode *node;
|
135
|
+
ID id;
|
136
|
+
VALUE value;
|
137
|
+
VALUE (*cfunc)(ANYARGS);
|
138
|
+
ID *tbl;
|
139
|
+
} u1;
|
140
|
+
union {
|
141
|
+
struct RNode *node;
|
142
|
+
ID id;
|
143
|
+
long argc;
|
144
|
+
VALUE value;
|
145
|
+
} u2;
|
146
|
+
union {
|
147
|
+
struct RNode *node;
|
148
|
+
ID id;
|
149
|
+
long state;
|
150
|
+
struct global_entry *entry;
|
151
|
+
long cnt;
|
152
|
+
VALUE value;
|
153
|
+
} u3;
|
154
|
+
} NODE;
|
155
|
+
|
156
|
+
#define RNODE(obj) (R_CAST(RNode)(obj))
|
157
|
+
|
158
|
+
#define nd_type(n) ((int)(((RNODE(n))->flags>>FL_USHIFT)&0xff))
|
159
|
+
#define nd_set_type(n,t) \
|
160
|
+
RNODE(n)->flags=((RNODE(n)->flags&~FL_UMASK)|(((t)<<FL_USHIFT)&FL_UMASK))
|
161
|
+
|
162
|
+
#define NODE_LSHIFT (FL_USHIFT+8)
|
163
|
+
#define NODE_LMASK (((long)1<<(sizeof(NODE*)*CHAR_BIT-NODE_LSHIFT))-1)
|
164
|
+
#define nd_line(n) ((unsigned int)(((RNODE(n))->flags>>NODE_LSHIFT)&NODE_LMASK))
|
165
|
+
#define nd_set_line(n,l) \
|
166
|
+
RNODE(n)->flags=((RNODE(n)->flags&~(-1<<NODE_LSHIFT))|(((l)&NODE_LMASK)<<NODE_LSHIFT))
|
167
|
+
|
168
|
+
#define nd_head u1.node
|
169
|
+
#define nd_alen u2.argc
|
170
|
+
#define nd_next u3.node
|
171
|
+
|
172
|
+
#define nd_cond u1.node
|
173
|
+
#define nd_body u2.node
|
174
|
+
#define nd_else u3.node
|
175
|
+
|
176
|
+
#define nd_orig u3.value
|
177
|
+
|
178
|
+
#define nd_resq u2.node
|
179
|
+
#define nd_ensr u3.node
|
180
|
+
|
181
|
+
#define nd_1st u1.node
|
182
|
+
#define nd_2nd u2.node
|
183
|
+
|
184
|
+
#define nd_stts u1.node
|
185
|
+
|
186
|
+
#define nd_entry u3.entry
|
187
|
+
#define nd_vid u1.id
|
188
|
+
#define nd_cflag u2.id
|
189
|
+
#define nd_cval u3.value
|
190
|
+
|
191
|
+
#define nd_cnt u3.cnt
|
192
|
+
#define nd_tbl u1.tbl
|
193
|
+
|
194
|
+
#define nd_var u1.node
|
195
|
+
#define nd_ibdy u2.node
|
196
|
+
#define nd_iter u3.node
|
197
|
+
|
198
|
+
#define nd_value u2.node
|
199
|
+
#define nd_aid u3.id
|
200
|
+
|
201
|
+
#define nd_lit u1.value
|
202
|
+
|
203
|
+
#define nd_frml u1.node
|
204
|
+
#define nd_rest u2.argc
|
205
|
+
#define nd_opt u1.node
|
206
|
+
|
207
|
+
#define nd_recv u1.node
|
208
|
+
#define nd_mid u2.id
|
209
|
+
#define nd_args u3.node
|
210
|
+
|
211
|
+
#define nd_noex u1.id
|
212
|
+
#define nd_defn u3.node
|
213
|
+
|
214
|
+
#define nd_old u1.id
|
215
|
+
#define nd_new u2.id
|
216
|
+
|
217
|
+
#define nd_cfnc u1.cfunc
|
218
|
+
#define nd_argc u2.argc
|
219
|
+
|
220
|
+
#define nd_cpath u1.node
|
221
|
+
#define nd_super u3.node
|
222
|
+
|
223
|
+
#define nd_modl u1.id
|
224
|
+
#define nd_clss u1.value
|
225
|
+
|
226
|
+
#define nd_beg u1.node
|
227
|
+
#define nd_end u2.node
|
228
|
+
#define nd_state u3.state
|
229
|
+
#define nd_rval u2.value
|
230
|
+
|
231
|
+
#define nd_nth u2.argc
|
232
|
+
|
233
|
+
#define nd_tag u1.id
|
234
|
+
#define nd_tval u2.value
|
235
|
+
|
236
|
+
#define NEW_NODE(t,a0,a1,a2) syd_node_newnode((t),(VALUE)(a0),(VALUE)(a1),(VALUE)(a2))
|
237
|
+
|
238
|
+
#define NEW_METHOD(n,x) NEW_NODE(NODE_METHOD,x,n,0)
|
239
|
+
#define NEW_FBODY(n,i,o) NEW_NODE(NODE_FBODY,n,i,o)
|
240
|
+
#define NEW_DEFN(i,a,d,p) NEW_NODE(NODE_DEFN,p,i,NEW_RFUNC(a,d))
|
241
|
+
#define NEW_DEFS(r,i,a,d) NEW_NODE(NODE_DEFS,r,i,NEW_RFUNC(a,d))
|
242
|
+
#define NEW_CFUNC(f,c) NEW_NODE(NODE_CFUNC,f,c,0)
|
243
|
+
#define NEW_IFUNC(f,c) NEW_NODE(NODE_IFUNC,f,c,0)
|
244
|
+
#define NEW_RFUNC(b1,b2) NEW_SCOPE(block_append(b1,b2))
|
245
|
+
#define NEW_SCOPE(b) NEW_NODE(NODE_SCOPE,syd_local_tbl(vps),0,(b))
|
246
|
+
#define NEW_BLOCK(a) NEW_NODE(NODE_BLOCK,a,0,0)
|
247
|
+
#define NEW_IF(c,t,e) NEW_NODE(NODE_IF,c,t,e)
|
248
|
+
#define NEW_UNLESS(c,t,e) NEW_IF(c,e,t)
|
249
|
+
#define NEW_CASE(h,b) NEW_NODE(NODE_CASE,h,b,0)
|
250
|
+
#define NEW_WHEN(c,t,e) NEW_NODE(NODE_WHEN,c,t,e)
|
251
|
+
#define NEW_OPT_N(b) NEW_NODE(NODE_OPT_N,0,b,0)
|
252
|
+
#define NEW_WHILE(c,b,n) NEW_NODE(NODE_WHILE,c,b,n)
|
253
|
+
#define NEW_UNTIL(c,b,n) NEW_NODE(NODE_UNTIL,c,b,n)
|
254
|
+
#define NEW_FOR(v,i,b) NEW_NODE(NODE_FOR,v,b,i)
|
255
|
+
#define NEW_ITER(v,i,b) NEW_NODE(NODE_ITER,v,b,i)
|
256
|
+
#define NEW_BREAK(s) NEW_NODE(NODE_BREAK,s,0,0)
|
257
|
+
#define NEW_NEXT(s) NEW_NODE(NODE_NEXT,s,0,0)
|
258
|
+
#define NEW_REDO() NEW_NODE(NODE_REDO,0,0,0)
|
259
|
+
#define NEW_RETRY() NEW_NODE(NODE_RETRY,0,0,0)
|
260
|
+
#define NEW_BEGIN(b) NEW_NODE(NODE_BEGIN,0,b,0)
|
261
|
+
#define NEW_RESCUE(b,res,e) NEW_NODE(NODE_RESCUE,b,res,e)
|
262
|
+
#define NEW_RESBODY(a,ex,n) NEW_NODE(NODE_RESBODY,n,ex,a)
|
263
|
+
#define NEW_ENSURE(b,en) NEW_NODE(NODE_ENSURE,b,0,en)
|
264
|
+
#define NEW_RETURN(s) NEW_NODE(NODE_RETURN,s,0,0)
|
265
|
+
#define NEW_YIELD(a,s) NEW_NODE(NODE_YIELD,a,0,s)
|
266
|
+
#define NEW_LIST(a) NEW_ARRAY(a)
|
267
|
+
#define NEW_ARRAY(a) NEW_NODE(NODE_ARRAY,a,1,0)
|
268
|
+
#define NEW_ZARRAY() NEW_NODE(NODE_ZARRAY,0,0,0)
|
269
|
+
#define NEW_HASH(a) NEW_NODE(NODE_HASH,a,0,0)
|
270
|
+
#define NEW_POSITIONAL(a) NEW_NODE(NODE_HASH,a,1,0)
|
271
|
+
#define NEW_NOT(a) NEW_NODE(NODE_NOT,0,a,0)
|
272
|
+
#define NEW_MASGN(l,r) NEW_NODE(NODE_MASGN,l,0,r)
|
273
|
+
#define NEW_GASGN(v,val) NEW_NODE(NODE_GASGN,v,val,rb_global_entry(v))
|
274
|
+
#define NEW_LASGN(v,val) NEW_NODE(NODE_LASGN,v,val,local_cnt(v))
|
275
|
+
#define NEW_DASGN(v,val) NEW_NODE(NODE_DASGN,v,val,0)
|
276
|
+
#define NEW_DASGN_CURR(v,val) NEW_NODE(NODE_DASGN_CURR,v,val,0)
|
277
|
+
#define NEW_IASGN(v,val) NEW_NODE(NODE_IASGN,v,val,0)
|
278
|
+
#define NEW_CDECL(v,val,path) NEW_NODE(NODE_CDECL,v,val,path)
|
279
|
+
#define NEW_CVASGN(v,val) NEW_NODE(NODE_CVASGN,v,val,0)
|
280
|
+
#define NEW_CVDECL(v,val) NEW_NODE(NODE_CVDECL,v,val,0)
|
281
|
+
#define NEW_OP_ASGN1(p,id,a) NEW_NODE(NODE_OP_ASGN1,p,id,a)
|
282
|
+
#define NEW_OP_ASGN2(r,i,o,val) NEW_NODE(NODE_OP_ASGN2,r,val,NEW_OP_ASGN22(i,o))
|
283
|
+
#define NEW_OP_ASGN22(i,o) NEW_NODE(NODE_OP_ASGN2,i,o,rb_id_attrset(i))
|
284
|
+
#define NEW_OP_ASGN_OR(i,val) NEW_NODE(NODE_OP_ASGN_OR,i,val,0)
|
285
|
+
#define NEW_OP_ASGN_AND(i,val) NEW_NODE(NODE_OP_ASGN_AND,i,val,0)
|
286
|
+
#define NEW_GVAR(v) NEW_NODE(NODE_GVAR,v,0,rb_global_entry(v))
|
287
|
+
#define NEW_LVAR(v) NEW_NODE(NODE_LVAR,v,0,local_cnt(v))
|
288
|
+
#define NEW_DVAR(v) NEW_NODE(NODE_DVAR,v,0,0)
|
289
|
+
#define NEW_IVAR(v) NEW_NODE(NODE_IVAR,v,0,0)
|
290
|
+
#define NEW_CONST(v) NEW_NODE(NODE_CONST,v,0,0)
|
291
|
+
#define NEW_CVAR(v) NEW_NODE(NODE_CVAR,v,0,0)
|
292
|
+
#define NEW_NTH_REF(n) NEW_NODE(NODE_NTH_REF,0,n,local_cnt('~'))
|
293
|
+
#define NEW_BACK_REF(n) NEW_NODE(NODE_BACK_REF,0,n,local_cnt('~'))
|
294
|
+
#define NEW_MATCH(c) NEW_NODE(NODE_MATCH,c,0,0)
|
295
|
+
#define NEW_MATCH2(n1,n2) NEW_NODE(NODE_MATCH2,n1,n2,0)
|
296
|
+
#define NEW_MATCH3(r,n2) NEW_NODE(NODE_MATCH3,r,n2,0)
|
297
|
+
#define NEW_LIT(l) NEW_NODE(NODE_LIT,l,0,0)
|
298
|
+
#define NEW_STR(s) NEW_NODE(NODE_STR,s,0,0)
|
299
|
+
#define NEW_DSTR(s) NEW_NODE(NODE_DSTR,s,1,0)
|
300
|
+
#define NEW_XSTR(s) NEW_NODE(NODE_XSTR,s,0,0)
|
301
|
+
#define NEW_DXSTR(s) NEW_NODE(NODE_DXSTR,s,0,0)
|
302
|
+
#define NEW_DSYM(s) NEW_NODE(NODE_DSYM,s,0,0)
|
303
|
+
#define NEW_EVSTR(n) NEW_NODE(NODE_EVSTR,0,(n),0)
|
304
|
+
#define NEW_CALL(r,m,a) NEW_NODE(NODE_CALL,r,m,a)
|
305
|
+
#define NEW_FCALL(m,a) NEW_NODE(NODE_FCALL,0,m,a)
|
306
|
+
#define NEW_VCALL(m) NEW_NODE(NODE_VCALL,0,m,0)
|
307
|
+
#define NEW_SUPER(a) NEW_NODE(NODE_SUPER,0,0,a)
|
308
|
+
#define NEW_ZSUPER() NEW_NODE(NODE_ZSUPER,0,0,0)
|
309
|
+
#define NEW_ARGS(f,o,r) NEW_NODE(NODE_ARGS,o,r,f)
|
310
|
+
#define NEW_ARGSCAT(a,b) NEW_NODE(NODE_ARGSCAT,a,b,0)
|
311
|
+
#define NEW_ARGSPUSH(a,b) NEW_NODE(NODE_ARGSPUSH,a,b,0)
|
312
|
+
#define NEW_SPLAT(a) NEW_NODE(NODE_SPLAT,a,0,0)
|
313
|
+
#define NEW_TO_ARY(a) NEW_NODE(NODE_TO_ARY,a,0,0)
|
314
|
+
#define NEW_SVALUE(a) NEW_NODE(NODE_SVALUE,a,0,0)
|
315
|
+
#define NEW_BLOCK_ARG(v) NEW_NODE(NODE_BLOCK_ARG,v,0,local_cnt(v))
|
316
|
+
#define NEW_BLOCK_PASS(b) NEW_NODE(NODE_BLOCK_PASS,0,b,0)
|
317
|
+
#define NEW_ALIAS(n,o) NEW_NODE(NODE_ALIAS,o,n,0)
|
318
|
+
#define NEW_VALIAS(n,o) NEW_NODE(NODE_VALIAS,o,n,0)
|
319
|
+
#define NEW_UNDEF(i) NEW_NODE(NODE_UNDEF,0,i,0)
|
320
|
+
#define NEW_CLASS(n,b,s) NEW_NODE(NODE_CLASS,n,NEW_SCOPE(b),(s))
|
321
|
+
#define NEW_SCLASS(r,b) NEW_NODE(NODE_SCLASS,r,NEW_SCOPE(b),0)
|
322
|
+
#define NEW_MODULE(n,b) NEW_NODE(NODE_MODULE,n,NEW_SCOPE(b),0)
|
323
|
+
#define NEW_COLON2(c,i) NEW_NODE(NODE_COLON2,c,i,0)
|
324
|
+
#define NEW_COLON3(i) NEW_NODE(NODE_COLON3,0,i,0)
|
325
|
+
#define NEW_CREF(c) (NEW_NODE(NODE_CREF,0,0,c))
|
326
|
+
#define NEW_DOT2(b,e) NEW_NODE(NODE_DOT2,b,e,0)
|
327
|
+
#define NEW_DOT3(b,e) NEW_NODE(NODE_DOT3,b,e,0)
|
328
|
+
#define NEW_ATTRSET(a) NEW_NODE(NODE_ATTRSET,a,0,0)
|
329
|
+
#define NEW_SELF() NEW_NODE(NODE_SELF,0,0,0)
|
330
|
+
#define NEW_NIL() NEW_NODE(NODE_NIL,0,0,0)
|
331
|
+
#define NEW_TRUE() NEW_NODE(NODE_TRUE,0,0,0)
|
332
|
+
#define NEW_FALSE() NEW_NODE(NODE_FALSE,0,0,0)
|
333
|
+
#define NEW_DEFINED(e) NEW_NODE(NODE_DEFINED,e,0,0)
|
334
|
+
#define NEW_NEWLINE(n) NEW_NODE(NODE_NEWLINE,0,0,n)
|
335
|
+
#define NEW_PREEXE(b) NEW_SCOPE(b)
|
336
|
+
#define NEW_POSTEXE() NEW_NODE(NODE_POSTEXE,0,0,0)
|
337
|
+
#define NEW_DMETHOD(b) NEW_NODE(NODE_DMETHOD,0,0,b)
|
338
|
+
#define NEW_BMETHOD(b) NEW_NODE(NODE_BMETHOD,0,0,b)
|
339
|
+
#define NEW_ATTRASGN(r,m,a) NEW_NODE(NODE_ATTRASGN,r,m,a)
|
340
|
+
|
341
|
+
#define NOEX_PUBLIC 0
|
342
|
+
#define NOEX_NOSUPER 1
|
343
|
+
#define NOEX_PRIVATE 2
|
344
|
+
#define NOEX_PROTECTED 4
|
345
|
+
#define NOEX_MASK 6
|
346
|
+
|
347
|
+
#define NOEX_UNDEF NOEX_NOSUPER
|
348
|
+
|
349
|
+
NODE *rb_compile_cstr _((const char*, const char*, int, int));
|
350
|
+
|
351
|
+
void rb_add_method _((VALUE, ID, NODE *, int));
|
352
|
+
NODE *syd_node_newnode _((enum node_type,VALUE,VALUE,VALUE));
|
353
|
+
|
354
|
+
NODE* rb_method_node _((VALUE klass, ID id));
|
355
|
+
|
356
|
+
struct global_entry *rb_global_entry _((ID));
|
357
|
+
VALUE rb_gvar_get _((struct global_entry *));
|
358
|
+
VALUE rb_gvar_set _((struct global_entry *, VALUE));
|
359
|
+
VALUE rb_gvar_defined _((struct global_entry *));
|
360
|
+
|
361
|
+
#if defined(__cplusplus)
|
362
|
+
} /* extern "C" { */
|
363
|
+
#endif
|
364
|
+
|
365
|
+
#endif
|