revise arguments for addCode method on lnotab. take several numbers

that are internally converted to chars, rather than taking a string.
This commit is contained in:
Jeremy Hylton 2000-03-06 18:53:14 +00:00
parent fa974a9d06
commit abd7ebf70b
2 changed files with 26 additions and 20 deletions

View File

@ -143,17 +143,19 @@ def makeCodeObject(self):
for t in self.insts: for t in self.insts:
opname = t[0] opname = t[0]
if len(t) == 1: if len(t) == 1:
lnotab.addCode(chr(self.opnum[opname])) lnotab.addCode(self.opnum[opname])
elif len(t) == 2: elif len(t) == 2:
oparg = self._convertArg(opname, t[1])
if opname == 'SET_LINENO': if opname == 'SET_LINENO':
oparg = t[1]
lnotab.nextLine(oparg) lnotab.nextLine(oparg)
else:
oparg = self._convertArg(opname, t[1])
try: try:
hi, lo = divmod(oparg, 256) hi, lo = divmod(oparg, 256)
except TypeError: except TypeError:
raise TypeError, "untranslated arg: %s, %s" % (opname, oparg) raise TypeError, "untranslated arg: %s, %s" % (opname, oparg)
lnotab.addCode(chr(self.opnum[opname]) + chr(lo) + lnotab.addCode(self.opnum[opname], lo, hi)
chr(hi))
# why is a module a special case? # why is a module a special case?
if self.flags == 0: if self.flags == 0:
nlocals = 0 nlocals = 0
@ -324,9 +326,10 @@ def __init__(self):
self.lastoff = 0 self.lastoff = 0
self.lnotab = [] self.lnotab = []
def addCode(self, code): def addCode(self, *args):
self.code.append(code) for arg in args:
self.codeOffset = self.codeOffset + len(code) self.code.append(chr(arg))
self.codeOffset = self.codeOffset + len(args)
def nextLine(self, lineno): def nextLine(self, lineno):
if self.firstline == 0: if self.firstline == 0:
@ -451,9 +454,9 @@ def findDepth(self, insts):
('LOAD_', 1), ('LOAD_', 1),
('IMPORT_', 1), ('IMPORT_', 1),
] ]
# special cases
# special cases:
#: UNPACK_TUPLE, UNPACK_LIST, BUILD_TUPLE, # UNPACK_TUPLE, UNPACK_LIST, BUILD_TUPLE,
# BUILD_LIST, CALL_FUNCTION, MAKE_FUNCTION, BUILD_SLICE # BUILD_LIST, CALL_FUNCTION, MAKE_FUNCTION, BUILD_SLICE
def UNPACK_TUPLE(self, count): def UNPACK_TUPLE(self, count):
return count return count

View File

@ -143,17 +143,19 @@ def makeCodeObject(self):
for t in self.insts: for t in self.insts:
opname = t[0] opname = t[0]
if len(t) == 1: if len(t) == 1:
lnotab.addCode(chr(self.opnum[opname])) lnotab.addCode(self.opnum[opname])
elif len(t) == 2: elif len(t) == 2:
oparg = self._convertArg(opname, t[1])
if opname == 'SET_LINENO': if opname == 'SET_LINENO':
oparg = t[1]
lnotab.nextLine(oparg) lnotab.nextLine(oparg)
else:
oparg = self._convertArg(opname, t[1])
try: try:
hi, lo = divmod(oparg, 256) hi, lo = divmod(oparg, 256)
except TypeError: except TypeError:
raise TypeError, "untranslated arg: %s, %s" % (opname, oparg) raise TypeError, "untranslated arg: %s, %s" % (opname, oparg)
lnotab.addCode(chr(self.opnum[opname]) + chr(lo) + lnotab.addCode(self.opnum[opname], lo, hi)
chr(hi))
# why is a module a special case? # why is a module a special case?
if self.flags == 0: if self.flags == 0:
nlocals = 0 nlocals = 0
@ -324,9 +326,10 @@ def __init__(self):
self.lastoff = 0 self.lastoff = 0
self.lnotab = [] self.lnotab = []
def addCode(self, code): def addCode(self, *args):
self.code.append(code) for arg in args:
self.codeOffset = self.codeOffset + len(code) self.code.append(chr(arg))
self.codeOffset = self.codeOffset + len(args)
def nextLine(self, lineno): def nextLine(self, lineno):
if self.firstline == 0: if self.firstline == 0:
@ -451,9 +454,9 @@ def findDepth(self, insts):
('LOAD_', 1), ('LOAD_', 1),
('IMPORT_', 1), ('IMPORT_', 1),
] ]
# special cases
# special cases:
#: UNPACK_TUPLE, UNPACK_LIST, BUILD_TUPLE, # UNPACK_TUPLE, UNPACK_LIST, BUILD_TUPLE,
# BUILD_LIST, CALL_FUNCTION, MAKE_FUNCTION, BUILD_SLICE # BUILD_LIST, CALL_FUNCTION, MAKE_FUNCTION, BUILD_SLICE
def UNPACK_TUPLE(self, count): def UNPACK_TUPLE(self, count):
return count return count