[pypy-svn] r50430 - in pypy/branch/simpler-pyassem/pypy/interpreter/astcompiler: . test
arigo at codespeak.net
arigo at codespeak.net
Mon Jan 7 18:41:14 CET 2008
Author: arigo
Date: Mon Jan 7 18:41:14 2008
New Revision: 50430
Modified:
pypy/branch/simpler-pyassem/pypy/interpreter/astcompiler/pyassem.py
pypy/branch/simpler-pyassem/pypy/interpreter/astcompiler/test/test_compiler.py
Log:
Bug fix. Missing: __doc__ handling, and co_lnotab.
Modified: pypy/branch/simpler-pyassem/pypy/interpreter/astcompiler/pyassem.py
==============================================================================
--- pypy/branch/simpler-pyassem/pypy/interpreter/astcompiler/pyassem.py (original)
+++ pypy/branch/simpler-pyassem/pypy/interpreter/astcompiler/pyassem.py Mon Jan 7 18:41:14 2008
@@ -28,9 +28,8 @@
if newlocals:
self.flags |= CO_NEWLOCALS
- # XXX we need to build app-level dict here, bleh
+ # we need to build an app-level dict here
self.w_consts = space.newdict()
- #self.const_list = []
self.names = []
# Free variables found by the symbol table scan, including
# variables used only in nested scopes, are included here.
@@ -207,6 +206,16 @@
# ____________________________________________________________
+ def dump(self):
+ try:
+ self.fixLabelTargets()
+ except:
+ pass
+ if not hasattr(self, 'stacksize'):
+ self.stacksize = 99 # temporarily
+ co = self.newCodeObject()
+ co.dump()
+
def getCode(self):
self.fixLabelTargets()
self.computeStackDepth()
@@ -233,6 +242,7 @@
self._stackdepths[0] = 0
just_loaded_const = None
consts_w = self.getConsts()
+ finally_targets = {}
largestsize = 0
i = 0
@@ -268,6 +278,8 @@
target_i = i + oparg
effect = DEPTH_OP_EFFECT_ALONG_JUMP[opcode]
self._setdepth(target_i, curstackdepth + effect)
+ if opcode == pythonopcode.opmap['SETUP_FINALLY']:
+ finally_targets[target_i] = None
try:
tracker = DEPTH_OP_TRACKER[opcode]
@@ -284,7 +296,10 @@
effect = - nfreevars - oparg
else:
effect = tracker(oparg)
- self._setdepth(i, curstackdepth + effect)
+ curstackdepth += effect
+ if i in finally_targets:
+ curstackdepth += 2 # see pyopcode.FinallyBlock.cleanup()
+ self._setdepth(i, curstackdepth)
if opcode == pythonopcode.opmap['LOAD_CONST']:
just_loaded_const = consts_w[oparg]
Modified: pypy/branch/simpler-pyassem/pypy/interpreter/astcompiler/test/test_compiler.py
==============================================================================
--- pypy/branch/simpler-pyassem/pypy/interpreter/astcompiler/test/test_compiler.py (original)
+++ pypy/branch/simpler-pyassem/pypy/interpreter/astcompiler/test/test_compiler.py Mon Jan 7 18:41:14 2008
@@ -373,12 +373,25 @@
decl = str(decl) + "\n"
yield self.st, decl + "x = make_adder(40)(2)", 'x', 42
+ def test_try_except_finally(self):
+ yield self.simple_test, """
+ try:
+ x = 5
+ try:
+ if x > 2:
+ raise ValueError
+ finally:
+ x += 1
+ except ValueError:
+ x *= 7
+ """, 'x', 42
+
def test_pprint(self):
# a larger example that showed a bug with jumps
# over more than 256 bytes
decl = py.code.Source("""
def _safe_repr(object, context, maxlevels, level):
- typ = _type(object)
+ typ = type(object)
if typ is str:
if 'locale' not in _sys.modules:
return repr(object), True, False
@@ -402,7 +415,7 @@
if issubclass(typ, dict) and r is dict.__repr__:
if not object:
return "{}", True, False
- objid = _id(object)
+ objid = id(object)
if maxlevels and level > maxlevels:
return "{...}", False, objid in context
if objid in context:
@@ -422,7 +435,7 @@
if krecur or vrecur:
recursive = True
del context[objid]
- return "{%s}" % _commajoin(components), readable, recursive
+ return "{%s}" % ', '.join(components), readable, recursive
if (issubclass(typ, list) and r is list.__repr__) or \
(issubclass(typ, tuple) and r is tuple.__repr__):
@@ -436,7 +449,7 @@
if not object:
return "()", True, False
format = "(%s)"
- objid = _id(object)
+ objid = id(object)
if maxlevels and level > maxlevels:
return format % "...", False, objid in context
if objid in context:
@@ -455,10 +468,13 @@
if orecur:
recursive = True
del context[objid]
- return format % _commajoin(components), readable, recursive
+ return format % ', '.join(components), readable, recursive
rep = repr(object)
return rep, (rep and not rep.startswith('<')), False
""")
decl = str(decl) + '\n'
- yield self.st, decl + 'x=_safe_repr([5], {}, 3, 0)', 'x', '[5]'
+ g = {}
+ exec decl in g
+ expected = g['_safe_repr']([5], {}, 3, 0)
+ yield self.st, decl + 'x=_safe_repr([5], {}, 3, 0)', 'x', expected
More information about the Pypy-commit
mailing list