[pypy-svn] r14804 - in pypy/dist/pypy/rpython: . test
ac at codespeak.net
ac at codespeak.net
Wed Jul 20 12:07:03 CEST 2005
Author: ac
Date: Wed Jul 20 12:07:03 2005
New Revision: 14804
Modified:
pypy/dist/pypy/rpython/rint.py
pypy/dist/pypy/rpython/test/test_rint.py
Log:
Implement builtin oct.
Modified: pypy/dist/pypy/rpython/rint.py
==============================================================================
--- pypy/dist/pypy/rpython/rint.py (original)
+++ pypy/dist/pypy/rpython/rint.py Wed Jul 20 12:07:03 2005
@@ -313,6 +313,11 @@
true = inputconst(Bool, True)
return hop.gendirectcall(ll_int2hex, varg, true)
+ def rtype_oct(_, hop):
+ varg = hop.inputarg(hop.args_r[0], 0)
+ true = inputconst(Bool, True)
+ return hop.gendirectcall(ll_int2oct, varg, true)
+
CHAR_ARRAY = GcArray(Char)
@@ -355,6 +360,38 @@
j += 1
return result
+def ll_int2oct(i, addPrefix):
+ from pypy.rpython.rstr import STR
+ if i == 0:
+ result = malloc(STR, 1)
+ result.chars[0] = '0'
+ return result
+ temp = malloc(CHAR_ARRAY, 25)
+ len = 0
+ sign = 0
+ if i < 0:
+ sign = 1
+ i = -i
+ while i:
+ temp[len] = hex_chars[i%8]
+ i //= 8
+ len += 1
+ len += sign
+ if addPrefix:
+ len += 1
+ result = malloc(STR, len)
+ j = 0
+ if sign:
+ result.chars[0] = '-'
+ j = 1
+ if addPrefix:
+ result.chars[j] = '0'
+ j += 1
+ while j < len:
+ result.chars[j] = temp[len-j-1]
+ j += 1
+ return result
+
#
# _________________________ Conversions _________________________
Modified: pypy/dist/pypy/rpython/test/test_rint.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rint.py (original)
+++ pypy/dist/pypy/rpython/test/test_rint.py Wed Jul 20 12:07:03 2005
@@ -75,7 +75,20 @@
res = interpret(dummy, [-123])
assert ''.join(res.chars) == '-0x7b'
+
+def test_oct_of_int():
+ def dummy(i):
+ return oct(i)
+ res = interpret(dummy, [0])
+ assert ''.join(res.chars) == '0'
+
+ res = interpret(dummy, [1034])
+ assert ''.join(res.chars) == '02012'
+
+ res = interpret(dummy, [-123])
+ assert ''.join(res.chars) == '-0173'
+
def test_unsigned():
def dummy(i):
i = r_uint(i)
More information about the Pypy-commit
mailing list