Class: Mirah::AST::Local

Inherits:
Node
  • Object
show all
Includes:
Named, Scoped
Defined in:
lib/mirah/ast/local.rb,
lib/mirah/compiler/local.rb

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 included from Named

#string_value, #validate_name

Methods inherited from Node

#<<, ===, #[], #[]=, #_dump, _load, #_set_parent, child, child_name, #child_nodes, #each, #empty?, #expr?, #inferred_type!, #initialize_copy, #insert, #inspect, #inspect_children, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #string_value, #temp, #top_level?, #validate_child, #validate_children

Constructor Details

#initialize(parent, line_number, name) ⇒ Local

Returns a new instance of Local.



88
89
90
91
# File 'lib/mirah/ast/local.rb', line 88

def initialize(parent, line_number, name)
  super(parent, line_number, [])
  self.name = name
end

Instance Method Details

#captured?Boolean

Returns:



93
94
95
# File 'lib/mirah/ast/local.rb', line 93

def captured?
  scope && scope.static_scope.captured?(name)
end

#compile(compiler, expression) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mirah/compiler/local.rb', line 45

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
rescue Exception => ex
  raise Mirah::InternalCompilerError.wrap(ex, self)
end

#infer(typer, expression) ⇒ Object



105
106
107
108
109
110
# File 'lib/mirah/ast/local.rb', line 105

def infer(typer, expression)
  resolve_if(typer) do
    scope.static_scope << name
    typer.local_type(containing_scope, name)
  end
end

#to_sObject



97
98
99
# File 'lib/mirah/ast/local.rb', line 97

def to_s
  "Local(name = #{name}, scope = #{scope}, captured = #{captured? == true})"
end

#type_reference(typer) ⇒ Object



101
102
103
# File 'lib/mirah/ast/local.rb', line 101

def type_reference(typer)
  typer.type_reference(scope, @name)
end