Class: Rubex::AST::Statement::While

Inherits:
Base
  • Object
show all
Defined in:
lib/rubex/ast/statement/while.rb

Instance Attribute Summary

Attributes inherited from Base

#location

Instance Method Summary collapse

Methods inherited from Base

#==, #statement?

Constructor Details

#initialize(expr, statements, location) ⇒ While

Returns a new instance of While.



5
6
7
8
9
# File 'lib/rubex/ast/statement/while.rb', line 5

def initialize(expr, statements, location)
  super(location)
  @expr = expr
  @statements = statements
end

Instance Method Details

#analyse_statement(local_scope) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/rubex/ast/statement/while.rb', line 11

def analyse_statement(local_scope)
  @expr.analyse_types local_scope
  @expr.release_temps local_scope
  @statements.each do |stat|
    stat.analyse_statement local_scope
  end
  @expr.release_temps local_scope
end

#generate_code(code, local_scope) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubex/ast/statement/while.rb', line 20

def generate_code(code, local_scope)
  @expr.generate_evaluation_code code, local_scope
  stmt = "while (#{@expr.c_code(local_scope)})"
  code << stmt
  code.block do
    @statements.each do |stat|
      stat.generate_code code, local_scope
    end
  end
  @expr.generate_disposal_code code
end