Author: Tobias Pape <tob...@netshed.de> Branch: Changeset: r19:4da7f6a039b9 Date: 2012-04-19 13:37 +0200 http://bitbucket.org/pypy/lang-smalltalk/changeset/4da7f6a039b9/
Log: Re-import a FixedStack implementation - fix deprecated overflowcheck w/ shift - fix r_uints missing diff --git a/spyvm/fixedstack.py b/spyvm/fixedstack.py new file mode 100644 --- /dev/null +++ b/spyvm/fixedstack.py @@ -0,0 +1,65 @@ +""" +A Fixed stack for SPy. +""" + +import types + +from pypy.rlib.rarithmetic import r_uint + +class FixedStack(object): + _annspecialcase_ = "specialize:ctr_location" # polymorphic + + def __init__(self): + pass + + def setup(self, stacksize): + self.ptr = r_uint(0) # we point after the last element + self.items = [None] * stacksize + + def clone(self): + # this is only needed if we support flow space + s = self.__class__() + s.setup(len(self.items)) + for item in self.items[:self.ptr]: + try: + item = item.clone() + except AttributeError: + pass + s.push(item) + return s + + def push(self, item): + ptr = self.ptr + self.items[ptr] = item + self.ptr = ptr + 1 + + def pop(self): + ptr = self.ptr - 1 + ret = self.items[ptr] # you get OverflowError if the stack is empty + self.items[ptr] = None + self.ptr = ptr + return ret + + def drop(self, n): + while n > 0: + n -= 1 + self.ptr -= 1 + self.items[self.ptr] = None + + def top(self, position=0): + # for a fixed stack, we assume correct indices + rpos = r_uint(position) + return self.items[self.ptr + ~rpos] + + def set_top(self, value, position=0): + # for a fixed stack, we assume correct indices + rpos = r_uint(position) + self.items[self.ptr + ~rpos] = value + + def depth(self): + return self.ptr + + def empty(self): + return not self.ptr + + diff --git a/spyvm/model.py b/spyvm/model.py --- a/spyvm/model.py +++ b/spyvm/model.py @@ -424,7 +424,7 @@ return self.words[n] def setword(self, n, word): - self.words[n] = word + self.words[n] = r_uint(word) def size(self): return len(self.words) diff --git a/spyvm/objspace.py b/spyvm/objspace.py --- a/spyvm/objspace.py +++ b/spyvm/objspace.py @@ -217,7 +217,7 @@ val = w_value.value if val < 0: raise UnwrappingError("got negative integer") - return w_value.value + return r_uint(w_value.value) if isinstance(w_value, model.W_BytesObject): # TODO: Completely untested! This failed translation bigtime... # XXX Probably we want to allow all subclasses diff --git a/spyvm/primitives.py b/spyvm/primitives.py --- a/spyvm/primitives.py +++ b/spyvm/primitives.py @@ -202,7 +202,7 @@ # left shift, must fail if we lose bits beyond 32 if argument > 0: try: - shifted = rarithmetic.ovfcheck_lshift(receiver, argument) + shifted = rarithmetic.ovfcheck(receiver << argument) except OverflowError: raise PrimitiveFailedError() return interp.space.wrap_int(shifted) diff --git a/spyvm/shadow.py b/spyvm/shadow.py --- a/spyvm/shadow.py +++ b/spyvm/shadow.py @@ -315,7 +315,7 @@ __metaclass__ = extendabletype def __init__(self, space, w_self): - from pypy.interpreter.miscutils import FixedStack + from spyvm.fixedstack import FixedStack self._w_sender = space.w_nil self._stack = FixedStack() _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit