[pypy-svn] r54788 - in pypy/branch/oo-jit/pypy: rpython/ootypesystem translator/cli translator/cli/test
antocuni at codespeak.net
antocuni at codespeak.net
Fri May 16 13:29:16 CEST 2008
Author: antocuni
Date: Fri May 16 13:29:13 2008
New Revision: 54788
Modified:
pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py
pypy/branch/oo-jit/pypy/translator/cli/dotnet.py
pypy/branch/oo-jit/pypy/translator/cli/opcodes.py
pypy/branch/oo-jit/pypy/translator/cli/test/test_dotnet.py
Log:
add a way to convert from ootype.Object to System.Object and back;
unfortunately, it works only when translated, because during
interpretation ootype objects are not generally .NET objects
Modified: pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py Fri May 16 13:29:13 2008
@@ -989,8 +989,8 @@
def __init__(self, INSTANCE, inst):
self.__dict__['_TYPE'] = INSTANCE
- assert isinstance(inst, (_instance, _record))
- assert isinstance(inst._TYPE, Record) or isSubclass(inst._TYPE, INSTANCE)
+ assert isinstance(inst, _instance)
+ assert isSubclass(inst._TYPE, INSTANCE)
self.__dict__['_inst'] = inst
def __repr__(self):
Modified: pypy/branch/oo-jit/pypy/translator/cli/dotnet.py
==============================================================================
--- pypy/branch/oo-jit/pypy/translator/cli/dotnet.py (original)
+++ pypy/branch/oo-jit/pypy/translator/cli/dotnet.py Fri May 16 13:29:13 2008
@@ -648,6 +648,40 @@
return hop.genop('oodowncast', [v_inst], resulttype = hop.r_result.lowleveltype)
+def cast_to_native_object(obj):
+ raise TypeError, "cast_to_native_object is meant to be rtyped and not called direclty"
+
+def cast_from_native_object(obj):
+ raise TypeError, "cast_from_native_object is meant to be rtyped and not called direclty"
+
+class Entry(ExtRegistryEntry):
+ _about_ = cast_to_native_object
+
+ def compute_result_annotation(self, s_value):
+ assert isinstance(s_value, annmodel.SomeOOObject)
+ assert s_value.ootype is ootype.Object
+ return SomeOOInstance(CLR.System.Object._INSTANCE)
+
+ def specialize_call(self, hop):
+ assert isinstance(hop.args_s[0], annmodel.SomeOOObject)
+ v_obj, = hop.inputargs(*hop.args_r)
+ hop.exception_cannot_occur()
+ return hop.genop('ooupcast', [v_obj], hop.r_result.lowleveltype)
+
+class Entry(ExtRegistryEntry):
+ _about_ = cast_from_native_object
+
+ def compute_result_annotation(self, s_value):
+ assert isinstance(s_value, annmodel.SomeOOInstance)
+ assert s_value.ootype is CLR.System.Object._INSTANCE
+ return annmodel.SomeOOObject()
+
+ def specialize_call(self, hop):
+ v_obj = hop.inputarg(hop.args_r[0], arg=0)
+ return hop.genop('oodowncast', [v_obj], hop.r_result.lowleveltype)
+
+
+
from pypy.translator.cli.query import CliNamespace
CLR = CliNamespace(None)
CLR._buildtree()
Modified: pypy/branch/oo-jit/pypy/translator/cli/opcodes.py
==============================================================================
--- pypy/branch/oo-jit/pypy/translator/cli/opcodes.py (original)
+++ pypy/branch/oo-jit/pypy/translator/cli/opcodes.py Fri May 16 13:29:13 2008
@@ -1,8 +1,7 @@
from pypy.translator.cli.metavm import Call, CallMethod, \
IndirectCall, GetField, SetField, DownCast, NewCustomDict,\
MapException, Box, Unbox, NewArray, GetArrayElem, SetArrayElem,\
- TypeOf, CastPrimitive, EventHandler, GetStaticField, SetStaticField,\
- FieldInfoForConst
+ TypeOf, CastPrimitive, EventHandler, GetStaticField, SetStaticField
from pypy.translator.oosupport.metavm import PushArg, PushAllArgs, StoreResult, InstructionList,\
New, RuntimeNew, CastTo, PushPrimitive, OOString, OOUnicode, OONewArray
from pypy.translator.cli.cts import WEAKREF
Modified: pypy/branch/oo-jit/pypy/translator/cli/test/test_dotnet.py
==============================================================================
--- pypy/branch/oo-jit/pypy/translator/cli/test/test_dotnet.py (original)
+++ pypy/branch/oo-jit/pypy/translator/cli/test/test_dotnet.py Fri May 16 13:29:13 2008
@@ -8,7 +8,7 @@
from pypy.translator.cli.dotnet import SomeCliClass, SomeCliStaticMethod,\
NativeInstance, CLR, box, unbox, OverloadingResolver, NativeException,\
native_exc, new_array, init_array, typeof, eventhandler, clidowncast,\
- classof
+ classof, cast_to_native_object, cast_from_native_object
System = CLR.System
ArrayList = CLR.System.Collections.ArrayList
@@ -613,7 +613,21 @@
return clidowncast(box(x), System.Type).get_Name()
res = self.interpret(fn, [True])
assert res == 'Int32'
-
+
+ def test_cast_native_object(self):
+ A = ootype.Instance("A", ootype.ROOT, {})
+ def fn():
+ a = ootype.new(A)
+ ahash = ootype.ooidentityhash(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.ooidentityhash(a2)
+ return name, ahash == a2hash
+ res = self.ll_to_tuple(self.interpret(fn, []))
+ assert res == ('A', True)
class TestPythonnet(TestDotnetRtyping):
# don't interpreter functions but execute them directly through pythonnet
@@ -642,3 +656,6 @@
return t.get_Name()
res = self.interpret(fn, [])
assert res == 'DelegateType_int__int_2'
+
+ def test_cast_native_object(self):
+ pass # it works only when translated
More information about the Pypy-commit
mailing list