Class: CastOff::Compiler::SimpleIR::LoopIR

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

Constant Summary

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 collapse

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?, #side_effect?, #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(loopkey, phase, param, argc, return_value, insn, cfg) ⇒ LoopIR

Returns a new instance of LoopIR.



1175
1176
1177
1178
1179
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1175

def initialize(loopkey, phase, param, argc, return_value, insn, cfg)
  super(param, argc, return_value, insn, cfg)
  @loop_phase = phase
  @loopkey = loopkey
end

Instance Attribute Details

#loop_phaseObject (readonly)

Returns the value of attribute loop_phase.



1173
1174
1175
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1173

def loop_phase
  @loop_phase
end

#loopkeyObject (readonly)

Returns the value of attribute loopkey.



1173
1174
1175
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1173

def loopkey
  @loopkey
end

Instance Method Details

#harmless?(recv_p) ⇒ Boolean

Returns:

  • (Boolean)


1250
1251
1252
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1250

def harmless?(recv_p)
  false
end

#propergate_guard_usageObject



1181
1182
1183
1184
1185
1186
1187
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1181

def propergate_guard_usage()
  params = param_irs()
  return if params.empty?
  recv = params.shift()
  recv.need_guard(true)
  params.each{|p| p.need_guard(false)}
end

#should_be_alive?Boolean

Returns:

  • (Boolean)


1254
1255
1256
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1254

def should_be_alive?
  true
end

#to_c(params) ⇒ Object



1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1189

def to_c(params)
  ret = []
  ret << super(params)
  param = param_variables()
  recv, *rest = *param
  s_param = rest.empty? ? nil : ", #{rest.join(", ")}"
  case @loop_phase
  when :cast_off_prep
    if @translator.inline_block?
      unless @loopkey.resolved?
        @translator.unsupported_or_re_compilation(<<-EOS)

<<< Failed to resolve iterater reciever type >>>
You should specify iterator reciever type, method name = #{@loopkey.id}.
-------------------------------------------------------------------------
Target file is (#{@translator.target_name()}).
Call site is (#{@insn}).
        EOS
      end
      @dependency.add(@loopkey.klass, @loopkey.id, true)
      ret << "  #{@return_value} = #{@loopkey.prep_func}(&#{@loopkey}, #{recv}, #{@argc - 1}#{s_param});"
    else
      ret << <<-EOS
  cast_off_set_block(#{@loopkey.block_iseq.block_generator()}(self));
  #{@return_value} = rb_funcall(#{recv}, #{@translator.allocate_id(@loopkey.id)}, #{@argc - 1}#{s_param});
#{@insn.iseq.update_dfp()}
      EOS
    end
  when :cast_off_loop
    if @translator.inline_block?
      bug() unless param.size == 1
      ret << "  #{@return_value} = #{@loopkey.loop_func}(&#{@loopkey}, #{param[0]}, #{@loopkey.argc}, cast_off_argv, #{@loopkey.splat? ? 1 : 0}, #{@loopkey.arg_argc}, #{@loopkey.arg_post_len}, #{@loopkey.arg_post_start}, #{@loopkey.arg_rest_index});"
    end
  when :cast_off_finl
    if @translator.inline_block?
      bug() unless param.empty?
      ret << "  #{@return_value} = #{@loopkey.finl_func}(&#{@loopkey});"
    end
  else
    bug()
  end
  ret.join("\n")
end

#to_verbose_stringObject



1258
1259
1260
1261
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1258

def to_verbose_string()
  recv = param_variables()[0]
  "[#{recv.dynamic? ? "dynamic" : recv.types.join(", ")}]##{@loopkey.id}"
end

#type_propergation(defs) ⇒ Object



1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1233

def type_propergation(defs)
  if @loop_phase == :cast_off_prep
    recv = @param[0].param_value
    @loopkey.resolve(recv.types) unless recv.undefined? || recv.dynamic?
  end

  case @loop_phase
  when :cast_off_prep
    return @return_value.is_dynamic()
  when :cast_off_loop
    return @return_value.is_static([TrueClass, FalseClass])
  when :cast_off_finl
    return @return_value.is_dynamic()
  end
  bug()
end