[pypy-svn] r18121 - pypy/dist/pypy/interpreter/astcompiler
ac at codespeak.net
ac at codespeak.net
Tue Oct 4 09:30:16 CEST 2005
Author: ac
Date: Tue Oct 4 09:30:15 2005
New Revision: 18121
Modified:
pypy/dist/pypy/interpreter/astcompiler/misc.py
pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
Log:
Minor cleanup.
Modified: pypy/dist/pypy/interpreter/astcompiler/misc.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/misc.py (original)
+++ pypy/dist/pypy/interpreter/astcompiler/misc.py Tue Oct 4 09:30:15 2005
@@ -1,4 +1,3 @@
-
from pypy.interpreter.astcompiler import ast
def flatten(tup):
@@ -19,45 +18,6 @@
self.count += 1
return i
-class Set:
- _annspecialcase_ = "specialize:ctr_location" # polymorphic
-
- def __init__(self):
- self.elts = {}
- def __len__(self):
- return len(self.elts)
- def __contains__(self, elt):
- return elt in self.elts
- def add(self, elt):
- self.elts[elt] = elt
- def elements(self):
- return self.elts.keys()
- def has_elt(self, elt):
- return elt in self.elts
- def remove(self, elt):
- del self.elts[elt]
- def copy(self):
- c = Set()
- c.elts.update(self.elts)
- return c
-
-class Stack:
- _annspecialcase_ = "specialize:ctr_location" # polymorphic
-
- def __init__(self):
- self.stack = []
- self.pop = self.stack.pop
- def __len__(self):
- return len(self.stack)
- def push(self, elt):
- self.stack.append(elt)
- def top(self):
- return self.stack[-1]
- def __getitem__(self, index): # needed by visitContinue()
- return self.stack[index]
- def elementAtIndex(self, index):
- return self.stack[index]
-
MANGLE_LEN = 256 # magic constant from compile.c
def mangle(name, klass):
Modified: pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/pycodegen.py (original)
+++ pypy/dist/pypy/interpreter/astcompiler/pycodegen.py Tue Oct 4 09:30:15 2005
@@ -143,7 +143,7 @@
def __init__(self, space, graph):
self.space = space
- self.setups = misc.Stack()
+ self.setups = []
self.last_lineno = -1
self._div_op = "BINARY_DIVIDE"
self.genexpr_cont_stack = []
@@ -425,7 +425,7 @@
self.emitop_block('SETUP_LOOP', after)
self.nextBlock(loop)
- self.setups.push((LOOP, loop))
+ self.setups.append((LOOP, loop))
self.set_lineno(node, force=True)
node.test.accept( self )
@@ -448,7 +448,7 @@
start = self.newBlock()
anchor = self.newBlock()
after = self.newBlock()
- self.setups.push((LOOP, start))
+ self.setups.append((LOOP, start))
self.set_lineno(node)
self.emitop_block('SETUP_LOOP', after)
@@ -469,15 +469,15 @@
self.nextBlock(after)
def visitBreak(self, node):
- if not self.setups:
+ if len(self.setups) == 0:
raise SyntaxError( "'break' outside loop", node.lineno)
self.set_lineno(node)
self.emit('BREAK_LOOP')
def visitContinue(self, node):
- if not self.setups:
+ if len(self.setups) == 0:
raise SyntaxError( "'continue' not properly in loop", node.lineno)
- kind, block = self.setups.top()
+ kind, block = self.setups[-1]
if kind == LOOP:
self.set_lineno(node)
self.emitop_block('JUMP_ABSOLUTE', block)
@@ -485,11 +485,11 @@
elif kind == EXCEPT or kind == TRY_FINALLY:
self.set_lineno(node)
# find the block that starts the loop
- top = len(self.setups.stack)
+ top = len(self.setups)
loop_block = None
while top > 0:
top = top - 1
- kind, loop_block = self.setups.elementAtIndex(top)
+ kind, loop_block = self.setups[top]
if kind == LOOP:
break
if kind != LOOP:
@@ -741,7 +741,7 @@
self.set_lineno(node)
self.emitop_block('SETUP_EXCEPT', handlers)
self.nextBlock(body)
- self.setups.push((EXCEPT, body))
+ self.setups.append((EXCEPT, body))
node.body.accept( self )
self.emit('POP_BLOCK')
self.setups.pop()
@@ -785,13 +785,13 @@
self.set_lineno(node)
self.emitop_block('SETUP_FINALLY', final)
self.nextBlock(body)
- self.setups.push((TRY_FINALLY, body))
+ self.setups.append((TRY_FINALLY, body))
node.body.accept( self )
self.emit('POP_BLOCK')
self.setups.pop()
self.emitop_obj('LOAD_CONST', self.space.w_None)
self.nextBlock(final)
- self.setups.push((END_FINALLY, final))
+ self.setups.append((END_FINALLY, final))
node.final.accept( self )
self.emit('END_FINALLY')
self.setups.pop()
@@ -1012,8 +1012,8 @@
self.emit('RETURN_VALUE')
def visitYield(self, node):
- if self.setups:
- kind, block = self.setups.top()
+ if len(self.setups):
+ kind, block = self.setups[-1]
if kind == TRY_FINALLY:
raise SyntaxError("'yield' not allowed in a 'try' block "
"with a 'finally' clause",
More information about the Pypy-commit
mailing list