[pypy-svn] r13577 - in pypy/dist/pypy: rpython translator/c/test

pedronis at codespeak.net pedronis at codespeak.net
Sat Jun 18 03:58:54 CEST 2005


Author: pedronis
Date: Sat Jun 18 03:58:51 2005
New Revision: 13577

Modified:
   pypy/dist/pypy/rpython/rbuiltin.py
   pypy/dist/pypy/translator/c/test/test_genc.py
Log:
time.clock support in rtyper, by now piggy-backing on CPython one



Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/rbuiltin.py	Sat Jun 18 03:58:51 2005
@@ -7,6 +7,8 @@
 from pypy.rpython.rrange import rtype_builtin_range
 from pypy.rpython.rmodel import Repr, TyperError
 from pypy.rpython import rptr
+from pypy.rpython.robject import pyobj_repr
+from pypy.rpython.rfloat import float_repr
 
 
 class __extend__(annmodel.SomeBuiltin):
@@ -142,3 +144,15 @@
 BUILTIN_TYPER[lltype.getRuntimeTypeInfo] = rtype_const_result
 BUILTIN_TYPER[lltype.runtime_type_info] = rtype_runtime_type_info
 BUILTIN_TYPER[rarithmetic.intmask] = rtype_intmask
+
+import time
+
+def rtype_time_clock(hop):
+    c = hop.inputconst(pyobj_repr, time.clock)
+    v = hop.genop('simple_call', [c], resulttype = pyobj_repr)
+    return hop.llops.convertvar(v, pyobj_repr, float_repr)
+
+BUILTIN_TYPER[time.clock] = rtype_time_clock
+    
+
+

Modified: pypy/dist/pypy/translator/c/test/test_genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_genc.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_genc.py	Sat Jun 18 03:58:51 2005
@@ -182,3 +182,27 @@
     f1()
     mallocs, frees = module.malloc_counters()
     assert mallocs == frees
+
+def test_time_clock():
+    import time
+    def does_stuff():
+        return time.clock()
+    t = Translator(does_stuff)
+    t.annotate([])
+    t.specialize()
+    #t.view()
+
+    db = LowLevelDatabase(t)
+    entrypoint = db.get(pyobjectptr(does_stuff))
+    db.complete()
+
+    module = compile_db(db)
+
+    f1 = getattr(module, entrypoint)
+    t0 = time.clock()
+    t1 = f1()
+    assert type(t1) is float
+    t2 = time.clock()
+    assert t0 <= t1 <= t2
+    mallocs, frees = module.malloc_counters()
+    assert mallocs == frees



More information about the Pypy-commit mailing list