Author: Armin Rigo <[email protected]>
Branch: ffistruct
Changeset: r49022:9699c8a780e1
Date: 2011-11-09 17:03 +0100
http://bitbucket.org/pypy/pypy/changeset/9699c8a780e1/
Log: Make rarithmetic.longlongmask() translatable.
diff --git a/pypy/annotation/builtin.py b/pypy/annotation/builtin.py
--- a/pypy/annotation/builtin.py
+++ b/pypy/annotation/builtin.py
@@ -294,6 +294,9 @@
def rarith_intmask(s_obj):
return SomeInteger()
+def rarith_longlongmask(s_obj):
+ return SomeInteger(knowntype=pypy.rlib.rarithmetic.r_longlong)
+
def robjmodel_instantiate(s_clspbc):
assert isinstance(s_clspbc, SomePBC)
clsdef = None
@@ -372,6 +375,7 @@
BUILTIN_ANALYZERS[original] = value
BUILTIN_ANALYZERS[pypy.rlib.rarithmetic.intmask] = rarith_intmask
+BUILTIN_ANALYZERS[pypy.rlib.rarithmetic.longlongmask] = rarith_longlongmask
BUILTIN_ANALYZERS[pypy.rlib.objectmodel.instantiate] = robjmodel_instantiate
BUILTIN_ANALYZERS[pypy.rlib.objectmodel.r_dict] = robjmodel_r_dict
BUILTIN_ANALYZERS[pypy.rlib.objectmodel.hlinvoke] = robjmodel_hlinvoke
diff --git a/pypy/rpython/rbuiltin.py b/pypy/rpython/rbuiltin.py
--- a/pypy/rpython/rbuiltin.py
+++ b/pypy/rpython/rbuiltin.py
@@ -239,6 +239,11 @@
vlist = hop.inputargs(lltype.Signed)
return vlist[0]
+def rtype_longlongmask(hop):
+ hop.exception_cannot_occur()
+ vlist = hop.inputargs(lltype.SignedLongLong)
+ return vlist[0]
+
def rtype_builtin_min(hop):
v1, v2 = hop.inputargs(hop.r_result, hop.r_result)
return hop.gendirectcall(ll_min, v1, v2)
@@ -549,6 +554,7 @@
BUILTIN_TYPER[lltype.Ptr] = rtype_const_result
BUILTIN_TYPER[lltype.runtime_type_info] = rtype_runtime_type_info
BUILTIN_TYPER[rarithmetic.intmask] = rtype_intmask
+BUILTIN_TYPER[rarithmetic.longlongmask] = rtype_longlongmask
BUILTIN_TYPER[objectmodel.hlinvoke] = rtype_hlinvoke
diff --git a/pypy/rpython/test/test_rbuiltin.py
b/pypy/rpython/test/test_rbuiltin.py
--- a/pypy/rpython/test/test_rbuiltin.py
+++ b/pypy/rpython/test/test_rbuiltin.py
@@ -5,7 +5,7 @@
from pypy.rlib.debug import llinterpcall
from pypy.rpython.lltypesystem import lltype
from pypy.tool import udir
-from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.rarithmetic import intmask, longlongmask, r_int64
from pypy.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong
from pypy.annotation.builtin import *
from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
@@ -79,6 +79,16 @@
res = self.interpret(f, [r_uint(5)])
assert type(res) is int and res == 5
+ def test_longlongmask(self):
+ def f(x=r_ulonglong):
+ try:
+ return longlongmask(x)
+ except ValueError:
+ return 0
+
+ res = self.interpret(f, [r_ulonglong(5)])
+ assert type(res) is r_int64 and res == 5
+
def test_rbuiltin_list(self):
def f():
l=list((1,2,3))
diff --git a/pypy/translator/c/test/test_typed.py
b/pypy/translator/c/test/test_typed.py
--- a/pypy/translator/c/test/test_typed.py
+++ b/pypy/translator/c/test/test_typed.py
@@ -877,3 +877,13 @@
assert res == 'acquire, hello, raised, release'
res = f(2)
assert res == 'acquire, hello, raised, release'
+
+ def test_longlongmask(self):
+ from pypy.rlib.rarithmetic import longlongmask, r_ulonglong
+ def func(n):
+ m = r_ulonglong(n)
+ m *= 100000
+ return longlongmask(m)
+ f = self.getcompiled(func, [int])
+ res = f(-2000000000)
+ assert res == -200000000000000
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit