|
definition: |
invokeFunction :: State -> [Task] -> State
invokeFunction _ [] = error "invokeFunction: empty tasks"
invokeFunction st (Task (CNode nid) stk fp : tsks) =
case lookupNode nid gr of
FuncNode f ns -> case bodyOf f (program st) of
IFuncBody blck ->
let ienv = [(0, nid)]
in st { tasks = Task (IBlockEnv blck ienv) stk fp : tsks }
IExternal en -> case en of
"normalForm" -> let nfarg = ns !! 0 in case lookupNode nfarg gr of
ConsNode c cargs ->
let argsenv = zip [1..] cargs
evalcargs = foldl (\xs x -> IFCall ("","$$!",0)
[xs, IFCall ("","normalForm",0)
[IVar (fst x)]])
(ICPCall ("",c,0) (length cargs) []) argsenv
(gr1,nexp) = extendGraph gr argsenv evalcargs
in st { graph = either (error "Internal error in normalForm")
(updateNode gr1 nid) nexp }
FreeNode -> -- Warning: this does not work of free variable will be
-- later instantiated!
st { graph = replaceNode gr nid nfarg
, tasks = Task (CNode nfarg) stk fp : tsks }
_ -> error "step: use of 'normalForm' without constructor argument"
_ -> st { graph = updateNode gr nid (evalExternal gr en ns) }
_ -> error "invokeFunction: no function node in control"
where gr = graph st
invokeFunction _ (Task (IBlockEnv _ _) _ _ : _) =
error "invokeFunction: no function node in control"
|
|
demand: |
argument 2 |
|
deterministic: |
deterministic operation |
|
documentation: |
This operation is used when the control of the first task contains a function node ready for execution, i.e., a possibly demanded argument has been evaluated. Then the control is replaced by the body of the function (or by the result of executing some external operation). |
|
failfree: |
<FAILING> |
|
indeterministic: |
referentially transparent operation |
|
infix: |
no fixity defined |
|
iotype: |
{({State},{:}) |-> {State} || (_,{:}) |-> _}
|
|
name: |
invokeFunction |
|
precedence: |
no precedence defined |
|
result-values: |
{State}
|
|
signature: |
State -> [Task] -> State |
|
solution-complete: |
operation might suspend on free variables |
|
terminating: |
possibly non-terminating |
|
totally-defined: |
possibly non-reducible on same data term |