[pypy-svn] r17542 - in pypy/dist/pypy/interpreter: astcompiler pyparser
pedronis at codespeak.net
pedronis at codespeak.net
Tue Sep 13 20:13:27 CEST 2005
Author: pedronis
Date: Tue Sep 13 20:13:26 2005
New Revision: 17542
Modified:
pypy/dist/pypy/interpreter/astcompiler/misc.py
pypy/dist/pypy/interpreter/astcompiler/symbols.py
pypy/dist/pypy/interpreter/pyparser/astbuilder.py
Log:
tentative removing of negative slice stops
Modified: pypy/dist/pypy/interpreter/astcompiler/misc.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/misc.py (original)
+++ pypy/dist/pypy/interpreter/astcompiler/misc.py Tue Sep 13 20:13:26 2005
@@ -77,7 +77,11 @@
tlen = len(klass) + len(name)
if tlen > MANGLE_LEN:
- klass = klass[:MANGLE_LEN-tlen]
+ end = len(klass) + MANGLE_LEN-tlen
+ if end < 0:
+ klass = '' # annotator hint
+ else:
+ klass = klass[:end]
return "_%s%s" % (klass, name)
Modified: pypy/dist/pypy/interpreter/astcompiler/symbols.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/symbols.py (original)
+++ pypy/dist/pypy/interpreter/astcompiler/symbols.py Tue Sep 13 20:13:26 2005
@@ -380,7 +380,7 @@
scope = self.cur_scope()
for name, asname in node.names:
i = name.find(".")
- if i > -1:
+ if i >= 0:
name = name[:i]
scope.add_def(asname or name)
Modified: pypy/dist/pypy/interpreter/pyparser/astbuilder.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/astbuilder.py (original)
+++ pypy/dist/pypy/interpreter/pyparser/astbuilder.py Tue Sep 13 20:13:26 2005
@@ -515,6 +515,13 @@
else:
raise ValueError, "unexpected tokens (%d): %s" % (nb, [str(i) for i in atoms])
+def slicecut(lst, first, endskip): # endskip is negative
+ last = len(lst)+endskip
+ if last > first:
+ return lst[first:last]
+ else:
+ return []
+
def build_power(builder, nb):
"""power: atom trailer* ['**' factor]"""
@@ -524,7 +531,7 @@
else:
token = atoms[-2]
if isinstance(token, TokenObject) and token.name == tok.DOUBLESTAR:
- obj = parse_attraccess(atoms[:-2])
+ obj = parse_attraccess(slicecut(atoms, 0, -2))
builder.push(ast.Power([obj, atoms[-1]]))
else:
obj = parse_attraccess(atoms)
@@ -797,7 +804,7 @@
"""lambdef: 'lambda' [varargslist] ':' test"""
atoms = get_atoms(builder, nb)
code = atoms[-1]
- names, defaults, flags = parse_arglist(atoms[1:-2])
+ names, defaults, flags = parse_arglist(slicecut(atoms, 1, -2))
builder.push(ast.Lambda(names, defaults, flags, code))
@@ -949,7 +956,7 @@
funcname = atoms[1]
arglist = []
index = 3
- arglist = atoms[3:-3]
+ arglist = slicecut(atoms, 3, -3)
names, default, flags = parse_arglist(arglist)
funcname_token = atoms[1]
assert isinstance(funcname_token, TokenObject)
@@ -998,7 +1005,7 @@
else:
# several statements
stmts = []
- nodes = atoms[2:-1]
+ nodes = slicecut(atoms, 2,-1)
for node in nodes:
if isinstance(node, ast.Stmt):
stmts.extend(node.nodes)
More information about the Pypy-commit
mailing list