[pypy-svn] r12839 - in pypy/dist/pypy: annotation rpython

ericvrp at codespeak.net ericvrp at codespeak.net
Fri May 27 16:15:48 CEST 2005


Author: ericvrp
Date: Fri May 27 16:15:48 2005
New Revision: 12839

Modified:
   pypy/dist/pypy/annotation/model.py
   pypy/dist/pypy/rpython/lltype.py
   pypy/dist/pypy/rpython/rfloat.py
Log:
Added (Some)Float and started implementing rfloat.py


Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py	(original)
+++ pypy/dist/pypy/annotation/model.py	Fri May 27 16:15:48 2005
@@ -327,6 +327,7 @@
     (SomeBool(), lltype.Bool),
     (SomeInteger(), lltype.Signed),
     (SomeInteger(nonneg=True, unsigned=True), lltype.Unsigned),    
+    (SomeFloat(), lltype.Float),
     (SomeChar(), lltype.Char),
     (SomePBC({None: True}), lltype.Void),
 ]

Modified: pypy/dist/pypy/rpython/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltype.py	Fri May 27 16:15:48 2005
@@ -185,6 +185,7 @@
 
 Signed   = Primitive("Signed", 0)
 Unsigned = Primitive("Unsigned", r_uint(0))
+Float    = Primitive("Float", 0.0)
 Char     = Primitive("Char", '\x00')
 Bool     = Primitive("Bool", False)
 Void     = Primitive("Void", None)
@@ -246,6 +247,8 @@
         return Unsigned
     if isinstance(val, int):
         return Signed
+    if isinstance(val, float):
+        return Float
     if isinstance(val, str):
         assert len(val) == 1
         return Char

Modified: pypy/dist/pypy/rpython/rfloat.py
==============================================================================
--- pypy/dist/pypy/rpython/rfloat.py	(original)
+++ pypy/dist/pypy/rpython/rfloat.py	Fri May 27 16:15:48 2005
@@ -1,17 +1,69 @@
 from pypy.annotation.pairtype import pair, pairtype
-from pypy.annotation.model import SomeFloat, SomeInteger, SomeBool
-from pypy.rpython.lltype import Signed, Unsigned, Bool
+from pypy.annotation.model import SomeFloat, SomeInteger, SomeBool, SomePBC
+from pypy.rpython.lltype import Signed, Unsigned, Bool, Float
 from pypy.rpython.rtyper import peek_at_result_annotation, receive, direct_op
 from pypy.rpython.rtyper import TyperError
 
 
 class __extend__(pairtype(SomeFloat, SomeFloat)):
-    pass
 
+    def rtype_add(args):
+        return _rtype_template(args, 'add')
+
+    rtype_inplace_add = rtype_add
+
+    def rtype_sub(args):
+        return _rtype_template(args, 'sub')
+
+    rtype_inplace_sub = rtype_sub
+
+    def rtype_mul(args):
+        return _rtype_template(args, 'mul')
+
+    rtype_inplace_mul = rtype_mul
+
+    def rtype_div(args):
+        return _rtype_template(args, 'div')
+
+    rtype_inplace_div = rtype_div
+
+    def rtype_pow((s_float1, s_float2), s_float3=SomePBC({None: True})):
+        if isinstance(s_float3, SomeInteger):
+            v_float3_list = [receive(Float, arg=2)]
+        elif s_float3.is_constant() and s_float3.const is None:
+            v_float3_list = []
+        else:
+            raise TyperError("pow() 3rd argument must be int or None")
+        v_float1 = receive(Float, arg=0)
+        v_float2 = receive(Float, arg=1)
+        return direct_op('float_pow', [v_float1, v_float2] + v_float3_list, resulttype=Float)
+
+    rtype_inplace_pow = rtype_pow
+
+
+#Helpers SomeFloat,Somefloat
+
+def _rtype_template((s_float1, s_float2), func):
+        v_float1 = receive(Float, arg=0)
+        v_float2 = receive(Float, arg=1)
+        return direct_op('float_'+func, [v_float1, v_float2], resulttype=Float)
+
+
+#
 
 class __extend__(pairtype(SomeFloat, SomeInteger)):
     pass
 
 
 class __extend__(SomeFloat):
-    pass
+
+    def rtype_is_true(s_float):
+        v_float = receive(Float, arg=0)
+        return direct_op('float_is_true', [v_float], resulttype=Bool)
+
+    def rtype_neg(s_int):
+        v_int = receive(Float, arg=0)
+        return direct_op('float_neg', [v_int], resulttype=Float)
+
+    def rtype_pos(s_int):
+        return receive(Float, arg=0)



More information about the Pypy-commit mailing list