Class: Rubinius::AST::MultipleAssignment
- Inherits:
-
Node
- Object
- Node
- Rubinius::AST::MultipleAssignment
show all
- Defined in:
- lib/compiler/ast/variables.rb
Instance Attribute Summary collapse
Attributes inherited from Node
#line
Instance Method Summary
collapse
Methods inherited from Node
#ascii_graph, #attributes, #children, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, node_name, #pos, #set_child, transform, #transform, transform_comment, transform_kind, transform_kind=, transform_name, #visit, #walk
Constructor Details
#initialize(line, left, right, splat) ⇒ MultipleAssignment
Returns a new instance of MultipleAssignment.
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
# File 'lib/compiler/ast/variables.rb', line 233
def initialize(line, left, right, splat)
@line = line
@left = left
@right = right
@splat = nil
@block = nil @post = nil
if Rubinius.ruby18?
@fixed = right.kind_of?(ArrayLiteral) ? true : false
elsif splat.kind_of?(PostArg)
@fixed = false
@post = splat.rest
splat = splat.into
elsif right.kind_of?(ArrayLiteral)
@fixed = right.body.size > 1
else
@fixed = false
end
if splat.kind_of? Node
if @left
if right
@splat = SplatAssignment.new line, splat
else
@splat = SplatWrapped.new line, splat
end
elsif @fixed
@splat = SplatArray.new line, splat, right.body.size
elsif right.kind_of? SplatValue
@splat = splat
else
@splat = SplatWrapped.new line, splat
end
elsif splat
size = @fixed ? right.body.size : 0
@splat = EmptySplat.new line, size
end
end
|
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
231
232
233
|
# File 'lib/compiler/ast/variables.rb', line 231
def block
@block
end
|
#left ⇒ Object
Returns the value of attribute left.
231
232
233
|
# File 'lib/compiler/ast/variables.rb', line 231
def left
@left
end
|
#right ⇒ Object
Returns the value of attribute right.
231
232
233
|
# File 'lib/compiler/ast/variables.rb', line 231
def right
@right
end
|
#splat ⇒ Object
Returns the value of attribute splat.
231
232
233
|
# File 'lib/compiler/ast/variables.rb', line 231
def splat
@splat
end
|
Instance Method Details
#declare_local_scope(scope) ⇒ Object
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
# File 'lib/compiler/ast/variables.rb', line 305
def declare_local_scope(scope)
if @left
@left.body.each do |var|
case var
when LocalVariable
scope.assign_local_reference var
when MultipleAssignment
var.declare_local_scope(scope)
end
end
end
if @splat and @splat.kind_of?(SplatAssignment)
if @splat.value.kind_of?(LocalVariable)
scope.assign_local_reference @splat.value
end
end
end
|
#iter_arguments ⇒ Object
301
302
303
|
# File 'lib/compiler/ast/variables.rb', line 301
def iter_arguments
@iter_arguments = true
end
|
#make_array(g) ⇒ Object
287
288
289
290
|
# File 'lib/compiler/ast/variables.rb', line 287
def make_array(g)
size = @right.body.size - @left.body.size
g.make_array size if size >= 0
end
|
#pad_short(g) ⇒ Object
274
275
276
277
278
279
280
|
# File 'lib/compiler/ast/variables.rb', line 274
def pad_short(g)
short = @left.body.size - @right.body.size
if short > 0
short.times { g.push :nil }
g.make_array 0 if @splat
end
end
|
#pop_excess(g) ⇒ Object
282
283
284
285
|
# File 'lib/compiler/ast/variables.rb', line 282
def pop_excess(g)
excess = @right.body.size - @left.body.size
excess.times { g.pop } if excess > 0
end
|
#rotate(g) ⇒ Object
292
293
294
295
296
297
298
299
|
# File 'lib/compiler/ast/variables.rb', line 292
def rotate(g)
if @splat
size = @left.body.size + 1
else
size = @right.body.size
end
g.rotate size
end
|
#to_sexp ⇒ Object
328
329
330
331
332
333
334
335
336
|
# File 'lib/compiler/ast/variables.rb', line 328
def to_sexp
left = @left ? @left.to_sexp : [:array]
left << [:splat, @splat.to_sexp] if @splat
left << @block.to_sexp if @block
sexp = [:masgn, left]
sexp << @right.to_sexp if @right
sexp
end
|