[pypy-commit] lang-smalltalk default: README.md edited online with Bitbucket

2015-02-15 Thread anton_gulenko
Author: anton_gulenko 
Branch: 
Changeset: r1072:8497f404f0ec
Date: 2015-02-15 17:07 +
http://bitbucket.org/pypy/lang-smalltalk/changeset/8497f404f0ec/

Log:README.md edited online with Bitbucket

diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -1,93 +1,98 @@
-RSqueak
-=
-
-A Squeak VM written in RPython.
-
-Setup
-
-
-### Required Projects
-
-You need three repositories: 
-
-* [This one](https://bitbucket.org/pypy/lang-smalltalk)
-* [pypy/pypy](https://bitbucket.org/pypy/pypy)
-* [pypy/rsdl](https://bitbucket.org/pypy/rsdl)
-* Alternatively download RSDL package from 
[PYPI](https://pypi.python.org/pypi/rsdl)
-* Then unpack and install it using ```python setup.py install``` or 
```pypy setup.py install```
-
-### Required packages
-
-You need the following packages on your OS. Install with your favorite package 
manager:
-
-* pypy
-* For faster translation of the RSqueak VM. Alternatively use default 
Python.
-* libsdl-dev
-* libffi-dev
-
-### Adjusting the PYTHONPATH
-In order to allow the RPython toolchain to find the rsdl and pypy packages you 
have to add the two folders to the PYTHONPATH.
-
-If you are using the rsdl *repository*, you have to add the rsdl subfolder of 
the rsdl repository to the PYTHONPATH.
-
-```
-export PYTHONPATH=${PYTHONPATH}:.:[path/to/pypy]:[path/to/rsdl]
-```
-
-### Setting the SDL Driver
-For testing the basic functionality of the VM you might want to disable the 
UI. You can do so by setting the SDL_VIDEODRIVER environment variable to dummy.
-
-```
-export SDL_VIDEODRIVER=dummy
-```
-
-### Building & Tests
-Execute the following commands inside the main directory of this repository.
-
-To build the VM:
-
-```
-[path to pypy repository]/rpython/bin/rpython targetimageloadingsmalltalk.py
-```
-
-To build the VM with enabled just-in-time compiler:
-
-```
-[path to pypy repository]/rpython/bin/rpython -Ojit 
targetimageloadingsmalltalk.py
-```
-
-To run the tests (most do not require building):
-
-```
-[path to pypy repository]/pytest.py [--slow|--quick] spyvm/test
-```
-
-### Starting an image
-The build process will produce an executable called rsqueak.
-The ```image/``` directory contains two images you can open with the following.
-Use ```--help``` to see command line switches.
-
-```
-./rsqueak images/mini.image
-./rsqueak images/Squeak4.5-noBitBlt.image
-```
-
-
-
-
-STM-enabled Rsqueak
-===
-This is a branch of RSqueak which incorporates the RPython STM transformation. 
Most of the initial code base comes from the results of a project seminar 
(https://bitbucket.org/amintos/lang-smalltalk). The stmgc-c7 branch is based on 
this version and the 64bit branch.
-
-Setup for stm-enabled RSqueak

-You can see the current state of the integration of the RPython STM in our 
stmgc-c7 branch.
-Beware that you can only build this branch if you have a 64-bit linux. To 
build this branch you have to setup several things:
-
-1. Change your local pypy repository to the stm-gc7 branch, commit dd3c06b
-2. Get a clang which has the patches from ([Clang 
patches](https://bitbucket.org/pypy/stmgc/src/d164a5bcad5e7615b4362b6a1a49d51e2e06de0c/c7/llvmfix/?at=default)).
 If you have a Debian-based OS you can use the following package: 
[llvm-pypystm](https://launchpad.net/~malte.swart/+archive/ubuntu/llvm-pypystm).
-
-To build, use the following command:
-```
-[path to pypy repository]/rpython/bin/rpython --gc=stmgc 
targetimageloadingsmalltalk.py
-```
+#**This Project has moved**#
+##Please visit [RSqueak on Github](https://github.com/HPI-SWA-Lab/RSqueak)##
+
+
+
+RSqueak
+=
+
+A Squeak VM written in RPython.
+
+Setup
+
+
+### Required Projects
+
+You need three repositories: 
+
+* [This one](https://bitbucket.org/pypy/lang-smalltalk)
+* [pypy/pypy](https://bitbucket.org/pypy/pypy)
+* [pypy/rsdl](https://bitbucket.org/pypy/rsdl)
+* Alternatively download RSDL package from 
[PYPI](https://pypi.python.org/pypi/rsdl)
+* Then unpack and install it using ```python setup.py install``` or 
```pypy setup.py install```
+
+### Required packages
+
+You need the following packages on your OS. Install with your favorite package 
manager:
+
+* pypy
+* For faster translation of the RSqueak VM. Alternatively use default 
Python.
+* libsdl-dev
+* libffi-dev
+
+### Adjusting the PYTHONPATH
+In order to allow the RPython toolchain to find the rsdl and pypy packages you 
have to add the two folders to the PYTHONPATH.
+
+If you are using the rsdl *repository*, you have to add the rsdl subfolder of 
the rsdl repository to the PYTHONPATH.
+
+```
+export PYTHONPATH=${PYTHONPATH}:.:[path/to/pypy]:[path/to/rsdl]
+```
+
+### Setting the SDL Driver
+For testing the basic functionality of the VM you might want to disable the 
UI. You can do so by setting the SDL_VIDEODRIVER environment variable to dummy.
+
+```
+export SDL_VIDEODRIVER=dummy
+```
+
+### Building & Tests
+Execute the following commands inside the main directory

[pypy-commit] pypy default: Merged pypy/pypy into default

2015-04-22 Thread anton_gulenko
Author: anton_gulenko 
Branch: 
Changeset: r76869:9ca81bee353c
Date: 2015-02-22 11:45 +0100
http://bitbucket.org/pypy/pypy/changeset/9ca81bee353c/

Log:Merged pypy/pypy into default

diff too long, truncating to 2000 out of 2663 lines

diff --git a/lib_pypy/audioop.py b/lib_pypy/audioop.py
--- a/lib_pypy/audioop.py
+++ b/lib_pypy/audioop.py
@@ -480,6 +480,7 @@
 state_d, prev_i, cur_i,
 weightA, weightB)
 result = ffi.buffer(rv)[:trim_index]
+d = state_d[0]
 samps = zip(prev_i, cur_i)
 return (result, (d, tuple(samps)))
 
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -6,8 +6,8 @@
 .. startrev: 397b96217b85
 
 
-Fix non-blocking file reads sometimes raising EAGAIN even though they
-have buffered data waiting (b1c4fcb04a42)
+Non-blocking file reads sometimes raised EAGAIN even though they
+had buffered data waiting, fixed in b1c4fcb04a42
 
 
 .. branch: vmprof
@@ -18,3 +18,15 @@
 
 .. branch: stdlib-2.7.9
 Update stdlib to version 2.7.9
+
+.. branch: fix-kqueue-error2
+Fix exception being raised by kqueue.control (CPython compatibility)
+
+.. branch: gitignore
+
+.. branch: framestate2
+Refactor rpython.flowspace.framestate.FrameState.
+
+.. branch: alt_errno
+Add an alternative location to save LastError, errno around ctypes,
+cffi external calls so things like pdb will not overwrite it
diff --git a/pypy/interpreter/unicodehelper.py 
b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -25,8 +25,8 @@
 self.reason = reason
 
 @specialize.memo()
-def encode_error_handler(space):
-# Fast version of the "strict" errors handler.
+def rpy_encode_error_handler():
+# A RPython version of the "strict" error handler.
 def raise_unicode_exception_encode(errors, encoding, msg, u,
startingpos, endingpos):
 raise RUnicodeEncodeError(encoding, u, startingpos, endingpos, msg)
@@ -62,7 +62,10 @@
 return result
 
 def encode_utf8(space, uni):
+# Note that this function never raises UnicodeEncodeError,
+# since surrogate pairs are allowed.
+# This is not the case with Python3.
 return runicode.unicode_encode_utf_8(
 uni, len(uni), "strict",
-errorhandler=encode_error_handler(space),
+errorhandler=rpy_encode_error_handler(),
 allow_surrogates=True)
diff --git a/pypy/module/_cffi_backend/ccallback.py 
b/pypy/module/_cffi_backend/ccallback.py
--- a/pypy/module/_cffi_backend/ccallback.py
+++ b/pypy/module/_cffi_backend/ccallback.py
@@ -210,6 +210,6 @@
 space.threadlocals.leave_thread(space)
 
 def invoke_callback(ffi_cif, ll_res, ll_args, ll_userdata):
-cerrno._errno_after(rffi.RFFI_ERR_ALL)
+cerrno._errno_after(rffi.RFFI_ERR_ALL | rffi.RFFI_ALT_ERRNO)
 _invoke_callback(ffi_cif, ll_res, ll_args, ll_userdata)
-cerrno._errno_before(rffi.RFFI_ERR_ALL)
+cerrno._errno_before(rffi.RFFI_ERR_ALL | rffi.RFFI_ALT_ERRNO)
diff --git a/pypy/module/_cffi_backend/cerrno.py 
b/pypy/module/_cffi_backend/cerrno.py
--- a/pypy/module/_cffi_backend/cerrno.py
+++ b/pypy/module/_cffi_backend/cerrno.py
@@ -13,18 +13,18 @@
 _errno_after  = rposix._errno_after
 
 def get_errno(space):
-return space.wrap(rposix.get_saved_errno())
+return space.wrap(rposix.get_saved_alterrno())
 
 @unwrap_spec(errno=int)
 def set_errno(space, errno):
-rposix.set_saved_errno(errno)
+rposix.set_saved_alterrno(errno)
 
 # 
 
 @unwrap_spec(code=int)
 def getwinerror(space, code=-1):
-from rpython.rlib.rwin32 import GetLastError_saved, FormatError
+from rpython.rlib.rwin32 import GetLastError_alt_saved, FormatError
 if code == -1:
-code = GetLastError_saved()
+code = GetLastError_alt_saved()
 message = FormatError(code)
 return space.newtuple([space.wrap(code), space.wrap(message)])
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py 
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -2716,6 +2716,14 @@
 assert data == b"Xhello\n"
 posix.close(fdr)
 
+def test_errno_saved():
+set_errno(42)
+# a random function that will reset errno to 0 (at least on non-windows)
+import os; os.stat('.')
+#
+res = get_errno()
+assert res == 42
+
 def test_GetLastError():
 if sys.platform != "win32":
 py.test.skip("GetLastError(): only for Windows")
diff --git a/pypy/module/_rawffi/interp_rawffi.py 
b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -608,19 +608,19 @@
 return space.wrap(W_CD

[pypy-commit] pypy default: Merged pypy/pypy into default

2015-04-22 Thread anton_gulenko
Author: anton_gulenko 
Branch: 
Changeset: r76870:fe4c27d34d37
Date: 2015-03-07 16:20 +0100
http://bitbucket.org/pypy/pypy/changeset/fe4c27d34d37/

Log:Merged pypy/pypy into default

diff too long, truncating to 2000 out of 4777 lines

diff --git a/lib_pypy/cffi.egg-info b/lib_pypy/cffi.egg-info
--- a/lib_pypy/cffi.egg-info
+++ b/lib_pypy/cffi.egg-info
@@ -1,6 +1,6 @@
 Metadata-Version: 1.0
 Name: cffi
-Version: 0.8.6+
+Version: 0.9.0
 Summary: Foreign Function Interface for Python calling C code.
 Home-page: http://cffi.readthedocs.org
 Author: Armin Rigo, Maciej Fijalkowski
diff --git a/lib_pypy/cffi/__init__.py b/lib_pypy/cffi/__init__.py
--- a/lib_pypy/cffi/__init__.py
+++ b/lib_pypy/cffi/__init__.py
@@ -4,8 +4,8 @@
 from .api import FFI, CDefError, FFIError
 from .ffiplatform import VerificationError, VerificationMissing
 
-__version__ = "0.8.6+"
-__version_info__ = (0, 8, 6, "plus")
+__version__ = "0.9.0"
+__version_info__ = (0, 9, 0)
 
 # The verifier module file names are based on the CRC32 of a string that
 # contains the following version number.  It may be older than __version__
diff --git a/lib_pypy/gdbm.py b/lib_pypy/gdbm.py
--- a/lib_pypy/gdbm.py
+++ b/lib_pypy/gdbm.py
@@ -20,9 +20,11 @@
 } datum;
 
 datum gdbm_fetch(void*, datum);
+datum pygdbm_fetch(void*, char*, int);
 int gdbm_delete(void*, datum);
 int gdbm_store(void*, datum, datum, int);
 int gdbm_exists(void*, datum);
+int pygdbm_exists(void*, char*, int);
 
 int gdbm_reorganize(void*);
 
@@ -37,19 +39,29 @@
 ''')
 
 try:
+verify_code = '''
+#include "gdbm.h"
+
+static datum pygdbm_fetch(GDBM_FILE gdbm_file, char *dptr, int dsize) {
+datum key = {dptr, dsize};
+return gdbm_fetch(gdbm_file, key);
+}
+
+static int pygdbm_exists(GDBM_FILE gdbm_file, char *dptr, int dsize) {
+datum key = {dptr, dsize};
+return gdbm_exists(gdbm_file, key);
+}
+
+'''
 if sys.platform.startswith('freebsd'):
 import os.path
 _localbase = os.environ.get('LOCALBASE', '/usr/local')
-lib = ffi.verify('''
-#include "gdbm.h"
-''', libraries=['gdbm'],
+lib = ffi.verify(verify_code, libraries=['gdbm'],
  include_dirs=[os.path.join(_localbase, 'include')],
  library_dirs=[os.path.join(_localbase, 'lib')]
 )
 else:
-lib = ffi.verify('''
-#include "gdbm.h"
-''', libraries=['gdbm'])
+lib = ffi.verify(verify_code, libraries=['gdbm'])
 except cffi.VerificationError as e:
 # distutils does not preserve the actual message,
 # but the verification is simple enough that the
@@ -59,6 +71,13 @@
 class error(Exception):
 pass
 
+def _checkstr(key):
+if isinstance(key, unicode):
+key = key.encode("ascii")
+if not isinstance(key, str):
+raise TypeError("gdbm mappings have string indices only")
+return key
+
 def _fromstr(key):
 if isinstance(key, unicode):
 key = key.encode("ascii")
@@ -107,12 +126,14 @@
 
 def __contains__(self, key):
 self._check_closed()
-return lib.gdbm_exists(self.ll_dbm, _fromstr(key))
+key = _checkstr(key)
+return lib.pygdbm_exists(self.ll_dbm, key, len(key))
 has_key = __contains__
 
 def __getitem__(self, key):
 self._check_closed()
-drec = lib.gdbm_fetch(self.ll_dbm, _fromstr(key))
+key = _checkstr(key)
+drec = lib.pygdbm_fetch(self.ll_dbm, key, len(key))
 if not drec.dptr:
 raise KeyError(key)
 res = str(ffi.buffer(drec.dptr, drec.dsize))
diff --git a/lib_pypy/pyrepl/readline.py b/lib_pypy/pyrepl/readline.py
--- a/lib_pypy/pyrepl/readline.py
+++ b/lib_pypy/pyrepl/readline.py
@@ -73,7 +73,6 @@
 assume_immutable_completions = False
 use_brackets = False
 sort_in_column = True
-tab_insert_spaces_if_stem_is_empty = False
 
 def error(self, msg="none"):
 pass# don't show error messages by default
@@ -87,7 +86,7 @@
 return ''.join(b[p+1:self.pos])
 
 def get_completions(self, stem):
-if len(stem) == 0 and self.tab_insert_spaces_if_stem_is_empty:
+if len(stem) == 0 and self.more_lines is not None:
 b = self.buffer
 p = self.pos
 while p > 0 and b[p - 1] != '\n':
@@ -141,12 +140,16 @@
 
 def collect_keymap(self):
 return super(ReadlineAlikeReader, self).collect_keymap() + (
-(r'\n', 'maybe-accept'),)
+(r'\n', 'maybe-accept'),
+(r'\', 'backspace-dedent'),
+)
 
 def __init__(se

[pypy-commit] pypy default: Merged pypy/pypy into default

2015-04-22 Thread anton_gulenko
Author: anton_gulenko 
Branch: 
Changeset: r76871:cc41fe9a9031
Date: 2015-03-12 13:07 +0100
http://bitbucket.org/pypy/pypy/changeset/cc41fe9a9031/

Log:Merged pypy/pypy into default

diff --git a/lib_pypy/cffi.egg-info b/lib_pypy/cffi.egg-info
--- a/lib_pypy/cffi.egg-info
+++ b/lib_pypy/cffi.egg-info
@@ -1,6 +1,6 @@
 Metadata-Version: 1.0
 Name: cffi
-Version: 0.9.0
+Version: 0.9.1
 Summary: Foreign Function Interface for Python calling C code.
 Home-page: http://cffi.readthedocs.org
 Author: Armin Rigo, Maciej Fijalkowski
diff --git a/lib_pypy/cffi/__init__.py b/lib_pypy/cffi/__init__.py
--- a/lib_pypy/cffi/__init__.py
+++ b/lib_pypy/cffi/__init__.py
@@ -4,8 +4,8 @@
 from .api import FFI, CDefError, FFIError
 from .ffiplatform import VerificationError, VerificationMissing
 
-__version__ = "0.9.0"
-__version_info__ = (0, 9, 0)
+__version__ = "0.9.1"
+__version_info__ = (0, 9, 1)
 
 # The verifier module file names are based on the CRC32 of a string that
 # contains the following version number.  It may be older than __version__
diff --git a/pypy/module/_cffi_backend/__init__.py 
b/pypy/module/_cffi_backend/__init__.py
--- a/pypy/module/_cffi_backend/__init__.py
+++ b/pypy/module/_cffi_backend/__init__.py
@@ -2,13 +2,15 @@
 from pypy.interpreter.mixedmodule import MixedModule
 from rpython.rlib import rdynload
 
+VERSION = "0.9.1"
+
 
 class Module(MixedModule):
 
 appleveldefs = {
 }
 interpleveldefs = {
-'__version__': 'space.wrap("0.9.0")',
+'__version__': 'space.wrap("%s")' % VERSION,
 
 'load_library': 'libraryobj.load_library',
 
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py 
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -3249,4 +3249,4 @@
 
 def test_version():
 # this test is here mostly for PyPy
-assert __version__ == "0.9.0"
+assert __version__ == "0.9.1"
diff --git a/pypy/module/_cffi_backend/test/test_file.py 
b/pypy/module/_cffi_backend/test/test_file.py
--- a/pypy/module/_cffi_backend/test/test_file.py
+++ b/pypy/module/_cffi_backend/test/test_file.py
@@ -15,3 +15,15 @@
 "Update test/_backend_test_c.py by copying it from "
 "https://bitbucket.org/cffi/cffi/raw/default/c/test_c.py "
 "and killing the import lines at the start")
+
+def test_egginfo_version():
+from pypy.module._cffi_backend import VERSION
+line = "Version: %s\n" % VERSION
+eggfile = py.path.local(__file__).join('..', '..', '..', '..', '..',
+   'lib_pypy', 'cffi.egg-info')
+assert line in eggfile.readlines()
+
+def test_app_version():
+from pypy.module import _cffi_backend
+from lib_pypy import cffi
+assert _cffi_backend.VERSION == cffi.__version__
diff --git a/pypy/module/_random/interp_random.py 
b/pypy/module/_random/interp_random.py
--- a/pypy/module/_random/interp_random.py
+++ b/pypy/module/_random/interp_random.py
@@ -4,7 +4,7 @@
 from pypy.interpreter.typedef import TypeDef
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.baseobjspace import W_Root
-from rpython.rlib.rarithmetic import r_uint, intmask
+from rpython.rlib.rarithmetic import r_uint, intmask, widen
 from rpython.rlib import rbigint, rrandom, rstring
 
 
@@ -54,8 +54,8 @@
 def getstate(self, space):
 state = [None] * (rrandom.N + 1)
 for i in range(rrandom.N):
-state[i] = space.newint(intmask(self._rnd.state[i]))
-state[rrandom.N] = space.newint(self._rnd.index)
+state[i] = space.wrap(widen(self._rnd.state[i]))
+state[rrandom.N] = space.newlong(self._rnd.index)
 return space.newtuple(state)
 
 def setstate(self, space, w_state):
diff --git a/pypy/module/_random/test/test_random.py 
b/pypy/module/_random/test/test_random.py
--- a/pypy/module/_random/test/test_random.py
+++ b/pypy/module/_random/test/test_random.py
@@ -41,6 +41,17 @@
 # does not crash
 rnd1.setstate((-1, ) * 624 + (0, ))
 
+def test_state_repr(self):
+# since app-level jumpahead salts with repr(state),
+# it is important the repr is consistent with cpython
+import _random
+rnd = _random.Random()
+rnd.seed(1234)
+state = rnd.getstate()
+s = repr(state)
+assert len(s) == 7956
+assert s.count('L') == 625
+
 def test_seed(self):
 import _random, sys
 rnd = _random.Random()
diff --git a/pypy/module/_ssl/__init__.py b/pypy/module/_ssl/__init__.py
--- a/pypy/module/_ssl/__init__.py
+++ b/pypy/module/_ssl/__init__.py
@@ -51,6 +51,11 @@

[pypy-commit] pypy default: Removed pdb, added warning message and made more robust.

2015-04-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: 
Changeset: r76868:4e43d96d9d48
Date: 2015-02-22 11:43 +0100
http://bitbucket.org/pypy/pypy/changeset/4e43d96d9d48/

Log:Removed pdb, added warning message and made more robust.

diff --git a/rpython/rlib/rstrategies/logparser.py 
b/rpython/rlib/rstrategies/logparser.py
--- a/rpython/rlib/rstrategies/logparser.py
+++ b/rpython/rlib/rstrategies/logparser.py
@@ -12,7 +12,7 @@
 If the name of the logfile includes one of the AVAILABLE_VMS as a substring, 
the first three global variables
 are automatically configured.
 The script should work without these configurations, but the output will 
probably not be that pretty.
-To avoid errors, use the -a flag when running without proper configuration.
+To avoid errors, the -a flag is implied when running without proper 
configuration.
 """
 
 # This should contain a full list of storage nodes (strategies).
@@ -45,6 +45,21 @@
 
 AVAILABLE_VMS = ['RSqueak', 'Pycket', 'Topaz']
 
+def configure_vm(logfile, flags):
+vm_config_name = None
+for vm_name in AVAILABLE_VMS:
+if vm_name in logfile:
+vm_config_name = vm_name
+break
+if vm_config_name is not None:
+print "Using VM configuration %s" % vm_name
+SET_VM(vm_name)
+else:
+print "No VM configuration found in filename '%s'. Available 
configurations: %s" % \
+(logfile, AVAILABLE_VMS)
+print "Please add new VM configuration or rename logfile. Turning on 
-a flag to avoid errors."
+flags.allstorage = True
+
 # 
 #  Logfile parsing
 # 
@@ -370,8 +385,6 @@
 self.operations = set()
 
 def node(self, name):
-if str(name) == 'None':
-import pdb; pdb.set_trace()
 if name not in self.nodes:
 self.nodes[name] = StorageNode(name)
 return self.nodes[name]
@@ -666,11 +679,7 @@
 usage(flags, commands)
 logfile = argv[0]
 flags.logfile = logfile
-for vm_name in AVAILABLE_VMS:
-if vm_name in logfile:
-print "Using VM configuration %s" % vm_name
-SET_VM(vm_name)
-break
+configure_vm(logfile, flags)
 command = argv[1]
 for flag in argv[2:]:
 if not flags.handle(flag):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Added rstrategies (from https://github.com/antongulenko/rstrategies).

2015-04-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: 
Changeset: r76867:25ca52e41849
Date: 2015-02-15 19:15 +0100
http://bitbucket.org/pypy/pypy/changeset/25ca52e41849/

Log:Added rstrategies (from
https://github.com/antongulenko/rstrategies).

diff --git a/rpython/rlib/rstrategies/README.md 
b/rpython/rlib/rstrategies/README.md
new file mode 100644
--- /dev/null
+++ b/rpython/rlib/rstrategies/README.md
@@ -0,0 +1,101 @@
+# rstrategies
+
+A library to implement storage strategies in VMs based on the RPython 
toolchain.
+rstrategies can be used in VMs for any language or language family.
+
+This library has been developed as part of a Masters Thesis by [Anton 
Gulenko](https://github.com/antongulenko).
+
+The original paper describing the optimization "Storage Strategies for 
collections in dynamically typed languages" by C.F. Bolz, L. Diekmann and L. 
Tratt can be found 
[here](http://stups.hhu.de/mediawiki/images/3/3b/Pub-BoDiTr13_246.pdf).
+
+So far, this library has been adpoted by 3 VMs: 
[RSqueak](https://github.com/HPI-SWA-Lab/RSqueak), 
[Topaz](https://github.com/topazproject/topaz) ([Forked 
here](https://github.com/antongulenko/topaz/tree/rstrategies)) and 
[Pycket](https://github.com/samth/pycket) ([Forked 
here](https://github.com/antongulenko/pycket/tree/rstrategies)).
+
+ Concept
+
+Collections are often used homogeneously, i.e. they contain only objects of 
the same type.
+Primitive numeric types like ints or floats are especially interesting for 
optimization.
+These cases can be optimized by storing the unboxed data of these objects in 
consecutive memory.
+This is done by letting a special "strategy" object handle the entire storage 
of a collection.
+The collection object holds two separate references: one to its strategy and 
one to its storage.
+Every operation on the collection is delegated to the strategy, which accesses 
the storage when needed.
+The strategy can be switched to a more suitable one, which might require 
converting the storage array.
+
+## Usage
+
+The following are the steps needed to integrated rstrategies in an RPython VM.
+Because of the special nature of this library it is not enough to simply call 
some API methods; the library must be integrated within existing VM classes 
using a metaclass, mixins and other meta-programming techniques.
+
+The sequence of steps described here is something like a "setup walkthrough", 
and might be a bit abstract.
+To see a concrete example, look at 
[AbstractShadow](https://github.com/HPI-SWA-Lab/RSqueak/blob/d5ff2572106d23a5246884de6f8b86f46d85f4f7/spyvm/storage.py#L73),
 
[StrategyFactory](https://github.com/HPI-SWA-Lab/RSqueak/blob/d5ff2572106d23a5246884de6f8b86f46d85f4f7/spyvm/storage.py#L126)
 and 
[W_PointersObject](https://github.com/HPI-SWA-Lab/RSqueak/blob/d5ff2572106d23a5246884de6f8b86f46d85f4f7/spyvm/model.py#L565)
 from the [RSqueak VM](https://github.com/HPI-SWA-Lab/RSqueak).
+The code is also well commented.
+
+ Basics
+
+Currently the rstrategies library supports fixed sized and variable sized 
collections.
+This can be used to optimize a wide range of primitive data structures like 
arrays, lists or regular objects.
+Any of these are called 'collections' in this context.
+The VM should have a central class or class hierarchy for collections.
+In order to extend these classes and use strategies, the library needs 
accessor methods for two attributes of collection objects: strategy and storage.
+The easiest way is adding the following line to the body of the root 
collection class:
+```
+rstrategies.make_accessors(strategy='strategy', storage='storage')
+```
+This will generate the 4 accessor methods 
```_[get/set]_[storage/strategy]()``` for the respective attributes.
+Alternatively, implement these methods manually or overwrite the 
getters/setters in ```StrategyFactory```.
+
+Next, the strategy classes must be defined. This requires a small class 
hierarchy with a dedicated root class.
+In the definition of this root class, include the following lines:
+```
+__metaclass__ = rstrategies.StrategyMetaclass
+import_from_mixin(rstrategies.AbstractStrategy)
+import_from_mixin(rstrategies.SafeIndexingMixin)
+```
+
+```import_from_mixin``` can be found in ```rpython.rlib.objectmodel```.
+If index-checking is performed safely at other places in the VM, you can use 
```rstrategies.UnsafeIndexingMixin``` instead.
+If you need your own metaclass, you can combine yours with the rstrategies one 
using multiple inheritance [like 
here](https://github.com/HPI-SWA-Lab/RSqueak/blob/d5ff2572106d23a5246884de6f8b86f46d85f4f7/spyvm/storage_contexts.py#L24).
+Also implement a ```storage_factory()``` method, which returns an instance of 
```rstrategies.StorageFactory```, which is described below.
+
+ Strategy classes
+
+Now you can create the actual strategy classes, subclassing them from the 
single root class.
+The following list summarizes the basic strategies available.
+* ```EmptyStrategy```
+A strategy for empty 

[pypy-commit] pypy default: Added tests to improve coverage. logger.py and rstrategies.py: 96%.

2015-04-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: 
Changeset: r76875:0f889cf7f755
Date: 2015-03-12 13:04 +0100
http://bitbucket.org/pypy/pypy/changeset/0f889cf7f755/

Log:Added tests to improve coverage. logger.py and rstrategies.py: 96%.

diff --git a/rpython/rlib/rstrategies/.coveragerc 
b/rpython/rlib/rstrategies/.coveragerc
new file mode 100644
--- /dev/null
+++ b/rpython/rlib/rstrategies/.coveragerc
@@ -0,0 +1,10 @@
+# .coveragerc file to control coverage.py (code coverage plugin for pytest)
+# Get it here: https://pypi.python.org/pypi/pytest-cov
+# Examples:
+# $ python -m pytest test --cov rpython.rlib.rstrategies --cov-report html 
--cov-config .coveragerc
+
+[run]
+omit =
+test/*
+*/__init__.py
+logparser.py
diff --git a/rpython/rlib/rstrategies/logger.py 
b/rpython/rlib/rstrategies/logger.py
--- a/rpython/rlib/rstrategies/logger.py
+++ b/rpython/rlib/rstrategies/logger.py
@@ -51,4 +51,8 @@
 classname_string = " of %s" % typename if typename else ""
 element_string = (" elements: " + " ".join(element_typenames)) if 
element_typenames else ""
 format = (cause, old_strategy_string, new_strategy, classname_string, 
slots, objects, element_string)
-print "%s (%s%s)%s size %d objects %d%s" % format
+self.do_print("%s (%s%s)%s size %d objects %d%s" % format)
+
+def do_print(self, str):
+# Hook to increase testability
+print str
diff --git a/rpython/rlib/rstrategies/test/test_rstrategies.py 
b/rpython/rlib/rstrategies/test/test_rstrategies.py
--- a/rpython/rlib/rstrategies/test/test_rstrategies.py
+++ b/rpython/rlib/rstrategies/test/test_rstrategies.py
@@ -72,11 +72,10 @@
 
 def __init__(self, root_class):
 self.decorate_strategies({
-EmptyStrategy: [GenericStrategy],
+EmptyStrategy: [NilStrategy, IntegerStrategy, 
IntegerOrNilStrategy, GenericStrategy],
 NilStrategy: [IntegerOrNilStrategy, GenericStrategy],
 GenericStrategy: [],
-WeakGenericStrategy: [],
-IntegerStrategy: [IntegerOrNilStrategy, GenericStrategy],
+IntegerStrategy: [IntegerOrNilStrategy, GenericStrategy],
 IntegerOrNilStrategy: [GenericStrategy],
 })
 rs.StrategyFactory.__init__(self, root_class)
@@ -94,6 +93,7 @@
 
 class EmptyStrategy(AbstractStrategy):
 import_from_mixin(rs.EmptyStrategy)
+# TODO - implement and test transition from Generic back to Empty
 
 class NilStrategy(AbstractStrategy):
 import_from_mixin(rs.SingleValueStrategy)
@@ -129,11 +129,16 @@
 def __init__(self, factory, w_list=None, size=0):
 super(NonSingletonStrategy, self).__init__(factory, w_list, size)
 self.w_list = w_list
-self.size = size
+self.the_size = size
 
 class NonStrategy(NonSingletonStrategy):
 pass
 
+@rs.strategy(generalize=[])
+class InefficientStrategy(GenericStrategy):
+def _convert_storage_from(self, w_self, previous_strategy):
+return AbstractStrategy._convert_storage_from(self, w_self, 
previous_strategy)
+
 factory = Factory(AbstractStrategy)
 
 def check_contents(list, expected):
@@ -207,6 +212,8 @@
 assert s.size(l) == 0
 py.test.raises(IndexError, s.fetch, l, 0)
 py.test.raises(IndexError, s.fetch, l, 10)
+py.test.raises(IndexError, s.delete, l, 0, 1)
+py.test.raises(AssertionError, W_List, EmptyStrategy, 2) # Only size 0 
possible.
 
 def test_init_Nil():
 do_test_initialization(NilStrategy)
@@ -265,13 +272,17 @@
 def do_test_insert(cls, values):
 l = W_List(cls, 0)
 assert len(values) >= 6
-values1 = values[0:2]
+values0 = values[0:1]
+values1 = values[1:2]
 values2 = values[2:4]
 values3 = values[4:6]
-l.insert(0, values1+values3)
-check_contents(l, values1+values3)
+l.insert(3, values0) # Will still be inserted at the very beginning
+check_contents(l, values0)
+l.insert(1, values1+values3)
+check_contents(l, values0+values1+values3)
 l.insert(2, values2)
 check_contents(l, values)
+return l
 
 def test_insert_Nil():
 do_test_insert(NilStrategy, [w_nil]*6)
@@ -291,9 +302,11 @@
 
 # === Test Delete
 
-def do_test_delete(cls, values):
+def do_test_delete(cls, values, indexing_unsafe=False):
 assert len(values) >= 6
 l = W_List(cls, len(values), values)
+if not indexing_unsafe:
+py.test.raises(IndexError, l.delete, 2, 1)
 l.delete(2, 4)
 del values[2: 4]
 check_contents(l, values)
@@ -305,7 +318,7 @@
 do_test_delete(NilStrategy, [w_nil]*6)
 
 def test_delete_Generic():
-do_test_delete(GenericStrategy, [W_Object() for _ in range(6)])
+do_test_delete(GenericStrategy, [W_Object() for _ in range(6)], 
indexing_unsafe=True)
 
 def test_delete_WeakGeneric():
 do_test_delete(WeakGenericStrategy, [W_Object() for _ in range(6)])
@@ -356,6 +369,13 @@
 def test_Integer_to_IntegerOrNil():
 do_test_transition(IntegerStrategy, w_nil, IntegerOrNilStr

[pypy-commit] pypy default: Renamed test.py

2015-04-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: 
Changeset: r76872:400f8dc54f5d
Date: 2015-03-07 16:18 +0100
http://bitbucket.org/pypy/pypy/changeset/400f8dc54f5d/

Log:Renamed test.py

diff --git a/rpython/rlib/rstrategies/test.py 
b/rpython/rlib/rstrategies/test_rstrategies.py
rename from rpython/rlib/rstrategies/test.py
rename to rpython/rlib/rstrategies/test_rstrategies.py
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Moved test file into test/ directory.

2015-04-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: 
Changeset: r76873:e9e6ff0ec517
Date: 2015-03-07 17:01 +0100
http://bitbucket.org/pypy/pypy/changeset/e9e6ff0ec517/

Log:Moved test file into test/ directory. Added underscore to some
internal methods.

diff --git a/rpython/rlib/rstrategies/rstrategies.py 
b/rpython/rlib/rstrategies/rstrategies.py
--- a/rpython/rlib/rstrategies/rstrategies.py
+++ b/rpython/rlib/rstrategies/rstrategies.py
@@ -74,7 +74,7 @@
 
 def __init__(self, root_class, all_strategy_classes=None):
 if all_strategy_classes is None:
-all_strategy_classes = self.collect_subclasses(root_class)
+all_strategy_classes = self._collect_subclasses(root_class)
 self.strategies = []
 self.logger = logger.Logger()
 
@@ -82,15 +82,15 @@
 self.strategy_singleton_field = "__singleton_%i" % 
StrategyFactory.factory_instance_counter
 StrategyFactory.factory_instance_counter += 1
 
-self.create_strategy_instances(root_class, all_strategy_classes)
+self._create_strategy_instances(root_class, all_strategy_classes)
 
-def create_strategy_instances(self, root_class, all_strategy_classes):
+def _create_strategy_instances(self, root_class, all_strategy_classes):
 for strategy_class in all_strategy_classes:
 if strategy_class._is_strategy:
 setattr(strategy_class, self.strategy_singleton_field, 
self.instantiate_strategy(strategy_class))
 self.strategies.append(strategy_class)
-self.patch_strategy_class(strategy_class, root_class)
-self.order_strategies()
+self._patch_strategy_class(strategy_class, root_class)
+self._order_strategies()
 
 # =
 # API methods
@@ -217,7 +217,7 @@
 # Internal methods
 # =
 
-def patch_strategy_class(self, strategy_class, root_class):
+def _patch_strategy_class(self, strategy_class, root_class):
 "NOT_RPYTHON"
 # Patch root class: Add default handler for visitor
 def convert_storage_from_OTHER(self, w_self, previous_strategy):
@@ -231,15 +231,15 @@
 getattr(new_strategy, funcname)(w_self, self)
 strategy_class.convert_storage_to = convert_storage_to
 
-def collect_subclasses(self, cls):
+def _collect_subclasses(self, cls):
 "NOT_RPYTHON"
 subclasses = []
 for subcls in cls.__subclasses__():
 subclasses.append(subcls)
-subclasses.extend(self.collect_subclasses(subcls))
+subclasses.extend(self._collect_subclasses(subcls))
 return subclasses
 
-def order_strategies(self):
+def _order_strategies(self):
 "NOT_RPYTHON"
 def get_generalization_depth(strategy, visited=None):
 if visited is None:
@@ -327,7 +327,7 @@
 raise NotImplementedError("Abstract method")
 
 def convert_storage_to(self, w_self, new_strategy):
-# This will be overwritten in patch_strategy_class
+# This will be overwritten in _patch_strategy_class
 new_strategy.convert_storage_from(w_self, self)
 
 @jit.unroll_safe
diff --git a/rpython/rlib/rstrategies/test_rstrategies.py 
b/rpython/rlib/rstrategies/test/test_rstrategies.py
rename from rpython/rlib/rstrategies/test_rstrategies.py
rename to rpython/rlib/rstrategies/test/test_rstrategies.py
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Converted README.md to reStructuredText inside rpython/doc/

2015-04-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: 
Changeset: r76878:9b7808006d44
Date: 2015-03-12 13:40 +0100
http://bitbucket.org/pypy/pypy/changeset/9b7808006d44/

Log:Converted README.md to reStructuredText inside rpython/doc/ Added
short section and reference inside rlib.rst.

diff --git a/rpython/doc/rlib.rst b/rpython/doc/rlib.rst
--- a/rpython/doc/rlib.rst
+++ b/rpython/doc/rlib.rst
@@ -128,6 +128,14 @@
 a hierarchy of Address classes, in a typical static-OO-programming style.
 
 
+rstrategies
+---
+
+The :source:`rpython/rlib/rstrategies` module contains a library to implement 
storage strategies in
+RPython VMs. The library is language-independent and extensible.
+More details and examples can be found in the :doc:`rstrategies documentation 
`.
+
+
 streamio
 
 
diff --git a/rpython/doc/rstrategies.rst b/rpython/doc/rstrategies.rst
new file mode 100644
--- /dev/null
+++ b/rpython/doc/rstrategies.rst
@@ -0,0 +1,148 @@
+rstrategies
+===
+
+A library to implement storage strategies in VMs based on the RPython
+toolchain. rstrategies can be used in VMs for any language or language
+family.
+
+This library has been developed as part of a Masters Thesis by `Anton
+Gulenko `__.
+
+The original paper describing the optimization "Storage Strategies for
+collections in dynamically typed languages" by C.F. Bolz, L. Diekmann
+and L. Tratt can be found
+`here `__.
+
+So far, this library has been adpoted by 3 VMs:
+`RSqueak `__,
+`Topaz `__ (`Forked
+here `__) and
+`Pycket `__ (`Forked
+here `__).
+
+Concept
+^^^
+
+Collections are often used homogeneously, i.e. they contain only objects
+of the same type. Primitive numeric types like ints or floats are
+especially interesting for optimization. These cases can be optimized by
+storing the unboxed data of these objects in consecutive memory. This is
+done by letting a special "strategy" object handle the entire storage of
+a collection. The collection object holds two separate references: one
+to its strategy and one to its storage. Every operation on the
+collection is delegated to the strategy, which accesses the storage when
+needed. The strategy can be switched to a more suitable one, which might
+require converting the storage array.
+
+Usage
+-
+
+The following are the steps needed to integrated rstrategies in an
+RPython VM. Because of the special nature of this library it is not
+enough to simply call some API methods; the library must be integrated
+within existing VM classes using a metaclass, mixins and other
+meta-programming techniques.
+
+The sequence of steps described here is something like a "setup
+walkthrough", and might be a bit abstract. To see a concrete example,
+look at
+`AbstractShadow 
`__,
+`StrategyFactory 
`__
+and
+`W\_PointersObject 
`__
+from the `RSqueak VM `__. The
+code is also well commented.
+
+Basics
+^^
+
+Currently the rstrategies library supports fixed sized and variable
+sized collections. This can be used to optimize a wide range of
+primitive data structures like arrays, lists or regular objects. Any of
+these are called 'collections' in this context. The VM should have a
+central class or class hierarchy for collections. In order to extend
+these classes and use strategies, the library needs accessor methods for
+two attributes of collection objects: strategy and storage. The easiest
+way is adding the following line to the body of the root collection
+class:
+
+::
+
+rstrategies.make_accessors(strategy='strategy', storage='storage')
+
+This will generate the 4 accessor methods
+``_[get/set]_[storage/strategy]()`` for the respective attributes.
+Alternatively, implement these methods manually or overwrite the
+getters/setters in ``StrategyFactory``.
+
+Next, the strategy classes must be defined. This requires a small class
+hierarchy with a dedicated root class. In the definition of this root
+class, include the following lines:
+
+::
+
+__metaclass__ = rstrategies.StrategyMetaclass
+import_from_mixin(rstrategies.AbstractStrategy)
+import_from_mixin(rstrategies.SafeIndexingMixin)
+
+``import_from_mixin`` can be found in ``rpython.rlib.objectmodel``. If
+index-checking is performed safely at other places in the VM, you can
+use ``rstrategies.UnsafeIndexingMixin`` instead. If you need your ow

[pypy-commit] pypy default: 2 small bugfixes, 1 comment

2015-04-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: 
Changeset: r76876:86b93d0474f4
Date: 2015-03-12 13:05 +0100
http://bitbucket.org/pypy/pypy/changeset/86b93d0474f4/

Log:2 small bugfixes, 1 comment

diff --git a/rpython/rlib/rstrategies/rstrategies.py 
b/rpython/rlib/rstrategies/rstrategies.py
--- a/rpython/rlib/rstrategies/rstrategies.py
+++ b/rpython/rlib/rstrategies/rstrategies.py
@@ -250,7 +250,7 @@
 visited.add(strategy)
 depth = 0
 for generalization in strategy._generalizations:
-other_depth = get_generalization_depth(generalization, 
visited)
+other_depth = get_generalization_depth(generalization, 
set(visited))
 depth = max(depth, other_depth)
 return depth + 1
 else:
@@ -370,7 +370,7 @@
 def fetch(self, w_self, index0):
 raise IndexError
 def store(self, w_self, index0, value):
-self._cannot_handle_insert(w_self, index0, [value])
+self._cannot_handle_store(w_self, index0, [value])
 def insert(self, w_self, index0, list_w):
 self._cannot_handle_insert(w_self, index0, list_w)
 def delete(self, w_self, start, end):
@@ -465,6 +465,8 @@
 
 @jit.unroll_safe
 def insert(self, w_self, start, list_w):
+# This is following Python's behaviour - insert automatically
+# happens at the beginning of an array, even if index is larger
 if start > self.size(w_self):
 start = self.size(w_self)
 for i in range(len(list_w)):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Fixed source-code formatting in doc

2015-04-22 Thread anton_gulenko
Author: anton_gulenko 
Branch: 
Changeset: r76880:7d7e19e7f237
Date: 2015-03-12 13:58 +
http://bitbucket.org/pypy/pypy/changeset/7d7e19e7f237/

Log:Fixed source-code formatting in doc (rstrategies.rst edited online
with Bitbucket)

diff --git a/rpython/doc/rstrategies.rst b/rpython/doc/rstrategies.rst
--- a/rpython/doc/rstrategies.rst
+++ b/rpython/doc/rstrategies.rst
@@ -98,18 +98,18 @@
 
 ::
 
-class AbstractStrategy(AbstractStrategy):
-_attrs_ = ['space']
-_immutable_fields_ = ['space']
-__metaclass__ = rstrat.StrategyMetaclass
-import_from_mixin(rstrat.AbstractStrategy)
-import_from_mixin(rstrategies.SafeIndexingMixin)
-
-def __init__(self, space):
-self.space = space
-
-def strategy_factory(self):
-return self.space.strategy_factory
+class AbstractStrategy(AbstractStrategy):
+_attrs_ = ['space']
+_immutable_fields_ = ['space']
+__metaclass__ = rstrat.StrategyMetaclass
+import_from_mixin(rstrat.AbstractStrategy)
+import_from_mixin(rstrategies.SafeIndexingMixin)
+
+def __init__(self, space):
+self.space = space
+
+def strategy_factory(self):
+return self.space.strategy_factory
 
 
 Strategy classes
@@ -144,14 +144,14 @@
 
 ::
 
-@rstrat.strategy(generalize=[GenericStrategy])
-class IntegerOrNilStrategy(AbstractStrategy):
-import_from_mixin(rstrat.TaggingStrategy)
-contained_type = model.W_Integer
-def wrap(self, val): return self.space.wrap_int(val)
-def unwrap(self, w_val): return self.space.unwrap_int(w_val)
-def wrapped_tagged_value(self): return self.space.w_nil
-def unwrapped_tagged_value(self): return constants.MAXINT
+@rstrat.strategy(generalize=[GenericStrategy])
+class IntegerOrNilStrategy(AbstractStrategy):
+import_from_mixin(rstrat.TaggingStrategy)
+contained_type = model.W_Integer
+def wrap(self, val): return self.space.wrap_int(val)
+def unwrap(self, w_val): return self.space.unwrap_int(w_val)
+def wrapped_tagged_value(self): return self.space.w_nil
+def unwrapped_tagged_value(self): return constants.MAXINT
 
 Strategy Factory
 
@@ -188,22 +188,22 @@
 
 ::
 
-class StrategyFactory(rstrategies.StrategyFactory):
-_attrs_ = ['space']
-_immutable_fields_ = ['space']
-
-def __init__(self, space):
-self.space = space
-rstrat.StrategyFactory.__init__(self, AbstractStrategy)
-
-def instantiate_strategy(self, strategy_type):
-return strategy_type(self.space)
-
-def strategy_type_for(self, list_w, weak=False):
-"""
-Helper method for handling weak objects specially
-"""
-if weak:
-return WeakListStrategy
+class StrategyFactory(rstrategies.StrategyFactory):
+_attrs_ = ['space']
+_immutable_fields_ = ['space']
+
+def __init__(self, space):
+self.space = space
+rstrat.StrategyFactory.__init__(self, AbstractStrategy)
+
+def instantiate_strategy(self, strategy_type):
+return strategy_type(self.space)
+
+def strategy_type_for(self, list_w, weak=False):
+"""
+Helper method for handling weak objects specially
+"""
+if weak:
+return WeakListStrategy
 return rstrategies.StrategyFactory.strategy_type_for(self, list_w)
 
\ No newline at end of file
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Added underscore to some more methods.

2015-04-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: 
Changeset: r76874:45166060bc6f
Date: 2015-03-07 17:10 +0100
http://bitbucket.org/pypy/pypy/changeset/45166060bc6f/

Log:Added underscore to some more methods.

diff --git a/rpython/rlib/rstrategies/rstrategies.py 
b/rpython/rlib/rstrategies/rstrategies.py
--- a/rpython/rlib/rstrategies/rstrategies.py
+++ b/rpython/rlib/rstrategies/rstrategies.py
@@ -56,7 +56,7 @@
 def generalized_strategy_for(self, value):
 # TODO - optimize this method
 for strategy in generalize:
-if 
self.strategy_factory().strategy_singleton_instance(strategy).check_can_handle(value):
+if 
self.strategy_factory().strategy_singleton_instance(strategy)._check_can_handle(value):
 return strategy
 raise Exception("Could not find generalized strategy for %s 
coming from %s" % (value, self))
 strategy_class.generalized_strategy_for = generalized_strategy_for
@@ -109,7 +109,7 @@
 size = old_strategy.size(w_self)
 new_strategy = self.instantiate_strategy(new_strategy_type, 
w_self, size)
 self.set_strategy(w_self, new_strategy)
-old_strategy.convert_storage_to(w_self, new_strategy)
+old_strategy._convert_storage_to(w_self, new_strategy)
 new_strategy.strategy_switched(w_self)
 self.log(w_self, new_strategy, old_strategy, new_element)
 return new_strategy
@@ -127,7 +127,7 @@
 else:
 strategy = self.instantiate_strategy(strategy_type, w_self, size)
 self.set_strategy(w_self, strategy)
-strategy.initialize_storage(w_self, size)
+strategy._initialize_storage(w_self, size)
 element = None
 if elements:
 strategy.store_all(w_self, elements)
@@ -147,7 +147,7 @@
 if specialized_strategies <= 1:
 break
 for i, strategy in enumerate(self.strategies):
-if can_handle[i] and not 
self.strategy_singleton_instance(strategy).check_can_handle(obj):
+if can_handle[i] and not 
self.strategy_singleton_instance(strategy)._check_can_handle(obj):
 can_handle[i] = False
 specialized_strategies -= 1
 for i, strategy_type in enumerate(self.strategies):
@@ -220,16 +220,16 @@
 def _patch_strategy_class(self, strategy_class, root_class):
 "NOT_RPYTHON"
 # Patch root class: Add default handler for visitor
-def convert_storage_from_OTHER(self, w_self, previous_strategy):
-self.convert_storage_from(w_self, previous_strategy)
-funcname = "convert_storage_from_" + strategy_class.__name__
-convert_storage_from_OTHER.func_name = funcname
-setattr(root_class, funcname, convert_storage_from_OTHER)
+def _convert_storage_from_OTHER(self, w_self, previous_strategy):
+self._convert_storage_from(w_self, previous_strategy)
+funcname = "_convert_storage_from_" + strategy_class.__name__
+_convert_storage_from_OTHER.func_name = funcname
+setattr(root_class, funcname, _convert_storage_from_OTHER)
 
 # Patch strategy class: Add polymorphic visitor function
-def convert_storage_to(self, w_self, new_strategy):
+def _convert_storage_to(self, w_self, new_strategy):
 getattr(new_strategy, funcname)(w_self, self)
-strategy_class.convert_storage_to = convert_storage_to
+strategy_class._convert_storage_to = _convert_storage_to
 
 def _collect_subclasses(self, cls):
 "NOT_RPYTHON"
@@ -320,37 +320,37 @@
 
 # Internal methods
 
-def initialize_storage(self, w_self, initial_size):
+def _initialize_storage(self, w_self, initial_size):
 raise NotImplementedError("Abstract method")
 
-def check_can_handle(self, value):
+def _check_can_handle(self, value):
 raise NotImplementedError("Abstract method")
 
-def convert_storage_to(self, w_self, new_strategy):
+def _convert_storage_to(self, w_self, new_strategy):
 # This will be overwritten in _patch_strategy_class
-new_strategy.convert_storage_from(w_self, self)
+new_strategy._convert_storage_from(w_self, self)
 
 @jit.unroll_safe
-def convert_storage_from(self, w_self, previous_strategy):
+def _convert_storage_from(self, w_self, previous_strategy):
 # This is a very unefficient (but most generic) way to do this.
 # Subclasses should specialize.
 storage = previous_strategy.fetch_all(w_self)
-self.initialize_storage(w_self, previous_strategy.size(w_self))
+self._initialize_storage(w_self, previous_strategy.size(w_self))
 for i, field in enumerate(storage):
 self.store(w_self, i, field)
 
-def generalize_for_value(self, w_self, value):
+def _generalize_for_value(self, w_self, value):
 

[pypy-commit] pypy default: Fixed formatting issues in doc file.

2015-04-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: 
Changeset: r76879:83b5d7b51f28
Date: 2015-03-12 14:52 +0100
http://bitbucket.org/pypy/pypy/changeset/83b5d7b51f28/

Log:Fixed formatting issues in doc file. Added example code for the
Usage-walkthrough.

diff --git a/rpython/doc/rstrategies.rst b/rpython/doc/rstrategies.rst
--- a/rpython/doc/rstrategies.rst
+++ b/rpython/doc/rstrategies.rst
@@ -21,7 +21,7 @@
 here `__).
 
 Concept
-^^^
+---
 
 Collections are often used homogeneously, i.e. they contain only objects
 of the same type. Primitive numeric types like ints or floats are
@@ -35,7 +35,7 @@
 require converting the storage array.
 
 Usage
--
+~
 
 The following are the steps needed to integrated rstrategies in an
 RPython VM. Because of the special nature of this library it is not
@@ -46,15 +46,15 @@
 The sequence of steps described here is something like a "setup
 walkthrough", and might be a bit abstract. To see a concrete example,
 look at
-`AbstractShadow 
`__,
-`StrategyFactory 
`__
+`SingletonStorageStrategy 
`__,
+`StrategyFactory 
`__
 and
-`W\_PointersObject 
`__
+`W\_PointersObject 
`__
 from the `RSqueak VM `__. The
 code is also well commented.
 
 Basics
-^^
+---
 
 Currently the rstrategies library supports fixed sized and variable
 sized collections. This can be used to optimize a wide range of
@@ -94,23 +94,37 @@
 Also implement a ``storage_factory()`` method, which returns an instance
 of ``rstrategies.StorageFactory``, which is described below.
 
+An example ``AbstractStrategy`` class, which also stores an additional 
``space`` parameter could looks like this:
+
+::
+
+class AbstractStrategy(AbstractStrategy):
+_attrs_ = ['space']
+_immutable_fields_ = ['space']
+__metaclass__ = rstrat.StrategyMetaclass
+import_from_mixin(rstrat.AbstractStrategy)
+import_from_mixin(rstrategies.SafeIndexingMixin)
+
+def __init__(self, space):
+self.space = space
+
+def strategy_factory(self):
+return self.space.strategy_factory
+
+
 Strategy classes
-
+
 
 Now you can create the actual strategy classes, subclassing them from
 the single root class. The following list summarizes the basic
-strategies available. \* ``EmptyStrategy`` A strategy for empty
-collections; very efficient, but limited. Does not allocate anything. \*
-``SingleValueStrategy`` A strategy for collections containing the same
-object ``n`` times. Only allocates memory to store the size of the
-collection. \* ``GenericStrategy`` A non-optimized strategy backed by a
-generic python list. This is the fallback strategy, since it can store
-everything, but is not optimized. \* ``WeakGenericStrategy`` Like
-``GenericStrategy``, but uses ``weakref`` to hold on weakly to its
-elements. \* ``SingleTypeStrategy`` Can store a single unboxed type like
-int or float. This is the main \* ``TaggingStrategy`` Extension of
-SingleTypeStrategy. Uses a specific value in the value range of the
-unboxed type to represent one additional, arbitrary object.
+strategies available.
+
+- ``EmptyStrategy`` A strategy for empty collections; very efficient, but 
limited. Does not allocate anything.
+- ``SingleValueStrategy`` A strategy for collections containing the same 
object ``n`` times. Only allocates memory to store the size of the collection.
+- ``GenericStrategy`` A non-optimized strategy backed by a generic python 
list. This is the fallback strategy, since it can store everything, but is not 
optimized.
+- ``WeakGenericStrategy`` Like ``GenericStrategy``, but uses ``weakref`` to 
hold on weakly to its elements.
+- ``SingleTypeStrategy`` Can store a single unboxed type like int or float. 
This is the main optimizing strategy
+- ``TaggingStrategy`` Extension of SingleTypeStrategy. Uses a specific value 
in the value range of the unboxed type to represent one additional, arbitrary 
object. For example, one of ``float``'s ``NaN`` representations can be used to 
represent special value like ``nil``.
 
 There are also intermediate classes, which allow creating new, more
 customized strategies. For this, you should get familiar with the code.
@@ -118,7 +132,7 @@
 Include one of these mixin classes using ``import_from_mixin``. The
 mix

[pypy-commit] pypy default: Merged file edited online.

2015-04-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: 
Changeset: r76882:f1984a4d5583
Date: 2015-03-12 15:04 +0100
http://bitbucket.org/pypy/pypy/changeset/f1984a4d5583/

Log:Merged file edited online.

diff --git a/rpython/doc/rstrategies.rst b/rpython/doc/rstrategies.rst
--- a/rpython/doc/rstrategies.rst
+++ b/rpython/doc/rstrategies.rst
@@ -98,18 +98,18 @@
 
 ::
 
-class AbstractStrategy(AbstractStrategy):
-_attrs_ = ['space']
-_immutable_fields_ = ['space']
-__metaclass__ = rstrat.StrategyMetaclass
-import_from_mixin(rstrat.AbstractStrategy)
-import_from_mixin(rstrategies.SafeIndexingMixin)
-
-def __init__(self, space):
-self.space = space
-
-def strategy_factory(self):
-return self.space.strategy_factory
+class AbstractStrategy(AbstractStrategy):
+_attrs_ = ['space']
+_immutable_fields_ = ['space']
+__metaclass__ = rstrat.StrategyMetaclass
+import_from_mixin(rstrat.AbstractStrategy)
+import_from_mixin(rstrategies.SafeIndexingMixin)
+
+def __init__(self, space):
+self.space = space
+
+def strategy_factory(self):
+return self.space.strategy_factory
 
 
 Strategy classes
@@ -144,14 +144,14 @@
 
 ::
 
-@rstrat.strategy(generalize=[GenericStrategy])
-class IntegerOrNilStrategy(AbstractStrategy):
-import_from_mixin(rstrat.TaggingStrategy)
-contained_type = model.W_Integer
-def wrap(self, val): return self.space.wrap_int(val)
-def unwrap(self, w_val): return self.space.unwrap_int(w_val)
-def wrapped_tagged_value(self): return self.space.w_nil
-def unwrapped_tagged_value(self): return constants.MAXINT
+@rstrat.strategy(generalize=[GenericStrategy])
+class IntegerOrNilStrategy(AbstractStrategy):
+import_from_mixin(rstrat.TaggingStrategy)
+contained_type = model.W_Integer
+def wrap(self, val): return self.space.wrap_int(val)
+def unwrap(self, w_val): return self.space.unwrap_int(w_val)
+def wrapped_tagged_value(self): return self.space.w_nil
+def unwrapped_tagged_value(self): return constants.MAXINT
 
 Strategy Factory
 
@@ -188,22 +188,22 @@
 
 ::
 
-class StrategyFactory(rstrategies.StrategyFactory):
-_attrs_ = ['space']
-_immutable_fields_ = ['space']
-
-def __init__(self, space):
-self.space = space
-rstrat.StrategyFactory.__init__(self, AbstractStrategy)
-
-def instantiate_strategy(self, strategy_type):
-return strategy_type(self.space)
-
-def strategy_type_for(self, list_w, weak=False):
-"""
-Helper method for handling weak objects specially
-"""
-if weak:
-return WeakListStrategy
+class StrategyFactory(rstrategies.StrategyFactory):
+_attrs_ = ['space']
+_immutable_fields_ = ['space']
+
+def __init__(self, space):
+self.space = space
+rstrat.StrategyFactory.__init__(self, AbstractStrategy)
+
+def instantiate_strategy(self, strategy_type):
+return strategy_type(self.space)
+
+def strategy_type_for(self, list_w, weak=False):
+"""
+Helper method for handling weak objects specially
+"""
+if weak:
+return WeakListStrategy
 return rstrategies.StrategyFactory.strategy_type_for(self, list_w)
 
\ No newline at end of file
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Merged from pypy/pypy

2015-04-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: 
Changeset: r76877:f26c8203
Date: 2015-03-12 13:11 +0100
http://bitbucket.org/pypy/pypy/changeset/f26c8203/

Log:Merged from pypy/pypy

diff too long, truncating to 2000 out of 13267 lines

diff --git a/lib_pypy/audioop.py b/lib_pypy/audioop.py
--- a/lib_pypy/audioop.py
+++ b/lib_pypy/audioop.py
@@ -480,6 +480,7 @@
 state_d, prev_i, cur_i,
 weightA, weightB)
 result = ffi.buffer(rv)[:trim_index]
+d = state_d[0]
 samps = zip(prev_i, cur_i)
 return (result, (d, tuple(samps)))
 
diff --git a/lib_pypy/cffi.egg-info b/lib_pypy/cffi.egg-info
--- a/lib_pypy/cffi.egg-info
+++ b/lib_pypy/cffi.egg-info
@@ -1,6 +1,6 @@
 Metadata-Version: 1.0
 Name: cffi
-Version: 0.8.6+
+Version: 0.9.1
 Summary: Foreign Function Interface for Python calling C code.
 Home-page: http://cffi.readthedocs.org
 Author: Armin Rigo, Maciej Fijalkowski
diff --git a/lib_pypy/cffi/__init__.py b/lib_pypy/cffi/__init__.py
--- a/lib_pypy/cffi/__init__.py
+++ b/lib_pypy/cffi/__init__.py
@@ -4,8 +4,8 @@
 from .api import FFI, CDefError, FFIError
 from .ffiplatform import VerificationError, VerificationMissing
 
-__version__ = "0.8.6+"
-__version_info__ = (0, 8, 6, "plus")
+__version__ = "0.9.1"
+__version_info__ = (0, 9, 1)
 
 # The verifier module file names are based on the CRC32 of a string that
 # contains the following version number.  It may be older than __version__
diff --git a/lib_pypy/gdbm.py b/lib_pypy/gdbm.py
--- a/lib_pypy/gdbm.py
+++ b/lib_pypy/gdbm.py
@@ -20,9 +20,11 @@
 } datum;
 
 datum gdbm_fetch(void*, datum);
+datum pygdbm_fetch(void*, char*, int);
 int gdbm_delete(void*, datum);
 int gdbm_store(void*, datum, datum, int);
 int gdbm_exists(void*, datum);
+int pygdbm_exists(void*, char*, int);
 
 int gdbm_reorganize(void*);
 
@@ -37,19 +39,29 @@
 ''')
 
 try:
+verify_code = '''
+#include "gdbm.h"
+
+static datum pygdbm_fetch(GDBM_FILE gdbm_file, char *dptr, int dsize) {
+datum key = {dptr, dsize};
+return gdbm_fetch(gdbm_file, key);
+}
+
+static int pygdbm_exists(GDBM_FILE gdbm_file, char *dptr, int dsize) {
+datum key = {dptr, dsize};
+return gdbm_exists(gdbm_file, key);
+}
+
+'''
 if sys.platform.startswith('freebsd'):
 import os.path
 _localbase = os.environ.get('LOCALBASE', '/usr/local')
-lib = ffi.verify('''
-#include "gdbm.h"
-''', libraries=['gdbm'],
+lib = ffi.verify(verify_code, libraries=['gdbm'],
  include_dirs=[os.path.join(_localbase, 'include')],
  library_dirs=[os.path.join(_localbase, 'lib')]
 )
 else:
-lib = ffi.verify('''
-#include "gdbm.h"
-''', libraries=['gdbm'])
+lib = ffi.verify(verify_code, libraries=['gdbm'])
 except cffi.VerificationError as e:
 # distutils does not preserve the actual message,
 # but the verification is simple enough that the
@@ -59,6 +71,13 @@
 class error(Exception):
 pass
 
+def _checkstr(key):
+if isinstance(key, unicode):
+key = key.encode("ascii")
+if not isinstance(key, str):
+raise TypeError("gdbm mappings have string indices only")
+return key
+
 def _fromstr(key):
 if isinstance(key, unicode):
 key = key.encode("ascii")
@@ -107,12 +126,14 @@
 
 def __contains__(self, key):
 self._check_closed()
-return lib.gdbm_exists(self.ll_dbm, _fromstr(key))
+key = _checkstr(key)
+return lib.pygdbm_exists(self.ll_dbm, key, len(key))
 has_key = __contains__
 
 def __getitem__(self, key):
 self._check_closed()
-drec = lib.gdbm_fetch(self.ll_dbm, _fromstr(key))
+key = _checkstr(key)
+drec = lib.pygdbm_fetch(self.ll_dbm, key, len(key))
 if not drec.dptr:
 raise KeyError(key)
 res = str(ffi.buffer(drec.dptr, drec.dsize))
diff --git a/lib_pypy/pyrepl/readline.py b/lib_pypy/pyrepl/readline.py
--- a/lib_pypy/pyrepl/readline.py
+++ b/lib_pypy/pyrepl/readline.py
@@ -73,7 +73,6 @@
 assume_immutable_completions = False
 use_brackets = False
 sort_in_column = True
-tab_insert_spaces_if_stem_is_empty = False
 
 def error(self, msg="none"):
 pass# don't show error messages by default
@@ -87,7 +86,7 @@
 return ''.join(b[p+1:self.pos])
 
 def get_completions(self, stem):
-if len(stem) == 0 and self.tab_insert_spaces_if_stem_is_empty:
+if len(stem) == 0 and self.more_lines is not None:
 b = self.buffer
 p = self.pos
 while p > 0 and b[p - 1] != '\n':
@@ -141,12 +140,16 @@
 
 def collect_keymap(self):
 return super(ReadlineAlikeReader, self).collect_keymap() + (
-(r'\n', 'maybe-accept'),)
+(r'\n', 'maybe-accept'),
+(r'\', 'backspace-dedent'),
+)
 
 def __init__(self, console):
 super(Readlin

[pypy-commit] lang-smalltalk storage: Added some code to the Matrix benchmark.

2014-07-07 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r867:d1dfa8569637
Date: 2014-07-04 10:14 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/d1dfa8569637/

Log:Added some code to the Matrix benchmark.

diff --git a/images/Squeak4.5-noBitBlt.changes 
b/images/Squeak4.5-noBitBlt.changes
--- a/images/Squeak4.5-noBitBlt.changes
+++ b/images/Squeak4.5-noBitBlt.changes
@@ -12208,4 +12208,4 @@
].
 
"self footer."
-   ^ self! !

QUIT{2 April 2014 . 11:59:41 am} Squeak4.5-noBitBlt.image priorSource: 
15812182!

STARTUP{3 July 2014 . 11:14:14 am} as 
C:\Dev\lang-smalltalk\images\Squeak4.5-noBitBlt.image!


SystemOrganization addCategory: #Anton!

Object subclass: #AntonMatrix
instanceVariableNames: 'fields columns rows'
classVariableNames: ''
poolDictionaries: ''
category: 'Anton'!

Object subclass: #AntonMatrix
instanceVariableNames: 'fields columns rows'
classVariableNames: ''
poolDictionaries: ''
category: 'Anton'!
!AntonMatrix methodsFor: 'accessing' stamp: 'ag 7/3/2014 10:17'!
at: point

^ self x: point x y: point y! !
!AntonMatrix methodsFor: 'accessing' stamp: 'ag 7/3/2014 10:16'!
at: point put: number

^ self x: point x y: point y put: number! !
!AntonMatrix methodsFor: 'accessing' stamp: 'ag 7/3/2014 10:12'!
columns

^ columns! !
!AntonMatrix methodsFor: 'accessing' stamp: 'ag 7/3/2014 10:55'!
fieldsDo: block

(1 to: self rows) do: [ :row |
(1 to: self columns) do: [ :column |
block value: row value: column ] ].! !
!AntonMatrix methodsFor: 'accessing' stamp: 'ag 7/3/2014 10:56'!
fill: block

self fieldsDo: [ :x :y |
self x: x y: y put: (block value: x value: y) ].! !
!AntonMatrix methodsFor: 'accessing' stamp: 'ag 7/3/2014 10:12'!
rows

^ rows! !
!AntonMatrix methodsFor: 'accessing' stamp: 'ag 7/3/2014 10:17'!
x: x y: y

^ fields at: (self offsetX: x y: y)! !
!AntonMatrix methodsFor: 'accessing' stamp: 'ag 7/3/2014 10:17'!
x: x y: y put: number

fields at: (self offsetX: x y: y) put: number! !
!AntonMatrix methodsFor: 'private' stamp: 'ag 7/3/2014 10:44'!
offsetX: x y: y

^ (y-1) * columns + x! !
!AntonMatrix methodsFor: 'initialization' stamp: 'ag 7/3/2014 10:43'!
initializeFields: f rows: r 

rows := r.
(f size \\ r) = 0 ifFalse: [ self error: 'Illegal initialization.' ].
columns := f size / r.
fields := f.! !
!AntonMatrix methodsFor: 'initialization' stamp: 'ag 7/3/2014 10:18'!
initializeRows: r columns: c

rows := r.
columns := c.
fields := Array new: rows * columns.! !
!AntonMatrix methodsFor: 'math' stamp: 'ag 7/3/2014 10:30'!
* other

| result |
(self columns = other rows and: [ self rows = other columns ])
ifFalse: [ ^ self error: 'Cannot multiply, wrong dimensions.' ].
result := AntonMatrix rows: self rows columns: other columns.
(1 to: self rows) do: [ :row |
(1 to: other columns) do: [ :column | | value |
value := 0.

(1 to: self columns) do: [ :i |
value := value + ((self x: i y: row) * (other 
x: column y: i)) ].

result x: column y: row put: value ] ].
^ result! !
!AntonMatrix methodsFor: 'printing' stamp: 'ag 7/3/2014 10:47'!
printOn: s

(1 to: self rows) do: [ :row |
(1 to: self columns) do: [ :column |
s nextPutAll: (self x: column y: row) asString.
s nextPutAll: ' ' ].
s nextPutAll: String cr ].! !
!AntonMatrix methodsFor: 'benchmarking' stamp: 'ag 7/3/2014 11:01'!
fillRandomFloats: generator

| max |
max := SmallInteger maxVal sqrt asInteger.
self fill: [ :x :y | max atRandom: generator ].! !
!AntonMatrix methodsFor: 'benchmarking' stamp: 'ag 7/3/2014 11:02'!
fillRandomInts: generator
"Fill with SmallInteger values small enough to stay SmallIntegers after 
multiplication."

self fill: [ :x :y | generator next * 100 ].! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

AntonMatrix class
instanceVariableNames: ''!
!AntonMatrix class methodsFor: 'benchmarking' stamp: 'ag 7/3/2014 11:13'!
benchFloats: numOfRuns multiplicationsPerRun: mults rows: r columns: c

| generator |
generator := Random seed: 23456432.
numOfRuns timesRepeat: [ | a b |
a := AntonMatrix rows: r columns: c.
b := AntonMatrix rows: r columns: c.
a fillRandomFloats: generator.
b fillRandomFloats: generator.
mults timesRepeat: [ a * b ] ].! 

[pypy-commit] lang-smalltalk storage: Renamed variable/parameter.

2014-07-07 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r852:35d8fe62d2aa
Date: 2014-05-28 15:08 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/35d8fe62d2aa/

Log:Renamed variable/parameter.

diff --git a/spyvm/storage_statistics.py b/spyvm/storage_statistics.py
--- a/spyvm/storage_statistics.py
+++ b/spyvm/storage_statistics.py
@@ -49,7 +49,7 @@
 
 class StatisticsModule(object):
 uses_classname = False
-def storage_operation(self, operation_key, storage_size, 
element_classname):
+def storage_operation(self, operation_key, storage_size, 
container_classname):
 raise NotImplementedError("Abstract class")
 def print_results(self):
 raise NotImplementedError("Abstract class")
@@ -61,12 +61,12 @@
 
 class StatisticsLogger(StatisticsModule):
 uses_classname = True
-def storage_operation(self, operation_key, storage_size, 
element_classname):
-print self.log_string(operation_key, storage_size, element_classname)
+def storage_operation(self, operation_key, storage_size, 
container_classname):
+print self.log_string(operation_key, storage_size, container_classname)
 
-def log_string(self, operation_key, storage_size, element_classname):
-if element_classname:
-return "%s of %s size %d" % (self.key_string(operation_key), 
element_classname, storage_size)
+def log_string(self, operation_key, storage_size, container_classname):
+if container_classname:
+return "%s of %s size %d" % (self.key_string(operation_key), 
container_classname, storage_size)
 else:
 return "%s size %d" % (self.key_string(operation_key), 
storage_size)
 
@@ -79,7 +79,7 @@
 def __init__(self):
 self.stats = {}
 
-def storage_operation(self, operation_key, storage_size, 
element_classname):
+def storage_operation(self, operation_key, storage_size, 
container_classname):
 if not operation_key in self.stats:
 self.stats[operation_key] = self.initial_value()
 self.increment_value(self.stats[operation_key], storage_size)
@@ -112,8 +112,8 @@
 self.outgoing_operations = {}
 self.outgoing_elements = {}
 
-def storage_operation(self, key, storage_size, element_classname):
-StatisticsCollector.storage_operation(self, key, storage_size, 
element_classname)
+def storage_operation(self, key, storage_size, container_classname):
+StatisticsCollector.storage_operation(self, key, storage_size, 
container_classname)
 source_type = key[1]
 target_type = key[2]
 self.fill_maps(self.incoming_operations, self.incoming_elements, 
target_type, storage_size)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Using 4 bytes to encode object size due to large objects in Squeak image.

2014-07-07 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r860:a5b744a0ec04
Date: 2014-07-01 17:21 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/a5b744a0ec04/

Log:Using 4 bytes to encode object size due to large objects in Squeak
image.

diff --git a/spyvm/storage_logger.py b/spyvm/storage_logger.py
--- a/spyvm/storage_logger.py
+++ b/spyvm/storage_logger.py
@@ -71,19 +71,26 @@
 assert new_storage in storage_map, "Cannot handle new-storage type %s" % 
new_storage
 bytes.append(storage_map[new_storage])
 
-# Next: 2 bytes encoding object size (big endian)
-assert size < 2**16, "Object of type %s too large (size %d)" % (classname, 
size)
+# Next: 4 bytes encoding object size (big endian)
+# Assert not compiling in RPython
+# assert size < 2**32, "Object of type %s too large (size %d)" % 
(classname, size)
 mask = (1<<8)-1
-bytes.append(size & mask)
+shift = 0
+bytes.append((size & mask) >> shift)
 mask = mask<<8
-bytes.append((size & mask) >> 8)
+shift += 8
+bytes.append((size & mask) >> shift)
+mask = mask<<8
+shift += 8
+bytes.append((size & mask) >> shift)
+mask = mask<<8
+shift += 8
+bytes.append((size & mask) >> shift)
 
 # Next: classname string plus terminating null-character
-i = 5
 if classname:
 for c in classname:
 bytes.append(ord(c))
-i += 1
 bytes.append(0)
 
 # No simpler way for RPython's sake.
diff --git a/spyvm/tool/storagelog_parser.py b/spyvm/tool/storagelog_parser.py
--- a/spyvm/tool/storagelog_parser.py
+++ b/spyvm/tool/storagelog_parser.py
@@ -57,9 +57,9 @@
 old_storage = storage_map[old_storage_byte]
 new_storage = storage_map[new_storage_byte]
 
-# Next 2 bytes: object size (big endian)
-size_bytes = file.read(2)
-size = int(ord(size_bytes[0]) + (ord(size_bytes[1])<<8))
+# Next 4 bytes: object size (big endian)
+size_bytes = file.read(4)
+size = int(ord(size_bytes[0]) + (ord(size_bytes[1])<<8) + 
(ord(size_bytes[2])<<16) + (ord(size_bytes[3])<<24))
 
 # Last: classname, nul-terminated
 classname = ""
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Changed perform/create_toplevel_context methods of interpreter to work better with RPython.

2014-07-10 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r874:01a714785a05
Date: 2014-07-07 17:35 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/01a714785a05/

Log:Changed perform/create_toplevel_context methods of interpreter to
work better with RPython.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -211,20 +211,18 @@
 except ReturnFromTopLevel, e:
 return e.object
 
-def perform(self, w_receiver, selector, *w_arguments):
-s_frame = self.create_toplevel_context(w_receiver, selector, 
*w_arguments)
+def perform(self, w_receiver, selector="", w_selector=None, 
w_arguments=[]):
+s_frame = self.create_toplevel_context(w_receiver, selector, 
w_selector, w_arguments)
 self.interrupt_check_counter = self.interrupt_counter_size
 return self.interpret_toplevel(s_frame.w_self())
 
-def create_toplevel_context(self, w_receiver, selector, *w_arguments):
-if isinstance(selector, str):
+def create_toplevel_context(self, w_receiver, selector="", 
w_selector=None, w_arguments=[]):
+if w_selector is None:
+assert selector, "Need either string or W_Object selector"
 if selector == "asSymbol":
 w_selector = self.image.w_asSymbol
 else:
-w_selector = self.perform(self.space.wrap_string(selector),
-"asSymbol")
-else:
-w_selector = selector
+w_selector = self.perform(self.space.wrap_string(selector), 
"asSymbol")
 
 w_method = model.W_CompiledMethod(self.space, header=512)
 w_method.literalatput0(self.space, 1, w_selector)
diff --git a/spyvm/test/jit.py b/spyvm/test/jit.py
--- a/spyvm/test/jit.py
+++ b/spyvm/test/jit.py
@@ -36,7 +36,7 @@
 def preload_perform(imagename, receiver, selector, *args):
 interp = load(imagename)
 def interp_miniloop():
-return interp.perform(receiver, selector, *args)
+return interp.perform(receiver, selector, w_arguments=list(args))
 return interp_miniloop
 
 # This will build a jit executing a synthetic method composed of the given 
bytecodes and literals,
diff --git a/spyvm/test/test_largeinteger.py b/spyvm/test/test_largeinteger.py
--- a/spyvm/test/test_largeinteger.py
+++ b/spyvm/test/test_largeinteger.py
@@ -7,7 +7,6 @@
 def setup_module():
 space, interp, _, _ = read_image('bootstrapped.image')
 w = space.w
-perform = interp.perform
 copy_to_module(locals(), __name__)
 interp.trace = False
 space.initialize_class(space.w_String, interp)
diff --git a/spyvm/test/test_miniimage.py b/spyvm/test/test_miniimage.py
--- a/spyvm/test/test_miniimage.py
+++ b/spyvm/test/test_miniimage.py
@@ -5,7 +5,10 @@
 def setup_module():
 space, interp, image, reader = read_image("mini.image")
 w = space.w
-perform = interp.perform
+def perform_wrapper(receiver, selector, *args):
+w_selector = None if isinstance(selector, str) else selector
+return interp.perform(receiver, selector, w_selector, list(args))
+perform = perform_wrapper
 copy_to_module(locals(), __name__)
 
 def teardown_module():
@@ -191,7 +194,7 @@
 w_abs = interp.perform(interp.space.w("abs"), "asSymbol")
 for value in [10, -3, 0]:
 w_object = model.W_SmallInteger(value)
-w_res = interp.perform(w_object, w_abs)
+w_res = interp.perform(w_object, w_selector=w_abs)
 assert w_res.value == abs(value)
 
 def test_lookup_abs_in_integer():
diff --git a/spyvm/test/util.py b/spyvm/test/util.py
--- a/spyvm/test/util.py
+++ b/spyvm/test/util.py
@@ -266,5 +266,5 @@
 def initialize_class(self, w_class, interp):
 initialize_symbol = find_symbol_in_methoddict_of("initialize", 
 w_class.class_shadow(self))
-interp.perform(w_class, initialize_symbol)
+interp.perform(w_class, w_selector=initialize_symbol)
 
\ No newline at end of file
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Added a suppress_process_switch flag as a hack to enable the -r flag in the Squeak image.

2014-07-10 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r876:f77d391e1255
Date: 2014-07-07 18:46 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/f77d391e1255/

Log:Added a suppress_process_switch flag as a hack to enable the -r flag
in the Squeak image.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -86,6 +86,7 @@
 s_new_context = s_sender
 s_new_context.push(nlr.value)
 except ProcessSwitch, p:
+assert not self.space.suppress_process_switch, "ProcessSwitch 
should be disabled..."
 if self.trace:
 print "== Switched process from: %s" % 
s_new_context.short_str()
 print "== to: %s " % p.s_new_context.short_str()
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -21,6 +21,9 @@
 
 self.make_bootstrap_classes()
 self.make_bootstrap_objects()
+
+# This is a hack; see compile_code() in targetimageloadingsmalltalk.py
+self.suppress_process_switch = False
 
 def find_executable(self, executable):
 if os.sep in executable or (os.name == "nt" and ":" in executable):
diff --git a/spyvm/wrapper.py b/spyvm/wrapper.py
--- a/spyvm/wrapper.py
+++ b/spyvm/wrapper.py
@@ -93,8 +93,9 @@
 active_priority = active_process.priority()
 priority = self.priority()
 if priority > active_priority:
-active_process.deactivate(s_current_frame)
-self.activate()
+if not self.space.suppress_process_switch:
+active_process.deactivate(s_current_frame)
+self.activate()
 else:
 self.put_to_sleep()
 
@@ -103,10 +104,11 @@
 
 def suspend(self, s_current_frame):
 if self.is_active_process():
-assert self.my_list().is_nil(self.space)
-w_process = scheduler(self.space).pop_highest_priority_process()
-self.deactivate(s_current_frame, put_to_sleep=False)
-ProcessWrapper(self.space, w_process).activate()
+if not self.space.suppress_process_switch:
+assert self.my_list().is_nil(self.space)
+w_process = 
scheduler(self.space).pop_highest_priority_process()
+self.deactivate(s_current_frame, put_to_sleep=False)
+ProcessWrapper(self.space, w_process).activate()
 else:
 if not self.my_list().is_nil(self.space):
 process_list = ProcessListWrapper(self.space, self.my_list())
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -172,13 +172,22 @@
 space = interp.space
 w_receiver_class = w_receiver.getclass(space)
 try:
-w_result = interp.perform(
-w_receiver_class,
-"compile:classified:notifying:",
-w_arguments = [space.wrap_string("%s\r\n%s" % (selector, code)),
-space.wrap_string("spy-run-code"),
-space.w_nil]
-)
+try:
+# The suppress_process_switch flag is a hack/workaround to enable 
compiling code
+# before having initialized the image cleanly. The problem is that 
the TimingSemaphore is not yet
+# registered (primitive 136 not called), so the idle process will 
never be left once it is entered.
+# TODO - Find a way to cleanly initialize the image, without 
executing the active_context of the image.
+# Instead, we want to execute our own context. Then remove this 
flag (and all references to it)
+interp.space.suppress_process_switch = True
+w_result = interp.perform(
+w_receiver_class,
+"compile:classified:notifying:",
+w_arguments = [space.wrap_string("%s\r\n%s" % (selector, 
code)),
+space.wrap_string("spy-run-code"),
+space.w_nil]
+)
+finally:
+interp.space.suppress_process_switch = False
 # TODO - is this expected in every image?
 if not isinstance(w_result, model.W_BytesObject) or 
w_result.as_string() != selector:
 print "Compilation failed, unexpected result: %s" % 
result_string(w_result)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Removed forgotten pdb breakpoints.

2014-07-10 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r873:d033d87d9e19
Date: 2014-07-07 17:33 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/d033d87d9e19/

Log:Removed forgotten pdb breakpoints.

diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -1385,13 +1385,11 @@
 
 @expose_primitive(RESUME, unwrap_spec=[object], no_result=True, 
clean_stack=False)
 def func(interp, s_frame, w_rcvr):
-import pdb; pdb.set_trace()
 assert_class(interp, w_rcvr, interp.space.w_Process)
 wrapper.ProcessWrapper(interp.space, w_rcvr).resume(s_frame)
 
 @expose_primitive(SUSPEND, unwrap_spec=[object], no_result=True, 
clean_stack=False)
 def func(interp, s_frame, w_rcvr):
-import pdb; pdb.set_trace()
 assert_class(interp, w_rcvr, interp.space.w_Process)
 wrapper.ProcessWrapper(interp.space, w_rcvr).suspend(s_frame)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Removed virtual reference of sender. Was causing performance problems.

2014-07-10 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r880:4934d77ae183
Date: 2014-07-10 12:38 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/4934d77ae183/

Log:Removed virtual reference of sender. Was causing performance
problems. Going to add this refactoring to the vref branch.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -67,10 +67,7 @@
 s_new_context = w_active_context.as_context_get_shadow(self.space)
 while True:
 assert self.current_stack_depth == 0
-# Need to save s_sender, loop_bytecodes will nil this on return
-# Virtual references are not allowed here, and neither are "fresh" 
contexts (except for the toplevel one).
-assert s_new_context.virtual_sender is jit.vref_None
-s_sender = s_new_context.direct_sender
+s_sender = s_new_context.s_sender()
 try:
 self.loop_bytecodes(s_new_context)
 raise Exception("loop_bytecodes left without raising...")
@@ -81,7 +78,7 @@
 except Return, nlr:
 s_new_context = s_sender
 while s_new_context is not nlr.s_target_context:
-s_sender = s_new_context.direct_sender
+s_sender = s_new_context.s_sender()
 s_new_context._activate_unwind_context(self)
 s_new_context = s_sender
 s_new_context.push(nlr.value)
@@ -122,27 +119,19 @@
 # This is a wrapper around loop_bytecodes that cleanly enters/leaves the 
frame
 # and handles the stack overflow protection mechanism.
 def stack_frame(self, s_frame, s_sender, may_context_switch=True):
-assert s_frame.virtual_sender is jit.vref_None
 try:
-# Enter the context - store a virtual reference back to the sender
-# Non-fresh contexts can happen, e.g. when activating a stored 
BlockContext.
-# The same frame object must not pass through here recursively!
-if s_frame.is_fresh() and s_sender is not None:
-s_frame.virtual_sender = jit.virtual_ref(s_sender)
-
+if s_frame._s_sender is None and s_sender is not None:
+s_frame.store_s_sender(s_sender, raise_error=False)
+
 self.current_stack_depth += 1
 if self.max_stack_depth > 0:
 if self.current_stack_depth >= self.max_stack_depth:
 raise StackOverflow(s_frame)
-
+
 # Now (continue to) execute the context bytecodes
 self.loop_bytecodes(s_frame, may_context_switch)
 finally:
 self.current_stack_depth -= 1
-# Cleanly leave the context. This will finish the virtual 
sender-reference, if
-# it is still there, which can happen in case of ProcessSwitch or 
StackOverflow;
-# in case of a Return, this will already be handled while 
unwinding the stack.
-s_frame.finish_virtual_sender(s_sender)
 
 def step(self, context):
 bytecode = context.fetch_next_bytecode()
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -607,13 +607,13 @@
 class ContextPartShadow(AbstractRedirectingShadow):
 
 __metaclass__ = extendabletype
-_attrs_ = ['direct_sender', 'virtual_sender',
+_attrs_ = ['_s_sender',
 '_pc', '_temps_and_stack',
 '_stack_ptr', 'instances_w']
 repr_classname = "ContextPartShadow"
 
 _virtualizable_ = [
-'direct_sender', 'virtual_sender',
+'_s_sender',
 "_pc", "_temps_and_stack[*]", "_stack_ptr",
 "_w_self", "_w_self_size"
 ]
@@ -622,8 +622,7 @@
 # Initialization
 
 def __init__(self, space, w_self):
-self.direct_sender = None
-self.virtual_sender = jit.vref_None
+self._s_sender = None
 AbstractRedirectingShadow.__init__(self, space, w_self)
 self.instances_w = {}
 
@@ -692,27 +691,9 @@
 raise error.WrapperException("Index in context out of bounds")
 
 # === Sender ===
-# There are two fields for the sender (virtual and direct). Only one of 
them is can be set at a time.
-# As long as the frame object is virtualized, using the virtual reference 
should increase performance.
-# As soon as a frame object is forced to the heap, the direct reference 
must be used.
-
-def is_fresh(self):
-return self.direct_sender is None and self.virtual_sender is 
jit.vref_None
-
-def finish_virtual_sender(self, s_sender):
-if self.virtual_sender is not jit.vref_None:
-if self.pc() != -1:
-# stack is unrolling, but this frame was not
-# marked_returned: it is an escaped frame
-sender = self.virtual_sender()
-self.direct_sender = sender
-jit.virtual_ref_fin

[pypy-commit] lang-smalltalk storage: Fixed the suppress_process_switch hack, using an array to store the flag, making it modifiable.

2014-07-10 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r877:307b424d7195
Date: 2014-07-09 13:59 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/307b424d7195/

Log:Fixed the suppress_process_switch hack, using an array to store the
flag, making it modifiable.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -86,7 +86,7 @@
 s_new_context = s_sender
 s_new_context.push(nlr.value)
 except ProcessSwitch, p:
-assert not self.space.suppress_process_switch, "ProcessSwitch 
should be disabled..."
+assert not self.space.suppress_process_switch[0], 
"ProcessSwitch should be disabled..."
 if self.trace:
 print "== Switched process from: %s" % 
s_new_context.short_str()
 print "== to: %s " % p.s_new_context.short_str()
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -23,7 +23,7 @@
 self.make_bootstrap_objects()
 
 # This is a hack; see compile_code() in targetimageloadingsmalltalk.py
-self.suppress_process_switch = False
+self.suppress_process_switch = [False]
 
 def find_executable(self, executable):
 if os.sep in executable or (os.name == "nt" and ":" in executable):
diff --git a/spyvm/wrapper.py b/spyvm/wrapper.py
--- a/spyvm/wrapper.py
+++ b/spyvm/wrapper.py
@@ -93,7 +93,7 @@
 active_priority = active_process.priority()
 priority = self.priority()
 if priority > active_priority:
-if not self.space.suppress_process_switch:
+if not self.space.suppress_process_switch[0]:
 active_process.deactivate(s_current_frame)
 self.activate()
 else:
@@ -104,7 +104,7 @@
 
 def suspend(self, s_current_frame):
 if self.is_active_process():
-if not self.space.suppress_process_switch:
+if not self.space.suppress_process_switch[0]:
 assert self.my_list().is_nil(self.space)
 w_process = 
scheduler(self.space).pop_highest_priority_process()
 self.deactivate(s_current_frame, put_to_sleep=False)
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -178,7 +178,7 @@
 # registered (primitive 136 not called), so the idle process will 
never be left once it is entered.
 # TODO - Find a way to cleanly initialize the image, without 
executing the active_context of the image.
 # Instead, we want to execute our own context. Then remove this 
flag (and all references to it)
-interp.space.suppress_process_switch = True
+interp.space.suppress_process_switch[0] = True
 w_result = interp.perform(
 w_receiver_class,
 "compile:classified:notifying:",
@@ -187,7 +187,7 @@
 space.w_nil]
 )
 finally:
-interp.space.suppress_process_switch = False
+interp.space.suppress_process_switch[0] = False
 # TODO - is this expected in every image?
 if not isinstance(w_result, model.W_BytesObject) or 
w_result.as_string() != selector:
 print "Compilation failed, unexpected result: %s" % 
result_string(w_result)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Refactored command line flags a little to be more precise and give more controll over what happens.

2014-07-10 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r875:f9f21debba52
Date: 2014-07-07 17:36 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/f9f21debba52/

Log:Refactored command line flags a little to be more precise and give
more controll over what happens. Added descriptions to the usage-
string.

diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -10,201 +10,114 @@
 from spyvm.tool.analyseimage import create_image
 from spyvm.interpreter_proxy import VirtualMachine
 
-def print_result(w_result):
-# This will also print contents of strings/symbols/numbers
-print w_result.as_repr_string().replace('\r', '\n')
-
-def _run_benchmark(interp, number, benchmark, arg):
-from spyvm.plugins.vmdebugging import stop_ui_process
-stop_ui_process()
-
-space = interp.space
-scheduler = wrapper.scheduler(space)
-w_hpp = scheduler.active_process()
-if space.unwrap_int(scheduler.active_process().fetch(space, 2)) > 
space.unwrap_int(w_hpp.fetch(space, 2)):
-w_hpp = scheduler.active_process()
-assert isinstance(w_hpp, model.W_PointersObject)
-w_benchmark_proc = model.W_PointersObject(
-space,
-w_hpp.getclass(space),
-w_hpp.size()
-)
-
-s_frame = context_for(interp, number, benchmark, arg)
-# second variable is suspended context
-w_benchmark_proc.store(space, 1, s_frame.w_self())
-
-# third variable is priority
-priority = space.unwrap_int(w_hpp.fetch(space, 2)) / 2 + 1
-# Priorities below 10 are not allowed in newer versions of Squeak.
-if interp.image.version.has_closures:
-priority = max(11, priority)
-else:
-priority = 7
-w_benchmark_proc.store(space, 2, space.wrap_int(priority))
-
-# make process eligible for scheduling
-wrapper.ProcessWrapper(space, w_benchmark_proc).put_to_sleep()
-
-t1 = time.time()
-w_result = _run_image(interp)
-t2 = time.time()
-if w_result:
-print_result(w_result)
-print "took %s seconds" % (t2 - t1)
-return 0
-return -1
-
-def _run_image(interp):
-space = interp.space
-ap = wrapper.ProcessWrapper(space, 
wrapper.scheduler(space).active_process())
-w_ctx = ap.suspended_context()
-assert isinstance(w_ctx, model.W_PointersObject)
-ap.store_suspended_context(space.w_nil)
-try:
-return interp.interpret_toplevel(w_ctx)
-except error.Exit, e:
-print e.msg
-
-def _run_code(interp, code, as_benchmark=False):
-import time
-selector = "DoIt%d" % int(time.time())
-space = interp.space
-w_receiver = space.w_nil
-w_receiver_class = w_receiver.getclass(space)
-try:
-w_result = interp.perform(
-w_receiver_class,
-"compile:classified:notifying:",
-space.wrap_string("%s\r\n%s" % (selector, code)),
-space.wrap_string("spy-run-code"),
-space.w_nil
-)
-
w_receiver_class.as_class_get_shadow(space).s_methoddict().sync_method_cache()
-except interpreter.ReturnFromTopLevel, e:
-print e.object
-return 1
-except error.Exit, e:
-print e.msg
-return 1
-
-if not as_benchmark:
-try:
-w_result = interp.perform(w_receiver, selector)
-except interpreter.ReturnFromTopLevel, e:
-print e.object
-return 1
-except error.Exit, e:
-print e.msg
-return 1
-if w_result:
-print_result(w_result)
-return 0
-else:
-return _run_benchmark(interp, 0, selector, "")
-
-def context_for(interp, number, benchmark, stringarg):
-w_receiver = interp.space.wrap_int(number)
-if stringarg:
-return interp.create_toplevel_context(w_receiver, benchmark, 
interp.space.wrap_string(stringarg))
-else:
-return interp.create_toplevel_context(w_receiver, benchmark)
-
 def _usage(argv):
 print """
-Usage: %s
-  -j|--jit [jitargs]
-  -n|--number [smallint, default: 0]
-  -m|--method [benchmark on smallint]
-  -a|--arg [string argument to #method]
-  -r|--run [code string]
-  -b|--benchmark [code string]
-  -p|--poll_events
-  -ni|--no-interrupts
-  -d|--max-stack-depth [number, default %d, <= 0 disables stack 
protection]
-  -l|--storage-log
-  -L|--storage-log-aggregate
-  -E|--storage-log-elements
-  [image path, default: Squeak.image]
+Usage: %s  [-r|-m] [-naH] [-jpis] [-tlLE]
+ - image path (default: Squeak.image)
+  
+  Execution mode:
+(no flags) - Image will be normally opened.
+-r|--run - Code will be compiled and executed, 
result printed.
+-m|--method  - Selector will be sent to a SmallInteger, 
result printed.
+

[pypy-commit] lang-smalltalk storage: Fixed console output when executing an entire image.

2014-07-10 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r881:54246f8c1106
Date: 2014-07-10 12:41 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/54246f8c1106/

Log:Fixed console output when executing an entire image.

diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -163,6 +163,8 @@
 
 def result_string(w_result):
 # This will also print contents of strings/symbols/numbers
+if not w_result:
+return ""
 return w_result.as_repr_string().replace('\r', '\n')
 
 def compile_code(interp, w_receiver, code):
@@ -232,6 +234,7 @@
 return w_active_context.as_context_get_shadow(space)
 
 def execute_context(interp, s_frame, measure=False):
+print "" # Line break after image-loading-indicator characters
 try:
 return interp.interpret_toplevel(s_frame.w_self())
 except error.Exit, e:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Merged

2014-07-10 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r878:656c751d8f58
Date: 2014-07-09 17:13 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/656c751d8f58/

Log:Merged

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -26,7 +26,7 @@
 _immutable_fields_ = ["space", "image", "image_name",
   "max_stack_depth", "interrupt_counter_size",
   "startup_time", "evented", "interrupts"]
-
+
 jit_driver = jit.JitDriver(
 greens=['pc', 'self', 'method'],
 reds=['s_context'],
@@ -38,7 +38,7 @@
 trace=False, evented=True, interrupts=True,
 max_stack_depth=constants.MAX_LOOP_DEPTH):
 import time
-
+
 # === Initialize immutable variables
 self.space = space
 self.image = image
@@ -54,7 +54,7 @@
 self.interrupt_counter_size = int(os.environ["SPY_ICS"])
 except KeyError:
 self.interrupt_counter_size = constants.INTERRUPT_COUNTER_SIZE
-
+
 # === Initialize mutable variables
 self.interrupt_check_counter = self.interrupt_counter_size
 self.current_stack_depth = 0
@@ -91,7 +91,7 @@
 print "== Switched process from: %s" % 
s_new_context.short_str()
 print "== to: %s " % p.s_new_context.short_str()
 s_new_context = p.s_new_context
-
+
 def loop_bytecodes(self, s_context, may_context_switch=True):
 old_pc = 0
 if not jit.we_are_jitted() and may_context_switch:
@@ -118,7 +118,7 @@
 raise nlr
 else:
 s_context.push(nlr.value)
-
+
 # This is a wrapper around loop_bytecodes that cleanly enters/leaves the 
frame
 # and handles the stack overflow protection mechanism.
 def stack_frame(self, s_frame, s_sender, may_context_switch=True):
@@ -127,14 +127,14 @@
 # Enter the context - store a virtual reference back to the sender
 # Non-fresh contexts can happen, e.g. when activating a stored 
BlockContext.
 # The same frame object must not pass through here recursively!
-if s_frame.is_fresh():
+if s_frame.is_fresh() and s_sender is not None:
 s_frame.virtual_sender = jit.virtual_ref(s_sender)
-
+
 self.current_stack_depth += 1
 if self.max_stack_depth > 0:
 if self.current_stack_depth >= self.max_stack_depth:
 raise StackOverflow(s_frame)
-
+
 # Now (continue to) execute the context bytecodes
 self.loop_bytecodes(s_frame, may_context_switch)
 finally:
@@ -142,8 +142,8 @@
 # Cleanly leave the context. This will finish the virtual 
sender-reference, if
 # it is still there, which can happen in case of ProcessSwitch or 
StackOverflow;
 # in case of a Return, this will already be handled while 
unwinding the stack.
-s_frame.finish_virtual_sender()
-
+s_frame.finish_virtual_sender(s_sender)
+
 def step(self, context):
 bytecode = context.fetch_next_bytecode()
 for entry in UNROLLING_BYTECODE_RANGES:
@@ -156,9 +156,9 @@
 if start <= bytecode <= stop:
 return getattr(context, methname)(self, bytecode)
 assert 0, "unreachable"
-
+
 # == Methods for handling user interrupts ==
-
+
 def jitted_check_for_interrupt(self, s_frame):
 if not self.interrupts:
 return
@@ -169,7 +169,7 @@
 decr_by = int(trace_length // 100)
 decr_by = max(decr_by, 1)
 self.quick_check_for_interrupt(s_frame, decr_by)
-
+
 def quick_check_for_interrupt(self, s_frame, dec=1):
 if not self.interrupts:
 return
@@ -205,7 +205,7 @@
 return intmask(int((time.time() - self.startup_time) * 1000) & 
constants.TAGGED_MASK)
 
 # == Convenience methods for executing code ==
-
+
 def interpret_toplevel(self, w_frame):
 try:
 self.loop(w_frame)
@@ -234,7 +234,7 @@
 s_frame.push(w_receiver)
 s_frame.push_all(list(w_arguments))
 return s_frame
-
+
 def padding(self, symbol=' '):
 return symbol * self.current_stack_depth
 
@@ -264,11 +264,26 @@
 class ProcessSwitch(ContextSwitchException):
 """This causes the interpreter to switch the executed context."""
 
+
+import rpython.rlib.unroll
+if hasattr(unroll, "unrolling_zero"):
+unrolling_zero = unroll.unrolling_zero
+else:
+class unrolling_int(int, unroll.SpecTag):
+def __add__(self, other):
+return unrolling_int(int.__add__(self, other))
+__radd__ = __add__
+def __sub__(self, other):
+return unrolling_int(int.__sub__(s

[pypy-commit] lang-smalltalk storage: Enabled headless mode by default, to behave like the original flags.

2014-07-10 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r879:cf03ec7872eb
Date: 2014-07-10 11:46 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/cf03ec7872eb/

Log:Enabled headless mode by default, to behave like the original flags.

diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -12,7 +12,7 @@
 
 def _usage(argv):
 print """
-Usage: %s  [-r|-m] [-naH] [-jpis] [-tlLE]
+Usage: %s  [-r|-m] [-naHu] [-jpis] [-tlLE]
  - image path (default: Squeak.image)
   
   Execution mode:
@@ -24,13 +24,12 @@
   Execution parameters:
 -n|--num  - Only with -m or -r, SmallInteger to be used as 
receiver (default: nil).
 -a|--arg  - Only with -m, will be used as single String 
argument.
--H|--headless  - Only with -m or -r, run in headless mode.
- Execute the context directly, ignoring the active 
context in the image.
- The execution will 'hijack' the active process.
- Image window will probably not open. Good for 
benchmarking.
- By default, a high-priority process will be 
created for the context, then the image
- will be started normally.
--u - Only with -m or -r, try to stop UI-process at 
startup. Can help with -H.
+-P|--process   - Only with -m or -r, create a high-priority 
Process for the context.
+ The images last active Process will be started 
first.
+ By default, run in headless mode. This will 
ignore the active process
+ in the image and execute the context directly. 
The image window will
+ probably not open. Good for benchmarking.
+-u - Only with -m or -r, try to stop UI-process at 
startup. Can help benchmarking.
 
   Other parameters:
 -j|--jit  - jitargs will be passed to the jit 
configuration.
@@ -62,7 +61,7 @@
 number = 0
 have_number = False
 stringarg = None
-headless = False
+headless = True
 # == Other parameters
 poll = False
 interrupts = True
@@ -100,8 +99,8 @@
 elif arg in ["-s"]:
 arg, idx = get_parameter(argv, idx, arg)
 max_stack_depth = int(arg)
-elif arg in ["-H", "--headless"]:
-headless = True
+elif arg in ["-P", "--process"]:
+headless = False
 elif arg in ["-u"]:
 from spyvm.plugins.vmdebugging import stop_ui_process
 stop_ui_process()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Fixed error-reporting and other outputs after parsing arguments.

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r898:3146c682cb30
Date: 2014-07-10 16:39 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/3146c682cb30/

Log:Fixed error-reporting and other outputs after parsing arguments.
Added flag to disable specialized storage strategies.

diff --git a/spyvm/display.py b/spyvm/display.py
--- a/spyvm/display.py
+++ b/spyvm/display.py
@@ -229,7 +229,7 @@
 return
 elif c_type == RSDL.QUIT:
 from spyvm.error import Exit
-raise Exit("Window closed..")
+raise Exit("Window closed")
 finally:
 lltype.free(event, flavor='raw')
 
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -8,6 +8,10 @@
 
 class ObjSpace(object):
 def __init__(self):
+# If this is True, then no optimizing storage strategies will be used.
+# Intended for performance comparisons. Breaks tests.
+self.no_specialized_storage = [False]
+
 self.classtable = {}
 self.objtable = {}
 self._executable_path = [""] # XXX: we cannot set the attribute
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -374,7 +374,6 @@
 
 @expose_primitive(FAIL)
 def func(interp, s_frame, argcount):
-from spyvm.error import Exit
 if s_frame.w_method().lookup_selector == 'doesNotUnderstand:':
 print ''
 print s_frame.print_stack()
@@ -837,7 +836,7 @@
 @expose_primitive(QUIT, unwrap_spec=[object])
 def func(interp, s_frame, w_rcvr):
 from spyvm.error import Exit
-raise Exit('Quit-Primitive called..')
+raise Exit('Quit-Primitive called')
 
 @expose_primitive(EXIT_TO_DEBUGGER, unwrap_spec=[object])
 def func(interp, s_frame, w_rcvr):
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -8,10 +8,6 @@
 from rpython.rlib.rstruct.runpack import runpack
 from rpython.rtyper.lltypesystem import rffi, lltype
 
-# If this is True, then no optimizing storage strategies will be used.
-# Intended for performance comparisons. Breaks tests.
-no_specialized_storage = False
-
 class AbstractShadow(object):
 """A shadow is an optional extra bit of information that
 can be attached at run-time to any Smalltalk object.
@@ -170,14 +166,14 @@
 def empty_storage(space, w_self, size, weak=False):
 if weak:
 return WeakListStorageShadow(space, w_self, size)
-if no_specialized_storage:
+if space.no_specialized_storage[0]:
 return ListStorageShadow(space, w_self, size)
 return AllNilStorageShadow(space, w_self, size)
 
 def find_storage_for_objects(space, vars, weak=False):
 if weak:
 return WeakListStorageShadow
-if no_specialized_storage:
+if space.no_specialized_storage[0]:
 return ListStorageShadow
 specialized_strategies = 3
 all_nil_can_handle = True
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -38,6 +38,7 @@
 -s- After num stack frames, the entire stack will 
be dumped to the heap.
  This breaks performance, but protects agains 
stack overflow.
  num <= 0 disables stack protection (default: 
%d)
+-S - Disable specialized storage strategies; 
always use generic ListStorage
 
   Logging parameters:
 -t|--trace - Output a trace of each message, 
primitive, return value and process switch.
@@ -49,13 +50,25 @@
 
 def get_parameter(argv, idx, arg):
 if len(argv) < idx + 1:
-raise RuntimeError("Error: missing argument after %s" % arg)
+raise error.Exit("Missing argument after %s" % arg)
 return argv[idx], idx + 1
 
+def get_int_parameter(argv, idx, arg):
+param, idx = get_parameter(argv, idx, arg)
+try:
+result = int(param)
+except ValueError, e:
+raise error.Exit("Non-int argument after %s" % arg)
+return result, idx
+
+def print_error(str):
+os.write(2, str + os.linesep)
+
 prebuilt_space = objspace.ObjSpace()
 
 def entry_point(argv):
 # == Main execution parameters
+path = None
 selector = None
 code = ""
 number = 0
@@ -68,54 +81,61 @@
 max_stack_depth = constants.MAX_LOOP_DEPTH
 trace = False
 
-path = argv[1] if len(argv) > 1 else "Squeak.image"
-idx = 2
-
-while idx < len(argv):
-arg = argv[idx]
-idx += 1
-if arg in ["-h", "--help"]:
-_usage(argv)
-return 0
-elif arg in ["-j", "--jit"]:
-jitarg, idx = get_parameter(argv, idx, arg)
-jit.set_user_param(interpreter.Interpreter.jit_driver, jitarg)
-elif arg in ["-n", "--number"]:
-

[pypy-commit] lang-smalltalk storage: Added a stack_deth mechanism, but only if interp.trace is set.

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r902:4c9262d36e3b
Date: 2014-07-13 15:55 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/4c9262d36e3b/

Log:Added a stack_deth mechanism, but only if interp.trace is set. Added
a ConstantFlag class to make CLI flags (and other boolean flags)
constant for jit traces (promoted). A few code cleanups.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -1,7 +1,7 @@
 import py
 import os
 from spyvm.shadow import ContextPartShadow, MethodContextShadow, 
BlockContextShadow, MethodNotFound
-from spyvm import model, constants, primitives, conftest, wrapper
+from spyvm import model, constants, primitives, conftest, wrapper, objspace
 from spyvm.tool.bitmanipulation import splitter
 
 from rpython.rlib import jit, rstackovf
@@ -36,8 +36,6 @@
 
 def __init__(self, space, image=None, image_name="",
 trace=False, evented=True, interrupts=True):
-import time
-
 # === Initialize immutable variables
 self.space = space
 self.image = image
@@ -56,8 +54,9 @@
 # === Initialize mutable variables
 self.interrupt_check_counter = self.interrupt_counter_size
 self.next_wakeup_tick = 0
-self.trace = trace
-self.trace_proxy = False
+self.trace = objspace.ConstantFlag(trace)
+self.trace_proxy = objspace.ConstantFlag()
+self.stack_depth = 0
 
 def loop(self, w_active_context):
 # This is the top-level loop and is not invoked recursively.
@@ -68,7 +67,7 @@
 self.loop_bytecodes(s_new_context)
 raise Exception("loop_bytecodes left without raising...")
 except StackOverflow, e:
-if self.trace:
+if self.is_tracing():
 print "== StackOverflow, contexts forced to heap at: 
%s" % e.s_new_context.short_str()
 s_new_context = e.s_new_context
 except Return, nlr:
@@ -81,8 +80,8 @@
 s_new_context = s_sender
 s_new_context.push(nlr.value)
 except ProcessSwitch, p:
-assert not self.space.suppress_process_switch[0], 
"ProcessSwitch should be disabled..."
-if self.trace:
+assert not self.space.suppress_process_switch.is_set(), 
"ProcessSwitch should be disabled..."
+if self.is_tracing():
 print "== Switched process from: %s" % 
s_new_context.short_str()
 print "== to: %s " % p.s_new_context.short_str()
 s_new_context = p.s_new_context
@@ -118,16 +117,19 @@
 s_context._activate_unwind_context(self)
 raise nlr
 
-
 # This is a wrapper around loop_bytecodes that cleanly enters/leaves the 
frame
 # and handles the stack overflow protection mechanism.
 def stack_frame(self, s_frame, s_sender, may_context_switch=True):
 try:
+if self.is_tracing():
+self.stack_depth += 1
 if s_frame._s_sender is None and s_sender is not None:
 s_frame.store_s_sender(s_sender, raise_error=False)
 # Now (continue to) execute the context bytecodes
 self.loop_bytecodes(s_frame, may_context_switch)
 except rstackovf.StackOverflow:
+if self.is_tracing():
+self.stack_depth -= 1
 rstackovf.check_stack_overflow()
 raise StackOverflow(s_frame)
 
@@ -184,7 +186,7 @@
 wrapper.SemaphoreWrapper(self.space, semaphore).signal(s_frame)
 # We have no finalization process, so far.
 # We do not support external semaphores.
-# In cog, the method to add such a semaphore is only called in GC.
+# In cog, the method to add such a semaphore is only called in GC.
 
 def time_now(self):
 import time
@@ -222,8 +224,12 @@
 s_frame.push_all(list(w_arguments))
 return s_frame
 
+def is_tracing(self):
+return self.trace.is_set()
+
 def padding(self, symbol=' '):
-return symbol
+assert self.is_tracing()
+return self.stack_depth * symbol
 
 class ReturnFromTopLevel(Exception):
 _attrs_ = ["object"]
@@ -245,9 +251,9 @@
 self.s_new_context = s_new_context
 
 class StackOverflow(ContextSwitchException):
-"""This causes the current jit-loop to be left.
-This is an experimental mechanism to avoid stack-overflow errors
-on OS level, and we suspect it breaks jit performance at least 
sometimes."""
+"""This causes the current jit-loop to be left, thus avoiding stack 
overflows.
+This breaks performance, so it should rarely happen.
+In case of severe performance problems, execute with -t and check if this 
occurrs."""
 
 class ProcessSwitch(ContextSwitchException):
 """This causes the int

[pypy-commit] lang-smalltalk storage: - Added a parameterized --trace option to control the stack depth up to which the trace is performed.

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r908:cedc9509b5c7
Date: 2014-07-14 18:35 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/cedc9509b5c7/

Log:- Added a parameterized --trace option to control the stack depth up
to which the trace is performed.
- Added helper to step through bytecode executions.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -35,7 +35,7 @@
 )
 
 def __init__(self, space, image=None, image_name="",
-trace=False, evented=True, interrupts=True):
+trace_depth=-1, evented=True, interrupts=True):
 # === Initialize immutable variables
 self.space = space
 self.image = image
@@ -54,7 +54,7 @@
 # === Initialize mutable variables
 self.interrupt_check_counter = self.interrupt_counter_size
 self.next_wakeup_tick = 0
-self.trace = objspace.ConstantFlag(trace)
+self.trace_depth = trace_depth
 self.trace_proxy = objspace.ConstantFlag()
 self.stack_depth = 0
 
@@ -225,12 +225,36 @@
 s_frame.push_all(list(w_arguments))
 return s_frame
 
+# == Methods for tracing, printing and debugging ==
+
+def activate_trace(self, trace_depth=0):
+self.trace_depth = trace_depth
+
+def deactivate_trace(self):
+self.trace_depth = -1
+
 def is_tracing(self):
-return self.trace.is_set()
+return jit.promote(self.trace_depth) >= 0
 
-def padding(self, symbol=' '):
-assert self.is_tracing()
-return symbol * self.stack_depth
+def print_padded(self, str):
+depth = jit.promote(self.trace_depth)
+assert depth >= 0
+if self.stack_depth <= depth:
+print (' ' * self.stack_depth) + str
+
+def activate_debug_bytecode(self):
+"NOT_RPYTHON"
+def do_break(self):
+import pdb
+if self.break_on_bytecodes:
+pdb.set_trace()
+Interpreter.debug_bytecode = do_break
+self.break_on_bytecodes = True
+
+def debug_bytecode(self):
+# This is for debugging. In a pdb console, execute the following:
+# self.activate_debug_bytecode()
+pass
 
 class ReturnFromTopLevel(Exception):
 _attrs_ = ["object"]
@@ -287,7 +311,7 @@
 parameters += (self.fetch_next_bytecode(), )
 i = i + 1
 # This is a good place to step through bytecodes.
-# import pdb; pdb.set_trace()
+interp.debug_bytecode()
 return actual_implementation_method(self, interp, 
current_bytecode, *parameters)
 bytecode_implementation_wrapper.func_name = 
actual_implementation_method.func_name
 return bytecode_implementation_wrapper
@@ -577,7 +601,7 @@
 
 # 
##
 if interp.is_tracing():
-print interp.padding() + s_frame.short_str()
+interp.print_padded('-> ' + s_frame.short_str())
 
 return interp.stack_frame(s_frame, self)
 
@@ -594,7 +618,7 @@
 
 # 
##
 if interp.is_tracing():
-print '%s %s %s: #%s' % (interp.padding('#'), special_selector, 
s_frame.short_str(), w_args)
+interp.print_padded('-> %s %s' % (special_selector, 
s_frame.short_str()))
 if not objectmodel.we_are_translated():
 import pdb; pdb.set_trace()
 
@@ -625,8 +649,8 @@
 def _call_primitive(self, code, interp, argcount, w_method, w_selector):
 # ##
 if interp.is_tracing():
-print "%s-> primitive %d \t(in %s, named #%s)" % (
-interp.padding(), code, 
self.w_method().get_identifier_string(), w_selector.str_content())
+interp.print_padded("-> primitive %d \t(in %s, named #%s)" % (
+code, 
self.w_method().get_identifier_string(), w_selector.str_content()))
 func = primitives.prim_holder.prim_table[code]
 try:
 # note: argcount does not include rcvr
@@ -634,8 +658,8 @@
 return func(interp, self, argcount, w_method)
 except primitives.PrimitiveFailedError, e:
 if interp.is_tracing():
-print "%s primitive %d FAILED\t (in %s, named %s)" % (
-interp.padding(), code, w_method.safe_identifier_string(), 
w_selector.str_content())
+interp.print_padded("-- primitive %d FAILED\t (in %s, named 
%s)" % (
+code, w_method.safe_identifier_string(), 
w_selector.str_content()))
 raise e
 
 def _return(self, return_value, interp, local_return=False):
@@ -644,7 +668,7 @@
 
 # #

[pypy-commit] lang-smalltalk storage: Fixed tracing and doesNotUnderstand outputs

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r904:c5189bb59f35
Date: 2014-07-13 17:17 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/c5189bb59f35/

Log:Fixed tracing and doesNotUnderstand outputs

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -128,10 +128,11 @@
 # Now (continue to) execute the context bytecodes
 self.loop_bytecodes(s_frame, may_context_switch)
 except rstackovf.StackOverflow:
+rstackovf.check_stack_overflow()
+raise StackOverflow(s_frame)
+finally:
 if self.is_tracing():
 self.stack_depth -= 1
-rstackovf.check_stack_overflow()
-raise StackOverflow(s_frame)
 
 def step(self, context):
 bytecode = context.fetch_next_bytecode()
@@ -229,7 +230,7 @@
 
 def padding(self, symbol=' '):
 assert self.is_tracing()
-return self.stack_depth * symbol
+return symbol * self.stack_depth
 
 class ReturnFromTopLevel(Exception):
 _attrs_ = ["object"]
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -370,24 +370,31 @@
 
 FAIL = 19
 
+def get_string(w_obj):
+if isinstance(w_obj, model.W_BytesObject):
+return w_obj.as_string()
+return w_obj.as_repr_string()
+
 @expose_primitive(FAIL)
 def func(interp, s_frame, argcount):
 if interp.space.headless.is_set() and s_frame.w_method().lookup_selector 
== 'doesNotUnderstand:':
-w_msg = s_frame.peek(1)
-if isinstance(w_msg, model.W_BytesObject):
-print "== Error message: %s" % w_msg.as_string()
+print "== Error message: %s" % get_string(s_frame.peek(1))
+print "== Receiver: %s" % s_frame.w_receiver().as_repr_string()
+w_arguments = s_frame.w_arguments()
+if len(w_arguments) >= 1:
+w_message = w_arguments[0]
+if isinstance(w_message, model.W_PointersObject):
+fields = w_message.fetch_all(interp.space)
+if len(fields) >= 1:
+print "== Selector: %s" % get_string(fields[0])
+if len(fields) >= 2:
+w_args = fields[0]
+if isinstance(w_args, model.W_PointersObject):
+arg_strings = [ get_string(w_arg) for w_arg in 
w_args.fetch_all(interp.space) ]
+print "== Arguments: %s" % ', '.join(arg_strings)
+else:
+print "== Message: %s" % w_message
 print "== VM Stack:%s" % s_frame.print_stack()
-print "== Message:"
-for w_argument in s_frame.w_arguments():
-print w_argument.as_repr_string()
-if isinstance(w_argument, model.W_PointersObject):
-fields = w_argument.fetch_all(interp.space)
-for i, w_field in enumerate(fields):
-print "\t%s" % w_field.as_repr_string()
-if i == 1 and isinstance(w_field, model.W_PointersObject):
-# These are the arguments to the not-undersood message
-for w_field_field in w_field.fetch_all(interp.space):
-print "\t\t%s" % w_field_field.as_repr_string()
 w_stack = s_frame.peek(0)
 if isinstance(w_stack, model.W_BytesObject):
 print "== Squeak stack:\n%s" % w_stack.as_string()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Fixed help string.

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r901:37ace0c8899d
Date: 2014-07-12 13:16 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/37ace0c8899d/

Log:Fixed help string.

diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -12,7 +12,7 @@
 
 def _usage(argv):
 print """
-Usage: %s  [-r|-m] [-naHu] [-jpis] [-tlLE]
+Usage: %s  [-r|-m|-h] [-naPu] [-jpis] [-tlLE]
  - image path (default: Squeak.image)
 
   Execution mode:
@@ -35,9 +35,6 @@
 -j|--jit  - jitargs will be passed to the jit 
configuration.
 -p|--poll  - Actively poll for events. Try this if the 
image is not responding well.
 -i|--no-interrupts - Disable timer interrupt. Disables 
non-cooperative scheduling.
--s- After num stack frames, the entire stack will 
be dumped to the heap.
- This breaks performance, but protects agains 
stack overflow.
- num <= 0 disables stack protection (default: 
%d)
 -S - Disable specialized storage strategies; 
always use generic ListStorage
 
   Logging parameters:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Optimizing storage strategies.

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r899:2c3b6f965b1a
Date: 2014-07-10 21:29 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/2c3b6f965b1a/

Log:Optimizing storage strategies.

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -614,7 +614,7 @@
 
 def switch_shadow(self, new_shadow, w_element=None):
 old_shadow = self.assert_shadow()
-new_shadow.copy_from(old_shadow)
+old_shadow.copy_into(new_shadow)
 self.store_shadow(new_shadow)
 new_shadow.attach_shadow()
 self.log_storage("Switched", old_shadow, w_element=w_element)
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -38,16 +38,27 @@
 def size(self):
 raise NotImplementedError("Abstract class")
 
+# This will invoke an appropriate copy_from_* method.
+# Overwriting this allows optimized transitions between certain storage 
types.
+def copy_into(self, other_shadow):
+other_shadow.copy_from(self)
+
 def attach_shadow(self): pass
 
 def copy_field_from(self, n0, other_shadow):
 self.store(n0, other_shadow.fetch(n0))
 
-# This can be overwritten to change the order of initialization.
 def copy_from(self, other_shadow):
 assert self.size() == other_shadow.size()
 for i in range(self.size()):
 self.copy_field_from(i, other_shadow)
+
+def copy_from_AllNil(self, all_nil_storage):
+self.copy_from(all_nil_storage)
+def copy_from_SmallIntegerOrNil(self, small_int_storage):
+self.copy_from(small_int_storage)
+def copy_from_FloatOrNil(self, float_storage):
+self.copy_from(float_storage)
 
 class AbstractStorageShadow(AbstractShadow):
 _attrs_ = []
@@ -80,6 +91,8 @@
 if n0 >= self._size:
 raise IndexError
 return self.space.w_nil
+def copy_into(self, other_shadow):
+other_shadow.copy_from_AllNil(self)
 def do_store(self, n0, w_value):
 pass
 def size(self):
@@ -117,6 +130,9 @@
 self.storage[n0] = self.nil_value
 else:
 self.storage[n0] = self.unwrap(self.space, w_val)
+
+def copy_from_AllNil(self, all_nil_storage):
+pass # Already initialized
 
 # This is to avoid code duplication
 @objectmodel.specialize.arg(0)
@@ -143,6 +159,8 @@
 @staticmethod
 def unwrap(space, w_val):
 return space.unwrap_int(w_val)
+def copy_into(self, other_shadow):
+other_shadow.copy_from_SmallIntegerOrNil(self)
 
 class FloatOrNilStorageShadow(AbstractStorageShadow):
 repr_classname = "FloatOrNilStorageShadow"
@@ -162,6 +180,8 @@
 @staticmethod
 def unwrap(space, w_val):
 return space.unwrap_float(w_val)
+def copy_into(self, other_shadow):
+other_shadow.copy_from_FloatOrNil(self)
 
 def empty_storage(space, w_self, size, weak=False):
 if weak:
@@ -170,6 +190,7 @@
 return ListStorageShadow(space, w_self, size)
 return AllNilStorageShadow(space, w_self, size)
 
+@jit.unroll_safe
 def find_storage_for_objects(space, vars, weak=False):
 if weak:
 return WeakListStorageShadow
@@ -212,7 +233,10 @@
 def copy_from(self, other_shadow):
 if self.size() != other_shadow.size():
 self.initialize_storage(other_shadow.size())
-AbstractShadow.copy_from(self, other_shadow)
+for i in range(self.size()):
+w_val = other_shadow.fetch(i)
+if not w_val.is_nil(self.space):
+self.store(i, w_val)
 
 class ListStorageShadow(AbstractStorageShadow):
 _attrs_ = ['storage']
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Printing better information in case of a doesNotUnderstand:

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r903:b73849087f13
Date: 2014-07-13 16:42 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/b73849087f13/

Log:Printing better information in case of a doesNotUnderstand:

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -821,9 +821,10 @@
 
 def as_string(self):
 if self.bytes is not None:
-return "".join(self.bytes)
+string = "".join(self.bytes)
 else:
-return "".join([self.c_bytes[i] for i in range(self.size())])
+string = "".join([self.c_bytes[i] for i in range(self.size())])
+return string.replace('\r', '\n')
 
 def invariant(self):
 if not W_AbstractObjectWithClassReference.invariant(self):
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -33,6 +33,7 @@
 self.no_specialized_storage = ConstantFlag()
 # This is a hack; see compile_code() in targetimageloadingsmalltalk.py
 self.suppress_process_switch = ConstantFlag()
+self.headless = ConstantFlag()
 
 self.classtable = {}
 self.objtable = {}
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -2,10 +2,8 @@
 import inspect
 import math
 import operator
-from spyvm import model, shadow
-from spyvm import constants, display
-from spyvm.error import PrimitiveFailedError, \
-PrimitiveNotYetWrittenError
+from spyvm import model, shadow, error, constants, display
+from spyvm.error import PrimitiveFailedError, PrimitiveNotYetWrittenError
 from spyvm import wrapper
 
 from rpython.rlib import rarithmetic, rfloat, unroll, jit
@@ -374,14 +372,26 @@
 
 @expose_primitive(FAIL)
 def func(interp, s_frame, argcount):
-if s_frame.w_method().lookup_selector == 'doesNotUnderstand:':
-print ''
-print s_frame.print_stack()
-w_message = s_frame.peek(0)
-print ("%s" % w_message).replace('\r', '\n')
-print ("%s" % s_frame.peek(1)).replace('\r', '\n')
-if isinstance(w_message, model.W_PointersObject):
-print ('%s' % w_message.fetch_all(s_frame.space)).replace('\r', 
'\n')
+if interp.space.headless.is_set() and s_frame.w_method().lookup_selector 
== 'doesNotUnderstand:':
+w_msg = s_frame.peek(1)
+if isinstance(w_msg, model.W_BytesObject):
+print "== Error message: %s" % w_msg.as_string()
+print "== VM Stack:%s" % s_frame.print_stack()
+print "== Message:"
+for w_argument in s_frame.w_arguments():
+print w_argument.as_repr_string()
+if isinstance(w_argument, model.W_PointersObject):
+fields = w_argument.fetch_all(interp.space)
+for i, w_field in enumerate(fields):
+print "\t%s" % w_field.as_repr_string()
+if i == 1 and isinstance(w_field, model.W_PointersObject):
+# These are the arguments to the not-undersood message
+for w_field_field in w_field.fetch_all(interp.space):
+print "\t\t%s" % w_field_field.as_repr_string()
+w_stack = s_frame.peek(0)
+if isinstance(w_stack, model.W_BytesObject):
+print "== Squeak stack:\n%s" % w_stack.as_string()
+raise error.Exit("Unhandled doesNotUnderstand:")
 raise PrimitiveFailedError()
 
 # ___
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -929,6 +929,9 @@
 # __
 # Printing
 
+def argument_strings(self):
+return [ w_arg.as_repr_string() for w_arg in self.w_arguments() ]
+
 def __str__(self):
 retval = self.short_str()
 retval += "\n%s" % 
self.w_method().bytecode_string(markBytecode=self.pc() + 1)
@@ -1099,7 +1102,7 @@
 
 # === Printing ===
 
-def argument_strings(self):
+def w_arguments(self):
 return []
 
 def method_str(self):
@@ -1255,13 +1258,9 @@
 
 # === Printing ===
 
-def argument_strings(self):
+def w_arguments(self):
 argcount = self.w_method().argsize
-tempsize = self.w_method().tempsize()
-args = []
-for i in range(argcount):
-args.append(self.peek(tempsize - i - 1).as_repr_string())
-return args
+return [ self.stack_get(i) for i in range(argcount) ]
 
 def method_str(self):
 block = '[] in ' if self.is_closure_context() else ''
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -165,6 +165,7 @@
 return -1 # Compilation failed, message is printed.
 s_frame = create_context(interp, w_receiver, se

[pypy-commit] lang-smalltalk storage: Merged.

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r900:f71c6de0dab8
Date: 2014-07-10 21:31 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/f71c6de0dab8/

Log:Merged.

diff --git a/spyvm/constants.py b/spyvm/constants.py
--- a/spyvm/constants.py
+++ b/spyvm/constants.py
@@ -190,6 +190,5 @@
 # Interpreter constants
 #
 
-MAX_LOOP_DEPTH = 100
 INTERRUPT_COUNTER_SIZE = 1
 CompileTime = time.time()
diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -4,7 +4,7 @@
 from spyvm import model, constants, primitives, conftest, wrapper
 from spyvm.tool.bitmanipulation import splitter
 
-from rpython.rlib import jit
+from rpython.rlib import jit, rstackovf
 from rpython.rlib import objectmodel, unroll
 
 class MissingBytecode(Exception):
@@ -24,7 +24,7 @@
 
 class Interpreter(object):
 _immutable_fields_ = ["space", "image", "image_name",
-  "max_stack_depth", "interrupt_counter_size",
+  "interrupt_counter_size",
   "startup_time", "evented", "interrupts"]
 
 jit_driver = jit.JitDriver(
@@ -35,8 +35,7 @@
 )
 
 def __init__(self, space, image=None, image_name="",
-trace=False, evented=True, interrupts=True,
-max_stack_depth=constants.MAX_LOOP_DEPTH):
+trace=False, evented=True, interrupts=True):
 import time
 
 # === Initialize immutable variables
@@ -47,7 +46,6 @@
 self.startup_time = image.startup_time
 else:
 self.startup_time = constants.CompileTime
-self.max_stack_depth = max_stack_depth
 self.evented = evented
 self.interrupts = interrupts
 try:
@@ -57,7 +55,6 @@
 
 # === Initialize mutable variables
 self.interrupt_check_counter = self.interrupt_counter_size
-self.current_stack_depth = 0
 self.next_wakeup_tick = 0
 self.trace = trace
 self.trace_proxy = False
@@ -66,7 +63,6 @@
 # This is the top-level loop and is not invoked recursively.
 s_new_context = w_active_context.as_context_get_shadow(self.space)
 while True:
-assert self.current_stack_depth == 0
 s_sender = s_new_context.s_sender()
 try:
 self.loop_bytecodes(s_new_context)
@@ -76,11 +72,13 @@
 print "== StackOverflow, contexts forced to heap at: 
%s" % e.s_new_context.short_str()
 s_new_context = e.s_new_context
 except Return, nlr:
+assert nlr.s_target_context or nlr.is_local
 s_new_context = s_sender
-while s_new_context is not nlr.s_target_context:
-s_sender = s_new_context.s_sender()
-s_new_context._activate_unwind_context(self)
-s_new_context = s_sender
+if not nlr.is_local:
+while s_new_context is not nlr.s_target_context:
+s_sender = s_new_context.s_sender()
+s_new_context._activate_unwind_context(self)
+s_new_context = s_sender
 s_new_context.push(nlr.value)
 except ProcessSwitch, p:
 assert not self.space.suppress_process_switch[0], 
"ProcessSwitch should be disabled..."
@@ -110,11 +108,16 @@
 try:
 self.step(s_context)
 except Return, nlr:
-if nlr.s_target_context is not s_context:
+if nlr.s_target_context is s_context or nlr.is_local:
+s_context.push(nlr.value)
+else:
+if nlr.s_target_context is None:
+# This is the case where we are returning to our 
sender.
+# Mark the return as local, so our sender will take it
+nlr.is_local = True
 s_context._activate_unwind_context(self)
 raise nlr
-else:
-s_context.push(nlr.value)
+
 
 # This is a wrapper around loop_bytecodes that cleanly enters/leaves the 
frame
 # and handles the stack overflow protection mechanism.
@@ -122,16 +125,11 @@
 try:
 if s_frame._s_sender is None and s_sender is not None:
 s_frame.store_s_sender(s_sender, raise_error=False)
-
-self.current_stack_depth += 1
-if self.max_stack_depth > 0:
-if self.current_stack_depth >= self.max_stack_depth:
-raise StackOverflow(s_frame)
-
 # Now (continue to) execute the context bytecodes
 self.loop_bytecodes(s_frame, may_context_switch)
-finally:
-self.current_stack_depth -= 1
+except rstackovf.StackOverflow:
+rstackovf.check_stack_overflow()
+raise Stack

[pypy-commit] lang-smalltalk storage: Fixed test.

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r906:84e2ca8cd10e
Date: 2014-07-14 13:35 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/84e2ca8cd10e/

Log:Fixed test.

diff --git a/spyvm/test/test_shadow.py b/spyvm/test/test_shadow.py
--- a/spyvm/test/test_shadow.py
+++ b/spyvm/test/test_shadow.py
@@ -195,11 +195,12 @@
 assert s_object.fetch(1).value == 13
 
 def test_cached_object_shadow():
-w_o = space.wrap_list([0, 1, 2, 3, 4, 5, 6, 7])
+l = map(space.w, [0, 1, 2, 3, 4, 5, 6, 7])
+w_o = space.wrap_list(l)
 s_o = w_o.as_cached_object_get_shadow(space)
 version = s_o.version
 for i in range(w_o.size()):
-assert w_o.at0(space, i) == i
+assert w_o.at0(space, i) == l[i]
 w_o.atput0(space, 0, 8)
 assert version is not s_o.version
 assert w_o.at0(space, 0) == 8
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Added a name for the executable

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r915:c52509373e77
Date: 2014-07-16 00:19 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/c52509373e77/

Log:Added a name for the executable

diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -268,6 +268,7 @@
 if hasattr(rgc, "stm_is_enabled"):
 driver.config.translation.stm = True
 driver.config.translation.thread = True
+driver.exe_name = "rsqueak"
 return safe_entry_point, None
 
 def jitpolicy(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Removed obsolete CLI flag.

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r907:0b36d560ebf1
Date: 2014-07-14 13:35 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/0b36d560ebf1/

Log:Removed obsolete CLI flag.

diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -12,7 +12,7 @@
 
 def _usage(argv):
 print """
-Usage: %s  [-r|-m|-h] [-naPu] [-jpis] [-tlLE]
+Usage: %s  [-r|-m|-h] [-naPu] [-jpiS] [-tlLE]
  - image path (default: Squeak.image)
 
   Execution mode:
@@ -104,8 +104,6 @@
 code, idx = get_parameter(argv, idx, arg)
 elif arg in ["-i", "--no-interrupts"]:
 interrupts = False
-elif arg in ["-s"]:
-max_stack_depth, idx = get_int_parameter(argv, idx, arg)
 elif arg in ["-P", "--process"]:
 headless = False
 elif arg in ["-S"]:
@@ -172,7 +170,7 @@
 context = active_context(space)
 else:
 context = active_context(space)
-
+
 w_result = execute_context(interp, context)
 print result_string(w_result)
 storage_logger.print_aggregated_log()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Commented out flushCache primitive. We should not need it, since we monitor changes to MethodDictionary objects directly. This primitive takes too long and preven

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r911:63016d515218
Date: 2014-07-14 18:44 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/63016d515218/

Log:Commented out flushCache primitive. We should not need it, since we
monitor changes to MethodDictionary objects directly. This primitive
takes too long and prevents running the VM in interpreted mode.

diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -967,7 +967,9 @@
 # MethodDictionaryShadow objects and flush them.
 @expose_primitive(SYMBOL_FLUSH_CACHE, unwrap_spec=[object])
 def func(interp, s_frame, w_rcvr):
-walk_gc_objects_of_type(shadow.MethodDictionaryShadow, lambda s_dict: 
s_dict.flush_method_cache())
+# This takes a long time (at least in interpreted mode), and is not 
really necessary.
+# We are monitoring changes to MethodDictionaries, so there is no need 
for the image to tell us.
+#walk_gc_objects_of_type(shadow.MethodDictionaryShadow, lambda s_dict: 
s_dict.flush_method_cache())
 return w_rcvr
 
 # ___
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Fixed tests and removed obsolete tests.

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r905:6656aa03e7b0
Date: 2014-07-14 13:32 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/6656aa03e7b0/

Log:Fixed tests and removed obsolete tests.

diff --git a/spyvm/test/test_interpreter.py b/spyvm/test/test_interpreter.py
--- a/spyvm/test/test_interpreter.py
+++ b/spyvm/test/test_interpreter.py
@@ -26,8 +26,11 @@
 if retval is not None:
 return retval.w_self()
 except interpreter.Return, nlr:
-nlr.s_target_context.push(nlr.value)
-return nlr.s_target_context.w_self()
+new_context = nlr.s_target_context
+if new_context is None:
+new_context = ctxt.s_sender()
+new_context.push(nlr.value)
+return new_context.w_self()
 
 def assert_list(list, expected):
 for i in range(len(list)):
@@ -975,81 +978,6 @@
 2, "value:value:"]],
 test)
 
-def test_stacking_interpreter():
-# | testBlock |
-# testBlock := [ :aNumber |
-# aNumber = 0
-# ifTrue: [ 0 ]
-# ifFalse: [ (testBlock value: aNumber - 1) + aNumber ]].
-# ^ testBlock value: 11
-interp = TestInterpreter(space, max_stack_depth=3)
-#create a method with the correct bytecodes and a literal
-bytes = reduce(operator.add, map(chr, [0x8a, 0x01, 0x68, 0x10, 0x8f, 0x11,
-0x00, 0x11, 0x10, 0x75, 0xb6, 0x9a, 0x75, 0xa4, 0x09, 0x8c, 0x00, 0x01,
-0x10, 0x76, 0xb1, 0xca, 0x10, 0xb0, 0x7d, 0x8e, 0x00, 0x00, 0x8c, 0x00,
-0x00, 0x20, 0xca, 0x7c]))
-w_method = model.W_CompiledMethod(space, len(bytes))
-w_method.islarge = 1
-w_method.bytes = bytes
-w_method.argsize=0
-w_method._tempsize=1
-w_method.setliterals([space.wrap_int(11)])
-
-#create a frame for that method
-w_frame = w_method.create_frame(space, space.wrap_int(0), []).w_self()
-try:
-interp.loop(w_frame)
-except interpreter.ReturnFromTopLevel, e:
-assert space.unwrap_int(e.object) == 66
-except interpreter.StackOverflow, e:
-assert False
-try:
-interp = TestInterpreter(space, image_name="", max_stack_depth=10)
-interp._loop = True
-interp.loop_bytecodes(w_method.create_frame(space, space.wrap_int(0), 
[]))
-except interpreter.StackOverflow, e:
-assert isinstance(e.s_new_context, shadow.MethodContextShadow)
-except interpreter.ReturnFromTopLevel, e:
-assert False
-
-class StackTestInterpreter(TestInterpreter):
-def stack_frame(self, s_frame, s_sender, may_interrupt=True):
-stack_depth = self.current_stack_depth
-for i in range(stack_depth + 1):
-assert sys._getframe(5 + i * 7).f_code.co_name == 'loop_bytecodes'
-assert sys._getframe(6 + stack_depth * 7).f_code.co_name == 'loop'
-return interpreter.Interpreter.stack_frame(self, s_frame, s_sender, 
may_interrupt)
-
-def test_actual_stackdepth():
-# | testBlock |
-# testBlock := [ :aNumber |
-# aNumber = 0
-# ifTrue: [ 2 ]
-# ifFalse: [ (testBlock value: aNumber - 1) + aNumber ]].
-# ^ testBlock value: 11
-interp = StackTestInterpreter(space, max_stack_depth=10)
-#create a method with the correct bytecodes and a literal
-bytes = reduce(operator.add, map(chr, [0x8a, 0x01, 0x68, 0x10, 0x8f, 0x11,
-0x00, 0x11, 0x10, 0x75, 0xb6, 0x9a, 0x77, 0xa4, 0x09, 0x8c, 0x00, 0x01,
-0x10, 0x76, 0xb1, 0xca, 0x10, 0xb0, 0x7d, 0x8e, 0x00, 0x00, 0x8c, 0x00,
-0x00, 0x20, 0xca, 0x7c]))
-
-w_method = model.W_CompiledMethod(space, len(bytes))
-w_method.islarge = 1
-w_method.bytes = bytes
-w_method.argsize=0
-w_method._tempsize=1
-w_method.setliterals([space.wrap_int(11)])
-
-#create a frame for that method
-w_frame = w_method.create_frame(space, space.wrap_int(0), []).w_self()
-try:
-interp.loop(w_frame)
-except interpreter.ReturnFromTopLevel, e:
-assert space.unwrap_int(e.object) == 68
-except interpreter.StackOverflow, e:
-assert False
-
 def test_c_stack_reset_on_sender_chain_manipulation():
 bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00]))
 w_frame, s_frame = new_frame(bytes)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Added safety-net try-except block to print Exception messages (not printed by itself in translated mode).

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r913:0f59f7f54a2c
Date: 2014-07-15 22:54 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/0f59f7f54a2c/

Log:Added safety-net try-except block to print Exception messages (not
printed by itself in translated mode).

diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -64,6 +64,16 @@
 
 prebuilt_space = objspace.ObjSpace()
 
+def safe_entry_point(argv):
+try:
+return entry_point(argv)
+except error.Exit, e:
+print_error("Exited: %s" % e.msg)
+return -1
+except Exception, e:
+print_error("Exception: %s" % str(e))
+return -1
+
 def entry_point(argv):
 # == Main execution parameters
 path = None
@@ -146,7 +156,7 @@
 except OSError as e:
 print_error("%s -- %s (LoadError)" % (os.strerror(e.errno), path))
 return 1
-
+
 # Load & prepare image and environment
 image_reader = squeakimage.reader_for_image(space, 
squeakimage.Stream(data=imagedata))
 image = create_image(space, image_reader)
@@ -164,8 +174,6 @@
 w_receiver = space.wrap_int(number)
 if code:
 selector = compile_code(interp, w_receiver, code)
-if selector is None:
-return -1 # Compilation failed, message is printed.
 s_frame = create_context(interp, w_receiver, selector, stringarg)
 if headless:
 space.headless.set()
@@ -198,24 +206,19 @@
 # TODO - Find a way to cleanly initialize the image, without executing the 
active_context of the image.
 # Instead, we want to execute our own context. Then remove this flag (and 
all references to it)
 space.suppress_process_switch.set()
-try:
-w_result = interp.perform(
-w_receiver_class,
-"compile:classified:notifying:",
-w_arguments = [space.wrap_string("%s\r\n%s" % (selector, code)),
-space.wrap_string("spy-run-code"),
-space.w_nil]
-)
-
-# TODO - is this expected in every image?
-if not isinstance(w_result, model.W_BytesObject) or 
w_result.as_string() != selector:
-print_error("Compilation failed, unexpected result: %s" % 
result_string(w_result))
-return None
-except error.Exit, e:
-print_error("Exited while compiling code: %s" % e.msg)
-return None
-finally:
-space.suppress_process_switch.unset()
+
+w_result = interp.perform(
+w_receiver_class,
+"compile:classified:notifying:",
+w_arguments = [space.wrap_string("%s\r\n%s" % (selector, code)),
+space.wrap_string("spy-run-code"),
+space.w_nil]
+)
+# TODO - is this expected in every image?
+if not isinstance(w_result, model.W_BytesObject) or w_result.as_string() 
!= selector:
+raise error.Exit("Unexpected compilation result (probably failed to 
compile): %s" % result_string(w_result))
+space.suppress_process_switch.unset()
+
 
w_receiver_class.as_class_get_shadow(space).s_methoddict().sync_method_cache()
 return selector
 
@@ -253,12 +256,8 @@
 active_process.store_suspended_context(space.w_nil)
 return w_active_context.as_context_get_shadow(space)
 
-def execute_context(interp, s_frame, measure=False):
-try:
-return interp.interpret_toplevel(s_frame.w_self())
-except error.Exit, e:
-print_error("Exited: %s" % e.msg)
-return None
+def execute_context(interp, s_frame):
+return interp.interpret_toplevel(s_frame.w_self())
 
 # _ Target and Main _
 
@@ -269,11 +268,11 @@
 if hasattr(rgc, "stm_is_enabled"):
 driver.config.translation.stm = True
 driver.config.translation.thread = True
-return entry_point, None
+return safe_entry_point, None
 
 def jitpolicy(self):
 from rpython.jit.codewriter.policy import JitPolicy
 return JitPolicy()
 
 if __name__ == "__main__":
-entry_point(sys.argv)
+safe_entry_point(sys.argv)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Fixed bug in CompiledMethod: literals were set to nil when the header was changed. Caused incorrectly compiled code.

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r909:c063fbae6f06
Date: 2014-07-14 18:39 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/c063fbae6f06/

Log:Fixed bug in CompiledMethod: literals were set to nil when the
header was changed. Caused incorrectly compiled code.

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -1154,7 +1154,7 @@
 
 def compute_pos(self, n):
 return n * (NATIVE_DEPTH / self._depth)
-
+
 # XXX Shouldn't compiledmethod have class reference for subclassed compiled
 # methods?
 class W_CompiledMethod(W_AbstractObjectWithIdentityHash):
@@ -1185,20 +1185,22 @@
 
 def __init__(self, space, bytecount=0, header=0):
 self.bytes = ["\x00"] * bytecount
-self.setheader(space, header)
+self.setheader(space, header, initializing=True)
 
 def fillin(self, space, g_self):
 # Implicitely sets the header, including self.literalsize
 for i, w_object in enumerate(g_self.get_pointers()):
-self.literalatput0(space, i, w_object)
+self.literalatput0(space, i, w_object, initializing=True)
 self.setbytes(g_self.get_bytes()[self.bytecodeoffset():])
 
 # === Setters ===
 
-def setheader(self, space, header):
+def setheader(self, space, header, initializing=False):
 _primitive, literalsize, islarge, tempsize, argsize = 
constants.decode_compiled_method_header(header)
-self.literalsize = literalsize
-self.literals = [space.w_nil] * self.literalsize
+if initializing or self.literalsize != literalsize:
+# Keep the literals if possible.
+self.literalsize = literalsize
+self.literals = [space.w_nil] * self.literalsize
 self.header = header
 self.argsize = argsize
 self._tempsize = tempsize
@@ -1314,11 +1316,11 @@
 return space.wrap_int(self.getheader())
 else:
 return self.getliteral(index0 - 1)
-
-def literalatput0(self, space, index0, w_value):
+
+def literalatput0(self, space, index0, w_value, initializing=False):
 if index0 == 0:
 header = space.unwrap_int(w_value)
-self.setheader(space, header)
+self.setheader(space, header, initializing=initializing)
 else:
 self.setliteral(index0 - 1, w_value)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Some fixes to storage strategies:

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r912:541b01ff2814
Date: 2014-07-14 20:22 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/541b01ff2814/

Log:Some fixes to storage strategies:
- Added size parameter to each Shadow constructor
- Optimized transitions between certain strategies.

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -693,7 +693,7 @@
 old_shadow = self._get_shadow()
 shadow = old_shadow
 if not isinstance(old_shadow, TheClass):
-shadow = TheClass(space, self)
+shadow = TheClass(space, self, old_shadow.size())
 self.switch_shadow(shadow)
 return shadow
 
diff --git a/spyvm/plugins/bitblt.py b/spyvm/plugins/bitblt.py
--- a/spyvm/plugins/bitblt.py
+++ b/spyvm/plugins/bitblt.py
@@ -727,8 +727,8 @@
 _attrs_ = ["w_bits", "width", "height", "depth", "offsetX",
"offsetY", "msb", "pixPerWord", "pitch", "invalid"]
 
-def __init__(self, space, w_self):
-AbstractCachingShadow.__init__(self, space, w_self)
+def __init__(self, space, w_self, size):
+AbstractCachingShadow.__init__(self, space, w_self, size)
 self.invalid = False
 
 def intOrIfNil(self, w_int, i):
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -1314,7 +1314,7 @@
 # The block bytecodes are stored inline: so we skip past the
 # byteodes to invoke this primitive to find them (hence +2)
 initialip = s_frame.pc() + 2
-s_new_context = shadow.BlockContextShadow(interp.space, None, 
w_method_context, argcnt, initialip)
+s_new_context = shadow.BlockContextShadow(interp.space, None, 0, 
w_method_context, argcnt, initialip)
 return s_new_context.w_self()
 
 @expose_primitive(VALUE, result_is_new_frame=True)
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -17,7 +17,7 @@
 provides_getname = False
 repr_classname = "AbstractShadow"
 
-def __init__(self, space, w_self):
+def __init__(self, space, w_self, size):
 self.space = space
 assert w_self is None or isinstance(w_self, model.W_PointersObject)
 self._w_self = w_self
@@ -64,7 +64,7 @@
 _attrs_ = []
 repr_classname = "AbstractStorageShadow"
 def __init__(self, space, w_self, size):
-AbstractShadow.__init__(self, space, w_self)
+AbstractShadow.__init__(self, space, w_self, size)
 def store(self, n0, w_val):
 if self.can_contain(w_val):
 return self.do_store(n0, w_val)
@@ -79,6 +79,15 @@
 raise NotImplementedError()
 def generalized_strategy_for(self, w_val):
 raise NotImplementedError()
+
+def copy_from_AllNil(self, all_nil_storage):
+pass # Already initialized
+def copy_from(self, other_shadow):
+assert self.size() == other_shadow.size()
+for i in range(self.size()):
+w_val = other_shadow.fetch(i)
+if not w_val.is_nil(self.space): # nil fields already initialized
+self.store(i, w_val)
 
 class AllNilStorageShadow(AbstractStorageShadow):
 repr_classname = "AllNilStorageShadow"
@@ -130,9 +139,6 @@
 self.storage[n0] = self.nil_value
 else:
 self.storage[n0] = self.unwrap(self.space, w_val)
-
-def copy_from_AllNil(self, all_nil_storage):
-pass # Already initialized
 
 # This is to avoid code duplication
 @objectmodel.specialize.arg(0)
@@ -230,13 +236,6 @@
 self.initialize_storage(size)
 def size(self):
 return len(self.storage)
-def copy_from(self, other_shadow):
-if self.size() != other_shadow.size():
-self.initialize_storage(other_shadow.size())
-for i in range(self.size()):
-w_val = other_shadow.fetch(i)
-if not w_val.is_nil(self.space):
-self.store(i, w_val)
 
 class ListStorageShadow(AbstractStorageShadow):
 _attrs_ = ['storage']
@@ -273,8 +272,8 @@
 import_from_mixin(version.VersionMixin)
 version = None
 
-def __init__(self, space, w_self):
-ListStorageShadow.__init__(self, space, w_self, 0)
+def __init__(self, space, w_self, size):
+ListStorageShadow.__init__(self, space, w_self, size)
 self.changed()
 
 # 
@@ -305,9 +304,9 @@
 provides_getname = True
 repr_classname = "ClassShadow"
 
-def __init__(self, space, w_self):
+def __init__(self, space, w_self, size):
 self.subclass_s = {}
-AbstractCachingShadow.__init__(self, space, w_self)
+AbstractCachingShadow.__init__(self, space, w_self, size)
 
 def store(self, n0, w_val):
 AbstractCachingShadow.store(self, n0, w_val)
@@ -425,7 +424,7 @@
 def flush_method_caches(self):
 look_in_shadow = self
 while look_in_shado

[pypy-commit] lang-smalltalk storage: Changes to the benchmarks. We really should put this on Monticello or something.

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r916:30a053f8596e
Date: 2014-07-16 11:07 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/30a053f8596e/

Log:Changes to the benchmarks. We really should put this on Monticello
or something.

diff --git a/images/Squeak4.5-noBitBlt.changes 
b/images/Squeak4.5-noBitBlt.changes
--- a/images/Squeak4.5-noBitBlt.changes
+++ b/images/Squeak4.5-noBitBlt.changes
@@ -12348,4 +12348,276 @@

^ 0! !
!BalloonEngine methodsFor: 'primitives-misc' stamp: 'tfel 7/2/2014 17:13' 
prior: 17242774!
primInitializeBuffer: buffer

-   ^ 0! !
!BalloonEngine methodsFor: 'profiling' stamp: 'ar 11/11/1998 21:16' prior: 
17242962!
doAddCompressedShape: points segments: nSegments leftFills: leftFills 
rightFills: rightFills lineWidths: lineWidths lineFills: lineFills 
fillIndexList: fillIndexList matrix: aMatrix
"Note: This method is for profiling the overhead of loading a 
compressed shape into the engine."
^self primAddCompressedShape: points segments: nSegments leftFills: 
leftFills rightFills: rightFills lineWidths: lineWidths lineFills: lineFills 
fillIndexList: fillIndexList matrix: aMatrix! !
!BalloonEngine methodsFor: 'as yet unclassified' stamp: 'tfel 1/7/2014 18:07' 
prior: 47363563!
error: aString

^self! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

BalloonEngine class
instanceVariableNames: ''!
!BalloonEngine class methodsFor: 'accessing' stamp: 'ar 10/25/1998 17:37' 
prior: 17243620!
debug: aBoolean
"BalloonEngine debug: true"
"BalloonEngine debug: false"
Debug := aBoolean! !
!BalloonEngine class methodsFor: 'accessing' stamp: 'ar 2/2/2001 15:47' prior: 
17243791!
doProfileStats: aBool
"Note: On Macintosh systems turning on profiling can significantly
degrade the performance of Balloon since we're using the high
accuracy timer for measuring."
"BalloonEngine doProfileStats: true"
"BalloonEngine doProfileStats: false"

^false! !
!BalloonEngine class methodsFor: 'accessing' stamp: 'ar 10/30/1998 23:57' 
prior: 17244200!
printBezierStats
"BalloonEngine printBezierStats"
"BalloonEngine resetBezierStats"
Transcript 
cr; nextPutAll:'Bezier statistics:';
crtab; print: (BezierStats at: 1); tab; nextPutAll:' 
non-monoton curves splitted';
crtab; print: (BezierStats at: 2); tab; nextPutAll:' curves 
splitted for numerical accuracy';
crtab; print: (BezierStats at: 3); tab; nextPutAll:' curves 
splitted to avoid integer overflow';
crtab; print: (BezierStats at: 4); tab; nextPutAll:' curves 
internally converted to lines';
endEntry.! !
!BalloonEngine class methodsFor: 'accessing' stamp: 'ar 10/28/1998 23:59' 
prior: 17244801!
printStat: time count: n string: aString
Transcript
cr;
print: time; tab;
nextPutAll:' mSecs -- ';
print: n; tab;
nextPutAll:' ops -- ';
print: ((time asFloat / (n max: 1) asFloat) roundTo: 0.01); tab;
nextPutAll: ' avg. mSecs/op -- ';
nextPutAll: aString.! !
!BalloonEngine class methodsFor: 'accessing' stamp: 'ar 1/12/1999 10:52' prior: 
17245153!
printStats
"BalloonEngine doProfileStats: true"
"BalloonEngine printStats"
"BalloonEngine resetStats"
Transcript cr; nextPutAll:'/** BalloonEngine statistics 
/'.
self printStat: (Times at: 1) count: (Counts at: 1) string: 
'Initialization'.
self printStat: (Times at: 2) count: (Counts at: 2) string: 'Finish 
test'.
self printStat: (Times at: 3) count: (Counts at: 3) string: 
'Fetching/Adding GET entries'.
self printStat: (Times at: 4) count: (Counts at: 4) string: 'Adding AET 
entries'.
self printStat: (Times at: 5) count: (Counts at: 5) string: 
'Fetching/Computing fills'.
self printStat: (Times at: 6) count: (Counts at: 6) string: 'Merging 
fills'.
self printStat: (Times at: 7) count: (Counts at: 7) string: 'Displaying 
span buffer'.
self printStat: (Times at: 8) count: (Counts at: 8) string: 
'Fetching/Updating AET entries'.
self printStat: (Times at: 9) count: (Counts at: 9) string: 'Changing 
AET entries'.
Transcript cr; print: Times sum; nextPutAll:' mSecs for all operations'.
Transcript cr; print: Counts sum; nextPutAll: ' overall operations'.
Transcript endEntry.! !
!BalloonEngine class methodsFor: 'accessing' stamp: 'ar 10/30/1998 23:57' 
prior: 17246355!
resetBezierStats
BezierStats := WordArray new: 4.! !
!BalloonEngine class methodsFor: 'accessing' stamp: 'ar 10/28/1998 23:38' 
prior: 17246485!
resetStats
Times := WordArray new: 10.
Counts := WordArray new: 10.! !
!BalloonEngine class methodsFor: 'class initialization

[pypy-commit] lang-smalltalk storage: Fixed an initialization issue

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r914:a742cab321c8
Date: 2014-07-15 23:51 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/a742cab321c8/

Log:Fixed an initialization issue

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -614,8 +614,8 @@
 
 def switch_shadow(self, new_shadow, w_element=None):
 old_shadow = self.assert_shadow()
+self.store_shadow(new_shadow)
 old_shadow.copy_into(new_shadow)
-self.store_shadow(new_shadow)
 new_shadow.attach_shadow()
 self.log_storage("Switched", old_shadow, w_element=w_element)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Improved crash report when running in headless mode.

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r910:9a0c4bf44ab6
Date: 2014-07-14 18:42 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/9a0c4bf44ab6/

Log:Improved crash report when running in headless mode. Refactored
flushCache primitive to walk the GC roots with less memory overhead.
Not allocating huge lists containing all objects, instead walking
recursively.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -224,7 +224,7 @@
 s_frame.push(w_receiver)
 s_frame.push_all(list(w_arguments))
 return s_frame
-
+
 # == Methods for tracing, printing and debugging ==
 
 def activate_trace(self, trace_depth=0):
@@ -585,7 +585,7 @@
 w_method = receiverclassshadow.lookup(w_selector)
 except MethodNotFound:
 return self._doesNotUnderstand(w_selector, argcount, interp, 
receiver)
-
+
 code = w_method.primitive()
 if code:
 if w_arguments:
@@ -615,7 +615,7 @@
 s_class = receiver.class_shadow(self.space)
 w_method = s_class.lookup(w_special_selector)
 s_frame = w_method.create_frame(interp.space, receiver, w_args)
-
+
 # 
##
 if interp.is_tracing():
 interp.print_padded('-> %s %s' % (special_selector, 
s_frame.short_str()))
@@ -635,13 +635,15 @@
 self.pop() # The receiver, already known.
 
 try:
+if interp.space.headless.is_set():
+primitives.exitFromHeadlessExecution(self, 
"doesNotUnderstand:", w_message)
 return self._sendSpecialSelector(interp, receiver, 
"doesNotUnderstand", [w_message])
 except MethodNotFound:
 from spyvm.shadow import ClassShadow
 s_class = receiver.class_shadow(self.space)
 assert isinstance(s_class, ClassShadow)
-print "Missing doesNotUnderstand in hierarchy of %s" % 
s_class.getname()
-raise
+from spyvm import error
+raise error.Exit("Missing doesNotUnderstand in hierarchy of %s" % 
s_class.getname())
 
 def _mustBeBoolean(self, interp, receiver):
 return self._sendSpecialSelector(interp, receiver, "mustBeBoolean")
@@ -665,11 +667,11 @@
 def _return(self, return_value, interp, local_return=False):
 # unfortunately, this assert is not true for some tests. TODO fix this.
 # assert self._stack_ptr == self.tempsize()
-
+
 # ##
 if interp.is_tracing():
 interp.print_padded('<- ' + return_value.as_repr_string())
-
+
 if self.home_is_self() or local_return:
 # a local return just needs to go up the stack once. there
 # it will find the sender as a local, and we don't have to
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -6,7 +6,7 @@
 from spyvm.error import PrimitiveFailedError, PrimitiveNotYetWrittenError
 from spyvm import wrapper
 
-from rpython.rlib import rarithmetic, rfloat, unroll, jit
+from rpython.rlib import rarithmetic, rfloat, unroll, jit, objectmodel
 
 def assert_class(interp, w_obj, w_class):
 if not w_obj.getclass(interp.space).is_same_object(w_class):
@@ -375,30 +375,34 @@
 return w_obj.as_string()
 return w_obj.as_repr_string()
 
+def exitFromHeadlessExecution(s_frame, selector="", w_message=None):
+if not objectmodel.we_are_translated():
+import pdb; pdb.set_trace()
+print "== Receiver: %s" % s_frame.w_receiver().as_repr_string()
+if isinstance(w_message, model.W_PointersObject):
+fields = w_message.fetch_all(s_frame.space)
+if len(fields) >= 1:
+print "== Selector: %s" % get_string(fields[0])
+if len(fields) >= 2:
+w_args = fields[1]
+if isinstance(w_args, model.W_PointersObject):
+arg_strings = [ get_string(w_arg) for w_arg in 
w_args.fetch_all(s_frame.space) ]
+if len(arg_strings) > 0:
+print "== Arguments: %s" % ', '.join(arg_strings)
+print "== Smalltalk Stack:%s" % s_frame.print_stack()
+if selector == "":
+selector = s_frame.w_method().lookup_selector
+raise error.Exit("Unhandled %s in headless mode." % selector)
+
 @expose_primitive(FAIL)
 def func(interp, s_frame, argcount):
-if interp.space.headless.is_set() and s_frame.w_method().lookup_selector 
== 'doesNotUnderstand:':
-print "== Error message: %s" % get_string(s_frame.peek(1))
-print "== Receiver: %s" % s_frame.w_receiver().as_repr_string()
-w_arguments = s_frame.w_arguments()
-if len(w_arguments) >= 1:
-w_message = w_arguments[0]
-if isinstance(w_messa

[pypy-commit] lang-smalltalk storage: Moved SenderChainManipulation exception to interpreter.py, as subclass of ContextSwitchException.

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r917:25b23527e013
Date: 2014-07-18 13:34 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/25b23527e013/

Log:Moved SenderChainManipulation exception to interpreter.py, as
subclass of ContextSwitchException. Catching SenderChainManipulation
explicitely in toplevel loop. Added "sender is not new_sender"
condition to raising SenderChainManipulation. Fixed test.

diff --git a/spyvm/error.py b/spyvm/error.py
--- a/spyvm/error.py
+++ b/spyvm/error.py
@@ -30,7 +30,3 @@
 _attrs_ = ["msg"]
 def __init__(self, msg):
 self.msg = msg
-
-class SenderChainManipulation(Exception):
-def __init__(self, manipulated_context):
-self.s_context = manipulated_context
diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -70,6 +70,10 @@
 if self.is_tracing():
 print "== StackOverflow, contexts forced to heap at: 
%s" % e.s_new_context.short_str()
 s_new_context = e.s_new_context
+except SenderChainManipulation, e:
+if self.is_tracing():
+print "== SenderChainManipulation, contexts forced to 
heap at: %s" % e.s_new_context.short_str()
+s_new_context = e.s_new_context
 except Return, nlr:
 assert nlr.s_target_context or nlr.is_local
 s_new_context = s_sender
@@ -198,13 +202,13 @@
 
 def interpret_toplevel(self, w_frame):
 try:
+self.interrupt_check_counter = self.interrupt_counter_size
 self.loop(w_frame)
 except ReturnFromTopLevel, e:
 return e.object
 
 def perform(self, w_receiver, selector="", w_selector=None, 
w_arguments=[]):
 s_frame = self.create_toplevel_context(w_receiver, selector, 
w_selector, w_arguments)
-self.interrupt_check_counter = self.interrupt_counter_size
 return self.interpret_toplevel(s_frame.w_self())
 
 def create_toplevel_context(self, w_receiver, selector="", 
w_selector=None, w_arguments=[]):
@@ -276,13 +280,18 @@
 self.s_new_context = s_new_context
 
 class StackOverflow(ContextSwitchException):
-"""This causes the current jit-loop to be left, thus avoiding stack 
overflows.
+"""This causes the current jit-loop to be left, dumping all virtualized 
objects to the heap.
 This breaks performance, so it should rarely happen.
 In case of severe performance problems, execute with -t and check if this 
occurrs."""
 
 class ProcessSwitch(ContextSwitchException):
-"""This causes the interpreter to switch the executed context."""
+"""This causes the interpreter to switch the executed context.
+Triggered when switching the process."""
 
+class SenderChainManipulation(ContextSwitchException):
+"""Manipulation of the sender chain can invalidate the jitted C stack.
+We have to dump all virtual objects and rebuild the stack.
+We try to raise this as rarely as possible and as late as possible."""
 
 import rpython.rlib.unroll
 if hasattr(unroll, "unrolling_zero"):
@@ -753,15 +762,16 @@
 association = wrapper.AssociationWrapper(self.space, w_association)
 self.push(association.value())
 elif opType == 5:
+# TODO - the following two special cases should not be necessary
 try:
 self.w_receiver().store(self.space, third, self.top())
-except error.SenderChainManipulation, e:
-raise StackOverflow(self)
+except SenderChainManipulation, e:
+raise SenderChainManipulation(self)
 elif opType == 6:
 try:
 self.w_receiver().store(self.space, third, self.pop())
-except error.SenderChainManipulation, e:
-raise StackOverflow(self)
+except SenderChainManipulation, e:
+raise SenderChainManipulation(self)
 elif opType == 7:
 w_association = self.w_method().getliteral(third)
 association = wrapper.AssociationWrapper(self.space, w_association)
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -659,10 +659,11 @@
 self.instances_w = {}
 
 def copy_field_from(self, n0, other_shadow):
+from spyvm.interpreter import SenderChainManipulation
 try:
 AbstractRedirectingShadow.copy_field_from(self, n0, other_shadow)
-except error.SenderChainManipulation, e:
-assert e.s_context == self
+except SenderChainManipulation, e:
+assert e.s_new_context == self
 
 def copy_from(self, other_shadow):
 # Some fields have to be initialized before the rest, to ensure 
correct initialization.
@@ -725,9 +726,11 @@
 # === Sender ===
 
 def store_s_sender(self, s_sender, raise_error=True):
-self._s_sen

[pypy-commit] lang-smalltalk storage: Merged.

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r919:8c1727512fd2
Date: 2014-07-18 13:50 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/8c1727512fd2/

Log:Merged. Removed configurable trace depth (unnecessary).

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -35,7 +35,7 @@
 )
 
 def __init__(self, space, image=None, image_name="",
-trace_depth=-1, evented=True, interrupts=True):
+trace=False, evented=True, interrupts=True):
 # === Initialize immutable variables
 self.space = space
 self.image = image
@@ -54,7 +54,7 @@
 # === Initialize mutable variables
 self.interrupt_check_counter = self.interrupt_counter_size
 self.next_wakeup_tick = 0
-self.trace_depth = trace_depth
+self.trace = trace
 self.trace_proxy = objspace.ConstantFlag()
 self.stack_depth = 0
 
@@ -230,21 +230,13 @@
 return s_frame
 
 # == Methods for tracing, printing and debugging ==
-
-def activate_trace(self, trace_depth=0):
-self.trace_depth = trace_depth
-
-def deactivate_trace(self):
-self.trace_depth = -1
-
+
 def is_tracing(self):
-return jit.promote(self.trace_depth) >= 0
-
+return jit.promote(self.trace)
+
 def print_padded(self, str):
-depth = jit.promote(self.trace_depth)
-assert depth >= 0
-if self.stack_depth <= depth:
-print (' ' * self.stack_depth) + str
+assert self.is_tracing()
+print (' ' * self.stack_depth) + str
 
 def activate_debug_bytecode(self):
 "NOT_RPYTHON"
diff --git a/spyvm/plugins/vmdebugging.py b/spyvm/plugins/vmdebugging.py
--- a/spyvm/plugins/vmdebugging.py
+++ b/spyvm/plugins/vmdebugging.py
@@ -10,12 +10,12 @@
 
 @DebuggingPlugin.expose_primitive(unwrap_spec=[object])
 def trace(interp, s_frame, w_rcvr):
-interp.activate_trace()
+interp.trace = True
 return w_rcvr
 
 @DebuggingPlugin.expose_primitive(unwrap_spec=[object])
 def untrace(interp, s_frame, w_rcvr):
-interp.deactivate_trace()
+interp.trace = False
 return w_rcvr
 
 @DebuggingPlugin.expose_primitive(unwrap_spec=[object])
diff --git a/spyvm/test/test_largeinteger.py b/spyvm/test/test_largeinteger.py
--- a/spyvm/test/test_largeinteger.py
+++ b/spyvm/test/test_largeinteger.py
@@ -8,7 +8,7 @@
 space, interp, _, _ = read_image('bootstrapped.image')
 w = space.w
 copy_to_module(locals(), __name__)
-interp.deactivate_trace()
+interp.trace = False
 space.initialize_class(space.w_String, interp)
 
 def teardown_module():
@@ -38,10 +38,7 @@
 except Exception:
 w_selector = find_symbol_in_methoddict_of(selector, 
w(intmask(candidates[0])).getclass(space).shadow)
 
-if trace:
-interp.activate_trace()
-else:
-interp.deactivate_trace()
+interp.trace = trace
 for i, v in enumerate(candidates):
 x = w_l(v)
 if j is None:
@@ -53,7 +50,7 @@
 y = w_l(j)
 z = perform_primitive(x, w_selector, y)
 assert r_uint(z.value) == r_uint(operation(v, y.value))
-interp.deactivate_trace()
+interp.trace = False
 
 def test_bitAnd():
 do_primitive("bitAnd:", operator.and_)
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -12,7 +12,7 @@
 
 def _usage(argv):
 print """
-Usage: %s  [-r|-m|-h] [-naPu] [-jpiS] [-tTlLE]
+Usage: %s  [-r|-m|-h] [-naPu] [-jpiS] [-tlLE]
  - image path (default: Squeak.image)
 
   Execution mode:
@@ -39,7 +39,6 @@
 
   Logging parameters:
 -t|--trace - Output a trace of each message, 
primitive, return value and process switch.
--T  - Like -t, but limit the stack depth 
for the trace to .
 -l|--storage-log   - Output a log of storage operations.
 -L|--storage-log-aggregate - Output an aggregated storage log at 
the end of execution.
 -E|--storage-log-elements  - Include classnames of elements into 
the storage log.
@@ -89,7 +88,7 @@
 # == Other parameters
 poll = False
 interrupts = True
-trace_depth = -1
+trace = False
 
 space = prebuilt_space
 idx = 1
@@ -109,11 +108,7 @@
 elif arg in ["-m", "--method"]:
 selector, idx = get_parameter(argv, idx, arg)
 elif arg in ["-t", "--trace"]:
-trace_depth = sys.maxint
-elif arg in ["-T"]:
-trace_depth, idx = get_int_parameter(argv, idx, arg)
-if trace_depth < 0:
-raise error.Exit("Need argument >= 0 for -T.")
+trace = True
 elif arg in ["-p", "--pol

[pypy-commit] lang-smalltalk storage: Printing stack trace in non-translated mode

2014-07-18 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r918:2a1d5616e87f
Date: 2014-07-18 13:38 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/2a1d5616e87f/

Log:Printing stack trace in non-translated mode

diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -3,7 +3,7 @@
 import os
 
 from rpython.rlib.streamio import open_file_as_stream
-from rpython.rlib import jit, rpath
+from rpython.rlib import jit, rpath, objectmodel
 
 from spyvm import model, interpreter, squeakimage, objspace, wrapper,\
 error, shadow, storage_logger, constants
@@ -72,6 +72,9 @@
 return -1
 except Exception, e:
 print_error("Exception: %s" % str(e))
+if not objectmodel.we_are_translated():
+import traceback
+traceback.print_exc()
 return -1
 
 def entry_point(argv):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-context-state: Fixed tests, added tests.

2014-07-19 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state
Changeset: r922:2d1854d40231
Date: 2014-07-18 15:29 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/2d1854d40231/

Log:Fixed tests, added tests.

diff --git a/spyvm/test/test_interpreter.py b/spyvm/test/test_interpreter.py
--- a/spyvm/test/test_interpreter.py
+++ b/spyvm/test/test_interpreter.py
@@ -978,9 +978,32 @@
 2, "value:value:"]],
 test)
 
-def test_c_stack_reset_on_sender_chain_manipulation():
-bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00]))
+def test_frame_dirty_if_active():
+bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00])) + 
returnReceiverBytecode
 w_frame, s_frame = new_frame(bytes)
 s_frame.store_w_receiver(w_frame)
 s_frame.push(w_frame)
-py.test.raises(interpreter.SenderChainManipulation, step_in_interp, 
s_frame)
+s_frame.state = shadow.ActiveContext
+step_in_interp(s_frame)
+assert s_frame.state is shadow.DirtyContext
+
+def test_frame_not_dirty_if_inactive():
+bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00])) + 
returnReceiverBytecode
+w_frame, s_frame = new_frame(bytes)
+w_other_frame, s_other_frame = new_frame("")
+s_frame.store_w_receiver(w_other_frame)
+s_frame.push(w_frame)
+s_frame.state = shadow.ActiveContext
+step_in_interp(s_frame)
+assert s_frame.state is shadow.ActiveContext
+assert s_other_frame.state is shadow.InactiveContext
+
+def test_raise_SenderManipulation_on_dirty_frame():
+w_frame, s_frame = new_frame(returnReceiverBytecode)
+s_frame.state = shadow.DirtyContext
+def run_frame():
+#import pdb; pdb.set_trace()
+interp._loop = True
+interp.stack_frame(s_frame, None)
+py.test.raises(interpreter.SenderChainManipulation, run_frame)
+
\ No newline at end of file
diff --git a/spyvm/test/test_zin_squeak_4_5_image.py 
b/spyvm/test/test_zin_squeak_4_5_image.py
--- a/spyvm/test/test_zin_squeak_4_5_image.py
+++ b/spyvm/test/test_zin_squeak_4_5_image.py
@@ -43,7 +43,7 @@
 # create a frame for our newly crafted method with a valid sender (to 
avoid raising returnFromTop to early)
 s_initial_frame = create_method(chr(0x7c)).create_frame(space, w(0), [])
 s_frame = w_method.create_frame(space, w(0))
-s_frame.store_s_sender(s_initial_frame, raise_error=False)
+s_frame.store_s_sender(s_initial_frame)
 
 try:
 interp.loop(s_frame.w_self())
@@ -70,7 +70,7 @@
 # create a frame for our newly crafted method with a valid sender (to 
avoid raising returnFromTop to early)
 s_initial_frame = create_method(chr(0x7c)).create_frame(space, w(0))
 s_frame = w_method.create_frame(space, w(0))
-s_frame.store_s_sender(s_initial_frame, raise_error=False)
+s_frame.store_s_sender(s_initial_frame)
 
 try:
 interp.loop(s_frame.w_self())
diff --git a/spyvm/test/util.py b/spyvm/test/util.py
--- a/spyvm/test/util.py
+++ b/spyvm/test/util.py
@@ -85,7 +85,7 @@
 if not self._loop:
 # this test is done to not loop in test, but rather step just once 
where wanted
 # Unfortunately, we have to mimick some of the original behaviour.
-s_new_frame.store_s_sender(s_sender, raise_error=False)
+s_new_frame.store_s_sender(s_sender)
 return s_new_frame
 return interpreter.Interpreter.stack_frame(self, s_new_frame, 
s_sender, may_context_switch)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-context-state: Fixed ensure: mechanism. Fixed test.

2014-07-19 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state
Changeset: r924:f5b3945a1fdc
Date: 2014-07-19 13:48 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/f5b3945a1fdc/

Log:Fixed ensure: mechanism. Fixed test.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -819,10 +819,8 @@
 self.push(self.gettemp(0)) # push the first argument
 try:
 self.bytecodePrimValue(interp, 0)
-except Return, nlr:
-assert nlr.s_target_context or nlr.is_local
-if self is not nlr.s_target_context and not nlr.is_local:
-raise nlr
+except LocalReturn, ret:
+pass # Local return value of ensure: block is ignored
 finally:
 self.mark_returned()
 
diff --git a/spyvm/test/test_interpreter.py b/spyvm/test/test_interpreter.py
--- a/spyvm/test/test_interpreter.py
+++ b/spyvm/test/test_interpreter.py
@@ -979,7 +979,7 @@
 test)
 
 def test_frame_dirty_if_active():
-bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00])) + 
returnReceiverBytecode
+bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00]))
 w_frame, s_frame = new_frame(bytes)
 s_frame.store_w_receiver(w_frame)
 s_frame.push(w_frame)
@@ -988,7 +988,7 @@
 assert s_frame.state is shadow.DirtyContext
 
 def test_frame_not_dirty_if_inactive():
-bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00])) + 
returnReceiverBytecode
+bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00]))
 w_frame, s_frame = new_frame(bytes)
 w_other_frame, s_other_frame = new_frame("")
 s_frame.store_w_receiver(w_other_frame)
@@ -998,12 +998,14 @@
 assert s_frame.state is shadow.ActiveContext
 assert s_other_frame.state is shadow.InactiveContext
 
-def test_raise_SenderManipulation_on_dirty_frame():
-w_frame, s_frame = new_frame(returnReceiverBytecode)
-s_frame.state = shadow.DirtyContext
-def run_frame():
-#import pdb; pdb.set_trace()
-interp._loop = True
+def test_raise_NonVirtualReturn_on_dirty_frame():
+bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00])) + 
returnTopFromMethodBytecode
+w_frame, s_frame = new_frame(bytes)
+s_frame.store_w_receiver(w_frame)
+s_frame.push(w_frame)
+
+interp._loop = True
+def do_test():
 interp.stack_frame(s_frame, None)
-py.test.raises(interpreter.SenderChainManipulation, run_frame)
+py.test.raises(interpreter.NonVirtualReturn, do_test)
 
\ No newline at end of file
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Refactoring, reduced code duplication.

2014-07-19 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r920:2dd2b3555772
Date: 2014-07-18 14:21 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/2dd2b3555772/

Log:Refactoring, reduced code duplication.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -66,13 +66,9 @@
 try:
 self.loop_bytecodes(s_new_context)
 raise Exception("loop_bytecodes left without raising...")
-except StackOverflow, e:
+except ContextSwitchException, e:
 if self.is_tracing():
-print "== StackOverflow, contexts forced to heap at: 
%s" % e.s_new_context.short_str()
-s_new_context = e.s_new_context
-except SenderChainManipulation, e:
-if self.is_tracing():
-print "== SenderChainManipulation, contexts forced to 
heap at: %s" % e.s_new_context.short_str()
+e.print_trace(s_new_context)
 s_new_context = e.s_new_context
 except Return, nlr:
 assert nlr.s_target_context or nlr.is_local
@@ -83,13 +79,7 @@
 s_new_context._activate_unwind_context(self)
 s_new_context = s_sender
 s_new_context.push(nlr.value)
-except ProcessSwitch, p:
-assert not self.space.suppress_process_switch.is_set(), 
"ProcessSwitch should be disabled..."
-if self.is_tracing():
-print "== Switched process from: %s" % 
s_new_context.short_str()
-print "== to: %s " % p.s_new_context.short_str()
-s_new_context = p.s_new_context
-
+
 def loop_bytecodes(self, s_context, may_context_switch=True):
 old_pc = 0
 if not jit.we_are_jitted() and may_context_switch:
@@ -267,23 +257,34 @@
 class ContextSwitchException(Exception):
 """General Exception that causes the interpreter to leave
 the current context."""
+
 _attrs_ = ["s_new_context"]
+type = "ContextSwitch"
 def __init__(self, s_new_context):
 self.s_new_context = s_new_context
-
+
+def print_trace(self, old_context):
+print "== %s, contexts forced to heap at: %s" % (self.type, 
self.s_new_context.short_str())
+
 class StackOverflow(ContextSwitchException):
 """This causes the current jit-loop to be left, dumping all virtualized 
objects to the heap.
 This breaks performance, so it should rarely happen.
 In case of severe performance problems, execute with -t and check if this 
occurrs."""
-
+type = "Stack Overflow"
+
 class ProcessSwitch(ContextSwitchException):
 """This causes the interpreter to switch the executed context.
 Triggered when switching the process."""
-
+
+def print_trace(self, old_context):
+print "== Switched process from: %s" % old_context.short_str()
+print "== to: %s " % self.s_new_context.short_str()
+
 class SenderChainManipulation(ContextSwitchException):
 """Manipulation of the sender chain can invalidate the jitted C stack.
 We have to dump all virtual objects and rebuild the stack.
 We try to raise this as rarely as possible and as late as possible."""
+type = "Sender Manipulation"
 
 import rpython.rlib.unroll
 if hasattr(unroll, "unrolling_zero"):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-context-state: Delaying SenderChainManipulation as much as possible.

2014-07-19 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state
Changeset: r921:76c81645836d
Date: 2014-07-18 15:29 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/76c81645836d/

Log:Delaying SenderChainManipulation as much as possible. Added a
'state' field to Context objects, can be Inactive, Active or Dirty.
Setting the sender of an Active context makes it Dirty. When a Dirty
context is left, SenderChainManipulation will be raised, forcing all
remaining contexts from the stack to the heap.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -1,6 +1,6 @@
 import py
 import os
-from spyvm.shadow import ContextPartShadow, MethodContextShadow, 
BlockContextShadow, MethodNotFound
+from spyvm.shadow import ContextPartShadow, MethodContextShadow, 
BlockContextShadow, MethodNotFound, ActiveContext, InactiveContext, DirtyContext
 from spyvm import model, constants, primitives, conftest, wrapper, objspace
 from spyvm.tool.bitmanipulation import splitter
 
@@ -118,8 +118,10 @@
 if self.is_tracing():
 self.stack_depth += 1
 if s_frame._s_sender is None and s_sender is not None:
-s_frame.store_s_sender(s_sender, raise_error=False)
+s_frame.store_s_sender(s_sender)
 # Now (continue to) execute the context bytecodes
+assert s_frame.state is InactiveContext
+s_frame.state = ActiveContext
 self.loop_bytecodes(s_frame, may_context_switch)
 except rstackovf.StackOverflow:
 rstackovf.check_stack_overflow()
@@ -127,7 +129,11 @@
 finally:
 if self.is_tracing():
 self.stack_depth -= 1
-
+dirty_frame = s_frame.state is DirtyContext
+s_frame.state = InactiveContext
+if dirty_frame:
+raise SenderChainManipulation(s_frame)
+
 def step(self, context):
 bytecode = context.fetch_next_bytecode()
 for entry in UNROLLING_BYTECODE_RANGES:
@@ -755,16 +761,9 @@
 association = wrapper.AssociationWrapper(self.space, w_association)
 self.push(association.value())
 elif opType == 5:
-# TODO - the following two special cases should not be necessary
-try:
-self.w_receiver().store(self.space, third, self.top())
-except SenderChainManipulation, e:
-raise SenderChainManipulation(self)
+self.w_receiver().store(self.space, third, self.top())
 elif opType == 6:
-try:
-self.w_receiver().store(self.space, third, self.pop())
-except SenderChainManipulation, e:
-raise SenderChainManipulation(self)
+self.w_receiver().store(self.space, third, self.pop())
 elif opType == 7:
 w_association = self.w_method().getliteral(third)
 association = wrapper.AssociationWrapper(self.space, w_association)
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -636,18 +636,29 @@
 def size(self):
 return self._w_self_size
 
+class ContextState(object):
+def __init__(self, name):
+self.name = name
+def __str__(self):
+return self.name
+def __repr__(self):
+return self.name
+InactiveContext = ContextState("InactiveContext")
+ActiveContext = ContextState("ActiveContext")
+DirtyContext = ContextState("DirtyContext")
+
 class ContextPartShadow(AbstractRedirectingShadow):
 
 __metaclass__ = extendabletype
 _attrs_ = ['_s_sender',
 '_pc', '_temps_and_stack',
-'_stack_ptr', 'instances_w']
+'_stack_ptr', 'instances_w', 'state']
 repr_classname = "ContextPartShadow"
 
 _virtualizable_ = [
 '_s_sender',
 "_pc", "_temps_and_stack[*]", "_stack_ptr",
-"_w_self", "_w_self_size"
+"_w_self", "_w_self_size", 'state'
 ]
 
 # __
@@ -657,13 +668,7 @@
 self._s_sender = None
 AbstractRedirectingShadow.__init__(self, space, w_self, size)
 self.instances_w = {}
-
-def copy_field_from(self, n0, other_shadow):
-from spyvm.interpreter import SenderChainManipulation
-try:
-AbstractRedirectingShadow.copy_field_from(self, n0, other_shadow)
-except SenderChainManipulation, e:
-assert e.s_new_context == self
+self.state = InactiveContext
 
 def copy_from(self, other_shadow):
 # Some fields have to be initialized before the rest, to ensure 
correct initialization.
@@ -705,7 +710,7 @@
 if n0 == constants.CTXPART_SENDER_INDEX:
 assert isinstance(w_value, model.W_PointersObject)
 if w_value.is_nil(self.space):
-self.store_s_sender(None, raise_error=False)
+   

[pypy-commit] lang-smalltalk storage-context-state: Refactored Return-mechanism to make the context state and late sender-chain-manipulation refactoring work.

2014-07-19 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state
Changeset: r923:a27bd7d3d458
Date: 2014-07-19 13:15 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/a27bd7d3d458/

Log:Refactored Return-mechanism to make the context state and late
sender-chain-manipulation refactoring work. Added LocalReturn class.
stack_frame() handles dispatching of Return types, always invoked
together with loop_bytecodes now.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -60,25 +60,58 @@
 
 def loop(self, w_active_context):
 # This is the top-level loop and is not invoked recursively.
-s_new_context = w_active_context.as_context_get_shadow(self.space)
+s_context = w_active_context.as_context_get_shadow(self.space)
 while True:
-s_sender = s_new_context.s_sender()
+s_sender = s_context.s_sender()
 try:
-self.loop_bytecodes(s_new_context)
+self.stack_frame(s_context, None)
 raise Exception("loop_bytecodes left without raising...")
 except ContextSwitchException, e:
 if self.is_tracing():
-e.print_trace(s_new_context)
-s_new_context = e.s_new_context
-except Return, nlr:
-assert nlr.s_target_context or nlr.is_local
-s_new_context = s_sender
-if not nlr.is_local:
-while s_new_context is not nlr.s_target_context:
-s_sender = s_new_context.s_sender()
-s_new_context._activate_unwind_context(self)
-s_new_context = s_sender
-s_new_context.push(nlr.value)
+e.print_trace()
+s_context = e.s_new_context
+except LocalReturn, ret:
+s_context = self.unwind_context_chain(s_sender, s_sender, 
ret.value)
+except Return, ret:
+s_context = self.unwind_context_chain(s_sender, 
ret.s_target_context, ret.value)
+except NonVirtualReturn, ret:
+if self.is_tracing():
+ret.print_trace()
+s_context = self.unwind_context_chain(ret.s_current_context, 
ret.s_target_context, ret.value)
+
+# This is a wrapper around loop_bytecodes that cleanly enters/leaves the 
frame,
+# handles the stack overflow protection mechanism and handles/dispatches 
Returns.
+def stack_frame(self, s_frame, s_sender, may_context_switch=True):
+try:
+if self.is_tracing():
+self.stack_depth += 1
+if s_frame._s_sender is None and s_sender is not None:
+s_frame.store_s_sender(s_sender)
+# Now (continue to) execute the context bytecodes
+assert s_frame.state is InactiveContext
+s_frame.state = ActiveContext
+self.loop_bytecodes(s_frame, may_context_switch)
+except rstackovf.StackOverflow:
+rstackovf.check_stack_overflow()
+raise StackOverflow(s_frame)
+except Return, e:
+# Do not catch NonVirtualReturn. If there are multiple dirty 
contexts
+# on the stack, the inner-most one will count.
+if s_frame.state is DirtyContext:
+s_sender = s_frame.s_sender()
+s_frame._activate_unwind_context(self)
+target_context = s_sender if e.is_local else e.s_target_context
+raise NonVirtualReturn(target_context, e.value, s_sender)
+else:
+s_frame._activate_unwind_context(self)
+if e.s_target_context is s_sender or e.is_local:
+raise LocalReturn(e.value)
+else:
+raise e
+finally:
+if self.is_tracing():
+self.stack_depth -= 1
+s_frame.state = InactiveContext
 
 def loop_bytecodes(self, s_context, may_context_switch=True):
 old_pc = 0
@@ -100,39 +133,22 @@
 s_context=s_context)
 try:
 self.step(s_context)
-except Return, nlr:
-if nlr.s_target_context is s_context or nlr.is_local:
-s_context.push(nlr.value)
-else:
-if nlr.s_target_context is None:
-# This is the case where we are returning to our 
sender.
-# Mark the return as local, so our sender will take it
-nlr.is_local = True
-s_context._activate_unwind_context(self)
-raise nlr
-
-# This is a wrapper around loop_bytecodes that cleanly enters/leaves the 
frame
-# and handles the stack overflow protection mechanism.
-def stack_frame(self, s_frame, s_sender, may_context_switch=True):
-  

[pypy-commit] lang-smalltalk storage-gcrefs: Extracted walking of gc references in separate module.

2014-07-21 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-gcrefs
Changeset: r925:8476f6a16d21
Date: 2014-07-21 11:10 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/8476f6a16d21/

Log:Extracted walking of gc references in separate module. Implemented
walking the heap correctly without collecting a huge list of all
objects. someInstance primitive still fails in interpreted mode, due
to MemoryError in get_rpy_roots(). Don't see a way to fix except to
go 64 bit. Translated version segfaults.

diff --git a/spyvm/gcrefs.py b/spyvm/gcrefs.py
new file mode 100644
--- /dev/null
+++ b/spyvm/gcrefs.py
@@ -0,0 +1,67 @@
+
+from rpython.rlib import rgc, objectmodel, jit
+
+#  Internal functions 
+
+def flag(gcref):
+return rgc.get_gcflag_extra(gcref)
+
+def toggle_flag(gcref):
+rgc.toggle_gcflag_extra(gcref)
+
+def references(gcref):
+return rgc.get_rpy_referents(gcref)
+
+def gc_roots():
+return rgc.get_rpy_roots()
+
+def _clear_all_flags(gcrefs):
+for gcref in gcrefs:
+if gcref and flag(gcref):
+toggle_flag(gcref)
+_clear_all_flags(references(gcref))
+
+def _walk_gc_references(func, extra_parameter, collect_into, gcrefs):
+for gcref in gcrefs:
+if gcref and not flag(gcref):
+toggle_flag(gcref)
+result = func(gcref, extra_parameter)
+if result is not None:
+collect_into.append(result)
+_walk_gc_references(func, extra_parameter, collect_into, 
references(gcref))
+return collect_into
+
+#  API of this module 
+# The extra_parameter is here to avoid creating closures in the function 
parameters,
+# and still be able to pass some context into the functions. It should always 
be a short tuple,
+# so that rpython can autmatically specialize these functions. If it fails to 
do so, annotate
+# all functions with extra_parameter with @objectmodel.specialize.argtype(2).
+
+def try_cast(type, gcref):
+return rgc.try_cast_gcref_to_instance(type, gcref)
+
+@jit.dont_look_inside
+def walk_gc_references(func, extra_parameter = None):
+roots = gc_roots()
+result = _walk_gc_references(func, extra_parameter, [], roots)
+_clear_all_flags(roots)
+_clear_all_flags(gc_roots()) # Just in case
+return result
+
+def walk_gc_references_of_type(type, func, extra_parameter = None):
+def check_type(gcref, extra):
+type, func, extra_parameter = extra
+w_obj = try_cast(type, gcref)
+if w_obj:
+func(w_obj, extra_parameter)
+return None
+walk_gc_references(check_type, (type, func, extra_parameter))
+
+def collect_gc_references_of_type(type, filter_func = lambda obj, extra: True, 
extra_parameter = None):
+def check_type(gcref, extra):
+type, filter_func, extra_parameter = extra
+w_obj = try_cast(type, gcref)
+if w_obj and filter_func(w_obj, extra_parameter):
+return w_obj
+return None
+return walk_gc_references(check_type, (type, filter_func, extra_parameter))
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -4,7 +4,7 @@
 import operator
 from spyvm import model, shadow, error, constants, display
 from spyvm.error import PrimitiveFailedError, PrimitiveNotYetWrittenError
-from spyvm import wrapper
+from spyvm import wrapper, gcrefs
 
 from rpython.rlib import rarithmetic, rfloat, unroll, jit, objectmodel
 
@@ -540,43 +540,25 @@
 w_frame.store(interp.space, constants.CTXPART_STACKP_INDEX, 
interp.space.wrap_int(stackp))
 return w_frame
 
-
 def stm_enabled():
 """NOT RPYTHON"""
 from rpython.rlib import rgc
 return hasattr(rgc, "stm_is_enabled") and rgc.stm_is_enabled()
+
 if stm_enabled():
 def get_instances_array(space, s_frame, w_class):
 return []
 else:
 def get_instances_array(space, s_frame, w_class):
-# This primitive returns some instance of the class on the stack.
-# Not sure quite how to do this; maintain a weak list of all
-# existing instances or something?
-match_w = s_frame.instances_array(w_class)
-if match_w is None:
-match_w = []
-from rpython.rlib import rgc
-
-roots = [gcref for gcref in rgc.get_rpy_roots() if gcref]
-pending = roots[:]
-while pending:
-gcref = pending.pop()
-if not rgc.get_gcflag_extra(gcref):
-rgc.toggle_gcflag_extra(gcref)
-w_obj = rgc.try_cast_gcref_to_instance(model.W_Object, 
gcref)
-if (w_obj is not None and w_obj.has_class()
-and w_obj.getclass(space) is w_class):
-match_w.append(w_obj)
-pending.extend(rgc.get_rpy_referents(gcref))
-
-while roots:
-gcref = roots.pop()
-if rgc.get_gcflag_extra(gcref):
- 

[pypy-commit] lang-smalltalk storage: Fixed WeakMessageSend class.

2014-07-21 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r926:64d91d5de341
Date: 2014-07-21 18:35 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/64d91d5de341/

Log:Fixed WeakMessageSend class. Errors at startup are gone, and print-
its in workspace work!!

diff --git a/images/Squeak4.5-noBitBlt.changes 
b/images/Squeak4.5-noBitBlt.changes
--- a/images/Squeak4.5-noBitBlt.changes
+++ b/images/Squeak4.5-noBitBlt.changes
@@ -12620,4 +12620,15 @@

1 to: self splayTreeSize do: [:i |
self insertNewNode.
-   ]! !

SNAPSHOT{15 July 2014 . 6:10:56 pm} Squeak4.5-noBitBlt.image 
priorSource: 15894330!
\ No newline at end of file
+   ]! !

SNAPSHOT{15 July 2014 . 6:10:56 pm} Squeak4.5-noBitBlt.image 
priorSource: 15894330!
+
+QUIT/NOSAVE{21 July 2014 . 4:18:39 pm} Squeak4.5-noBitBlt.image 
priorSource: 15894825!

STARTUP{21 July 2014 . 6:19:06 pm} as 
C:\Dev\lang-smalltalk\images\Squeak4.5-noBitBlt.image!

!WeakMessageSend methodsFor: 'private' stamp: 'ag 7/21/2014 18:20' prior: 
34321504!
withEnsuredReceiverAndArgumentsDo: aBlock otherwise: altBlock
"Grab real references to receiver and arguments. If they still exist, 
evaluate aBlock."

"Return if my receiver has gone away"
| r a |
r := self receiver.
r ifNil: [ ^altBlock value ].

"Make sure that my arguments haven't gone away"
arguments ifNil: [ ^ altBlock value ].
a := Array withAll: arguments.
a with: shouldBeNil do: [ :arg :flag |
arg ifNil: [ flag ifFalse: [ ^altBlock value ]]
].

^aBlock value: r value: a! !

QUIT{21 July 2014 . 6:20:43 pm} Squeak4.5-noBitBlt.image priorSource: 
15894825!
+
+QUIT/NOSAVE{21 July 2014 . 4:21:36 pm} Squeak4.5-noBitBlt.image 
priorSource: 15895702!

STARTUP{21 July 2014 . 6:21:54 pm} as 
C:\Dev\lang-smalltalk\images\Squeak4.5-noBitBlt.image!

!WeakMessageSend methodsFor: 'comparing' stamp: 'ag 7/21/2014 18:22' prior: 
33144463!
= anObject
"Compare equal to equivalent MessageSend"
^ anObject isMessageSend
and: [self receiver == anObject receiver
and: [selector == anObject selector
and: [(Array withAll: self arguments) = (Array withAll: 
anObject arguments)]]]
! !
!WeakMessageSend methodsFor: 'private' stamp: 'ag 7/21/2014 18:23' prior: 
49449636!
withEnsuredReceiverAndArgumentsDo: aBlock otherwise: altBlock
"Grab real references to receiver and arguments. If they still exist, 
evaluate aBlock."

"Return if my receiver has gone away"
| r a |
r := self receiver.
r ifNil: [ ^altBlock value ].

"Make sure that my arguments haven't gone away"
a := Array withAll: self arguments.
a with: shouldBeNil do: [ :arg :flag |
arg ifNil: [ flag ifFalse: [ ^altBlock value ]]
].

^aBlock value: r value: a! !

QUIT{21 July 2014 . 6:23:49 pm} Squeak4.5-noBitBlt.image priorSource: 
15895702!

STARTUP{21 July 2014 . 6:31:05 pm} as 
C:\Dev\lang-smalltalk\images\Squeak4.5-noBitBlt.image!

!WeakMessageSend methodsFor: 'accessing' stamp: 'ag 7/21/2014 18:31'!
shouldBeNil

^ shouldBeNil ifNil: [ Array new ]! !
!WeakMessageSend methodsFor: 'private' stamp: 'ag 7/21/2014 18:31' prior: 
33148869!
isAnyArgumentGarbage
"Make sure that my arguments haven't gone away"
arguments ifNotNil: [
arguments with: self shouldBeNil do: [ :arg :flag |
(flag not and: [arg isNil])
ifTrue: [^true]
]
].
^false
! !
!WeakMessageSend methodsFor: 'private' stamp: 'ag 7/21/2014 18:31' prior: 
49450841!
withEnsuredReceiverAndArgumentsDo: aBlock otherwise: altBlock
"Grab real references to receiver and arguments. If they still exist, 
evaluate aBlock."

"Return if my receiver has gone away"
| r a |
r := self receiver.
r ifNil: [ ^altBlock value ].

"Make sure that my arguments haven't gone away"
a := Array withAll: self arguments.
a with: self shouldBeNil do: [ :arg :flag |
arg ifNil: [ flag ifFalse: [ ^altBlock value ]]
].

^aBlock value: r value: a! !
!WeakMessageSend methodsFor: 'private' stamp: 'ag 7/21/2014 18:32' prior: 
34360552!
withEnsuredReceiverAndArgumentsDo: aBlock withEnoughArguments: anArray 
otherwise: altBlock
"call the selector with enough arguments from arguments and anArray"
| r selfArgs enoughArgs |
r := self receiver.
r ifNil: [ ^altBlock value ].

selfArgs := self arguments.
selfArgs with: self shouldBeNil do: [ :arg :flag |
arg ifNil: [ flag ifFalse: [ ^altBlock value ]]
].

enoughArgs := Array new: selector numArgs.
enoughArgs replaceFrom: 1
   

[pypy-commit] lang-smalltalk storage-display-refactoring: Clean error message on EXIT_TO_DEBUGGER primitive.

2014-07-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-display-refactoring
Changeset: r931:ef90a282ad1f
Date: 2014-07-21 18:43 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/ef90a282ad1f/

Log:Clean error message on EXIT_TO_DEBUGGER primitive.

diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -860,8 +860,8 @@
 
 @expose_primitive(EXIT_TO_DEBUGGER, unwrap_spec=[object])
 def func(interp, s_frame, w_rcvr):
-if not objectmodel.we_are_translated():
-import pdb; pdb.set_trace()
+if interp.space.headless.is_set():
+exitFromHeadlessExecution(s_frame, "EXIT_TO_DEBUGGER")
 raise PrimitiveNotYetWrittenError()
 
 @expose_primitive(CHANGE_CLASS, unwrap_spec=[object, object], no_result=True)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-display-refactoring: Deleted obsolete Exception class

2014-07-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-display-refactoring
Changeset: r927:3b12d3eb24dc
Date: 2014-07-21 17:02 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/3b12d3eb24dc/

Log:Deleted obsolete Exception class

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -1467,8 +1467,3 @@
 if isinstance(s_class, ClassShadow):
 return "%s >> #%s" % (s_class.getname(), self.lookup_selector)
 return "#%s" % self.lookup_selector
-
-class DetachingShadowError(Exception):
-def __init__(self, old_shadow, new_shadow_class):
-self.old_shadow = old_shadow
-self.new_shadow_class = new_shadow_class
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-display-refactoring: Added --hacks parameter to enable run_spy_hacks method.

2014-07-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-display-refactoring
Changeset: r930:b5dbc52fd7e3
Date: 2014-07-21 18:35 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/b5dbc52fd7e3/

Log:Added --hacks parameter to enable run_spy_hacks method.

diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -33,6 +33,7 @@
 self.no_specialized_storage = ConstantFlag()
 # This is a hack; see compile_code() in targetimageloadingsmalltalk.py
 self.suppress_process_switch = ConstantFlag()
+self.run_spy_hacks = ConstantFlag()
 self.headless = ConstantFlag()
 
 self.classtable = {}
diff --git a/spyvm/squeakimage.py b/spyvm/squeakimage.py
--- a/spyvm/squeakimage.py
+++ b/spyvm/squeakimage.py
@@ -386,12 +386,13 @@
 self.startup_time = time.time()
 
 def run_spy_hacks(self, space):
-pass
-# w_display = space.objtable["w_display"]
-# if w_display is not None and not w_display.is_nil(space):
-# if space.unwrap_int(w_display.fetch(space, 3)) < 8:
-# # non-native indexed color depth not well supported
-# w_display.store(space, 3, space.wrap_int(8))
+if not space.run_spy_hacks.is_set():
+return
+w_display = space.objtable["w_display"]
+if w_display is not None and not w_display.is_nil(space):
+if space.unwrap_int(w_display.fetch(space, 3)) < 8:
+# non-native indexed color depth not well supported
+w_display.store(space, 3, space.wrap_int(8))
 
 def find_symbol(self, space, reader, symbol):
 w_dnu = self.special(constants.SO_DOES_NOT_UNDERSTAND)
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -36,6 +36,7 @@
 -p|--poll  - Actively poll for events. Try this if the 
image is not responding well.
 -i|--no-interrupts - Disable timer interrupt. Disables 
non-cooperative scheduling.
 -S - Disable specialized storage strategies; 
always use generic ListStorage
+--hacks- Enable Spy hacks. Set display color depth to 
8.
 
   Logging parameters:
 -t|--trace - Output a trace of each message, 
primitive, return value and process switch.
@@ -119,6 +120,8 @@
 interrupts = False
 elif arg in ["-P", "--process"]:
 headless = False
+elif arg in ["--hacks"]:
+space.run_spy_hacks.set()
 elif arg in ["-S"]:
 space.no_specialized_storage.set()
 elif arg in ["-u"]:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-display-refactoring: Trying to get AssertionErrors to print their message.

2014-07-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-display-refactoring
Changeset: r928:6a516e497789
Date: 2014-07-21 18:05 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/6a516e497789/

Log:Trying to get AssertionErrors to print their message.

diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -69,7 +69,7 @@
 except error.Exit, e:
 print_error("Exited: %s" % e.msg)
 return -1
-except Exception, e:
+except BaseException, e:
 print_error("Exception: %s" % str(e))
 if not objectmodel.we_are_translated():
 import traceback
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-display-refactoring: Extracted Display classes from model into a seperate module model_display.

2014-07-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-display-refactoring
Changeset: r929:2dac2e226121
Date: 2014-07-21 18:08 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/2dac2e226121/

Log:Extracted Display classes from model into a seperate module
model_display.

diff --git a/spyvm/constants.py b/spyvm/constants.py
--- a/spyvm/constants.py
+++ b/spyvm/constants.py
@@ -54,6 +54,11 @@
 BLKCLSR_NUMARGS = 2
 BLKCLSR_SIZE = 3
 
+FORM_BITS = 0
+FORM_WIDTH = 1
+FORM_HEIGHT = 2
+FORM_DEPTH = 3
+
 # ___
 # Miscellaneous constants
 
diff --git a/spyvm/interpreter_proxy.py b/spyvm/interpreter_proxy.py
--- a/spyvm/interpreter_proxy.py
+++ b/spyvm/interpreter_proxy.py
@@ -17,7 +17,7 @@
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rlib.unroll import unrolling_iterable
 
-from spyvm import error, model, objspace
+from spyvm import error, model, model_display, objspace
 
 sqInt = rffi.INT
 sqLong = rffi.LONG
@@ -242,7 +242,7 @@
 return w_object.convert_to_c_layout()
 elif isinstance(w_object, model.W_BytesObject):
 return rffi.cast(sqIntArrayPtr, w_object.convert_to_c_layout())
-elif isinstance(w_object, model.W_DisplayBitmap):
+elif isinstance(w_object, model_display.W_DisplayBitmap):
 return rffi.cast(sqIntArrayPtr, w_object.convert_to_c_layout())
 else:
 raise ProxyFunctionFailed
@@ -529,7 +529,7 @@
 @expose_on_virtual_machine_proxy([], int)
 def fullDisplayUpdate():
 w_display = IProxy.space.objtable['w_display']
-if isinstance(w_display, model.W_DisplayBitmap):
+if isinstance(w_display, model_display.W_DisplayBitmap):
 w_display.update_from_buffer()
 w_display.flush_to_screen()
 return 0
@@ -559,16 +559,7 @@
 # display memory
 space = IProxy.space
 if w_dest_form.is_same_object(space.objtable['w_display']):
-w_bitmap = w_dest_form.fetch(space, 0)
-if not isinstance(w_bitmap, model.W_DisplayBitmap):
-assert isinstance(w_bitmap, model.W_WordsObject)
-w_display_bitmap = w_bitmap.as_display_bitmap(
-w_dest_form,
-IProxy.interp,
-sdldisplay=None
-)
-else:
-w_display_bitmap = w_bitmap
+w_display_bitmap = model_display.get_display_bitmap(IProxy.interp, 
w_dest_form)
 w_display_bitmap.update_from_buffer()
 w_display_bitmap.flush_to_screen()
 return 0
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -987,26 +987,6 @@
 c_words[i] = intmask(old_words[i])
 self.words = None
 return c_words
-
-def as_display_bitmap(self, w_form, interp, sdldisplay=None):
-width = interp.space.unwrap_int(w_form.fetch(interp.space, 1))
-height = interp.space.unwrap_int(w_form.fetch(interp.space, 2))
-depth = interp.space.unwrap_int(w_form.fetch(interp.space, 3))
-if not sdldisplay:
-from spyvm import display
-sdldisplay = display.SDLDisplay(interp.image_name)
-sdldisplay.set_video_mode(width, height, depth)
-w_display_bitmap = W_DisplayBitmap.create(
-interp.space,
-self.getclass(interp.space),
-self.size(),
-depth,
-sdldisplay
-)
-for idx in range(self.size()):
-w_display_bitmap.setword(idx, self.getword(idx))
-w_form.store(interp.space, 0, w_display_bitmap)
-return w_display_bitmap
 
 def _become(self, w_other):
 assert isinstance(w_other, W_WordsObject)
@@ -1019,144 +999,6 @@
 if self.words is None:
 lltype.free(self.c_words, flavor='raw')
 
-class W_DisplayBitmap(W_AbstractObjectWithClassReference):
-_attrs_ = ['pixelbuffer', '_realsize', '_real_depth_buffer', 'display', 
'_depth']
-_immutable_fields_ = ['_realsize', 'display', '_depth']
-repr_classname = "W_DisplayBitmap"
-
-pixelbuffer = None
-
-@staticmethod
-def create(space, w_class, size, depth, display):
-if depth < 8:
-return W_MappingDisplayBitmap(space, w_class, size * (8 / depth), 
depth, display)
-elif depth == 8:
-return W_8BitDisplayBitmap(space, w_class, size, depth, display)
-elif depth == 16:
-return W_16BitDisplayBitmap(space, w_class, size, depth, display)
-else:
-return W_DisplayBitmap(space, w_class, size, depth, display)
-
-def repr_content(self):
-return "len=%d depth=%d %s" % (self.size(), self._depth, 
self.str_content())
-
-def __init__(self, space, w_class, size, depth, display):
-W_AbstractObjectWithClassReference.__init__(self, space, w_class)
-self._real_depth_buffer = lltype.malloc(rffi.CArray(rffi.UINT), size, 
flavor='raw')
-self._realsize = size
-self.display = 

[pypy-commit] lang-smalltalk storage-display-refactoring: Finally got the 1-bit drawing correctly when width is no multiple of 32.

2014-07-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-display-refactoring
Changeset: r935:5dc629a29736
Date: 2014-07-22 19:47 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/5dc629a29736/

Log:Finally got the 1-bit drawing correctly when width is no multiple of
32.

diff --git a/spyvm/model_display.py b/spyvm/model_display.py
--- a/spyvm/model_display.py
+++ b/spyvm/model_display.py
@@ -1,6 +1,6 @@
 
 from spyvm import model, constants, display
-from rpython.rlib import jit
+from rpython.rlib import jit, objectmodel
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rlib.rarithmetic import r_uint
 
@@ -11,7 +11,7 @@
 w_class = w_obj.getclass(space)
 
 if depth < 8:
-w_display_bitmap = W_MappingDisplayBitmap(space, w_class, size, depth, 
form.width())
+w_display_bitmap = W_MappingDisplayBitmap(space, w_class, size, depth)
 elif depth == 8:
 w_display_bitmap = W_8BitDisplayBitmap(space, w_class, size, depth)
 elif depth == 16:
@@ -159,45 +159,47 @@
 else:
 self.pixelbuffer_UINT()[n] = r_uint(word)
 
+BITS = r_uint(32)
 class W_MappingDisplayBitmap(W_DisplayBitmap):
 
 repr_classname = "W_MappingDisplayBitmap"
-_attrs_ = ['mapping_factor', 'words_per_line', 'bits_in_last_word', 
'width']
-_immutable_fields_ = ['mapping_factor', 'words_per_line', 
'bits_in_last_word', 'width']
+_attrs_ = ['words_per_line', 'bits_in_last_word', 'pitch']
+_immutable_fields_ = ['words_per_line?', 'bits_in_last_word?', 'pitch?']
 
-pixel_per_word = constants.BYTES_PER_WORD
+def __init__(self, space, w_class, size, depth):
+assert depth in [1, 2, 4]
+W_DisplayBitmap.__init__(self, space, w_class, size, depth)
 
-def __init__(self, space, w_class, size, depth, width):
-assert depth in [1, 2, 4]
-width = r_uint(width)
-self.width = width
-self.mapping_factor = display.MINIMUM_DEPTH / depth
-self.words_per_line = r_uint(width / 32 + 1)
-self.bits_in_last_word = width % 32
-W_DisplayBitmap.__init__(self, space, w_class, size, depth)
+def take_over_display(self):
+pitch = r_uint(self.display.pitch)
+self.pitch = pitch
+self.bits_in_last_word = pitch % BITS
+self.words_per_line = r_uint((pitch - self.bits_in_last_word) / BITS)
+if self.bits_in_last_word > 0:
+self.words_per_line += 1
+W_DisplayBitmap.take_over_display(self)
 
 @jit.unroll_safe
 def set_pixelbuffer_word(self, n, word):
 n = r_uint(n)
-word = r_uint(word)
-pos = self.compute_pos(n)
-buf = self.display.screen.c_pixels
-
-if (n+1) % self.words_per_line == 0:
+if ((n+1) % self.words_per_line) == 0 and self.bits_in_last_word > 0:
 # This is the last word on the line. A few bits are cut off.
 bits = self.bits_in_last_word
 else:
-bits = 32
+bits = BITS
 
+word = r_uint(word)
+pos = self.compute_pos(n)
+buf = rffi.ptradd(self.display.screen.c_pixels, pos)
 depth = r_uint(self._depth)
-rshift = 32 - depth
-for i in range(r_uint(bits) / depth):
+rshift = BITS - depth
+for i in range(bits / depth):
 pixel = word >> rshift
-buf[pos] = rffi.cast(rffi.UCHAR, pixel)
-word <<= self._depth
-pos += 1
-
+buf[i] = rffi.cast(rffi.UCHAR, pixel)
+word <<= depth
+
 def compute_pos(self, n):
 word_on_line = n % self.words_per_line
-complete_lines = r_uint((n - word_on_line) / self.words_per_line)
-return complete_lines * self.width + 32*word_on_line
+y = r_uint((n - word_on_line) / self.words_per_line)
+x = word_on_line * BITS / r_uint(self._depth)
+return y * r_uint(self.pitch) + x
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-display-refactoring: Made image_name available from object space.

2014-07-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-display-refactoring
Changeset: r933:97b7b7828d10
Date: 2014-07-21 19:19 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/97b7b7828d10/

Log:Made image_name available from object space.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -23,7 +23,7 @@
 
 
 class Interpreter(object):
-_immutable_fields_ = ["space", "image", "image_name",
+_immutable_fields_ = ["space", "image",
   "interrupt_counter_size",
   "startup_time", "evented", "interrupts"]
 
@@ -34,12 +34,11 @@
 get_printable_location=get_printable_location
 )
 
-def __init__(self, space, image=None, image_name="",
+def __init__(self, space, image=None,
 trace=False, evented=True, interrupts=True):
 # === Initialize immutable variables
 self.space = space
 self.image = image
-self.image_name = image_name
 if image:
 self.startup_time = image.startup_time
 else:
@@ -1009,9 +1008,8 @@
 # in order to enable tracing/jumping for message sends etc.
 def debugging():
 def stepping_debugger_init(original):
-def meth(self, space, image=None, image_name="", trace=False):
-return_value = original(self, space, image=image,
-image_name=image_name, trace=trace)
+def meth(self, space, image=None, trace=False):
+return_value = original(self, space, image=image, trace=trace)
 # ##
 
 self.message_stepping = False
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -14,8 +14,7 @@
 self.flag = [set_initially]
 
 def is_set(self):
-flag = jit.promote(self.flag[0])
-return flag
+return jit.promote(self.flag[0])
 
 def set(self):
 self.flag[0] = True
@@ -26,6 +25,16 @@
 def set_to(self, flag):
 self.flag[0] = flag
 
+class ConstantString(object):
+def __init__(self):
+self.value = [""]
+
+def get(self):
+return jit.promote(self.value[0])
+
+def set(self, value):
+self.value[0] = value
+
 class ObjSpace(object):
 def __init__(self):
 # If this flag is set, then no optimizing storage strategies will be 
used.
@@ -38,8 +47,8 @@
 
 self.classtable = {}
 self.objtable = {}
-self._executable_path = [""] # XXX: we cannot set the attribute
-  # directly on the frozen objectspace
+self._executable_path = ConstantString()
+self._image_name = ConstantString()
 
 # Create the nil object.
 # Circumvent the constructor because nil is already referenced there.
@@ -62,11 +71,12 @@
 break
 return rpath.rabspath(executable)
 
-def runtime_setup(self, executable):
+def runtime_setup(self, executable, image_name):
 fullpath = rpath.rabspath(self.find_executable(executable))
 i = fullpath.rfind(os.path.sep) + 1
 assert i > 0
-self._executable_path[0] = fullpath[:i]
+self._executable_path.set(fullpath[:i])
+self._image_name.set(image_name)
 
 def populate_special_objects(self, specials):
 for name, idx in constants.objects_in_special_object_table.items():
@@ -77,7 +87,10 @@
 self.classtable["w_Metaclass"] = self.w_SmallInteger.w_class.w_class
 
 def executable_path(self):
-return self._executable_path[0]
+return self._executable_path.get()
+
+def image_name(self):
+return self._image_name.get()
 
 def add_bootstrap_class(self, name, cls):
 self.classtable[name] = cls
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -982,7 +982,7 @@
 def func(interp, s_frame, argument_count):
 if argument_count == 0:
 s_frame.pop()
-return interp.space.wrap_string(interp.image_name)
+return interp.space.wrap_string(interp.space.image_name())
 elif argument_count == 1:
 pass # XXX
 raise PrimitiveFailedError
diff --git a/spyvm/test/test_primitives.py b/spyvm/test/test_primitives.py
--- a/spyvm/test/test_primitives.py
+++ b/spyvm/test/test_primitives.py
@@ -47,7 +47,8 @@
 frame = context
 for i in range(len(stack)):
 frame.as_context_get_shadow(space).push(stack[i])
-interp = TestInterpreter(space, image_name=IMAGENAME)
+interp = TestInterpreter(space)
+interp.space._image_name.set(IMAGENAME)
 return interp, frame, len(stack)
 
 def _prim(space, code, stack, context = None):
@@ -680,7 +681,7 @@
 
 closure = space.newClosure(w_frame, 4, 0, [])
 s_frame = w_frame.as_methodcontext_get_shadow(space)
-

[pypy-commit] lang-smalltalk storage-display-refactoring: Added FormWrapper to clean up display handling code.

2014-07-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-display-refactoring
Changeset: r932:f151c3506b41
Date: 2014-07-21 19:16 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/f151c3506b41/

Log:Added FormWrapper to clean up display handling code.

diff --git a/spyvm/interpreter_proxy.py b/spyvm/interpreter_proxy.py
--- a/spyvm/interpreter_proxy.py
+++ b/spyvm/interpreter_proxy.py
@@ -17,7 +17,7 @@
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rlib.unroll import unrolling_iterable
 
-from spyvm import error, model, model_display, objspace
+from spyvm import error, model, model_display, objspace, wrapper
 
 sqInt = rffi.INT
 sqLong = rffi.LONG
@@ -559,7 +559,8 @@
 # display memory
 space = IProxy.space
 if w_dest_form.is_same_object(space.objtable['w_display']):
-w_display_bitmap = model_display.get_display_bitmap(IProxy.interp, 
w_dest_form)
+form = wrapper.FormWrapper(space, w_dest_form)
+w_display_bitmap = form.get_display_bitmap(IProxy.interp)
 w_display_bitmap.update_from_buffer()
 w_display_bitmap.flush_to_screen()
 return 0
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -734,14 +734,13 @@
 
 if not isinstance(w_rcvr, model.W_PointersObject) or w_rcvr.size() < 4:
 raise PrimitiveFailedError
-# the fields required are bits (a pointer to a Bitmap), width, height, 
depth
-
-# XXX: TODO get the initial image TODO: figure out whether we
-# should decide the width an report it in the other SCREEN_SIZE
-w_bitmap = w_rcvr.fetch(interp.space, 0)
-width = interp.space.unwrap_int(w_rcvr.fetch(interp.space, 1))
-height = interp.space.unwrap_int(w_rcvr.fetch(interp.space, 2))
-depth = interp.space.unwrap_int(w_rcvr.fetch(interp.space, 3))
+
+# TODO: figure out whether we should decide the width an report it in the 
SCREEN_SIZE primitive
+form = wrapper.FormWrapper(interp.space, w_rcvr)
+w_bitmap = form.bits()
+width = form.width()
+height = form.height()
+depth = form.depth()
 
 sdldisplay = None
 
@@ -751,7 +750,7 @@
 if isinstance(w_prev_bitmap, model_display.W_DisplayBitmap):
 sdldisplay = w_prev_bitmap.display
 sdldisplay.set_video_mode(width, height, depth)
-
+
 if isinstance(w_bitmap, model_display.W_DisplayBitmap):
 assert (sdldisplay is None) or (sdldisplay is w_bitmap.display)
 sdldisplay = w_bitmap.display
@@ -759,7 +758,7 @@
 w_display_bitmap = w_bitmap
 else:
 assert isinstance(w_bitmap, model.W_WordsObject)
-w_display_bitmap = model_display.get_display_bitmap(interp, w_rcvr, 
sdldisplay=sdldisplay)
+w_display_bitmap = form.get_display_bitmap(interp, sdldisplay)
 
 w_display_bitmap.flush_to_screen()
 if interp.image:
diff --git a/spyvm/wrapper.py b/spyvm/wrapper.py
--- a/spyvm/wrapper.py
+++ b/spyvm/wrapper.py
@@ -1,4 +1,4 @@
-from spyvm import model, constants
+from spyvm import model, model_display, constants
 from spyvm.error import FatalError, WrapperException, PrimitiveFailedError
 
 class Wrapper(object):
@@ -263,6 +263,21 @@
 def size(self):
 return self._w_self.size() - constants.BLKCLSR_SIZE
 
+class FormWrapper(Wrapper):
+bits, store_bits = make_getter_setter(constants.FORM_BITS)
+width, store_width = make_int_getter_setter(constants.FORM_WIDTH)
+height, store_height = make_int_getter_setter(constants.FORM_HEIGHT)
+depth, store_depth = make_int_getter_setter(constants.FORM_DEPTH)
+
+def get_display_bitmap(self, interp, sdldisplay=None):
+w_bitmap = self.bits()
+if not isinstance(w_bitmap, model_display.W_DisplayBitmap):
+w_display_bitmap = model_display.from_words_object(interp, 
w_bitmap, self, sdldisplay)
+self.store_bits(w_display_bitmap)
+else:
+w_display_bitmap = w_bitmap
+return w_display_bitmap
+
 # XXX Wrappers below are not used yet.
 class OffsetWrapper(Wrapper):
 offset_x  = make_int_getter(0)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-display-refactoring: Refactoring.

2014-07-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-display-refactoring
Changeset: r934:2d4fa0b3f3b7
Date: 2014-07-22 15:51 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/2d4fa0b3f3b7/

Log:Refactoring. The SDLDisplay instance is globally accessible in the
space. Cleaned up the process for a form to become the display.
Added model_display.py (forgotten in previous commit). Fixed
MappingDisplay: handling the case that width is not dividable by 32.

diff --git a/images/Squeak4.5-noBitBlt.changes 
b/images/Squeak4.5-noBitBlt.changes
--- a/images/Squeak4.5-noBitBlt.changes
+++ b/images/Squeak4.5-noBitBlt.changes
@@ -12620,4 +12620,8 @@

1 to: self splayTreeSize do: [:i |
self insertNewNode.
-   ]! !

SNAPSHOT{15 July 2014 . 6:10:56 pm} Squeak4.5-noBitBlt.image 
priorSource: 15894330!
\ No newline at end of file
+   ]! !

SNAPSHOT{15 July 2014 . 6:10:56 pm} Squeak4.5-noBitBlt.image 
priorSource: 15894330!
+
+QUIT/NOSAVE{21 July 2014 . 7:09:22 pm} Squeak4.5-noBitBlt.image 
priorSource: 15894825!
+
+QUIT{21 July 2014 . 7:10:12 pm} Squeak4.5-noBitBlt.image priorSource: 
15894825!

STARTUP{22 July 2014 . 10:55:07 am} as 
C:\Dev\lang-smalltalk\images\Squeak4.5-noBitBlt.image!


Smalltalk specialObjectsArray at:15!

(Smalltalk specialObjectsArray at:15) depth!
\ No newline at end of file
diff --git a/spyvm/display.py b/spyvm/display.py
--- a/spyvm/display.py
+++ b/spyvm/display.py
@@ -35,12 +35,13 @@
 WindowEventPaint = 5
 WindowEventStinks = 6
 
+MINIMUM_DEPTH = 8
 
 class SDLDisplay(object):
 _attrs_ = ["screen", "width", "height", "depth", "surface", "has_surface",
"mouse_position", "button", "key", "interrupt_key", 
"_defer_updates",
-   "_deferred_event", "pixelbuffer"]
-_immutable_fields_ = ["pixelbuffer?"]
+   "_deferred_event", "bpp", "pitch"]
+#_immutable_fields_ = ["pixelbuffer?"]
 
 def __init__(self, title):
 assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
@@ -58,26 +59,31 @@
 def set_video_mode(self, w, h, d):
 assert w > 0 and h > 0
 assert d in [1, 2, 4, 8, 16, 32]
+if d < MINIMUM_DEPTH:
+d = MINIMUM_DEPTH
 self.width = w
 self.height = h
 self.depth = d
 flags = RSDL.HWPALETTE | RSDL.RESIZABLE | RSDL.ASYNCBLIT | 
RSDL.DOUBLEBUF
-if d < 8:
-d = 8
 self.screen = RSDL.SetVideoMode(w, h, d, flags)
 if not self.screen:
 print "Could not open display at depth %d" % d
 raise RuntimeError
-elif d == 8:
+elif d == MINIMUM_DEPTH:
 self.set_squeak_colormap(self.screen)
-self.pixelbuffer = rffi.cast(rffi.UINTP, self.screen.c_pixels)
-
-def get_pixelbuffer(self):
-return jit.promote(self.pixelbuffer)
-
+self.bpp = rffi.getintfield(self.screen.c_format, 'c_BytesPerPixel')
+self.pitch = rffi.getintfield(self.screen, 'c_pitch')
+
+def get_pixelbuffer_UCHAR(self):
+# return jit.promote(rffi.cast(RSDL.Uint8P, self.screen.c_pixels))
+return jit.promote(self.screen.c_pixels)
+
+def get_pixelbuffer_UINT(self):
+return jit.promote(rffi.cast(RSDL.Uint32P, self.screen.c_pixels))
+
 def defer_updates(self, flag):
 self._defer_updates = flag
-
+
 def flip(self, force=False):
 if (not self._defer_updates) or force:
 RSDL.Flip(self.screen)
diff --git a/spyvm/interpreter_proxy.py b/spyvm/interpreter_proxy.py
--- a/spyvm/interpreter_proxy.py
+++ b/spyvm/interpreter_proxy.py
@@ -560,7 +560,7 @@
 space = IProxy.space
 if w_dest_form.is_same_object(space.objtable['w_display']):
 form = wrapper.FormWrapper(space, w_dest_form)
-w_display_bitmap = form.get_display_bitmap(IProxy.interp)
+w_display_bitmap = form.get_display_bitmap()
 w_display_bitmap.update_from_buffer()
 w_display_bitmap.flush_to_screen()
 return 0
@@ -1000,7 +1000,7 @@
 self.argcount = 0
 self.w_method = None
 self.fail_reason = 0
-self.trace_proxy.unset()
+self.trace_proxy.deactivate()
 
 def call(self, signature, interp, s_frame, argcount, w_method):
 self.initialize_from_call(signature, interp, s_frame, argcount, 
w_method)
@@ -1042,7 +1042,7 @@
 self.argcount = argcount
 self.w_method = w_method
 self.space = interp.space
-self.trace_proxy.set_to(interp.trace_proxy.is_set())
+self.trace_proxy.set(interp.trace_proxy.is_set())
 # ensure that space.w_nil gets the first possible oop
 self.object_to_oop(self.space.w_nil)
 
diff --git a/spyvm/model_display.py b/spyvm/model_display.py
new file mode 100644
--- /dev/null
+++ b/spyvm/model_display.py
@@ -0,0 +1,203 @@
+
+from spyvm import model, constants, display
+from rpython.rlib import jit
+from rpython.rtyper.lltypesystem import llt

[pypy-commit] lang-smalltalk storage-display-refactoring: Added comment.

2014-07-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-display-refactoring
Changeset: r936:6f3f768d7ce8
Date: 2014-07-22 21:01 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/6f3f768d7ce8/

Log:Added comment.

diff --git a/spyvm/model_display.py b/spyvm/model_display.py
--- a/spyvm/model_display.py
+++ b/spyvm/model_display.py
@@ -171,7 +171,7 @@
 W_DisplayBitmap.__init__(self, space, w_class, size, depth)
 
 def take_over_display(self):
-pitch = r_uint(self.display.pitch)
+pitch = r_uint(self.display.pitch) # The pitch is different from the 
width input to SDL!
 self.pitch = pitch
 self.bits_in_last_word = pitch % BITS
 self.words_per_line = r_uint((pitch - self.bits_in_last_word) / BITS)
@@ -202,4 +202,4 @@
 word_on_line = n % self.words_per_line
 y = r_uint((n - word_on_line) / self.words_per_line)
 x = word_on_line * BITS / r_uint(self._depth)
-return y * r_uint(self.pitch) + x
+return y * self.pitch + x
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-display-refactoring: Cleanups.

2014-07-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-display-refactoring
Changeset: r939:e363f2952c1e
Date: 2014-07-22 21:58 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/e363f2952c1e/

Log:Cleanups.

diff --git a/spyvm/display.py b/spyvm/display.py
--- a/spyvm/display.py
+++ b/spyvm/display.py
@@ -74,11 +74,7 @@
 self.bpp = rffi.getintfield(self.screen.c_format, 'c_BytesPerPixel')
 self.pitch = rffi.getintfield(self.screen, 'c_pitch')
 
-def get_pixelbuffer_UCHAR(self):
-# return jit.promote(rffi.cast(RSDL.Uint8P, self.screen.c_pixels))
-return jit.promote(self.screen.c_pixels)
-
-def get_pixelbuffer_UINT(self):
+def get_pixelbuffer(self):
 return jit.promote(rffi.cast(RSDL.Uint32P, self.screen.c_pixels))
 
 def defer_updates(self, flag):
diff --git a/spyvm/model_display.py b/spyvm/model_display.py
--- a/spyvm/model_display.py
+++ b/spyvm/model_display.py
@@ -61,14 +61,14 @@
 
 # === Graphics
 
-def pixelbuffer_UINT(self):
-return self.display.get_pixelbuffer_UINT()
+def pixelbuffer(self):
+return self.display.get_pixelbuffer()
 
 def pixelbuffer_UCHAR(self):
 return self.display.get_pixelbuffer_UCHAR()
 
 def set_pixelbuffer_word(self, n, word):
-self.pixelbuffer_UINT()[n] = word
+self.pixelbuffer()[n] = word
 
 def take_over_display(self):
 # Make sure FrameWrapper.take_over_display() is called first for the 
correct Frame object.
@@ -135,7 +135,7 @@
 ((msb & mask) << 11)
 )
 
-self.pixelbuffer_UINT()[n] = r_uint(lsb | (msb << 16))
+self.pixelbuffer()[n] = r_uint(lsb | (msb << 16))
 
 class W_8BitDisplayBitmap(W_DisplayBitmap):
 
@@ -143,7 +143,7 @@
 
 def set_pixelbuffer_word(self, n, word):
 # Invert the byte-order.
-self.pixelbuffer_UINT()[n] = r_uint(
+self.pixelbuffer()[n] = r_uint(
 (word >> 24) |
 ((word >> 8) & 0xff00) |
 ((word << 8) & 0x00ff) |
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Merged.

2014-07-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r940:ad963bc84269
Date: 2014-07-22 22:36 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/ad963bc84269/

Log:Merged.

diff --git a/spyvm/constants.py b/spyvm/constants.py
--- a/spyvm/constants.py
+++ b/spyvm/constants.py
@@ -54,6 +54,11 @@
 BLKCLSR_NUMARGS = 2
 BLKCLSR_SIZE = 3
 
+FORM_BITS = 0
+FORM_WIDTH = 1
+FORM_HEIGHT = 2
+FORM_DEPTH = 3
+
 # ___
 # Miscellaneous constants
 
diff --git a/spyvm/display.py b/spyvm/display.py
--- a/spyvm/display.py
+++ b/spyvm/display.py
@@ -35,12 +35,13 @@
 WindowEventPaint = 5
 WindowEventStinks = 6
 
+MINIMUM_DEPTH = 8
 
 class SDLDisplay(object):
 _attrs_ = ["screen", "width", "height", "depth", "surface", "has_surface",
"mouse_position", "button", "key", "interrupt_key", 
"_defer_updates",
-   "_deferred_event", "pixelbuffer"]
-_immutable_fields_ = ["pixelbuffer?"]
+   "_deferred_event", "bpp", "pitch"]
+#_immutable_fields_ = ["pixelbuffer?"]
 
 def __init__(self, title):
 assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
@@ -58,26 +59,27 @@
 def set_video_mode(self, w, h, d):
 assert w > 0 and h > 0
 assert d in [1, 2, 4, 8, 16, 32]
+if d < MINIMUM_DEPTH:
+d = MINIMUM_DEPTH
 self.width = w
 self.height = h
 self.depth = d
 flags = RSDL.HWPALETTE | RSDL.RESIZABLE | RSDL.ASYNCBLIT | 
RSDL.DOUBLEBUF
-if d < 8:
-d = 8
 self.screen = RSDL.SetVideoMode(w, h, d, flags)
 if not self.screen:
 print "Could not open display at depth %d" % d
 raise RuntimeError
-elif d == 8:
+elif d == MINIMUM_DEPTH:
 self.set_squeak_colormap(self.screen)
-self.pixelbuffer = rffi.cast(rffi.UINTP, self.screen.c_pixels)
-
+self.bpp = rffi.getintfield(self.screen.c_format, 'c_BytesPerPixel')
+self.pitch = rffi.getintfield(self.screen, 'c_pitch')
+
 def get_pixelbuffer(self):
-return jit.promote(self.pixelbuffer)
-
+return jit.promote(rffi.cast(RSDL.Uint32P, self.screen.c_pixels))
+
 def defer_updates(self, flag):
 self._defer_updates = flag
-
+
 def flip(self, force=False):
 if (not self._defer_updates) or force:
 RSDL.Flip(self.screen)
diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -23,7 +23,7 @@
 
 
 class Interpreter(object):
-_immutable_fields_ = ["space", "image", "image_name",
+_immutable_fields_ = ["space", "image",
   "interrupt_counter_size",
   "startup_time", "evented", "interrupts"]
 
@@ -34,12 +34,11 @@
 get_printable_location=get_printable_location
 )
 
-def __init__(self, space, image=None, image_name="",
+def __init__(self, space, image=None,
 trace=False, evented=True, interrupts=True):
 # === Initialize immutable variables
 self.space = space
 self.image = image
-self.image_name = image_name
 if image:
 self.startup_time = image.startup_time
 else:
@@ -1009,9 +1008,8 @@
 # in order to enable tracing/jumping for message sends etc.
 def debugging():
 def stepping_debugger_init(original):
-def meth(self, space, image=None, image_name="", trace=False):
-return_value = original(self, space, image=image,
-image_name=image_name, trace=trace)
+def meth(self, space, image=None, trace=False):
+return_value = original(self, space, image=image, trace=trace)
 # ##
 
 self.message_stepping = False
diff --git a/spyvm/interpreter_proxy.py b/spyvm/interpreter_proxy.py
--- a/spyvm/interpreter_proxy.py
+++ b/spyvm/interpreter_proxy.py
@@ -17,7 +17,7 @@
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rlib.unroll import unrolling_iterable
 
-from spyvm import error, model, objspace
+from spyvm import error, model, model_display, objspace, wrapper
 
 sqInt = rffi.INT
 sqLong = rffi.LONG
@@ -242,7 +242,7 @@
 return w_object.convert_to_c_layout()
 elif isinstance(w_object, model.W_BytesObject):
 return rffi.cast(sqIntArrayPtr, w_object.convert_to_c_layout())
-elif isinstance(w_object, model.W_DisplayBitmap):
+elif isinstance(w_object, model_display.W_DisplayBitmap):
 return rffi.cast(sqIntArrayPtr, w_object.convert_to_c_layout())
 else:
 raise ProxyFunctionFailed
@@ -529,7 +529,7 @@
 @expose_on_virtual_machine_proxy([], int)
 def fullDisplayUpdate():
 w_display = IProxy.space.objtable['w_display']
-if isinstance(w_display, model.W_DisplayBitmap):
+if isinstance(w_display, model_display.W_DisplayBitmap):
 w_dis

[pypy-commit] lang-smalltalk storage-display-refactoring: Reverted changes file back to storage version. Accidentally committed.

2014-07-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-display-refactoring
Changeset: r937:123f68a9dffe
Date: 2014-07-22 21:37 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/123f68a9dffe/

Log:Reverted changes file back to storage version. Accidentally
committed.

diff --git a/images/Squeak4.5-noBitBlt.changes 
b/images/Squeak4.5-noBitBlt.changes
--- a/images/Squeak4.5-noBitBlt.changes
+++ b/images/Squeak4.5-noBitBlt.changes
@@ -12622,6 +12622,13 @@
self insertNewNode.
]! !

SNAPSHOT{15 July 2014 . 6:10:56 pm} Squeak4.5-noBitBlt.image 
priorSource: 15894330!
 
-QUIT/NOSAVE{21 July 2014 . 7:09:22 pm} Squeak4.5-noBitBlt.image 
priorSource: 15894825!
-
-QUIT{21 July 2014 . 7:10:12 pm} Squeak4.5-noBitBlt.image priorSource: 
15894825!

STARTUP{22 July 2014 . 10:55:07 am} as 
C:\Dev\lang-smalltalk\images\Squeak4.5-noBitBlt.image!


Smalltalk specialObjectsArray at:15!

(Smalltalk specialObjectsArray at:15) depth!
\ No newline at end of file
+QUIT/NOSAVE{21 July 2014 . 4:18:39 pm} Squeak4.5-noBitBlt.image 
priorSource: 15894825!

STARTUP{21 July 2014 . 6:19:06 pm} as 
C:\Dev\lang-smalltalk\images\Squeak4.5-noBitBlt.image!

!WeakMessageSend methodsFor: 'private' stamp: 'ag 7/21/2014 18:20' prior: 
34321504!
withEnsuredReceiverAndArgumentsDo: aBlock otherwise: altBlock
"Grab real references to receiver and arguments. If they still exist, 
evaluate aBlock."

"Return if my receiver has gone away"
| r a |
r := self receiver.
r ifNil: [ ^altBlock value ].

"Make sure that my arguments haven't gone away"
arguments ifNil: [ ^ altBlock value ].
a := Array withAll: arguments.
a with: shouldBeNil do: [ :arg :flag |
arg ifNil: [ flag ifFalse: [ ^altBlock value ]]
].

^aBlock value: r value: a! !

QUIT{21 July 2014 . 6:20:43 pm} Squeak4.5-noBitBlt.image priorSource: 
15894825!
+
+QUIT/NOSAVE{21 July 2014 . 4:21:36 pm} Squeak4.5-noBitBlt.image 
priorSource: 15895702!

STARTUP{21 July 2014 . 6:21:54 pm} as 
C:\Dev\lang-smalltalk\images\Squeak4.5-noBitBlt.image!

!WeakMessageSend methodsFor: 'comparing' stamp: 'ag 7/21/2014 18:22' prior: 
33144463!
= anObject
"Compare equal to equivalent MessageSend"
^ anObject isMessageSend
and: [self receiver == anObject receiver
and: [selector == anObject selector
and: [(Array withAll: self arguments) = (Array withAll: 
anObject arguments)]]]
! !
!WeakMessageSend methodsFor: 'private' stamp: 'ag 7/21/2014 18:23' prior: 
49449636!
withEnsuredReceiverAndArgumentsDo: aBlock otherwise: altBlock
"Grab real references to receiver and arguments. If they still exist, 
evaluate aBlock."

"Return if my receiver has gone away"
| r a |
r := self receiver.
r ifNil: [ ^altBlock value ].

"Make sure that my arguments haven't gone away"
a := Array withAll: self arguments.
a with: shouldBeNil do: [ :arg :flag |
arg ifNil: [ flag ifFalse: [ ^altBlock value ]]
].

^aBlock value: r value: a! !

QUIT{21 July 2014 . 6:23:49 pm} Squeak4.5-noBitBlt.image priorSource: 
15895702!

STARTUP{21 July 2014 . 6:31:05 pm} as 
C:\Dev\lang-smalltalk\images\Squeak4.5-noBitBlt.image!

!WeakMessageSend methodsFor: 'accessing' stamp: 'ag 7/21/2014 18:31'!
shouldBeNil

^ shouldBeNil ifNil: [ Array new ]! !
!WeakMessageSend methodsFor: 'private' stamp: 'ag 7/21/2014 18:31' prior: 
33148869!
isAnyArgumentGarbage
"Make sure that my arguments haven't gone away"
arguments ifNotNil: [
arguments with: self shouldBeNil do: [ :arg :flag |
(flag not and: [arg isNil])
ifTrue: [^true]
]
].
^false
! !
!WeakMessageSend methodsFor: 'private' stamp: 'ag 7/21/2014 18:31' prior: 
49450841!
withEnsuredReceiverAndArgumentsDo: aBlock otherwise: altBlock
"Grab real references to receiver and arguments. If they still exist, 
evaluate aBlock."

"Return if my receiver has gone away"
| r a |
r := self receiver.
r ifNil: [ ^altBlock value ].

"Make sure that my arguments haven't gone away"
a := Array withAll: self arguments.
a with: self shouldBeNil do: [ :arg :flag |
arg ifNil: [ flag ifFalse: [ ^altBlock value ]]
].

^aBlock value: r value: a! !
!WeakMessageSend methodsFor: 'private' stamp: 'ag 7/21/2014 18:32' prior: 
34360552!
withEnsuredReceiverAndArgumentsDo: aBlock withEnoughArguments: anArray 
otherwise: altBlock
"call the selector with enough arguments from arguments and anArray"
| r selfArgs enoughArgs |
r := self receiver.
r ifNil: [ ^altBlock value ].

selfArgs := self arguments.
selfArgs 

[pypy-commit] lang-smalltalk storage-context-state: Merged.

2014-07-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state
Changeset: r941:4e7e88455fcc
Date: 2014-07-22 23:12 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/4e7e88455fcc/

Log:Merged.

diff --git a/images/Squeak4.5-noBitBlt.changes 
b/images/Squeak4.5-noBitBlt.changes
--- a/images/Squeak4.5-noBitBlt.changes
+++ b/images/Squeak4.5-noBitBlt.changes
@@ -12620,4 +12620,15 @@

1 to: self splayTreeSize do: [:i |
self insertNewNode.
-   ]! !

SNAPSHOT{15 July 2014 . 6:10:56 pm} Squeak4.5-noBitBlt.image 
priorSource: 15894330!
\ No newline at end of file
+   ]! !

SNAPSHOT{15 July 2014 . 6:10:56 pm} Squeak4.5-noBitBlt.image 
priorSource: 15894330!
+
+QUIT/NOSAVE{21 July 2014 . 4:18:39 pm} Squeak4.5-noBitBlt.image 
priorSource: 15894825!

STARTUP{21 July 2014 . 6:19:06 pm} as 
C:\Dev\lang-smalltalk\images\Squeak4.5-noBitBlt.image!

!WeakMessageSend methodsFor: 'private' stamp: 'ag 7/21/2014 18:20' prior: 
34321504!
withEnsuredReceiverAndArgumentsDo: aBlock otherwise: altBlock
"Grab real references to receiver and arguments. If they still exist, 
evaluate aBlock."

"Return if my receiver has gone away"
| r a |
r := self receiver.
r ifNil: [ ^altBlock value ].

"Make sure that my arguments haven't gone away"
arguments ifNil: [ ^ altBlock value ].
a := Array withAll: arguments.
a with: shouldBeNil do: [ :arg :flag |
arg ifNil: [ flag ifFalse: [ ^altBlock value ]]
].

^aBlock value: r value: a! !

QUIT{21 July 2014 . 6:20:43 pm} Squeak4.5-noBitBlt.image priorSource: 
15894825!
+
+QUIT/NOSAVE{21 July 2014 . 4:21:36 pm} Squeak4.5-noBitBlt.image 
priorSource: 15895702!

STARTUP{21 July 2014 . 6:21:54 pm} as 
C:\Dev\lang-smalltalk\images\Squeak4.5-noBitBlt.image!

!WeakMessageSend methodsFor: 'comparing' stamp: 'ag 7/21/2014 18:22' prior: 
33144463!
= anObject
"Compare equal to equivalent MessageSend"
^ anObject isMessageSend
and: [self receiver == anObject receiver
and: [selector == anObject selector
and: [(Array withAll: self arguments) = (Array withAll: 
anObject arguments)]]]
! !
!WeakMessageSend methodsFor: 'private' stamp: 'ag 7/21/2014 18:23' prior: 
49449636!
withEnsuredReceiverAndArgumentsDo: aBlock otherwise: altBlock
"Grab real references to receiver and arguments. If they still exist, 
evaluate aBlock."

"Return if my receiver has gone away"
| r a |
r := self receiver.
r ifNil: [ ^altBlock value ].

"Make sure that my arguments haven't gone away"
a := Array withAll: self arguments.
a with: shouldBeNil do: [ :arg :flag |
arg ifNil: [ flag ifFalse: [ ^altBlock value ]]
].

^aBlock value: r value: a! !

QUIT{21 July 2014 . 6:23:49 pm} Squeak4.5-noBitBlt.image priorSource: 
15895702!

STARTUP{21 July 2014 . 6:31:05 pm} as 
C:\Dev\lang-smalltalk\images\Squeak4.5-noBitBlt.image!

!WeakMessageSend methodsFor: 'accessing' stamp: 'ag 7/21/2014 18:31'!
shouldBeNil

^ shouldBeNil ifNil: [ Array new ]! !
!WeakMessageSend methodsFor: 'private' stamp: 'ag 7/21/2014 18:31' prior: 
33148869!
isAnyArgumentGarbage
"Make sure that my arguments haven't gone away"
arguments ifNotNil: [
arguments with: self shouldBeNil do: [ :arg :flag |
(flag not and: [arg isNil])
ifTrue: [^true]
]
].
^false
! !
!WeakMessageSend methodsFor: 'private' stamp: 'ag 7/21/2014 18:31' prior: 
49450841!
withEnsuredReceiverAndArgumentsDo: aBlock otherwise: altBlock
"Grab real references to receiver and arguments. If they still exist, 
evaluate aBlock."

"Return if my receiver has gone away"
| r a |
r := self receiver.
r ifNil: [ ^altBlock value ].

"Make sure that my arguments haven't gone away"
a := Array withAll: self arguments.
a with: self shouldBeNil do: [ :arg :flag |
arg ifNil: [ flag ifFalse: [ ^altBlock value ]]
].

^aBlock value: r value: a! !
!WeakMessageSend methodsFor: 'private' stamp: 'ag 7/21/2014 18:32' prior: 
34360552!
withEnsuredReceiverAndArgumentsDo: aBlock withEnoughArguments: anArray 
otherwise: altBlock
"call the selector with enough arguments from arguments and anArray"
| r selfArgs enoughArgs |
r := self receiver.
r ifNil: [ ^altBlock value ].

selfArgs := self arguments.
selfArgs with: self shouldBeNil do: [ :arg :flag |
arg ifNil: [ flag ifFalse: [ ^altBlock value ]]
].

enoughArgs := Array new: selector numArgs.
enoughArgs replaceFrom: 1
to: ( selfArgs size min: enoughArgs size)
with: selfArgs

[pypy-commit] lang-smalltalk storage-display-refactoring: Removed --invert flag.

2014-07-22 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-display-refactoring
Changeset: r938:39973aaf497d
Date: 2014-07-22 21:54 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/39973aaf497d/

Log:Removed --invert flag.

diff --git a/spyvm/model_display.py b/spyvm/model_display.py
--- a/spyvm/model_display.py
+++ b/spyvm/model_display.py
@@ -24,12 +24,6 @@
 
 return w_display_bitmap
 
-invert_byte_order = [False]
-
-def invert():
-inv = invert_byte_order[0]
-return jit.promote(inv)
-
 class W_DisplayBitmap(model.W_AbstractObjectWithClassReference):
 _attrs_ = ['pixelbuffer_words', '_real_depth_buffer', '_realsize', 
'display', '_depth']
 _immutable_fields_ = ['pixelbuffer_words?', '_real_depth_buffer', 
'_realsize', 'display', '_depth']
@@ -148,16 +142,13 @@
 repr_classname = "W_8BitDisplayBitmap"
 
 def set_pixelbuffer_word(self, n, word):
-if invert():
-# Invert the byte-order.
-self.pixelbuffer_UINT()[n] = r_uint(
-(word >> 24) |
-((word >> 8) & 0xff00) |
-((word << 8) & 0x00ff) |
-(word << 24)
-)
-else:
-self.pixelbuffer_UINT()[n] = r_uint(word)
+# Invert the byte-order.
+self.pixelbuffer_UINT()[n] = r_uint(
+(word >> 24) |
+((word >> 8) & 0xff00) |
+((word << 8) & 0x00ff) |
+(word << 24)
+)
 
 BITS = r_uint(32)
 class W_MappingDisplayBitmap(W_DisplayBitmap):
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -122,9 +122,6 @@
 headless = False
 elif arg in ["--hacks"]:
 space.run_spy_hacks.activate()
-elif arg in ["--invert"]:
-from spyvm import model_display
-model_display.invert_byte_order[0] = True
 elif arg in ["-S"]:
 space.no_specialized_storage.activate()
 elif arg in ["-u"]:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Added --safe-trace flag which omits printing contents of byte objects.

2014-07-24 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r942:adcfa00d78d1
Date: 2014-07-23 19:27 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/adcfa00d78d1/

Log:Added --safe-trace flag which omits printing contents of byte
objects.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -648,12 +648,13 @@
 
 def _mustBeBoolean(self, interp, receiver):
 return self._sendSpecialSelector(interp, receiver, "mustBeBoolean")
-
+
 def _call_primitive(self, code, interp, argcount, w_method, w_selector):
 # ##
 if interp.is_tracing():
-interp.print_padded("-> primitive %d \t(in %s, named #%s)" % (
-code, 
self.w_method().get_identifier_string(), w_selector.str_content()))
+interp.print_padded("-> primitive %d \t(in %s, named %s)" % (
+code, 
self.w_method().get_identifier_string(),
+w_selector.selector_string()))
 func = primitives.prim_holder.prim_table[code]
 try:
 # note: argcount does not include rcvr
@@ -662,7 +663,7 @@
 except primitives.PrimitiveFailedError, e:
 if interp.is_tracing():
 interp.print_padded("-- primitive %d FAILED\t (in %s, named 
%s)" % (
-code, w_method.safe_identifier_string(), 
w_selector.str_content()))
+code, w_method.safe_identifier_string(), 
w_selector.selector_string()))
 raise e
 
 def _return(self, return_value, interp, local_return=False):
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -194,6 +194,9 @@
 
 def repr_content(self):
 return self.str_content()
+
+def selector_string(self):
+return self.as_repr_string()
 
 class W_SmallInteger(W_Object):
 """Boxed integer value"""
@@ -817,15 +820,22 @@
 return self._size
 
 def str_content(self):
-return "'%s'" % self.as_string()
+if self.has_class() and self.w_class.has_space():
+if self.w_class.space().omit_printing_raw_bytes.is_set():
+return ""
+else:
+return "'%s'" % self.as_string().replace('\r', '\n')
 
 def as_string(self):
 if self.bytes is not None:
 string = "".join(self.bytes)
 else:
 string = "".join([self.c_bytes[i] for i in range(self.size())])
-return string.replace('\r', '\n')
-
+return string
+
+def selector_string(self):
+return "#" + self.as_string()
+
 def invariant(self):
 if not W_AbstractObjectWithClassReference.invariant(self):
 return False
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -52,6 +52,7 @@
 self.suppress_process_switch = ConstantFlag()
 self.run_spy_hacks = ConstantFlag()
 self.headless = ConstantFlag()
+self.omit_printing_raw_bytes = ConstantFlag()
 
 self.classtable = {}
 self.objtable = {}
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -12,7 +12,7 @@
 
 def _usage(argv):
 print """
-Usage: %s  [-r|-m|-h] [-naPu] [-jpiS] [-tlLE]
+Usage: %s  [-r|-m|-h] [-naPu] [-jpiS] [-tslLE]
  - image path (default: Squeak.image)
 
   Execution mode:
@@ -40,6 +40,7 @@
 
   Logging parameters:
 -t|--trace - Output a trace of each message, 
primitive, return value and process switch.
+-s|--safe-trace- Like -t, but without printing 
contents of BytesObjects
 -l|--storage-log   - Output a log of storage operations.
 -L|--storage-log-aggregate - Output an aggregated storage log at 
the end of execution.
 -E|--storage-log-elements  - Include classnames of elements into 
the storage log.
@@ -110,6 +111,9 @@
 selector, idx = get_parameter(argv, idx, arg)
 elif arg in ["-t", "--trace"]:
 trace = True
+elif arg in ["-s", "--safe-trace"]:
+trace = True
+space.omit_printing_raw_bytes.activate()
 elif arg in ["-p", "--poll"]:
 poll = True
 elif arg in ["-a", "--arg"]:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-context-state: Added --safe-trace flag which omits printing contents of byte objects.

2014-07-24 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state
Changeset: r944:eca2665b8824
Date: 2014-07-23 19:27 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/eca2665b8824/

Log:Added --safe-trace flag which omits printing contents of byte
objects.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -685,12 +685,13 @@
 
 def _mustBeBoolean(self, interp, receiver):
 return self._sendSpecialSelector(interp, receiver, "mustBeBoolean")
-
+
 def _call_primitive(self, code, interp, argcount, w_method, w_selector):
 # ##
 if interp.is_tracing():
-interp.print_padded("-> primitive %d \t(in %s, named #%s)" % (
-code, 
self.w_method().get_identifier_string(), w_selector.str_content()))
+interp.print_padded("-> primitive %d \t(in %s, named %s)" % (
+code, 
self.w_method().get_identifier_string(),
+w_selector.selector_string()))
 func = primitives.prim_holder.prim_table[code]
 try:
 # note: argcount does not include rcvr
@@ -699,7 +700,7 @@
 except primitives.PrimitiveFailedError, e:
 if interp.is_tracing():
 interp.print_padded("-- primitive %d FAILED\t (in %s, named 
%s)" % (
-code, w_method.safe_identifier_string(), 
w_selector.str_content()))
+code, w_method.safe_identifier_string(), 
w_selector.selector_string()))
 raise e
 
 def _return(self, return_value, interp, local_return=False):
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -194,6 +194,9 @@
 
 def repr_content(self):
 return self.str_content()
+
+def selector_string(self):
+return self.as_repr_string()
 
 class W_SmallInteger(W_Object):
 """Boxed integer value"""
@@ -817,15 +820,22 @@
 return self._size
 
 def str_content(self):
-return "'%s'" % self.as_string()
+if self.has_class() and self.w_class.has_space():
+if self.w_class.space().omit_printing_raw_bytes.is_set():
+return ""
+else:
+return "'%s'" % self.as_string().replace('\r', '\n')
 
 def as_string(self):
 if self.bytes is not None:
 string = "".join(self.bytes)
 else:
 string = "".join([self.c_bytes[i] for i in range(self.size())])
-return string.replace('\r', '\n')
-
+return string
+
+def selector_string(self):
+return "#" + self.as_string()
+
 def invariant(self):
 if not W_AbstractObjectWithClassReference.invariant(self):
 return False
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -52,6 +52,7 @@
 self.suppress_process_switch = ConstantFlag()
 self.run_spy_hacks = ConstantFlag()
 self.headless = ConstantFlag()
+self.omit_printing_raw_bytes = ConstantFlag()
 
 self.classtable = {}
 self.objtable = {}
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -12,7 +12,7 @@
 
 def _usage(argv):
 print """
-Usage: %s  [-r|-m|-h] [-naPu] [-jpiS] [-tlLE]
+Usage: %s  [-r|-m|-h] [-naPu] [-jpiS] [-tslLE]
  - image path (default: Squeak.image)
 
   Execution mode:
@@ -40,6 +40,7 @@
 
   Logging parameters:
 -t|--trace - Output a trace of each message, 
primitive, return value and process switch.
+-s|--safe-trace- Like -t, but without printing 
contents of BytesObjects
 -l|--storage-log   - Output a log of storage operations.
 -L|--storage-log-aggregate - Output an aggregated storage log at 
the end of execution.
 -E|--storage-log-elements  - Include classnames of elements into 
the storage log.
@@ -110,6 +111,9 @@
 selector, idx = get_parameter(argv, idx, arg)
 elif arg in ["-t", "--trace"]:
 trace = True
+elif arg in ["-s", "--safe-trace"]:
+trace = True
+space.omit_printing_raw_bytes.activate()
 elif arg in ["-p", "--poll"]:
 poll = True
 elif arg in ["-a", "--arg"]:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-context-state: Updated test.

2014-07-24 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state
Changeset: r943:369091d66f5d
Date: 2014-07-23 15:30 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/369091d66f5d/

Log:Updated test.

diff --git a/spyvm/test/test_model.py b/spyvm/test/test_model.py
--- a/spyvm/test/test_model.py
+++ b/spyvm/test/test_model.py
@@ -403,12 +403,23 @@
 for i in xrange(6, 8):
 assert target.pixelbuffer[i] == 0x0
 
-def test_display_offset_computation():
-dbitmap = model_display.W_MappingDisplayBitmap(space, space.w_Array, 5, 1)
+def test_display_offset_computation_even():
+dbitmap = model_display.W_MappingDisplayBitmap(space, space.w_Array, 200, 
1)
+dbitmap.pitch = 64
+dbitmap.words_per_line = 2
 assert dbitmap.compute_pos(0) == 0
-assert dbitmap.compute_pos(1) == 8
-assert dbitmap.size() == 5 * 8
+assert dbitmap.compute_pos(1) == 32
+assert dbitmap.compute_pos(2) == 64
 
+def test_display_offset_computation_uneven():
+dbitmap = model_display.W_MappingDisplayBitmap(space, space.w_Array, 200, 
1)
+dbitmap.pitch = 67
+dbitmap.words_per_line = 2
+assert dbitmap.compute_pos(0) == 0
+assert dbitmap.compute_pos(1) == 32
+assert dbitmap.compute_pos(2) == 67
+assert dbitmap.compute_pos(3) == 67 + 32
+
 @py.test.mark.skipif("socket.gethostname() == 'precise32'")
 def test_weak_pointers():
 w_cls = bootstrap_class(2)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-context-state: Merged.

2014-07-24 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state
Changeset: r945:6f021854ceab
Date: 2014-07-23 19:28 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/6f021854ceab/

Log:Merged.

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-interpreter-refactoring: Finished refactoring. Tests green and compiling.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-interpreter-refactoring
Changeset: r950:1551fe558ac2
Date: 2014-07-25 09:05 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/1551fe558ac2/

Log:Finished refactoring. Tests green and compiling.

diff --git a/spyvm/interpreter_bytecodes.py b/spyvm/interpreter_bytecodes.py
--- a/spyvm/interpreter_bytecodes.py
+++ b/spyvm/interpreter_bytecodes.py
@@ -1,5 +1,5 @@
 
-from spyvm.shadow import ContextPartShadow
+from spyvm.shadow import ContextPartShadow, ClassShadow
 from spyvm import model, primitives, wrapper, error
 from spyvm.tool.bitmanipulation import splitter
 from rpython.rlib import objectmodel, unroll, jit
@@ -357,7 +357,6 @@
 primitives.exitFromHeadlessExecution(self, 
"doesNotUnderstand:", w_message)
 return self._sendSpecialSelector(interp, receiver, 
"doesNotUnderstand", [w_message])
 except error.MethodNotFound:
-from spyvm.shadow import ClassShadow
 s_class = receiver.class_shadow(self.space)
 assert isinstance(s_class, ClassShadow)
 raise error.Exit("Missing doesNotUnderstand in hierarchy of %s" % 
s_class.getname())
@@ -509,6 +508,7 @@
 if self.gettemp(1).is_nil(self.space):
 self.settemp(1, self.space.w_true) # mark unwound
 self.push(self.gettemp(0)) # push the first argument
+from spyvm.interpreter import Return
 try:
 self.bytecodePrimValue(interp, 0)
 except Return, nlr:
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -72,7 +72,7 @@
 print_error("Exited: %s" % e.msg)
 return -1
 except error.SmalltalkException, e:
-print_error("Unhandled Smalltalk Exception type %s. Message: %s" % 
(e.exception_type, e.msg)
+print_error("Unhandled %s. Message: %s" % (e.exception_type, e.msg))
 return -1
 except BaseException, e:
 print_error("Exception: %s" % str(e))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-interpreter-refactoring: Updated test.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-interpreter-refactoring
Changeset: r949:b18685474409
Date: 2014-07-23 15:30 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/b18685474409/

Log:Updated test.

diff --git a/spyvm/test/test_model.py b/spyvm/test/test_model.py
--- a/spyvm/test/test_model.py
+++ b/spyvm/test/test_model.py
@@ -404,12 +404,23 @@
 for i in xrange(6, 8):
 assert target.pixelbuffer[i] == 0x0
 
-def test_display_offset_computation():
-dbitmap = model_display.W_MappingDisplayBitmap(space, space.w_Array, 5, 1)
+def test_display_offset_computation_even():
+dbitmap = model_display.W_MappingDisplayBitmap(space, space.w_Array, 200, 
1)
+dbitmap.pitch = 64
+dbitmap.words_per_line = 2
 assert dbitmap.compute_pos(0) == 0
-assert dbitmap.compute_pos(1) == 8
-assert dbitmap.size() == 5 * 8
+assert dbitmap.compute_pos(1) == 32
+assert dbitmap.compute_pos(2) == 64
 
+def test_display_offset_computation_uneven():
+dbitmap = model_display.W_MappingDisplayBitmap(space, space.w_Array, 200, 
1)
+dbitmap.pitch = 67
+dbitmap.words_per_line = 2
+assert dbitmap.compute_pos(0) == 0
+assert dbitmap.compute_pos(1) == 32
+assert dbitmap.compute_pos(2) == 67
+assert dbitmap.compute_pos(3) == 67 + 32
+
 @py.test.mark.skipif("socket.gethostname() == 'precise32'")
 def test_weak_pointers():
 w_cls = bootstrap_class(2)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Fixed printing of ByteObjects.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r947:d8f09e784dd7
Date: 2014-07-24 19:23 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/d8f09e784dd7/

Log:Fixed printing of ByteObjects.

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -823,8 +823,7 @@
 if self.has_class() and self.w_class.has_space():
 if self.w_class.space().omit_printing_raw_bytes.is_set():
 return ""
-else:
-return "'%s'" % self.as_string().replace('\r', '\n')
+return "'%s'" % self.as_string().replace('\r', '\n')
 
 def as_string(self):
 if self.bytes is not None:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-context-state-v2: Added the rest of the refactoring.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state-v2
Changeset: r955:92d182dabea1
Date: 2014-07-25 16:33 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/92d182dabea1/

Log:Added the rest of the refactoring.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -1,7 +1,7 @@
 import os
 
 from spyvm.shadow import MethodContextShadow, ActiveContext, InactiveContext, 
DirtyContext
-from spyvm import model, constants, wrapper, objspace, interpreter_bytecodes
+from spyvm import model, constants, wrapper, objspace, interpreter_bytecodes, 
error
 
 from rpython.rlib import jit, rstackovf, unroll
 
@@ -17,6 +17,16 @@
 self.s_target_context = s_target_context
 self.is_local = is_local
 
+class NonVirtualReturn(Exception):
+_attrs_ = ["s_target_context", "s_current_context", "value"]
+def __init__(self, s_target_context, s_current_context, w_result):
+self.value = w_result
+self.s_target_context = s_target_context
+self.s_current_context = s_current_context
+
+def print_trace(self):
+print "\n== Sender Chain Manipulation, contexts forced to heap at: 
%s" % self.s_current_context.short_str()
+
 class LocalReturn(Exception):
 _attrs_ = ["value"]
 def __init__(self, value):
@@ -25,14 +35,13 @@
 class ContextSwitchException(Exception):
 """General Exception that causes the interpreter to leave
 the current context."""
-
 _attrs_ = ["s_new_context"]
 type = "ContextSwitch"
 def __init__(self, s_new_context):
 self.s_new_context = s_new_context
 
-def print_trace(self, old_context):
-print "== %s, contexts forced to heap at: %s" % (self.type, 
self.s_new_context.short_str())
+def print_trace(self):
+print "\n== %s at: %s" % (self.type, 
self.s_new_context.short_str())
 
 class StackOverflow(ContextSwitchException):
 """This causes the current jit-loop to be left, dumping all virtualized 
objects to the heap.
@@ -43,17 +52,8 @@
 class ProcessSwitch(ContextSwitchException):
 """This causes the interpreter to switch the executed context.
 Triggered when switching the process."""
+type = "Process Switch"
 
-def print_trace(self, old_context):
-print "== Switched process from: %s" % old_context.short_str()
-print "== to: %s " % self.s_new_context.short_str()
-
-class SenderChainManipulation(ContextSwitchException):
-"""Manipulation of the sender chain can invalidate the jitted C stack.
-We have to dump all virtual objects and rebuild the stack.
-We try to raise this as rarely as possible and as late as possible."""
-type = "Sender Manipulation"
-
 UNROLLING_BYTECODE_RANGES = 
unroll.unrolling_iterable(interpreter_bytecodes.BYTECODE_RANGES)
 
 def get_printable_location(pc, self, method):
@@ -98,23 +98,27 @@
 
 def loop(self, w_active_context):
 # This is the top-level loop and is not invoked recursively.
-s_new_context = w_active_context.as_context_get_shadow(self.space)
+s_context = w_active_context.as_context_get_shadow(self.space)
 while True:
-s_sender = s_new_context.s_sender()
+s_sender = s_context.s_sender()
 try:
-self.stack_frame(s_new_context, None)
+self.stack_frame(s_context, None)
 raise Exception("loop_bytecodes left without raising...")
 except ContextSwitchException, e:
 if self.is_tracing():
-e.print_trace(s_new_context)
-s_new_context = e.s_new_context
+e.print_trace()
+s_context = e.s_new_context
 except LocalReturn, ret:
-s_new_context = self.unwind_context_chain(s_sender, s_sender, 
ret.value)
+s_context = self.unwind_context_chain(s_sender, s_sender, 
ret.value, "LocalReturn")
 except Return, ret:
-s_new_context = self.unwind_context_chain(s_sender, 
ret.s_target_context, ret.value)
+s_context = self.unwind_context_chain(s_sender, 
ret.s_target_context, ret.value, "Return")
+except NonVirtualReturn, ret:
+if self.is_tracing():
+ret.print_trace()
+s_context = self.unwind_context_chain(ret.s_current_context, 
ret.s_target_context, ret.value, "NonVirtual")
 
-# This is a wrapper around loop_bytecodes that cleanly enters/leaves the 
frame
-# and handles the stack overflow protection mechanism.
+# This is a wrapper around loop_bytecodes that cleanly enters/leaves the 
frame,
+# handles the stack overflow protection mechanism and handles/dispatches 
Returns.
 def stack_frame(self, s_frame, s_sender, may_context_switch=True):
 try:
 if self.is_tracing():
@@ -129,17 +133,21 @@
 rstackovf.check_stack_overflo

[pypy-commit] lang-smalltalk storage: Commented out instpecting of event input queue in #fetchMoreEvents.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r958:6e826a50e53c
Date: 2014-07-26 10:26 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/6e826a50e53c/

Log:Commented out instpecting of event input queue in #fetchMoreEvents.

diff --git a/images/Squeak4.5-noBitBlt.changes 
b/images/Squeak4.5-noBitBlt.changes
--- a/images/Squeak4.5-noBitBlt.changes
+++ b/images/Squeak4.5-noBitBlt.changes
@@ -12631,4 +12631,4 @@
 
 1+1!
 
-QUIT/NOSAVE{21 July 2014 . 4:33:15 pm} Squeak4.5-noBitBlt.image 
priorSource: 15898877!
\ No newline at end of file
+QUIT/NOSAVE{21 July 2014 . 4:33:15 pm} Squeak4.5-noBitBlt.image 
priorSource: 15898877!

STARTUP{26 July 2014 . 10:25:02 am} as 
C:\Dev\lang-smalltalk\images\Squeak4.5-noBitBlt.image!

!EventSensor methodsFor: 'private-I/O' stamp: 'ag 7/26/2014 10:25' prior: 
47373772!
fetchMoreEvents
"Fetch more events from the VM"
| eventBuffer type |

"Reset input semaphore so clients can wait for the next events after 
this one."
inputSemaphore isSignaled
ifTrue: [ hasInputSemaphore := true.
inputSemaphore initSignals ].

"Remember the last time that I checked for events."
lastEventPoll := Time millisecondClockValue.

eventBuffer := Array new: 8.
[self primGetNextEvent: eventBuffer.
type := eventBuffer at: 1.
"type = EventTypeWindow ifTrue: [eventBuffer inspect]."
type = EventTypeNone]
whileFalse: [self processEvent: eventBuffer].
! !

QUIT{26 July 2014 . 10:25:36 am} Squeak4.5-noBitBlt.image priorSource: 
15898877!
\ No newline at end of file
diff --git a/images/Squeak4.5-noBitBlt.image b/images/Squeak4.5-noBitBlt.image
index 
00843c2c83f9c11e5dcfa3b9927bd415d0a22cd8..09f9fb6fb17051fefa839fb357c4170d285c1c8a
GIT binary patch

[cut]

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-context-state-v2: Added part of the context state refactoring.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state-v2
Changeset: r954:7292a07cb139
Date: 2014-07-25 11:07 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/7292a07cb139/

Log:Added part of the context state refactoring.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -12,10 +12,15 @@
 
 class Return(Exception):
 _attrs_ = ["value", "s_target_context", "is_local"]
-def __init__(self, s_target_context, w_result):
+def __init__(self, s_target_context, w_result, is_local):
 self.value = w_result
 self.s_target_context = s_target_context
-self.is_local = False
+self.is_local = is_local
+
+class LocalReturn(Exception):
+_attrs_ = ["value"]
+def __init__(self, value):
+self.value = value
 
 class ContextSwitchException(Exception):
 """General Exception that causes the interpreter to leave
@@ -97,21 +102,44 @@
 while True:
 s_sender = s_new_context.s_sender()
 try:
-self.loop_bytecodes(s_new_context)
+self.stack_frame(s_new_context, None)
 raise Exception("loop_bytecodes left without raising...")
 except ContextSwitchException, e:
 if self.is_tracing():
 e.print_trace(s_new_context)
 s_new_context = e.s_new_context
-except Return, nlr:
-assert nlr.s_target_context or nlr.is_local
-s_new_context = s_sender
-if not nlr.is_local:
-while s_new_context is not nlr.s_target_context:
-s_sender = s_new_context.s_sender()
-s_new_context._activate_unwind_context(self)
-s_new_context = s_sender
-s_new_context.push(nlr.value)
+except LocalReturn, ret:
+s_new_context = self.unwind_context_chain(s_sender, s_sender, 
ret.value)
+except Return, ret:
+s_new_context = self.unwind_context_chain(s_sender, 
ret.s_target_context, ret.value)
+
+# This is a wrapper around loop_bytecodes that cleanly enters/leaves the 
frame
+# and handles the stack overflow protection mechanism.
+def stack_frame(self, s_frame, s_sender, may_context_switch=True):
+try:
+if self.is_tracing():
+self.stack_depth += 1
+if s_frame._s_sender is None and s_sender is not None:
+s_frame.store_s_sender(s_sender)
+# Now (continue to) execute the context bytecodes
+assert s_frame.state is InactiveContext
+s_frame.state = ActiveContext
+self.loop_bytecodes(s_frame, may_context_switch)
+except rstackovf.StackOverflow:
+rstackovf.check_stack_overflow()
+raise StackOverflow(s_frame)
+except Return, ret:
+if ret.is_local:
+raise LocalReturn(ret.value)
+else:
+raise ret
+finally:
+if self.is_tracing():
+self.stack_depth -= 1
+dirty_frame = s_frame.state is DirtyContext
+s_frame.state = InactiveContext
+if dirty_frame:
+raise SenderChainManipulation(s_frame)
 
 def loop_bytecodes(self, s_context, may_context_switch=True):
 old_pc = 0
@@ -133,39 +161,22 @@
 s_context=s_context)
 try:
 self.step(s_context)
-except Return, nlr:
-if nlr.s_target_context is s_context or nlr.is_local:
-s_context.push(nlr.value)
-else:
-if nlr.s_target_context is None:
-# This is the case where we are returning to our 
sender.
-# Mark the return as local, so our sender will take it
-nlr.is_local = True
-s_context._activate_unwind_context(self)
-raise nlr
-
-# This is a wrapper around loop_bytecodes that cleanly enters/leaves the 
frame
-# and handles the stack overflow protection mechanism.
-def stack_frame(self, s_frame, s_sender, may_context_switch=True):
-try:
-if self.is_tracing():
-self.stack_depth += 1
-if s_frame._s_sender is None and s_sender is not None:
-s_frame.store_s_sender(s_sender)
-# Now (continue to) execute the context bytecodes
-assert s_frame.state is InactiveContext
-s_frame.state = ActiveContext
-self.loop_bytecodes(s_frame, may_context_switch)
-except rstackovf.StackOverflow:
-rstackovf.check_stack_overflow()
-raise StackOverflow(s_frame)
-finally:
-if self.is_tracing():
-self.stack_depth -= 1
-dirty_frame = s_frame.

[pypy-commit] lang-smalltalk storage-context-state-v2: Removed LocalReturn exception, handling it with flags in the Return exception.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state-v2
Changeset: r959:b76819c9b3b6
Date: 2014-07-27 11:18 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/b76819c9b3b6/

Log:Removed LocalReturn exception, handling it with flags in the Return
exception. This fixed drawing issue in the mini image.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -11,11 +11,13 @@
 self.object = object
 
 class Return(Exception):
-_attrs_ = ["value", "s_target_context", "is_local"]
-def __init__(self, s_target_context, w_result, is_local):
+_attrs_ = ["value", "s_target_context", "is_local", "arrived_at_target"]
+_immutable_attrs_ = ["value", "s_target_context", "is_local"]
+def __init__(self, s_target_context, w_result):
 self.value = w_result
 self.s_target_context = s_target_context
-self.is_local = is_local
+self.arrived_at_target = False
+self.is_local = s_target_context is None
 
 class NonVirtualReturn(Exception):
 _attrs_ = ["s_target_context", "s_current_context", "value"]
@@ -27,11 +29,6 @@
 def print_trace(self):
 print "\n== Sender Chain Manipulation, contexts forced to heap at: 
%s" % self.s_current_context.short_str()
 
-class LocalReturn(Exception):
-_attrs_ = ["value"]
-def __init__(self, value):
-self.value = value
-
 class ContextSwitchException(Exception):
 """General Exception that causes the interpreter to leave
 the current context."""
@@ -108,14 +105,13 @@
 if self.is_tracing():
 e.print_trace()
 s_context = e.s_new_context
-except LocalReturn, ret:
-s_context = self.unwind_context_chain(s_sender, s_sender, 
ret.value, "LocalReturn")
 except Return, ret:
-s_context = self.unwind_context_chain(s_sender, 
ret.s_target_context, ret.value, "Return")
+target = s_sender if ret.arrived_at_target else 
ret.s_target_context
+s_context = self.unwind_context_chain(s_sender, target, 
ret.value)
 except NonVirtualReturn, ret:
 if self.is_tracing():
 ret.print_trace()
-s_context = self.unwind_context_chain(ret.s_current_context, 
ret.s_target_context, ret.value, "NonVirtual")
+s_context = self.unwind_context_chain(ret.s_current_context, 
ret.s_target_context, ret.value)
 
 # This is a wrapper around loop_bytecodes that cleanly enters/leaves the 
frame,
 # handles the stack overflow protection mechanism and handles/dispatches 
Returns.
@@ -140,10 +136,9 @@
 raise NonVirtualReturn(target_context, s_sender, ret.value)
 else:
 s_frame._activate_unwind_context(self)
-if ret.s_target_context is s_sender or ret.is_local:
-raise LocalReturn(ret.value)
-else:
-raise ret
+if ret.is_local or ret.s_target_context is s_sender:
+ret.arrived_at_target = True
+raise ret
 finally:
 if self.is_tracing():
 self.stack_depth -= 1
@@ -169,10 +164,13 @@
 s_context=s_context)
 try:
 self.step(s_context)
-except LocalReturn, ret:
-s_context.push(ret.value)
+except Return, ret:
+if ret.arrived_at_target:
+s_context.push(ret.value)
+else:
+raise ret
 
-def unwind_context_chain(self, start_context, target_context, 
return_value, source=""):
+def unwind_context_chain(self, start_context, target_context, 
return_value):
 if start_context is None:
 # This is the toplevel frame. Execution ended.
 raise ReturnFromTopLevel(return_value)
@@ -180,8 +178,7 @@
 context = start_context
 while context is not target_context:
 if not context:
-msg = "Context chain ended (source: %s) while trying to 
return\n%s\nfrom\n%s\n(pc %s)\nto\n%s\n(pc %s)" % (
-source,
+msg = "Context chain ended while trying to 
return\n%s\nfrom\n%s\n(pc %s)\nto\n%s\n(pc %s)" % (
 return_value.as_repr_string(),
 start_context.short_str(),
 start_context.pc(),
diff --git a/spyvm/interpreter_bytecodes.py b/spyvm/interpreter_bytecodes.py
--- a/spyvm/interpreter_bytecodes.py
+++ b/spyvm/interpreter_bytecodes.py
@@ -393,13 +393,12 @@
 # it will find the sender as a local, and we don't have to
 # force the reference
 s_return_to = None
-is_local = True
 else:
 s_return_to = self.s_home().s_sender()
-is_local = False
+assert s_r

[pypy-commit] lang-smalltalk storage: Merged.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r960:3c59d53022d4
Date: 2014-07-27 11:24 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/3c59d53022d4/

Log:Merged.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -1,7 +1,7 @@
 import os
 
-from spyvm.shadow import MethodContextShadow
-from spyvm import model, constants, wrapper, objspace, interpreter_bytecodes
+from spyvm.shadow import MethodContextShadow, ActiveContext, InactiveContext, 
DirtyContext
+from spyvm import model, constants, wrapper, objspace, interpreter_bytecodes, 
error
 
 from rpython.rlib import jit, rstackovf, unroll
 
@@ -11,23 +11,34 @@
 self.object = object
 
 class Return(Exception):
-_attrs_ = ["value", "s_target_context", "is_local"]
+_attrs_ = ["value", "s_target_context", "is_local", "arrived_at_target"]
+_immutable_attrs_ = ["value", "s_target_context", "is_local"]
 def __init__(self, s_target_context, w_result):
 self.value = w_result
 self.s_target_context = s_target_context
-self.is_local = False
+self.arrived_at_target = False
+self.is_local = s_target_context is None
+
+class NonVirtualReturn(Exception):
+_attrs_ = ["s_target_context", "s_current_context", "value"]
+def __init__(self, s_target_context, s_current_context, w_result):
+self.value = w_result
+self.s_target_context = s_target_context
+self.s_current_context = s_current_context
+
+def print_trace(self):
+print "\n== Sender Chain Manipulation, contexts forced to heap at: 
%s" % self.s_current_context.short_str()
 
 class ContextSwitchException(Exception):
 """General Exception that causes the interpreter to leave
 the current context."""
-
 _attrs_ = ["s_new_context"]
 type = "ContextSwitch"
 def __init__(self, s_new_context):
 self.s_new_context = s_new_context
 
-def print_trace(self, old_context):
-print "== %s, contexts forced to heap at: %s" % (self.type, 
self.s_new_context.short_str())
+def print_trace(self):
+print "\n== %s at: %s" % (self.type, 
self.s_new_context.short_str())
 
 class StackOverflow(ContextSwitchException):
 """This causes the current jit-loop to be left, dumping all virtualized 
objects to the heap.
@@ -38,17 +49,8 @@
 class ProcessSwitch(ContextSwitchException):
 """This causes the interpreter to switch the executed context.
 Triggered when switching the process."""
+type = "Process Switch"
 
-def print_trace(self, old_context):
-print "== Switched process from: %s" % old_context.short_str()
-print "== to: %s " % self.s_new_context.short_str()
-
-class SenderChainManipulation(ContextSwitchException):
-"""Manipulation of the sender chain can invalidate the jitted C stack.
-We have to dump all virtual objects and rebuild the stack.
-We try to raise this as rarely as possible and as late as possible."""
-type = "Sender Manipulation"
-
 UNROLLING_BYTECODE_RANGES = 
unroll.unrolling_iterable(interpreter_bytecodes.BYTECODE_RANGES)
 
 def get_printable_location(pc, self, method):
@@ -94,25 +96,54 @@
 
 def loop(self, w_active_context):
 # This is the top-level loop and is not invoked recursively.
-s_new_context = w_active_context.as_context_get_shadow(self.space)
+s_context = w_active_context.as_context_get_shadow(self.space)
 while True:
-s_sender = s_new_context.s_sender()
+s_sender = s_context.s_sender()
 try:
-self.loop_bytecodes(s_new_context)
+self.stack_frame(s_context, None)
 raise Exception("loop_bytecodes left without raising...")
 except ContextSwitchException, e:
-if self.is_tracing() or self.trace_important:
-e.print_trace(s_new_context)
-s_new_context = e.s_new_context
-except Return, nlr:
-assert nlr.s_target_context or nlr.is_local
-s_new_context = s_sender
-if not nlr.is_local:
-while s_new_context is not nlr.s_target_context:
-s_sender = s_new_context.s_sender()
-s_new_context._activate_unwind_context(self)
-s_new_context = s_sender
-s_new_context.push(nlr.value)
+if self.is_tracing():
+e.print_trace()
+s_context = e.s_new_context
+except Return, ret:
+target = s_sender if ret.arrived_at_target else 
ret.s_target_context
+s_context = self.unwind_context_chain(s_sender, target, 
ret.value)
+except NonVirtualReturn, ret:
+if self.is_tracing():
+ret.print_trace()
+s_context = self.unwind_context_

[pypy-commit] lang-smalltalk storage: Added trace option to only show process switches, stack overflows and sender chain manipulations.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r957:4e239fce82f4
Date: 2014-07-26 10:24 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/4e239fce82f4/

Log:Added trace option to only show process switches, stack overflows
and sender chain manipulations.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -58,7 +58,7 @@
 
 class Interpreter(object):
 _immutable_fields_ = ["space", "image",
-  "interrupt_counter_size",
+  "interrupt_counter_size", "trace_important",
   "startup_time", "evented", "interrupts"]
 
 jit_driver = jit.JitDriver(
@@ -68,7 +68,7 @@
 get_printable_location=get_printable_location
 )
 
-def __init__(self, space, image=None,
+def __init__(self, space, image=None, trace_important=False,
 trace=False, evented=True, interrupts=True):
 # === Initialize immutable variables
 self.space = space
@@ -79,6 +79,7 @@
 self.startup_time = constants.CompileTime
 self.evented = evented
 self.interrupts = interrupts
+self.trace_important = trace_important
 try:
 self.interrupt_counter_size = int(os.environ["SPY_ICS"])
 except KeyError:
@@ -100,7 +101,7 @@
 self.loop_bytecodes(s_new_context)
 raise Exception("loop_bytecodes left without raising...")
 except ContextSwitchException, e:
-if self.is_tracing():
+if self.is_tracing() or self.trace_important:
 e.print_trace(s_new_context)
 s_new_context = e.s_new_context
 except Return, nlr:
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -12,7 +12,7 @@
 
 def _usage(argv):
 print """
-Usage: %s  [-r|-m|-h] [-naPu] [-jpiS] [-tslLE]
+Usage: %s  [-r|-m|-h] [-naPu] [-jpiS] [-tTslLE]
  - image path (default: Squeak.image)
 
   Execution mode:
@@ -40,7 +40,8 @@
 
   Logging parameters:
 -t|--trace - Output a trace of each message, 
primitive, return value and process switch.
--s|--safe-trace- Like -t, but without printing 
contents of BytesObjects
+-T - Trace important events (Process 
switch, stack overflow, sender chain manipulation)
+-s|--safe-trace- If tracing is active, omit printing 
contents of BytesObjects
 -l|--storage-log   - Output a log of storage operations.
 -L|--storage-log-aggregate - Output an aggregated storage log at 
the end of execution.
 -E|--storage-log-elements  - Include classnames of elements into 
the storage log.
@@ -94,6 +95,7 @@
 poll = False
 interrupts = True
 trace = False
+trace_important = False
 
 space = prebuilt_space
 idx = 1
@@ -114,8 +116,9 @@
 selector, idx = get_parameter(argv, idx, arg)
 elif arg in ["-t", "--trace"]:
 trace = True
+elif arg in ["-T"]:
+trace_important = True
 elif arg in ["-s", "--safe-trace"]:
-trace = True
 space.omit_printing_raw_bytes.activate()
 elif arg in ["-p", "--poll"]:
 poll = True
@@ -169,8 +172,8 @@
 image_reader = squeakimage.reader_for_image(space, 
squeakimage.Stream(data=imagedata))
 image = create_image(space, image_reader)
 interp = interpreter.Interpreter(space, image,
-trace=trace, evented=not poll,
-interrupts=interrupts)
+trace=trace, trace_important=trace_important,
+evented=not poll, interrupts=interrupts)
 space.runtime_setup(argv[0], path)
 print_error("") # Line break after image-loading characters
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-interpreter-refactoring: Intermediate commit.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-interpreter-refactoring
Changeset: r948:3d889c32a173
Date: 2014-07-25 08:55 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/3d889c32a173/

Log:Intermediate commit. Added message to all SmalltalkExceptions,
catching and printing at toplevel. Extracted
interpreter_debugging.py and interpreter_bytecodes.py.

diff too long, truncating to 2000 out of 2010 lines

diff --git a/spyvm/error.py b/spyvm/error.py
--- a/spyvm/error.py
+++ b/spyvm/error.py
@@ -1,30 +1,42 @@
-# some exception classes for the Smalltalk VM
+
+# Some exception classes for the Smalltalk VM
 
 class SmalltalkException(Exception):
 """Base class for Smalltalk exception hierarchy"""
+exception_type = "SmalltalkException"
+_attrs_ = ["msg"]
+def __init__(self, msg=""):
+self.msg = msg
 
 class PrimitiveFailedError(SmalltalkException):
-pass
+exception_type = "PrimitiveFailedError"
 
 class PrimitiveNotYetWrittenError(PrimitiveFailedError):
-pass
+exception_type = "PrimitiveNotYetWrittenError"
 
 class UnwrappingError(PrimitiveFailedError):
-pass
+exception_type = "UnwrappingError"
 
 class WrappingError(PrimitiveFailedError):
-pass
+exception_type = "WrappingError"
 
 class WrapperException(SmalltalkException):
-def __init__(self, msg):
-self.msg = msg
+exception_type = "WrapperException"
 
 class FatalError(SmalltalkException):
-def __init__(self, msg):
-self.msg = msg
+exception_type = "FatalError"
 
 class BlockCannotReturnError(SmalltalkException):
-   pass
+   exception_type = "BlockCannotReturnError"
+
+class MethodNotFound(SmalltalkException):
+exception_type = "MethodNotFound"
+
+class MissingBytecode(SmalltalkException):
+"""Bytecode not implemented yet."""
+exception_type = "MissingBytecode"
+def __init__(self, bytecodename):
+SmalltalkException.__init__(self, "Missing bytecode encountered: %s" % 
bytecodename)
 
 class Exit(Exception):
 _attrs_ = ["msg"]
diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -1,26 +1,60 @@
-import py
 import os
-from spyvm.shadow import ContextPartShadow, MethodContextShadow, 
BlockContextShadow, MethodNotFound
-from spyvm import model, constants, primitives, conftest, wrapper, objspace
-from spyvm.tool.bitmanipulation import splitter
 
-from rpython.rlib import jit, rstackovf
-from rpython.rlib import objectmodel, unroll
+from spyvm.shadow import MethodContextShadow
+from spyvm import model, constants, wrapper, objspace, interpreter_bytecodes
 
-class MissingBytecode(Exception):
-"""Bytecode not implemented yet."""
-def __init__(self, bytecodename):
-self.bytecodename = bytecodename
-print "MissingBytecode:", bytecodename # hack for debugging
+from rpython.rlib import jit, rstackovf, unroll
 
-class IllegalStoreError(Exception):
-"""Illegal Store."""
+class ReturnFromTopLevel(Exception):
+_attrs_ = ["object"]
+def __init__(self, object):
+self.object = object
+
+class Return(Exception):
+_attrs_ = ["value", "s_target_context", "is_local"]
+def __init__(self, s_target_context, w_result):
+self.value = w_result
+self.s_target_context = s_target_context
+self.is_local = False
+
+class ContextSwitchException(Exception):
+"""General Exception that causes the interpreter to leave
+the current context."""
+
+_attrs_ = ["s_new_context"]
+type = "ContextSwitch"
+def __init__(self, s_new_context):
+self.s_new_context = s_new_context
+
+def print_trace(self, old_context):
+print "== %s, contexts forced to heap at: %s" % (self.type, 
self.s_new_context.short_str())
+
+class StackOverflow(ContextSwitchException):
+"""This causes the current jit-loop to be left, dumping all virtualized 
objects to the heap.
+This breaks performance, so it should rarely happen.
+In case of severe performance problems, execute with -t and check if this 
occurrs."""
+type = "Stack Overflow"
+
+class ProcessSwitch(ContextSwitchException):
+"""This causes the interpreter to switch the executed context.
+Triggered when switching the process."""
+
+def print_trace(self, old_context):
+print "== Switched process from: %s" % old_context.short_str()
+print "== to: %s " % self.s_new_context.short_str()
+
+class SenderChainManipulation(ContextSwitchException):
+"""Manipulation of the sender chain can invalidate the jitted C stack.
+We have to dump all virtual objects and rebuild the stack.
+We try to raise this as rarely as possible and as late as possible."""
+type = "Sender Manipulation"
+
+UNROLLING_BYTECODE_RANGES = 
unroll.unrolling_iterable(interpreter_bytecodes.BYTECODE_RANGES)
 
 def get_printable_location(pc, self, method):
 bc = ord(method.bytes[pc])
 name = method.s

[pypy-commit] lang-smalltalk storage: Merged.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r951:c78638460d93
Date: 2014-07-25 09:07 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/c78638460d93/

Log:Merged.

diff too long, truncating to 2000 out of 2038 lines

diff --git a/spyvm/error.py b/spyvm/error.py
--- a/spyvm/error.py
+++ b/spyvm/error.py
@@ -1,30 +1,42 @@
-# some exception classes for the Smalltalk VM
+
+# Some exception classes for the Smalltalk VM
 
 class SmalltalkException(Exception):
 """Base class for Smalltalk exception hierarchy"""
+exception_type = "SmalltalkException"
+_attrs_ = ["msg"]
+def __init__(self, msg=""):
+self.msg = msg
 
 class PrimitiveFailedError(SmalltalkException):
-pass
+exception_type = "PrimitiveFailedError"
 
 class PrimitiveNotYetWrittenError(PrimitiveFailedError):
-pass
+exception_type = "PrimitiveNotYetWrittenError"
 
 class UnwrappingError(PrimitiveFailedError):
-pass
+exception_type = "UnwrappingError"
 
 class WrappingError(PrimitiveFailedError):
-pass
+exception_type = "WrappingError"
 
 class WrapperException(SmalltalkException):
-def __init__(self, msg):
-self.msg = msg
+exception_type = "WrapperException"
 
 class FatalError(SmalltalkException):
-def __init__(self, msg):
-self.msg = msg
+exception_type = "FatalError"
 
 class BlockCannotReturnError(SmalltalkException):
-   pass
+   exception_type = "BlockCannotReturnError"
+
+class MethodNotFound(SmalltalkException):
+exception_type = "MethodNotFound"
+
+class MissingBytecode(SmalltalkException):
+"""Bytecode not implemented yet."""
+exception_type = "MissingBytecode"
+def __init__(self, bytecodename):
+SmalltalkException.__init__(self, "Missing bytecode encountered: %s" % 
bytecodename)
 
 class Exit(Exception):
 _attrs_ = ["msg"]
diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -1,26 +1,60 @@
-import py
 import os
-from spyvm.shadow import ContextPartShadow, MethodContextShadow, 
BlockContextShadow, MethodNotFound
-from spyvm import model, constants, primitives, conftest, wrapper, objspace
-from spyvm.tool.bitmanipulation import splitter
 
-from rpython.rlib import jit, rstackovf
-from rpython.rlib import objectmodel, unroll
+from spyvm.shadow import MethodContextShadow
+from spyvm import model, constants, wrapper, objspace, interpreter_bytecodes
 
-class MissingBytecode(Exception):
-"""Bytecode not implemented yet."""
-def __init__(self, bytecodename):
-self.bytecodename = bytecodename
-print "MissingBytecode:", bytecodename # hack for debugging
+from rpython.rlib import jit, rstackovf, unroll
 
-class IllegalStoreError(Exception):
-"""Illegal Store."""
+class ReturnFromTopLevel(Exception):
+_attrs_ = ["object"]
+def __init__(self, object):
+self.object = object
+
+class Return(Exception):
+_attrs_ = ["value", "s_target_context", "is_local"]
+def __init__(self, s_target_context, w_result):
+self.value = w_result
+self.s_target_context = s_target_context
+self.is_local = False
+
+class ContextSwitchException(Exception):
+"""General Exception that causes the interpreter to leave
+the current context."""
+
+_attrs_ = ["s_new_context"]
+type = "ContextSwitch"
+def __init__(self, s_new_context):
+self.s_new_context = s_new_context
+
+def print_trace(self, old_context):
+print "== %s, contexts forced to heap at: %s" % (self.type, 
self.s_new_context.short_str())
+
+class StackOverflow(ContextSwitchException):
+"""This causes the current jit-loop to be left, dumping all virtualized 
objects to the heap.
+This breaks performance, so it should rarely happen.
+In case of severe performance problems, execute with -t and check if this 
occurrs."""
+type = "Stack Overflow"
+
+class ProcessSwitch(ContextSwitchException):
+"""This causes the interpreter to switch the executed context.
+Triggered when switching the process."""
+
+def print_trace(self, old_context):
+print "== Switched process from: %s" % old_context.short_str()
+print "== to: %s " % self.s_new_context.short_str()
+
+class SenderChainManipulation(ContextSwitchException):
+"""Manipulation of the sender chain can invalidate the jitted C stack.
+We have to dump all virtual objects and rebuild the stack.
+We try to raise this as rarely as possible and as late as possible."""
+type = "Sender Manipulation"
+
+UNROLLING_BYTECODE_RANGES = 
unroll.unrolling_iterable(interpreter_bytecodes.BYTECODE_RANGES)
 
 def get_printable_location(pc, self, method):
 bc = ord(method.bytes[pc])
 name = method.safe_identifier_string()
-return '(%s) [%d]: <%s>%s' % (name, pc, hex(bc), BYTECODE_NAMES[bc])
-
+return '(%s) [%d]: <%s>%s' % (name, pc, hex(bc), 
interpreter_bytecodes.BYTECODE_NAMES[bc]

[pypy-commit] lang-smalltalk storage: Cleaned up tests a little by extracting helper methods.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r961:95be1db81391
Date: 2014-07-27 12:16 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/95be1db81391/

Log:Cleaned up tests a little by extracting helper methods.

diff --git a/spyvm/test/test_interpreter.py b/spyvm/test/test_interpreter.py
--- a/spyvm/test/test_interpreter.py
+++ b/spyvm/test/test_interpreter.py
@@ -9,16 +9,22 @@
 def setup_module():
 space, interp = create_space_interp(bootstrap = True)
 w = space.w
+interpret_bc = interp.interpret_bc
 copy_to_module(locals(), __name__)
 
 def teardown_module():
 cleanup_module(__name__)
 
+# === Helper methods ===
+
 def bootstrap_class(instsize, w_superclass=None, w_metaclass=None,
 name='?', format=shadow.POINTERS, varsized=True):
 return space.bootstrap_class(instsize, w_superclass, w_metaclass,
 name, format, varsized)
 
+def new_frame(bytes, receiver=None):
+return space.make_frame(bytes, receiver=receiver, args=[w("foo"), 
w("bar")])
+
 def step_in_interp(ctxt): # due to missing resets in between tests
 interp._loop = False
 try:
@@ -89,22 +95,8 @@
 return lit
 return [fakeliteral(lit) for lit in literals]
 
-def _new_frame(space, bytes, receiver=None):
-assert isinstance(bytes, str)
-w_method = model.W_CompiledMethod(space, len(bytes))
-w_method.islarge = 1
-w_method.bytes = bytes
-w_method.argsize=2
-w_method._tempsize=8
-w_method.setliterals([model.W_PointersObject(space, None, 2)])
-if receiver is None:
-receiver = space.w_nil
-s_frame = w_method.create_frame(space, receiver, [space.w("foo"), 
space.w("bar")])
-return s_frame.w_self(), s_frame
+# === Test methods ===
 
-def new_frame(bytes, receiver=None):
-return _new_frame(space, bytes, receiver)
-
 def test_create_frame():
 w_method = model.W_CompiledMethod(space, len("hello"))
 w_method.bytes="hello"
@@ -695,14 +687,6 @@
 
 storeAssociation(doubleExtendedDoAnythingBytecode + chr(7<<5) + chr(0))
 
-def interpret_bc(bcodes, literals, receiver=None):
-if not receiver:
-receiver = space.w_nil
-bcode = "".join([chr(x) for x in bcodes])
-w_frame, s_frame = new_frame(bcode, receiver=receiver)
-s_frame.w_method().setliterals(literals)
-return interp.interpret_toplevel(w_frame)
-
 # tests: bytecodePrimValue & bytecodePrimValueWithArg
 def test_bc_3_plus_4():
 # value0
diff --git a/spyvm/test/test_largeinteger.py b/spyvm/test/test_largeinteger.py
--- a/spyvm/test/test_largeinteger.py
+++ b/spyvm/test/test_largeinteger.py
@@ -1,7 +1,7 @@
 import py, operator
 from spyvm import squeakimage, model, constants, error, interpreter, shadow, 
primitives
 from spyvm.test.test_primitives import MockFrame
-from .util import read_image, find_symbol_in_methoddict_of, copy_to_module, 
cleanup_module
+from .util import read_image, copy_to_module, cleanup_module
 from rpython.rlib.rarithmetic import intmask, r_uint
 
 def setup_module():
@@ -36,7 +36,7 @@
 try:
 w_selector = space.get_special_selector(selector)
 except Exception:
-w_selector = find_symbol_in_methoddict_of(selector, 
w(intmask(candidates[0])).getclass(space).shadow)
+w_selector = space.find_symbol_in_methoddict(selector, 
w(intmask(candidates[0])).getclass(space))
 
 interp.trace = trace
 for i, v in enumerate(candidates):
diff --git a/spyvm/test/test_primitives.py b/spyvm/test/test_primitives.py
--- a/spyvm/test/test_primitives.py
+++ b/spyvm/test/test_primitives.py
@@ -6,20 +6,17 @@
 from rpython.rlib.rarithmetic import intmask
 from rpython.rtyper.lltypesystem import lltype, rffi
 from .util import create_space, copy_to_module, cleanup_module, TestInterpreter
-from .test_interpreter import _new_frame
 
 def setup_module():
 space = create_space(bootstrap = True)
 wrap = space.w
 bootstrap_class = space.bootstrap_class
+new_frame = space.make_frame
 copy_to_module(locals(), __name__)
 
 def teardown_module():
 cleanup_module(__name__)
 
-def new_frame(bytes):
-return _new_frame(space, bytes, space.w_nil)
-
 class MockFrame(model.W_PointersObject):
 def __init__(self, space, stack):
 size = 6 + len(stack) + 6
diff --git a/spyvm/test/test_wrapper.py b/spyvm/test/test_wrapper.py
--- a/spyvm/test/test_wrapper.py
+++ b/spyvm/test/test_wrapper.py
@@ -2,18 +2,15 @@
 from spyvm import wrapper, model, interpreter, objspace
 from spyvm.error import WrapperException, FatalError
 from .util import create_space, copy_to_module, cleanup_module
-from spyvm.test.test_interpreter import _new_frame
 
 def setup_module():
 space = create_space(bootstrap = True)
+new_frame = lambda: space.make_frame("")[1]
 copy_to_module(locals(), __name__)
 
 def teardown_module():
 cleanup_module(__name__)
 
-def new_frame():
-return _new_frame(space, "")[0].as_context_get_shadow(space)
-
 def test_simpleread():
   

[pypy-commit] lang-smalltalk storage-context-state-v2: Delaying SenderChainManipulation as much as possible.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state-v2
Changeset: r952:288e40aaf989
Date: 2014-07-18 15:29 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/288e40aaf989/

Log:Delaying SenderChainManipulation as much as possible. Added a
'state' field to Context objects, can be Inactive, Active or Dirty.
Setting the sender of an Active context makes it Dirty. When a Dirty
context is left, SenderChainManipulation will be raised, forcing all
remaining contexts from the stack to the heap.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -1,6 +1,6 @@
 import os
 
-from spyvm.shadow import MethodContextShadow
+from spyvm.shadow import MethodContextShadow, ActiveContext, InactiveContext, 
DirtyContext
 from spyvm import model, constants, wrapper, objspace, interpreter_bytecodes
 
 from rpython.rlib import jit, rstackovf, unroll
@@ -151,8 +151,10 @@
 if self.is_tracing():
 self.stack_depth += 1
 if s_frame._s_sender is None and s_sender is not None:
-s_frame.store_s_sender(s_sender, raise_error=False)
+s_frame.store_s_sender(s_sender)
 # Now (continue to) execute the context bytecodes
+assert s_frame.state is InactiveContext
+s_frame.state = ActiveContext
 self.loop_bytecodes(s_frame, may_context_switch)
 except rstackovf.StackOverflow:
 rstackovf.check_stack_overflow()
@@ -160,7 +162,11 @@
 finally:
 if self.is_tracing():
 self.stack_depth -= 1
-
+dirty_frame = s_frame.state is DirtyContext
+s_frame.state = InactiveContext
+if dirty_frame:
+raise SenderChainManipulation(s_frame)
+
 def step(self, context):
 bytecode = context.fetch_next_bytecode()
 for entry in UNROLLING_BYTECODE_RANGES:
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -633,18 +633,29 @@
 def size(self):
 return self._w_self_size
 
+class ContextState(object):
+def __init__(self, name):
+self.name = name
+def __str__(self):
+return self.name
+def __repr__(self):
+return self.name
+InactiveContext = ContextState("InactiveContext")
+ActiveContext = ContextState("ActiveContext")
+DirtyContext = ContextState("DirtyContext")
+
 class ContextPartShadow(AbstractRedirectingShadow):
 
 __metaclass__ = extendabletype
 _attrs_ = ['_s_sender',
 '_pc', '_temps_and_stack',
-'_stack_ptr', 'instances_w']
+'_stack_ptr', 'instances_w', 'state']
 repr_classname = "ContextPartShadow"
 
 _virtualizable_ = [
 '_s_sender',
 "_pc", "_temps_and_stack[*]", "_stack_ptr",
-"_w_self", "_w_self_size"
+"_w_self", "_w_self_size", 'state'
 ]
 
 # __
@@ -654,13 +665,7 @@
 self._s_sender = None
 AbstractRedirectingShadow.__init__(self, space, w_self, size)
 self.instances_w = {}
-
-def copy_field_from(self, n0, other_shadow):
-from spyvm.interpreter import SenderChainManipulation
-try:
-AbstractRedirectingShadow.copy_field_from(self, n0, other_shadow)
-except SenderChainManipulation, e:
-assert e.s_new_context == self
+self.state = InactiveContext
 
 def copy_from(self, other_shadow):
 # Some fields have to be initialized before the rest, to ensure 
correct initialization.
@@ -702,7 +707,7 @@
 if n0 == constants.CTXPART_SENDER_INDEX:
 assert isinstance(w_value, model.W_PointersObject)
 if w_value.is_nil(self.space):
-self.store_s_sender(None, raise_error=False)
+self.store_s_sender(None)
 else:
 self.store_s_sender(w_value.as_context_get_shadow(self.space))
 return
@@ -722,12 +727,12 @@
 
 # === Sender ===
 
-def store_s_sender(self, s_sender, raise_error=True):
+def store_s_sender(self, s_sender):
 if s_sender is not self._s_sender:
 self._s_sender = s_sender
-if raise_error:
-from spyvm.interpreter import SenderChainManipulation
-raise SenderChainManipulation(self)
+# If new sender is None, we are just being marked as returned.
+if s_sender is not None and self.state is ActiveContext:
+self.state = DirtyContext
 
 def w_sender(self):
 sender = self.s_sender()
@@ -819,7 +824,7 @@
 
 def mark_returned(self):
 self.store_pc(-1)
-self.store_s_sender(None, raise_error=False)
+self.store_s_sender(None)
 
 def is_returned(self):
 return self.pc() == -1 and self.w_sender().is_nil(self.space)
__

[pypy-commit] lang-smalltalk storage-context-state-v2: Added some Squeak image tests.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state-v2
Changeset: r956:f500ff8dea45
Date: 2014-07-25 16:33 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/f500ff8dea45/

Log:Added some Squeak image tests.

diff --git a/spyvm/test/test_interpreter.py b/spyvm/test/test_interpreter.py
--- a/spyvm/test/test_interpreter.py
+++ b/spyvm/test/test_interpreter.py
@@ -979,7 +979,7 @@
 test)
 
 def test_frame_dirty_if_active():
-bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00])) + 
returnReceiverBytecode
+bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00]))
 w_frame, s_frame = new_frame(bytes)
 s_frame.store_w_receiver(w_frame)
 s_frame.push(w_frame)
@@ -988,7 +988,7 @@
 assert s_frame.state is shadow.DirtyContext
 
 def test_frame_not_dirty_if_inactive():
-bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00])) + 
returnReceiverBytecode
+bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00]))
 w_frame, s_frame = new_frame(bytes)
 w_other_frame, s_other_frame = new_frame("")
 s_frame.store_w_receiver(w_other_frame)
@@ -998,12 +998,14 @@
 assert s_frame.state is shadow.ActiveContext
 assert s_other_frame.state is shadow.InactiveContext
 
-def test_raise_SenderManipulation_on_dirty_frame():
-w_frame, s_frame = new_frame(returnReceiverBytecode)
-s_frame.state = shadow.DirtyContext
-def run_frame():
-#import pdb; pdb.set_trace()
-interp._loop = True
+def test_raise_NonVirtualReturn_on_dirty_frame():
+bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00])) + 
returnTopFromMethodBytecode
+w_frame, s_frame = new_frame(bytes)
+s_frame.store_w_receiver(w_frame)
+s_frame.push(w_frame)
+
+interp._loop = True
+def do_test():
 interp.stack_frame(s_frame, None)
-py.test.raises(interpreter.SenderChainManipulation, run_frame)
+py.test.raises(interpreter.NonVirtualReturn, do_test)
 
\ No newline at end of file
diff --git a/spyvm/test/test_zin_squeak_4_5_image.py 
b/spyvm/test/test_zin_squeak_4_5_image.py
--- a/spyvm/test/test_zin_squeak_4_5_image.py
+++ b/spyvm/test/test_zin_squeak_4_5_image.py
@@ -1,6 +1,8 @@
 from spyvm import squeakimage, model, constants, interpreter, shadow, objspace
 from .util import read_image, find_symbol_in_methoddict_of, copy_to_module, 
cleanup_module
 
+import operator
+
 def setup_module():
 space, interp, image, reader = read_image('Squeak4.5-12568.image')
 w = space.w
@@ -25,21 +27,13 @@
 w_method.setliterals(literals)
 return w_method
 
-def test_ensure():
-#ensure
-#[^'b1'] ensure: [^'b2']
-import operator
-bytes = reduce(operator.add, map(chr, [0x8F, 0, 0, 2, 0x21, 0x7c,
-   0x8F, 0, 0, 2, 0x22, 0x7c,
-   0xe0, 0x87, 0x78]))
-
-s_class = space.w_BlockClosure.as_class_get_shadow(space)
-ensure_ = find_symbol_in_methoddict_of('ensure:', s_class)
-assert ensure_ is not None, 'Using image without #ensure:-method.'
-
-w_method = create_method(bytes, [ensure_, w('b1'), w('b2'),
-w('ensure'), space.w_BlockClosure])
-
+def find_symbol(w_class, symbolname):
+s_class = w_class.as_class_get_shadow(space)
+symbol = find_symbol_in_methoddict_of(symbolname, s_class)
+assert symbol is not None, 'Using image without %s method.' % symbolname
+return symbol
+
+def execute_frame(w_method):
 # create a frame for our newly crafted method with a valid sender (to 
avoid raising returnFromTop to early)
 s_initial_frame = create_method(chr(0x7c)).create_frame(space, w(0), [])
 s_frame = w_method.create_frame(space, w(0))
@@ -48,33 +42,141 @@
 try:
 interp.loop(s_frame.w_self())
 except interpreter.ReturnFromTopLevel, e:
-assert e.object.as_string() == 'b2'
-except interpreter.StackOverflow, e:
-assert False
+return e.object
+
+def test_ensure():
+#ensure
+#[^'b1'] ensure: [^'b2']
+
+ensure_ = find_symbol(space.w_BlockClosure, "ensure:")
+bytes = reduce(operator.add, map(chr, [0x8F, 0, 0, 2, 0x21, 0x7c,
+   0x8F, 0, 0, 2, 0x22, 0x7c,
+   0xe0, 0x87, 0x78]))
+
+w_method = create_method(bytes, [ensure_, w('b1'), w('b2'),
+w('ensure'), space.w_BlockClosure])
+result = execute_frame(w_method)
+assert result.as_string() == 'b2'
 
 def test_ensure_save_original_nlr():
 #ensure
 #[^'b1'] ensure: ['b2']
-import operator
+
+ensure_ = find_symbol(space.w_BlockClosure, "ensure:")
 bytes = reduce(operator.add, map(chr, [0x8F, 0, 0, 2, 0x21, 0x7c,
0x8F, 0, 0, 2, 0x22, 0x7d,
0xe0, 0x87, 0x78]))
 
-s_class = space.w_BlockClosure.as_cla

[pypy-commit] lang-smalltalk storage-context-state-v2: Fixed tests, added tests.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state-v2
Changeset: r953:6a476300d0c3
Date: 2014-07-18 15:29 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/6a476300d0c3/

Log:Fixed tests, added tests.

diff --git a/spyvm/test/test_interpreter.py b/spyvm/test/test_interpreter.py
--- a/spyvm/test/test_interpreter.py
+++ b/spyvm/test/test_interpreter.py
@@ -978,9 +978,32 @@
 2, "value:value:"]],
 test)
 
-def test_c_stack_reset_on_sender_chain_manipulation():
-bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00]))
+def test_frame_dirty_if_active():
+bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00])) + 
returnReceiverBytecode
 w_frame, s_frame = new_frame(bytes)
 s_frame.store_w_receiver(w_frame)
 s_frame.push(w_frame)
-py.test.raises(interpreter.SenderChainManipulation, step_in_interp, 
s_frame)
+s_frame.state = shadow.ActiveContext
+step_in_interp(s_frame)
+assert s_frame.state is shadow.DirtyContext
+
+def test_frame_not_dirty_if_inactive():
+bytes = reduce(operator.add, map(chr, [0x84, 0xc0, 0x00])) + 
returnReceiverBytecode
+w_frame, s_frame = new_frame(bytes)
+w_other_frame, s_other_frame = new_frame("")
+s_frame.store_w_receiver(w_other_frame)
+s_frame.push(w_frame)
+s_frame.state = shadow.ActiveContext
+step_in_interp(s_frame)
+assert s_frame.state is shadow.ActiveContext
+assert s_other_frame.state is shadow.InactiveContext
+
+def test_raise_SenderManipulation_on_dirty_frame():
+w_frame, s_frame = new_frame(returnReceiverBytecode)
+s_frame.state = shadow.DirtyContext
+def run_frame():
+#import pdb; pdb.set_trace()
+interp._loop = True
+interp.stack_frame(s_frame, None)
+py.test.raises(interpreter.SenderChainManipulation, run_frame)
+
\ No newline at end of file
diff --git a/spyvm/test/test_zin_squeak_4_5_image.py 
b/spyvm/test/test_zin_squeak_4_5_image.py
--- a/spyvm/test/test_zin_squeak_4_5_image.py
+++ b/spyvm/test/test_zin_squeak_4_5_image.py
@@ -43,7 +43,7 @@
 # create a frame for our newly crafted method with a valid sender (to 
avoid raising returnFromTop to early)
 s_initial_frame = create_method(chr(0x7c)).create_frame(space, w(0), [])
 s_frame = w_method.create_frame(space, w(0))
-s_frame.store_s_sender(s_initial_frame, raise_error=False)
+s_frame.store_s_sender(s_initial_frame)
 
 try:
 interp.loop(s_frame.w_self())
@@ -70,7 +70,7 @@
 # create a frame for our newly crafted method with a valid sender (to 
avoid raising returnFromTop to early)
 s_initial_frame = create_method(chr(0x7c)).create_frame(space, w(0))
 s_frame = w_method.create_frame(space, w(0))
-s_frame.store_s_sender(s_initial_frame, raise_error=False)
+s_frame.store_s_sender(s_initial_frame)
 
 try:
 interp.loop(s_frame.w_self())
diff --git a/spyvm/test/util.py b/spyvm/test/util.py
--- a/spyvm/test/util.py
+++ b/spyvm/test/util.py
@@ -85,7 +85,7 @@
 if not self._loop:
 # this test is done to not loop in test, but rather step just once 
where wanted
 # Unfortunately, we have to mimick some of the original behaviour.
-s_new_frame.store_s_sender(s_sender, raise_error=False)
+s_new_frame.store_s_sender(s_sender)
 return s_new_frame
 return interpreter.Interpreter.stack_frame(self, s_new_frame, 
s_sender, may_context_switch)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage: Merged default.

2014-07-27 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage
Changeset: r962:44419a6b6d08
Date: 2014-07-27 12:29 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/44419a6b6d08/

Log:Merged default.

diff --git a/README.md b/README.md
new file mode 100644
--- /dev/null
+++ b/README.md
@@ -0,0 +1,69 @@
+Spy
+=
+
+A Squeak VM written in RPython, called "SPy VM".
+
+Setup
+
+### Required Projects
+You need three repositories: 
+* This one
+* pypy/pypy
+* pypy/rsdl
+
+### Required packages
+You need the following packages on your OS. Install with your favorite package
+manager:
+* pypy (For faster translation of the SPY VM)
+* libsdl-dev
+
+### Adjusting the PYTHONPATH
+In order to allow the RPython toolchain to find the rsdl module you have to add
+the rsdl folder to the PYTHONPATH. Note that you have to add the rsdl subfolder
+of the rsdl repository to the PYTHONPATH.
+
+```
+export PYTHONPATH=${PYTHONPATH}:[path to rsdl repository]/rsdl
+```
+
+### Setting the SDL Driver
+For testing the basic functionality of the VM it is currently best to disable
+the UI. You can do so by setting the SDL_VIDEODRIVER environment variable to
+dummy.
+```
+export SDL_VIDEODRIVER=dummy
+```
+
+### Building
+To build the VM enter the following:
+
+```
+[path to pypy repository]/rpython/bin/rpython [path to lang-smalltalk
+repository]/targetimageloadingsmalltalk.py
+```
+
+To build the VM with enabled just-in-time compiler:
+```
+[path to pypy repository]/rpython/bin/rpython -O jit [path to lang-smalltalk
+repository]/targetimageloadingsmalltalk.py
+```
+
+### Starting an image
+The build process will produce an executable e.g. called
+targetimageloadingsmalltalk-c. Start it with the following:
+```
+./targetimageloadingsmalltalk-c images/Squeak4.5-*.image
+```
+
+Setup for stm-enabled SPY
+---
+There are two branches integrating the RPython STM into SPY: stm-c4,
+storage-stm-c4. You have to change two things of the setup to build those
+branches.
+
+1. Change your local pypy repository to the stm-c4 branch.
+2. Build using the following command:
+```
+[path to pypy repository]/rpython/bin/rpython --gc=stmgc [path to 
lang-smalltalk
+repository]/targetimageloadingsmalltalk.py
+```
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-context-state-v3: Calling stack_frame from loop()

2014-07-28 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state-v3
Changeset: r993:da722243ee58
Date: 2014-07-26 23:38 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/da722243ee58/

Log:Calling stack_frame from loop()

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -98,7 +98,7 @@
 while True:
 s_sender = s_new_context.s_sender()
 try:
-self.loop_bytecodes(s_new_context)
+self.stack_frame(s_new_context, None)
 raise Exception("loop_bytecodes left without raising...")
 except ContextSwitchException, e:
 if self.is_tracing() or self.trace_important:
@@ -114,6 +114,23 @@
 s_new_context = s_sender
 s_new_context.push(nlr.value)
 
+# This is a wrapper around loop_bytecodes that cleanly enters/leaves the 
frame
+# and handles the stack overflow protection mechanism.
+def stack_frame(self, s_frame, s_sender, may_context_switch=True):
+try:
+if self.is_tracing():
+self.stack_depth += 1
+if s_frame._s_sender is None and s_sender is not None:
+s_frame.store_s_sender(s_sender, raise_error=False)
+# Now (continue to) execute the context bytecodes
+self.loop_bytecodes(s_frame, may_context_switch)
+except rstackovf.StackOverflow:
+rstackovf.check_stack_overflow()
+raise StackOverflow(s_frame)
+finally:
+if self.is_tracing():
+self.stack_depth -= 1
+
 def loop_bytecodes(self, s_context, may_context_switch=True):
 old_pc = 0
 if not jit.we_are_jitted() and may_context_switch:
@@ -145,23 +162,6 @@
 s_context._activate_unwind_context(self)
 raise nlr
 
-# This is a wrapper around loop_bytecodes that cleanly enters/leaves the 
frame
-# and handles the stack overflow protection mechanism.
-def stack_frame(self, s_frame, s_sender, may_context_switch=True):
-try:
-if self.is_tracing():
-self.stack_depth += 1
-if s_frame._s_sender is None and s_sender is not None:
-s_frame.store_s_sender(s_sender, raise_error=False)
-# Now (continue to) execute the context bytecodes
-self.loop_bytecodes(s_frame, may_context_switch)
-except rstackovf.StackOverflow:
-rstackovf.check_stack_overflow()
-raise StackOverflow(s_frame)
-finally:
-if self.is_tracing():
-self.stack_depth -= 1
-
 def step(self, context):
 bytecode = context.fetch_next_bytecode()
 for entry in UNROLLING_BYTECODE_RANGES:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-vref: Added vref refactoring: keeping a virtual back-reference to the sender as long as possible.

2014-07-28 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-vref
Changeset: r992:3fa384225c32
Date: 2014-07-10 12:56 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/3fa384225c32/

Log:Added vref refactoring: keeping a virtual back-reference to the
sender as long as possible. TODO: Explore why this breaks
performance; it should actually improve it.

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -67,6 +67,9 @@
 s_new_context = w_active_context.as_context_get_shadow(self.space)
 while True:
 assert self.current_stack_depth == 0
+# Need to save s_sender, loop_bytecodes will nil this on return
+# Virtual references are not allowed here, and neither are "fresh" 
contexts (except for the toplevel one).
+assert s_new_context.virtual_sender is jit.vref_None
 s_sender = s_new_context.s_sender()
 try:
 self.loop_bytecodes(s_new_context)
@@ -119,19 +122,27 @@
 # This is a wrapper around loop_bytecodes that cleanly enters/leaves the 
frame
 # and handles the stack overflow protection mechanism.
 def stack_frame(self, s_frame, s_sender, may_context_switch=True):
+assert s_frame.virtual_sender is jit.vref_None
 try:
-if s_frame._s_sender is None and s_sender is not None:
-s_frame.store_s_sender(s_sender, raise_error=False)
-
+# Enter the context - store a virtual reference back to the sender
+# Non-fresh contexts can happen, e.g. when activating a stored 
BlockContext.
+# The same frame object must not pass through here recursively!
+if s_frame.is_fresh() and s_sender is not None:
+s_frame.virtual_sender = jit.virtual_ref(s_sender)
+
 self.current_stack_depth += 1
 if self.max_stack_depth > 0:
 if self.current_stack_depth >= self.max_stack_depth:
 raise StackOverflow(s_frame)
-
+
 # Now (continue to) execute the context bytecodes
 self.loop_bytecodes(s_frame, may_context_switch)
 finally:
 self.current_stack_depth -= 1
+# Cleanly leave the context. This will finish the virtual 
sender-reference, if
+# it is still there, which can happen in case of ProcessSwitch or 
StackOverflow;
+# in case of a Return, this will already be handled while 
unwinding the stack.
+s_frame.finish_virtual_sender(s_sender)
 
 def step(self, context):
 bytecode = context.fetch_next_bytecode()
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -607,13 +607,13 @@
 class ContextPartShadow(AbstractRedirectingShadow):
 
 __metaclass__ = extendabletype
-_attrs_ = ['_s_sender',
+_attrs_ = ['direct_sender', 'virtual_sender',
 '_pc', '_temps_and_stack',
 '_stack_ptr', 'instances_w']
 repr_classname = "ContextPartShadow"
 
 _virtualizable_ = [
-'_s_sender',
+'direct_sender', 'virtual_sender',
 "_pc", "_temps_and_stack[*]", "_stack_ptr",
 "_w_self", "_w_self_size"
 ]
@@ -622,7 +622,8 @@
 # Initialization
 
 def __init__(self, space, w_self):
-self._s_sender = None
+self.direct_sender = None
+self.virtual_sender = jit.vref_None
 AbstractRedirectingShadow.__init__(self, space, w_self)
 self.instances_w = {}
 
@@ -691,9 +692,25 @@
 raise error.WrapperException("Index in context out of bounds")
 
 # === Sender ===
+# There are two fields for the sender (virtual and direct). Only one of 
them is can be set at a time.
+# As long as the frame object is virtualized, using the virtual reference 
should increase performance.
+# As soon as a frame object is forced to the heap, the direct reference 
must be used.
+
+def is_fresh(self):
+return self.direct_sender is None and self.virtual_sender is 
jit.vref_None
+
+def finish_virtual_sender(self, s_sender):
+if self.virtual_sender is not jit.vref_None:
+if self.pc() != -1:
+# stack is unrolling, but this frame was not
+# marked_returned: it is an escaped frame
+sender = self.virtual_sender()
+self.direct_sender = sender
+jit.virtual_ref_finish(self.virtual_sender, s_sender)
+self.virtual_sender = jit.vref_None
 
 def store_s_sender(self, s_sender, raise_error=True):
-self._s_sender = s_sender
+self.direct_sender = s_sender
 if raise_error:
 raise error.SenderChainManipulation(self)
 
@@ -704,7 +721,11 @@
 return sender.w_self()
 
 def s_sender(self):
-return self._s_sender
+if self.direct_sender:
+return self.direct_sender
+else:
+  

[pypy-commit] lang-smalltalk storage-allocRemoval: Merged storage branch.

2014-07-28 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-allocRemoval
Changeset: r989:2e3b082dd9a1
Date: 2014-04-03 10:55 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/2e3b082dd9a1/

Log:Merged storage branch.

diff too long, truncating to 2000 out of 4957 lines

diff --git a/images/Squeak4.5-noBitBlt.changes 
b/images/Squeak4.5-noBitBlt.changes
--- a/images/Squeak4.5-noBitBlt.changes
+++ b/images/Squeak4.5-noBitBlt.changes
@@ -12198,4 +12198,14 @@
].
 
"self footer."
-   ^ self! !

SMarkRunner execute: CPBAStarBenchmark new with: 3
!

SMarkRunner execute: CPBAStarBenchmark new with: 3
!

SMarkRunner execute: CPBAStarBenchmark new with: 3
!

Object subclass: #Benchmarks
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Cross-Platform-Benchmarks'!
!Benchmarks class methodsFor: 'no messages' stamp: 'ag 3/8/2014 23:21'!
runAll: iterations

^ String streamContents: [ :str |
self allBenchmarks do: [ :bench |
str nextPutAll:
(SMarkRunner execute: bench new with: 
iterations) ] ]! !
!Benchmarks class methodsFor: 'as yet unclassified' stamp: 'ag 3/8/2014 23:21' 
prior: 49281266!
runAll: iterations

^ String streamContents: [ :str |
self allBenchmarks do: [ :bench |
str nextPutAll:
(SMarkRunner execute: bench new with: 
iterations) asString ] ]! !
!Benchmarks class methodsFor: 'as yet unclassified' stamp: 'ag 3/8/2014 23:22'!
allBenchmarks

^ {
CPBAStarBenchmark.
}! !
!Benchmarks class methodsFor: 'as yet unclassified' stamp: 'ag 3/8/2014 23:26' 
prior: 49281795!
allBenchmarks

^ {
CPBAStarBenchmark.
CPBBinaryTreeBenchmark.
CPBBlowfishSuite.
CPBChameneosBenchmark.
CPBDeltaBlueBenchmark.
CPBMandelbrotBenchmarkSuite.
CPBNBodyBenchmark.
CPBPolymorphyBenchmark.
CPBRichardsBenchmark.
CPBSplayTreeBenchmark.
}! !
!Benchmarks class methodsFor: 'as yet unclassified' stamp: 'ag 3/8/2014 23:26' 
prior: 49281938!
allBenchmarks

^ {
CPBAStarBenchmark.
CPBBinaryTreeBenchmark.
CPBBlowfishSuite.
CPBChameneosBenchmark.
CPBDeltaBlueBenchmark.
CPBMandelbrotBenchmarkSuite.
CPBNBodyBenchmark.
CPBPolymorphyBenchmark.
CPBRichardsBenchmark.
CPBSplayTreeBenchmark.
}! !
!Benchmarks class methodsFor: 'as yet unclassified' stamp: 'ag 3/8/2014 23:27'!
run: benchmarks iterations: iterations

^ String streamContents: [ :str |
benchmarks do: [ :bench |
str cr; nextPutAll:
(SMarkRunner execute: bench new with: 
iterations) asString ] ]! !
!Benchmarks class methodsFor: 'as yet unclassified' stamp: 'ag 3/8/2014 23:27' 
prior: 49281534!
runAll: iterations

^ self run: self allBenchmarks iterations: iterations! !
!Benchmarks class methodsFor: 'as yet unclassified' stamp: 'ag 3/8/2014 23:27'!
runAll

^ self runAll: 5! !
!Benchmarks class methodsFor: 'as yet unclassified' stamp: 'ag 3/8/2014 23:29'!
list

^ String streamContents: [ :str |
self allBenchmarks do: [ :bench | str cr; nextPutAll: bench 
name asString ] ]! !

'CPBBinaryTreeBenchmark' indexOf: 'Binary'!

'CPBBinaryTreeBenchmark' includesSubString: 'Binary'!
!Benchmarks class methodsFor: 'as yet unclassified' stamp: 'ag 3/8/2014 23:30' 
prior: 49283190!
list

^ String streamContents: [ :str |
self allBenchmarkNames do: [ :benchName | str cr; nextPutAll: 
benchName ] ]! !
!Benchmarks class methodsFor: 'as yet unclassified' stamp: 'ag 3/8/2014 23:31'!
allBenchmarkNames

^ self allBenchmarks collect: [ :bench | bench name asString ]! !
!Benchmarks class methodsFor: 'as yet unclassified' stamp: 'ag 3/8/2014 23:32'!
selectBenchmarks: substring

^ self allBenchmarks select: [ :bench | bench name includesSubString: 
substring ]! !
!Benchmarks class methodsFor: 'as yet unclassified' stamp: 'ag 3/8/2014 23:35'!
runMatching: substring iterations: iterations

| benchmarks |
benchmarks := self selectBenchmarks: substring.
benchmarks ifEmpty: [ 
^ String streamContents: [ :str |
str
nextPutAll: 'No benchmarks matched "';
nextPutAll: substring;
nextPutAll: '"';
cr;
nextPutAll: 'Available benchmarks:'.
self allBenchmarkNames do: [ :name | str cr; 
nextPutAll: name ] ] ].
! !
!Benchmarks class methodsFor: 'as yet unclassified' stamp: 'ag 3/8/2014 23:35' 
prior: 4928407

[pypy-commit] lang-smalltalk storage-context-state-v3:

2014-07-28 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state-v3
Changeset: r995:a334c37ae996
Date: 2014-07-27 12:20 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/a334c37ae996/

Log:

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-interpreter-refactoring:

2014-07-28 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-interpreter-refactoring
Changeset: r998:63c0ad701980
Date: 2014-07-27 12:21 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/63c0ad701980/

Log:

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk strategies:

2014-07-28 Thread anton_gulenko
Author: Anton Gulenko 
Branch: strategies
Changeset: r1001:f23c08f44b8b
Date: 2014-07-28 09:47 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/f23c08f44b8b/

Log:

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-ignoringStackOverflow:

2014-07-28 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-ignoringStackOverflow
Changeset: r999:ae4fc5aa360d
Date: 2014-07-28 09:42 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/ae4fc5aa360d/

Log:

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk storage-context-state-v2:

2014-07-28 Thread anton_gulenko
Author: Anton Gulenko 
Branch: storage-context-state-v2
Changeset: r1002:e4a9aefa19ac
Date: 2014-07-28 09:47 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/e4a9aefa19ac/

Log:

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


  1   2   3   4   >