compile

package
Version: v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2022 License: BSD-3-Clause Imports: 12 Imported by: 13

Documentation

Overview

compile python code

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(src, srcDesc string, mode py.CompileMode, futureFlags int, dont_inherit bool) (*py.Code, error)

Compile(src, srcDesc, compileMode, flags, dont_inherit) -> code object

Compile the source string (a Python module, statement or expression) into a code object that can be executed.

srcDesc is used for run-time error messages and is typically a file system pathname,

See py.CompileMode for compile mode options.

The flags argument, if present, controls which future statements influence the compilation of the code.

The dont_inherit argument, if non-zero, stops the compilation inheriting the effects of any future statements in effect in the code calling compile; if absent or zero these statements do influence the compilation, in addition to any features explicitly specified.

func LegacyCompile

func LegacyCompile(str, filename, mode string, flags int, dont_inherit bool) py.Object

Compile(source, filename, mode, flags, dont_inherit) -> code object

Compile the source string (a Python module, statement or expression) into a code object that can be executed by exec() or eval(). The filename will be used for run-time error messages. The mode must be 'exec' to compile a module, 'single' to compile a single (interactive) statement, or 'eval' to compile an expression. The flags argument, if present, controls which future statements influence the compilation of the code. The dont_inherit argument, if non-zero, stops the compilation inheriting the effects of any future statements in effect in the code calling compile; if absent or zero these statements do influence the compilation, in addition to any features explicitly specified.

Types

type Instruction

type Instruction interface {
	Pos() uint32
	Number() int
	Lineno() int
	SetLineno(int)
	SetPos(int, uint32) bool
	Size() uint32
	Output() []byte
	StackEffect() int
}

type Instructions

type Instructions []Instruction

Resolved or unresolved instruction stream

func (*Instructions) Add

func (is *Instructions) Add(i Instruction)

Add an instruction to the instructions

func (Instructions) Assemble

func (is Instructions) Assemble() string

Assemble the instructions into an Opcode string

func (Instructions) EndsWithReturn

func (is Instructions) EndsWithReturn() bool

EndsWithReturn returns true if the instruction stream ends with a RETURN_VALUE

func (Instructions) Lnotab

func (is Instructions) Lnotab() []byte

Creates the lnotab from the instruction stream

See Objects/lnotab_notes.txt for the description of the line number table.

func (Instructions) Pass

func (is Instructions) Pass(pass int) bool

Do a pass of assembly

Returns a boolean as to whether the stream changed

func (Instructions) StackDepth

func (is Instructions) StackDepth() int

Find the flow path that needs the largest stack. We assume that cycles in the flow graph have no net effect on the stack depth.

type JumpAbs

type JumpAbs struct {
	OpArg
	Dest *Label
	// contains filtered or unexported fields
}

An absolute JUMP with destination label

func (*JumpAbs) Lineno

func (p *JumpAbs) Lineno() int

Read lineno

func (*JumpAbs) Number

func (p *JumpAbs) Number() int

Read instruction number

func (*JumpAbs) Pos

func (p *JumpAbs) Pos() uint32

Read position

func (*JumpAbs) Resolve

func (o *JumpAbs) Resolve()

Set the Arg from the Jump Label

func (*JumpAbs) SetLineno

func (p *JumpAbs) SetLineno(lineno int)

Set lineno

func (*JumpAbs) SetPos

func (p *JumpAbs) SetPos(number int, newPos uint32) bool

Set Position - returns changed

type JumpRel

type JumpRel struct {
	OpArg
	Dest *Label
	// contains filtered or unexported fields
}

A relative JUMP with destination label

func (*JumpRel) Lineno

func (p *JumpRel) Lineno() int

Read lineno

func (*JumpRel) Number

func (p *JumpRel) Number() int

Read instruction number

func (*JumpRel) Pos

func (p *JumpRel) Pos() uint32

Read position

func (*JumpRel) Resolve

func (o *JumpRel) Resolve()

Set the Arg from the Jump Label

func (*JumpRel) SetLineno

func (p *JumpRel) SetLineno(lineno int)

Set lineno

func (*JumpRel) SetPos

func (p *JumpRel) SetPos(number int, newPos uint32) bool

Set Position - returns changed

type Label

type Label struct {
	// contains filtered or unexported fields
}

A label

func (*Label) Lineno

func (p *Label) Lineno() int

Read lineno

func (*Label) Number

func (p *Label) Number() int

Read instruction number

func (Label) Output

func (o Label) Output() []byte

Output

func (*Label) Pos

func (p *Label) Pos() uint32

Read position

func (*Label) SetLineno

func (p *Label) SetLineno(lineno int)

Set lineno

func (*Label) SetPos

func (p *Label) SetPos(number int, newPos uint32) bool

Set Position - returns changed

func (*Label) Size

func (o *Label) Size() uint32

Uses 0 bytes in the output stream

func (*Label) StackEffect

func (o *Label) StackEffect() int

StackEffect

type Op

type Op struct {
	Op vm.OpCode
	// contains filtered or unexported fields
}

A plain opcode

func (*Op) Lineno

func (p *Op) Lineno() int

Read lineno

func (*Op) Number

func (p *Op) Number() int

Read instruction number

func (*Op) Output

func (o *Op) Output() []byte

Output

func (*Op) Pos

func (p *Op) Pos() uint32

Read position

func (*Op) SetLineno

func (p *Op) SetLineno(lineno int)

Set lineno

func (*Op) SetPos

func (p *Op) SetPos(number int, newPos uint32) bool

Set Position - returns changed

func (*Op) Size

func (o *Op) Size() uint32

Uses 1 byte in the output stream

func (*Op) StackEffect

func (o *Op) StackEffect() int

StackEffect

type OpArg

type OpArg struct {
	Op  vm.OpCode
	Arg uint32
	// contains filtered or unexported fields
}

An opcode with argument

func (*OpArg) Lineno

func (p *OpArg) Lineno() int

Read lineno

func (*OpArg) Number

func (p *OpArg) Number() int

Read instruction number

func (*OpArg) Output

func (o *OpArg) Output() []byte

Output

func (*OpArg) Pos

func (p *OpArg) Pos() uint32

Read position

func (*OpArg) SetLineno

func (p *OpArg) SetLineno(lineno int)

Set lineno

func (*OpArg) SetPos

func (p *OpArg) SetPos(number int, newPos uint32) bool

Set Position - returns changed

func (*OpArg) Size

func (o *OpArg) Size() uint32

Uses 1 byte in the output stream

func (*OpArg) StackEffect

func (o *OpArg) StackEffect() int

StackEffect

type Resolver

type Resolver interface {
	Resolve()
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL