@@ -60,7 +60,7 @@ class PyAssembler:
6060 def __init__ (self , args = (), name = '?' , filename = '<?>' ,
6161 docstring = None ):
6262 # XXX why is the default value for flags 3?
63- self .insts = []
63+ self .insts = []
6464 # used by makeCodeObject
6565 self ._getArgCount (args )
6666 self .code = ''
@@ -107,10 +107,10 @@ def setKWArgs(self):
107107 self .flags = self .flags | CO_VARKEYWORDS
108108
109109 def getCurInst (self ):
110- return len (self .insts )
110+ return len (self .insts )
111111
112112 def getNextInst (self ):
113- return len (self .insts ) + 1
113+ return len (self .insts ) + 1
114114
115115 def dump (self , io = sys .stdout ):
116116 i = 0
@@ -162,7 +162,7 @@ def makeCodeObject(self):
162162 # XXX danger! can't pass through here twice
163163 if self .flags & CO_VARKEYWORDS :
164164 self .argcount = self .argcount - 1
165- stacksize = findDepth (self .insts )
165+ stacksize = findDepth (self .insts )
166166 try :
167167 co = new .code (self .argcount , nlocals , stacksize ,
168168 self .flags , lnotab .getCode (), self ._getConsts (),
@@ -193,9 +193,9 @@ def _getConsts(self):
193193 """
194194 l = []
195195 for elt in self .consts :
196- # XXX might be clearer to just as isinstance(CodeGen)
197- if hasattr (elt , 'asConst' ):
198- l .append (elt .asConst ())
196+ # XXX might be clearer to just as isinstance(CodeGen)
197+ if hasattr (elt , 'asConst' ):
198+ l .append (elt .asConst ())
199199 else :
200200 l .append (elt )
201201 return tuple (l )
@@ -286,14 +286,14 @@ def _lookupName(self, name, list):
286286
287287 opnum = {}
288288 for num in range (len (dis .opname )):
289- opnum [dis .opname [num ]] = num
289+ opnum [dis .opname [num ]] = num
290290
291291 # this version of emit + arbitrary hooks might work, but it's damn
292292 # messy.
293293
294294 def emit (self , * args ):
295295 self ._emitDispatch (args [0 ], args [1 :])
296- self .insts .append (args )
296+ self .insts .append (args )
297297
298298 def _emitDispatch (self , type , args ):
299299 for func in self ._emit_hooks .get (type , []):
@@ -363,115 +363,115 @@ class StackRef:
363363 count = 0
364364
365365 def __init__ (self , id = None , val = None ):
366- if id is None :
367- id = StackRef .count
368- StackRef .count = StackRef .count + 1
369- self .id = id
370- self .val = val
366+ if id is None :
367+ id = StackRef .count
368+ StackRef .count = StackRef .count + 1
369+ self .id = id
370+ self .val = val
371371
372372 def __repr__ (self ):
373- if self .val :
374- return "StackRef(val=%d)" % self .val
375- else :
376- return "StackRef(id=%d)" % self .id
373+ if self .val :
374+ return "StackRef(val=%d)" % self .val
375+ else :
376+ return "StackRef(id=%d)" % self .id
377377
378378 def bind (self , inst ):
379- self .val = inst
379+ self .val = inst
380380
381381 def resolve (self ):
382382 if self .val is None :
383383 print "UNRESOLVE REF" , self
384384 return 0
385- return self .val
385+ return self .val
386386
387387class StackDepthTracker :
388388 # XXX need to keep track of stack depth on jumps
389389
390390 def findDepth (self , insts ):
391- depth = 0
392- maxDepth = 0
393- for i in insts :
394- opname = i [0 ]
395- delta = self .effect .get (opname , 0 )
396- if delta > 1 :
397- depth = depth + delta
398- elif delta < 0 :
399- if depth > maxDepth :
400- maxDepth = depth
401- depth = depth + delta
402- else :
403- if depth > maxDepth :
404- maxDepth = depth
405- # now check patterns
406- for pat , delta in self .patterns :
407- if opname [:len (pat )] == pat :
408- depth = depth + delta
409- break
410- # if we still haven't found a match
411- if delta == 0 :
412- meth = getattr (self , opname )
413- depth = depth + meth (i [1 ])
414- if depth < 0 :
415- depth = 0
416- return maxDepth
391+ depth = 0
392+ maxDepth = 0
393+ for i in insts :
394+ opname = i [0 ]
395+ delta = self .effect .get (opname , 0 )
396+ if delta > 1 :
397+ depth = depth + delta
398+ elif delta < 0 :
399+ if depth > maxDepth :
400+ maxDepth = depth
401+ depth = depth + delta
402+ else :
403+ if depth > maxDepth :
404+ maxDepth = depth
405+ # now check patterns
406+ for pat , delta in self .patterns :
407+ if opname [:len (pat )] == pat :
408+ depth = depth + delta
409+ break
410+ # if we still haven't found a match
411+ if delta == 0 :
412+ meth = getattr (self , opname )
413+ depth = depth + meth (i [1 ])
414+ if depth < 0 :
415+ depth = 0
416+ return maxDepth
417417
418418 effect = {
419- 'POP_TOP' : - 1 ,
420- 'DUP_TOP' : 1 ,
421- 'SLICE+1' : - 1 ,
422- 'SLICE+2' : - 1 ,
423- 'SLICE+3' : - 2 ,
424- 'STORE_SLICE+0' : - 1 ,
425- 'STORE_SLICE+1' : - 2 ,
426- 'STORE_SLICE+2' : - 2 ,
427- 'STORE_SLICE+3' : - 3 ,
428- 'DELETE_SLICE+0' : - 1 ,
429- 'DELETE_SLICE+1' : - 2 ,
430- 'DELETE_SLICE+2' : - 2 ,
431- 'DELETE_SLICE+3' : - 3 ,
432- 'STORE_SUBSCR' : - 3 ,
433- 'DELETE_SUBSCR' : - 2 ,
434- # PRINT_EXPR?
435- 'PRINT_ITEM' : - 1 ,
436- 'LOAD_LOCALS' : 1 ,
437- 'RETURN_VALUE' : - 1 ,
438- 'EXEC_STMT' : - 2 ,
439- 'BUILD_CLASS' : - 2 ,
440- 'STORE_NAME' : - 1 ,
441- 'STORE_ATTR' : - 2 ,
442- 'DELETE_ATTR' : - 1 ,
443- 'STORE_GLOBAL' : - 1 ,
444- 'BUILD_MAP' : 1 ,
445- 'COMPARE_OP' : - 1 ,
446- 'STORE_FAST' : - 1 ,
447- }
419+ 'POP_TOP' : - 1 ,
420+ 'DUP_TOP' : 1 ,
421+ 'SLICE+1' : - 1 ,
422+ 'SLICE+2' : - 1 ,
423+ 'SLICE+3' : - 2 ,
424+ 'STORE_SLICE+0' : - 1 ,
425+ 'STORE_SLICE+1' : - 2 ,
426+ 'STORE_SLICE+2' : - 2 ,
427+ 'STORE_SLICE+3' : - 3 ,
428+ 'DELETE_SLICE+0' : - 1 ,
429+ 'DELETE_SLICE+1' : - 2 ,
430+ 'DELETE_SLICE+2' : - 2 ,
431+ 'DELETE_SLICE+3' : - 3 ,
432+ 'STORE_SUBSCR' : - 3 ,
433+ 'DELETE_SUBSCR' : - 2 ,
434+ # PRINT_EXPR?
435+ 'PRINT_ITEM' : - 1 ,
436+ 'LOAD_LOCALS' : 1 ,
437+ 'RETURN_VALUE' : - 1 ,
438+ 'EXEC_STMT' : - 2 ,
439+ 'BUILD_CLASS' : - 2 ,
440+ 'STORE_NAME' : - 1 ,
441+ 'STORE_ATTR' : - 2 ,
442+ 'DELETE_ATTR' : - 1 ,
443+ 'STORE_GLOBAL' : - 1 ,
444+ 'BUILD_MAP' : 1 ,
445+ 'COMPARE_OP' : - 1 ,
446+ 'STORE_FAST' : - 1 ,
447+ }
448448 # use pattern match
449449 patterns = [
450- ('BINARY_' , - 1 ),
451- ('LOAD_' , 1 ),
452- ('IMPORT_' , 1 ),
453- ]
450+ ('BINARY_' , - 1 ),
451+ ('LOAD_' , 1 ),
452+ ('IMPORT_' , 1 ),
453+ ]
454454 # special cases
455455
456456 #: UNPACK_TUPLE, UNPACK_LIST, BUILD_TUPLE,
457457 # BUILD_LIST, CALL_FUNCTION, MAKE_FUNCTION, BUILD_SLICE
458458 def UNPACK_TUPLE (self , count ):
459- return count
459+ return count
460460 def UNPACK_LIST (self , count ):
461- return count
461+ return count
462462 def BUILD_TUPLE (self , count ):
463- return - count
463+ return - count
464464 def BUILD_LIST (self , count ):
465- return - count
465+ return - count
466466 def CALL_FUNCTION (self , argc ):
467- hi , lo = divmod (argc , 256 )
468- return lo + hi * 2
467+ hi , lo = divmod (argc , 256 )
468+ return lo + hi * 2
469469 def MAKE_FUNCTION (self , argc ):
470- return - argc
470+ return - argc
471471 def BUILD_SLICE (self , argc ):
472- if argc == 2 :
473- return - 1
474- elif argc == 3 :
475- return - 2
472+ if argc == 2 :
473+ return - 1
474+ elif argc == 3 :
475+ return - 2
476476
477477findDepth = StackDepthTracker ().findDepth
0 commit comments