curry.backends.py.graph.variable module
- class curry.backends.py.graph.variable.Variable(rts, root, target, realpath=None, guards=None)[source]
Bases:
objectRepresents an ordinary (non-free) Curry variable.
This objects tracks a root, target, path between them, and set guards crossed. It is the focal point when working with expressions in generated code. These objects help with accessing and head-normalizing subexpressions, getting case selectors, building replacement expressions, and rewriting.
- Variables:
root – The function-labeled redex root. Dominates the target expression.
target – The Curry expression referenced by this variable. Typically an inductive position of the root function.
realpath – The real path from
roottotarget.guards – A set containing the set guards crossed on the path from
roottotarget.rvalue – The value to use when this variable appears in a RHS replacement expression. Any guards crossed along the path from root to target are inserted before the target.
Example
The
Prelude.headfunction is defined as follows:head (a:as) = a
Here, both ‘a’ and ‘as’ are variables. In addition, for the purpose of finding redexes, the compiler generates variables for unnamed inductive positions, such as (:) in this example. This might be compiled to the following ICurry:
var $1 $1 <- $0[0] case $1 of Prelude.[] -> exempt Prelude.: _ _ -> var $2 $2 <- $1[0] return $2The generated Python code might use
Variableas follows:def step(rts, _0): # _0 = rts.variable(_0) # (1) _1 = None _1 = rts.variable(_0, 0) # (2) _1.hnf(typedef=ty_Nil) # (3) if _1.tag == 1: # (4) _0.rewrite(rts.Failure) # (5a) else: _2 = None _2 = rts.variable(_1, 0) _0.rewrite(rts.Fwd, _2) # (5b)
At (1), the root variable, _0, is constructed. This will serve as the base for other variables, and for rewriting. This is in fact taken care of by the system before calling the step function. At (2), the variable corresponding to _1 in ICurry or ‘:’ in the source code is defined. Step (3) head-normalizes the subexpression at _1. The tag is inspected at (4). At (5a,5b), the root is rewritten. When considering set functions, this step might need to insert set guards before _2.
- extend()[source]
Step over a forward node or set guard at the target position.
This might be needed, for instance, after a rewrite step that modifies the target.
- guards
- property info
- property is_boxed
- property is_root
- realpath
- root
- rts
- property rvalue
Returns the target with the appropriate set guards inserted.
- property successors
- property tag
- target
- property typedef
- property unboxed_value