[Python-checkins] CVS: python/dist/src/Tools/compiler/compiler pyassem.py,1.22,1.23
Jeremy Hylton
jhylton@users.sourceforge.net
Wed, 29 Aug 2001 12:45:35 -0700
Update of /cvsroot/python/python/dist/src/Tools/compiler/compiler
In directory usw-pr-cvs1:/tmp/cvs-serv4464
Modified Files:
pyassem.py
Log Message:
Undo change from list to dict for handling varnames, consts, etc.
As the doc string for _lookupName() explains:
This routine uses a list instead of a dictionary, because a
dictionary can't store two different keys if the keys have the
same value but different types, e.g. 2 and 2L. The compiler
must treat these two separately, so it does an explicit type
comparison before comparing the values.
Index: pyassem.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/compiler/compiler/pyassem.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** pyassem.py 2001/08/29 18:09:50 1.22
--- pyassem.py 2001/08/29 19:45:33 1.23
***************
*** 16,30 ****
return l
- def list2dict(l):
- d = {}
- for i in range(len(l)):
- d[l[i]] = i
- return d
-
- def dict2list(d):
- l = [(v, k) for k, v in d.items()]
- l.sort()
- return [k for v, k in l]
-
class FlowGraph:
def __init__(self):
--- 16,19 ----
***************
*** 458,467 ****
self.consts.insert(0, self.docstring)
self.sort_cellvars()
-
- self.c_varnames = list2dict(self.varnames)
- self.c_names = list2dict(self.names)
- self.c_consts = list2dict(self.consts)
- self.c_closure = list2dict(self.closure)
-
for i in range(len(self.insts)):
t = self.insts[i]
--- 447,450 ----
***************
*** 471,480 ****
if conv:
self.insts[i] = opname, conv(self, oparg)
-
- self.varnames = dict2list(self.c_varnames)
- self.names = dict2list(self.c_names)
- self.consts = dict2list(self.c_consts)
- self.closure = dict2list(self.c_closure)
-
self.stage = CONV
--- 454,457 ----
***************
*** 492,512 ****
self.closure = self.cellvars + self.freevars
! def _lookupName(self, name, dict):
! i = dict.get(name, None)
! if i is None:
! i = dict[name] = len(dict)
! return i
! def XXX_lookupName(self, name, list):
! """Return index of name in list, appending if necessary"""
! # XXX It should be possible to replace this with some
! # dictionary operations, but not sure how
t = type(name)
for i in range(len(list)):
! # must do a comparison on type first to prevent UnicodeErrors
! # not clear that a dictionary would work, because we could
! # get UnicodeErrors on lookups
! elt = list[i]
! if isinstance(elt, t) and elt == name:
return i
end = len(list)
--- 469,484 ----
self.closure = self.cellvars + self.freevars
! def _lookupName(self, name, list):
! """Return index of name in list, appending if necessary
! This routine uses a list instead of a dictionary, because a
! dictionary can't store two different keys if the keys have the
! same value but different types, e.g. 2 and 2L. The compiler
! must treat these two separately, so it does an explicit type
! comparison before comparing the values.
! """
t = type(name)
for i in range(len(list)):
! if t == type(list[i]) and list[i] == name:
return i
end = len(list)
***************
*** 518,536 ****
if hasattr(arg, 'getCode'):
arg = arg.getCode()
! return self._lookupName(arg, self.c_consts)
def _convert_LOAD_FAST(self, arg):
! self._lookupName(arg, self.c_names)
! return self._lookupName(arg, self.c_varnames)
_convert_STORE_FAST = _convert_LOAD_FAST
_convert_DELETE_FAST = _convert_LOAD_FAST
def _convert_LOAD_NAME(self, arg):
! return self._lookupName(arg, self.c_names)
def _convert_NAME(self, arg):
! if self.klass is None:
! self._lookupName(arg, self.c_varnames)
! return self._lookupName(arg, self.c_names)
_convert_STORE_NAME = _convert_NAME
_convert_DELETE_NAME = _convert_NAME
--- 490,509 ----
if hasattr(arg, 'getCode'):
arg = arg.getCode()
! return self._lookupName(arg, self.consts)
def _convert_LOAD_FAST(self, arg):
! self._lookupName(arg, self.names)
! return self._lookupName(arg, self.varnames)
_convert_STORE_FAST = _convert_LOAD_FAST
_convert_DELETE_FAST = _convert_LOAD_FAST
def _convert_LOAD_NAME(self, arg):
! if self.klass is None:
! self._lookupName(arg, self.varnames)
! return self._lookupName(arg, self.names)
def _convert_NAME(self, arg):
! self._lookupName(arg, self.varnames)
! return self._lookupName(arg, self.names)
_convert_STORE_NAME = _convert_NAME
_convert_DELETE_NAME = _convert_NAME
***************
*** 545,557 ****
def _convert_DEREF(self, arg):
! self._lookupName(arg, self.c_names)
! self._lookupName(arg, self.c_varnames)
! return self._lookupName(arg, self.c_closure)
_convert_LOAD_DEREF = _convert_DEREF
_convert_STORE_DEREF = _convert_DEREF
def _convert_LOAD_CLOSURE(self, arg):
! self._lookupName(arg, self.c_varnames)
! return self._lookupName(arg, self.c_closure)
_cmp = list(dis.cmp_op)
--- 518,530 ----
def _convert_DEREF(self, arg):
! self._lookupName(arg, self.names)
! self._lookupName(arg, self.varnames)
! return self._lookupName(arg, self.closure)
_convert_LOAD_DEREF = _convert_DEREF
_convert_STORE_DEREF = _convert_DEREF
def _convert_LOAD_CLOSURE(self, arg):
! self._lookupName(arg, self.varnames)
! return self._lookupName(arg, self.closure)
_cmp = list(dis.cmp_op)