[pypy-svn] r62376 - in pypy/branch/spy-graphic/pypy/lang/smalltalk: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Mar 2 14:32:16 CET 2009
Author: cfbolz
Date: Mon Mar 2 14:32:15 2009
New Revision: 62376
Modified:
pypy/branch/spy-graphic/pypy/lang/smalltalk/interpreter.py
pypy/branch/spy-graphic/pypy/lang/smalltalk/model.py
pypy/branch/spy-graphic/pypy/lang/smalltalk/primitives.py
pypy/branch/spy-graphic/pypy/lang/smalltalk/test/test_primitives.py
Log:
Implement a couple of primitives that the mini image is trying to run. Some of
the implementations are stubs so far, fix this later.
Modified: pypy/branch/spy-graphic/pypy/lang/smalltalk/interpreter.py
==============================================================================
--- pypy/branch/spy-graphic/pypy/lang/smalltalk/interpreter.py (original)
+++ pypy/branch/spy-graphic/pypy/lang/smalltalk/interpreter.py Mon Mar 2 14:32:15 2009
@@ -19,11 +19,12 @@
class Interpreter(object):
_w_last_active_context = None
+ cnt = 0
- def __init__(self, space):
+ def __init__(self, space, image_name=""):
self._w_active_context = None
self.space = space
- self.cnt = 0
+ self.image_name = image_name
def w_active_context(self):
return self._w_active_context
Modified: pypy/branch/spy-graphic/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/branch/spy-graphic/pypy/lang/smalltalk/model.py (original)
+++ pypy/branch/spy-graphic/pypy/lang/smalltalk/model.py Mon Mar 2 14:32:15 2009
@@ -99,6 +99,9 @@
False means swapping failed"""
return False
+ def clone(self):
+ raise NotImplementedError
+
class W_SmallInteger(W_Object):
"""Boxed integer value"""
# TODO can we tell pypy that its never larger then 31-bit?
@@ -136,6 +139,8 @@
def __hash__(self):
return self.value
+ def clone(self):
+ return self
class W_Float(W_Object):
"""Boxed float value."""
@@ -172,6 +177,9 @@
def __hash__(self):
return hash(self.value)
+ def clone(self):
+ return self
+
class W_AbstractObjectWithIdentityHash(W_Object):
"""Object with explicit hash (ie all except small
ints and floats)."""
@@ -344,6 +352,10 @@
W_AbstractObjectWithClassReference._become(self, w_other)
return True
+ def clone(self):
+ w_result = W_PointersObject(self.w_class, len(self._vars))
+ w_result._vars[:] = self._vars
+ return w_result
class W_BytesObject(W_AbstractObjectWithClassReference):
def __init__(self, w_class, size):
@@ -389,6 +401,11 @@
return False
return self.bytes == other.bytes
+ def clone(self):
+ w_result = W_BytesObject(self.w_class, len(self.bytes))
+ w_result.bytes[:] = self.bytes
+ return w_result
+
class W_WordsObject(W_AbstractObjectWithClassReference):
def __init__(self, w_class, size):
W_AbstractObjectWithClassReference.__init__(self, w_class)
@@ -415,6 +432,11 @@
return (W_AbstractObjectWithClassReference.invariant(self) and
isinstance(self.words, list))
+ def clone(self):
+ w_result = W_WordsObject(self.w_class, len(self.words))
+ w_result.words[:] = self.words
+ return w_result
+
# XXX Shouldn't compiledmethod have class reference for subclassed compiled
# methods?
class W_CompiledMethod(W_AbstractObjectWithIdentityHash):
Modified: pypy/branch/spy-graphic/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/branch/spy-graphic/pypy/lang/smalltalk/primitives.py (original)
+++ pypy/branch/spy-graphic/pypy/lang/smalltalk/primitives.py Mon Mar 2 14:32:15 2009
@@ -490,6 +490,14 @@
interp.space.objtable['w_display'] = w_rcvr
return w_rcvr
+ at expose_primitive(SCREEN_SIZE, unwrap_spec=[object])
+def func(interp, w_rcvr):
+ # XXX get the real screen size
+ w_res = interp.space.w_Point.as_class_get_shadow(interp.space).new(2)
+ point = wrapper.PointWrapper(interp.space, w_res)
+ point.store_x(640)
+ point.store_y(480)
+ return w_res
# ___________________________________________________________________________
# Control Primitives
@@ -549,10 +557,32 @@
w_rcvr.w_class = w_arg.w_class
# ___________________________________________________________________________
+# Miscellaneous Primitives (120-127)
+CALLOUT_TO_FFI = 120
+IMAGE_NAME = 121
+NOOP = 122
+VALUE_UNINTERRUPTABLY = 123
+LOW_SPACE_SEMAPHORE = 124
+SIGNAL_AT_BYTES_LEFT = 125
+
+ at expose_primitive(IMAGE_NAME)
+def func(interp, argument_count):
+ if argument_count == 0:
+ interp.s_active_context().pop()
+ return interp.space.wrap_string(interp.image_name)
+ elif argument_count == 1:
+ pass # XXX
+ raise PrimitiveFailedError
+
+
+
+
+# ___________________________________________________________________________
# Squeak Miscellaneous Primitives (128-149)
BECOME = 128
FULL_GC = 130
INC_GC = 131
+CLONE = 148
@expose_primitive(BECOME, unwrap_spec=[object, object])
def func(interp, w_rcvr, w_new):
@@ -582,6 +612,10 @@
rgc.collect()
return fake_bytes_left(interp)
+ at expose_primitive(CLONE, unwrap_spec=[object])
+def func(interp, w_arg):
+ return w_arg.clone()
+
#____________________________________________________________________________
# Time Primitives
MILLISECOND_CLOCK = 135
@@ -604,6 +638,32 @@
return interp.space.wrap_uint(sec_since_1901)
# ___________________________________________________________________________
+# File primitives (150-169)
+# (XXX they are obsolete in Squeak and done with a plugin)
+
+FILE_AT_END = 150
+FILE_CLOSE = 151
+FILE_GET_POSITION = 152
+FILE_OPEN = 153
+FILE_READ = 154
+FILE_SET_POSITION = 155
+FILE_DELETE = 156
+FILE_SIZE = 157
+FILE_WRITE = 158
+FILE_RENAME = 159
+DIRECTORY_CREATE = 160
+DIRECTORY_DELIMITOR = 161
+DIRECTORY_LOOKUP = 162
+DIRECTORY_DELTE = 163
+
+
+ at expose_primitive(DIRECTORY_DELIMITOR, unwrap_spec=[object])
+def func(interp, _):
+ import os.path
+ return interp.space.wrap_char(os.path.sep)
+
+
+# ___________________________________________________________________________
# Boolean Primitives
LESSTHAN = 3
Modified: pypy/branch/spy-graphic/pypy/lang/smalltalk/test/test_primitives.py
==============================================================================
--- pypy/branch/spy-graphic/pypy/lang/smalltalk/test/test_primitives.py (original)
+++ pypy/branch/spy-graphic/pypy/lang/smalltalk/test/test_primitives.py Mon Mar 2 14:32:15 2009
@@ -419,6 +419,24 @@
assert w_method.literalat0(space, 1).is_same_object(space.w_nil)
assert w_method.bytes == "\x00" * len(bytecode)
+def test_image_name():
+ w_v = prim(primitives.IMAGE_NAME, [2])
+ assert w_v.bytes == []
+
+def test_clone():
+ w_obj = mockclass(space, 1, varsized=True).as_class_get_shadow(space).new(1)
+ w_obj.atput0(space, 0, space.wrap_int(1))
+ w_v = prim(primitives.CLONE, [w_obj])
+ assert space.unwrap_int(w_v.at0(space, 0)) == 1
+ w_obj.atput0(space, 0, space.wrap_int(2))
+ assert space.unwrap_int(w_v.at0(space, 0)) == 1
+
+def test_directory_delimitor():
+ import os.path
+ w_c = prim(primitives.DIRECTORY_DELIMITOR, [1])
+ assert space.unwrap_char(w_c) == os.path.sep
+
+
# Note:
# primitives.NEXT is unimplemented as it is a performance optimization
More information about the Pypy-commit
mailing list