From 81c420575cca57b8a624777e217e677e49ec0a46 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 27 Jun 2013 07:51:07 -0700 Subject: [PATCH] fix some other methods --- topaz/objects/arrayobject.py | 6 +++++- topaz/objects/intobject.py | 27 ++++++++++++++++----------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/topaz/objects/arrayobject.py b/topaz/objects/arrayobject.py index 56124a38a..4a0997157 100644 --- a/topaz/objects/arrayobject.py +++ b/topaz/objects/arrayobject.py @@ -2,6 +2,7 @@ from rpython.rlib import jit from rpython.rlib.listsort import make_timsort_class +from rpython.rlib.rbigint import rbigint from topaz.coerce import Coerce from topaz.module import ClassDef, check_frozen @@ -22,7 +23,10 @@ def __init__(self, space, list, listlength=None, sortblock=None): def lt(self, w_a, w_b): w_cmp_res = self.space.compare(w_a, w_b, self.sortblock) - return self.space.int_w(w_cmp_res) < 0 + if self.space.is_kind_of(w_cmp_res, self.space.w_bignum): + return self.space.bigint_w(w_cmp_res).lt(rbigint.fromint(0)) + else: + return self.space.int_w(w_cmp_res) < 0 class RubySortBy(BaseRubySortBy): diff --git a/topaz/objects/intobject.py b/topaz/objects/intobject.py index 412b7a41a..d985060a8 100644 --- a/topaz/objects/intobject.py +++ b/topaz/objects/intobject.py @@ -249,17 +249,22 @@ def method_right_shift(self, space, other): else: return space.newint(self.intvalue >> other) - @classdef.method("&", other="int") - def method_and(self, space, other): - return space.newint(self.intvalue & other) - - @classdef.method("^", other="int") - def method_xor(self, space, other): - return space.newint(self.intvalue ^ other) - - @classdef.method("|", other="int") - def method_or(self, space, other): - return space.newint(self.intvalue | other) + def new_bitwise_op(classdef, name, func): + @classdef.method(name) + def method(self, space, w_other): + w_other = space.convert_type(w_other, space.w_integer, "to_int") + if space.is_kind_of(w_other, space.w_fixnum): + other = space.int_w(w_other) + return space.newint(func(self.intvalue, other)) + elif space.is_kind_of(w_other, space.w_bignum): + return space.send(space.newbigint_fromint(self.intvalue), name, [w_other]) + else: + return W_NumericObject.retry_binop_coercing(space, self, w_other, name) + method.__name__ = "method_%s" % func.__name__ + return method + method_and = new_bitwise_op(classdef, "&", operator.and_) + method_or = new_bitwise_op(classdef, "|", operator.or_) + method_xor = new_bitwise_op(classdef, "^", operator.xor) @classdef.method("~") def method_invert(self, space):