Class: Duby::AST::ForLoop
- Defined in:
- lib/duby/ast/flow.rb,
lib/duby/compiler.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#iter ⇒ Object
readonly
Returns the value of attribute iter.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Loop
Attributes inherited from Node
#children, #inferred_type, #newline, #parent, #position
Instance Method Summary collapse
- #compile(compiler, expression) ⇒ Object
- #infer(typer) ⇒ Object
-
#initialize(parent, position, &block) ⇒ ForLoop
constructor
A new instance of ForLoop.
Methods inherited from Loop
Methods inherited from Node
#[], #each, #expr?, #inspect, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #temp, #to_s
Constructor Details
#initialize(parent, position, &block) ⇒ ForLoop
Returns a new instance of ForLoop.
135 136 137 138 139 140 141 |
# File 'lib/duby/ast/flow.rb', line 135 def initialize(parent, position, &block) super(parent, position, &block) var = children.shift @body, @iter = children @scope = var.scope @name = var.name end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
133 134 135 |
# File 'lib/duby/ast/flow.rb', line 133 def body @body end |
#iter ⇒ Object (readonly)
Returns the value of attribute iter.
133 134 135 |
# File 'lib/duby/ast/flow.rb', line 133 def iter @iter end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
133 134 135 |
# File 'lib/duby/ast/flow.rb', line 133 def name @name end |
Instance Method Details
#compile(compiler, expression) ⇒ Object
160 161 162 163 |
# File 'lib/duby/compiler.rb', line 160 def compile(compiler, expression) compiler.line(line_number) compiler.for_loop(self, expression) end |
#infer(typer) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/duby/ast/flow.rb', line 143 def infer(typer) super iter_type = @iter.inferred_type if iter_type if !iter_type.iterable? raise "#{iter_type} is not iterable." end typer.learn_local_type(@scope, name, iter_type.component_type) end @inferred_type end |