def printcodelist(codelist, to=sys.stdout):
labeldict = {}<EOL>pendinglabels = []<EOL>for i, (op, arg) in enumerate(codelist):<EOL><INDENT>if isinstance(op, Label):<EOL><INDENT>pendinglabels.append(op)<EOL><DEDENT>elif op is SetLineno:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>while pendinglabels:<EOL><INDENT>labeldict[pendinglabels.pop()] = i<EOL><DEDENT><DEDENT><DEDENT>lineno = None<EOL>islabel = False<EOL>for i, (op, arg) in enumerate(codelist):<EOL><INDENT>if op is SetLineno:<EOL><INDENT>lineno = arg<EOL>print(file=to)<EOL>continue<EOL><DEDENT>if isinstance(op, Label):<EOL><INDENT>islabel = True<EOL>continue<EOL><DEDENT>if lineno is None:<EOL><INDENT>linenostr = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>linenostr = str(lineno)<EOL>lineno = None<EOL><DEDENT>if islabel:<EOL><INDENT>islabelstr = '<STR_LIT>'<EOL>islabel = False<EOL><DEDENT>else:<EOL><INDENT>islabelstr = '<STR_LIT>'<EOL><DEDENT>if op in hasconst:<EOL><INDENT>argstr = repr(arg)<EOL><DEDENT>elif op in hasjump:<EOL><INDENT>try:<EOL><INDENT>argstr = '<STR_LIT>' + str(labeldict[arg])<EOL><DEDENT>except KeyError:<EOL><INDENT>argstr = repr(arg)<EOL><DEDENT><DEDENT>elif op in hasarg:<EOL><INDENT>argstr = str(arg)<EOL><DEDENT>else:<EOL><INDENT>argstr = '<STR_LIT>'<EOL><DEDENT>print('<STR_LIT>' % (<EOL>linenostr,<EOL>islabelstr,<EOL>i,<EOL>op,<EOL>argstr), file=to)<EOL><DEDENT>
Get a code list. Print it nicely.