Class: Rubex::AST::Expression::Print

Inherits:
Base
  • Object
show all
Defined in:
lib/rubex/ast/expression/command_call/print.rb

Instance Attribute Summary

Attributes inherited from Base

#entry, #type, #typecast

Instance Method Summary collapse

Methods inherited from Base

#allocate_temp, #allocate_temps, #analyse_for_target_type, #c_code, #expression?, #from_ruby_object, #generate_and_dispose_subexprs, #generate_assignment_code, #generate_disposal_code, #has_temp, #possible_typecast, #release_temp, #release_temps, #to_ruby_object

Constructor Details

#initialize(expressions) ⇒ Print

Returns a new instance of Print.



5
6
7
# File 'lib/rubex/ast/expression/command_call/print.rb', line 5

def initialize(expressions)
  @expressions = expressions
end

Instance Method Details

#analyse_types(local_scope) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/rubex/ast/expression/command_call/print.rb', line 9

def analyse_types(local_scope)
  @expressions.each do |expr|
    expr.analyse_types local_scope
    expr.allocate_temps local_scope
    expr.release_temps local_scope
  end
end

#generate_evaluation_code(code, local_scope) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rubex/ast/expression/command_call/print.rb', line 17

def generate_evaluation_code(code, local_scope)
  super
  @expressions.each do |expr|
    expr.generate_evaluation_code code, local_scope

    str = 'printf('
    str << "\"#{expr.type.p_formatter}\""
    str << ", #{inspected_expr(expr, local_scope)}"
    str << ');'
    code << str
    code.nl

    expr.generate_disposal_code code
  end

  code.nl
end