Skip to content
Permalink
Browse files

fix some other methods

  • Loading branch information
alex committed Jun 27, 2013
1 parent 797d363 commit 81c420575cca57b8a624777e217e677e49ec0a46
Showing with 21 additions and 12 deletions.
  1. +5 −1 topaz/objects/arrayobject.py
  2. +16 −11 topaz/objects/intobject.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):
@@ -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):

0 comments on commit 81c4205

Please sign in to comment.
You can’t perform that action at this time.