[pypy-svn] r32585 - pypy/dist/pypy/jit/tl

arigo at codespeak.net arigo at codespeak.net
Fri Sep 22 18:23:03 CEST 2006


Author: arigo
Date: Fri Sep 22 18:23:02 2006
New Revision: 32585

Modified:
   pypy/dist/pypy/jit/tl/tlc.py
Log:
Express a loop as a recursion again, which is necessary for now to avoid merging.


Modified: pypy/dist/pypy/jit/tl/tlc.py
==============================================================================
--- pypy/dist/pypy/jit/tl/tlc.py	(original)
+++ pypy/dist/pypy/jit/tl/tlc.py	Fri Sep 22 18:23:02 2006
@@ -49,10 +49,9 @@
 
     def div(self, n):
         n = n.int_o()
-        cur = self
-        for i in range(n):
-            cur = cur.cdr()
-        return cur.car()
+        if n < 0:
+            raise IndexError
+        return self._nth(n)
 
     def add(self, other):
         if not isinstance(other, LispObj):
@@ -67,12 +66,12 @@
     def eq(self, other):
         return self is other
 
-    def car(self): raise IndexError
-    def cdr(self): raise IndexError    
-
     def _concat(self, other):
         return other
 
+    def _nth(self, n):
+        raise IndexError
+
 nil = NilObj()
 
 class ConsObj(LispObj):
@@ -96,6 +95,12 @@
     def _concat(self, other):
         return ConsObj(self._car, self._cdr._concat(other))
 
+    def _nth(self, n):
+        if n == 0:
+            return self._car
+        else:
+            return self._cdr._nth(n-1)
+
 def char2int(c):
     t = ord(c)
     if t & 128:



More information about the Pypy-commit mailing list