Class: CastOff::Compiler::SimpleIR::Defined
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
Attributes inherited from VMInsnIR
#argv
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 VMInsnIR
#dont_duplicate_if_harmless
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(param, argc, return_value, insn, cfg) ⇒ Defined
Returns a new instance of Defined.
1047
1048
1049
1050
1051
1052
1053
1054
1055
|
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1047
def initialize(param, argc, return_value, insn, cfg)
super(param, argc, return_value, insn, cfg)
argv = insn.argv
@defined_t = argv[0]
sym = argv[1]
bug() unless sym.instance_of?(Symbol)
@id = @translator.allocate_id(sym)
@needstr = argv[2] end
|
Instance Method Details
#harmless?(recv_p) ⇒ Boolean
1117
1118
1119
|
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1117
def harmless?(recv_p)
true
end
|
#propergate_guard_usage ⇒ Object
1057
1058
1059
1060
|
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1057
def propergate_guard_usage()
params = param_irs()
params.each{|p| p.need_guard(false)}
end
|
#should_be_alive? ⇒ Boolean
1121
1122
1123
|
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1121
def should_be_alive?
false
end
|
#side_effect? ⇒ Boolean
1125
1126
1127
|
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1125
def side_effect?
false
end
|
#to_c(params) ⇒ Object
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
|
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1062
def to_c(params)
ret = []
ret << super(params)
param = param_variables()
val = param.pop()
case @defined_t
when DEFINED_IVAR
ret << <<-EOS
if (rb_ivar_defined(self, #{@id})) {
#{@return_value} = #{@needstr ? 'rb_str_new2("instance-variable")' : 'Qtrue'};
} else {
#{@return_value} = Qnil;
}
EOS
when DEFINED_GVAR
ret << <<-EOS
if (rb_gvar_defined(rb_global_entry(#{@id}))) {
#{@return_value} = #{@needstr ? 'rb_str_new2("global-variable")' : 'Qtrue'};
} else {
#{@return_value} = Qnil;
}
EOS
when DEFINED_FUNC
ret << <<-EOS
if (rb_method_boundp(rb_class_of(#{val}), #{@id}, 0)) {
#{@return_value} = #{@needstr ? 'rb_str_new2("method")' : 'Qtrue'};
} else {
#{@return_value} = Qnil;
}
EOS
when DEFINED_CONST
ret << <<-EOS
if (cast_off_const_defined(#{val}, #{@id})) {
#{@return_value} = #{@needstr ? 'rb_str_new2("constant")' : 'Qtrue'};
} else {
#{@return_value} = Qnil;
}
EOS
else
bug()
end
bug() unless param.empty?
ret.join("\n")
end
|
#type_propergation(defs) ⇒ Object
1109
1110
1111
1112
1113
1114
1115
|
# File 'lib/cast_off/compile/ir/call_ir.rb', line 1109
def type_propergation(defs)
if @needstr
@return_value.is_static([NilClass, String])
else
@return_value.is_static([NilClass, TrueClass])
end
end
|