Class: Duby::AST::Local

Inherits:
Node show all
Includes:
Named, Scoped
Defined in:
lib/duby/compiler.rb,
lib/duby/ast/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

#scope

Methods inherited from Node

#[], #each, #expr?, #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.



58
59
60
61
# File 'lib/duby/ast/local.rb', line 58

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

Instance Method Details

#compile(compiler, expression) ⇒ Object



73
74
75
76
77
78
# File 'lib/duby/compiler.rb', line 73

def compile(compiler, expression)
  if expression
    compiler.line(line_number)
    compiler.local(name, inferred_type)
  end
end

#infer(typer) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/duby/ast/local.rb', line 67

def infer(typer)
  unless @inferred_type
    @inferred_type = typer.local_type(scope, name)

    @inferred_type ? resolved! : typer.defer(self)
  end

  @inferred_type
end

#to_sObject



63
64
65
# File 'lib/duby/ast/local.rb', line 63

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