Class: Duby::AST::Print

Inherits:
Node show all
Defined in:
lib/duby/compiler.rb,
lib/duby/ast/intrinsics.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #inferred_type, #newline, #parent, #position

Instance Method Summary collapse

Methods inherited from Node

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

Constructor Details

#initialize(parent, line_number, println, &block) ⇒ Print

Returns a new instance of Print.



6
7
8
9
10
# File 'lib/duby/ast/intrinsics.rb', line 6

def initialize(parent, line_number, println, &block)
  super(parent, line_number, &block)
  @parameters = children
  @println = println
end

Instance Attribute Details

#parametersObject

Returns the value of attribute parameters.



3
4
5
# File 'lib/duby/ast/intrinsics.rb', line 3

def parameters
  @parameters
end

#printlnObject

Returns the value of attribute println.



4
5
6
# File 'lib/duby/ast/intrinsics.rb', line 4

def println
  @println
end

Instance Method Details

#compile(compiler, expression) ⇒ Object



65
66
67
68
69
# File 'lib/duby/compiler.rb', line 65

def compile(compiler, expression)
  # TODO: what does it mean for printline to be an expression?
  compiler.line(line_number)
  compiler.print(self)
end

#infer(typer) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/duby/ast/intrinsics.rb', line 12

def infer(typer)
  if parameters.size > 0
    resolved = parameters.select {|param| typer.infer(param); param.resolved?}
    resolved! if resolved.size == parameters.size
  else
    resolved!
  end
  typer.no_type
end