[pypy-svn] r20549 - in pypy/branch/somepbc-refactoring/pypy: annotation rpython rpython/test
arigo at codespeak.net
arigo at codespeak.net
Thu Dec 1 23:41:53 CET 2005
Author: arigo
Date: Thu Dec 1 23:41:52 2005
New Revision: 20549
Modified:
pypy/branch/somepbc-refactoring/pypy/annotation/unaryop.py
pypy/branch/somepbc-refactoring/pypy/rpython/rfloat.py
pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rfloat.py
Log:
(tismer, replayed from r20152)
added support for float valued dict keys
Modified: pypy/branch/somepbc-refactoring/pypy/annotation/unaryop.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/annotation/unaryop.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/annotation/unaryop.py Thu Dec 1 23:41:52 2005
@@ -191,6 +191,9 @@
return getbookkeeper().immutablevalue(bool(self.const))
return SomeBool()
+ def hash(flt):
+ return SomeInteger()
+
class __extend__(SomeInteger):
def invert(self):
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/rfloat.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/rfloat.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/rfloat.py Thu Dec 1 23:41:52 2005
@@ -10,6 +10,7 @@
from pypy.rpython import rstr
from pypy.rpython.rmodel import log
+import math
class __extend__(annmodel.SomeFloat):
def rtyper_makerepr(self, rtyper):
@@ -105,7 +106,10 @@
return float(value)
def get_ll_eq_function(self):
- return None
+ return None
+
+ def get_ll_hash_function(self):
+ return ll_hash_float
def rtype_is_true(_, hop):
vlist = hop.inputargs(Float)
@@ -133,7 +137,27 @@
from pypy.rpython.module.ll_strtod import ll_strtod_formatd
return ll_strtod_formatd(percent_f, f)
+ def rtype_hash(_, hop):
+ v_flt, = hop.inputargs(float_repr)
+ return hop.gendirectcall(ll_hash_float, v_flt)
+
percent_f = string_repr.convert_const("%f")
+
+TAKE_NEXT = float(2**31)
+
+def ll_hash_float(f):
+ """
+ this implementation is identical to the CPython implementation,
+ despite the fact that the integer case is not treated, specially.
+ This should be special-cased in W_FloatObject.
+ In the low-level case, floats cannot be used with ints in dicts, anyway.
+ """
+ v, expo = math.frexp(f)
+ v *= TAKE_NEXT
+ hipart = int(v)
+ v = (v - float(hipart)) * TAKE_NEXT
+ x = hipart + int(v) + (expo << 15)
+ return x
#
# _________________________ Conversions _________________________
Modified: pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rfloat.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rfloat.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/test/test_rfloat.py Thu Dec 1 23:41:52 2005
@@ -49,3 +49,9 @@
res = interpret(fn, [1.5])
assert float(''.join(res.chars)) == 1.5
+
+def test_hash():
+ def fn(f):
+ return hash(f)
+ res = interpret(fn, [1.5])
+ assert res == hash(1.5)
More information about the Pypy-commit
mailing list