[Python-ideas] Standard (portable) bytecode "assembly" format

Brett Cannon brett at python.org
Fri Feb 26 11:51:39 EST 2016


On Fri, 26 Feb 2016 at 06:34 Victor Stinner <victor.stinner at gmail.com>
wrote:

> I just released bytecode 0.1, to discuss a "stable" (released) API :-)
> https://pypi.python.org/pypi/bytecode
>
> Instr constructor is now: Instr(name, arg=UNSET, *, lineno=None).
>
> I added SetLineno pseudo-instruction. If Instr is created with no line
> number, the line number is inherited from previous instructions, from
> SetLineno, or from the first line number of the bytecode object
> (default: 1).
>
> Mandatory "Hello World" example:
>
>     from bytecode import Instr, Bytecode
>
>     bytecode = Bytecode()
>     bytecode.extend([Instr("LOAD_NAME", 'print'),
>                      Instr("LOAD_CONST", 'Hello World!'),
>                      Instr("CALL_FUNCTION", 1),
>                      Instr("POP_TOP"),
>                      Instr("LOAD_CONST", None),
>                      Instr("RETURN_VALUE")])
>     code = bytecode.to_code()
>     exec(code)
>

Any reason you went with string constants instead of enums?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160226/0b30701b/attachment.html>


More information about the Python-ideas mailing list