curry.backends.py.graph.indexing module
Code for indexing to subexpressions.
- curry.backends.py.graph.indexing.compress_fwd_chain(end)[source]
Compresses a chain of forward nodes.
- curry.backends.py.graph.indexing.logical_subexpr(root, path, update_fwd_nodes=True)[source]
Like subexpr, but assumes a logical path. That is, steps through forward nodes and set guards do not appear in the path.
- curry.backends.py.graph.indexing.realpath(root, path, update_fwd_nodes=True)[source]
Gets the real path from
rootto the subexpression along the logical pathpath. The real path is formed by skipping over forward nodes and set guards. These implicit steps are inserted into the path so that the result can be passed toindex. Optionally, forward nodes can be spliced out instead of added to the real path.- Parameters:
root – A Curry expression. Can be an instance of graph.Node or a built-in such as an
int,str, orfloat.path – A sequence of integers specifying the logical path to the intended subexpression.
update_fwd_nodes – When True, forward nodes are spliced out, where possible, and chains of forward nodes are short-cut to their end.
- Returns:
A
namedtuple(target, realpath, guards), wheretargetis the subexpression atroot[path];realpathis the actual path used to reach the target, including entries for any forward nodes or set guards skipped over; andguardsis a set containing the IDs for each guard crossed.
- curry.backends.py.graph.indexing.subexpr(root, path)[source]
Performs straightforward indexing into a Curry expression. Returns the subexpression at
root[path]. No special handling of any kind is performed. More specifically, neither forward nodes nor set guards are skipped, and boxed fundamental types can be indexed to find their unboxed contents.- Parameters:
root – The expression at which to begin indexing. This is usually an instance of
Node, though unboxed values are accepted if the path is empty.path – An integral number or sequence of such numbers specifying the path.
- Raises:
CurryTypeError –
rootis not a Curry expression.CurryIndexError – A path component is invalid.
- Returns:
The subexpression at
root[path].