[pypy-svn] rev 1675 - in pypy/trunk/src/pypy/translator: . test
mwh at codespeak.net
mwh at codespeak.net
Fri Oct 10 17:51:35 CEST 2003
Author: mwh
Date: Fri Oct 10 17:51:34 2003
New Revision: 1675
Added:
pypy/trunk/src/pypy/translator/test/buildclisp.py (contents, props changed)
pypy/trunk/src/pypy/translator/test/test_cltrans.py (contents, props changed)
Modified:
pypy/trunk/src/pypy/translator/gencl.py
Log:
tests and improvements from sanxiyn, while he has svn auth problems.
the test is currently disabled because it fails when clisp isn't
installed. this should be shallow to change into a skip in that case.
Modified: pypy/trunk/src/pypy/translator/gencl.py
==============================================================================
--- pypy/trunk/src/pypy/translator/gencl.py (original)
+++ pypy/trunk/src/pypy/translator/gencl.py Fri Oct 10 17:51:34 2003
@@ -67,45 +67,14 @@
print "(setq", var, init, ")"
self.emit_block(branch.target)
def emit_conditional_branch(self, branch):
- # XXX: Fix this
- print "(if (not (zerop", self.str(branch.condition), "))"
+ print "(if"
+ self.emit_truth_test(branch.condition)
self.emit_branch(branch.ifbranch)
self.emit_branch(branch.elsebranch)
print ")"
def emit_end_branch(self, branch):
retval = self.str(branch.returnvalue)
print "(return", retval, ")"
-
-def my_gcd(a, b):
- r = a % b
- while r:
- a = b
- b = r
- r = a % b
- return b
-
-import sys
-from pypy.objspace.flow import Space
-from vpath.adapter.process import exec_cmd
-from cStringIO import StringIO
-
-def test(func, *args):
- fun = Space().build_flow(func)
- gen = GenCL(fun)
- out = StringIO()
- sys.stdout = out
- gen.emit()
- sys.stdout = sys.__stdout__
- fp = file("test.lisp", "w")
- fp.write(out.getvalue())
- print >>fp, "(write (", fun.functionname,
- for arg in args:
- print >>fp, str(arg),
- print >>fp, "))"
- fp.close()
- output = exec_cmd("clisp test.lisp")
- print "Python:", func(*args)
- print "Lisp:", output
-
-if __name__ == "__main__":
- test(my_gcd, 96, 64)
+ def emit_truth_test(self, obj):
+ # XXX: Fix this
+ print "(not (zerop", self.str(obj), "))"
Added: pypy/trunk/src/pypy/translator/test/buildclisp.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/translator/test/buildclisp.py Fri Oct 10 17:51:34 2003
@@ -0,0 +1,36 @@
+import autopath
+
+import sys
+from cStringIO import StringIO
+from pypy.objspace.flow import Space
+from pypy.translator.gencl import GenCL
+from vpath.adapter.process import exec_cmd
+
+def readlisp(s):
+ # For now, let's return int only
+ return int(s)
+
+def make_cl_func(func, path):
+ fun = Space().build_flow(func)
+ gen = GenCL(fun)
+ out = StringIO()
+ sys.stdout = out
+ gen.emit()
+ sys.stdout = sys.__stdout__
+ fp = path.join("test.lisp")
+ i = 0
+ while fp.exists():
+ fp = path.join("test%d.lisp" % i)
+ i += 1
+ fp.write(out.getvalue())
+ fname = fp.path
+ def _(*args):
+ fp = file(fname, "a")
+ print >>fp, "(write (", fun.functionname,
+ for arg in args:
+ print >>fp, str(arg),
+ print >>fp, "))"
+ fp.close()
+ output = exec_cmd("clisp %s" % fname)
+ return readlisp(output)
+ return _
Added: pypy/trunk/src/pypy/translator/test/test_cltrans.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/translator/test/test_cltrans.py Fri Oct 10 17:51:34 2003
@@ -0,0 +1,24 @@
+import autopath
+from pypy.tool import test
+from pypy.tool.udir import udir
+from pypy.translator.test.buildclisp import make_cl_func
+
+class GenCLTestCase(test.IntTestCase):
+
+ #___________________________________
+ def my_gcd(a, b):
+ r = a % b
+ while r:
+ a = b
+ b = r
+ r = a % b
+ return b
+ def XXXtest_gcd(self):
+ # disabled because it's rude to fail just because the clisp
+ # common lisp implementation isn't installed.
+ # (will arrange to skip the test in that case eventually) -- mwh
+ cl_gcd = make_cl_func(self.my_gcd, udir)
+ self.assertEquals(cl_gcd(96, 64), 32)
+
+if __name__ == '__main__':
+ test.main()
More information about the Pypy-commit
mailing list