[pypy-svn] r14286 - pypy/dist/pypy/translator/llvm2

hpk at codespeak.net hpk at codespeak.net
Tue Jul 5 15:03:16 CEST 2005


Author: hpk
Date: Tue Jul  5 15:03:13 2005
New Revision: 14286

Modified:
   pypy/dist/pypy/translator/llvm2/arraynode.py
   pypy/dist/pypy/translator/llvm2/node.py
Log:
(hpk, rxe) 

slight refactoring of representing refs in llvm source


Modified: pypy/dist/pypy/translator/llvm2/arraynode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/arraynode.py	(original)
+++ pypy/dist/pypy/translator/llvm2/arraynode.py	Tue Jul  5 15:03:13 2005
@@ -6,10 +6,7 @@
 import itertools  
 log = log.structnode
 
-count = itertools.count().next 
-
-def wrapstr(s):
-    return '"%s"' % s
+nextnum = itertools.count().next 
 
 class ArrayTypeNode(LLVMNode):
     _issetup = False
@@ -17,11 +14,16 @@
         self.db = db
         assert isinstance(array, lltype.Array)
         self.array = array
-        c = count()
-        ref_template = wrapstr("%%array.%s." + str(c))
+        c = nextnum()
+        ref_template = "%%array.%s." + str(c)
 
+        # ref is used to reference the arraytype in llvm source 
         self.ref = ref_template % array.OF
-        self.constructor_ref = wrapstr("%%new.array.%s" % c)
+        # constructor_ref is used to reference the constructor 
+        # for the array type in llvm source code 
+        self.constructor_ref = "%%new.array.%s" % c 
+        # constructor_decl is used to declare the constructor
+        # for the array type (see writeimpl). 
         self.constructor_decl = "%s * %s(int %%len)" % \
                                 (self.ref, self.constructor_ref)
 
@@ -72,8 +74,7 @@
     def writedatatypedecl(self, codewriter):
         codewriter.arraydef(self.ref, self.db.repr_arg_type(self.array.OF))
 
-# Each ArrayNode is a global constant.  This needs to have a specific type of
-# a certain type.
+# Each ArrayNode instance is a global constant. 
 
 class ArrayNode(LLVMNode):
 
@@ -82,7 +83,8 @@
 
     def __init__(self, db, value):
         self.db = db
-        name = '"%%arrayinstance.%s.%s"' % (value._TYPE.OF, ArrayNode.array_counter)
+        name = '"%%arrayinstance.%s.%s"' % (
+                    value._TYPE.OF, ArrayNode.array_counter)
         self.ref = name
         self.value = value
         ArrayNode.array_counter += 1

Modified: pypy/dist/pypy/translator/llvm2/node.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/node.py	(original)
+++ pypy/dist/pypy/translator/llvm2/node.py	Tue Jul  5 15:03:13 2005
@@ -1,12 +1,30 @@
 class LLVMNode(object):
-    def _get_ref(self):
-        return self._ref
-    def _set_ref(self, ref):
-        if hasattr(self, "_ref"):
-            raise TypeError, ("can only set ref once! currently: %s" %
-                               (self._ref,))
-        self._ref = ref
-    ref = property(_get_ref, _set_ref)
+
+    def ref(): 
+        def _get_ref(self):
+            return self._ref 
+        def _set_ref(self, ref):
+            if hasattr(self, "_ref"):
+                raise TypeError, ("can only set ref once! currently: %s" %
+                                   (self._ref,))
+            if " " in ref: 
+                ref = '"%s"' % (ref,)
+            self._ref = ref
+        return property(_get_ref, _set_ref)
+    ref = ref()
+
+    def constructor_ref(): 
+        def _get_ref(self):
+            return self._constructor_ref 
+        def _set_ref(self, ref):
+            if hasattr(self, "_constructor_ref"):
+                raise TypeError, ("can only set constructor_ref once!"
+                                  " currently: %s" % (self._constructor_ref,))
+            if " " in ref: 
+                ref = '"%s"' % (ref,)
+            self._constructor_ref = ref
+        return property(_get_ref, _set_ref)
+    constructor_ref = constructor_ref()
 
     # __________________ before "implementation" ____________________
     def writedatatypedecl(self, codewriter):



More information about the Pypy-commit mailing list