Skip to content

Commit

Permalink
fix some other methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Jun 27, 2013
1 parent 797d363 commit 81c4205
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
6 changes: 5 additions & 1 deletion topaz/objects/arrayobject.py
Expand Up @@ -2,6 +2,7 @@


from rpython.rlib import jit from rpython.rlib import jit
from rpython.rlib.listsort import make_timsort_class from rpython.rlib.listsort import make_timsort_class
from rpython.rlib.rbigint import rbigint


from topaz.coerce import Coerce from topaz.coerce import Coerce
from topaz.module import ClassDef, check_frozen from topaz.module import ClassDef, check_frozen
Expand All @@ -22,7 +23,10 @@ def __init__(self, space, list, listlength=None, sortblock=None):


def lt(self, w_a, w_b): def lt(self, w_a, w_b):
w_cmp_res = self.space.compare(w_a, w_b, self.sortblock) 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): class RubySortBy(BaseRubySortBy):
Expand Down
27 changes: 16 additions & 11 deletions topaz/objects/intobject.py
Expand Up @@ -249,17 +249,22 @@ def method_right_shift(self, space, other):
else: else:
return space.newint(self.intvalue >> other) return space.newint(self.intvalue >> other)


@classdef.method("&", other="int") def new_bitwise_op(classdef, name, func):
def method_and(self, space, other): @classdef.method(name)
return space.newint(self.intvalue & other) def method(self, space, w_other):

w_other = space.convert_type(w_other, space.w_integer, "to_int")
@classdef.method("^", other="int") if space.is_kind_of(w_other, space.w_fixnum):
def method_xor(self, space, other): other = space.int_w(w_other)
return space.newint(self.intvalue ^ other) return space.newint(func(self.intvalue, other))

elif space.is_kind_of(w_other, space.w_bignum):
@classdef.method("|", other="int") return space.send(space.newbigint_fromint(self.intvalue), name, [w_other])
def method_or(self, space, other): else:
return space.newint(self.intvalue | other) 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("~") @classdef.method("~")
def method_invert(self, space): def method_invert(self, space):
Expand Down

0 comments on commit 81c4205

Please sign in to comment.