mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	 314e3fb215
			
		
	
	
		314e3fb215
		
	
	
	
	
		
			
			embedded code objects (e.g. functions) rather than the generated code
object.  This change means that the compiler generates code for
everything at the end, rather then generating code for each function
as it finds it.  Implementation note: _convert_LOAD_CONST in
pyassem.py must be change to call getCode().
Other changes follow.  Several changes creates extra edges between
basic blocks to reflect control flow for loops and exceptions.  These
missing edges had gone unnoticed because they do not affect the
current compilation process.
pyassem.py:
    Add _enable_debug() and _disable_debug() methods that print
    instructions and blocks to stdout as they are generated.
    Add edges between blocks for instructions like SETUP_LOOP,
    FOR_LOOP, etc.
    Add pruneNext to get rid of bogus edges remaining after
    unconditional transfer ops (e.g. JUMP_FORWARD)
    Change repr of Block to omit block length.
pycodegen.py:
    Make sure a new block is started after FOR_LOOP, etc.
    Change assert implementation to use RAISE_VARARGS 1 when there is
    no user-specified failure output.
misc.py:
    Implement __contains__ and copy for Set.
		
	
			
		
			
				
	
	
		
			41 lines
		
	
	
	
		
			960 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
	
		
			960 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import types
 | |
| 
 | |
| def flatten(tup):
 | |
|     elts = []
 | |
|     for elt in tup:
 | |
|         if type(elt) == types.TupleType:
 | |
|             elts = elts + flatten(elt)
 | |
|         else:
 | |
|             elts.append(elt)
 | |
|     return elts
 | |
| 
 | |
| class Set:
 | |
|     def __init__(self):
 | |
|         self.elts = {}
 | |
|     def __len__(self):
 | |
|         return len(self.elts)
 | |
|     def __contains__(self, elt):
 | |
|         return self.elts.has_key(elt)
 | |
|     def add(self, elt):
 | |
|         self.elts[elt] = elt
 | |
|     def elements(self):
 | |
|         return self.elts.keys()
 | |
|     def has_elt(self, elt):
 | |
|         return self.elts.has_key(elt)
 | |
|     def remove(self, elt):
 | |
|         del self.elts[elt]
 | |
|     def copy(self):
 | |
|         c = Set()
 | |
|         c.elts.update(self.elts)
 | |
|         return c
 | |
| 
 | |
| class Stack:
 | |
|     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]
 |