[pypy-svn] r33941 - in pypy/dist/pypy/translator/cli: . test
antocuni at codespeak.net
antocuni at codespeak.net
Tue Oct 31 12:00:50 CET 2006
Author: antocuni
Date: Tue Oct 31 12:00:49 2006
New Revision: 33941
Modified:
pypy/dist/pypy/translator/cli/database.py
pypy/dist/pypy/translator/cli/dotnet.py
pypy/dist/pypy/translator/cli/metavm.py
pypy/dist/pypy/translator/cli/test/test_dotnet.py
Log:
Use None instead of dotnet.Null for representing the "null" value when
calling native methods. This has the advantage that it works out of
the box with pythonnet.
Modified: pypy/dist/pypy/translator/cli/database.py
==============================================================================
--- pypy/dist/pypy/translator/cli/database.py (original)
+++ pypy/dist/pypy/translator/cli/database.py Tue Oct 31 12:00:49 2006
@@ -239,7 +239,7 @@
PRIMITIVE_TYPES = set([ootype.Void, ootype.Bool, ootype.Char, ootype.UniChar,
ootype.Float, ootype.Signed, ootype.Unsigned, ootype.String,
- lltype.SignedLongLong, lltype.UnsignedLongLong, dotnet.NullType])
+ lltype.SignedLongLong, lltype.UnsignedLongLong])
def is_primitive(cls, TYPE):
return TYPE in cls.PRIMITIVE_TYPES
@@ -270,9 +270,6 @@
ilasm.opcode('ldnull')
else:
ilasm.opcode("ldstr", string_literal(value._str))
- elif TYPE is dotnet.NullType:
- assert value is dotnet.Null
- ilasm.opcode('ldnull')
else:
assert TYPE not in cls.PRIMITIVE_TYPES
const = db.record_const(value)
Modified: pypy/dist/pypy/translator/cli/dotnet.py
==============================================================================
--- pypy/dist/pypy/translator/cli/dotnet.py (original)
+++ pypy/dist/pypy/translator/cli/dotnet.py Tue Oct 31 12:00:49 2006
@@ -103,8 +103,8 @@
class OverloadingResolver(ootype.OverloadingResolver):
def _can_convert_from_to(self, ARG1, ARG2):
- if ARG1 is NullType and isinstance(ARG2, NativeInstance):
- return True # Null is always convertible to a NativeInstance
+ if ARG1 is ootype.Void and isinstance(ARG2, NativeInstance):
+ return True # ARG1 could be None, that is always convertible to a NativeInstance
else:
return ootype.OverloadingResolver._can_convert_from_to(self, ARG1, ARG2)
@@ -166,25 +166,9 @@
self._classname = name
ootype.Instance.__init__(self, fullname, superclass, fields, methods, _is_root, _hints)
-class NullType(ootype.OOType):
- pass
-NullType = NullType()
-
## RPython interface definition
-class NullValue:
- _TYPE = NullType
-Null = NullValue()
-del NullValue
-
-class Entry(ExtRegistryEntry):
- _about_ = Null
-
- def compute_annotation(self):
- return SomeOOInstance(ootype=NullType)
-
-
class CliClass(object):
def __init__(self, INSTANCE, static_methods):
self._name = INSTANCE._name
Modified: pypy/dist/pypy/translator/cli/metavm.py
==============================================================================
--- pypy/dist/pypy/translator/cli/metavm.py (original)
+++ pypy/dist/pypy/translator/cli/metavm.py Tue Oct 31 12:00:49 2006
@@ -4,7 +4,7 @@
PushAllArgs, StoreResult, GetField, SetField, DownCast
from pypy.translator.cli.comparer import EqualityComparer
from pypy.translator.cli.cts import WEAKREF
-from pypy.translator.cli.dotnet import _static_meth
+from pypy.translator.cli.dotnet import _static_meth, NativeInstance
STRING_HELPER_CLASS = '[pypylib]pypy.runtime.String'
@@ -21,9 +21,18 @@
else:
self._render_method(generator, method_name, op.args[1:])
+ def _load_arg_or_null(self, generator, arg):
+ if arg.concretetype is ootype.Void:
+ if arg.value is None:
+ generator.ilasm.opcode('ldnull') # special-case: use None as a null value
+ else:
+ assert False, "Don't know how to load this arg"
+ else:
+ generator.load(arg)
+
def _render_native_function(self, generator, funcdesc, args):
for func_arg in args[1:]: # push parameters
- generator.load(func_arg)
+ self._load_arg_or_null(generator, func_arg)
cts = generator.cts
ret_type = cts.lltype_to_cts(funcdesc._TYPE.RESULT)
arg_types = [cts.lltype_to_cts(arg) for arg in funcdesc._TYPE.ARGS if arg is not ootype.Void]
@@ -45,8 +54,12 @@
def _render_method(self, generator, method_name, args):
this = args[0]
+ native = isinstance(this.concretetype, NativeInstance)
for arg in args: # push parametes
- generator.load(arg)
+ if native:
+ self._load_arg_or_null(generator, arg)
+ else:
+ generator.load(arg)
# XXX: very hackish, need refactoring
if this.concretetype is ootype.String:
Modified: pypy/dist/pypy/translator/cli/test/test_dotnet.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_dotnet.py (original)
+++ pypy/dist/pypy/translator/cli/test/test_dotnet.py Tue Oct 31 12:00:49 2006
@@ -6,7 +6,7 @@
ROOT, overload, Instance, new
from pypy.translator.cli.test.runtest import CliTest
from pypy.translator.cli.dotnet import SomeCliClass, SomeCliStaticMethod,\
- NativeInstance, CLR, box, unbox, OverloadingResolver, Null, NullType
+ NativeInstance, CLR, box, unbox, OverloadingResolver
System = CLR.System
Math = CLR.System.Math
@@ -112,13 +112,6 @@
assert isinstance(s, annmodel.SomeOOInstance)
assert s.ootype._name == '[mscorlib]System.Object'
- def test_Null(self):
- def fn():
- return Null
- a = RPythonAnnotator()
- s = a.build_types(fn, [])
- assert s.ootype is NullType
-
class TestDotnetRtyping(CliTest):
def _skip_pythonnet(self, msg):
pass
@@ -194,22 +187,16 @@
return unbox(array[0], ootype.Signed)
assert self.interpret(fn, []) == 42
- def test_Null(self):
- self._skip_pythonnet("Null support not yet completed'")
+ def test_null(self):
def fn():
- return System.Object.Equals(Null, Null)
+ return System.Object.Equals(None, None)
assert self.interpret(fn, []) == True
- def test_Null_bound_method(self):
- self._skip_pythonnet("Null support not yet completed'")
+ def test_null_bound_method(self):
def fn():
x = ArrayList()
- x.Add(Null)
+ x.Add(None)
return x.get_Item(0)
- # a bit of explanation for the result: after IL has been
- # generated there is no distinction between dotnet.Null and
- # None, because both are rendered as the CLI 'null' value. So
- # interpret returns 'None', as it has always done.
assert self.interpret(fn, []) is None
class TestPythonnet(TestDotnetRtyping):
@@ -222,4 +209,3 @@
def test_whitout_box(self):
pass # it makes sense only during translation
-
More information about the Pypy-commit
mailing list