Class: Rubinius::ToolSet.current::TS::AST::While
- Inherits:
-
Node
- Object
- Node
- Rubinius::ToolSet.current::TS::AST::While
show all
- Defined in:
- lib/rubinius/ast/control_flow.rb
Direct Known Subclasses
Until
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, #or_bytecode, #pos, #set_child, transform, #transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk
Constructor Details
#initialize(line, condition, body, check_first) ⇒ While
Returns a new instance of While.
348
349
350
351
352
353
|
# File 'lib/rubinius/ast/control_flow.rb', line 348
def initialize(line, condition, body, check_first)
@line = line
@condition = condition
@body = body || NilLiteral.new(line)
@check_first = check_first
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
346
347
348
|
# File 'lib/rubinius/ast/control_flow.rb', line 346
def body
@body
end
|
#check_first ⇒ Object
Returns the value of attribute check_first.
346
347
348
|
# File 'lib/rubinius/ast/control_flow.rb', line 346
def check_first
@check_first
end
|
#condition ⇒ Object
Returns the value of attribute condition.
346
347
348
|
# File 'lib/rubinius/ast/control_flow.rb', line 346
def condition
@condition
end
|
Instance Method Details
#body_bytecode(g, lbl) ⇒ Object
364
365
366
367
368
369
370
371
372
373
374
|
# File 'lib/rubinius/ast/control_flow.rb', line 364
def body_bytecode(g, lbl)
g.state.push_loop
@body.bytecode(g)
g.state.pop_loop
lbl.set!
g.pop
g.check_interrupts
end
|
#bytecode(g, use_gif = true) ⇒ Object
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
# File 'lib/rubinius/ast/control_flow.rb', line 376
def bytecode(g, use_gif=true)
pos(g)
g.push_modifiers
top = g.new_label
post = g.next = g.new_label
bottom = g.new_label
g.break = g.new_label
if @check_first
g.redo = g.new_label
top.set!
condition_bytecode(g, bottom, use_gif)
g.redo.set!
body_bytecode(g, post)
else
g.redo = top
top.set!
body_bytecode(g, post)
condition_bytecode(g, bottom, use_gif)
end
g.goto top
g.set_line 0
bottom.set!
g.push :nil
g.break.set!
g.pop_modifiers
end
|
#condition_bytecode(g, bottom, use_gif) ⇒ Object
355
356
357
358
359
360
361
362
|
# File 'lib/rubinius/ast/control_flow.rb', line 355
def condition_bytecode(g, bottom, use_gif)
@condition.bytecode(g)
if use_gif
g.gif bottom
else
g.git bottom
end
end
|
#defined(g) ⇒ Object
416
417
418
|
# File 'lib/rubinius/ast/control_flow.rb', line 416
def defined(g)
g.push_literal "expression"
end
|
#sexp_name ⇒ Object
420
421
422
|
# File 'lib/rubinius/ast/control_flow.rb', line 420
def sexp_name
:while
end
|
#to_sexp ⇒ Object
424
425
426
|
# File 'lib/rubinius/ast/control_flow.rb', line 424
def to_sexp
[sexp_name, @condition.to_sexp, @body.to_sexp, @check_first]
end
|