Class: CodeTools::AST::While
- Inherits:
-
Node
- Object
- Node
- CodeTools::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.
347
348
349
350
351
352
|
# File 'lib/rubinius/ast/control_flow.rb', line 347
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.
345
346
347
|
# File 'lib/rubinius/ast/control_flow.rb', line 345
def body
@body
end
|
#check_first ⇒ Object
Returns the value of attribute check_first.
345
346
347
|
# File 'lib/rubinius/ast/control_flow.rb', line 345
def check_first
@check_first
end
|
#condition ⇒ Object
Returns the value of attribute condition.
345
346
347
|
# File 'lib/rubinius/ast/control_flow.rb', line 345
def condition
@condition
end
|
Instance Method Details
#body_bytecode(g, lbl) ⇒ Object
363
364
365
366
367
368
369
370
371
372
373
|
# File 'lib/rubinius/ast/control_flow.rb', line 363
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
375
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
|
# File 'lib/rubinius/ast/control_flow.rb', line 375
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
354
355
356
357
358
359
360
361
|
# File 'lib/rubinius/ast/control_flow.rb', line 354
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
415
416
417
|
# File 'lib/rubinius/ast/control_flow.rb', line 415
def defined(g)
g.push_literal "expression"
end
|
#sexp_name ⇒ Object
419
420
421
|
# File 'lib/rubinius/ast/control_flow.rb', line 419
def sexp_name
:while
end
|
#to_sexp ⇒ Object
423
424
425
|
# File 'lib/rubinius/ast/control_flow.rb', line 423
def to_sexp
[sexp_name, @condition.to_sexp, @body.to_sexp, @check_first]
end
|