{-# LANGUAGE LambdaCase #-}
module Language.Drasil.Code.ExternalLibrary (ExternalLibrary, Step(..),
FunctionInterface(..), Result(..), Argument(..), ArgumentInfo(..),
Parameter(..), ClassInfo(..), MethodInfo(..), FuncType(..), externalLib,
choiceSteps, choiceStep, mandatoryStep, mandatorySteps, callStep,
libFunction, libMethod, libFunctionWithResult, libMethodWithResult,
libConstructor, libConstructorMultiReqs, constructAndReturn, lockedArg,
lockedNamedArg, inlineArg, inlineNamedArg, preDefinedArg, preDefinedNamedArg,
functionArg, customObjArg, recordArg, lockedParam, unnamedParam, customClass,
implementation, constructorInfo, methodInfo, methodInfoNoReturn,
appendCurrSol, populateSolList, assignArrayIndex, assignSolFromObj,
initSolListFromArray, initSolListWithVal, solveAndPopulateWhile,
returnExprList, fixedReturn, fixedReturn', initSolWithVal
) where
import Language.Drasil (Space, HasSpace(typ))
import Language.Drasil.Chunk.Code (CodeVarChunk, CodeFuncChunk, codeName)
import Language.Drasil.Chunk.Parameter (ParameterChunk, pcAuto)
import Language.Drasil.Chunk.NamedArgument (NamedArgument)
import Language.Drasil.CodeExpr.Development
import Language.Drasil.CodeExpr
import Language.Drasil.Mod (FuncStmt(..), Description)
import Control.Lens ((^.))
import Data.List.NonEmpty (NonEmpty(..), fromList)
type Condition = CodeExpr
type Requires = String
type ExternalLibrary = [StepGroup]
type StepGroup = NonEmpty [Step]
data Step = Call FunctionInterface
| Loop (NonEmpty FunctionInterface) ([CodeExpr] -> Condition) (NonEmpty Step)
| Statement ([CodeVarChunk] -> [CodeExpr] -> FuncStmt)
data FunctionInterface = FI (NonEmpty Requires) FuncType CodeFuncChunk [Argument] (Maybe Result)
data Result = Assign CodeVarChunk | Return
data Argument = Arg (Maybe NamedArgument) ArgumentInfo
data ArgumentInfo =
LockedArg CodeExpr
| Basic Space (Maybe CodeVarChunk)
| Fn CodeFuncChunk [Parameter] Step
| Class [Requires] Description CodeVarChunk CodeFuncChunk ClassInfo
| Record (NonEmpty Requires) CodeFuncChunk CodeVarChunk [CodeVarChunk]
data Parameter = LockedParam ParameterChunk | NameableParam Space
data ClassInfo = Regular [MethodInfo] | Implements String [MethodInfo]
data MethodInfo = CI Description [Parameter] [Step]
| MI CodeFuncChunk Description [Parameter] (Maybe Description) (NonEmpty Step)
data FuncType = Function | Method CodeVarChunk | Constructor
externalLib :: [StepGroup] -> ExternalLibrary
externalLib :: [StepGroup] -> [StepGroup]
externalLib = [StepGroup] -> [StepGroup]
forall a. a -> a
id
choiceSteps :: [[Step]] -> StepGroup
choiceSteps :: [[Step]] -> StepGroup
choiceSteps [] = [Char] -> StepGroup
forall a. HasCallStack => [Char] -> a
error [Char]
"choiceSteps should be called with a non-empty list"
choiceSteps [[Step]]
sg = [[Step]] -> StepGroup
forall a. HasCallStack => [a] -> NonEmpty a
fromList [[Step]]
sg
choiceStep :: [Step] -> StepGroup
choiceStep :: [Step] -> StepGroup
choiceStep [] = [Char] -> StepGroup
forall a. HasCallStack => [Char] -> a
error [Char]
"choiceStep should be called with a non-empty list"
choiceStep [Step]
ss = [[Step]] -> StepGroup
forall a. HasCallStack => [a] -> NonEmpty a
fromList ([[Step]] -> StepGroup) -> [[Step]] -> StepGroup
forall a b. (a -> b) -> a -> b
$ (Step -> [Step]) -> [Step] -> [[Step]]
forall a b. (a -> b) -> [a] -> [b]
map (Step -> [Step] -> [Step]
forall a. a -> [a] -> [a]
: []) [Step]
ss
mandatoryStep :: Step -> StepGroup
mandatoryStep :: Step -> StepGroup
mandatoryStep Step
f = [Step
f] [Step] -> [[Step]] -> StepGroup
forall a. a -> [a] -> NonEmpty a
:| []
mandatorySteps :: [Step] -> StepGroup
mandatorySteps :: [Step] -> StepGroup
mandatorySteps [Step]
fs = [Step]
fs [Step] -> [[Step]] -> StepGroup
forall a. a -> [a] -> NonEmpty a
:| []
callStep :: FunctionInterface -> Step
callStep :: FunctionInterface -> Step
callStep = FunctionInterface -> Step
Call
loopStep :: [FunctionInterface] -> ([CodeExpr] -> Condition) -> [Step] -> Step
loopStep :: [FunctionInterface] -> ([CodeExpr] -> CodeExpr) -> [Step] -> Step
loopStep [] [CodeExpr] -> CodeExpr
_ [Step]
_ = [Char] -> Step
forall a. HasCallStack => [Char] -> a
error [Char]
"loopStep should be called with a non-empty list of FunctionInterface"
loopStep [FunctionInterface]
_ [CodeExpr] -> CodeExpr
_ [] = [Char] -> Step
forall a. HasCallStack => [Char] -> a
error [Char]
"loopStep should be called with a non-empty list of Step"
loopStep [FunctionInterface]
fis [CodeExpr] -> CodeExpr
c [Step]
ss = NonEmpty FunctionInterface
-> ([CodeExpr] -> CodeExpr) -> NonEmpty Step -> Step
Loop ([FunctionInterface] -> NonEmpty FunctionInterface
forall a. HasCallStack => [a] -> NonEmpty a
fromList [FunctionInterface]
fis) [CodeExpr] -> CodeExpr
c ([Step] -> NonEmpty Step
forall a. HasCallStack => [a] -> NonEmpty a
fromList [Step]
ss)
libFunction :: Requires -> CodeFuncChunk -> [Argument] -> FunctionInterface
libFunction :: [Char] -> CodeFuncChunk -> [Argument] -> FunctionInterface
libFunction [Char]
rq CodeFuncChunk
f [Argument]
ps = NonEmpty [Char]
-> FuncType
-> CodeFuncChunk
-> [Argument]
-> Maybe Result
-> FunctionInterface
FI ([Char]
rq [Char] -> [[Char]] -> NonEmpty [Char]
forall a. a -> [a] -> NonEmpty a
:| []) FuncType
Function CodeFuncChunk
f [Argument]
ps Maybe Result
forall a. Maybe a
Nothing
libMethod :: Requires -> CodeVarChunk -> CodeFuncChunk -> [Argument] ->
FunctionInterface
libMethod :: [Char]
-> CodeVarChunk -> CodeFuncChunk -> [Argument] -> FunctionInterface
libMethod [Char]
rq CodeVarChunk
o CodeFuncChunk
m [Argument]
ps = NonEmpty [Char]
-> FuncType
-> CodeFuncChunk
-> [Argument]
-> Maybe Result
-> FunctionInterface
FI ([Char]
rq [Char] -> [[Char]] -> NonEmpty [Char]
forall a. a -> [a] -> NonEmpty a
:| []) (CodeVarChunk -> FuncType
Method CodeVarChunk
o) CodeFuncChunk
m [Argument]
ps Maybe Result
forall a. Maybe a
Nothing
libFunctionWithResult :: Requires -> CodeFuncChunk -> [Argument] ->
CodeVarChunk -> FunctionInterface
libFunctionWithResult :: [Char]
-> CodeFuncChunk -> [Argument] -> CodeVarChunk -> FunctionInterface
libFunctionWithResult [Char]
rq CodeFuncChunk
f [Argument]
ps CodeVarChunk
r = NonEmpty [Char]
-> FuncType
-> CodeFuncChunk
-> [Argument]
-> Maybe Result
-> FunctionInterface
FI ([Char]
rq [Char] -> [[Char]] -> NonEmpty [Char]
forall a. a -> [a] -> NonEmpty a
:| []) FuncType
Function CodeFuncChunk
f [Argument]
ps (Result -> Maybe Result
forall a. a -> Maybe a
Just (Result -> Maybe Result) -> Result -> Maybe Result
forall a b. (a -> b) -> a -> b
$ CodeVarChunk -> Result
Assign CodeVarChunk
r)
libMethodWithResult :: Requires -> CodeVarChunk -> CodeFuncChunk -> [Argument]
-> CodeVarChunk -> FunctionInterface
libMethodWithResult :: [Char]
-> CodeVarChunk
-> CodeFuncChunk
-> [Argument]
-> CodeVarChunk
-> FunctionInterface
libMethodWithResult [Char]
rq CodeVarChunk
o CodeFuncChunk
m [Argument]
ps CodeVarChunk
r = NonEmpty [Char]
-> FuncType
-> CodeFuncChunk
-> [Argument]
-> Maybe Result
-> FunctionInterface
FI ([Char]
rq [Char] -> [[Char]] -> NonEmpty [Char]
forall a. a -> [a] -> NonEmpty a
:| []) (CodeVarChunk -> FuncType
Method CodeVarChunk
o) CodeFuncChunk
m [Argument]
ps (Result -> Maybe Result
forall a. a -> Maybe a
Just (Result -> Maybe Result) -> Result -> Maybe Result
forall a b. (a -> b) -> a -> b
$ CodeVarChunk -> Result
Assign CodeVarChunk
r)
libConstructor :: Requires -> CodeFuncChunk -> [Argument] -> CodeVarChunk ->
FunctionInterface
libConstructor :: [Char]
-> CodeFuncChunk -> [Argument] -> CodeVarChunk -> FunctionInterface
libConstructor [Char]
rq CodeFuncChunk
c [Argument]
as CodeVarChunk
r = NonEmpty [Char]
-> FuncType
-> CodeFuncChunk
-> [Argument]
-> Maybe Result
-> FunctionInterface
FI ([Char]
rq [Char] -> [[Char]] -> NonEmpty [Char]
forall a. a -> [a] -> NonEmpty a
:| []) FuncType
Constructor CodeFuncChunk
c [Argument]
as (Result -> Maybe Result
forall a. a -> Maybe a
Just (Result -> Maybe Result) -> Result -> Maybe Result
forall a b. (a -> b) -> a -> b
$ CodeVarChunk -> Result
Assign CodeVarChunk
r)
libConstructorMultiReqs :: [Requires] -> CodeFuncChunk -> [Argument] ->
CodeVarChunk -> FunctionInterface
libConstructorMultiReqs :: [[Char]]
-> CodeFuncChunk -> [Argument] -> CodeVarChunk -> FunctionInterface
libConstructorMultiReqs [] CodeFuncChunk
_ [Argument]
_ CodeVarChunk
_ = [Char] -> FunctionInterface
forall a. HasCallStack => [Char] -> a
error ([Char] -> FunctionInterface) -> [Char] -> FunctionInterface
forall a b. (a -> b) -> a -> b
$ [Char]
"libConstructorMultiReqs should" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
[Char]
" be called with a non-empty list of Requires"
libConstructorMultiReqs [[Char]]
rqs CodeFuncChunk
c [Argument]
as CodeVarChunk
r = NonEmpty [Char]
-> FuncType
-> CodeFuncChunk
-> [Argument]
-> Maybe Result
-> FunctionInterface
FI ([[Char]] -> NonEmpty [Char]
forall a. HasCallStack => [a] -> NonEmpty a
fromList [[Char]]
rqs) FuncType
Constructor CodeFuncChunk
c [Argument]
as
(Result -> Maybe Result
forall a. a -> Maybe a
Just (Result -> Maybe Result) -> Result -> Maybe Result
forall a b. (a -> b) -> a -> b
$ CodeVarChunk -> Result
Assign CodeVarChunk
r)
constructAndReturn :: Requires -> CodeFuncChunk -> [Argument] ->
FunctionInterface
constructAndReturn :: [Char] -> CodeFuncChunk -> [Argument] -> FunctionInterface
constructAndReturn [Char]
rq CodeFuncChunk
c [Argument]
as = NonEmpty [Char]
-> FuncType
-> CodeFuncChunk
-> [Argument]
-> Maybe Result
-> FunctionInterface
FI ([Char]
rq [Char] -> [[Char]] -> NonEmpty [Char]
forall a. a -> [a] -> NonEmpty a
:| []) FuncType
Constructor CodeFuncChunk
c [Argument]
as (Result -> Maybe Result
forall a. a -> Maybe a
Just Result
Return)
lockedArg :: CodeExpr -> Argument
lockedArg :: CodeExpr -> Argument
lockedArg = Maybe NamedArgument -> ArgumentInfo -> Argument
Arg Maybe NamedArgument
forall a. Maybe a
Nothing (ArgumentInfo -> Argument)
-> (CodeExpr -> ArgumentInfo) -> CodeExpr -> Argument
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CodeExpr -> ArgumentInfo
LockedArg
lockedNamedArg :: NamedArgument -> CodeExpr -> Argument
lockedNamedArg :: NamedArgument -> CodeExpr -> Argument
lockedNamedArg NamedArgument
n = Maybe NamedArgument -> ArgumentInfo -> Argument
Arg (NamedArgument -> Maybe NamedArgument
forall a. a -> Maybe a
Just NamedArgument
n) (ArgumentInfo -> Argument)
-> (CodeExpr -> ArgumentInfo) -> CodeExpr -> Argument
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CodeExpr -> ArgumentInfo
LockedArg
inlineArg :: Space -> Argument
inlineArg :: Space -> Argument
inlineArg Space
t = Maybe NamedArgument -> ArgumentInfo -> Argument
Arg Maybe NamedArgument
forall a. Maybe a
Nothing (ArgumentInfo -> Argument) -> ArgumentInfo -> Argument
forall a b. (a -> b) -> a -> b
$ Space -> Maybe CodeVarChunk -> ArgumentInfo
Basic Space
t Maybe CodeVarChunk
forall a. Maybe a
Nothing
inlineNamedArg :: NamedArgument -> Space -> Argument
inlineNamedArg :: NamedArgument -> Space -> Argument
inlineNamedArg NamedArgument
n Space
t = Maybe NamedArgument -> ArgumentInfo -> Argument
Arg (NamedArgument -> Maybe NamedArgument
forall a. a -> Maybe a
Just NamedArgument
n) (ArgumentInfo -> Argument) -> ArgumentInfo -> Argument
forall a b. (a -> b) -> a -> b
$ Space -> Maybe CodeVarChunk -> ArgumentInfo
Basic Space
t Maybe CodeVarChunk
forall a. Maybe a
Nothing
preDefinedArg :: CodeVarChunk -> Argument
preDefinedArg :: CodeVarChunk -> Argument
preDefinedArg CodeVarChunk
v = Maybe NamedArgument -> ArgumentInfo -> Argument
Arg Maybe NamedArgument
forall a. Maybe a
Nothing (ArgumentInfo -> Argument) -> ArgumentInfo -> Argument
forall a b. (a -> b) -> a -> b
$ Space -> Maybe CodeVarChunk -> ArgumentInfo
Basic (CodeVarChunk
v CodeVarChunk -> Getting Space CodeVarChunk Space -> Space
forall s a. s -> Getting a s a -> a
^. Getting Space CodeVarChunk Space
forall c. HasSpace c => Getter c Space
Getter CodeVarChunk Space
typ) (CodeVarChunk -> Maybe CodeVarChunk
forall a. a -> Maybe a
Just CodeVarChunk
v)
preDefinedNamedArg :: NamedArgument -> CodeVarChunk -> Argument
preDefinedNamedArg :: NamedArgument -> CodeVarChunk -> Argument
preDefinedNamedArg NamedArgument
n CodeVarChunk
v = Maybe NamedArgument -> ArgumentInfo -> Argument
Arg (NamedArgument -> Maybe NamedArgument
forall a. a -> Maybe a
Just NamedArgument
n) (ArgumentInfo -> Argument) -> ArgumentInfo -> Argument
forall a b. (a -> b) -> a -> b
$ Space -> Maybe CodeVarChunk -> ArgumentInfo
Basic (CodeVarChunk
v CodeVarChunk -> Getting Space CodeVarChunk Space -> Space
forall s a. s -> Getting a s a -> a
^. Getting Space CodeVarChunk Space
forall c. HasSpace c => Getter c Space
Getter CodeVarChunk Space
typ) (CodeVarChunk -> Maybe CodeVarChunk
forall a. a -> Maybe a
Just CodeVarChunk
v)
functionArg :: CodeFuncChunk -> [Parameter] -> Step -> Argument
functionArg :: CodeFuncChunk -> [Parameter] -> Step -> Argument
functionArg CodeFuncChunk
f [Parameter]
ps Step
b = Maybe NamedArgument -> ArgumentInfo -> Argument
Arg Maybe NamedArgument
forall a. Maybe a
Nothing (CodeFuncChunk -> [Parameter] -> Step -> ArgumentInfo
Fn CodeFuncChunk
f [Parameter]
ps Step
b)
customObjArg :: [Requires] -> Description -> CodeVarChunk -> CodeFuncChunk ->
ClassInfo -> Argument
customObjArg :: [[Char]]
-> [Char] -> CodeVarChunk -> CodeFuncChunk -> ClassInfo -> Argument
customObjArg [[Char]]
rs [Char]
d CodeVarChunk
o CodeFuncChunk
c ClassInfo
ci = Maybe NamedArgument -> ArgumentInfo -> Argument
Arg Maybe NamedArgument
forall a. Maybe a
Nothing ([[Char]]
-> [Char]
-> CodeVarChunk
-> CodeFuncChunk
-> ClassInfo
-> ArgumentInfo
Class [[Char]]
rs [Char]
d CodeVarChunk
o CodeFuncChunk
c ClassInfo
ci)
recordArg :: Requires -> CodeFuncChunk -> CodeVarChunk -> [CodeVarChunk] ->
Argument
recordArg :: [Char]
-> CodeFuncChunk -> CodeVarChunk -> [CodeVarChunk] -> Argument
recordArg [Char]
rq CodeFuncChunk
c CodeVarChunk
o [CodeVarChunk]
fs = Maybe NamedArgument -> ArgumentInfo -> Argument
Arg Maybe NamedArgument
forall a. Maybe a
Nothing (NonEmpty [Char]
-> CodeFuncChunk -> CodeVarChunk -> [CodeVarChunk] -> ArgumentInfo
Record ([Char]
rq [Char] -> [[Char]] -> NonEmpty [Char]
forall a. a -> [a] -> NonEmpty a
:| []) CodeFuncChunk
c CodeVarChunk
o [CodeVarChunk]
fs)
lockedParam :: CodeVarChunk -> Parameter
lockedParam :: CodeVarChunk -> Parameter
lockedParam = ParameterChunk -> Parameter
LockedParam (ParameterChunk -> Parameter)
-> (CodeVarChunk -> ParameterChunk) -> CodeVarChunk -> Parameter
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CodeVarChunk -> ParameterChunk
forall c. CodeIdea c => c -> ParameterChunk
pcAuto
unnamedParam :: Space -> Parameter
unnamedParam :: Space -> Parameter
unnamedParam = Space -> Parameter
NameableParam
customClass :: [MethodInfo] -> ClassInfo
customClass :: [MethodInfo] -> ClassInfo
customClass = [MethodInfo] -> ClassInfo
Regular
implementation :: String -> [MethodInfo] -> ClassInfo
implementation :: [Char] -> [MethodInfo] -> ClassInfo
implementation = [Char] -> [MethodInfo] -> ClassInfo
Implements
constructorInfo :: CodeFuncChunk -> [Parameter] -> [Step] -> MethodInfo
constructorInfo :: CodeFuncChunk -> [Parameter] -> [Step] -> MethodInfo
constructorInfo CodeFuncChunk
c = [Char] -> [Parameter] -> [Step] -> MethodInfo
CI ([Char]
"Constructor for " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ CodeFuncChunk -> [Char]
forall c. CodeIdea c => c -> [Char]
codeName CodeFuncChunk
c [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" objects")
methodInfo :: CodeFuncChunk -> Description -> [Parameter] -> Description ->
[Step] -> MethodInfo
methodInfo :: CodeFuncChunk
-> [Char] -> [Parameter] -> [Char] -> [Step] -> MethodInfo
methodInfo CodeFuncChunk
_ [Char]
_ [Parameter]
_ [Char]
_ [] = [Char] -> MethodInfo
forall a. HasCallStack => [Char] -> a
error [Char]
"methodInfo should be called with a non-empty list of Step"
methodInfo CodeFuncChunk
m [Char]
d [Parameter]
ps [Char]
rd [Step]
ss = CodeFuncChunk
-> [Char]
-> [Parameter]
-> Maybe [Char]
-> NonEmpty Step
-> MethodInfo
MI CodeFuncChunk
m [Char]
d [Parameter]
ps ([Char] -> Maybe [Char]
forall a. a -> Maybe a
Just [Char]
rd) ([Step] -> NonEmpty Step
forall a. HasCallStack => [a] -> NonEmpty a
fromList [Step]
ss)
methodInfoNoReturn :: CodeFuncChunk -> Description -> [Parameter] -> [Step] ->
MethodInfo
methodInfoNoReturn :: CodeFuncChunk -> [Char] -> [Parameter] -> [Step] -> MethodInfo
methodInfoNoReturn CodeFuncChunk
_ [Char]
_ [Parameter]
_ [] = [Char] -> MethodInfo
forall a. HasCallStack => [Char] -> a
error [Char]
"methodInfoNoReturn should be called with a non-empty list of Step"
methodInfoNoReturn CodeFuncChunk
m [Char]
d [Parameter]
ps [Step]
ss = CodeFuncChunk
-> [Char]
-> [Parameter]
-> Maybe [Char]
-> NonEmpty Step
-> MethodInfo
MI CodeFuncChunk
m [Char]
d [Parameter]
ps Maybe [Char]
forall a. Maybe a
Nothing ([Step] -> NonEmpty Step
forall a. HasCallStack => [a] -> NonEmpty a
fromList [Step]
ss)
appendCurrSol :: CodeExpr -> Step
appendCurrSol :: CodeExpr -> Step
appendCurrSol CodeExpr
curr = ([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
statementStep (\[CodeVarChunk]
cdchs [CodeExpr]
es -> case ([CodeVarChunk]
cdchs, [CodeExpr]
es) of
([CodeVarChunk
s], []) -> CodeExpr -> CodeVarChunk -> FuncStmt
appendCurrSolFS CodeExpr
curr CodeVarChunk
s
([CodeVarChunk]
_,[CodeExpr]
_) -> [Char] -> FuncStmt
forall a. HasCallStack => [Char] -> a
error [Char]
"Fill for appendCurrSol should provide one CodeChunk and no Exprs")
populateSolList :: CodeVarChunk -> CodeVarChunk -> CodeVarChunk -> [Step]
populateSolList :: CodeVarChunk -> CodeVarChunk -> CodeVarChunk -> [Step]
populateSolList CodeVarChunk
arr CodeVarChunk
el CodeVarChunk
fld = [([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
statementStep (\[CodeVarChunk]
cdchs [CodeExpr]
es -> case ([CodeVarChunk]
cdchs, [CodeExpr]
es) of
([CodeVarChunk
s], []) -> CodeVarChunk -> CodeExpr -> FuncStmt
FAsg CodeVarChunk
s ([[CodeExpr]] -> CodeExpr
Matrix [[]])
([CodeVarChunk]
_,[CodeExpr]
_) -> [Char] -> FuncStmt
forall a. HasCallStack => [Char] -> a
error [Char]
popErr),
([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
statementStep (\[CodeVarChunk]
cdchs [CodeExpr]
es -> case ([CodeVarChunk]
cdchs, [CodeExpr]
es) of
([CodeVarChunk
s], []) -> CodeVarChunk -> CodeExpr -> [FuncStmt] -> FuncStmt
FForEach CodeVarChunk
el (CodeVarChunk -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy CodeVarChunk
arr) [CodeExpr -> CodeVarChunk -> FuncStmt
appendCurrSolFS (CodeVarChunk -> CodeVarChunk -> CodeExpr
forall r. CodeExprC r => CodeVarChunk -> CodeVarChunk -> r
field CodeVarChunk
el CodeVarChunk
fld) CodeVarChunk
s]
([CodeVarChunk]
_,[CodeExpr]
_) -> [Char] -> FuncStmt
forall a. HasCallStack => [Char] -> a
error [Char]
popErr)]
where popErr :: [Char]
popErr = [Char]
"Fill for populateSolList should provide one CodeChunk and no Exprs"
assignArrayIndex :: Step
assignArrayIndex :: Step
assignArrayIndex = ([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
statementStep (\[CodeVarChunk]
cdchs [CodeExpr]
es -> case ([CodeVarChunk]
cdchs, [CodeExpr]
es) of
([CodeVarChunk
a],[CodeExpr]
vs) -> [FuncStmt] -> FuncStmt
FMulti ([FuncStmt] -> FuncStmt) -> [FuncStmt] -> FuncStmt
forall a b. (a -> b) -> a -> b
$ (Integer -> CodeExpr -> FuncStmt)
-> [Integer] -> [CodeExpr] -> [FuncStmt]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (CodeVarChunk -> Integer -> CodeExpr -> FuncStmt
FAsgIndex CodeVarChunk
a) [Integer
0..] [CodeExpr]
vs
([CodeVarChunk]
_,[CodeExpr]
_) -> [Char] -> FuncStmt
forall a. HasCallStack => [Char] -> a
error [Char]
"Fill for assignArrayIndex should provide one CodeChunk")
assignSolFromObj :: CodeVarChunk -> Step
assignSolFromObj :: CodeVarChunk -> Step
assignSolFromObj CodeVarChunk
o = ([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
statementStep (\[CodeVarChunk]
cdchs [CodeExpr]
es -> case ([CodeVarChunk]
cdchs, [CodeExpr]
es) of
([CodeVarChunk
s],[]) -> CodeVarChunk -> CodeExpr -> FuncStmt
FAsg CodeVarChunk
s (CodeVarChunk -> CodeVarChunk -> CodeExpr
forall r. CodeExprC r => CodeVarChunk -> CodeVarChunk -> r
field CodeVarChunk
o CodeVarChunk
s)
([CodeVarChunk]
_,[CodeExpr]
_) -> [Char] -> FuncStmt
forall a. HasCallStack => [Char] -> a
error [Char]
"Fill for assignSolFromObj should provide one CodeChunk and no Exprs")
initSolListFromArray :: CodeVarChunk -> Step
initSolListFromArray :: CodeVarChunk -> Step
initSolListFromArray CodeVarChunk
a = ([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
statementStep (\[CodeVarChunk]
cdchs [CodeExpr]
es -> case ([CodeVarChunk]
cdchs, [CodeExpr]
es) of
([CodeVarChunk
s],[]) -> CodeVarChunk -> CodeExpr -> FuncStmt
FAsg CodeVarChunk
s ([[CodeExpr]] -> CodeExpr
forall r. ExprC r => [[r]] -> r
matrix [[CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
idx (CodeVarChunk -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy CodeVarChunk
a) (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
0)]])
([CodeVarChunk]
_,[CodeExpr]
_) -> [Char] -> FuncStmt
forall a. HasCallStack => [Char] -> a
error [Char]
"Fill for initSolListFromArray should provide one CodeChunk and no Exprs")
initSolListWithVal :: Step
initSolListWithVal :: Step
initSolListWithVal = ([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
statementStep (\[CodeVarChunk]
cdchs [CodeExpr]
es -> case ([CodeVarChunk]
cdchs, [CodeExpr]
es) of
([CodeVarChunk
s],[CodeExpr
v]) -> CodeVarChunk -> CodeExpr -> FuncStmt
FDecDef CodeVarChunk
s ([[CodeExpr]] -> CodeExpr
forall r. ExprC r => [[r]] -> r
matrix [[CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
idx CodeExpr
v (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
0)]])
([CodeVarChunk]
_,[CodeExpr]
_) -> [Char] -> FuncStmt
forall a. HasCallStack => [Char] -> a
error [Char]
"Fill for initSolListWithVal should provide one CodeChunk and one Expr")
solveAndPopulateWhile :: FunctionInterface -> CodeVarChunk -> CodeVarChunk ->
FunctionInterface -> CodeVarChunk -> Step
solveAndPopulateWhile :: FunctionInterface
-> CodeVarChunk
-> CodeVarChunk
-> FunctionInterface
-> CodeVarChunk
-> Step
solveAndPopulateWhile FunctionInterface
lc CodeVarChunk
ob CodeVarChunk
iv FunctionInterface
slv CodeVarChunk
popArr = [FunctionInterface] -> ([CodeExpr] -> CodeExpr) -> [Step] -> Step
loopStep [FunctionInterface
lc] (\case
[CodeExpr
ub] -> CodeVarChunk -> CodeVarChunk -> CodeExpr
forall r. CodeExprC r => CodeVarChunk -> CodeVarChunk -> r
field CodeVarChunk
ob CodeVarChunk
iv CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$< CodeExpr
ub
[CodeExpr]
_ -> [Char] -> CodeExpr
forall a. HasCallStack => [Char] -> a
error [Char]
"Fill for solveAndPopulateWhile should provide one Expr")
[FunctionInterface -> Step
callStep FunctionInterface
slv, CodeExpr -> Step
appendCurrSol (CodeVarChunk -> CodeVarChunk -> CodeExpr
forall r. CodeExprC r => CodeVarChunk -> CodeVarChunk -> r
field CodeVarChunk
ob CodeVarChunk
popArr)]
returnExprList :: Step
returnExprList :: Step
returnExprList = ([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
statementStep (\[CodeVarChunk]
cdchs [CodeExpr]
es -> case ([CodeVarChunk]
cdchs, [CodeExpr]
es) of
([], [CodeExpr]
_) -> CodeExpr -> FuncStmt
FRet (CodeExpr -> FuncStmt) -> CodeExpr -> FuncStmt
forall a b. (a -> b) -> a -> b
$ [[CodeExpr]] -> CodeExpr
Matrix [[CodeExpr]
es]
([CodeVarChunk]
_,[CodeExpr]
_) -> [Char] -> FuncStmt
forall a. HasCallStack => [Char] -> a
error [Char]
"Fill for returnExprList should provide no CodeChunks")
appendCurrSolFS :: CodeExpr -> CodeVarChunk -> FuncStmt
appendCurrSolFS :: CodeExpr -> CodeVarChunk -> FuncStmt
appendCurrSolFS CodeExpr
cs CodeVarChunk
s = CodeExpr -> CodeExpr -> FuncStmt
FAppend (CodeVarChunk -> CodeExpr
forall c. (HasUID c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy CodeVarChunk
s) (CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
idx CodeExpr
cs (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
0))
fixedReturn :: CodeExpr -> Step
fixedReturn :: CodeExpr -> Step
fixedReturn = FuncStmt -> Step
lockedStatement (FuncStmt -> Step) -> (CodeExpr -> FuncStmt) -> CodeExpr -> Step
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CodeExpr -> FuncStmt
FRet
fixedReturn' :: Step
fixedReturn' :: Step
fixedReturn' = ([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
statementStep [CodeVarChunk] -> [CodeExpr] -> FuncStmt
forall {a}. [a] -> [CodeExpr] -> FuncStmt
go
where
go :: [a] -> [CodeExpr] -> FuncStmt
go [] [CodeExpr
e] = CodeExpr -> FuncStmt
FRet CodeExpr
e
go [a]
_ [CodeExpr
_] = [Char] -> FuncStmt
forall a. HasCallStack => [Char] -> a
error [Char]
"Fill for fixReturn' should provide no CodeChunk."
go [a]
_ [CodeExpr]
_ = [Char] -> FuncStmt
forall a. HasCallStack => [Char] -> a
error [Char]
"fixedReturn' does not yet handle multiple values."
statementStep :: ([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
statementStep :: ([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
statementStep = ([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
Statement
lockedStatement :: FuncStmt -> Step
lockedStatement :: FuncStmt -> Step
lockedStatement FuncStmt
s = ([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
Statement (\[CodeVarChunk]
_ [CodeExpr]
_ -> FuncStmt
s)
initSolWithVal :: Step
initSolWithVal :: Step
initSolWithVal = ([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
statementStep (\[CodeVarChunk]
cdchs [CodeExpr]
es -> case ([CodeVarChunk]
cdchs, [CodeExpr]
es) of
([CodeVarChunk
s],[CodeExpr
v]) -> CodeVarChunk -> CodeExpr -> FuncStmt
FDecDef CodeVarChunk
s CodeExpr
v
([CodeVarChunk]
_,[CodeExpr]
_) -> [Char] -> FuncStmt
forall a. HasCallStack => [Char] -> a
error [Char]
"Fill for initSolWithVal should provide one CodeChunk and one Expr")