[pypy-svn] r25697 - in pypy/dist/pypy/translator/cli: . test

antocuni at codespeak.net antocuni at codespeak.net
Tue Apr 11 14:51:01 CEST 2006


Author: antocuni
Date: Tue Apr 11 14:50:52 2006
New Revision: 25697

Modified:
   pypy/dist/pypy/translator/cli/database.py
   pypy/dist/pypy/translator/cli/function.py
   pypy/dist/pypy/translator/cli/ilgenerator.py
   pypy/dist/pypy/translator/cli/metavm.py
   pypy/dist/pypy/translator/cli/opcodes.py
   pypy/dist/pypy/translator/cli/test/compile.py
Log:
Corrected some minor bugs that prevented test_oo to pass under Windows.


Modified: pypy/dist/pypy/translator/cli/database.py
==============================================================================
--- pypy/dist/pypy/translator/cli/database.py	(original)
+++ pypy/dist/pypy/translator/cli/database.py	Tue Apr 11 14:50:52 2006
@@ -79,9 +79,13 @@
 class AbstractConst(object):
     def make(db, const):
         if isinstance(const, ootype._view):
+            static_type = const._TYPE
             const = const._inst
+        else:
+            static_type = None
+
         if isinstance(const, ootype._instance):
-            return InstanceConst(db, const)
+            return InstanceConst(db, const, static_type)
         else:
             assert False, 'Unknown constant: %s' % const
     make = staticmethod(make)
@@ -96,9 +100,14 @@
         pass
 
 class InstanceConst(AbstractConst):
-    def __init__(self, db, obj):
+    def __init__(self, db, obj, static_type):
         self.cts = CTS(db)
         self.obj = obj
+        if static_type is None:
+            self.static_type = obj._TYPE
+        else:
+            self.static_type = static_type
+            self.cts.lltype_to_cts(obj._TYPE) # force scheduling of obj's class
 
     def __hash__(self):
         return hash(self.obj)
@@ -111,7 +120,7 @@
         return '%s_%d' % (name, n)
 
     def get_type(self):
-        return self.cts.lltype_to_cts(self.obj._TYPE)
+        return self.cts.lltype_to_cts(self.static_type)
 
     def init(self, ilasm):
         classdef = self.obj._TYPE        

Modified: pypy/dist/pypy/translator/cli/function.py
==============================================================================
--- pypy/dist/pypy/translator/cli/function.py	(original)
+++ pypy/dist/pypy/translator/cli/function.py	Tue Apr 11 14:50:52 2006
@@ -253,6 +253,15 @@
         self.db.pending_function(graph)
         self.ilasm.call(func_name)
 
+    def call_signature(self, signature):
+        self.ilasm.call(signature)
+
+    def cast_to(self, lltype):
+        cts_type = self.cts.lltype_to_cts(lltype)
+        if cts_type.startswith('class '):
+            cts_type = cts_type[len('class '):]
+        self.ilasm.opcode('castclass', cts_type)
+
     def new(self, obj):
         self.ilasm.new(self.cts.ctor_name(obj))
 

Modified: pypy/dist/pypy/translator/cli/ilgenerator.py
==============================================================================
--- pypy/dist/pypy/translator/cli/ilgenerator.py	(original)
+++ pypy/dist/pypy/translator/cli/ilgenerator.py	Tue Apr 11 14:50:52 2006
@@ -37,7 +37,7 @@
         self.out = outfile
         self.code = CodeGenerator(self.out)
         self.code.writeline('.assembly extern mscorlib {}')
-        self.code.writeline('.assembly extern pypy {}')
+        self.code.writeline('.assembly extern pypylib {}')
         self.code.writeline('.assembly %s {}' % name)
 
     def close(self):

Modified: pypy/dist/pypy/translator/cli/metavm.py
==============================================================================
--- pypy/dist/pypy/translator/cli/metavm.py	(original)
+++ pypy/dist/pypy/translator/cli/metavm.py	Tue Apr 11 14:50:52 2006
@@ -92,6 +92,12 @@
 
         generator.call_method(this.concretetype, method.value)
 
+class _RuntimeNew(MicroInstruction):
+    def render(self, generator, op):
+        generator.load(op.args[0])
+        generator.call_signature('object [pypylib]pypy.runtime.Utils::RuntimeNew(class [mscorlib]System.Type)')
+        generator.cast_to(op.result.concretetype)
+
 
 PushAllArgs = _PushAllArgs()
 StoreResult = _StoreResult()
@@ -100,3 +106,4 @@
 SetField = _SetField()
 GetField = _GetField()
 CallMethod = _CallMethod()
+RuntimeNew = _RuntimeNew()

Modified: pypy/dist/pypy/translator/cli/opcodes.py
==============================================================================
--- pypy/dist/pypy/translator/cli/opcodes.py	(original)
+++ pypy/dist/pypy/translator/cli/opcodes.py	Tue Apr 11 14:50:52 2006
@@ -1,5 +1,5 @@
-from pypy.translator.cli.metavm import PushArg, PushAllArgs,\
-     StoreResult, Call, InstructionList, New, SetField, GetField, CallMethod
+from pypy.translator.cli.metavm import PushArg, PushAllArgs, StoreResult, Call,\
+     InstructionList, New, SetField, GetField, CallMethod, RuntimeNew
 
 # some useful instruction patterns
 Not = ['ldc.i4.0', 'ceq']
@@ -11,12 +11,11 @@
 def _abs(type_):
     return [PushAllArgs, 'call %s class [mscorlib]System.Math::Abs(%s)' % (type_, type_)]
 
-_runtimenew = 'object [pypylib]pypy.runtime.Utils::RuntimeNew([mscorlib]System.Type)'
 
 opcodes = {
     # __________ object oriented operations __________
     'new':                      [New],
-    'runtimenew':               [PushAllArgs, 'call ' + _runtimenew],
+    'runtimenew':               [RuntimeNew],
     'oosetfield':               [SetField],
     'oogetfield':               [GetField],
     'oosend':                   [CallMethod],

Modified: pypy/dist/pypy/translator/cli/test/compile.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/compile.py	(original)
+++ pypy/dist/pypy/translator/cli/test/compile.py	Tue Apr 11 14:50:52 2006
@@ -23,13 +23,49 @@
     else:
         print 'OK'
 
-def foo(mylist, i):
-    return mylist[i]
+
+class MyClass:
+    INCREMENT = 1
+
+    def __init__(self, x, y):
+        self.x = x
+        self.y = y
+
+    def compute(self):
+        return self.x + self.y
+
+    def compute_and_multiply(self, factor):
+        return self.compute() * factor
+
+    def static_meth(x, y):
+        return x*y
+    static_meth = staticmethod(static_meth)
+
+##    def class_meth(cls, x, y):
+##        return x*y + cls.INCREMENT
+##    class_meth = classmethod(class_meth)
+
+    def class_attribute(self):
+        return self.x + self.INCREMENT
+
+class MyDerivedClass(MyClass):
+    INCREMENT = 2
+
+    def __init__(self, x, y):
+        MyClass.__init__(self, x+12, y+34)
+
+    def compute(self):
+        return self.x - self.y
+
+
+
+def init_and_compute(cls, x, y):
+    return cls(x, y).compute()
+
 
 def bar(x, y):
-    mylist = [1,2,3,x,y]
-    mylist[0] = 432
-    return foo(mylist, (x+y)%5)
+    return init_and_compute(MyClass, x, y) + init_and_compute(MyDerivedClass, x, y)
+
 
 f = compile_function(bar, [int, int])
 



More information about the Pypy-commit mailing list