codegen package

Package providing the code generation framework.

_prefs module

Module declaring general code generation preferences.

codeobject module

Module providing the base CodeObject and related functions.

Exported members: CodeObject, CodeObjectUpdater

Classes

CodeObject(owner, code, variables, ...[, name]) Executable code object.

Functions

check_code_units(code, group[, user_code, ...]) Check statements for correct units.
create_runner_codeobj(group, code, template_name) Create a CodeObject for the execution of code in the context of a Group.

statements module

Module providing the Statement class.

Classes

Statement(var, op, expr, comment, dtype[, ...]) A single line mathematical statement.

targets module

Module that stores all known code generation targets as codegen_targets.

Exported members: codegen_targets

templates module

Handles loading templates from a directory.

Exported members: Templater

Classes

CodeObjectTemplate(template, template_source)
MultiTemplate(module)
Templater(package_name[, env_globals]) Class to load and return all the templates a CodeObject defines.

Functions

autoindent(code)
autoindent_postfilter(code)

translation module

This module translates a series of statements into a language-specific syntactically correct code block that can be inserted into a template.

It infers whether or not a variable can be declared as constant, etc. It should handle common subexpressions, and so forth.

The input information needed:

  • The sequence of statements (a multiline string) in standard mathematical form
  • The list of known variables, common subexpressions and functions, and for each variable whether or not it is a value or an array, and if an array what the dtype is.
  • The dtype to use for newly created variables
  • The language to translate to

Exported members: make_statements(), analyse_identifiers(), get_identifiers_recursively()

Classes

LineInfo(**kwds) A helper class, just used to store attributes.

Functions

analyse_identifiers(code, variables[, recursive]) Analyses a code string (sequence of statements) to find all identifiers by type.
get_identifiers_recursively(expressions, ...) Gets all the identifiers in a list of expressions, recursing down into subexpressions.
make_statements(code, variables, dtype) Turn a series of abstract code statements into Statement objects, inferring whether each line is a set/declare operation, whether the variables are constant or not, and handling the cacheing of subexpressions.