Class: Rubex::AST::Statement::For

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

Instance Attribute Summary

Attributes inherited from Base

#location

Instance Method Summary collapse

Methods inherited from Base

#==, #statement?

Constructor Details

#initialize(left_expr, left_op, middle, right_op, right_expr, statements, location) ⇒ For

Returns a new instance of For.



5
6
7
8
9
10
11
12
13
# File 'lib/rubex/ast/statement/for.rb', line 5

def initialize(left_expr, left_op, middle, right_op, right_expr, statements, location)
  super(location)
  @left_expr = left_expr
  @left_op = left_op
  @middle = middle
  @right_op = right_op
  @right_expr = right_expr
  @statements = statements
end

Instance Method Details

#analyse_statement(local_scope) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubex/ast/statement/for.rb', line 15

def analyse_statement(local_scope)
  @left_expr.analyse_types local_scope
  @right_expr.analyse_types local_scope

  [@left_expr, @right_expr].each do |e|
    e.allocate_temps local_scope
  end
  [@left_expr, @right_expr].each do |e|
    e.release_temps local_scope
  end

  @middle = local_scope[@middle] # middle will not be an expr.
  @statements.each do |stat|
    stat.analyse_statement local_scope
  end
end

#generate_code(code, local_scope) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/rubex/ast/statement/for.rb', line 32

def generate_code(code, local_scope)
  code << for_loop_header(code, local_scope)
  code.block do
    @statements.each do |stat|
      stat.generate_code code, local_scope
    end
  end
  @left_expr.generate_disposal_code code
  @right_expr.generate_disposal_code code
end