Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit abd7ebf

Browse files
committed
revise arguments for addCode method on lnotab. take several numbers
that are internally converted to chars, rather than taking a string.
1 parent fa974a9 commit abd7ebf

2 files changed

Lines changed: 26 additions & 20 deletions

File tree

Lib/compiler/pyassem.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,19 @@ def makeCodeObject(self):
143143
for t in self.insts:
144144
opname = t[0]
145145
if len(t) == 1:
146-
lnotab.addCode(chr(self.opnum[opname]))
146+
lnotab.addCode(self.opnum[opname])
147147
elif len(t) == 2:
148-
oparg = self._convertArg(opname, t[1])
149148
if opname == 'SET_LINENO':
149+
oparg = t[1]
150150
lnotab.nextLine(oparg)
151+
else:
152+
oparg = self._convertArg(opname, t[1])
151153
try:
152154
hi, lo = divmod(oparg, 256)
153155
except TypeError:
154156
raise TypeError, "untranslated arg: %s, %s" % (opname, oparg)
155-
lnotab.addCode(chr(self.opnum[opname]) + chr(lo) +
156-
chr(hi))
157+
lnotab.addCode(self.opnum[opname], lo, hi)
158+
157159
# why is a module a special case?
158160
if self.flags == 0:
159161
nlocals = 0
@@ -324,9 +326,10 @@ def __init__(self):
324326
self.lastoff = 0
325327
self.lnotab = []
326328

327-
def addCode(self, code):
328-
self.code.append(code)
329-
self.codeOffset = self.codeOffset + len(code)
329+
def addCode(self, *args):
330+
for arg in args:
331+
self.code.append(chr(arg))
332+
self.codeOffset = self.codeOffset + len(args)
330333

331334
def nextLine(self, lineno):
332335
if self.firstline == 0:
@@ -451,9 +454,9 @@ def findDepth(self, insts):
451454
('LOAD_', 1),
452455
('IMPORT_', 1),
453456
]
454-
# special cases
455-
456-
#: UNPACK_TUPLE, UNPACK_LIST, BUILD_TUPLE,
457+
458+
# special cases:
459+
# UNPACK_TUPLE, UNPACK_LIST, BUILD_TUPLE,
457460
# BUILD_LIST, CALL_FUNCTION, MAKE_FUNCTION, BUILD_SLICE
458461
def UNPACK_TUPLE(self, count):
459462
return count

Tools/compiler/compiler/pyassem.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,19 @@ def makeCodeObject(self):
143143
for t in self.insts:
144144
opname = t[0]
145145
if len(t) == 1:
146-
lnotab.addCode(chr(self.opnum[opname]))
146+
lnotab.addCode(self.opnum[opname])
147147
elif len(t) == 2:
148-
oparg = self._convertArg(opname, t[1])
149148
if opname == 'SET_LINENO':
149+
oparg = t[1]
150150
lnotab.nextLine(oparg)
151+
else:
152+
oparg = self._convertArg(opname, t[1])
151153
try:
152154
hi, lo = divmod(oparg, 256)
153155
except TypeError:
154156
raise TypeError, "untranslated arg: %s, %s" % (opname, oparg)
155-
lnotab.addCode(chr(self.opnum[opname]) + chr(lo) +
156-
chr(hi))
157+
lnotab.addCode(self.opnum[opname], lo, hi)
158+
157159
# why is a module a special case?
158160
if self.flags == 0:
159161
nlocals = 0
@@ -324,9 +326,10 @@ def __init__(self):
324326
self.lastoff = 0
325327
self.lnotab = []
326328

327-
def addCode(self, code):
328-
self.code.append(code)
329-
self.codeOffset = self.codeOffset + len(code)
329+
def addCode(self, *args):
330+
for arg in args:
331+
self.code.append(chr(arg))
332+
self.codeOffset = self.codeOffset + len(args)
330333

331334
def nextLine(self, lineno):
332335
if self.firstline == 0:
@@ -451,9 +454,9 @@ def findDepth(self, insts):
451454
('LOAD_', 1),
452455
('IMPORT_', 1),
453456
]
454-
# special cases
455-
456-
#: UNPACK_TUPLE, UNPACK_LIST, BUILD_TUPLE,
457+
458+
# special cases:
459+
# UNPACK_TUPLE, UNPACK_LIST, BUILD_TUPLE,
457460
# BUILD_LIST, CALL_FUNCTION, MAKE_FUNCTION, BUILD_SLICE
458461
def UNPACK_TUPLE(self, count):
459462
return count

0 commit comments

Comments
 (0)