Ejemplo n.º 1
0
 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 = {}
Ejemplo n.º 2
0
Archivo: runner.py Proyecto: sota/pypy
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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'
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
0
Archivo: method.py Proyecto: sota/pypy
 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 = {}
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
 def do_runtimenew(self, classbox):
     classobj = classbox.getref(ootype.Class)
     res = ootype.runtimenew(classobj)
     return BoxObj(ootype.cast_to_object(res))
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
0
 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)
Ejemplo n.º 13
0
 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
Ejemplo n.º 14
0
 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
Ejemplo n.º 15
0
Archivo: runner.py Proyecto: sota/pypy
 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)
Ejemplo n.º 16
0
Archivo: runner.py Proyecto: sota/pypy
 def typedescr2classbox(self, descr):
     assert isinstance(descr, TypeDescr)
     return ConstObj(ootype.cast_to_object(descr.ooclass))
Ejemplo n.º 17
0
Archivo: runner.py Proyecto: sota/pypy
 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
Ejemplo n.º 18
0
Archivo: runner.py Proyecto: sota/pypy
 def do_runtimenew(self, classbox):
     classobj = classbox.getref(ootype.Class)
     res = ootype.runtimenew(classobj)
     return BoxObj(ootype.cast_to_object(res))
Ejemplo n.º 19
0
Archivo: runner.py Proyecto: sota/pypy
 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)
Ejemplo n.º 20
0
def op_cast_to_object(inst):
    return ootype.cast_to_object(inst)
Ejemplo n.º 21
0
Archivo: runner.py Proyecto: sota/pypy
 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
Ejemplo n.º 22
0
Archivo: runner.py Proyecto: sota/pypy
 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
Ejemplo n.º 23
0
 def typedescr2classbox(self, descr):
     assert isinstance(descr, TypeDescr)
     return ConstObj(ootype.cast_to_object(descr.ooclass))
Ejemplo n.º 24
0
def op_cast_to_object(inst):
    return ootype.cast_to_object(inst)