[pypy-svn] r18283 - in pypy/dist/pypy/translator/c: . test

pedronis at codespeak.net pedronis at codespeak.net
Sat Oct 8 15:56:16 CEST 2005


Author: pedronis
Date: Sat Oct  8 15:56:13 2005
New Revision: 18283

Modified:
   pypy/dist/pypy/translator/c/database.py
   pypy/dist/pypy/translator/c/genc.py
   pypy/dist/pypy/translator/c/node.py
   pypy/dist/pypy/translator/c/test/test_genc.py
Log:
store HUGE_VAL at runtime in global constants, it maybe an external



Modified: pypy/dist/pypy/translator/c/database.py
==============================================================================
--- pypy/dist/pypy/translator/c/database.py	(original)
+++ pypy/dist/pypy/translator/c/database.py	Sat Oct  8 15:56:13 2005
@@ -24,6 +24,7 @@
         self.completedcontainers = 0
         self.containerstats = {}
         self.externalfuncs = {}
+        self.infs = []
         self.namespace = CNameManager()
         if not standalone:
             self.pyobjmaker = PyObjMaker(self.namespace, self.get, translator)

Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py	(original)
+++ pypy/dist/pypy/translator/c/genc.py	Sat Oct  8 15:56:13 2005
@@ -294,6 +294,11 @@
     for line in database.gcpolicy.gc_startup_code():
         print >> f,"\t" + line
 
+    # put float infinities in global constants, we should not have so many of them for now to make
+    # a table+loop preferable
+    for dest, value in database.infs:
+        print >> f, "\t%s = %s;" % (dest, value)
+
     firsttime = True
     for node in database.containerlist:
         lines = list(node.startupcode())

Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py	(original)
+++ pypy/dist/pypy/translator/c/node.py	Sat Oct  8 15:56:13 2005
@@ -1,13 +1,13 @@
 from __future__ import generators
 from pypy.rpython.lltype import Struct, Array, FuncType, PyObjectType, typeOf
 from pypy.rpython.lltype import GcStruct, GcArray, GC_CONTAINER, ContainerType
-from pypy.rpython.lltype import parentlink, Ptr, PyObject, Void, OpaqueType
+from pypy.rpython.lltype import parentlink, Ptr, PyObject, Void, OpaqueType, Float
 from pypy.rpython.lltype import RuntimeTypeInfo, getRuntimeTypeInfo, Char
 from pypy.translator.c.funcgen import FunctionCodeGenerator
 from pypy.translator.c.external import CExternalFunctionCodeGenerator
 from pypy.translator.c.support import USESLOTS # set to False if necessary while refactoring
 from pypy.translator.c.support import cdecl, somelettersfrom, c_string_constant
-from pypy.translator.c.primitive import PrimitiveType
+from pypy.translator.c.primitive import PrimitiveType, isinf
 from pypy.translator.c import extfunc
 from pypy.rpython.rstr import STR
 
@@ -414,6 +414,9 @@
             node = db.getcontainernode(value._obj)
             expr = 'NULL /*%s*/' % node.name
             node.where_to_copy_me.append('&%s' % access_expr)
+        elif typeOf(value) == Float and isinf(value):
+            db.infs.append(('%s' % access_expr, db.get(value)))
+            expr = '0.0'
         else:
             expr = db.get(value)
             if typeOf(value) is Void:

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 Oct  8 15:56:13 2005
@@ -221,18 +221,25 @@
         def __init__(self, d):
             self.d = d
     b1 = Box(x)
-    b2 = Box(0.0)
+    b2 = Box(-x)
+    b3 = Box(1.5)
 
     def f(i):
-        if i:
+        if i==0:
             b = b1
-        else:
+        elif i==1:
             b = b2
+        else:
+            b = b3
         return b.d
 
     f1 = compile(f, [int])
-    res = f1(1)
+    res = f1(0)
     assert res > 0 and res == res / 2
+    res = f1(1)
+    assert res < 0 and res == res / 2
+    res = f1(3)
+    assert res == 1.5
 
 def test_x():
     class A:



More information about the Pypy-commit mailing list