mutant-melbourne 2.0.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/LICENSE +25 -0
- data/README.md +69 -0
- data/Rakefile +14 -0
- data/ext/melbourne/.gitignore +3 -0
- data/ext/melbourne/bstring-license.txt +29 -0
- data/ext/melbourne/bstrlib.c +2687 -0
- data/ext/melbourne/bstrlib.h +267 -0
- data/ext/melbourne/encoding_compat.cpp +188 -0
- data/ext/melbourne/encoding_compat.hpp +57 -0
- data/ext/melbourne/extconf.rb +87 -0
- data/ext/melbourne/grammar18.cpp +11280 -0
- data/ext/melbourne/grammar18.hpp +13 -0
- data/ext/melbourne/grammar18.y +6088 -0
- data/ext/melbourne/grammar19.cpp +12420 -0
- data/ext/melbourne/grammar19.hpp +11 -0
- data/ext/melbourne/grammar19.y +7113 -0
- data/ext/melbourne/lex.c.blt +152 -0
- data/ext/melbourne/lex.c.tab +136 -0
- data/ext/melbourne/local_state.hpp +43 -0
- data/ext/melbourne/melbourne.cpp +88 -0
- data/ext/melbourne/melbourne.hpp +19 -0
- data/ext/melbourne/node18.hpp +262 -0
- data/ext/melbourne/node19.hpp +271 -0
- data/ext/melbourne/node_types.rb +304 -0
- data/ext/melbourne/node_types18.cpp +255 -0
- data/ext/melbourne/node_types18.hpp +129 -0
- data/ext/melbourne/node_types19.cpp +249 -0
- data/ext/melbourne/node_types19.hpp +126 -0
- data/ext/melbourne/parser_state18.hpp +181 -0
- data/ext/melbourne/parser_state19.hpp +251 -0
- data/ext/melbourne/quark.cpp +42 -0
- data/ext/melbourne/quark.hpp +45 -0
- data/ext/melbourne/symbols.cpp +224 -0
- data/ext/melbourne/symbols.hpp +119 -0
- data/ext/melbourne/var_table18.cpp +83 -0
- data/ext/melbourne/var_table18.hpp +33 -0
- data/ext/melbourne/var_table19.cpp +65 -0
- data/ext/melbourne/var_table19.hpp +35 -0
- data/ext/melbourne/visitor18.cpp +963 -0
- data/ext/melbourne/visitor18.hpp +12 -0
- data/ext/melbourne/visitor19.cpp +960 -0
- data/ext/melbourne/visitor19.hpp +15 -0
- data/lib/compiler/ast/constants.rb +81 -0
- data/lib/compiler/ast/control_flow.rb +290 -0
- data/lib/compiler/ast/data.rb +14 -0
- data/lib/compiler/ast/definitions.rb +749 -0
- data/lib/compiler/ast/encoding.rb +18 -0
- data/lib/compiler/ast/exceptions.rb +138 -0
- data/lib/compiler/ast/file.rb +11 -0
- data/lib/compiler/ast/grapher.rb +89 -0
- data/lib/compiler/ast/literals.rb +207 -0
- data/lib/compiler/ast/node.rb +362 -0
- data/lib/compiler/ast/operators.rb +106 -0
- data/lib/compiler/ast/self.rb +15 -0
- data/lib/compiler/ast/sends.rb +615 -0
- data/lib/compiler/ast/transforms.rb +298 -0
- data/lib/compiler/ast/values.rb +88 -0
- data/lib/compiler/ast/variables.rb +351 -0
- data/lib/compiler/ast.rb +20 -0
- data/lib/compiler/locals.rb +109 -0
- data/lib/melbourne/processor.rb +651 -0
- data/lib/melbourne/version.rb +3 -0
- data/lib/melbourne.rb +143 -0
- metadata +112 -0
@@ -0,0 +1,651 @@
|
|
1
|
+
require 'compiler/locals'
|
2
|
+
require 'compiler/ast'
|
3
|
+
|
4
|
+
module Rubinius
|
5
|
+
class Melbourne
|
6
|
+
def process_parse_error(message, column, line, source)
|
7
|
+
@syntax_errors << SyntaxError.from(message, column, line, source, @name)
|
8
|
+
end
|
9
|
+
|
10
|
+
def process_dangling_node
|
11
|
+
puts "Processing called but node was NULL"
|
12
|
+
# TODO: output info about the current AST node
|
13
|
+
end
|
14
|
+
|
15
|
+
# This method is analogous to #method_missing. It is called
|
16
|
+
# if there is no processing method defined for a node.
|
17
|
+
def process_missing_node(line, node_name, node_type)
|
18
|
+
puts "Unhandled node #{node_name} (#{node_type})"
|
19
|
+
end
|
20
|
+
|
21
|
+
# TODO: remove when all processors are defined
|
22
|
+
def method_missing(sym, *args)
|
23
|
+
puts " *** missing #{sym} #{args.map { |x| x.inspect}.join(", ")}"
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
# Processing methods
|
28
|
+
|
29
|
+
def process_alias(line, to, from)
|
30
|
+
AST::Alias.new line, to, from
|
31
|
+
end
|
32
|
+
|
33
|
+
def process_and(line, left, right)
|
34
|
+
AST::And.new line, left, right
|
35
|
+
end
|
36
|
+
|
37
|
+
def process_args(line, args, defaults, splat)
|
38
|
+
AST::FormalArguments.new line, args, defaults, splat
|
39
|
+
end
|
40
|
+
|
41
|
+
def process_argscat(line, array, rest)
|
42
|
+
AST::ConcatArgs.new line, array, rest
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_argspush(line, arguments, value)
|
46
|
+
AST::PushArgs.new line, arguments, value
|
47
|
+
end
|
48
|
+
|
49
|
+
def process_array(line, array)
|
50
|
+
AST::ArrayLiteral.new line, array
|
51
|
+
end
|
52
|
+
|
53
|
+
def process_attrasgn(line, receiver, name, arguments)
|
54
|
+
if name == :[]=
|
55
|
+
AST::ElementAssignment.new line, receiver, arguments
|
56
|
+
else
|
57
|
+
AST::AttributeAssignment.new line, receiver, name, arguments
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def process_back_ref(line, ref)
|
62
|
+
AST::BackRef.new line, ref
|
63
|
+
end
|
64
|
+
|
65
|
+
def process_begin(line, body)
|
66
|
+
AST::Begin.new line, body
|
67
|
+
end
|
68
|
+
|
69
|
+
def process_block(line, array)
|
70
|
+
AST::Block.new line, array
|
71
|
+
end
|
72
|
+
|
73
|
+
def process_block_arg(line, name)
|
74
|
+
AST::BlockArgument.new line, name
|
75
|
+
end
|
76
|
+
|
77
|
+
def process_block_pass(line, method_send, body)
|
78
|
+
node = AST::BlockPass.new line, body
|
79
|
+
if method_send
|
80
|
+
method_send.block = node
|
81
|
+
method_send
|
82
|
+
else
|
83
|
+
node
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def process_break(line, value)
|
88
|
+
AST::Break.new line, value
|
89
|
+
end
|
90
|
+
|
91
|
+
def process_call(line, receiver, name, arguments)
|
92
|
+
if arguments.kind_of? AST::BlockPass
|
93
|
+
block = arguments
|
94
|
+
arguments = block.arguments
|
95
|
+
block.arguments = nil
|
96
|
+
else
|
97
|
+
block = nil
|
98
|
+
end
|
99
|
+
|
100
|
+
if node = process_transforms(line, receiver, name, arguments)
|
101
|
+
node.block = block if block
|
102
|
+
return node
|
103
|
+
end
|
104
|
+
|
105
|
+
if arguments
|
106
|
+
node = AST::SendWithArguments.new line, receiver, name, arguments
|
107
|
+
else
|
108
|
+
node = AST::Send.new line, receiver, name
|
109
|
+
end
|
110
|
+
|
111
|
+
node.block = block
|
112
|
+
node
|
113
|
+
end
|
114
|
+
|
115
|
+
def process_case(line, receiver, whens, else_body)
|
116
|
+
if receiver
|
117
|
+
AST::ReceiverCase.new line, receiver, whens, else_body
|
118
|
+
else
|
119
|
+
AST::Case.new line, whens, else_body
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def process_cdecl(line, expr, value)
|
124
|
+
AST::ConstantAssignment.new line, expr, value
|
125
|
+
end
|
126
|
+
|
127
|
+
def process_class(line, name, superclass, body)
|
128
|
+
AST::Class.new line, name, superclass, body
|
129
|
+
end
|
130
|
+
|
131
|
+
def process_colon2(line, outer, name)
|
132
|
+
if outer
|
133
|
+
if name == :Type and
|
134
|
+
outer.kind_of? AST::ConstantAccess and
|
135
|
+
outer.name == :Rubinius
|
136
|
+
AST::TypeConstant.new line
|
137
|
+
else
|
138
|
+
AST::ScopedConstant.new line, outer, name
|
139
|
+
end
|
140
|
+
else
|
141
|
+
AST::ConstantAccess.new line, name
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def process_colon3(line, name)
|
146
|
+
AST::ToplevelConstant.new line, name
|
147
|
+
end
|
148
|
+
|
149
|
+
def process_const(line, name)
|
150
|
+
AST::ConstantAccess.new line, name
|
151
|
+
end
|
152
|
+
|
153
|
+
def process_cvar(line, name)
|
154
|
+
AST::ClassVariableAccess.new line, name
|
155
|
+
end
|
156
|
+
|
157
|
+
def process_cvasgn(line, name, value)
|
158
|
+
AST::ClassVariableAssignment.new line, name, value
|
159
|
+
end
|
160
|
+
|
161
|
+
def process_cvdecl(line, name, value)
|
162
|
+
AST::ClassVariableDeclaration.new line, name, value
|
163
|
+
end
|
164
|
+
|
165
|
+
def process_defined(line, expr)
|
166
|
+
AST::Defined.new line, expr
|
167
|
+
end
|
168
|
+
|
169
|
+
def process_defn(line, name, body)
|
170
|
+
AST::Define.new line, name, body
|
171
|
+
end
|
172
|
+
|
173
|
+
def process_defs(line, receiver, name, body)
|
174
|
+
AST::DefineSingleton.new line, receiver, name, body
|
175
|
+
end
|
176
|
+
|
177
|
+
def process_dot2(line, start, finish)
|
178
|
+
AST::Range.new line, start, finish
|
179
|
+
end
|
180
|
+
|
181
|
+
def process_dot3(line, start, finish)
|
182
|
+
AST::RangeExclude.new line, start, finish
|
183
|
+
end
|
184
|
+
|
185
|
+
def process_dregx(line, str, array, flags)
|
186
|
+
AST::DynamicRegex.new line, str, array, flags
|
187
|
+
end
|
188
|
+
|
189
|
+
def process_dregx_once(line, str, array, flags)
|
190
|
+
AST::DynamicOnceRegex.new line, str, array, flags
|
191
|
+
end
|
192
|
+
|
193
|
+
def process_dstr(line, str, array)
|
194
|
+
AST::DynamicString.new line, str, array
|
195
|
+
end
|
196
|
+
|
197
|
+
def process_dsym(line, str, array)
|
198
|
+
AST::DynamicSymbol.new line, str, array
|
199
|
+
end
|
200
|
+
|
201
|
+
def process_dxstr(line, str, array)
|
202
|
+
AST::DynamicExecuteString.new line, str, array
|
203
|
+
end
|
204
|
+
|
205
|
+
def process_ensure(line, body, ensr)
|
206
|
+
AST::Ensure.new line, body, ensr
|
207
|
+
end
|
208
|
+
|
209
|
+
def process_evstr(line, value)
|
210
|
+
if value
|
211
|
+
AST::ToString.new line, value
|
212
|
+
else
|
213
|
+
AST::StringLiteral.new line, ""
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def process_false(line)
|
218
|
+
AST::FalseLiteral.new line
|
219
|
+
end
|
220
|
+
|
221
|
+
def process_fcall(line, name, arguments)
|
222
|
+
receiver = AST::Self.new line
|
223
|
+
|
224
|
+
if arguments.kind_of? AST::BlockPass
|
225
|
+
block = arguments
|
226
|
+
arguments = block.arguments
|
227
|
+
block.arguments = nil
|
228
|
+
else
|
229
|
+
block = nil
|
230
|
+
end
|
231
|
+
|
232
|
+
if node = process_transforms(line, receiver, name, arguments, true)
|
233
|
+
node.block = block if block
|
234
|
+
return node
|
235
|
+
end
|
236
|
+
|
237
|
+
if arguments
|
238
|
+
node = AST::SendWithArguments.new line, receiver, name, arguments, true
|
239
|
+
else
|
240
|
+
node = AST::Send.new line, receiver, name, true
|
241
|
+
end
|
242
|
+
|
243
|
+
node.block = block
|
244
|
+
node
|
245
|
+
end
|
246
|
+
|
247
|
+
def process_file(line)
|
248
|
+
AST::File.new line
|
249
|
+
end
|
250
|
+
|
251
|
+
def process_fixnum(line, value)
|
252
|
+
AST::FixnumLiteral.new line, value
|
253
|
+
end
|
254
|
+
|
255
|
+
def process_flip2(line, start, finish)
|
256
|
+
AST::Flip2.new line, start, finish
|
257
|
+
end
|
258
|
+
|
259
|
+
def process_flip3(line, start, finish)
|
260
|
+
AST::Flip3.new line, start, finish
|
261
|
+
end
|
262
|
+
|
263
|
+
def process_float(line, str)
|
264
|
+
AST::FloatLiteral.new line, str
|
265
|
+
end
|
266
|
+
|
267
|
+
def process_for(line, iter, arguments, body)
|
268
|
+
method_send = AST::Send.new line, iter, :each
|
269
|
+
method_send.block = AST::For.new line, arguments, body
|
270
|
+
method_send
|
271
|
+
end
|
272
|
+
|
273
|
+
def process_gasgn(line, name, expr)
|
274
|
+
AST::GlobalVariableAssignment.new line, name, expr
|
275
|
+
end
|
276
|
+
|
277
|
+
def process_gvar(line, name)
|
278
|
+
AST::GlobalVariableAccess.for_name line, name
|
279
|
+
end
|
280
|
+
|
281
|
+
def process_hash(line, array)
|
282
|
+
AST::HashLiteral.new line, array
|
283
|
+
end
|
284
|
+
|
285
|
+
def process_iasgn(line, name, value)
|
286
|
+
AST::InstanceVariableAssignment.new line, name, value
|
287
|
+
end
|
288
|
+
|
289
|
+
def process_if(line, cond, body, else_body)
|
290
|
+
AST::If.new line, cond, body, else_body
|
291
|
+
end
|
292
|
+
|
293
|
+
def process_iter(line, method_send, arguments, body)
|
294
|
+
method_send.block = AST::Iter.new line, arguments, body
|
295
|
+
method_send
|
296
|
+
end
|
297
|
+
|
298
|
+
def process_ivar(line, name)
|
299
|
+
AST::InstanceVariableAccess.new line, name
|
300
|
+
end
|
301
|
+
|
302
|
+
def process_lasgn(line, name, value)
|
303
|
+
AST::LocalVariableAssignment.new line, name, value
|
304
|
+
end
|
305
|
+
|
306
|
+
def process_lit(line, sym)
|
307
|
+
AST::SymbolLiteral.new line, sym
|
308
|
+
end
|
309
|
+
|
310
|
+
def process_lvar(line, name)
|
311
|
+
AST::LocalVariableAccess.new line, name
|
312
|
+
end
|
313
|
+
|
314
|
+
def process_masgn(line, left, right, splat)
|
315
|
+
AST::MultipleAssignment.new line, left, right, splat
|
316
|
+
end
|
317
|
+
|
318
|
+
def process_match(line, pattern, flags)
|
319
|
+
AST::Match.new line, pattern, flags
|
320
|
+
end
|
321
|
+
|
322
|
+
def process_match2(line, pattern, value)
|
323
|
+
AST::Match2.new line, pattern, value
|
324
|
+
end
|
325
|
+
|
326
|
+
def process_match3(line, pattern, value)
|
327
|
+
AST::Match3.new line, pattern, value
|
328
|
+
end
|
329
|
+
|
330
|
+
def process_module(line, name, body)
|
331
|
+
AST::Module.new line, name, body
|
332
|
+
end
|
333
|
+
|
334
|
+
def process_negate(line, value)
|
335
|
+
AST::Negate.new line, value
|
336
|
+
end
|
337
|
+
|
338
|
+
def process_next(line, value)
|
339
|
+
AST::Next.new line, value
|
340
|
+
end
|
341
|
+
|
342
|
+
def process_nil(line)
|
343
|
+
AST::NilLiteral.new line
|
344
|
+
end
|
345
|
+
|
346
|
+
def process_not(line, value)
|
347
|
+
AST::Not.new line, value
|
348
|
+
end
|
349
|
+
|
350
|
+
def process_nth_ref(line, ref)
|
351
|
+
AST::NthRef.new line, ref
|
352
|
+
end
|
353
|
+
|
354
|
+
# TODO: Fix the way 1.8 parser handles this
|
355
|
+
def process_number(line, base, str)
|
356
|
+
value = str.to_i base
|
357
|
+
case value
|
358
|
+
when Fixnum
|
359
|
+
AST::FixnumLiteral.new line, value
|
360
|
+
when Bignum
|
361
|
+
AST::NumberLiteral.new line, value
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
def process_op_asgn1(line, receiver, index, op, value)
|
366
|
+
AST::OpAssign1.new line, receiver, index, op, value
|
367
|
+
end
|
368
|
+
|
369
|
+
def process_op_asgn2(line, receiver, name, op, value)
|
370
|
+
AST::OpAssign2.new line, receiver, name, op, value
|
371
|
+
end
|
372
|
+
|
373
|
+
def process_op_asgn_and(line, var, value)
|
374
|
+
AST::OpAssignAnd.new line, var, value
|
375
|
+
end
|
376
|
+
|
377
|
+
def process_op_asgn_or(line, var, value)
|
378
|
+
AST::OpAssignOr.new line, var, value
|
379
|
+
end
|
380
|
+
|
381
|
+
def process_or(line, left, right)
|
382
|
+
AST::Or.new line, left, right
|
383
|
+
end
|
384
|
+
|
385
|
+
def process_postexe(line)
|
386
|
+
AST::Send.new line, AST::Self.new(line), :at_exit, true
|
387
|
+
end
|
388
|
+
|
389
|
+
def process_preexe(line)
|
390
|
+
node = AST::PreExe.new line
|
391
|
+
add_pre_exe node
|
392
|
+
node
|
393
|
+
end
|
394
|
+
|
395
|
+
def process_redo(line)
|
396
|
+
AST::Redo.new line
|
397
|
+
end
|
398
|
+
|
399
|
+
def process_regex(line, str, flags)
|
400
|
+
AST::RegexLiteral.new line, str, flags
|
401
|
+
end
|
402
|
+
|
403
|
+
def process_resbody(line, conditions, body, nxt)
|
404
|
+
AST::RescueCondition.new line, conditions, body, nxt
|
405
|
+
end
|
406
|
+
|
407
|
+
def process_rescue(line, body, rescue_body, else_body)
|
408
|
+
AST::Rescue.new line, body, rescue_body, else_body
|
409
|
+
end
|
410
|
+
|
411
|
+
def process_retry(line)
|
412
|
+
AST::Retry.new line
|
413
|
+
end
|
414
|
+
|
415
|
+
def process_return(line, value)
|
416
|
+
AST::Return.new line, value
|
417
|
+
end
|
418
|
+
|
419
|
+
def process_sclass(line, receiver, body)
|
420
|
+
AST::SClass.new line, receiver, body
|
421
|
+
end
|
422
|
+
|
423
|
+
def process_scope(line, body)
|
424
|
+
if body.kind_of? AST::Block
|
425
|
+
body
|
426
|
+
elsif body
|
427
|
+
AST::Block.new line, [body]
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
def process_self(line)
|
432
|
+
AST::Self.new line
|
433
|
+
end
|
434
|
+
|
435
|
+
def process_splat(line, expr)
|
436
|
+
AST::SplatValue.new line, expr
|
437
|
+
end
|
438
|
+
|
439
|
+
def process_str(line, str)
|
440
|
+
AST::StringLiteral.new line, str
|
441
|
+
end
|
442
|
+
|
443
|
+
def process_super(line, arguments)
|
444
|
+
AST::Super.new line, arguments
|
445
|
+
end
|
446
|
+
|
447
|
+
def process_svalue(line, expr)
|
448
|
+
AST::SValue.new line, expr
|
449
|
+
end
|
450
|
+
|
451
|
+
def process_to_ary(line, expr)
|
452
|
+
AST::ToArray.new line, expr
|
453
|
+
end
|
454
|
+
|
455
|
+
def process_true(line)
|
456
|
+
AST::TrueLiteral.new line
|
457
|
+
end
|
458
|
+
|
459
|
+
def process_undef(line, sym)
|
460
|
+
AST::Undef.new line, sym
|
461
|
+
end
|
462
|
+
|
463
|
+
def process_until(line, cond, body, check_first)
|
464
|
+
AST::Until.new line, cond, body, check_first
|
465
|
+
end
|
466
|
+
|
467
|
+
def process_vcall(line, name)
|
468
|
+
receiver = AST::Self.new line
|
469
|
+
|
470
|
+
if node = process_transforms(line, receiver, name, nil, true)
|
471
|
+
return node
|
472
|
+
end
|
473
|
+
|
474
|
+
AST::Send.new line, receiver, name, true, true
|
475
|
+
end
|
476
|
+
|
477
|
+
def process_valias(line, to, from)
|
478
|
+
AST::VAlias.new line, to, from
|
479
|
+
end
|
480
|
+
|
481
|
+
def process_values(line, first, rest)
|
482
|
+
rest.body.unshift first
|
483
|
+
rest
|
484
|
+
end
|
485
|
+
|
486
|
+
def process_when(line, conditions, body)
|
487
|
+
AST::When.new line, conditions, body
|
488
|
+
end
|
489
|
+
|
490
|
+
def process_while(line, cond, body, check_first)
|
491
|
+
AST::While.new line, cond, body, check_first
|
492
|
+
end
|
493
|
+
|
494
|
+
def process_xstr(line, str)
|
495
|
+
AST::ExecuteString.new line, str
|
496
|
+
end
|
497
|
+
|
498
|
+
def process_yield(line, arguments, unwrap)
|
499
|
+
AST::Yield.new line, arguments, unwrap
|
500
|
+
end
|
501
|
+
|
502
|
+
def process_zarray(line)
|
503
|
+
AST::EmptyArray.new line
|
504
|
+
end
|
505
|
+
|
506
|
+
def process_zsuper(line)
|
507
|
+
AST::ZSuper.new line
|
508
|
+
end
|
509
|
+
end
|
510
|
+
|
511
|
+
class Melbourne19 < Melbourne
|
512
|
+
def process_args(line, required, optional, splat, post, block)
|
513
|
+
AST::FormalArguments19.new line, required, optional, splat, post, block
|
514
|
+
end
|
515
|
+
|
516
|
+
def process_block_pass(line, arguments, body)
|
517
|
+
AST::BlockPass19.new line, arguments, body
|
518
|
+
end
|
519
|
+
|
520
|
+
def process_encoding(line, name)
|
521
|
+
AST::Encoding.new line, name
|
522
|
+
end
|
523
|
+
|
524
|
+
def process_postarg(line, into, rest)
|
525
|
+
AST::PostArg.new line, into, rest
|
526
|
+
end
|
527
|
+
|
528
|
+
def process_iter(line, method_send, scope)
|
529
|
+
ary = scope && scope.array || []
|
530
|
+
arguments = nil
|
531
|
+
|
532
|
+
if ary.first.kind_of? AST::FormalArguments
|
533
|
+
arguments = scope.array.shift
|
534
|
+
end
|
535
|
+
|
536
|
+
unless arguments
|
537
|
+
arguments = AST::FormalArguments19.new line, nil, nil, nil, nil, nil
|
538
|
+
end
|
539
|
+
|
540
|
+
case ary.size
|
541
|
+
when 0
|
542
|
+
body = nil
|
543
|
+
when 1
|
544
|
+
if scope.locals
|
545
|
+
body = scope
|
546
|
+
else
|
547
|
+
body = scope.array.shift
|
548
|
+
end
|
549
|
+
else
|
550
|
+
body = scope
|
551
|
+
end
|
552
|
+
|
553
|
+
method_send.block = AST::Iter19.new line, arguments, body
|
554
|
+
method_send
|
555
|
+
end
|
556
|
+
|
557
|
+
def process_for(line, iter, arguments, body)
|
558
|
+
send = AST::Send.new line, iter, :each
|
559
|
+
send.block = AST::For19.new line, arguments, body
|
560
|
+
send
|
561
|
+
end
|
562
|
+
|
563
|
+
def process_lambda(line, scope)
|
564
|
+
arguments = scope.array.shift
|
565
|
+
if scope.array.size == 1
|
566
|
+
body = scope.array.shift
|
567
|
+
else
|
568
|
+
body = scope
|
569
|
+
end
|
570
|
+
|
571
|
+
receiver = AST::Self.new line
|
572
|
+
method_send = AST::Send.new line, receiver, :lambda, true
|
573
|
+
|
574
|
+
method_send.block = AST::Iter19.new line, arguments, body
|
575
|
+
method_send
|
576
|
+
end
|
577
|
+
|
578
|
+
def process_number(line, value)
|
579
|
+
case value
|
580
|
+
when Fixnum
|
581
|
+
AST::FixnumLiteral.new line, value
|
582
|
+
when Bignum
|
583
|
+
AST::NumberLiteral.new line, value
|
584
|
+
end
|
585
|
+
end
|
586
|
+
|
587
|
+
def process_op_asgn_or(line, var, value)
|
588
|
+
AST::OpAssignOr19.new line, var, value
|
589
|
+
end
|
590
|
+
|
591
|
+
def process_opt_arg(line, arguments)
|
592
|
+
AST::Block.new line, arguments
|
593
|
+
end
|
594
|
+
|
595
|
+
def process_postexe(line, body)
|
596
|
+
node = AST::Send.new line, AST::Self.new(line), :at_exit, true
|
597
|
+
node.block = AST::Iter.new line, nil, body
|
598
|
+
node
|
599
|
+
end
|
600
|
+
|
601
|
+
def process_preexe(line, body)
|
602
|
+
node = AST::PreExe19.new line
|
603
|
+
node.block = AST::Iter19.new line, nil, body
|
604
|
+
add_pre_exe node
|
605
|
+
node
|
606
|
+
end
|
607
|
+
|
608
|
+
def process_scope(line, arguments, body, locals)
|
609
|
+
case body
|
610
|
+
when AST::Begin
|
611
|
+
if body.rescue.kind_of? AST::NilLiteral
|
612
|
+
return nil unless arguments
|
613
|
+
end
|
614
|
+
body = AST::Block.new line, [body.rescue]
|
615
|
+
when AST::Block
|
616
|
+
ary = body.array
|
617
|
+
if ary.size > 1 and
|
618
|
+
ary.first.kind_of?(AST::Begin) and
|
619
|
+
ary.first.rescue.kind_of?(AST::NilLiteral)
|
620
|
+
ary.shift
|
621
|
+
end
|
622
|
+
when nil
|
623
|
+
# Nothing
|
624
|
+
else
|
625
|
+
body = AST::Block.new line, [body]
|
626
|
+
end
|
627
|
+
|
628
|
+
if arguments and body
|
629
|
+
body.array.unshift arguments
|
630
|
+
end
|
631
|
+
|
632
|
+
body.locals = locals if locals
|
633
|
+
|
634
|
+
body
|
635
|
+
end
|
636
|
+
|
637
|
+
def process_super(line, arguments)
|
638
|
+
if arguments.kind_of? AST::BlockPass
|
639
|
+
block = arguments
|
640
|
+
arguments = block.arguments
|
641
|
+
block.arguments = nil
|
642
|
+
else
|
643
|
+
block = nil
|
644
|
+
end
|
645
|
+
|
646
|
+
node = AST::Super.new line, arguments
|
647
|
+
node.block = block
|
648
|
+
node
|
649
|
+
end
|
650
|
+
end
|
651
|
+
end
|