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

Andrew Barnert abarnert at yahoo.com
Fri Feb 26 14:28:54 EST 2016


Can we change the subject for this? Bikeshedding one of multiple different higher-level APIs that could be used for different kinds of bytecode processing is off-topic from having a simple portable format for representing bytecode, except tangentially in that I hope (and am pretty sure) that all such higher-level APIs can be built on top of the portable format.

Sent from my iPhone

> On Feb 26, 2016, at 09:19, Victor Stinner <victor.stinner at gmail.com> wrote:
> 
> 2016-02-26 17:51 GMT+01:00 Brett Cannon <brett at python.org>:
>>>    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")])
>> 
>> Any reason you went with string constants instead of enums?
> 
> My API is still a work-in-progress :-) Maybe the API can be changed to:
> 
> LOAD_CONST('Hello World!')
> POP_TOP()
> 
> But it means that your code will probably starts with "from bytecode
> import *" or "from bytecode import LOAD_CONST, POP_TOP". There are
> something like 155 opcodes, so I would prefer to not have to write the
> exhaustive list of imports.
> 
> Another option is something like:
> 
> Instr.LOAD_CONST('Hello World!')
> Instr.POP_TOP()
> 
> or
> 
> whatever.LOAD_CONST('Hello World!')
> whatever.POP_TOP()
> 
> I don't know what is the best. codetransformers uses
> instructions.LOAD_CONST("Hello World!") and instructions.LOAD_FAST is
> a type (it used for pattern matching).
> 
> Victor


More information about the Python-ideas mailing list