[pypy-svn] r60525 - in pypy/branch/oo-jit/pypy/jit/tl: . test
antocuni at codespeak.net
antocuni at codespeak.net
Tue Dec 16 21:06:43 CET 2008
Author: antocuni
Date: Tue Dec 16 21:06:40 2008
New Revision: 60525
Added:
pypy/branch/oo-jit/pypy/jit/tl/fibo.tlc (contents, props changed)
pypy/branch/oo-jit/pypy/jit/tl/fibo.tlc.src
Modified:
pypy/branch/oo-jit/pypy/jit/tl/test/test_tlc.py
Log:
add a tlc program that compute the nth fibonacci number
Added: pypy/branch/oo-jit/pypy/jit/tl/fibo.tlc
==============================================================================
Binary file. No diff available.
Added: pypy/branch/oo-jit/pypy/jit/tl/fibo.tlc.src
==============================================================================
--- (empty file)
+++ pypy/branch/oo-jit/pypy/jit/tl/fibo.tlc.src Tue Dec 16 21:06:40 2008
@@ -0,0 +1,26 @@
+main:
+ PUSH 0
+ PUSH 1
+ PUSHARG
+
+loop: # [a, b, n]
+ PUSH 1
+ SUB # [a, b, n-1]
+ PICK 0
+ BR_COND true
+ PUSH 1
+ BR_COND exit
+
+true: # [a, b, n]
+ SWAP
+ ROLL 3 # [n, b, a]
+ PICK 1 # [n, b, a, b]
+ ADD # [n, b, a+b]
+ ROLL 3 # [b, a+b, n]
+
+ PUSH 1
+ BR_COND loop
+
+exit: # [a, b, 0]
+ POP
+ RETURN
Modified: pypy/branch/oo-jit/pypy/jit/tl/test/test_tlc.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/tl/test/test_tlc.py (original)
+++ pypy/branch/oo-jit/pypy/jit/tl/test/test_tlc.py Tue Dec 16 21:06:40 2008
@@ -257,16 +257,20 @@
res = interp_eval(bytecode, 0, [nil], pool)
assert res.int_o() == 42
- def test_binarytree(self):
+ def compile(self, filename):
from pypy.jit.tl.tlc import interp_eval, IntObj
pool = ConstantPool()
- path = py.path.local(__file__).join('../../binarytree.tlc.src')
+ path = py.path.local(__file__).join(filename)
src = path.read()
bytecode = compile(src, pool)
- def search(n):
+ def fn(n):
obj = IntObj(n)
res = interp_eval(bytecode, 0, [obj], pool)
return res.int_o()
+ return fn
+
+ def test_binarytree(self):
+ search = self.compile('../../binarytree.tlc.src')
assert search(20)
assert search(10)
assert search(15)
@@ -275,3 +279,10 @@
assert not search(40)
assert not search(12)
assert not search(27)
+
+ def test_fibo(self):
+ fibo = self.compile('../../fibo.tlc.src')
+ assert fibo(1) == 1
+ assert fibo(2) == 1
+ assert fibo(3) == 2
+ assert fibo(7) == 13
More information about the Pypy-commit
mailing list