Class: Duby::AST::Local
Instance Attribute Summary
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?, #expr?, #initialize_copy, #insert, #inspect, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #temp
Constructor Details
#initialize(parent, line_number, name) ⇒ Local
Returns a new instance of Local.
68
69
70
71
|
# File 'lib/duby/ast/local.rb', line 68
def initialize(parent, line_number, name)
super(parent, line_number, [])
@name = name
end
|
Instance Method Details
73
74
75
|
# File 'lib/duby/ast/local.rb', line 73
def captured?
scope.static_scope.captured?(name)
end
|
#compile(compiler, expression) ⇒ Object
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/duby/compiler.rb', line 107
def compile(compiler, expression)
if expression
compiler.line(line_number)
if captured? && scope.has_binding?
compiler.captured_local(containing_scope, name, inferred_type)
else
compiler.local(containing_scope, name, inferred_type)
end
end
end
|
#infer(typer) ⇒ Object
81
82
83
84
85
86
|
# File 'lib/duby/ast/local.rb', line 81
def infer(typer)
resolve_if(typer) do
scope.static_scope << name
typer.local_type(containing_scope, name)
end
end
|
#to_s ⇒ Object
77
78
79
|
# File 'lib/duby/ast/local.rb', line 77
def to_s
"Local(name = #{name}, scope = #{scope}, captured = #{captured? == true})"
end
|