pg.mutfun.Code

Accessible via pg.mutfun.Code.

class Code[source]

Bases: pg.Object

Interface for code entity.

Methods:

compile()

Compiles current instruction.

evaluate(context)

Evaluates current instruction with variable dictionary.

format([compact, verbose, root_indent])

Overrides pg.Symbolic.format to support Python program representation.

input_defs([transitive])

Returns the symbol definitions for the inputs of this code entity.

input_vars([transitive])

Returns the input context from this code entity.

line()

Returns the top-level code entity of current line.

line_number()

Returns the 0-based line number of current line within its function.

output_refs([transitive])

Returns the references to the symbols that this code outputs.

output_vars([transitive])

Returns the output context from this instruction.

parent_code()

Returns the parent code entity of current code entity.

parent_func()

Returns the parent function of current code entity.

preceding_lines()

Iterates the preceding lines (first first).

preceding_lines_reversed()

Iterates the preceding lines in reversed order (recent first).

python_repr([block_indent])

Returns a Python code representation of current instruction.

seen_vars()

Returns seen context prior to this instruction.

succeeding_lines()

Iterates the top-level instructions of succeeding lines.

compile()[source]

Compiles current instruction.

Return type:

None

abstract evaluate(context)[source]

Evaluates current instruction with variable dictionary.

Return type:

Any

format(compact=True, verbose=False, root_indent=0, **kwargs)[source]

Overrides pg.Symbolic.format to support Python program representation.

Return type:

str

input_defs(transitive=True)[source]

Returns the symbol definitions for the inputs of this code entity.

Return type:

List[pg.mutfun.SymbolDefinition]

Parameters:

transitive – If True, transitive inputs will be included. Otherwise, only the direct dependencies will be included.

Returns:

A list of SymbolDefinition in their declaration order that produce the inputs required for current code entity.

input_vars(transitive=False)[source]

Returns the input context from this code entity.

Return type:

Set[str]

Parameters:

transitive – If True, transitive input context will be included.

Returns:

A set of context.

line()[source]

Returns the top-level code entity of current line.

Return type:

pg.mutfun.Code

line_number()[source]

Returns the 0-based line number of current line within its function.

Return type:

int

output_refs(transitive=True)[source]

Returns the references to the symbols that this code outputs.

Return type:

List[pg.mutfun.SymbolReference]

Parameters:

transitive – If True, transitive symbol references will be included. Otherwise, only the direct dependencies will be included.

Returns:

A list of Var` or ``FunctionCall in their definition order that consume the outputs of current instruction. Users can use parent_instruction or line to get their context.

output_vars(transitive=False)[source]

Returns the output context from this instruction.

Return type:

Set[str]

Parameters:

transitive – If True, transitive output context will be included.

Returns:

A set of output variable names.

parent_code()[source]

Returns the parent code entity of current code entity.

Return type:

Optional[pg.mutfun.Code]

parent_func()[source]

Returns the parent function of current code entity.

Return type:

Optional[pg.mutfun.Function]

preceding_lines()[source]

Iterates the preceding lines (first first).

Return type:

Iterable[pg.mutfun.Code]

preceding_lines_reversed()[source]

Iterates the preceding lines in reversed order (recent first).

Return type:

Iterable[pg.mutfun.Code]

abstract python_repr(block_indent=0)[source]

Returns a Python code representation of current instruction.

Return type:

str

seen_vars()[source]

Returns seen context prior to this instruction.

Return type:

Set[str]

succeeding_lines()[source]

Iterates the top-level instructions of succeeding lines.

Return type:

Iterable[pg.mutfun.Code]