The curry Package
This section gives a high-level view of the curry package. The intent
is to give readers some idea of where various bits of Sprite can be located.
Top-Level API
The curry module itself serves as a collection of classes and functions
intended to carry out the most common tasks. Many of these are methods of a
singleton Curry interpreter that is created when importing curry. For many
common use cases, one can simply use these methods without ever thinking about
an interpreter, let alone creating one.
The global interpreter can be obtained by calling curry.getInterpreter().
The top-level data and methods fall roughly into the following categories:
System Control
These can be used to manipulate the global interpreter:
curry.flags: The flags of the global interpreter, a dict; see Interpreter flags.
curry.path: Configure or view the Curry search path.
curry.reload(): Discard the global interpreter, then create a new one, with the flags given and those of the environment.
curry.reset(): Soft-reset the global interpreter: unload every module but the Prelude and the packages, reset the path, clear the signature table.
curry.stats(): Report the statistics of the run: time, steps, forks, collections, memory, compile time, collector time, the counts of tiered execution, and the counters of the collector.Also, see the
curry.configmodule.Symbols & Types
These can be used to find Curry objects.
curry.module(): Find a loaded module by name. A module of the Curry library of the installation is imported on demand; any other module must be imported first.
curry.symbol(): Find a symbol by name.
curry.type(): Find a type by name.
curry.currytype(): Get the Curry type that corresponds to a Python type.Curry Modules
These can be used to create, transform, load, or save Curry code.
curry.compile(): Create Curry modules (with mode ‘module’).
curry.import_(): Import a Curry module by name.
curry.load(): Load a compiled Curry module from its shared object.
curry.save(): Write the generated code of a module to a file, a program with a goal or a module alone (module_main=False). The form is the one of the backend.
curry.modules: Access imported modules.Expressions & Evaluation
These can be used to build and evaluate Curry expressions.
curry.compile(): Create Curry expressions (with mode ‘expr’).
curry.eval(): Evaluate a Curry goal; the arguments ofcurry.expr(), with the keywordconverter.
curry.expr(): Construct a Curry expression, typed (see Typed Expressions).
curry.raw_expr(): Construct a Curry expression without types.
curry.typeof(): The type of an expression or of a symbol.
curry.describe(): Describe an expression, to be typed as a whole later.
curry.topython(): Convert a Curry value to Python.
curry.show_value(): The text of a converted value in Curry format.Markers of expressions
These objects stand for the parts of an expression that are no Python value (
curry.expressions).
curry.free: A free variable; one marker is one variable.
curry.choice: A non-deterministic choice between two expressions.
curry.typed: A part with its type stated in Curry syntax.
curry.ref: A reference to a named subexpression (a keyword argument ofcurry.expr()).
curry.cons,curry.nil: The cells of a cons-style list.
curry.fail: A failure.
curry.unboxed: The unboxed payload of anInt,CharorFloat, as in[Prelude.Int, curry.unboxed(3)]. A payload that does not fit the primitive, and the marker anywhere else, is an error at construction; an item of an iterator is refused when the list is demanded.
The errors the package raises are in curry.exceptions. The errors
of the typed boundary are subclasses of
curry.exceptions.CurryTypeError, a TypeError, listed with an
example each under the error catalogue. The errors
of an evaluation are subclasses of
curry.exceptions.EvaluationError. EvaluationError and
curry.exceptions.CompileError derive from BaseException, not
from Exception, so except Exception does not catch them; name the
class in the except clause.
Interpreter flags
An interpreter has a dict of flags. curry.flags is the dict of the
global interpreter; the environment variable SPRITE_INTERPRETER_FLAGS
sets the flags of a process (interpret:off,rotation:steps:65536), and
curry.reload() or Interpreter(flags={...}) sets them for a new
interpreter, over the flags of the environment. A flag read at the start
of an evaluation takes effect at the next one when it is changed in the
dict. backend is read when the interpreter is made, so a change of it
in the dict has no effect; curry.reload() or a new interpreter
selects a backend. An assignment to curry.flags rebinds the name
in the package and changes nothing. curry.interpreter.flags
describes every flag at length; the table names them with their defaults.
Flag |
Default |
What it changes |
|---|---|---|
|
|
The backend: |
|
|
How the C++ backend runs a module without a compiled
object: |
|
|
How the C++ backend paces the rotation of its queue
of alternatives: time mode ( |
|
|
The bytes of C stack the C++ backend lets one
evaluation use; |
|
|
Whether |
|
|
The largest function body, in nodes built, that the
optimizer inlines at a call; a call of a single-case
function on a constructor becomes the branch. |
|
|
The converter of |
|
|
The checker mode of the Fair Scheme proofs program: the reference backend asserts the run-time invariants of the Fair Scheme at every fork, escape, pull-tab, instantiation and yield; the C++ backend ignores it. |
|
|
More consistency checks; the C++ backend compiles its modules in the debug flavor. |
|
|
Trace the computation. |
|
|
Seconds between the event reports of the runtime in
the log; |
|
|
Materialize a function when it is first needed. |
|
|
Keep the temporary files; a string names the directory for them. |
|
|
Copy the generated code of a failed compile from a string to the working directory. |
Package Structure
The contents of the curry package are documented in detail in the
API Reference. The major submodules are described briefly below.
curry.backendsThe interface
IBackend, its implementation, the C++ backend (curry.backends.cxx), and the generic code of the backends (curry.backends.generic).curry.cacheImplements caching for Curry-to-ICurry and other conversions.
curry.commonContains common definitions used throughout Sprite.
curry.configFunctions for interacting with Sprite’s system configuration.
curry.exceptionsContains all non-built-in exceptions Sprite might raise.
curry.expressionsThe builders
curry.expr(),curry.raw_expr(),curry.typeof()andcurry.describe(), and the markers of an expression.curry.icurryA Python implementation of ICurry, which serves as the Sprite IR.
curry.inspectA module for inspecting Curry objects: the predicates on nodes, the types of a module, the ICurry and the generated code of a symbol.
curry.interpreterDefines the Curry interpreter: the class
Interpreter, the flags, and the modules that implement its methods.curry.libA virtual package used as the base for importing Curry modules.
curry.objectsDefines the objects used to provide Python APIs to Curry objects. For instance, this defines
curry.objects.CurryModule, which is the object created by importing a Curry module, andcurry.objects.CurryNodeInfo, the object of a symbol.curry.showCode for converting Curry expressions to strings.
curry.toolchainContains code for manipulating the compilation pipeline. Driver functions for external programs used by Sprite can be found here, and the translation from FlatCurry to ICurry (
curry.toolchain.flat2icurry).curry.toolsDefines the command-line tools that come with Sprite. This is where the source for sprite-make and the REPL (
curry.tools.icy) can be found. sprite-exec is defined in the__main__.pyfile forcurry. This, incidentally, means that runningpython -m curryfrom a command prompt is a synonym for sprite-exec.curry.typecheckThe typed boundary between Python and Curry. The signature table reads the type schemes of the loaded symbols from the FlatCurry interfaces (
symbol.signature,symbol.scheme,interp.sigtable). The package also holds the defaulting table and the goals ofcurry.eval(), the engine and the builder that type the expressions ofcurry.expr(), and the error catalogue (curry.typecheck.errors).curry.utilityGeneral-purpose code.