Class: Rubex::AST::Expression::Yield

Inherits:
Base
  • Object
show all
Defined in:
lib/rubex/ast/expression/command_call/yield.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(args) ⇒ Yield

Returns a new instance of Yield.



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

def initialize(args)
  @args = args
end

Instance Method Details

#analyse_types(local_scope) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rubex/ast/expression/command_call/yield.rb', line 9

def analyse_types(local_scope)
  @args = @args.map do |arg|
    arg.analyse_types local_scope
    arg.allocate_temps local_scope
    arg.to_ruby_object
  end
  @args.each do |arg|
    arg.release_temps local_scope
  end
  @subexprs = @args
end

#generate_evaluation_code(code, local_scope) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rubex/ast/expression/command_call/yield.rb', line 21

def generate_evaluation_code(code, local_scope)
  generate_and_dispose_subexprs(code, local_scope) do
    if !@args.empty?
      code << "rb_yield_values(#{@args.size}, "
      code << (@args.map { |a| a.c_code(local_scope) }.join(',')).to_s
      code << ');'
    else
      code << 'rb_yield(Qnil);'
    end
    code.nl
  end
end