changes to _lookupName

- removed now (happily) unused second arg
- need to verify results of [].index are correct; for building consts,
  need to have same value and same type, e.g. 2 not the same as 2L
This commit is contained in:
Jeremy Hylton 2000-02-17 22:58:54 +00:00
parent 3ec7e2c4be
commit efd0694a2d
2 changed files with 26 additions and 28 deletions

View File

@ -63,7 +63,6 @@ class PyAssembler:
self.insts = [] self.insts = []
# used by makeCodeObject # used by makeCodeObject
self._getArgCount(args) self._getArgCount(args)
print name, args, self.argcount
self.code = '' self.code = ''
self.consts = [docstring] self.consts = [docstring]
self.filename = filename self.filename = filename
@ -260,20 +259,20 @@ class PyAssembler:
localOps = ('LOAD_FAST', 'STORE_FAST', 'DELETE_FAST') localOps = ('LOAD_FAST', 'STORE_FAST', 'DELETE_FAST')
globalOps = ('LOAD_GLOBAL', 'STORE_GLOBAL', 'DELETE_GLOBAL') globalOps = ('LOAD_GLOBAL', 'STORE_GLOBAL', 'DELETE_GLOBAL')
def _lookupName(self, name, list, list2=None): def _lookupName(self, name, list):
"""Return index of name in list, appending if necessary """Return index of name in list, appending if necessary"""
Yicky hack: Second list can be used for lookup of local names
where the name needs to be added to varnames and names.
"""
if name in list: if name in list:
return list.index(name) i = list.index(name)
else: # this is cheap, but incorrect in some cases, e.g 2 vs. 2L
end = len(list) if type(name) == type(list[i]):
list.append(name) return i
if list2 is not None: for i in range(len(list)):
list2.append(name) elt = list[i]
return end if type(elt) == type(name) and elt == name:
return i
end = len(list)
list.append(name)
return end
# Convert some stuff from the dis module for local use # Convert some stuff from the dis module for local use

View File

@ -63,7 +63,6 @@ class PyAssembler:
self.insts = [] self.insts = []
# used by makeCodeObject # used by makeCodeObject
self._getArgCount(args) self._getArgCount(args)
print name, args, self.argcount
self.code = '' self.code = ''
self.consts = [docstring] self.consts = [docstring]
self.filename = filename self.filename = filename
@ -260,20 +259,20 @@ class PyAssembler:
localOps = ('LOAD_FAST', 'STORE_FAST', 'DELETE_FAST') localOps = ('LOAD_FAST', 'STORE_FAST', 'DELETE_FAST')
globalOps = ('LOAD_GLOBAL', 'STORE_GLOBAL', 'DELETE_GLOBAL') globalOps = ('LOAD_GLOBAL', 'STORE_GLOBAL', 'DELETE_GLOBAL')
def _lookupName(self, name, list, list2=None): def _lookupName(self, name, list):
"""Return index of name in list, appending if necessary """Return index of name in list, appending if necessary"""
Yicky hack: Second list can be used for lookup of local names
where the name needs to be added to varnames and names.
"""
if name in list: if name in list:
return list.index(name) i = list.index(name)
else: # this is cheap, but incorrect in some cases, e.g 2 vs. 2L
end = len(list) if type(name) == type(list[i]):
list.append(name) return i
if list2 is not None: for i in range(len(list)):
list2.append(name) elt = list[i]
return end if type(elt) == type(name) and elt == name:
return i
end = len(list)
list.append(name)
return end
# Convert some stuff from the dis module for local use # Convert some stuff from the dis module for local use