Class: Duby::AST::LocalAssignment
- Inherits:
-
Node
- Object
- Node
- Duby::AST::LocalAssignment
show all
- Includes:
- Named, Scoped, Valued
- Defined in:
- lib/duby/compiler.rb,
lib/duby/ast/local.rb,
lib/duby/jvm/source_generator/precompile.rb
Instance Attribute Summary
Attributes included from Valued
#value
Attributes included from Typed
#type
Attributes included from Named
#name
Attributes inherited from Node
#children, #inferred_type, #newline, #parent, #position
Instance Method Summary
collapse
Methods included from Scoped
#containing_scope, #scope
Methods inherited from Node
#<<, ===, #[], #_set_parent, child, child_name, #each, #empty?, #initialize_copy, #insert, #inspect, #line_number, #log, #resolve_if, #resolved?, #simple_name, #temp
Constructor Details
#initialize(parent, line_number, name, &block) ⇒ LocalAssignment
Returns a new instance of LocalAssignment.
38
39
40
41
|
# File 'lib/duby/ast/local.rb', line 38
def initialize(parent, line_number, name, &block)
super(parent, line_number, &block)
@name = name
end
|
Instance Method Details
43
44
45
|
# File 'lib/duby/ast/local.rb', line 43
def captured?
scope.static_scope.captured?(name)
end
|
#compile(compiler, expression) ⇒ Object
131
132
133
134
135
136
137
138
|
# File 'lib/duby/compiler.rb', line 131
def compile(compiler, expression)
compiler.line(line_number)
if captured? && scope.has_binding?
compiler.captured_local_assign(self, expression)
else
compiler.local_assign(containing_scope, name, inferred_type, expression, value)
end
end
|
#expr?(compiler) ⇒ Boolean
121
122
123
|
# File 'lib/duby/jvm/source_generator/precompile.rb', line 121
def expr?(compiler)
compiler.method.local?(name) && value.expr?(compiler)
end
|
#infer(typer) ⇒ Object
51
52
53
54
55
56
|
# File 'lib/duby/ast/local.rb', line 51
def infer(typer)
resolve_if(typer) do
scope.static_scope << name
typer.infer(value)
end
end
|
#precompile(compiler) ⇒ Object
125
126
127
128
129
130
131
132
|
# File 'lib/duby/jvm/source_generator/precompile.rb', line 125
def precompile(compiler)
if expr?(compiler)
self
else
compile(compiler, false)
TempValue.new(name)
end
end
|
#resolved!(typer) ⇒ Object
58
59
60
61
|
# File 'lib/duby/ast/local.rb', line 58
def resolved!(typer)
typer.learn_local_type(containing_scope, name, @inferred_type)
super
end
|
#to_s ⇒ Object
47
48
49
|
# File 'lib/duby/ast/local.rb', line 47
def to_s
"LocalAssignment(name = #{name}, scope = #{scope}, captured = #{captured? == true})"
end
|