Class: CastOff::Compiler::SimpleIR::YieldIR

Inherits:
CallIR
  • Object
show all
Defined in:
lib/cast_off/compile/ir/call_ir.rb

Constant Summary collapse

SPLATCALL_TEMPLATE_YIELD =
ERB.new(<<-EOS, 0, '%-', 'io')
%bug() unless param.size > 0
  {
    int argc = <%= @argc - 1 %>;
    VALUE buf[<%= SPLATCALL_LIMIT %>]; /* FIXME */
    VALUE *argv = buf;
%splat_param  = param.last()
%normal_param = param.slice(0, param.size() - 1)
    VALUE ary = <%= splat_param %>;
%if splat_param.is_just?(Array)
%  is_ary = true
    VALUE tmp = ary;
%else
%  is_ary = false
    VALUE tmp = rb_check_convert_type(ary, T_ARRAY, "Array", "to_a");
%end

%normal_param.each_with_index do |p, i|
    argv[<%= i %>] = <%= p %>;
%end
%unless is_ary
    if (NIL_P(tmp)) {
/* do nothing */
    } else {
%else
    {
%end
VALUE *ptr;
long i, len = RARRAY_LEN(tmp);
ptr = RARRAY_PTR(tmp);
argc += len;
if (UNLIKELY(argc > <%= SPLATCALL_LIMIT %>)) {
  VALUE *newbuf = ALLOCA_N(VALUE, argc);
%normal_param.size.times do |i|
  newbuf[i] = argv[i];
%end
  argv = newbuf;
}
for (i = 0; i < len; i++) {
  argv[<%= normal_param.size %> + i] = ptr[i];
}
    }
    rb_yield_values2(argc, argv);
  }
EOS

Constants included from Instruction

Instruction::BlockSeparator, Instruction::BranchInstruction, Instruction::IgnoreInstruction, Instruction::JumpOrReturnInstruction, Instruction::SupportInstruction, Instruction::TypeInfoUser, Instruction::VM_CALL_ARGS_BLOCKARG_BIT, Instruction::VM_CALL_ARGS_SPLAT_BIT, Instruction::VM_CALL_FCALL_BIT, Instruction::VM_CALL_OPT_SEND_BIT, Instruction::VM_CALL_SUPER_BIT, Instruction::VM_CALL_TAILCALL_BIT, Instruction::VM_CALL_TAILRECURSION_BIT, Instruction::VM_CALL_VCALL_BIT

Instance Attribute Summary

Attributes inherited from CallIR

#argc, #result_variable, #return_value, #values, #variables, #variables_without_result

Attributes inherited from IR

#alias, #insn

Instance Method Summary collapse

Methods inherited from CallIR

#can_not_unbox, #mark, #param_irs, #param_variables, #propergate_boxed_value, #propergate_exact_class, #sampling_return_value, #sampling_return_value?, #unboxing_prelude

Methods included from Util

#bug, #dlog, #todo, #vlog

Methods inherited from IR

#add_sampling_variable, #alive, #alive?, #dispatch_method?, #generate_guard, #get_definition, #get_definition_str, #get_usage, #get_variable, #inlining_target?, #propergate_boxed_value, #reset, #sampling_variable, #set_info, #standard_guard_target, #unboxing_prelude, #vanish, #vanish?

Constructor Details

#initialize(flags, param, argc, return_value, insn, cfg) ⇒ YieldIR

Returns a new instance of YieldIR.



1386
1387
1388
1389
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1386

def initialize(flags, param, argc, return_value, insn, cfg)
  super(param, argc, return_value, insn, cfg)
  @flags = flags
end

Instance Method Details

#harmless?(recv_p) ⇒ Boolean

Returns:

  • (Boolean)


1468
1469
1470
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1468

def harmless?(recv_p)
  false
end

#propergate_guard_usageObject



1391
1392
1393
1394
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1391

def propergate_guard_usage()
  params = param_irs()
  params.each{|p| p.need_guard(splatyield?)}
end

#should_be_alive?Boolean

Returns:

  • (Boolean)


1472
1473
1474
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1472

def should_be_alive?
  true
end

#side_effect?Boolean

Returns:

  • (Boolean)


1476
1477
1478
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1476

def side_effect?
  true
end

#splatyield?Boolean

Returns:

  • (Boolean)


1480
1481
1482
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1480

def splatyield?
  (@flags & VM_CALL_ARGS_SPLAT_BIT) != 0
end

#to_c(params) ⇒ Object



1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1442

def to_c(params)
  ret = []
  ret << super(params)
  param = param_variables()

  if splatyield?
    ret << SPLATCALL_TEMPLATE_YIELD.trigger(binding)
  else
    if param.empty?
      ret << "  #{@return_value} = rb_yield(Qundef);"
    else
      ret << "  #{@return_value} = rb_yield_values(#{param.size}, #{param.join(", ")});"
    end
  end

  ret.join("\n")
end

#to_verbose_stringObject



1460
1461
1462
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1460

def to_verbose_string()
  "yield"
end

#type_propergation(defs) ⇒ Object



1464
1465
1466
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1464

def type_propergation(defs)
  @return_value.is_dynamic()
end