{-# LANGUAGE TypeFamilies #-}
module Drasil.GProc.LanguageRenderer.MatlabRenderer (
MatlabCode(..), mlName, mlVersion
) where
import Drasil.Shared.InterfaceCommon (Label, Value, Variable, getCodeType,
UnRepr(..), Body, Block, BodySym(..), BlockSym(..), TypeSym(..), TypeElim(..),
VariableSym(..), VariableElim(..), ValueSym(..), Argument(..), Literal(..),
MathConstant(..), VariableValue(..), CommandLineArgs(..),
NumericExpression(..), BooleanExpression(..), Comparison(..),
ValueExpression(..), IndexTranslator(..), Reference(..), Array(..), List(..),
ListStatement(..), Set(..), NativeVector(..), InternalList(..),
EmptyStatement(..), MultiStatement(..), ValueStatement(..),
AssignStatement(..), DeclStatement(..), PrintConsole(..), ReadConsole(..),
FileHandling(..), PrintFile(..), ReadFile(..), StringStatement(..),
FuncAppStatement(..), CommentStatement(..), ControlStatement(..), switchAsIf,
VisibilitySym(..), ScopeSym(..), ParameterSym(..), BinderSym(..),
BinderElim(..), MethodSym(..), funcApp, (&=), bodyStatements)
import Drasil.GProc.InterfaceProc (ProcProg, ProgramSym(..),
FileSym(..), ModuleSym(..))
import Drasil.Shared.RendererClassesCommon (CommonRenderSym, ImportSym(..),
RenderBody(..), BodyElim, RenderBlock(..), BlockElim, RenderType(..),
UnaryOpSym(..), BinaryOpSym(..), OpElim(uOpPrec, bOpPrec), RenderVariable(..),
InternalVarElim(variableBind), RenderValue(..), ValueElim(..),
InternalListFunc(..), RenderFunction(..), FunctionElim(functionType),
InternalAssignStmt(..), InternalIOStmt(..), InternalControlStmt(..),
RenderStatement(..), StatementElim(statementTerm), RenderVisibility(..),
VisibilityElim, MethodTypeSym(..), RenderParam(..),
ParamElim(parameterName, parameterType), RenderMethod(..), MethodElim,
BlockCommentSym(..), BlockCommentElim, ScopeElim(..), InternalBinderElim(..))
import qualified Drasil.Shared.RendererClassesCommon as RC (body, block, uOp,
bOp, variable, value, function, statement, visibility, parameter, method,
blockComment')
import Drasil.GProc.RendererClassesProc (ProcRenderSym, RenderFile(..),
RenderMod(..), ModuleElim, ProcRenderMethod(..))
import qualified Drasil.GProc.LanguageRenderer.AbstractProc as A (fileDoc,
docMod, fileFromData, modFromData, function, funcDecDef,
innerType)
import qualified Drasil.Shared.LanguageRenderer as R (commentedMod,
commentedItem, parameterList, body, addComments, multiStmt, sqrt, abs, log10,
log, exp, sin, cos, tan, asin, acos, atan, floor, ceil, break, continue)
import qualified Drasil.GProc.RendererClassesProc as RC (module')
import qualified Drasil.Shared.LanguageRenderer.LanguagePolymorphic as G (
comment, param, docFunc, var, multiBody, block, multiBlock, stmt, loopStmt,
negateOp, plusOp, minusOp, multOp, divideOp, equalOp, greaterOp,
greaterEqualOp, lessOp, lessEqualOp, csc, sec, cot, valueOf, litChar,
litDouble, litInt, litString, valStmt, emptyStmt, assign,
funcAppMixedArgs, call, print, ifCond, tryCatch, listAccess, smartAdd)
import qualified Drasil.Shared.LanguageRenderer.CommonPseudoOO as CP (mainBody,
functionDoc, docInOutFunc', inOutCall, multiAssign, intToIndex', indexToInt',
listDecDef, litSet)
import qualified Drasil.Shared.LanguageRenderer.CLike as C (andOp, orOp, litTrue,
litFalse, while)
import qualified Drasil.Shared.LanguageRenderer.Common as CS (varDecDef,
funcType, listSize, forEach')
import qualified Drasil.Shared.LanguageRenderer.Macros as M (ifExists,
increment1, decrement1, listSlice, stringListVals, stringListLists)
import Drasil.Shared.AST (Terminator(..), FileType(Combined), fileD, md,
updateMod, MethodData, mthd, mthdName, updateMthd, ParamData, paramVar,
paramDoc, pd, ProgData, TypeData, cType, vd, val, valPrec, valInt, valType,
opDoc, opPrec, varName, varType, varBind, varDoc, vard, progD, mthdDoc, modDoc,
FuncData(fType, funcDoc), fd, ScopeData, FileData, ModData, BinderD, Statement)
import Drasil.Shared.CodeType (CodeType(..))
import Drasil.Shared.LanguageRenderer.Constructors (typeFromData, unOpPrec,
powerPrec, multPrec, unExpr, unExpr', binExpr, binExpr', mkStateVal, mkVal,
mkStateVar, mkStmtNoEnd, compEqualPrec, typeUnExpr, typeBinExpr)
import Drasil.Shared.LanguageRenderer (listSep', valueList, intValue)
import Drasil.Shared.LanguageRenderer.LanguagePolymorphic (OptionalSpace(..))
import Drasil.Shared.Helpers (toCode, toState, onCodeValue, onStateValue,
onCodeList, onStateList, on2CodeValues, on2StateValues, emptyIfEmpty, vibcat)
import Drasil.Shared.State (MS, VS, FS, lensGStoFS, lensFStoMS, lensMStoVS,
revFiles, setFileType, setModuleName, getMainDoc)
import Control.Lens.Zoom (zoom)
import Control.Monad.State (modify)
import Drasil.FileHandling.Legacy (indent)
import Prelude hiding (break,print,sin,cos,tan,floor,(<>))
import qualified Prelude as P ((<>))
import Text.PrettyPrint.HughesPJ (Doc, empty, isEmpty, text, (<>), (<+>), vcat,
hcat, parens, brackets, braces, equals, quotes, punctuate, render)
newtype MatlabCode a = MLC {forall a. MatlabCode a -> a
unMLC :: a} deriving (forall a b. (a -> b) -> MatlabCode a -> MatlabCode b)
-> (forall a b. a -> MatlabCode b -> MatlabCode a)
-> Functor MatlabCode
forall a b. a -> MatlabCode b -> MatlabCode a
forall a b. (a -> b) -> MatlabCode a -> MatlabCode b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> MatlabCode a -> MatlabCode b
fmap :: forall a b. (a -> b) -> MatlabCode a -> MatlabCode b
$c<$ :: forall a b. a -> MatlabCode b -> MatlabCode a
<$ :: forall a b. a -> MatlabCode b -> MatlabCode a
Functor
instance Applicative MatlabCode where
pure :: forall a. a -> MatlabCode a
pure = a -> MatlabCode a
forall a. a -> MatlabCode a
MLC
(MLC a -> b
f) <*> :: forall a b. MatlabCode (a -> b) -> MatlabCode a -> MatlabCode b
<*> (MLC a
x) = b -> MatlabCode b
forall a. a -> MatlabCode a
MLC (a -> b
f a
x)
instance Monad MatlabCode where
MLC a
x >>= :: forall a b. MatlabCode a -> (a -> MatlabCode b) -> MatlabCode b
>>= a -> MatlabCode b
f = a -> MatlabCode b
f a
x
instance ProcProg MatlabCode ProgData FileData ModData MethodData Doc ParamData Body Block Statement Variable ScopeData Value BinderD TypeData
instance ProgramSym MatlabCode ProgData FileData where
prog :: String
-> String
-> [FS (MatlabCode FileData)]
-> GSProgram MatlabCode ProgData
prog String
n String
st [FS (MatlabCode FileData)]
files = do
fs <- (FS (MatlabCode FileData)
-> StateT GOOLState Identity (MatlabCode FileData))
-> [FS (MatlabCode FileData)]
-> StateT GOOLState Identity [MatlabCode FileData]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (LensLike'
(Zoomed (StateT FileState Identity) (MatlabCode FileData))
GOOLState
FileState
-> FS (MatlabCode FileData)
-> StateT GOOLState Identity (MatlabCode FileData)
forall c.
LensLike'
(Zoomed (StateT FileState Identity) c) GOOLState FileState
-> StateT FileState Identity c -> StateT GOOLState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT FileState Identity) (MatlabCode FileData))
GOOLState
FileState
(FileState -> Focusing Identity (MatlabCode FileData) FileState)
-> GOOLState -> Focusing Identity (MatlabCode FileData) GOOLState
Lens' GOOLState FileState
lensGStoFS) [FS (MatlabCode FileData)]
files
modify revFiles
pure $ onCodeList (progD n st) fs
instance CommonRenderSym MatlabCode MethodData Doc ParamData Body Block Statement Variable ScopeData Value BinderD TypeData
instance ProcRenderSym MatlabCode FileData ModData MethodData Doc ParamData Body Block Statement Variable ScopeData Value BinderD TypeData
instance UnRepr MatlabCode inner where
unRepr :: MatlabCode inner -> inner
unRepr = MatlabCode inner -> inner
forall a. MatlabCode a -> a
unMLC
instance FileSym MatlabCode FileData ModData where
fileDoc :: FS (MatlabCode ModData) -> FS (MatlabCode FileData)
fileDoc FS (MatlabCode ModData)
m = do
(FileState -> FileState) -> StateT FileState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (FileType -> FileState -> FileState
setFileType FileType
Combined)
String -> FS (MatlabCode ModData) -> FS (MatlabCode FileData)
forall (r :: * -> *) file mod.
RenderFile r file mod =>
String -> FS (r mod) -> FS (r file)
A.fileDoc String
mlExt FS (MatlabCode ModData)
m
docMod :: String
-> String
-> [String]
-> String
-> FS (MatlabCode FileData)
-> FS (MatlabCode FileData)
docMod = String
-> String
-> String
-> [String]
-> String
-> FS (MatlabCode FileData)
-> FS (MatlabCode FileData)
forall (r :: * -> *) file mod.
(BlockCommentSym r, RenderFile r file mod) =>
String
-> String
-> String
-> [String]
-> String
-> FS (r file)
-> FS (r file)
A.docMod String
mlExt
instance RenderFile MatlabCode FileData ModData where
top :: MatlabCode ModData -> MatlabCode Body
top MatlabCode ModData
_ = Body -> MatlabCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode Body
empty
bottom :: MatlabCode Body
bottom = Body -> MatlabCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode Body
empty
commentedMod :: FS (MatlabCode FileData)
-> FS (MatlabCode Body) -> FS (MatlabCode FileData)
commentedMod = (MatlabCode FileData -> MatlabCode Body -> MatlabCode FileData)
-> FS (MatlabCode FileData)
-> FS (MatlabCode Body)
-> FS (MatlabCode FileData)
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues ((FileData -> Body -> FileData)
-> MatlabCode FileData -> MatlabCode Body -> MatlabCode FileData
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues FileData -> Body -> FileData
R.commentedMod)
fileFromData :: String -> FS (MatlabCode ModData) -> FS (MatlabCode FileData)
fileFromData = (String -> MatlabCode ModData -> MatlabCode FileData)
-> String -> FS (MatlabCode ModData) -> FS (MatlabCode FileData)
forall {k} (r :: k -> *) (mod :: k) (file :: k).
ModuleElim r mod =>
(String -> r mod -> r file) -> String -> FS (r mod) -> FS (r file)
A.fileFromData ((ModData -> FileData) -> MatlabCode ModData -> MatlabCode FileData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ((ModData -> FileData)
-> MatlabCode ModData -> MatlabCode FileData)
-> (String -> ModData -> FileData)
-> String
-> MatlabCode ModData
-> MatlabCode FileData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ModData -> FileData
fileD)
instance ImportSym MatlabCode where
langImport :: String -> MatlabCode Body
langImport = String -> MatlabCode Body
forall a. HasCallStack => a
undefined
modImport :: String -> MatlabCode Body
modImport = String -> MatlabCode Body
forall a. HasCallStack => a
undefined
instance BodySym MatlabCode Body Block where
body :: [MS (MatlabCode Body)] -> MS (MatlabCode Body)
body = ([MatlabCode Body] -> MatlabCode Body)
-> [MS (MatlabCode Body)] -> MS (MatlabCode Body)
forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList (([Body] -> Body) -> [MatlabCode Body] -> MatlabCode Body
forall (m :: * -> *) a b. Monad m => ([a] -> b) -> [m a] -> m b
onCodeList [Body] -> Body
R.body)
addComments :: String -> MS (MatlabCode Body) -> MS (MatlabCode Body)
addComments String
s = (MatlabCode Body -> MatlabCode Body)
-> MS (MatlabCode Body) -> MS (MatlabCode Body)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue ((Body -> Body) -> MatlabCode Body -> MatlabCode Body
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue (String -> Body -> Body -> Body
R.addComments String
s Body
mlCmtStart))
instance RenderBody MatlabCode Body where
multiBody :: [MS (MatlabCode Body)] -> MS (MatlabCode Body)
multiBody = [MS (MatlabCode Body)] -> MS (MatlabCode Body)
forall (r :: * -> *) bod.
(BodyElim r bod, Monad r) =>
[MS (r bod)] -> MS (r Body)
G.multiBody
instance BodyElim MatlabCode Body where
body :: MatlabCode Body -> Body
body = MatlabCode Body -> Body
forall a. MatlabCode a -> a
unMLC
instance BlockSym MatlabCode Block Statement where
block :: [MS (MatlabCode Statement)] -> MS (MatlabCode Body)
block = [MS (MatlabCode Statement)] -> MS (MatlabCode Body)
forall (r :: * -> *) stmt.
(Monad r, RenderStatement r stmt, StatementElim r stmt) =>
[MS (r stmt)] -> MS (r Body)
G.block
instance RenderBlock MatlabCode Block where
multiBlock :: [MS (MatlabCode Body)] -> MS (MatlabCode Body)
multiBlock = [MS (MatlabCode Body)] -> MS (MatlabCode Body)
forall (r :: * -> *) block.
(BlockElim r block, Monad r) =>
[MS (r block)] -> MS (r Body)
G.multiBlock
instance BlockElim MatlabCode Block where
block :: MatlabCode Body -> Body
block = MatlabCode Body -> Body
forall a. MatlabCode a -> a
unMLC
instance TypeSym MatlabCode TypeData where
bool :: VS (MatlabCode TypeData)
bool = CodeType -> String -> VS (MatlabCode TypeData)
mlTy CodeType
Boolean String
"logical"
int :: VS (MatlabCode TypeData)
int = CodeType -> String -> VS (MatlabCode TypeData)
mlTy CodeType
Integer String
"int"
float :: VS (MatlabCode TypeData)
float = CodeType -> String -> VS (MatlabCode TypeData)
mlTy CodeType
Float String
"double"
double :: VS (MatlabCode TypeData)
double = CodeType -> String -> VS (MatlabCode TypeData)
mlTy CodeType
Double String
"double"
char :: VS (MatlabCode TypeData)
char = CodeType -> String -> VS (MatlabCode TypeData)
mlTy CodeType
Char String
"char"
string :: VS (MatlabCode TypeData)
string = CodeType -> String -> VS (MatlabCode TypeData)
mlTy CodeType
String String
"string"
infile :: VS (MatlabCode TypeData)
infile = CodeType -> String -> VS (MatlabCode TypeData)
mlTy CodeType
InFile String
"file"
outfile :: VS (MatlabCode TypeData)
outfile = CodeType -> String -> VS (MatlabCode TypeData)
mlTy CodeType
OutFile String
"file"
referenceType :: VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
referenceType = VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
forall a. a -> a
id
listType :: VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
listType = VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
mlListType
setType :: VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
setType = VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k).
TypeSym r typ =>
VS (r typ) -> VS (r typ)
listType
arrayType :: VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
arrayType = VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k).
TypeSym r typ =>
VS (r typ) -> VS (r typ)
listType
innerType :: VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
innerType = VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k).
(TypeSym r typ, TypeElim r typ) =>
VS (r typ) -> VS (r typ)
A.innerType
funcType :: [VS (MatlabCode TypeData)]
-> VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
funcType = [VS (MatlabCode TypeData)]
-> VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
forall (r :: * -> *).
(Monad r, TypeElim r TypeData) =>
[VS (r TypeData)] -> VS (r TypeData) -> VS (r TypeData)
CS.funcType
void :: VS (MatlabCode TypeData)
void = CodeType -> String -> VS (MatlabCode TypeData)
mlTy CodeType
Void String
"void"
instance TypeElim MatlabCode TypeData where
getCodeType :: MatlabCode TypeData -> CodeType
getCodeType = TypeData -> CodeType
cType (TypeData -> CodeType)
-> (MatlabCode TypeData -> TypeData)
-> MatlabCode TypeData
-> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode TypeData -> TypeData
forall a. MatlabCode a -> a
unMLC
instance RenderType MatlabCode TypeData where
multiType :: [VS (MatlabCode TypeData)] -> VS (MatlabCode TypeData)
multiType = [VS (MatlabCode TypeData)] -> VS (MatlabCode TypeData)
forall a. HasCallStack => a
undefined
instance UnaryOpSym MatlabCode where
notOp :: VSUnOp MatlabCode
notOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
"~"
negateOp :: VSUnOp MatlabCode
negateOp = VSUnOp MatlabCode
forall (r :: * -> *). Monad r => VSOp r
G.negateOp
sqrtOp :: VSUnOp MatlabCode
sqrtOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
R.sqrt
absOp :: VSUnOp MatlabCode
absOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
R.abs
logOp :: VSUnOp MatlabCode
logOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
R.log10
lnOp :: VSUnOp MatlabCode
lnOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
R.log
expOp :: VSUnOp MatlabCode
expOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
R.exp
sinOp :: VSUnOp MatlabCode
sinOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
R.sin
cosOp :: VSUnOp MatlabCode
cosOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
R.cos
tanOp :: VSUnOp MatlabCode
tanOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
R.tan
asinOp :: VSUnOp MatlabCode
asinOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
R.asin
acosOp :: VSUnOp MatlabCode
acosOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
R.acos
atanOp :: VSUnOp MatlabCode
atanOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
R.atan
floorOp :: VSUnOp MatlabCode
floorOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
R.floor
ceilOp :: VSUnOp MatlabCode
ceilOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
R.ceil
instance BinaryOpSym MatlabCode where
equalOp :: VSUnOp MatlabCode
equalOp = VSUnOp MatlabCode
forall (r :: * -> *). Monad r => VSOp r
G.equalOp
notEqualOp :: VSUnOp MatlabCode
notEqualOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
compEqualPrec String
"~="
greaterOp :: VSUnOp MatlabCode
greaterOp = VSUnOp MatlabCode
forall (r :: * -> *). Monad r => VSOp r
G.greaterOp
greaterEqualOp :: VSUnOp MatlabCode
greaterEqualOp = VSUnOp MatlabCode
forall (r :: * -> *). Monad r => VSOp r
G.greaterEqualOp
lessOp :: VSUnOp MatlabCode
lessOp = VSUnOp MatlabCode
forall (r :: * -> *). Monad r => VSOp r
G.lessOp
lessEqualOp :: VSUnOp MatlabCode
lessEqualOp = VSUnOp MatlabCode
forall (r :: * -> *). Monad r => VSOp r
G.lessEqualOp
plusOp :: VSUnOp MatlabCode
plusOp = VSUnOp MatlabCode
forall (r :: * -> *). Monad r => VSOp r
G.plusOp
minusOp :: VSUnOp MatlabCode
minusOp = VSUnOp MatlabCode
forall (r :: * -> *). Monad r => VSOp r
G.minusOp
multOp :: VSUnOp MatlabCode
multOp = VSUnOp MatlabCode
forall (r :: * -> *). Monad r => VSOp r
G.multOp
divideOp :: VSUnOp MatlabCode
divideOp = VSUnOp MatlabCode
forall (r :: * -> *). Monad r => VSOp r
G.divideOp
powerOp :: VSUnOp MatlabCode
powerOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
powerPrec String
"^"
moduloOp :: VSUnOp MatlabCode
moduloOp = String -> VSUnOp MatlabCode
forall (r :: * -> *). Monad r => String -> VSOp r
multPrec String
"mod"
andOp :: VSUnOp MatlabCode
andOp = VSUnOp MatlabCode
forall (r :: * -> *). Monad r => VSOp r
C.andOp
orOp :: VSUnOp MatlabCode
orOp = VSUnOp MatlabCode
forall (r :: * -> *). Monad r => VSOp r
C.orOp
instance OpElim MatlabCode where
uOp :: MatlabCode OpData -> Body
uOp = OpData -> Body
opDoc (OpData -> Body)
-> (MatlabCode OpData -> OpData) -> MatlabCode OpData -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode OpData -> OpData
forall a. MatlabCode a -> a
unMLC
bOp :: MatlabCode OpData -> Body
bOp = OpData -> Body
opDoc (OpData -> Body)
-> (MatlabCode OpData -> OpData) -> MatlabCode OpData -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode OpData -> OpData
forall a. MatlabCode a -> a
unMLC
uOpPrec :: MatlabCode OpData -> Int
uOpPrec = OpData -> Int
opPrec (OpData -> Int)
-> (MatlabCode OpData -> OpData) -> MatlabCode OpData -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode OpData -> OpData
forall a. MatlabCode a -> a
unMLC
bOpPrec :: MatlabCode OpData -> Int
bOpPrec = OpData -> Int
opPrec (OpData -> Int)
-> (MatlabCode OpData -> OpData) -> MatlabCode OpData -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode OpData -> OpData
forall a. MatlabCode a -> a
unMLC
instance ScopeSym MatlabCode ScopeData where
global :: MatlabCode ScopeData
global = MatlabCode ScopeData
forall a. HasCallStack => a
undefined
mainFn :: MatlabCode ScopeData
mainFn = MatlabCode ScopeData
forall a. HasCallStack => a
undefined
local :: MatlabCode ScopeData
local = MatlabCode ScopeData
forall a. HasCallStack => a
undefined
instance ScopeElim MatlabCode ScopeData where
scopeData :: MatlabCode ScopeData -> ScopeData
scopeData = MatlabCode ScopeData -> ScopeData
forall a. MatlabCode a -> a
unMLC
instance VariableSym MatlabCode Variable TypeData where
var :: String -> VS (MatlabCode TypeData) -> VS (MatlabCode Variable)
var = String -> VS (MatlabCode TypeData) -> VS (MatlabCode Variable)
forall {k} (r :: k -> *) (var :: k) (typ :: k).
RenderVariable r var typ =>
String -> VS (r typ) -> VS (r var)
G.var
constant :: String -> VS (MatlabCode TypeData) -> VS (MatlabCode Variable)
constant = String -> VS (MatlabCode TypeData) -> VS (MatlabCode Variable)
forall {k} (r :: k -> *) (var :: k) (typ :: k).
VariableSym r var typ =>
String -> VS (r typ) -> VS (r var)
var
extVar :: String
-> String -> VS (MatlabCode TypeData) -> VS (MatlabCode Variable)
extVar = String
-> String -> VS (MatlabCode TypeData) -> VS (MatlabCode Variable)
forall a. HasCallStack => a
undefined
instance VariableElim MatlabCode Variable TypeData where
variableName :: MatlabCode Variable -> String
variableName = Variable -> String
varName (Variable -> String)
-> (MatlabCode Variable -> Variable)
-> MatlabCode Variable
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode Variable -> Variable
forall a. MatlabCode a -> a
unMLC
variableType :: MatlabCode Variable -> MatlabCode TypeData
variableType = (Variable -> TypeData)
-> MatlabCode Variable -> MatlabCode TypeData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue Variable -> TypeData
varType
instance InternalVarElim MatlabCode Variable where
variableBind :: MatlabCode Variable -> AttachmentTag
variableBind = Variable -> AttachmentTag
varBind (Variable -> AttachmentTag)
-> (MatlabCode Variable -> Variable)
-> MatlabCode Variable
-> AttachmentTag
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode Variable -> Variable
forall a. MatlabCode a -> a
unMLC
variable :: MatlabCode Variable -> Body
variable = Variable -> Body
varDoc (Variable -> Body)
-> (MatlabCode Variable -> Variable) -> MatlabCode Variable -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode Variable -> Variable
forall a. MatlabCode a -> a
unMLC
instance RenderVariable MatlabCode Variable TypeData where
varFromData :: AttachmentTag
-> String
-> VS (MatlabCode TypeData)
-> Body
-> VS (MatlabCode Variable)
varFromData AttachmentTag
b String
n VS (MatlabCode TypeData)
t' Body
d = do
t <- VS (MatlabCode TypeData)
t'
toState $ on2CodeValues (vard b n) t (toCode d)
instance ValueSym MatlabCode Value TypeData where
valueType :: MatlabCode Value -> MatlabCode TypeData
valueType MatlabCode Value
v = Value -> TypeData
valType (Value -> TypeData) -> MatlabCode Value -> MatlabCode TypeData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
<$> MatlabCode Value
v
instance Argument MatlabCode Value where
pointerArg :: VS (MatlabCode Value) -> VS (MatlabCode Value)
pointerArg = VS (MatlabCode Value) -> VS (MatlabCode Value)
forall a. a -> a
id
instance Literal MatlabCode Value TypeData where
litTrue :: VS (MatlabCode Value)
litTrue = VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, TypeSym r typ) =>
VS (r val)
C.litTrue
litFalse :: VS (MatlabCode Value)
litFalse = VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, TypeSym r typ) =>
VS (r val)
C.litFalse
litChar :: Char -> VS (MatlabCode Value)
litChar = (Body -> Body) -> Char -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, TypeSym r typ) =>
(Body -> Body) -> Char -> VS (r val)
G.litChar Body -> Body
quotes
litDouble :: Double -> VS (MatlabCode Value)
litDouble = Double -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, TypeSym r typ) =>
Double -> VS (r val)
G.litDouble
litFloat :: Float -> VS (MatlabCode Value)
litFloat Float
f = VS (MatlabCode TypeData) -> Body -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r typ) -> Body -> VS (r val)
mkStateVal VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
float (String -> Body
text (String -> Body) -> String -> Body
forall a b. (a -> b) -> a -> b
$ Double -> String
forall a. Show a => a -> String
show (Float -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac Float
f :: Double))
litInt :: Integer -> VS (MatlabCode Value)
litInt = Integer -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, TypeSym r typ) =>
Integer -> VS (r val)
G.litInt
litString :: String -> VS (MatlabCode Value)
litString = String -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, TypeSym r typ) =>
String -> VS (r val)
G.litString
litArray :: VS (MatlabCode TypeData)
-> [VS (MatlabCode Value)] -> VS (MatlabCode Value)
litArray = VS (MatlabCode TypeData)
-> [VS (MatlabCode Value)] -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
VS (r typ) -> [VS (r val)] -> VS (r val)
litList
litList :: VS (MatlabCode TypeData)
-> [VS (MatlabCode Value)] -> VS (MatlabCode Value)
litList = VS (MatlabCode TypeData)
-> [VS (MatlabCode Value)] -> VS (MatlabCode Value)
mlLitList
litSet :: VS (MatlabCode TypeData)
-> [VS (MatlabCode Value)] -> VS (MatlabCode Value)
litSet = (Body -> Body)
-> (Body -> Body)
-> VS (MatlabCode TypeData)
-> [VS (MatlabCode Value)]
-> VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, TypeSym r typ, ValueElim r val) =>
(Body -> Body)
-> (Body -> Body) -> VS (r typ) -> [VS (r val)] -> VS (r val)
CP.litSet Body -> Body
forall a. a -> a
id Body -> Body
brackets
instance MathConstant MatlabCode Value where
pi :: VS (MatlabCode Value)
pi = VS (MatlabCode TypeData) -> Body -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r typ) -> Body -> VS (r val)
mkStateVal VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
double (String -> Body
text String
"pi")
instance VariableValue MatlabCode Variable Value where
valueOf :: VS (MatlabCode Variable) -> VS (MatlabCode Value)
valueOf = VS (MatlabCode Variable) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(InternalVarElim r var, RenderValue r var val typ,
VariableElim r var typ) =>
VS (r var) -> VS (r val)
G.valueOf
instance CommandLineArgs MatlabCode Value where
arg :: Integer -> VS (MatlabCode Value)
arg Integer
n = VS (MatlabCode Value) -> VS (MatlabCode Value)
mlArg (Integer -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
Integer -> VS (r val)
litInt (Integer
n Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
1))
argsList :: VS (MatlabCode Value)
argsList = VS (MatlabCode TypeData) -> Body -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r typ) -> Body -> VS (r val)
mkStateVal (VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k).
TypeSym r typ =>
VS (r typ) -> VS (r typ)
arrayType VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
string) (String -> Body
text String
"varargin")
argExists :: Integer -> VS (MatlabCode Value)
argExists = Integer -> VS (MatlabCode Value)
forall a. HasCallStack => a
undefined
instance NumericExpression MatlabCode Value where
#~ :: VS (MatlabCode Value) -> VS (MatlabCode Value)
(#~) = VSUnOp MatlabCode -> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr' VSUnOp MatlabCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
negateOp
#/^ :: VS (MatlabCode Value) -> VS (MatlabCode Value)
(#/^) = VSUnOp MatlabCode -> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp MatlabCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
sqrtOp
#| :: VS (MatlabCode Value) -> VS (MatlabCode Value)
(#|) = VSUnOp MatlabCode -> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp MatlabCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
absOp
#+ :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
(#+) = VSUnOp MatlabCode
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, TypeElim r typ,
ValueElim r val, ValueSym r val typ) =>
VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
binExpr VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
plusOp
#- :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
(#-) = VSUnOp MatlabCode
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, TypeElim r typ,
ValueElim r val, ValueSym r val typ) =>
VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
binExpr VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
minusOp
#* :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
(#*) = VSUnOp MatlabCode
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, TypeElim r typ,
ValueElim r val, ValueSym r val typ) =>
VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
binExpr VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
multOp
#/ :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
(#/) = VSUnOp MatlabCode
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, TypeElim r typ,
ValueElim r val, ValueSym r val typ) =>
VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
binExpr VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
divideOp
#% :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
(#%) = VSUnOp MatlabCode
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, TypeElim r typ,
ValueElim r val, ValueSym r val typ) =>
VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
binExpr' VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
moduloOp
#^ :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
(#^) = VSUnOp MatlabCode
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, TypeElim r typ,
ValueElim r val, ValueSym r val typ) =>
VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
binExpr VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
powerOp
log :: VS (MatlabCode Value) -> VS (MatlabCode Value)
log = VSUnOp MatlabCode -> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp MatlabCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
logOp
ln :: VS (MatlabCode Value) -> VS (MatlabCode Value)
ln = VSUnOp MatlabCode -> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp MatlabCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
lnOp
exp :: VS (MatlabCode Value) -> VS (MatlabCode Value)
exp = VSUnOp MatlabCode -> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp MatlabCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
expOp
sin :: VS (MatlabCode Value) -> VS (MatlabCode Value)
sin = VSUnOp MatlabCode -> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp MatlabCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
sinOp
cos :: VS (MatlabCode Value) -> VS (MatlabCode Value)
cos = VSUnOp MatlabCode -> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp MatlabCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
cosOp
tan :: VS (MatlabCode Value) -> VS (MatlabCode Value)
tan = VSUnOp MatlabCode -> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp MatlabCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
tanOp
csc :: VS (MatlabCode Value) -> VS (MatlabCode Value)
csc = VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
(ValueSym r val typ, Literal r val typ, NumericExpression r val,
TypeElim r typ) =>
VS (r val) -> VS (r val)
G.csc
sec :: VS (MatlabCode Value) -> VS (MatlabCode Value)
sec = VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
(ValueSym r val typ, Literal r val typ, NumericExpression r val,
TypeElim r typ) =>
VS (r val) -> VS (r val)
G.sec
cot :: VS (MatlabCode Value) -> VS (MatlabCode Value)
cot = VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
(ValueSym r val typ, Literal r val typ, NumericExpression r val,
TypeElim r typ) =>
VS (r val) -> VS (r val)
G.cot
arcsin :: VS (MatlabCode Value) -> VS (MatlabCode Value)
arcsin = VSUnOp MatlabCode -> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp MatlabCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
asinOp
arccos :: VS (MatlabCode Value) -> VS (MatlabCode Value)
arccos = VSUnOp MatlabCode -> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp MatlabCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
acosOp
arctan :: VS (MatlabCode Value) -> VS (MatlabCode Value)
arctan = VSUnOp MatlabCode -> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp MatlabCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
atanOp
floor :: VS (MatlabCode Value) -> VS (MatlabCode Value)
floor = VSUnOp MatlabCode -> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp MatlabCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
floorOp
ceil :: VS (MatlabCode Value) -> VS (MatlabCode Value)
ceil = VSUnOp MatlabCode -> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp MatlabCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
ceilOp
instance BooleanExpression MatlabCode Value where
?! :: VS (MatlabCode Value) -> VS (MatlabCode Value)
(?!) = VSUnOp MatlabCode
-> VS (MatlabCode TypeData)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSUnOp r -> VS (r typ) -> VS (r val) -> VS (r val)
typeUnExpr VSUnOp MatlabCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
notOp VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool
?&& :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
(?&&) = VSUnOp MatlabCode
-> VS (MatlabCode TypeData)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
andOp VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool
?|| :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
(?||) = VSUnOp MatlabCode
-> VS (MatlabCode TypeData)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
orOp VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool
instance Comparison MatlabCode Value where
?< :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
(?<) = VSUnOp MatlabCode
-> VS (MatlabCode TypeData)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
lessOp VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool
?<= :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
(?<=) = VSUnOp MatlabCode
-> VS (MatlabCode TypeData)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
lessEqualOp VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool
?> :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
(?>) = VSUnOp MatlabCode
-> VS (MatlabCode TypeData)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
greaterOp VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool
?>= :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
(?>=) = VSUnOp MatlabCode
-> VS (MatlabCode TypeData)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
greaterEqualOp VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool
?== :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
(?==) = Bool
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
mlEqOp Bool
False
?!= :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
(?!=) = Bool
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
mlEqOp Bool
True
instance ValueExpression MatlabCode Variable Value BinderD TypeData where
inlineIf :: VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
inlineIf = VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
mlInlineIf
funcAppMixedArgs :: MixedCall MatlabCode Variable Value TypeData
funcAppMixedArgs = MixedCall MatlabCode Variable Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
MixedCall r var val typ
G.funcAppMixedArgs
extFuncAppMixedArgs :: String -> MixedCall MatlabCode Variable Value TypeData
extFuncAppMixedArgs String
_ = MixedCall MatlabCode Variable Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
MixedCall r var val typ
G.funcAppMixedArgs
libFuncAppMixedArgs :: String -> MixedCall MatlabCode Variable Value TypeData
libFuncAppMixedArgs String
_ = MixedCall MatlabCode Variable Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
MixedCall r var val typ
G.funcAppMixedArgs
lambda :: [VS (MatlabCode BinderD)]
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
lambda = [VS (MatlabCode BinderD)]
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall a. HasCallStack => a
undefined
notNull :: VS (MatlabCode Value) -> VS (MatlabCode Value)
notNull VS (MatlabCode Value)
v = VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k).
BooleanExpression r val =>
VS (r val) -> VS (r val)
(?!) (VS (MatlabCode Value) -> VS (MatlabCode Value))
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall a b. (a -> b) -> a -> b
$ PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"isempty" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool [VS (MatlabCode Value)
v]
instance RenderValue MatlabCode Variable Value TypeData where
inputFunc :: VS (MatlabCode Value)
inputFunc = PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"input" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
string [String -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString String
"", String -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString String
"s"]
printFunc :: VS (MatlabCode Value)
printFunc = VS (MatlabCode Value)
mlPrintFunc
printLnFunc :: VS (MatlabCode Value)
printLnFunc = VS (MatlabCode Value)
mlPrintFunc
printFileFunc :: VS (MatlabCode Value) -> VS (MatlabCode Value)
printFileFunc VS (MatlabCode Value)
_ = VS (MatlabCode Value)
mlPrintFunc
printFileLnFunc :: VS (MatlabCode Value) -> VS (MatlabCode Value)
printFileLnFunc VS (MatlabCode Value)
_ = VS (MatlabCode Value)
mlPrintFunc
cast :: VS (MatlabCode TypeData)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
cast = VS (MatlabCode TypeData)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
mlCast
call :: Maybe String
-> Maybe Body -> MixedCall MatlabCode Variable Value TypeData
call = Body
-> Maybe String
-> Maybe Body
-> MixedCall MatlabCode Variable Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(InternalVarElim r var, RenderValue r var val typ,
ValueElim r val) =>
Body -> Maybe String -> Maybe Body -> MixedCall r var val typ
G.call Body
equals
valFromData :: Maybe Int
-> Maybe Integer
-> VS (MatlabCode TypeData)
-> Body
-> VS (MatlabCode Value)
valFromData Maybe Int
p Maybe Integer
i VS (MatlabCode TypeData)
t' Body
d = do
t <- VS (MatlabCode TypeData)
t'
toState $ on2CodeValues (vd p i) t (toCode d)
instance ValueElim MatlabCode Value where
valuePrec :: MatlabCode Value -> Maybe Int
valuePrec = Value -> Maybe Int
valPrec (Value -> Maybe Int)
-> (MatlabCode Value -> Value) -> MatlabCode Value -> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode Value -> Value
forall a. MatlabCode a -> a
unMLC
valueInt :: MatlabCode Value -> Maybe Integer
valueInt = Value -> Maybe Integer
valInt (Value -> Maybe Integer)
-> (MatlabCode Value -> Value) -> MatlabCode Value -> Maybe Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode Value -> Value
forall a. MatlabCode a -> a
unMLC
value :: MatlabCode Value -> Body
value = Value -> Body
val (Value -> Body)
-> (MatlabCode Value -> Value) -> MatlabCode Value -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode Value -> Value
forall a. MatlabCode a -> a
unMLC
instance IndexTranslator MatlabCode Value where
intToIndex :: VS (MatlabCode Value) -> VS (MatlabCode Value)
intToIndex = VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (typ :: k) (val :: k) (var :: k).
(TypeSym r typ, Literal r val typ, NumericExpression r val,
RenderValue r var val typ, ValueElim r val) =>
VS (r val) -> VS (r val)
CP.intToIndex'
indexToInt :: VS (MatlabCode Value) -> VS (MatlabCode Value)
indexToInt = VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (typ :: k) (val :: k) (var :: k).
(TypeSym r typ, Literal r val typ, NumericExpression r val,
RenderValue r var val typ, ValueElim r val) =>
VS (r val) -> VS (r val)
CP.indexToInt'
instance Reference MatlabCode Value where
makeRef :: VS (MatlabCode Value) -> VS (MatlabCode Value)
makeRef = VS (MatlabCode Value) -> VS (MatlabCode Value)
forall a. a -> a
id
maybeDeref :: VS (MatlabCode Value) -> VS (MatlabCode Value)
maybeDeref = VS (MatlabCode Value) -> VS (MatlabCode Value)
forall a. a -> a
id
instance Array MatlabCode Variable Value where
arrayElem :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Variable)
arrayElem = VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Variable)
mlArrayElem
arrayLength :: VS (MatlabCode Value) -> VS (MatlabCode Value)
arrayLength = VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k).
List r val =>
VS (r val) -> VS (r val)
listSize
arrayCopy :: VS (MatlabCode Value) -> VS (MatlabCode Value)
arrayCopy = VS (MatlabCode Value) -> VS (MatlabCode Value)
forall a. a -> a
id
instance List MatlabCode Value where
listSize :: VS (MatlabCode Value) -> VS (MatlabCode Value)
listSize = String -> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k)
(binder :: k).
(TypeSym r typ, ValueExpression r var val binder typ) =>
String -> VS (r val) -> VS (r val)
CS.listSize String
"length"
listAccess :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
listAccess = VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall (r :: * -> *) typ val var.
(TypeSym r typ, ValueSym r val typ, IndexTranslator r val,
InternalListFunc r val typ, FunctionElim r typ,
RenderFunction r typ, RenderValue r var val typ, TypeElim r typ,
ValueElim r val) =>
VS (r val) -> VS (r val) -> VS (r val)
G.listAccess
indexOf :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
indexOf VS (MatlabCode Value)
lst VS (MatlabCode Value)
v = PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"find" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
int [VS (MatlabCode Value)
lst VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k).
Comparison r val =>
VS (r val) -> VS (r val) -> VS (r val)
?== VS (MatlabCode Value)
v, Integer -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
Integer -> VS (r val)
litInt Integer
1] VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k).
NumericExpression r val =>
VS (r val) -> VS (r val) -> VS (r val)
#- Integer -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
Integer -> VS (r val)
litInt Integer
1
instance ListStatement MatlabCode Statement Value where
listAdd :: VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
listAdd = VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
mlListAdd
listAppend :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
listAppend VS (MatlabCode Value)
lst = VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
ListStatement r stmt val =>
VS (r val) -> VS (r val) -> VS (r val) -> MS (r stmt)
listSet VS (MatlabCode Value)
lst (VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k).
List r val =>
VS (r val) -> VS (r val)
listSize VS (MatlabCode Value)
lst)
listSet :: VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
listSet = VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
mlListSet
instance Set MatlabCode Value where
contains :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
contains VS (MatlabCode Value)
s VS (MatlabCode Value)
e = PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"ismember" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool [VS (MatlabCode Value)
e, VS (MatlabCode Value)
s]
setAdd :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
setAdd = VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall a. HasCallStack => a
undefined
setRemove :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
setRemove = VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall a. HasCallStack => a
undefined
setUnion :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
setUnion = VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall a. HasCallStack => a
undefined
instance NativeVector MatlabCode Value TypeData where
vecType :: VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
vecType = VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k).
TypeSym r typ =>
VS (r typ) -> VS (r typ)
listType
litVec :: VS (MatlabCode TypeData)
-> [VS (MatlabCode Value)] -> VS (MatlabCode Value)
litVec = VS (MatlabCode TypeData)
-> [VS (MatlabCode Value)] -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
VS (r typ) -> [VS (r val)] -> VS (r val)
litList
vecScale :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
vecScale = VSUnOp MatlabCode
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, TypeElim r typ,
ValueElim r val, ValueSym r val typ) =>
VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
binExpr VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
multOp
vecAdd :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
vecAdd = VSUnOp MatlabCode
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, TypeElim r typ,
ValueElim r val, ValueSym r val typ) =>
VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
binExpr VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
plusOp
vecIndex :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
vecIndex = VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
mlVecIndex
vecDot :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
vecDot VS (MatlabCode Value)
a VS (MatlabCode Value)
b = PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"dot" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
double [VS (MatlabCode Value)
a, VS (MatlabCode Value)
b]
vecMag :: VS (MatlabCode Value) -> VS (MatlabCode Value)
vecMag VS (MatlabCode Value)
a = PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"norm" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
double [VS (MatlabCode Value)
a]
vecUnit :: VS (MatlabCode Value) -> VS (MatlabCode Value)
vecUnit VS (MatlabCode Value)
a = VS (MatlabCode Value)
a VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k).
NumericExpression r val =>
VS (r val) -> VS (r val) -> VS (r val)
#/ VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
NativeVector r val typ =>
VS (r val) -> VS (r val)
vecMag VS (MatlabCode Value)
a
instance InternalList MatlabCode Block Variable Value where
listSlice' :: Maybe (VS (MatlabCode Value))
-> Maybe (VS (MatlabCode Value))
-> Maybe (VS (MatlabCode Value))
-> VS (MatlabCode Variable)
-> VS (MatlabCode Value)
-> MS (MatlabCode Body)
listSlice' = Maybe (VS (MatlabCode Value))
-> Maybe (VS (MatlabCode Value))
-> Maybe (VS (MatlabCode Value))
-> VS (MatlabCode Variable)
-> VS (MatlabCode Value)
-> MS (MatlabCode Body)
forall (r :: * -> *) bod block stmt var val typ binder.
(BodySym r bod block, BlockSym r block stmt, EmptyStatement r stmt,
ScopeSym r ScopeData, DeclStatement r bod stmt var ScopeData val,
AssignStatement r stmt var val,
ControlStatement r bod stmt var val, TypeSym r typ,
Literal r val typ, BooleanExpression r val, Comparison r val,
NumericExpression r val, ValueExpression r var val binder typ,
VariableSym r var typ, VariableValue r var val,
IndexTranslator r val, List r val, ListStatement r stmt val,
ValueElim r val, VariableElim r var typ) =>
Maybe (VS (r val))
-> Maybe (VS (r val))
-> Maybe (VS (r val))
-> VS (r var)
-> VS (r val)
-> MS (r block)
M.listSlice
instance InternalListFunc MatlabCode Value TypeData where
listAccessFunc :: VS (MatlabCode TypeData)
-> VS (MatlabCode Value) -> VS (MatlabCode FuncData)
listAccessFunc VS (MatlabCode TypeData)
t VS (MatlabCode Value)
v = do
t' <- VS (MatlabCode TypeData)
t
iv <- intValue v
funcFromData (mlListAccessFunc (cType (unMLC t')) iv) (pure t')
mlListAccessFunc :: CodeType -> MatlabCode Value -> Doc
mlListAccessFunc :: CodeType -> MatlabCode Value -> Body
mlListAccessFunc CodeType
ct MatlabCode Value
v = CodeType -> Body -> Body
mlCellWrap CodeType
ct (Body -> Body) -> Body -> Body
forall a b. (a -> b) -> a -> b
$ MatlabCode Value -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value MatlabCode Value
v
mlCellWrap :: CodeType -> Doc -> Doc
mlCellWrap :: CodeType -> Body -> Body
mlCellWrap CodeType
String = Body -> Body
braces
mlCellWrap CodeType
_ = Body -> Body
parens
instance BinderSym MatlabCode BinderD TypeData where
binder :: String -> VS (MatlabCode TypeData) -> VS (MatlabCode BinderD)
binder = String -> VS (MatlabCode TypeData) -> VS (MatlabCode BinderD)
forall a. HasCallStack => a
undefined
instance BinderElim MatlabCode BinderD TypeData where
binderName :: MatlabCode BinderD -> String
binderName = MatlabCode BinderD -> String
forall a. HasCallStack => a
undefined
binderType :: MatlabCode BinderD -> MatlabCode TypeData
binderType = MatlabCode BinderD -> MatlabCode TypeData
forall a. HasCallStack => a
undefined
instance InternalBinderElim MatlabCode BinderD where
binderElim :: MatlabCode BinderD -> Body
binderElim = MatlabCode BinderD -> Body
forall a. HasCallStack => a
undefined
instance RenderFunction MatlabCode TypeData where
funcFromData :: Body -> VS (MatlabCode TypeData) -> VS (MatlabCode FuncData)
funcFromData Body
d = (MatlabCode TypeData -> MatlabCode FuncData)
-> VS (MatlabCode TypeData) -> VS (MatlabCode FuncData)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue ((MatlabCode TypeData -> MatlabCode FuncData)
-> VS (MatlabCode TypeData) -> VS (MatlabCode FuncData))
-> (MatlabCode TypeData -> MatlabCode FuncData)
-> VS (MatlabCode TypeData)
-> VS (MatlabCode FuncData)
forall a b. (a -> b) -> a -> b
$ (TypeData -> FuncData)
-> MatlabCode TypeData -> MatlabCode FuncData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue (TypeData -> Body -> FuncData
`fd` Body
d)
instance FunctionElim MatlabCode TypeData where
functionType :: MatlabCode FuncData -> MatlabCode TypeData
functionType = (FuncData -> TypeData)
-> MatlabCode FuncData -> MatlabCode TypeData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue FuncData -> TypeData
fType
function :: MatlabCode FuncData -> Body
function = FuncData -> Body
funcDoc (FuncData -> Body)
-> (MatlabCode FuncData -> FuncData) -> MatlabCode FuncData -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode FuncData -> FuncData
forall a. MatlabCode a -> a
unMLC
instance InternalAssignStmt MatlabCode Statement Variable Value where
multiAssign :: [VS (MatlabCode Variable)]
-> [VS (MatlabCode Value)] -> MS (MatlabCode Statement)
multiAssign = (Body -> Body)
-> [VS (MatlabCode Variable)]
-> [VS (MatlabCode Value)]
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (typ :: k) (stmt :: k) (var :: k)
(val :: k).
(TypeSym r typ, AssignStatement r stmt var val,
InternalVarElim r var, RenderValue r var val typ,
RenderVariable r var typ, ValueElim r val) =>
(Body -> Body) -> [VS (r var)] -> [VS (r val)] -> MS (r stmt)
CP.multiAssign Body -> Body
brackets
instance InternalIOStmt MatlabCode Statement Value where
printSt :: Bool
-> Maybe (VS (MatlabCode Value))
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
printSt = Bool
-> Maybe (VS (MatlabCode Value))
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
mlPrint
instance InternalControlStmt MatlabCode Statement Value where
multiReturn :: [VS (MatlabCode Value)] -> MS (MatlabCode Statement)
multiReturn = [VS (MatlabCode Value)] -> MS (MatlabCode Statement)
forall a. HasCallStack => a
undefined
instance RenderStatement MatlabCode Statement where
stmt :: MS (MatlabCode Statement) -> MS (MatlabCode Statement)
stmt = MS (MatlabCode Statement) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k).
(RenderStatement r stmt, StatementElim r stmt) =>
MS (r stmt) -> MS (r stmt)
G.stmt
loopStmt :: MS (MatlabCode Statement) -> MS (MatlabCode Statement)
loopStmt = MS (MatlabCode Statement) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k).
(RenderStatement r stmt, StatementElim r stmt) =>
MS (r stmt) -> MS (r stmt)
G.loopStmt
stmtFromData :: Body -> Terminator -> MS (MatlabCode Statement)
stmtFromData Body
d Terminator
t = MatlabCode Statement -> MS (MatlabCode Statement)
forall a s. a -> State s a
toState (MatlabCode Statement -> MS (MatlabCode Statement))
-> MatlabCode Statement -> MS (MatlabCode Statement)
forall a b. (a -> b) -> a -> b
$ Statement -> MatlabCode Statement
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Body
d, Terminator
t)
instance StatementElim MatlabCode Statement where
statement :: MatlabCode Statement -> Body
statement = Statement -> Body
forall a b. (a, b) -> a
fst (Statement -> Body)
-> (MatlabCode Statement -> Statement)
-> MatlabCode Statement
-> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode Statement -> Statement
forall a. MatlabCode a -> a
unMLC
statementTerm :: MatlabCode Statement -> Terminator
statementTerm = Statement -> Terminator
forall a b. (a, b) -> b
snd (Statement -> Terminator)
-> (MatlabCode Statement -> Statement)
-> MatlabCode Statement
-> Terminator
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode Statement -> Statement
forall a. MatlabCode a -> a
unMLC
instance EmptyStatement MatlabCode Statement where
emptyStmt :: MS (MatlabCode Statement)
emptyStmt = MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k).
RenderStatement r stmt =>
MS (r stmt)
G.emptyStmt
instance MultiStatement MatlabCode Statement where
multi :: [MS (MatlabCode Statement)] -> MS (MatlabCode Statement)
multi = ([MatlabCode Statement] -> MatlabCode Statement)
-> [MS (MatlabCode Statement)] -> MS (MatlabCode Statement)
forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList (([Statement] -> Statement)
-> [MatlabCode Statement] -> MatlabCode Statement
forall (m :: * -> *) a b. Monad m => ([a] -> b) -> [m a] -> m b
onCodeList [Statement] -> Statement
R.multiStmt)
instance ValueStatement MatlabCode Statement Value where
valStmt :: VS (MatlabCode Value) -> MS (MatlabCode Statement)
valStmt = Terminator -> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
(RenderStatement r stmt, ValueElim r val) =>
Terminator -> VS (r val) -> MS (r stmt)
G.valStmt Terminator
Semi
instance AssignStatement MatlabCode Statement Variable Value where
assign :: VS (MatlabCode Variable)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
assign = Terminator
-> VS (MatlabCode Variable)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (var :: k) (stmt :: k) (val :: k).
(InternalVarElim r var, RenderStatement r stmt, ValueElim r val) =>
Terminator -> VS (r var) -> VS (r val) -> MS (r stmt)
G.assign Terminator
Semi
&-= :: VS (MatlabCode Variable)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
(&-=) VS (MatlabCode Variable)
vr VS (MatlabCode Value)
v = VS (MatlabCode Variable)
vr VS (MatlabCode Variable)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
AssignStatement r stmt var val =>
VS (r var) -> VS (r val) -> MS (r stmt)
&= (VS (MatlabCode Variable) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k).
VariableValue r var val =>
VS (r var) -> VS (r val)
valueOf VS (MatlabCode Variable)
vr VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k).
NumericExpression r val =>
VS (r val) -> VS (r val) -> VS (r val)
#- VS (MatlabCode Value)
v)
&+= :: VS (MatlabCode Variable)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
(&+=) VS (MatlabCode Variable)
vr VS (MatlabCode Value)
v = VS (MatlabCode Variable)
vr VS (MatlabCode Variable)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
AssignStatement r stmt var val =>
VS (r var) -> VS (r val) -> MS (r stmt)
&= VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (typ :: k) (val :: k) (var :: k).
(TypeSym r typ, NumericExpression r val, RenderValue r var val typ,
ValueElim r val) =>
VS (r val) -> VS (r val) -> VS (r val)
G.smartAdd (VS (MatlabCode Variable) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k).
VariableValue r var val =>
VS (r var) -> VS (r val)
valueOf VS (MatlabCode Variable)
vr) VS (MatlabCode Value)
v
&++ :: VS (MatlabCode Variable) -> MS (MatlabCode Statement)
(&++) = VS (MatlabCode Variable) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k)
(typ :: k).
(AssignStatement r stmt var val, Literal r val typ) =>
VS (r var) -> MS (r stmt)
M.increment1
&-- :: VS (MatlabCode Variable) -> MS (MatlabCode Statement)
(&--) = VS (MatlabCode Variable) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k)
(typ :: k).
(AssignStatement r stmt var val, Literal r val typ) =>
VS (r var) -> MS (r stmt)
M.decrement1
instance DeclStatement MatlabCode Body Statement Variable ScopeData Value where
varDec :: VS (MatlabCode Variable)
-> MatlabCode ScopeData -> MS (MatlabCode Statement)
varDec VS (MatlabCode Variable)
v MatlabCode ScopeData
scp = VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> Maybe (VS (MatlabCode Value))
-> MS (MatlabCode Statement)
forall (r :: * -> *) stmt var val typ.
(EmptyStatement r stmt, AssignStatement r stmt var val,
ScopeElim r ScopeData, VariableElim r var typ) =>
VS (r var) -> r ScopeData -> Maybe (VS (r val)) -> MS (r stmt)
CS.varDecDef VS (MatlabCode Variable)
v MatlabCode ScopeData
scp Maybe (VS (MatlabCode Value))
forall a. Maybe a
Nothing
varDecDef :: VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
varDecDef VS (MatlabCode Variable)
v MatlabCode ScopeData
scp VS (MatlabCode Value)
e = VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> Maybe (VS (MatlabCode Value))
-> MS (MatlabCode Statement)
forall (r :: * -> *) stmt var val typ.
(EmptyStatement r stmt, AssignStatement r stmt var val,
ScopeElim r ScopeData, VariableElim r var typ) =>
VS (r var) -> r ScopeData -> Maybe (VS (r val)) -> MS (r stmt)
CS.varDecDef VS (MatlabCode Variable)
v MatlabCode ScopeData
scp (VS (MatlabCode Value) -> Maybe (VS (MatlabCode Value))
forall a. a -> Maybe a
Just VS (MatlabCode Value)
e)
setDec :: VS (MatlabCode Variable)
-> MatlabCode ScopeData -> MS (MatlabCode Statement)
setDec = VS (MatlabCode Variable)
-> MatlabCode ScopeData -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
(scope :: k) (val :: k).
DeclStatement r bod stmt var scope val =>
VS (r var) -> r scope -> MS (r stmt)
varDec
setDecDef :: VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
setDecDef = VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
(scope :: k) (val :: k).
DeclStatement r bod stmt var scope val =>
VS (r var) -> r scope -> VS (r val) -> MS (r stmt)
varDecDef
listDec :: Integer
-> VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> MS (MatlabCode Statement)
listDec Integer
_ = VS (MatlabCode Variable)
-> MatlabCode ScopeData -> MS (MatlabCode Statement)
mlListDec
listDecDef :: VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> [VS (MatlabCode Value)]
-> MS (MatlabCode Statement)
listDecDef = VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> [VS (MatlabCode Value)]
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
(scope :: k) (val :: k) (typ :: k).
(DeclStatement r bod stmt var scope val, TypeSym r typ,
Literal r val typ, VariableElim r var typ) =>
VS (r var) -> r scope -> [VS (r val)] -> MS (r stmt)
CP.listDecDef
arrayDec :: Integer
-> VS (MatlabCode Value)
-> VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> MS (MatlabCode Statement)
arrayDec Integer
_ VS (MatlabCode Value)
_ = VS (MatlabCode Variable)
-> MatlabCode ScopeData -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
(scope :: k) (val :: k).
DeclStatement r bod stmt var scope val =>
VS (r var) -> r scope -> MS (r stmt)
varDec
arrayDecDef :: VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> [VS (MatlabCode Value)]
-> MS (MatlabCode Statement)
arrayDecDef = VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> [VS (MatlabCode Value)]
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
(scope :: k) (val :: k).
DeclStatement r bod stmt var scope val =>
VS (r var) -> r scope -> [VS (r val)] -> MS (r stmt)
listDecDef
constDecDef :: VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
constDecDef = VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
(scope :: k) (val :: k).
DeclStatement r bod stmt var scope val =>
VS (r var) -> r scope -> VS (r val) -> MS (r stmt)
varDecDef
funcDecDef :: VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> [VS (MatlabCode Variable)]
-> MS (MatlabCode Body)
-> MS (MatlabCode Statement)
funcDecDef = VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> [VS (MatlabCode Variable)]
-> MS (MatlabCode Body)
-> MS (MatlabCode Statement)
forall (r :: * -> *) file mod mthd vis param bod block stmt var val
binder typ.
ProcRenderSym
r
file
mod
mthd
vis
param
bod
block
stmt
var
ScopeData
val
binder
typ =>
VS (r var)
-> r ScopeData -> [VS (r var)] -> MS (r bod) -> MS (r stmt)
A.funcDecDef
instance PrintConsole MatlabCode Statement Value where
print :: VS (MatlabCode Value) -> MS (MatlabCode Statement)
print = Bool
-> Maybe (VS (MatlabCode Value))
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k)
(val :: k) (scope :: k) (var :: k) (typ :: k).
(BlockSym r block stmt, BodySym r bod block, MultiStatement r stmt,
PrintConsole r stmt val, PrintFile r stmt val, ScopeSym r scope,
DeclStatement r bod stmt var scope val,
AssignStatement r stmt var val,
ControlStatement r bod stmt var val, ValueSym r val typ,
Literal r val typ, NumericExpression r val, Comparison r val,
VariableSym r var typ, VariableValue r var val, List r val,
TypeSym r typ, TypeElim r typ, InternalIOStmt r stmt val) =>
Bool
-> Maybe (VS (r val)) -> VS (r val) -> VS (r val) -> MS (r stmt)
G.print Bool
False Maybe (VS (MatlabCode Value))
forall a. Maybe a
Nothing VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r val)
printFunc
printLn :: VS (MatlabCode Value) -> MS (MatlabCode Statement)
printLn = Bool
-> Maybe (VS (MatlabCode Value))
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k)
(val :: k) (scope :: k) (var :: k) (typ :: k).
(BlockSym r block stmt, BodySym r bod block, MultiStatement r stmt,
PrintConsole r stmt val, PrintFile r stmt val, ScopeSym r scope,
DeclStatement r bod stmt var scope val,
AssignStatement r stmt var val,
ControlStatement r bod stmt var val, ValueSym r val typ,
Literal r val typ, NumericExpression r val, Comparison r val,
VariableSym r var typ, VariableValue r var val, List r val,
TypeSym r typ, TypeElim r typ, InternalIOStmt r stmt val) =>
Bool
-> Maybe (VS (r val)) -> VS (r val) -> VS (r val) -> MS (r stmt)
G.print Bool
True Maybe (VS (MatlabCode Value))
forall a. Maybe a
Nothing VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r val)
printLnFunc
printStr :: String -> MS (MatlabCode Statement)
printStr = Bool
-> Maybe (VS (MatlabCode Value))
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k)
(val :: k) (scope :: k) (var :: k) (typ :: k).
(BlockSym r block stmt, BodySym r bod block, MultiStatement r stmt,
PrintConsole r stmt val, PrintFile r stmt val, ScopeSym r scope,
DeclStatement r bod stmt var scope val,
AssignStatement r stmt var val,
ControlStatement r bod stmt var val, ValueSym r val typ,
Literal r val typ, NumericExpression r val, Comparison r val,
VariableSym r var typ, VariableValue r var val, List r val,
TypeSym r typ, TypeElim r typ, InternalIOStmt r stmt val) =>
Bool
-> Maybe (VS (r val)) -> VS (r val) -> VS (r val) -> MS (r stmt)
G.print Bool
False Maybe (VS (MatlabCode Value))
forall a. Maybe a
Nothing VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r val)
printFunc (VS (MatlabCode Value) -> MS (MatlabCode Statement))
-> (String -> VS (MatlabCode Value))
-> String
-> MS (MatlabCode Statement)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString
printStrLn :: String -> MS (MatlabCode Statement)
printStrLn = Bool
-> Maybe (VS (MatlabCode Value))
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k)
(val :: k) (scope :: k) (var :: k) (typ :: k).
(BlockSym r block stmt, BodySym r bod block, MultiStatement r stmt,
PrintConsole r stmt val, PrintFile r stmt val, ScopeSym r scope,
DeclStatement r bod stmt var scope val,
AssignStatement r stmt var val,
ControlStatement r bod stmt var val, ValueSym r val typ,
Literal r val typ, NumericExpression r val, Comparison r val,
VariableSym r var typ, VariableValue r var val, List r val,
TypeSym r typ, TypeElim r typ, InternalIOStmt r stmt val) =>
Bool
-> Maybe (VS (r val)) -> VS (r val) -> VS (r val) -> MS (r stmt)
G.print Bool
True Maybe (VS (MatlabCode Value))
forall a. Maybe a
Nothing VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r val)
printLnFunc (VS (MatlabCode Value) -> MS (MatlabCode Statement))
-> (String -> VS (MatlabCode Value))
-> String
-> MS (MatlabCode Statement)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString
instance ReadConsole MatlabCode Statement Variable where
getInput :: VS (MatlabCode Variable) -> MS (MatlabCode Statement)
getInput = VS (MatlabCode Value)
-> VS (MatlabCode Variable) -> MS (MatlabCode Statement)
mlInput VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r val)
inputFunc
discardInput :: MS (MatlabCode Statement)
discardInput = VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
ValueStatement r stmt val =>
VS (r val) -> MS (r stmt)
valStmt VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r val)
inputFunc
instance FileHandling MatlabCode Statement Variable Value where
openFileR :: VS (MatlabCode Variable)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
openFileR VS (MatlabCode Variable)
f VS (MatlabCode Value)
n = VS (MatlabCode Variable)
f VS (MatlabCode Variable)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
AssignStatement r stmt var val =>
VS (r var) -> VS (r val) -> MS (r stmt)
&= PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"fopen" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
infile [VS (MatlabCode Value)
n, String -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString String
"r"]
openFileW :: VS (MatlabCode Variable)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
openFileW VS (MatlabCode Variable)
f VS (MatlabCode Value)
n = VS (MatlabCode Variable)
f VS (MatlabCode Variable)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
AssignStatement r stmt var val =>
VS (r var) -> VS (r val) -> MS (r stmt)
&= PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"fopen" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
outfile [VS (MatlabCode Value)
n, String -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString String
"w"]
openFileA :: VS (MatlabCode Variable)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
openFileA VS (MatlabCode Variable)
f VS (MatlabCode Value)
n = VS (MatlabCode Variable)
f VS (MatlabCode Variable)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
AssignStatement r stmt var val =>
VS (r var) -> VS (r val) -> MS (r stmt)
&= PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"fopen" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
outfile [VS (MatlabCode Value)
n, String -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString String
"a"]
closeFile :: VS (MatlabCode Value) -> MS (MatlabCode Statement)
closeFile VS (MatlabCode Value)
f = VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
ValueStatement r stmt val =>
VS (r val) -> MS (r stmt)
valStmt (VS (MatlabCode Value) -> MS (MatlabCode Statement))
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall a b. (a -> b) -> a -> b
$ PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"fclose" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
void [VS (MatlabCode Value)
f]
instance PrintFile MatlabCode Statement Value where
printFile :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
printFile VS (MatlabCode Value)
f = Bool
-> Maybe (VS (MatlabCode Value))
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k)
(val :: k) (scope :: k) (var :: k) (typ :: k).
(BlockSym r block stmt, BodySym r bod block, MultiStatement r stmt,
PrintConsole r stmt val, PrintFile r stmt val, ScopeSym r scope,
DeclStatement r bod stmt var scope val,
AssignStatement r stmt var val,
ControlStatement r bod stmt var val, ValueSym r val typ,
Literal r val typ, NumericExpression r val, Comparison r val,
VariableSym r var typ, VariableValue r var val, List r val,
TypeSym r typ, TypeElim r typ, InternalIOStmt r stmt val) =>
Bool
-> Maybe (VS (r val)) -> VS (r val) -> VS (r val) -> MS (r stmt)
G.print Bool
False (VS (MatlabCode Value) -> Maybe (VS (MatlabCode Value))
forall a. a -> Maybe a
Just VS (MatlabCode Value)
f) VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r val)
printFunc
printFileLn :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
printFileLn VS (MatlabCode Value)
f = Bool
-> Maybe (VS (MatlabCode Value))
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k)
(val :: k) (scope :: k) (var :: k) (typ :: k).
(BlockSym r block stmt, BodySym r bod block, MultiStatement r stmt,
PrintConsole r stmt val, PrintFile r stmt val, ScopeSym r scope,
DeclStatement r bod stmt var scope val,
AssignStatement r stmt var val,
ControlStatement r bod stmt var val, ValueSym r val typ,
Literal r val typ, NumericExpression r val, Comparison r val,
VariableSym r var typ, VariableValue r var val, List r val,
TypeSym r typ, TypeElim r typ, InternalIOStmt r stmt val) =>
Bool
-> Maybe (VS (r val)) -> VS (r val) -> VS (r val) -> MS (r stmt)
G.print Bool
True (VS (MatlabCode Value) -> Maybe (VS (MatlabCode Value))
forall a. a -> Maybe a
Just VS (MatlabCode Value)
f) VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r val)
printLnFunc
printFileStr :: VS (MatlabCode Value) -> String -> MS (MatlabCode Statement)
printFileStr VS (MatlabCode Value)
f = VS (MatlabCode Value)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
PrintFile r stmt val =>
VS (r val) -> VS (r val) -> MS (r stmt)
printFile VS (MatlabCode Value)
f (VS (MatlabCode Value) -> MS (MatlabCode Statement))
-> (String -> VS (MatlabCode Value))
-> String
-> MS (MatlabCode Statement)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString
printFileStrLn :: VS (MatlabCode Value) -> String -> MS (MatlabCode Statement)
printFileStrLn VS (MatlabCode Value)
f = VS (MatlabCode Value)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
PrintFile r stmt val =>
VS (r val) -> VS (r val) -> MS (r stmt)
printFileLn VS (MatlabCode Value)
f (VS (MatlabCode Value) -> MS (MatlabCode Statement))
-> (String -> VS (MatlabCode Value))
-> String
-> MS (MatlabCode Statement)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString
instance ReadFile MatlabCode Statement Variable Value where
getFileInput :: VS (MatlabCode Value)
-> VS (MatlabCode Variable) -> MS (MatlabCode Statement)
getFileInput VS (MatlabCode Value)
f = VS (MatlabCode Value)
-> VS (MatlabCode Variable) -> MS (MatlabCode Statement)
mlInput (VS (MatlabCode Value) -> VS (MatlabCode Value)
mlReadLine VS (MatlabCode Value)
f)
discardFileInput :: VS (MatlabCode Value) -> MS (MatlabCode Statement)
discardFileInput VS (MatlabCode Value)
f = VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
ValueStatement r stmt val =>
VS (r val) -> MS (r stmt)
valStmt (VS (MatlabCode Value) -> VS (MatlabCode Value)
mlReadLine VS (MatlabCode Value)
f)
getFileInputLine :: VS (MatlabCode Value)
-> VS (MatlabCode Variable) -> MS (MatlabCode Statement)
getFileInputLine = VS (MatlabCode Value)
-> VS (MatlabCode Variable) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
ReadFile r stmt var val =>
VS (r val) -> VS (r var) -> MS (r stmt)
getFileInput
discardFileLine :: VS (MatlabCode Value) -> MS (MatlabCode Statement)
discardFileLine = VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
ReadFile r stmt var val =>
VS (r val) -> MS (r stmt)
discardFileInput
getFileInputAll :: VS (MatlabCode Value)
-> VS (MatlabCode Variable) -> MS (MatlabCode Statement)
getFileInputAll = VS (MatlabCode Value)
-> VS (MatlabCode Variable) -> MS (MatlabCode Statement)
mlReadAllLines
instance StringStatement MatlabCode Statement Variable Value where
stringSplit :: Char
-> VS (MatlabCode Variable)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
stringSplit Char
d VS (MatlabCode Variable)
vnew VS (MatlabCode Value)
s = VS (MatlabCode Variable)
vnew VS (MatlabCode Variable)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
AssignStatement r stmt var val =>
VS (r var) -> VS (r val) -> MS (r stmt)
&= PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"strsplit" (VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k).
TypeSym r typ =>
VS (r typ) -> VS (r typ)
listType VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
string) [VS (MatlabCode Value)
s, String -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString [Char
d]]
stringListVals :: [VS (MatlabCode Variable)]
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
stringListVals = [VS (MatlabCode Variable)]
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k)
(typ :: k).
(MultiStatement r stmt, AssignStatement r stmt var val, List r val,
ValueSym r val typ, Literal r val typ, RenderValue r var val typ,
TypeElim r typ, VariableElim r var typ) =>
[VS (r var)] -> VS (r val) -> MS (r stmt)
M.stringListVals
stringListLists :: [VS (MatlabCode Variable)]
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
stringListLists = [VS (MatlabCode Variable)]
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (bod :: k) (block :: k) (stmt :: k)
(var :: k) (val :: k) (typ :: k).
(BodySym r bod block, BlockSym r block stmt,
ControlStatement r bod stmt var val, TypeSym r typ,
ValueSym r val typ, Literal r val typ, NumericExpression r val,
VariableSym r var typ, VariableValue r var val, List r val,
ListStatement r stmt val, TypeElim r typ, VariableElim r var typ,
RenderValue r var val typ) =>
[VS (r var)] -> VS (r val) -> MS (r stmt)
M.stringListLists
instance FuncAppStatement MatlabCode Statement Variable Value where
inOutCall :: InOutCall MatlabCode Statement Variable Value
inOutCall = PosCall MatlabCode Value TypeData
-> InOutCall MatlabCode Statement Variable Value
forall {k} (r :: k -> *) (typ :: k) (stmt :: k) (var :: k)
(val :: k).
(TypeSym r typ, InternalAssignStmt r stmt var val,
ValueStatement r stmt val, VariableValue r var val) =>
(String -> VS (r typ) -> [VS (r val)] -> VS (r val))
-> String
-> [VS (r val)]
-> [VS (r var)]
-> [VS (r var)]
-> MS (r stmt)
CP.inOutCall PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp
extInOutCall :: String -> InOutCall MatlabCode Statement Variable Value
extInOutCall = String -> InOutCall MatlabCode Statement Variable Value
forall a. HasCallStack => a
undefined
instance CommentStatement MatlabCode Statement where
comment :: String -> MS (MatlabCode Statement)
comment = Body -> String -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k).
RenderStatement r stmt =>
Body -> String -> MS (r stmt)
G.comment Body
mlCmtStart
instance ControlStatement MatlabCode Body Statement Variable Value where
break :: MS (MatlabCode Statement)
break = Body -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k).
RenderStatement r stmt =>
Body -> MS (r stmt)
mkStmtNoEnd Body
R.break
continue :: MS (MatlabCode Statement)
continue = Body -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k).
RenderStatement r stmt =>
Body -> MS (r stmt)
mkStmtNoEnd Body
R.continue
returnStmt :: VS (MatlabCode Value) -> MS (MatlabCode Statement)
returnStmt VS (MatlabCode Value)
v' = do
v <- LensLike'
(Zoomed (StateT ValueState Identity) (MatlabCode Value))
MethodState
ValueState
-> VS (MatlabCode Value)
-> StateT MethodState Identity (MatlabCode Value)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (MatlabCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (MatlabCode Value) ValueState)
-> MethodState -> Focusing Identity (MatlabCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS VS (MatlabCode Value)
v'
var mlRet (toState (valueType v)) &= v'
throw :: String -> MS (MatlabCode Statement)
throw String
errMsg = VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
ValueStatement r stmt val =>
VS (r val) -> MS (r stmt)
valStmt (VS (MatlabCode Value) -> MS (MatlabCode Statement))
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall a b. (a -> b) -> a -> b
$ PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"error" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
void [String -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString String
errMsg]
ifCond :: [(VS (MatlabCode Value), MS (MatlabCode Body))]
-> MS (MatlabCode Body) -> MS (MatlabCode Statement)
ifCond = (Body -> Body)
-> Body
-> OptionalSpace
-> Body
-> Body
-> Body
-> [(VS (MatlabCode Value), MS (MatlabCode Body))]
-> MS (MatlabCode Body)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (val :: k).
(BodyElim r bod, RenderStatement r stmt, ValueElim r val) =>
(Body -> Body)
-> Body
-> OptionalSpace
-> Body
-> Body
-> Body
-> [(VS (r val), MS (r bod))]
-> MS (r bod)
-> MS (r stmt)
G.ifCond Body -> Body
forall a. a -> a
id Body
empty (Body -> OptionalSpace
OSpace Body
empty) Body
mlElseIf Body
empty Body
mlEnd
switch :: VS (MatlabCode Value)
-> [(VS (MatlabCode Value), MS (MatlabCode Body))]
-> MS (MatlabCode Body)
-> MS (MatlabCode Statement)
switch = VS (MatlabCode Value)
-> [(VS (MatlabCode Value), MS (MatlabCode Body))]
-> MS (MatlabCode Body)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
(val :: k).
(ControlStatement r bod stmt var val, Comparison r val) =>
VS (r val)
-> [(VS (r val), MS (r bod))] -> MS (r bod) -> MS (r stmt)
switchAsIf
ifExists :: VS (MatlabCode Value)
-> MS (MatlabCode Body)
-> MS (MatlabCode Body)
-> MS (MatlabCode Statement)
ifExists = VS (MatlabCode Value)
-> MS (MatlabCode Body)
-> MS (MatlabCode Body)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
(val :: k) (binder :: k) (typ :: k).
(ControlStatement r bod stmt var val,
ValueExpression r var val binder typ) =>
VS (r val) -> MS (r bod) -> MS (r bod) -> MS (r stmt)
M.ifExists
for :: MS (MatlabCode Statement)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
-> MS (MatlabCode Body)
-> MS (MatlabCode Statement)
for MS (MatlabCode Statement)
initS VS (MatlabCode Value)
cond MS (MatlabCode Statement)
updateS MS (MatlabCode Body)
b = do
i <- MS (MatlabCode Statement)
initS
c <- zoom lensMStoVS cond
u <- updateS
bd <- b
mkStmtNoEnd (vcat [
RC.statement i <> text ";",
text "while" <+> RC.value c,
indent (RC.body bd),
indent (RC.statement u <> text ";"),
mlEnd])
forRange :: VS (MatlabCode Variable)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Body)
-> MS (MatlabCode Statement)
forRange VS (MatlabCode Variable)
i VS (MatlabCode Value)
initv VS (MatlabCode Value)
finalv VS (MatlabCode Value)
stepv = VS (MatlabCode Variable)
-> VS (MatlabCode Value)
-> MS (MatlabCode Body)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
(val :: k).
ControlStatement r bod stmt var val =>
VS (r var) -> VS (r val) -> MS (r bod) -> MS (r stmt)
forEach VS (MatlabCode Variable)
i (VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) mthd vis param bod block stmt var scope val
binder typ.
CommonRenderSym
r mthd vis param bod block stmt var scope val binder typ =>
VS (r val) -> VS (r val) -> VS (r val) -> VS (r val)
mlRange VS (MatlabCode Value)
initv VS (MatlabCode Value)
finalv VS (MatlabCode Value)
stepv)
forEach :: VS (MatlabCode Variable)
-> VS (MatlabCode Value)
-> MS (MatlabCode Body)
-> MS (MatlabCode Statement)
forEach = (MatlabCode Variable
-> MatlabCode Value -> MatlabCode Body -> Body)
-> VS (MatlabCode Variable)
-> VS (MatlabCode Value)
-> MS (MatlabCode Body)
-> MS (MatlabCode Statement)
forall (r :: * -> *) stmt var val.
RenderStatement r stmt =>
(r var -> r val -> r Body -> Body)
-> VS (r var) -> VS (r val) -> MS (r Body) -> MS (r stmt)
CS.forEach' MatlabCode Variable -> MatlabCode Value -> MatlabCode Body -> Body
forall (r :: * -> *) mthd vis param bod block stmt var scope val
binder typ.
CommonRenderSym
r mthd vis param bod block stmt var scope val binder typ =>
r var -> r val -> r bod -> Body
mlForEach
while :: VS (MatlabCode Value)
-> MS (MatlabCode Body) -> MS (MatlabCode Statement)
while = (Body -> Body)
-> Body
-> Body
-> VS (MatlabCode Value)
-> MS (MatlabCode Body)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (val :: k).
(BodyElim r bod, RenderStatement r stmt, ValueElim r val) =>
(Body -> Body)
-> Body -> Body -> VS (r val) -> MS (r bod) -> MS (r stmt)
C.while Body -> Body
forall a. a -> a
id Body
empty Body
mlEnd
tryCatch :: MS (MatlabCode Body)
-> MS (MatlabCode Body) -> MS (MatlabCode Statement)
tryCatch = (MatlabCode Body -> MatlabCode Body -> Body)
-> MS (MatlabCode Body)
-> MS (MatlabCode Body)
-> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (bod :: k).
RenderStatement r stmt =>
(r bod -> r bod -> Body) -> MS (r bod) -> MS (r bod) -> MS (r stmt)
G.tryCatch MatlabCode Body -> MatlabCode Body -> Body
forall (r :: * -> *) mthd vis param bod block stmt var scope val
binder typ.
CommonRenderSym
r mthd vis param bod block stmt var scope val binder typ =>
r bod -> r bod -> Body
mlTryCatch
assert :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
assert VS (MatlabCode Value)
cond VS (MatlabCode Value)
errMsg = VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
ValueStatement r stmt val =>
VS (r val) -> MS (r stmt)
valStmt (VS (MatlabCode Value) -> MS (MatlabCode Statement))
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall a b. (a -> b) -> a -> b
$ PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"assert" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
void [VS (MatlabCode Value)
cond, VS (MatlabCode Value)
errMsg]
instance VisibilitySym MatlabCode Doc where
private :: MatlabCode Body
private = Body -> MatlabCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode Body
empty
public :: MatlabCode Body
public = Body -> MatlabCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode Body
empty
instance RenderVisibility MatlabCode Doc where
visibilityFromData :: VisibilityTag -> Body -> MatlabCode Body
visibilityFromData = VisibilityTag -> Body -> MatlabCode Body
forall a. HasCallStack => a
undefined
instance VisibilityElim MatlabCode Doc where
visibility :: MatlabCode Body -> Body
visibility = MatlabCode Body -> Body
forall a. MatlabCode a -> a
unMLC
instance MethodTypeSym MatlabCode TypeData where
mType :: VS (MatlabCode TypeData) -> MS (MatlabCode TypeData)
mType = LensLike'
(Zoomed (StateT ValueState Identity) (MatlabCode TypeData))
MethodState
ValueState
-> VS (MatlabCode TypeData) -> MS (MatlabCode TypeData)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (MatlabCode TypeData))
MethodState
ValueState
(ValueState -> Focusing Identity (MatlabCode TypeData) ValueState)
-> MethodState
-> Focusing Identity (MatlabCode TypeData) MethodState
Lens' MethodState ValueState
lensMStoVS
instance ParameterSym MatlabCode ParamData Variable where
param :: VS (MatlabCode Variable) -> MS (MatlabCode ParamData)
param = (MatlabCode Variable -> Body)
-> VS (MatlabCode Variable) -> MS (MatlabCode ParamData)
forall {k} (r :: k -> *) (param :: k) (var :: k) (typ :: k).
(RenderParam r param var, VariableElim r var typ) =>
(r var -> Body) -> VS (r var) -> MS (r param)
G.param MatlabCode Variable -> Body
mlParam
pointerParam :: VS (MatlabCode Variable) -> MS (MatlabCode ParamData)
pointerParam = VS (MatlabCode Variable) -> MS (MatlabCode ParamData)
forall {k} (r :: k -> *) (param :: k) (var :: k).
ParameterSym r param var =>
VS (r var) -> MS (r param)
param
instance RenderParam MatlabCode ParamData Variable where
paramFromData :: VS (MatlabCode Variable) -> Body -> MS (MatlabCode ParamData)
paramFromData VS (MatlabCode Variable)
v' Body
d = do
v <- LensLike'
(Zoomed (StateT ValueState Identity) (MatlabCode Variable))
MethodState
ValueState
-> VS (MatlabCode Variable)
-> StateT MethodState Identity (MatlabCode Variable)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (MatlabCode Variable))
MethodState
ValueState
(ValueState -> Focusing Identity (MatlabCode Variable) ValueState)
-> MethodState
-> Focusing Identity (MatlabCode Variable) MethodState
Lens' MethodState ValueState
lensMStoVS VS (MatlabCode Variable)
v'
toState $ on2CodeValues pd v (toCode d)
instance ParamElim MatlabCode ParamData TypeData where
parameterName :: MatlabCode ParamData -> String
parameterName = MatlabCode Variable -> String
forall {k} (r :: k -> *) (var :: k) (typ :: k).
VariableElim r var typ =>
r var -> String
variableName (MatlabCode Variable -> String)
-> (MatlabCode ParamData -> MatlabCode Variable)
-> MatlabCode ParamData
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ParamData -> Variable)
-> MatlabCode ParamData -> MatlabCode Variable
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ParamData -> Variable
paramVar
parameterType :: MatlabCode ParamData -> MatlabCode TypeData
parameterType = MatlabCode Variable -> MatlabCode TypeData
forall {k} (r :: k -> *) (var :: k) (typ :: k).
VariableElim r var typ =>
r var -> r typ
variableType (MatlabCode Variable -> MatlabCode TypeData)
-> (MatlabCode ParamData -> MatlabCode Variable)
-> MatlabCode ParamData
-> MatlabCode TypeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ParamData -> Variable)
-> MatlabCode ParamData -> MatlabCode Variable
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ParamData -> Variable
paramVar
parameter :: MatlabCode ParamData -> Body
parameter = ParamData -> Body
paramDoc (ParamData -> Body)
-> (MatlabCode ParamData -> ParamData)
-> MatlabCode ParamData
-> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode ParamData -> ParamData
forall a. MatlabCode a -> a
unMLC
instance MethodSym MatlabCode MethodData Doc ParamData Body Variable TypeData where
docMain :: MS (MatlabCode Body) -> MS (MatlabCode MethodData)
docMain = MS (MatlabCode Body) -> MS (MatlabCode MethodData)
forall {k} (r :: k -> *) (mthd :: k) (vis :: k) (param :: k)
(bod :: k) (var :: k) (typ :: k).
MethodSym r mthd vis param bod var typ =>
MS (r bod) -> MS (r mthd)
mainFunction
function :: String
-> MatlabCode Body
-> VS (MatlabCode TypeData)
-> [MS (MatlabCode ParamData)]
-> MS (MatlabCode Body)
-> MS (MatlabCode MethodData)
function = String
-> MatlabCode Body
-> VS (MatlabCode TypeData)
-> [MS (MatlabCode ParamData)]
-> MS (MatlabCode Body)
-> MS (MatlabCode MethodData)
forall {k} (r :: k -> *) (typ :: k) (mthd :: k) (vis :: k)
(param :: k) (bod :: k).
(MethodTypeSym r typ, ProcRenderMethod r mthd vis param bod typ) =>
String
-> r vis
-> VS (r typ)
-> [MS (r param)]
-> MS (r bod)
-> MS (r mthd)
A.function
mainFunction :: MS (MatlabCode Body) -> MS (MatlabCode MethodData)
mainFunction = MS (MatlabCode Body) -> MS (MatlabCode MethodData)
forall (r :: * -> *) bod mthd.
(BodyElim r bod, RenderMethod r mthd) =>
MS (r bod) -> MS (r mthd)
CP.mainBody
docFunc :: String
-> [String]
-> Maybe String
-> MS (MatlabCode MethodData)
-> MS (MatlabCode MethodData)
docFunc = FuncDocRenderer
-> String
-> [String]
-> Maybe String
-> MS (MatlabCode MethodData)
-> MS (MatlabCode MethodData)
forall (r :: * -> *) mthd.
(BlockCommentSym r, RenderMethod r mthd) =>
FuncDocRenderer
-> String -> [String] -> Maybe String -> MS (r mthd) -> MS (r mthd)
G.docFunc FuncDocRenderer
CP.functionDoc
inOutFunc :: String
-> MatlabCode Body -> InOutFunc MatlabCode MethodData Body Variable
inOutFunc String
n MatlabCode Body
_ [VS (MatlabCode Variable)]
ins [VS (MatlabCode Variable)]
outs [VS (MatlabCode Variable)]
both MS (MatlabCode Body)
b = do
pms <- (VS (MatlabCode Variable) -> MS (MatlabCode ParamData))
-> [VS (MatlabCode Variable)]
-> StateT MethodState Identity [MatlabCode ParamData]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM VS (MatlabCode Variable) -> MS (MatlabCode ParamData)
forall {k} (r :: k -> *) (param :: k) (var :: k).
ParameterSym r param var =>
VS (r var) -> MS (r param)
param ([VS (MatlabCode Variable)]
both [VS (MatlabCode Variable)]
-> [VS (MatlabCode Variable)] -> [VS (MatlabCode Variable)]
forall a. Semigroup a => a -> a -> a
P.<> [VS (MatlabCode Variable)]
ins)
rets <- mapM (zoom lensMStoVS) (both P.<> outs)
bod <- b
pure $ toCode $ mthd n $ mlFuncDoc n (RC.variable <$> rets) pms (RC.body bod)
docInOutFunc :: String
-> MatlabCode Body
-> DocInOutFunc MatlabCode MethodData Body Variable
docInOutFunc String
n MatlabCode Body
s = FuncDocRenderer
-> InOutFunc MatlabCode MethodData Body Variable
-> DocInOutFunc MatlabCode MethodData Body Variable
forall (r :: * -> *) mthd var bod.
(BlockCommentSym r, RenderMethod r mthd) =>
FuncDocRenderer
-> ([VS (r var)]
-> [VS (r var)] -> [VS (r var)] -> MS (r bod) -> MS (r mthd))
-> String
-> [(String, VS (r var))]
-> [(String, VS (r var))]
-> [(String, VS (r var))]
-> MS (r bod)
-> MS (r mthd)
CP.docInOutFunc' FuncDocRenderer
CP.functionDoc (String
-> MatlabCode Body -> InOutFunc MatlabCode MethodData Body Variable
forall {k} (r :: k -> *) (mthd :: k) (vis :: k) (param :: k)
(bod :: k) (var :: k) (typ :: k).
MethodSym r mthd vis param bod var typ =>
String -> r vis -> InOutFunc r mthd bod var
inOutFunc String
n MatlabCode Body
s)
instance RenderMethod MatlabCode MethodData where
commentedFunc :: MS (MatlabCode Body)
-> MS (MatlabCode MethodData) -> MS (MatlabCode MethodData)
commentedFunc MS (MatlabCode Body)
cmt MS (MatlabCode MethodData)
m = (MatlabCode MethodData
-> MatlabCode (Body -> Body) -> MatlabCode MethodData)
-> MS (MatlabCode MethodData)
-> State MethodState (MatlabCode (Body -> Body))
-> MS (MatlabCode MethodData)
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues ((MethodData -> (Body -> Body) -> MethodData)
-> MatlabCode MethodData
-> MatlabCode (Body -> Body)
-> MatlabCode MethodData
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues MethodData -> (Body -> Body) -> MethodData
updateMthd) MS (MatlabCode MethodData)
m
((MatlabCode Body -> MatlabCode (Body -> Body))
-> MS (MatlabCode Body)
-> State MethodState (MatlabCode (Body -> Body))
forall a b s. (a -> b) -> State s a -> State s b
onStateValue ((Body -> Body -> Body)
-> MatlabCode Body -> MatlabCode (Body -> Body)
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue Body -> Body -> Body
R.commentedItem) MS (MatlabCode Body)
cmt)
mthdFromData :: VisibilityTag -> Body -> MS (MatlabCode MethodData)
mthdFromData VisibilityTag
_ Body
d = MatlabCode MethodData -> MS (MatlabCode MethodData)
forall a s. a -> State s a
toState (MatlabCode MethodData -> MS (MatlabCode MethodData))
-> MatlabCode MethodData -> MS (MatlabCode MethodData)
forall a b. (a -> b) -> a -> b
$ MethodData -> MatlabCode MethodData
forall (r :: * -> *) a. Monad r => a -> r a
toCode (MethodData -> MatlabCode MethodData)
-> MethodData -> MatlabCode MethodData
forall a b. (a -> b) -> a -> b
$ String -> Body -> MethodData
mthd String
"" Body
d
instance ProcRenderMethod MatlabCode MethodData Doc ParamData Body TypeData where
intFunc :: Bool
-> String
-> MatlabCode Body
-> MS (MatlabCode TypeData)
-> [MS (MatlabCode ParamData)]
-> MS (MatlabCode Body)
-> MS (MatlabCode MethodData)
intFunc Bool
_ String
n MatlabCode Body
_ MS (MatlabCode TypeData)
t [MS (MatlabCode ParamData)]
ps MS (MatlabCode Body)
b = do
pms <- [MS (MatlabCode ParamData)]
-> StateT MethodState Identity [MatlabCode ParamData]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence [MS (MatlabCode ParamData)]
ps
tp <- t
bod <- b
let outs = [String -> Body
text String
mlRet | TypeData -> CodeType
cType (MatlabCode TypeData -> TypeData
forall a. MatlabCode a -> a
unMLC MatlabCode TypeData
tp) CodeType -> CodeType -> Bool
forall a. Eq a => a -> a -> Bool
/= CodeType
Void]
pure $ toCode $ mthd n $ mlFuncDoc n outs pms (RC.body bod)
instance MethodElim MatlabCode MethodData where
method :: MatlabCode MethodData -> Body
method = MethodData -> Body
mthdDoc (MethodData -> Body)
-> (MatlabCode MethodData -> MethodData)
-> MatlabCode MethodData
-> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode MethodData -> MethodData
forall a. MatlabCode a -> a
unMLC
instance ModuleSym MatlabCode ModData MethodData where
buildModule :: String
-> [String]
-> [MS (MatlabCode MethodData)]
-> FS (MatlabCode ModData)
buildModule String
n [String]
_ [MS (MatlabCode MethodData)]
fs = String -> FS Body -> FS (MatlabCode ModData)
forall {k} (r :: k -> *) (mod :: k).
RenderMod r mod =>
String -> FS Body -> FS (r mod)
modFromData String
n (do
fns <- (MS (MatlabCode MethodData)
-> StateT FileState Identity (MatlabCode MethodData))
-> [MS (MatlabCode MethodData)]
-> StateT FileState Identity [MatlabCode MethodData]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (LensLike'
(Zoomed (StateT MethodState Identity) (MatlabCode MethodData))
FileState
MethodState
-> MS (MatlabCode MethodData)
-> StateT FileState Identity (MatlabCode MethodData)
forall c.
LensLike'
(Zoomed (StateT MethodState Identity) c) FileState MethodState
-> StateT MethodState Identity c -> StateT FileState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT MethodState Identity) (MatlabCode MethodData))
FileState
MethodState
(MethodState
-> Focusing Identity (MatlabCode MethodData) MethodState)
-> FileState -> Focusing Identity (MatlabCode MethodData) FileState
Lens' FileState MethodState
lensFStoMS) [MS (MatlabCode MethodData)]
fs
entryFn <- mlMainFunc n
let fnDocs = [Body] -> Body
vibcat (MatlabCode MethodData -> Body
forall {k} (r :: k -> *) (mthd :: k).
MethodElim r mthd =>
r mthd -> Body
RC.method (MatlabCode MethodData -> Body)
-> [MatlabCode MethodData] -> [Body]
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
<$> [MatlabCode MethodData]
fns)
content = [Body] -> Body
vibcat ((Body -> Bool) -> [Body] -> [Body]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Body -> Bool) -> Body -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Body -> Bool
isEmpty) [Body
entryFn, Body
fnDocs])
case fns of
(MatlabCode MethodData
f:[MatlabCode MethodData]
_) | Body -> Bool
isEmpty Body
entryFn -> (FileState -> FileState) -> StateT FileState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> FileState -> FileState
setModuleName (MethodData -> String
mthdName (MatlabCode MethodData -> MethodData
forall a. MatlabCode a -> a
unMLC MatlabCode MethodData
f)))
[MatlabCode MethodData]
_ -> () -> StateT FileState Identity ()
forall a. a -> StateT FileState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
pure $ emptyIfEmpty content content)
instance RenderMod MatlabCode ModData where
modFromData :: String -> FS Body -> FS (MatlabCode ModData)
modFromData String
n = String
-> (Body -> MatlabCode ModData)
-> FS Body
-> FS (MatlabCode ModData)
forall {k} (r :: k -> *) (mod :: k).
String -> (Body -> r mod) -> FS Body -> FS (r mod)
A.modFromData String
n (ModData -> MatlabCode ModData
forall (r :: * -> *) a. Monad r => a -> r a
toCode (ModData -> MatlabCode ModData)
-> (Body -> ModData) -> Body -> MatlabCode ModData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Body -> ModData
md String
n)
updateModuleDoc :: (Body -> Body) -> MatlabCode ModData -> MatlabCode ModData
updateModuleDoc Body -> Body
f = (ModData -> ModData) -> MatlabCode ModData -> MatlabCode ModData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ((Body -> Body) -> ModData -> ModData
updateMod Body -> Body
f)
instance ModuleElim MatlabCode ModData where
module' :: MatlabCode ModData -> Body
module' = ModData -> Body
modDoc (ModData -> Body)
-> (MatlabCode ModData -> ModData) -> MatlabCode ModData -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode ModData -> ModData
forall a. MatlabCode a -> a
unMLC
instance BlockCommentSym MatlabCode where
blockComment :: [String] -> MatlabCode Body
blockComment [String]
lns = Body -> MatlabCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Body -> MatlabCode Body) -> Body -> MatlabCode Body
forall a b. (a -> b) -> a -> b
$ [String] -> Body
mlLineCmt [String]
lns
docComment :: forall a. State a [String] -> State a (MatlabCode Body)
docComment = ([String] -> MatlabCode Body)
-> State a [String] -> State a (MatlabCode Body)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue (Body -> MatlabCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Body -> MatlabCode Body)
-> ([String] -> Body) -> [String] -> MatlabCode Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> Body
mlLineCmt)
instance BlockCommentElim MatlabCode where
blockComment' :: MatlabCode Body -> Body
blockComment' = MatlabCode Body -> Body
forall a. MatlabCode a -> a
unMLC
mlName, mlVersion :: String
mlName :: String
mlName = String
"MATLAB"
mlVersion :: String
mlVersion = String
"R2024b"
mlExt :: String
mlExt :: String
mlExt = String
"m"
mlRet :: String
mlRet :: String
mlRet = String
"result"
mlTy :: CodeType -> String -> VS (MatlabCode TypeData)
mlTy :: CodeType -> String -> VS (MatlabCode TypeData)
mlTy CodeType
c String
s = CodeType -> String -> Body -> VS (MatlabCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Body -> VS (r TypeData)
typeFromData CodeType
c String
s (String -> Body
text String
s)
mlParam :: MatlabCode Variable -> Doc
mlParam :: MatlabCode Variable -> Body
mlParam = MatlabCode Variable -> Body
forall {k} (r :: k -> *) (var :: k).
InternalVarElim r var =>
r var -> Body
RC.variable
mlFuncDoc
:: (ParamElim r param typ)
=> Label -> [Doc] -> [r param] -> Doc -> Doc
mlFuncDoc :: forall {k} (r :: k -> *) (param :: k) (typ :: k).
ParamElim r param typ =>
String -> [Body] -> [r param] -> Body -> Body
mlFuncDoc String
n [Body]
outs [r param]
pms Body
bod =
[Body] -> Body
vcat [String -> Body
text String
"function" Body -> Body -> Body
<+> (Body
retDoc Body -> Body -> Body
<> String -> Body
text String
n) Body -> Body -> Body
<> Body -> Body
parens ([r param] -> Body
forall {k} (r :: k -> *) (param :: k) (typ :: k).
ParamElim r param typ =>
[r param] -> Body
R.parameterList [r param]
pms),
Body -> Body
indent Body
bod,
String -> Body
text String
"end"]
where retDoc :: Body
retDoc = case [Body]
outs of
[] -> Body
empty
[Body
o] -> Body
o Body -> Body -> Body
<+> Body
equals Body -> Body -> Body
<> String -> Body
text String
" "
[Body]
os -> Body -> Body
brackets ([Body] -> Body
hcat (Body -> [Body] -> [Body]
punctuate (String -> Body
text String
", ") [Body]
os)) Body -> Body -> Body
<+> Body
equals Body -> Body -> Body
<> String -> Body
text String
" "
mlCmtStart :: Doc
mlCmtStart :: Body
mlCmtStart = String -> Body
text String
"%"
mlLineCmt :: [String] -> Doc
mlLineCmt :: [String] -> Body
mlLineCmt = [Body] -> Body
vcat ([Body] -> Body) -> ([String] -> [Body]) -> [String] -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> Body) -> [String] -> [Body]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Body
mlCmtStart Body -> Body -> Body
<+>) (Body -> Body) -> (String -> Body) -> String -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Body
text)
mlPrintFunc :: VS (MatlabCode Value)
mlPrintFunc :: VS (MatlabCode Value)
mlPrintFunc = VS (MatlabCode TypeData) -> Body -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r typ) -> Body -> VS (r val)
mkStateVal VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
void (String -> Body
text String
"fprintf")
mlMainFunc :: Label -> FS Doc
mlMainFunc :: String -> FS Body
mlMainFunc String
n = do
b <- FS Body
getMainDoc
pure $ emptyIfEmpty b $ vcat
[text "function" <+> text n <> parens (text "varargin"),
indent b,
text "end"]
mlArg :: VS (MatlabCode Value) -> VS (MatlabCode Value)
mlArg :: VS (MatlabCode Value) -> VS (MatlabCode Value)
mlArg VS (MatlabCode Value)
n' = do
n <- VS (MatlabCode Value)
n'
s <- string
mkVal s (text "varargin" <> braces (RC.value n))
mlVecIndex
:: VS (MatlabCode Value) -> VS (MatlabCode Value) -> VS (MatlabCode Value)
mlVecIndex :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
mlVecIndex VS (MatlabCode Value)
v' VS (MatlabCode Value)
i' = do
v <- VS (MatlabCode Value)
v'
i <- intToIndex i'
d <- double
mkVal d (RC.value v <> parens (RC.value i))
mlListType :: VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
mlListType :: VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
mlListType VS (MatlabCode TypeData)
t' = do
t <- VS (MatlabCode TypeData)
t'
mlTy (List $ getCodeType t) "vector"
mlLitList
:: VS (MatlabCode TypeData) -> [VS (MatlabCode Value)] -> VS (MatlabCode Value)
mlLitList :: VS (MatlabCode TypeData)
-> [VS (MatlabCode Value)] -> VS (MatlabCode Value)
mlLitList VS (MatlabCode TypeData)
t [VS (MatlabCode Value)]
es = do
elems <- [VS (MatlabCode Value)]
-> StateT ValueState Identity [MatlabCode Value]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence [VS (MatlabCode Value)]
es
mkStateVal (listType t) (brackets (valueList elems))
mlReadLine :: VS (MatlabCode Value) -> VS (MatlabCode Value)
mlReadLine :: VS (MatlabCode Value) -> VS (MatlabCode Value)
mlReadLine VS (MatlabCode Value)
f = PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"fgetl" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
string [VS (MatlabCode Value)
f]
mlInput
:: VS (MatlabCode Value)
-> VS (MatlabCode Variable)
-> MS (MatlabCode Statement)
mlInput :: VS (MatlabCode Value)
-> VS (MatlabCode Variable) -> MS (MatlabCode Statement)
mlInput VS (MatlabCode Value)
inSrc VS (MatlabCode Variable)
v = VS (MatlabCode Variable)
v VS (MatlabCode Variable)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
AssignStatement r stmt var val =>
VS (r var) -> VS (r val) -> MS (r stmt)
&= (VS (MatlabCode Variable)
v VS (MatlabCode Variable)
-> (MatlabCode Variable -> VS (MatlabCode Value))
-> VS (MatlabCode Value)
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CodeType -> VS (MatlabCode Value)
mlInput' (CodeType -> VS (MatlabCode Value))
-> (MatlabCode Variable -> CodeType)
-> MatlabCode Variable
-> VS (MatlabCode Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode TypeData -> CodeType
forall {k} (r :: k -> *) (typ :: k).
TypeElim r typ =>
r typ -> CodeType
getCodeType (MatlabCode TypeData -> CodeType)
-> (MatlabCode Variable -> MatlabCode TypeData)
-> MatlabCode Variable
-> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatlabCode Variable -> MatlabCode TypeData
forall {k} (r :: k -> *) (var :: k) (typ :: k).
VariableElim r var typ =>
r var -> r typ
variableType)
where mlInput' :: CodeType -> VS (MatlabCode Value)
mlInput' CodeType
Integer = PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"str2double" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
int [VS (MatlabCode Value)
inSrc]
mlInput' CodeType
Float = PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"str2double" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
float [VS (MatlabCode Value)
inSrc]
mlInput' CodeType
Double = PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"str2double" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
double [VS (MatlabCode Value)
inSrc]
mlInput' CodeType
String = VS (MatlabCode Value)
inSrc
mlInput' CodeType
_ = String -> VS (MatlabCode Value)
forall a. HasCallStack => String -> a
error String
"Attempt to read a value of unreadable type"
mlPrint
:: Bool
-> Maybe (VS (MatlabCode Value))
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
mlPrint :: Bool
-> Maybe (VS (MatlabCode Value))
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
mlPrint Bool
newLn Maybe (VS (MatlabCode Value))
f' VS (MatlabCode Value)
_ VS (MatlabCode Value)
v' = do
v <- LensLike'
(Zoomed (StateT ValueState Identity) (MatlabCode Value))
MethodState
ValueState
-> VS (MatlabCode Value)
-> StateT MethodState Identity (MatlabCode Value)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (MatlabCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (MatlabCode Value) ValueState)
-> MethodState -> Focusing Identity (MatlabCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS VS (MatlabCode Value)
v'
mf <- traverse (zoom lensMStoVS) f'
let fmt = case TypeData -> CodeType
cType (Value -> TypeData
valType (MatlabCode Value -> Value
forall a. MatlabCode a -> a
unMLC MatlabCode Value
v)) of
CodeType
String -> String
"%s"
CodeType
Char -> String
"%c"
CodeType
_ -> String
"%g"
nl = if Bool
newLn then String
"\\n" else String
""
fileArg = Body
-> (MatlabCode Value -> Body) -> Maybe (MatlabCode Value) -> Body
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Body
empty (\MatlabCode Value
fv -> MatlabCode Value -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value MatlabCode Value
fv Body -> Body -> Body
<> Body
listSep') Maybe (MatlabCode Value)
mf
stmtFromData (text "fprintf" <>
parens (fileArg <> text ("'" P.<> fmt P.<> nl P.<> "'") <> listSep' <> RC.value v))
Semi
mlInlineIf
:: VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
mlInlineIf :: VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
mlInlineIf VS (MatlabCode Value)
c' VS (MatlabCode Value)
v1' VS (MatlabCode Value)
v2' = do
c <- VS (MatlabCode Value)
c'
v1 <- v1'
v2 <- v2'
mkStateVal (toState $ valueType v1)
(parens (parens (RC.value c) <+> text ".*" <+> parens (RC.value v1)
<+> text "+ ~" <> parens (RC.value c) <+> text ".*" <+> parens (RC.value v2)))
mlCast
:: VS (MatlabCode TypeData) -> VS (MatlabCode Value) -> VS (MatlabCode Value)
mlCast :: VS (MatlabCode TypeData)
-> VS (MatlabCode Value) -> VS (MatlabCode Value)
mlCast VS (MatlabCode TypeData)
t' VS (MatlabCode Value)
v' = do
t <- VS (MatlabCode TypeData)
t'
v <- v'
let vTp = MatlabCode TypeData -> CodeType
forall {k} (r :: k -> *) (typ :: k).
TypeElim r typ =>
r typ -> CodeType
getCodeType (MatlabCode TypeData -> CodeType)
-> MatlabCode TypeData -> CodeType
forall a b. (a -> b) -> a -> b
$ MatlabCode Value -> MatlabCode TypeData
forall {k} (r :: k -> *) (val :: k) (typ :: k).
ValueSym r val typ =>
r val -> r typ
valueType MatlabCode Value
v
tTp = MatlabCode TypeData -> CodeType
forall {k} (r :: k -> *) (typ :: k).
TypeElim r typ =>
r typ -> CodeType
getCodeType MatlabCode TypeData
t
rv = MatlabCode Value -> VS (MatlabCode Value)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MatlabCode Value
v
rt = MatlabCode TypeData -> VS (MatlabCode TypeData)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MatlabCode TypeData
t
case (vTp, tTp) of
(CodeType
String, CodeType
Integer) -> PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"str2double" VS (MatlabCode TypeData)
rt [VS (MatlabCode Value)
rv]
(CodeType
String, CodeType
Float) -> PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"str2double" VS (MatlabCode TypeData)
rt [VS (MatlabCode Value)
rv]
(CodeType
String, CodeType
Double) -> PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"str2double" VS (MatlabCode TypeData)
rt [VS (MatlabCode Value)
rv]
(CodeType
String, CodeType
Boolean) -> PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"logical" VS (MatlabCode TypeData)
rt [PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"str2double" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
double [VS (MatlabCode Value)
rv]]
(CodeType
_, CodeType
String) -> PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"num2str" VS (MatlabCode TypeData)
rt [VS (MatlabCode Value)
rv]
(CodeType
_, CodeType
Char) -> PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"char" VS (MatlabCode TypeData)
rt [VS (MatlabCode Value)
rv]
(CodeType, CodeType)
_ -> MatlabCode Value -> VS (MatlabCode Value)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MatlabCode Value
v
mlEqOp
:: Bool
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
mlEqOp :: Bool
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
mlEqOp Bool
neg VS (MatlabCode Value)
v1' VS (MatlabCode Value)
v2' = do
v1 <- VS (MatlabCode Value)
v1'
v2 <- v2'
t <- bool
let tp = MatlabCode TypeData -> CodeType
forall {k} (r :: k -> *) (typ :: k).
TypeElim r typ =>
r typ -> CodeType
getCodeType (MatlabCode Value -> MatlabCode TypeData
forall {k} (r :: k -> *) (val :: k) (typ :: k).
ValueSym r val typ =>
r val -> r typ
valueType MatlabCode Value
v1)
d = String -> Body
text String
"strcmp" Body -> Body -> Body
<> Body -> Body
parens (MatlabCode Value -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value MatlabCode Value
v1 Body -> Body -> Body
<> Body
listSep' Body -> Body -> Body
<> MatlabCode Value -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value MatlabCode Value
v2)
strDoc = if Bool
neg then String -> Body
text String
"~" Body -> Body -> Body
<> Body
d else Body
d
case tp of
CodeType
String -> MatlabCode TypeData -> Body -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
r typ -> Body -> VS (r val)
mkVal MatlabCode TypeData
t Body
strDoc
CodeType
_ -> if Bool
neg then VSUnOp MatlabCode
-> VS (MatlabCode TypeData)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
notEqualOp VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool (MatlabCode Value -> VS (MatlabCode Value)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MatlabCode Value
v1) (MatlabCode Value -> VS (MatlabCode Value)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MatlabCode Value
v2)
else VSUnOp MatlabCode
-> VS (MatlabCode TypeData)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp MatlabCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
equalOp VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool (MatlabCode Value -> VS (MatlabCode Value)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MatlabCode Value
v1) (MatlabCode Value -> VS (MatlabCode Value)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MatlabCode Value
v2)
mlListDec
:: VS (MatlabCode Variable)
-> MatlabCode ScopeData
-> MS (MatlabCode Statement)
mlListDec :: VS (MatlabCode Variable)
-> MatlabCode ScopeData -> MS (MatlabCode Statement)
mlListDec VS (MatlabCode Variable)
v MatlabCode ScopeData
scp = do
vr <- LensLike'
(Zoomed (StateT ValueState Identity) (MatlabCode Variable))
MethodState
ValueState
-> VS (MatlabCode Variable)
-> StateT MethodState Identity (MatlabCode Variable)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (MatlabCode Variable))
MethodState
ValueState
(ValueState -> Focusing Identity (MatlabCode Variable) ValueState)
-> MethodState
-> Focusing Identity (MatlabCode Variable) MethodState
Lens' MethodState ValueState
lensMStoVS VS (MatlabCode Variable)
v
let emptyInit = case MatlabCode TypeData -> CodeType
forall {k} (r :: k -> *) (typ :: k).
TypeElim r typ =>
r typ -> CodeType
getCodeType (MatlabCode Variable -> MatlabCode TypeData
forall {k} (r :: k -> *) (var :: k) (typ :: k).
VariableElim r var typ =>
r var -> r typ
variableType MatlabCode Variable
vr) of
List CodeType
String -> Body -> Body
braces Body
empty
CodeType
_ -> Body -> Body
brackets Body
empty
CS.varDecDef (pure vr) scp
(Just (mkStateVal (toState $ variableType vr) emptyInit))
mlReadAllLines
:: VS (MatlabCode Value)
-> VS (MatlabCode Variable)
-> MS (MatlabCode Statement)
mlReadAllLines :: VS (MatlabCode Value)
-> VS (MatlabCode Variable) -> MS (MatlabCode Statement)
mlReadAllLines VS (MatlabCode Value)
f VS (MatlabCode Variable)
v = do
let var_line :: VS (MatlabCode Variable)
var_line = String -> VS (MatlabCode TypeData) -> VS (MatlabCode Variable)
forall {k} (r :: k -> *) (var :: k) (typ :: k).
VariableSym r var typ =>
String -> VS (r typ) -> VS (r var)
var String
"mlLine" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
string
v_line :: VS (MatlabCode Value)
v_line = VS (MatlabCode Variable) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k).
VariableValue r var val =>
VS (r var) -> VS (r val)
valueOf VS (MatlabCode Variable)
var_line
readLine :: VS (MatlabCode Value)
readLine = PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"fgetl" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
string [VS (MatlabCode Value)
f]
cond :: VS (MatlabCode Value)
cond = PosCall MatlabCode Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
(typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
"ischar" VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool [VS (MatlabCode Value)
v_line]
[MS (MatlabCode Statement)] -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k).
MultiStatement r stmt =>
[MS (r stmt)] -> MS (r stmt)
multi [VS (MatlabCode Variable)
var_line VS (MatlabCode Variable)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
AssignStatement r stmt var val =>
VS (r var) -> VS (r val) -> MS (r stmt)
&= VS (MatlabCode Value)
readLine,
VS (MatlabCode Value)
-> MS (MatlabCode Body) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
(val :: k).
ControlStatement r bod stmt var val =>
VS (r val) -> MS (r bod) -> MS (r stmt)
while VS (MatlabCode Value)
cond ([MS (MatlabCode Statement)] -> MS (MatlabCode Body)
forall {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k).
(BlockSym r block stmt, BodySym r bod block) =>
[MS (r stmt)] -> MS (r bod)
bodyStatements
[VS (MatlabCode Value)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
ListStatement r stmt val =>
VS (r val) -> VS (r val) -> MS (r stmt)
listAppend (VS (MatlabCode Variable) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k).
VariableValue r var val =>
VS (r var) -> VS (r val)
valueOf VS (MatlabCode Variable)
v) VS (MatlabCode Value)
v_line,
VS (MatlabCode Variable)
var_line VS (MatlabCode Variable)
-> VS (MatlabCode Value) -> MS (MatlabCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
AssignStatement r stmt var val =>
VS (r var) -> VS (r val) -> MS (r stmt)
&= VS (MatlabCode Value)
readLine])]
mlEnd, mlElseIf :: Doc
mlEnd :: Body
mlEnd = String -> Body
text String
"end"
mlElseIf :: Body
mlElseIf = String -> Body
text String
"elseif"
mlForEach
:: (CommonRenderSym r mthd vis param bod block stmt var scope val binder typ)
=> r var -> r val -> r bod -> Doc
mlForEach :: forall (r :: * -> *) mthd vis param bod block stmt var scope val
binder typ.
CommonRenderSym
r mthd vis param bod block stmt var scope val binder typ =>
r var -> r val -> r bod -> Body
mlForEach r var
i r val
lstVar r bod
b = [Body] -> Body
vcat [
String -> Body
text String
"for" Body -> Body -> Body
<+> r var -> Body
forall {k} (r :: k -> *) (var :: k).
InternalVarElim r var =>
r var -> Body
RC.variable r var
i Body -> Body -> Body
<+> Body
equals Body -> Body -> Body
<+> r val -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value r val
lstVar,
Body -> Body
indent (Body -> Body) -> Body -> Body
forall a b. (a -> b) -> a -> b
$ r bod -> Body
forall {k} (r :: k -> *) (bod :: k).
BodyElim r bod =>
r bod -> Body
RC.body r bod
b,
Body
mlEnd]
mlRange
:: (CommonRenderSym r mthd vis param bod block stmt var scope val binder typ)
=> VS (r val) -> VS (r val) -> VS (r val) -> VS (r val)
mlRange :: forall (r :: * -> *) mthd vis param bod block stmt var scope val
binder typ.
CommonRenderSym
r mthd vis param bod block stmt var scope val binder typ =>
VS (r val) -> VS (r val) -> VS (r val) -> VS (r val)
mlRange VS (r val)
initv VS (r val)
finalv VS (r val)
stepv = do
ini <- VS (r val)
initv
fin <- finalv
stp <- stepv
d <- double
mkVal d (RC.value ini <> text ":" <> RC.value stp <> text ":" <> RC.value fin)
mlTryCatch
:: (CommonRenderSym r mthd vis param bod block stmt var scope val binder typ)
=> r bod -> r bod -> Doc
mlTryCatch :: forall (r :: * -> *) mthd vis param bod block stmt var scope val
binder typ.
CommonRenderSym
r mthd vis param bod block stmt var scope val binder typ =>
r bod -> r bod -> Body
mlTryCatch r bod
tryB r bod
catchB = [Body] -> Body
vcat [
String -> Body
text String
"try",
Body -> Body
indent (Body -> Body) -> Body -> Body
forall a b. (a -> b) -> a -> b
$ r bod -> Body
forall {k} (r :: k -> *) (bod :: k).
BodyElim r bod =>
r bod -> Body
RC.body r bod
tryB,
String -> Body
text String
"catch" Body -> Body -> Body
<+> String -> Body
text String
"e",
Body -> Body
indent (Body -> Body) -> Body -> Body
forall a b. (a -> b) -> a -> b
$ r bod -> Body
forall {k} (r :: k -> *) (bod :: k).
BodyElim r bod =>
r bod -> Body
RC.body r bod
catchB,
Body
mlEnd]
mlArrayElem
:: VS (MatlabCode Value) -> VS (MatlabCode Value) -> VS (MatlabCode Variable)
mlArrayElem :: VS (MatlabCode Value)
-> VS (MatlabCode Value) -> VS (MatlabCode Variable)
mlArrayElem VS (MatlabCode Value)
arr' VS (MatlabCode Value)
i' = do
i <- VS (MatlabCode Value) -> VS (MatlabCode Value)
forall {k} (r :: k -> *) (val :: k).
IndexTranslator r val =>
VS (r val) -> VS (r val)
intToIndex VS (MatlabCode Value)
i'
arr <- arr'
mkStateVar (render $ RC.value arr) (A.innerType $ pure $ valueType arr)
(RC.value arr <> parens (RC.value i))
mlListAdd
:: VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
mlListAdd :: VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
mlListAdd VS (MatlabCode Value)
lst' VS (MatlabCode Value)
idx' VS (MatlabCode Value)
val' = do
lst <- LensLike'
(Zoomed (StateT ValueState Identity) (MatlabCode Value))
MethodState
ValueState
-> VS (MatlabCode Value)
-> StateT MethodState Identity (MatlabCode Value)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (MatlabCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (MatlabCode Value) ValueState)
-> MethodState -> Focusing Identity (MatlabCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS VS (MatlabCode Value)
lst'
idx <- zoom lensMStoVS (intToIndex idx')
v <- zoom lensMStoVS val'
let lstDoc = MatlabCode Value -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value MatlabCode Value
lst
idxDoc = MatlabCode Value -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value MatlabCode Value
idx
valDoc = MatlabCode Value -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value MatlabCode Value
v
lvar = String
-> VS (MatlabCode TypeData) -> Body -> VS (MatlabCode Variable)
forall {k} (r :: k -> *) (var :: k) (typ :: k).
RenderVariable r var typ =>
String -> VS (r typ) -> Body -> VS (r var)
mkStateVar (Body -> String
render Body
lstDoc) (MatlabCode TypeData -> VS (MatlabCode TypeData)
forall a s. a -> State s a
toState (MatlabCode TypeData -> VS (MatlabCode TypeData))
-> MatlabCode TypeData -> VS (MatlabCode TypeData)
forall a b. (a -> b) -> a -> b
$ MatlabCode Value -> MatlabCode TypeData
forall {k} (r :: k -> *) (val :: k) (typ :: k).
ValueSym r val typ =>
r val -> r typ
valueType MatlabCode Value
lst) Body
lstDoc
lvar &= mkStateVal (toState $ valueType lst)
(brackets (lstDoc <> parens (text "1:" <> parens (idxDoc <+> text "- 1"))
<> text "," <+> valDoc
<> text "," <+> lstDoc <> parens (idxDoc <> text ":end")))
mlListSet
:: VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
mlListSet :: VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> VS (MatlabCode Value)
-> MS (MatlabCode Statement)
mlListSet VS (MatlabCode Value)
lst' VS (MatlabCode Value)
idx' VS (MatlabCode Value)
val' = do
lst <- LensLike'
(Zoomed (StateT ValueState Identity) (MatlabCode Value))
MethodState
ValueState
-> VS (MatlabCode Value)
-> StateT MethodState Identity (MatlabCode Value)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (MatlabCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (MatlabCode Value) ValueState)
-> MethodState -> Focusing Identity (MatlabCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS VS (MatlabCode Value)
lst'
idx <- zoom lensMStoVS (intToIndex idx')
let wrap = case MatlabCode TypeData -> CodeType
forall {k} (r :: k -> *) (typ :: k).
TypeElim r typ =>
r typ -> CodeType
getCodeType (MatlabCode Value -> MatlabCode TypeData
forall {k} (r :: k -> *) (val :: k) (typ :: k).
ValueSym r val typ =>
r val -> r typ
valueType MatlabCode Value
lst) of
List CodeType
t -> CodeType -> Body -> Body
mlCellWrap CodeType
t
CodeType
_ -> Body -> Body
parens
lvar = String
-> VS (MatlabCode TypeData) -> Body -> VS (MatlabCode Variable)
forall {k} (r :: k -> *) (var :: k) (typ :: k).
RenderVariable r var typ =>
String -> VS (r typ) -> Body -> VS (r var)
mkStateVar (Body -> String
render (Body -> String) -> Body -> String
forall a b. (a -> b) -> a -> b
$ MatlabCode Value -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value MatlabCode Value
lst)
(VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
forall {k} (r :: k -> *) (typ :: k).
(TypeSym r typ, TypeElim r typ) =>
VS (r typ) -> VS (r typ)
A.innerType (VS (MatlabCode TypeData) -> VS (MatlabCode TypeData))
-> VS (MatlabCode TypeData) -> VS (MatlabCode TypeData)
forall a b. (a -> b) -> a -> b
$ MatlabCode TypeData -> VS (MatlabCode TypeData)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MatlabCode TypeData -> VS (MatlabCode TypeData))
-> MatlabCode TypeData -> VS (MatlabCode TypeData)
forall a b. (a -> b) -> a -> b
$ MatlabCode Value -> MatlabCode TypeData
forall {k} (r :: k -> *) (val :: k) (typ :: k).
ValueSym r val typ =>
r val -> r typ
valueType MatlabCode Value
lst)
(MatlabCode Value -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value MatlabCode Value
lst Body -> Body -> Body
<> Body -> Body
wrap (MatlabCode Value -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value MatlabCode Value
idx))
lvar &= val'