1. Larry Hastings
  2. maynard



Maynard Copyright 2013-2015 by Larry Hastings


Maynard is an assembler/disassembler for Python 3. It currently works with Python 3.3, 3.4, and 3.5.


maynard.disassemble(o, *, f=None)

Disassemble o. o can be one of three types:
types.FunctionType types.CodeType file - assumed to be an open module file


Assembler that simply converts text to bytecode. lineno argument specifies the first line number of the input.


add_opcode(opcode, oparg=None)
Add an opcode to the current program.
assemble(i, lineno=None)
Assemble lines from the iterable i. If lineno is not None, this is the starting line number of the submitted text. Blank lines are ignored.
assemble_line(s, lineno):
Assemble an individual line. Lineno is required. Blank lines are ignored.

maynard.Assembler(name, type)

Subclass of Assembler. Extends the bytecode syntax with the following statments:

arg name [default]
Specifies an argument to the function.
kwonly name [default]
Specifies a keyword-only argument to the function.
args name
Specifies that this function should take "*args" for additional positional parameters.
kwargs name
Specifies that this function should take "**kwargs" for additional keyword-only parameters.
global name
Creates an entry in the global name array for this function.
local name
Creates a local variable with the specified name. In functions, this is a "fast local"; in all other contexts this is a "slow local". (Which means that in classes this creates a member.)
const name value
Creates an entry in the constants table.

load name store name

Load and store to any variable known to the assembler (specified with arg, kwonly, args, kwargs, global, local, or const).
def name:
Start a function definition. Nested definitions (functions, classes) are permitted.
class name:
Start a class definition. Nested definitions (functions, classes) are permitted.
Ends the current function or class definition. Automatically adds the equivalent of a "return None" if the last opcode is not RETURN_VALUE.
label name:
Destination for a jump instruction. All jump opcodes accept these names as their destinations.
Line comment character.

Additional methods:

Returns a FunctionObject that will execute the assembled bytecode.
Returns a module object initialized using the assembled bytecode. If module is not None, it is the module used, otherwise a new types.ModuleType is used.