[pypy-svn] r47988 - pypy/dist/pypy/lang/smalltalk
arigo at codespeak.net
arigo at codespeak.net
Thu Oct 25 21:19:57 CEST 2007
Author: arigo
Date: Thu Oct 25 21:19:57 2007
New Revision: 47988
Modified:
pypy/dist/pypy/lang/smalltalk/interpreter.py
pypy/dist/pypy/lang/smalltalk/model.py
pypy/dist/pypy/lang/smalltalk/primitives.py
Log:
(akuhn, arigo, cfbolz around)
Various bugs and type inconsistencies found by trying to translate.
Modified: pypy/dist/pypy/lang/smalltalk/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/interpreter.py (original)
+++ pypy/dist/pypy/lang/smalltalk/interpreter.py Thu Oct 25 21:19:57 2007
@@ -10,9 +10,6 @@
class IllegalStoreError(Exception):
"""Illegal Store."""
-class IllegalFetchError(Exception):
- """Illegal Fetch."""
-
class Interpreter:
TRUE = objtable.w_true
@@ -470,17 +467,18 @@
def initialize_bytecode_table():
result = [None] * 256
for entry in BYTECODE_RANGES:
- def dump_func(f):
- def wrapped(*args):
- print "Bytecode: %s" % (f.__name__)
- return f(*args)
- return wrapped
+ #def dump_func(f):
+ # def wrapped(*args):
+ # print "Bytecode: %s" % (f.__name__)
+ # return f(*args)
+ # return wrapped
if len(entry) == 2:
positions = [entry[0]]
else:
positions = range(entry[0], entry[1]+1)
for pos in positions:
- result[pos] = dump_func(entry[-1])
+ #result[pos] = dump_func(entry[-1])
+ result[pos] = entry[-1]
assert None not in result
return result
Modified: pypy/dist/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/model.py (original)
+++ pypy/dist/pypy/lang/smalltalk/model.py Thu Oct 25 21:19:57 2007
@@ -37,11 +37,14 @@
def __repr__(self):
return "W_SmallInteger(%d)" % self.value
-
+
+class UnwrappingError(Exception):
+ pass
+
def unwrap_int(w_value):
if isinstance(w_value, W_SmallInteger):
return w_value.value
- raise ClassShadowError("expected a W_SmallInteger, got %s" % (w_value,))
+ raise UnwrappingError("expected a W_SmallInteger, got %s" % (w_value,))
class W_Float(W_Object):
def __init__(self, value):
@@ -267,24 +270,24 @@
assert isinstance(w_home, W_MethodContext)
self.w_home = w_home
self.w_sender = w_sender
-
- def getclass(self):
- from pypy.lang.smalltalk.classtable import w_ContextPart
- return w_ContextPart
# ______________________________________________________________________
# Imitate the primitive accessors
def fetch(self, index):
- if index == CTXPART_SENDER_INDEX:
+ from pypy.lang.smalltalk import objtable
+ if index == constants.CTXPART_SENDER_INDEX:
return self.w_sender
- elif index == CTXPART_PC_INDEX:
+ elif index == constants.CTXPART_PC_INDEX:
return objtable.wrap_int(self.pc)
- elif index == CTXPART_STACKP_INDEX:
+ elif index == constants.CTXPART_STACKP_INDEX:
return objtable.wrap_int(len(self.stack))
# Invalid!
- raise IllegalFetchError
+ raise IndexError
+
+ def store(self, index, value):
+ raise NotImplementedError
# ______________________________________________________________________
# Method that contains the bytecode for this method/block context
@@ -352,30 +355,33 @@
return w_BlockContext
def fetch(self, index):
- if index == BLKCTX_BLOCK_ARGUMENT_COUNT_INDEX:
+ from pypy.lang.smalltalk import objtable
+ if index == constants.BLKCTX_BLOCK_ARGUMENT_COUNT_INDEX:
return objtable.wrap_int(self.argcnt)
- elif index == BLKCTX_INITIAL_IP_INDEX:
+ elif index == constants.BLKCTX_INITIAL_IP_INDEX:
return objtable.wrap_int(self.initialip)
- elif index == BLKCTX_HOME_INDEX:
+ elif index == constants.BLKCTX_HOME_INDEX:
return self.w_home
- elif index >= BLKCTX_TEMP_FRAME_START:
+ elif index >= constants.BLKCTX_TEMP_FRAME_START:
stack_index = len(self.stack) - index - 1
return self.stack[stack_index]
else:
return W_ContextPart.fetch(index)
def store(self, index, value):
- if index == BLKCTX_BLOCK_ARGUMENT_COUNT_INDEX:
- self.argcnt = unwrap_int(self.argcnt)
- elif index == BLKCTX_INITIAL_IP_INDEX:
- self.pc = unwrap_int(self.argcnt)
- elif index == BLKCTX_HOME_INDEX:
+ # THIS IS ALL UNTESTED CODE and we're a bit unhappy about it
+ # because it crashd the translation N times :-(
+ if index == constants.BLKCTX_BLOCK_ARGUMENT_COUNT_INDEX:
+ self.argcnt = unwrap_int(value)
+ elif index == constants.BLKCTX_INITIAL_IP_INDEX:
+ self.pc = unwrap_int(value)
+ elif index == constants.BLKCTX_HOME_INDEX:
self.w_home = value
- elif index >= BLKCTX_TEMP_FRAME_START:
+ elif index >= constants.BLKCTX_TEMP_FRAME_START:
stack_index = len(self.stack) - index - 1
self.stack[stack_index] = value
else:
- return W_ContextPart.fetch(index)
+ W_ContextPart.store(index, value)
class W_MethodContext(W_ContextPart):
def __init__(self, w_method, w_receiver, arguments, w_sender = None):
@@ -389,15 +395,16 @@
return w_MethodContext
def fetch(self, index):
- if index == MTHDCTX_METHOD:
+ from pypy.lang.smalltalk import objtable
+ if index == constants.MTHDCTX_METHOD:
return self.w_method()
- elif index == MTHDCTX_RECEIVER_MAP: # what is this thing?
+ elif index == constants.MTHDCTX_RECEIVER_MAP: # what is this thing?
return objtable.w_nil
- elif index == MTHDCTX_RECEIVER:
+ elif index == constants.MTHDCTX_RECEIVER:
return self.w_receiver
- elif index >= MTHDCTX_TEMP_FRAME_START:
+ elif index >= constants.MTHDCTX_TEMP_FRAME_START:
# First set of indices are temporary variables:
- offset = index - MTHDCTX_TEMP_FRAME_START
+ offset = index - constants.MTHDCTX_TEMP_FRAME_START
if offset < len(self.temps):
return self.temps[offset]
Modified: pypy/dist/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/primitives.py (original)
+++ pypy/dist/pypy/lang/smalltalk/primitives.py Thu Oct 25 21:19:57 2007
@@ -100,9 +100,6 @@
ADD: operator.add,
SUBTRACT: operator.sub,
MULTIPLY: operator.mul,
- BIT_AND: operator.and_,
- BIT_OR: operator.or_,
- BIT_XOR: operator.xor
}
for (code,op) in math_ops.items():
def make_func(op):
@@ -118,6 +115,22 @@
return wrap_int(res)
make_func(op)
+bitwise_binary_ops = {
+ BIT_AND: operator.and_,
+ BIT_OR: operator.or_,
+ BIT_XOR: operator.xor,
+ }
+for (code,op) in bitwise_binary_ops.items():
+ def make_func(op):
+ @primitive(code)
+ @stack(2)
+ def func(args, (w_receiver, w_argument)):
+ receiver = unwrap_int(w_receiver)
+ argument = unwrap_int(w_argument)
+ res = op(receiver, argument)
+ return wrap_int(res)
+ make_func(op)
+
# #/ -- return the result of a division, only succeed if the division is exact
@primitive(DIVIDE)
@stack(2)
@@ -453,7 +466,10 @@
@primitive(EQUIVALENT)
@stack(2)
def func(args, (w_arg, w_rcvr)):
- return w_arg == w_rcvr
+ # XXX this is bogus in the presence of (our implementation of) become,
+ # as we might plan to implement become by copying all fields from one
+ # object to the other
+ return objtable.wrap_bool(w_arg is w_rcvr)
@primitive(EQUIVALENT)
@stack(1)
@@ -506,7 +522,7 @@
INC_GC = 131
def fake_bytes_left():
- return 2**20 # XXX we don't know how to do this :-(
+ return wrap_int(2**20) # XXX we don't know how to do this :-(
@primitive(INC_GC) # XXX the same for now
@primitive(FULL_GC)
@@ -593,10 +609,12 @@
(PUSH_ONE, objtable.w_one),
(PUSH_TWO, objtable.w_two),
]:
- @primitive(code)
- @stack(1)
- def func(args, stack, const=const): # n.b.: capture const
- return const
+ def make_func(const):
+ @primitive(code)
+ @stack(1)
+ def func(args, stack):
+ return const
+ make_func(const)
define_const_primitives()
# ___________________________________________________________________________
More information about the Pypy-commit
mailing list