[pypy-svn] r33553 - pypy/dist/pypy/translator/cli

antocuni at codespeak.net antocuni at codespeak.net
Mon Oct 23 13:48:18 CEST 2006


Author: antocuni
Date: Mon Oct 23 13:48:17 2006
New Revision: 33553

Modified:
   pypy/dist/pypy/translator/cli/dotnet.py
   pypy/dist/pypy/translator/cli/support.py
Log:
Explicitly declare System.Object as a NativeInstance with its own
methods instead of patchig ootype.ROOT. Thanks pedronis for the idea.



Modified: pypy/dist/pypy/translator/cli/dotnet.py
==============================================================================
--- pypy/dist/pypy/translator/cli/dotnet.py	(original)
+++ pypy/dist/pypy/translator/cli/dotnet.py	Mon Oct 23 13:48:17 2006
@@ -151,7 +151,12 @@
         ootype.Instance.__init__(self, fullname, superclass, fields, methods, _is_root, _hints)
 
 
-STRING_BUILDER = NativeInstance('[mscorlib]', 'System.Text', 'StringBuilder', ootype.ROOT, {}, {})
+OBJECT = NativeInstance('[mscorlib]', 'System', 'Object', ootype.ROOT, {},
+                        {'ToString': ootype.meth(ootype.Meth([], ootype.String)),
+                         })
+Object = CliClass(OBJECT, {})
+
+STRING_BUILDER = NativeInstance('[mscorlib]', 'System.Text', 'StringBuilder', OBJECT, {}, {})
 STRING_BUILDER._add_methods({'Append': meth(Meth([ootype.String], STRING_BUILDER)),
                              'AppendLine': overload(meth(Meth([ootype.String], STRING_BUILDER)),
                                                     meth(Meth([], STRING_BUILDER)))
@@ -162,7 +167,7 @@
 ##Console = CliClass(CONSOLE, {'WriteLine': {(ootype.String,): ootype.Void,
 ##                                           (ootype.Signed,): ootype.Void}})
 
-MATH = NativeInstance('[mscorlib]', 'System', 'Math', ootype.ROOT, {}, {})
+MATH = NativeInstance('[mscorlib]', 'System', 'Math', OBJECT, {}, {})
 Math = CliClass(MATH,
                 {'Abs': _overloaded_static_meth(_static_meth(StaticMethod([ootype.Signed], ootype.Signed)),
                                                 _static_meth(StaticMethod([ootype.Float], ootype.Float)))
@@ -170,7 +175,7 @@
 
 
 
-ARRAY_LIST = NativeInstance('[mscorlib]', 'System.Collections', 'ArrayList', ootype.ROOT, {},
-                            {'Add': meth(Meth([ootype.ROOT], ootype.Signed)),
+ARRAY_LIST = NativeInstance('[mscorlib]', 'System.Collections', 'ArrayList', OBJECT, {},
+                            {'Add': meth(Meth([OBJECT], ootype.Signed)),
                              'get_Count': meth(Meth([], ootype.Signed))})
 ArrayList = CliClass(ARRAY_LIST, {})

Modified: pypy/dist/pypy/translator/cli/support.py
==============================================================================
--- pypy/dist/pypy/translator/cli/support.py	(original)
+++ pypy/dist/pypy/translator/cli/support.py	Mon Oct 23 13:48:17 2006
@@ -80,23 +80,9 @@
         setattr(os, name, value)
     return olddefs
 
-def _patch_ROOT():
-    """
-    In gencli ootype.ROOT corresponds to System.Object: make the
-    annotator aware of its native methods such as ToString().
-    """
-    oldmeths = ootype.ROOT._methods.copy()
-    ootype.ROOT._add_methods({'ToString': ootype.meth(ootype.Meth([], ootype.String))})
-    return oldmeths
-
-def _unpatch_ROOT(oldmeths):
-    ootype.ROOT._methods = oldmeths
-
 def patch():
     olddefs = _patch_os()
-    oldmeths = _patch_ROOT()
-    return olddefs, oldmeths
+    return olddefs,
 
-def unpatch(olddefs, oldmeths):
+def unpatch(olddefs):
     _patch_os(olddefs)
-    _unpatch_ROOT(oldmeths)



More information about the Pypy-commit mailing list