Int conversion to long in py2.x

Updated to current master
    Droped HyInt/HyLong commit
This commit is contained in:
Guillermo Vaya 2013-08-21 01:09:03 +02:00
parent 312d4816ce
commit f61d702788
5 changed files with 17 additions and 8 deletions

View File

@ -37,7 +37,7 @@ from hy.models.list import HyList
from hy.models.dict import HyDict
from hy.macros import require, macroexpand
from hy._compat import str_type
from hy._compat import str_type, long_type
import hy.importer
import traceback
@ -1753,7 +1753,7 @@ class HyASTCompiler(object):
@builds(HyInteger)
def compile_integer(self, number):
return ast.Num(n=int(number),
return ast.Num(n=long_type(number),
lineno=number.start_line,
col_offset=number.start_column)

View File

@ -26,10 +26,10 @@ from hy.models.integer import HyInteger
from hy.models.float import HyFloat
from hy.models.complex import HyComplex
from hy.models.dict import HyDict
from hy._compat import str_type
from hy._compat import str_type, long_type
from collections import defaultdict
import sys
CORE_MACROS = [
"hy.core.bootstrap",
@ -87,6 +87,9 @@ _wrappers = {
list: lambda l: HyList(_wrap_value(x) for x in l)
}
if sys.version_info[0] < 3: # do not add long on python3
_wrappers[long_type] = HyInteger
def _wrap_value(x):
"""Wrap `x` into the corresponding Hy type.

View File

@ -19,14 +19,16 @@
# DEALINGS IN THE SOFTWARE.
from hy.models import HyObject
from hy._compat import long_type
class HyInteger(HyObject, int):
class HyInteger(HyObject, long_type):
"""
Internal represntation of a Hy Integer. May raise a ValueError as if
int(foo) was caled, given HyInteger(foo).
int(foo) was called, given HyInteger(foo). On python 2.x long will
be used instead
"""
def __new__(cls, number, *args, **kwargs):
number = int(number)
number = long_type(number)
return super(HyInteger, cls).__new__(cls, number)

View File

@ -163,7 +163,7 @@
(assert-false (instance? Foo2 foo))
(assert-true (instance? Foo foo3))
(assert-true (instance? float 1.0))
(assert-true (instance? int 3))
(assert-true (instance? int (int 3)))
(assert-true (instance? str (str "hello"))))
(defn test-integer? []

View File

@ -132,3 +132,7 @@
(let [[x 1]]
(^= x 1)
(assert (= x 0))))
(defn overflow-int-to-long []
"NATIVE: test if int does not raise an overflow exception"
(assert (integer? (+ 1 1000000000000000000000000))))