Class: Duby::AST::LocalAssignment

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

#scope

Methods inherited from Node

#[], #each, #inspect, #line_number, #log, #resolve_if, #resolved!, #resolved?, #simple_name, #temp

Constructor Details

#initialize(parent, line_number, name, &block) ⇒ LocalAssignment

Returns a new instance of LocalAssignment.



33
34
35
36
37
# File 'lib/duby/ast/local.rb', line 33

def initialize(parent, line_number, name, &block)
  super(parent, line_number, children, &block)
  @value = children[0]
  @name = name
end

Instance Method Details

#compile(compiler, expression) ⇒ Object



89
90
91
92
# File 'lib/duby/compiler.rb', line 89

def compile(compiler, expression)
  compiler.line(line_number)
  compiler.local_assign(name, inferred_type, expression, value)
end

#expr?(compiler) ⇒ Boolean

Returns:



105
106
107
# File 'lib/duby/jvm/source_generator/precompile.rb', line 105

def expr?(compiler)
  compiler.method.local?(name) && value.expr?(compiler)
end

#infer(typer) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/duby/ast/local.rb', line 43

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

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

  @inferred_type
end

#precompile(compiler) ⇒ Object



109
110
111
112
113
114
115
116
# File 'lib/duby/jvm/source_generator/precompile.rb', line 109

def precompile(compiler)
  if expr?(compiler)
    self
  else
    compile(compiler, false)
    TempValue.new(name)
  end
end

#to_sObject



39
40
41
# File 'lib/duby/ast/local.rb', line 39

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