Class: Duby::AST::Constant

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

#to_s

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, name) ⇒ Constant

Returns a new instance of Constant.



155
156
157
158
# File 'lib/duby/ast.rb', line 155

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

Instance Method Details

#compile(compiler, expression) ⇒ Object



56
57
58
59
60
61
# File 'lib/duby/compiler.rb', line 56

def compile(compiler, expression)
  if expression
    compiler.line(line_number)
    compiler.constant(self)
  end
end

#infer(typer) ⇒ Object



160
161
162
163
164
# File 'lib/duby/ast.rb', line 160

def infer(typer)
  @inferred_type ||= begin
    typer.type_reference(name, false, true)
  end
end