def __init__(self, cpu, cliloop): self.setoptions() self.cpu = cpu self.name = cliloop.get_fresh_cli_name() self.cliloop = cliloop self.boxes = {} # box --> local var self.branches = [] self.branchlabels = [] self.consts = {} # object --> index self.meth_wrapper = self._get_meth_wrapper() self.il = self.meth_wrapper.get_il_generator() self.av_consts = MethodArgument(0, System.Type.GetType("System.Object[]")) t_InputArgs = dotnet.typeof(InputArgs) self.av_inputargs = MethodArgument(1, t_InputArgs) self.av_ovf_flag = BoxInt() self.exc_value_field = t_InputArgs.GetField('exc_value') if cpu.rtyper: self.av_OverflowError = ConstObj( ootype.cast_to_object(cpu.ll_ovf_exc)) self.av_ZeroDivisionError = ConstObj( ootype.cast_to_object(cpu.ll_zero_exc)) else: self.av_OverflowError = None self.av_ZeroDivisionError = None self.box2type = {}
def get_exception(self): exc_value = self.get_inputargs().get_exc_value() if exc_value: exc_obj = dotnet.cast_from_native_object(exc_value) exc_inst = ootype.cast_from_object(ootype.ROOT, exc_obj) cls = ootype.classof(exc_value) return ootype.cast_to_object(cls) return ootype.cast_to_object(ootype.nullruntimeclass)
def test_unwrap_object(self): A = ootype.Instance("A", ootype.ROOT, {}) a1 = ootype.new(A) a2 = ootype.new(A) obj1 = ootype.cast_to_object(a1) obj2 = ootype.cast_to_object(a2) def fn(flag): if flag: obj = obj1 else: obj = obj2 a3 = ootype.cast_from_object(A, obj) return a3 is a1 res = self.interpret(fn, [True], backendopt=False) assert res is True
def test_convert_string_to_object(self): s = self.string_to_ll("hello world") obj = ootype.cast_to_object(s) def fn(): s1 = ootype.cast_from_object(ootype.String, obj) return s1 res = self.interpret(fn, [], backendopt=False) assert res == 'hello world'
def fn(): a = ootype.new(A) ahash = ootype.identityhash(a) obj = ootype.cast_to_object(a) native = cast_to_native_object(obj) name = native.GetType().get_Name() obj2 = cast_from_native_object(native) a2 = ootype.cast_from_object(A, obj2) a2hash = ootype.identityhash(a2) return name, ahash == a2hash
def __init__(self, cpu, cliloop): self.setoptions() self.cpu = cpu self.name = cliloop.get_fresh_cli_name() self.cliloop = cliloop self.boxes = {} # box --> local var self.branches = [] self.branchlabels = [] self.consts = {} # object --> index self.meth_wrapper = self._get_meth_wrapper() self.il = self.meth_wrapper.get_il_generator() self.av_consts = MethodArgument(0, System.Type.GetType("System.Object[]")) t_InputArgs = dotnet.typeof(InputArgs) self.av_inputargs = MethodArgument(1, t_InputArgs) self.av_ovf_flag = BoxInt() self.exc_value_field = t_InputArgs.GetField("exc_value") if cpu.rtyper: self.av_OverflowError = ConstObj(ootype.cast_to_object(cpu.ll_ovf_exc)) self.av_ZeroDivisionError = ConstObj(ootype.cast_to_object(cpu.ll_zero_exc)) else: self.av_OverflowError = None self.av_ZeroDivisionError = None self.box2type = {}
def _cast_instance_to_native_obj(self, e): from rpython.rtyper.annlowlevel import cast_instance_to_base_obj inst = cast_instance_to_base_obj(e) # SomeOOInstance obj = ootype.cast_to_object(inst) # SomeOOObject return dotnet.cast_to_native_object(obj) # System.Object
def do_runtimenew(self, classbox): classobj = classbox.getref(ootype.Class) res = ootype.runtimenew(classobj) return BoxObj(ootype.cast_to_object(res))
def set_zero_division_error(self): exc_obj = ootype.cast_to_object(self.ll_zero_exc) exc_value = dotnet.cast_to_native_object(exc_obj) self.get_inputargs().set_exc_value(exc_value)
def set_overflow_error(self): exc_obj = ootype.cast_to_object(self.ll_ovf_exc) exc_value = dotnet.cast_to_native_object(exc_obj) self.get_inputargs().set_exc_value(exc_value)
def get_zero_division_error(self): exc_type = ootype.cast_to_object(ootype.classof(self.ll_zero_exc)) exc_value = ootype.cast_to_object(self.ll_zero_exc) return exc_type, exc_value
def get_overflow_error(self): exc_type = ootype.cast_to_object(ootype.classof(self.ll_ovf_exc)) exc_value = ootype.cast_to_object(self.ll_ovf_exc) return exc_type, exc_value
def typedescr2classbox(self, descr): assert isinstance(descr, TypeDescr) return ConstObj(ootype.cast_to_object(descr.ooclass))
def op_cast_to_object(inst): return ootype.cast_to_object(inst)