[Python-checkins] r51571 - in python/branches/p3yk-noslice: Lib/compiler/pyassem.py Lib/compiler/pycodegen.py Lib/compiler/transformer.py Lib/test/test_compiler.py TODO
thomas.wouters
python-checkins at python.org
Thu Aug 24 22:59:12 CEST 2006
Author: thomas.wouters
Date: Thu Aug 24 22:59:09 2006
New Revision: 51571
Modified:
python/branches/p3yk-noslice/Lib/compiler/pyassem.py
python/branches/p3yk-noslice/Lib/compiler/pycodegen.py
python/branches/p3yk-noslice/Lib/compiler/transformer.py
python/branches/p3yk-noslice/Lib/test/test_compiler.py
python/branches/p3yk-noslice/TODO
Log:
Rip out the compiler-package's *SLICE opcode generation. It could probably
do with some more cleanup, but this at least works.
Modified: python/branches/p3yk-noslice/Lib/compiler/pyassem.py
==============================================================================
--- python/branches/p3yk-noslice/Lib/compiler/pyassem.py (original)
+++ python/branches/p3yk-noslice/Lib/compiler/pyassem.py Thu Aug 24 22:59:09 2006
@@ -745,17 +745,6 @@
'POP_TOP': -1,
'DUP_TOP': 1,
'LIST_APPEND': -2,
- 'SLICE+1': -1,
- 'SLICE+2': -1,
- 'SLICE+3': -2,
- 'STORE_SLICE+0': -1,
- 'STORE_SLICE+1': -2,
- 'STORE_SLICE+2': -2,
- 'STORE_SLICE+3': -3,
- 'DELETE_SLICE+0': -1,
- 'DELETE_SLICE+1': -2,
- 'DELETE_SLICE+2': -2,
- 'DELETE_SLICE+3': -3,
'STORE_SUBSCR': -3,
'DELETE_SUBSCR': -2,
# PRINT_EXPR?
Modified: python/branches/p3yk-noslice/Lib/compiler/pycodegen.py
==============================================================================
--- python/branches/p3yk-noslice/Lib/compiler/pycodegen.py (original)
+++ python/branches/p3yk-noslice/Lib/compiler/pycodegen.py Thu Aug 24 22:59:09 2006
@@ -1019,23 +1019,6 @@
self.emit('ROT_TWO')
self.emit('STORE_ATTR', self.mangle(node.attrname))
- def visitAugSlice(self, node, mode):
- if mode == "load":
- self.visitSlice(node, 1)
- elif mode == "store":
- slice = 0
- if node.lower:
- slice = slice | 1
- if node.upper:
- slice = slice | 2
- if slice == 0:
- self.emit('ROT_TWO')
- elif slice == 3:
- self.emit('ROT_FOUR')
- else:
- self.emit('ROT_THREE')
- self.emit('STORE_SLICE+%d' % slice)
-
def visitAugSubscript(self, node, mode):
if mode == "load":
self.visitSubscript(node, 1)
@@ -1108,34 +1091,7 @@
self.visit(node.value)
self.emit('YIELD_VALUE')
- # slice and subscript stuff
-
- def visitSlice(self, node, aug_flag=None):
- # aug_flag is used by visitAugSlice
- self.visit(node.expr)
- slice = 0
- if node.lower:
- self.visit(node.lower)
- slice = slice | 1
- if node.upper:
- self.visit(node.upper)
- slice = slice | 2
- if aug_flag:
- if slice == 0:
- self.emit('DUP_TOP')
- elif slice == 3:
- self.emit('DUP_TOPX', 3)
- else:
- self.emit('DUP_TOPX', 2)
- if node.flags == 'OP_APPLY':
- self.emit('SLICE+%d' % slice)
- elif node.flags == 'OP_ASSIGN':
- self.emit('STORE_SLICE+%d' % slice)
- elif node.flags == 'OP_DELETE':
- self.emit('DELETE_SLICE+%d' % slice)
- else:
- print "weird slice", node.flags
- raise
+ # subscript stuff
def visitSubscript(self, node, aug_flag=None):
self.visit(node.expr)
@@ -1508,16 +1464,12 @@
class AugName(Delegator):
pass
-class AugSlice(Delegator):
- pass
-
class AugSubscript(Delegator):
pass
wrapper = {
ast.Getattr: AugGetattr,
ast.Name: AugName,
- ast.Slice: AugSlice,
ast.Subscript: AugSubscript,
}
Modified: python/branches/p3yk-noslice/Lib/compiler/transformer.py
==============================================================================
--- python/branches/p3yk-noslice/Lib/compiler/transformer.py (original)
+++ python/branches/p3yk-noslice/Lib/compiler/transformer.py Thu Aug 24 22:59:09 2006
@@ -977,7 +977,7 @@
Names, slices, and attributes are the only allowable nodes.
"""
l = self.com_node(node)
- if l.__class__ in (Name, Slice, Subscript, Getattr):
+ if l.__class__ in (Name, Subscript, Getattr):
return l
raise SyntaxError, "can't assign to %s" % l.__class__.__name__
@@ -1272,14 +1272,6 @@
# extended_slicing: primary "[" slice_list "]"
# slice_list: slice_item ("," slice_item)* [","]
- # backwards compat slice for '[i:j]'
- if len(nodelist) == 2:
- sub = nodelist[1]
- if (sub[1][0] == token.COLON or \
- (len(sub) > 2 and sub[2][0] == token.COLON)) and \
- sub[-1][0] != symbol.sliceop:
- return self.com_slice(primary, sub, assigning)
-
subscripts = []
for i in range(1, len(nodelist), 2):
subscripts.append(self.com_subscript(nodelist[i]))
@@ -1332,20 +1324,6 @@
items.append(self.com_node(ch[2]))
return Sliceobj(items, lineno=extractLineNo(node))
- def com_slice(self, primary, node, assigning):
- # short_slice: [lower_bound] ":" [upper_bound]
- lower = upper = None
- if len(node) == 3:
- if node[1][0] == token.COLON:
- upper = self.com_node(node[2])
- else:
- lower = self.com_node(node[1])
- elif len(node) == 4:
- lower = self.com_node(node[1])
- upper = self.com_node(node[3])
- return Slice(primary, assigning, lower, upper,
- lineno=extractLineNo(node))
-
def get_docstring(self, node, n=None):
if n is None:
n = node[0]
Modified: python/branches/p3yk-noslice/Lib/test/test_compiler.py
==============================================================================
--- python/branches/p3yk-noslice/Lib/test/test_compiler.py (original)
+++ python/branches/p3yk-noslice/Lib/test/test_compiler.py Thu Aug 24 22:59:09 2006
@@ -124,7 +124,8 @@
self.assertEquals(eval(c), [(0, 3), (1, 3), (2, 3)])
-NOLINENO = (compiler.ast.Module, compiler.ast.Stmt, compiler.ast.Discard)
+NOLINENO = (compiler.ast.Module, compiler.ast.Stmt, compiler.ast.Discard,
+ compiler.ast.Const)
###############################################################################
# code below is just used to trigger some possible errors, for the benefit of
Modified: python/branches/p3yk-noslice/TODO
==============================================================================
--- python/branches/p3yk-noslice/TODO (original)
+++ python/branches/p3yk-noslice/TODO Thu Aug 24 22:59:09 2006
@@ -1,7 +1,7 @@
TODO in slice removal:
- - Fix compiler-package to avoid SLICE opcodes
+ - Clean up compilerpackage's code now that SLICE opcodes are gone
- Add tests for the extended slicing abilities of:
buffer
mmap.mmap
More information about the Python-checkins
mailing list