curry.typecheck.builder module
The typed builder of curry.expr (item Y7 of the typed boundary, epic
#48).
curry.expr describes its arguments as a tree of specs, types the tree
with the engine (engine), defaults the class constraints, resolves
the dictionaries, and then builds the nodes through make_node of the
backend. The conversion of the arguments, the typing and the
materialization each walk the tree with an explicit stack, so the depth of
a description is not bounded by the recursion limit. Python values convert
by the expected type: an int under Float is a Float, a str
under [Char] is one string, a list converts in a loop under its element
type, and the items of an iterator convert when the list is demanded. A
Curry node that fills a parameter is typed by a walk of its content, capped
at VALUE_WALK_CAP nodes; a bare node alone passes through untouched.
The walk types a node without successors, such as [], at every position
it holds, because the runtime shares one such node between positions of
different types (TypedProblem._walk()).
The result type of a node the builder returns is kept in a weak record
(TypeRecord) keyed by the identity of the node, so curry.typeof
answers for it and curry.eval hands the static type of a goal to the
converter. Description holds a tree of specs for the DSL and types
it only when a consumer asks for nodes.
- class curry.typecheck.builder.Description(interp, args, anchors=None, exprtype=None)[source]
Bases:
objectThe description of an expression: the spec tree of the arguments of
curry.expr, with the anchors of its keyword arguments and itsexprtype. It is typed when a consumer asks:curry.expr(description)orcurry.eval(description)build its node,typeof()gives its type, and each typing starts afresh. A description may be an argument of a larger one; its anchors travel with it, and a reference outside the description cannot name them.strprints it in Curry syntax.
- class curry.typecheck.builder.Group[source]
Bases:
SpecThe anchors of the keyword arguments followed by the expression. The type and the node of the group are those of the last item; the anchors are built first, so a reference to one of them finds its node.
- items
- class curry.typecheck.builder.Raw(payload, walk=False, typeexpr=None)[source]
Bases:
SpecA part the typed builder makes untyped. With
walkset, the payload is a Curry node typed by a walk of its content. Otherwise the payload is built by the untyped builder: thefailmarker, a list headed by an InfoTable, the application of a class dictionary (an_inst#symbol), or a boxed literal over an unboxed value; its type istypeexprwhen given, else a fresh variable.- typeexpr
- walk
- class curry.typecheck.builder.Ref(var)[source]
Bases:
SpecA reference to an anchor;
payloadis the variable of the anchor.
- class curry.typecheck.builder.TypeRecord[source]
Bases:
objectThe result types of the nodes
curry.exprreturned: the undefaulted scheme and the defaulted type. An entry is keyed by the identity of the node and held by a weak reference, so it goes when the node goes and is never lent to a node that took the same id later.
- class curry.typecheck.builder.TypedBuilder(interp, target=None)[source]
Bases:
objectBuilds one expression: converts the arguments of
curry.exprto specs (specs()), types them (TypedProblem) and makes the nodes (materialize()).- count_freevar()[source]
Counts a free variable made outside an evaluation; see
RuntimeState.set_goal.
- dict_node(d)[source]
The node of a dictionary term: the instance function applied to the dictionaries of its context, a partial application with one missing argument. One node per distinct term within one expression.
- static is_dictionary(arg)[source]
Whether an argument is a class dictionary: the symbol of an instance function, a node of one, or a list that starts with one.
- materialize(problem)[source]
The node of a solved problem: a post-order walk with an explicit stack.
- property raw
- spec_of(arg)[source]
The spec of one argument and the children to convert, as triples of a value, a container and an index.
- specs(args, anchors=())[source]
The spec tree of the arguments of
curry.expr.anchorsare the keyword arguments, pairs of a name and a value; they come first in aGroup.
- string_node(text, target=None)[source]
The node of a Python string at the type
[Char]: on the Python backend one_biStringnode over the code points, which the step unfolds one character at a time; on the C++ backend the list the step of_biStringwould build, made natively in one call (Node.create_string). The empty string is[].
- class curry.typecheck.builder.TypedProblem(builder, root, exprtype=None)[source]
Bases:
ProblemThe engine’s problem with the specs of the builder: a value typed by a walk of its content, the wrappers, the references and the groups.
- class curry.typecheck.builder.Unboxed(payload, primitive=None)[source]
Bases:
SpecAn
unboxedmarker the problem refuses;payloadis the Python value. The payload of a primitive,[Int, unboxed(3)], is aRawpart instead (TypedBuilder._application()), so this spec stands alone, in a list or a tuple, or as an argument, where a node is expected (issue #107); or, withprimitiveset to'Int','Char'or'Float', it is a payload that does not fit that primitive, such as[Int, unboxed(2.5)]. A description prints the payload.- primitive
- class curry.typecheck.builder.Wrap(kind, extra=None)[source]
Bases:
SpecA node around one typed child. The kinds:
anchor(extrais the variable of the anchor, shared with its references),fwd,setgrd(extrais the set id),strict,nonstrictandbinding(extrais the pair, built untyped).- extra
- items
- kind
- curry.typecheck.builder.build(interp, args, anchors, exprtype=None, target=None)[source]
curry.expron the typed path. A bare node alone passes through untouched when no type is asked of it.
- curry.typecheck.builder.recorded(interp, node)[source]
The recorded scheme and type of a node, or None.
- curry.typecheck.builder.result_type(interp, node)[source]
The defaulted result type of a node
curry.exprbuilt, or None.
- curry.typecheck.builder.symbol_map(interp)[source]
A dict from the id of an info table to its symbol, over the loaded modules of an interpreter. The map is built again when a module was loaded or released since the last call.
- curry.typecheck.builder.typeof(interp, e, defaulted=False)[source]
The type of an expression in Curry syntax: the undefaulted scheme, what
:typeprints, or the defaulted type.eis a nodecurry.exprreturned (its recorded type) or any other Curry node (typed by its content), a symbol, aDescription, or any argument ofcurry.expr.