{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PostfixOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleContexts #-}
module Drasil.GOOL.LanguageRenderer.SwiftRenderer (
SwiftCode(..), swiftName, swiftVersion
) where
import Drasil.FileHandling.Legacy (indent)
import Drasil.Shared.CodeType (CodeType(..))
import Drasil.Shared.InterfaceCommon (UnRepr(..), SharedProg, SharedStatement,
Label, Body, Block, Variable, SVariable, Value, SValue, BodySym(..), oneLiner,
bodyStatements, BlockSym(..), TypeSym(..), TypeElim(..), getTypeString,
VariableSym(..), VisibilitySym(..), VariableElim(..), ValueSym(..),
Argument(..), Literal(..), MathConstant(..), VariableValue(..),
CommandLineArgs(..), NumericExpression(..), BooleanExpression(..),
Comparison(..), ValueExpression(..), funcApp, funcAppNamedArgs, extFuncApp,
IndexTranslator(..), Reference(..), Array(..), List(..), Set(..), listSlice,
InternalList(..), StatementSym(..), AssignStatement(..), (&=),
DeclStatement(..), IOStatement(..), StringStatement(..), FunctionSym,
FuncAppStatement(..), CommentStatement(..), ControlStatement(..), ScopeSym(..),
ParameterSym(..), BinderSym(..), BinderElim(..), MethodSym(..), convScope)
import Drasil.GOOL.InterfaceGOOL (OOProg, StateVar, OOStatement, ProgramSym(..),
FileSym(..), ModuleSym(..), ClassSym(..), OOTypeSym(..), OOVariableSym(..),
SelfSym(..), StateVarSym(..), AttachmentSym(..), OOValueSym, OOVariableValue,
OOValueExpression(..), selfMethodCall, newObj, InternalValueExp(..),
objMethodCall, objMethodCallMixedArgs, objMethodCallNamedArgs,
objMethodCallNoParams, OOFunctionSym(..), ($.), GetSet(..),
OODeclStatement(..), OOFuncAppStatement(..), ObserverPattern(..),
StrategyPattern(..), OOMethodSym(..), Initializers, convTypeOO)
import Drasil.Shared.RendererClassesCommon (MSMthdType, CommonRenderSym,
ImportSym(..), RenderBody(..), BodyElim, RenderBlock(..), BlockElim,
RenderType(..), UnaryOpSym(..), BinaryOpSym(..), OpElim(uOpPrec, bOpPrec),
RenderVariable(..), InternalVarElim(variableBind), RenderValue(..),
ValueElim(valuePrec, valueInt), 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 (import', body, block,
uOp, bOp, variable, binderElim, value, function, statement, visibility,
parameter, method, blockComment', stmt)
import Drasil.GOOL.RendererClassesOO (OORenderSym, RenderFile(..),
PermElim(binding), InternalGetSet(..), OOMethodTypeSym(..),
OORenderMethod(..), StateVarElim, RenderClass(..), ClassElim, RenderMod(..),
ModuleElim)
import qualified Drasil.GOOL.RendererClassesOO as RC (perm, stateVar,
class', module')
import Drasil.GOOL.Renderers (renderType)
import Drasil.Shared.LanguageRenderer (blockCmtStart, blockCmtEnd, docCmtStart,
bodyStart, bodyEnd, commentStart, elseIfLabel, forLabel, inLabel, tryLabel,
catchLabel, throwLabel, throwsLabel, importLabel, listSep', printLabel,
listSep, piLabel, access, tuple, ClassDocRenderer, parameterList)
import qualified Drasil.Shared.LanguageRenderer as R (sqrt, abs, log10, log, exp,
sin, cos, tan, asin, acos, atan, floor, ceil, pow, class', multiStmt, body,
classVarAccess, func, castObj, classLevel, instanceLevel, break, continue,
private, blockCmt, docCmt, addComments, commentedMod, commentedItem, switch)
import Drasil.Shared.LanguageRenderer.Constructors (mkStmtNoEnd, mkStateVal,
mkVal, typeFromData, VSOp, unOpPrec, powerPrec, unExpr, unExpr', typeUnExpr,
binExpr, binExpr', typeBinExpr, typeFromData)
import qualified Drasil.Shared.LanguageRenderer.LanguagePolymorphic as G (
multiBody, block, multiBlock, obj, csc, sec, cot, negateOp, equalOp,
notEqualOp, greaterOp, greaterEqualOp, lessOp, lessEqualOp, plusOp, minusOp,
multOp, divideOp, moduloOp, var, classVar, instanceVarAccess, arrayElem,
litChar, litDouble, litInt, litString, valueOf, arg, argsList, objAccess,
objMethodCall, call, funcAppMixedArgs, newObjMixedArgs, lambda, func, get, set,
listAccess, getFunc, setFunc, stmt, loopStmt, emptyStmt, assign, subAssign,
objDecNew, print, returnStmt, valStmt, comment, throw, ifCond, tryCatch,
construct, param, method, getMethod, setMethod, initStmts, function, docFunc,
buildClass, implementingClass, docClass, commentedClass, modFromData, docMod,
fileDoc, fileFromData, defaultOptSpace, local)
import qualified Drasil.Shared.LanguageRenderer.Common as CS
import qualified Drasil.Shared.LanguageRenderer.CommonPseudoOO as CP (
classVarAccess, intClass, buildModule, modDoc', contains, bindingError,
notNull, listDecDef, destructorError, stateVarDef, constVar, litArray,
extraClass, doubleRender, double, openFileR, openFileW, self, multiAssign,
multiReturn, listDec, listSet, funcDecDef, inOutCall, forLoopError, mainBody,
inOutFunc, docInOutFunc', float, stringRender', string', inherit, implements,
functionDoc, intToIndex, indexToInt, global, setMethodCall)
import qualified Drasil.Shared.LanguageRenderer.CLike as C (notOp, andOp, orOp,
litTrue, litFalse, inlineIf, libFuncAppMixedArgs, libNewObjMixedArgs,
listSize', varDecDef, setDecDef, extObjDecNew, while)
import qualified Drasil.Shared.LanguageRenderer.Macros as M (ifExists,
decrement1, increment1, runStrategy, stringListVals, stringListLists,
notifyObservers', makeSetterVal, arrayDecAsList)
import qualified Drasil.GOOL.LanguageRenderer.CommonGOOL as CG (classMethodCall,
listAppend, innerType)
import Drasil.Shared.AST (Terminator(..), VisibilityTag(..), qualName,
FileType(..), fileD, FuncData(..), fd, ModData(..), md, updateMod,
MethodData(..), mthd, updateMthd, OpData(..), ParamData(..), pd, ProgData(..),
progD, TypeData(..), ValData(..), vd, AttachmentTag(..), VarData(..), vard,
ScopeData, BinderD(..), bindFormD)
import Drasil.Shared.Helpers (hicat, emptyIfNull, toCode, toState, onCodeValue,
onStateValue, on2CodeValues, on2StateValues, onCodeList, onStateList)
import Drasil.Shared.State (MS, VS, lensGStoFS, lensFStoCS, lensFStoMS,
lensCStoVS, lensMStoFS, lensMStoVS, lensVStoFS, revFiles, addLangImportVS,
getLangImports, getLibImports, setFileType, getClassName, setModuleName,
getModuleName, getCurrMain, getMethodExcMap, getMainDoc, setThrowUsed,
getThrowUsed, setErrorDefined, getErrorDefined, incrementLine, incrementWord,
getLineIndex, getWordIndex, resetIndices, useVarName, genVarNameIf,
setVarScope, getVarScope)
import Prelude hiding (break,print,(<>),sin,cos,tan,floor)
import Control.Lens.Zoom (zoom)
import Control.Monad.State (modify)
import Data.Composition ((.:))
import Data.List (intercalate, sort)
import Data.Map (findWithDefault)
import Data.Maybe (fromMaybe, isNothing)
import Text.PrettyPrint.HughesPJ (Doc, text, (<>), (<+>), parens, empty, equals,
vcat, lbrace, rbrace, braces, brackets, colon, space, doubleQuotes)
import qualified Text.PrettyPrint.HughesPJ as D (float)
swiftExt :: String
swiftExt :: String
swiftExt = String
"swift"
newtype SwiftCode a = SC {forall a. SwiftCode a -> a
unSC :: a} deriving SwiftCode a -> SwiftCode a -> Bool
(SwiftCode a -> SwiftCode a -> Bool)
-> (SwiftCode a -> SwiftCode a -> Bool) -> Eq (SwiftCode a)
forall a. Eq a => SwiftCode a -> SwiftCode a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => SwiftCode a -> SwiftCode a -> Bool
== :: SwiftCode a -> SwiftCode a -> Bool
$c/= :: forall a. Eq a => SwiftCode a -> SwiftCode a -> Bool
/= :: SwiftCode a -> SwiftCode a -> Bool
Eq
instance Functor SwiftCode where
fmap :: forall a b. (a -> b) -> SwiftCode a -> SwiftCode b
fmap a -> b
f (SC a
x) = b -> SwiftCode b
forall a. a -> SwiftCode a
SC (a -> b
f a
x)
instance Applicative SwiftCode where
pure :: forall a. a -> SwiftCode a
pure = a -> SwiftCode a
forall a. a -> SwiftCode a
SC
(SC a -> b
f) <*> :: forall a b. SwiftCode (a -> b) -> SwiftCode a -> SwiftCode b
<*> (SC a
x) = b -> SwiftCode b
forall a. a -> SwiftCode a
SC (a -> b
f a
x)
instance Monad SwiftCode where
SC a
x >>= :: forall a b. SwiftCode a -> (a -> SwiftCode b) -> SwiftCode b
>>= a -> SwiftCode b
f = a -> SwiftCode b
f a
x
instance SharedProg SwiftCode Doc (Doc, Terminator) MethodData
instance SharedStatement SwiftCode (Doc, Terminator)
instance OOStatement SwiftCode (Doc, Terminator)
instance OOProg SwiftCode Doc (Doc, Terminator) MethodData StateVar Doc ProgData
instance ProgramSym SwiftCode Doc (Doc, Terminator) MethodData StateVar Doc ProgData where
prog :: String
-> String -> [FS (SwiftCode File)] -> GSProgram SwiftCode ProgData
prog String
n String
st [FS (SwiftCode File)]
files = do
[SwiftCode File]
fs <- (FS (SwiftCode File) -> StateT GOOLState Identity (SwiftCode File))
-> [FS (SwiftCode File)]
-> StateT GOOLState Identity [SwiftCode File]
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) (SwiftCode File))
GOOLState
FileState
-> FS (SwiftCode File)
-> StateT GOOLState Identity (SwiftCode File)
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) (SwiftCode File))
GOOLState
FileState
(FileState -> Focusing Identity (SwiftCode File) FileState)
-> GOOLState -> Focusing Identity (SwiftCode File) GOOLState
Lens' GOOLState FileState
lensGStoFS) [FS (SwiftCode File)]
files
(GOOLState -> GOOLState) -> StateT GOOLState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify GOOLState -> GOOLState
revFiles
SwiftCode ProgData -> GSProgram SwiftCode ProgData
forall a. a -> StateT GOOLState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SwiftCode ProgData -> GSProgram SwiftCode ProgData)
-> SwiftCode ProgData -> GSProgram SwiftCode ProgData
forall a b. (a -> b) -> a -> b
$ ([File] -> ProgData) -> [SwiftCode File] -> SwiftCode ProgData
forall (m :: * -> *) a b. Monad m => ([a] -> b) -> [m a] -> m b
onCodeList (String -> String -> [File] -> ProgData
progD String
n String
st) [SwiftCode File]
fs
instance CommonRenderSym SwiftCode Doc (Doc, Terminator) MethodData
instance OORenderSym SwiftCode Doc (Doc, Terminator) MethodData StateVar Doc
instance UnRepr SwiftCode contents where
unRepr :: SwiftCode contents -> contents
unRepr = SwiftCode contents -> contents
forall a. SwiftCode a -> a
unSC
instance FileSym SwiftCode Doc (Doc, Terminator) MethodData StateVar Doc where
fileDoc :: FS (SwiftCode Module) -> FS (SwiftCode File)
fileDoc FS (SwiftCode Module)
m = do
(FileState -> FileState) -> StateT FileState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (FileType -> FileState -> FileState
setFileType FileType
Combined)
String
-> (SwiftCode Module -> SwiftCode Doc)
-> SwiftCode Doc
-> FS (SwiftCode Module)
-> FS (SwiftCode File)
forall (r :: * -> *).
(BlockElim r, RenderMod r, RenderFile r) =>
String
-> (r Module -> r Doc) -> r Doc -> FS (r Module) -> FS (r File)
G.fileDoc String
swiftExt SwiftCode Module -> SwiftCode Doc
forall (r :: * -> *). RenderFile r => r Module -> r Doc
top SwiftCode Doc
forall (r :: * -> *). RenderFile r => r Doc
bottom FS (SwiftCode Module)
m
docMod :: String
-> String
-> [String]
-> String
-> FS (SwiftCode File)
-> FS (SwiftCode File)
docMod = ModuleDocRenderer
-> String
-> String
-> String
-> [String]
-> String
-> FS (SwiftCode File)
-> FS (SwiftCode File)
forall (r :: * -> *).
RenderFile r =>
ModuleDocRenderer
-> String
-> String
-> String
-> [String]
-> String
-> FS (r File)
-> FS (r File)
G.docMod ModuleDocRenderer
CP.modDoc' String
swiftExt
instance RenderFile SwiftCode where
top :: SwiftCode Module -> SwiftCode Doc
top SwiftCode Module
_ = Doc -> SwiftCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
empty
bottom :: SwiftCode Doc
bottom = Doc -> SwiftCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
empty
commentedMod :: FS (SwiftCode File) -> FS (SwiftCode Doc) -> FS (SwiftCode File)
commentedMod = (SwiftCode File -> SwiftCode Doc -> SwiftCode File)
-> FS (SwiftCode File) -> FS (SwiftCode Doc) -> FS (SwiftCode File)
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues ((File -> Doc -> File)
-> SwiftCode File -> SwiftCode Doc -> SwiftCode File
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues File -> Doc -> File
R.commentedMod)
fileFromData :: String -> FS (SwiftCode Module) -> FS (SwiftCode File)
fileFromData = (String -> SwiftCode Module -> SwiftCode File)
-> String -> FS (SwiftCode Module) -> FS (SwiftCode File)
forall (r :: * -> *).
ModuleElim r =>
(String -> r Module -> r File)
-> String -> FS (r Module) -> FS (r File)
G.fileFromData ((Module -> File) -> SwiftCode Module -> SwiftCode File
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ((Module -> File) -> SwiftCode Module -> SwiftCode File)
-> (String -> Module -> File)
-> String
-> SwiftCode Module
-> SwiftCode File
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Module -> File
fileD)
instance ImportSym SwiftCode where
langImport :: String -> SwiftCode Doc
langImport String
n = Doc -> SwiftCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> SwiftCode Doc) -> Doc -> SwiftCode Doc
forall a b. (a -> b) -> a -> b
$ Doc
importLabel Doc -> Doc -> Doc
<+> String -> Doc
text String
n
modImport :: String -> SwiftCode Doc
modImport = String -> SwiftCode Doc
forall (r :: * -> *). ImportSym r => String -> r Doc
langImport
instance AttachmentSym SwiftCode Doc where
classLevel :: SwiftCode Doc
classLevel = Doc -> SwiftCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
R.classLevel
instanceLevel :: SwiftCode Doc
instanceLevel = Doc -> SwiftCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
R.instanceLevel
instance PermElim SwiftCode Doc where
perm :: SwiftCode Doc -> Doc
perm = SwiftCode Doc -> Doc
forall a. SwiftCode a -> a
unSC
binding :: SwiftCode Doc -> AttachmentTag
binding = String -> SwiftCode Doc -> AttachmentTag
forall a. HasCallStack => String -> a
error (String -> SwiftCode Doc -> AttachmentTag)
-> String -> SwiftCode Doc -> AttachmentTag
forall a b. (a -> b) -> a -> b
$ String -> String
CP.bindingError String
swiftName
instance BodySym SwiftCode (Doc, Terminator) where
body :: [MS (SwiftCode Doc)] -> MS (SwiftCode Doc)
body = ([SwiftCode Doc] -> SwiftCode Doc)
-> [MS (SwiftCode Doc)] -> MS (SwiftCode Doc)
forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList (([Doc] -> Doc) -> [SwiftCode Doc] -> SwiftCode Doc
forall (m :: * -> *) a b. Monad m => ([a] -> b) -> [m a] -> m b
onCodeList [Doc] -> Doc
R.body)
addComments :: String -> MS (SwiftCode Doc) -> MS (SwiftCode Doc)
addComments String
s = (SwiftCode Doc -> SwiftCode Doc)
-> MS (SwiftCode Doc) -> MS (SwiftCode Doc)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue ((Doc -> Doc) -> SwiftCode Doc -> SwiftCode Doc
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue (String -> Doc -> Doc -> Doc
R.addComments String
s Doc
commentStart))
instance RenderBody SwiftCode where
multiBody :: [MS (SwiftCode Doc)] -> MS (SwiftCode Doc)
multiBody = [MS (SwiftCode Doc)] -> MS (SwiftCode Doc)
forall (r :: * -> *).
(BodyElim r, Monad r) =>
[MS (r Doc)] -> MS (r Doc)
G.multiBody
instance BodyElim SwiftCode where
body :: SwiftCode Doc -> Doc
body = SwiftCode Doc -> Doc
forall a. SwiftCode a -> a
unSC
instance BlockSym SwiftCode (Doc, Terminator) where
block :: [MS (SwiftCode (Doc, Terminator))] -> MS (SwiftCode Doc)
block = [MS (SwiftCode (Doc, Terminator))] -> MS (SwiftCode Doc)
forall (r :: * -> *) smt.
(Monad r, RenderStatement r smt, StatementElim r smt) =>
[MS (r smt)] -> MS (r Doc)
G.block
instance RenderBlock SwiftCode where
multiBlock :: [MS (SwiftCode Doc)] -> MS (SwiftCode Doc)
multiBlock = [MS (SwiftCode Doc)] -> MS (SwiftCode Doc)
forall (r :: * -> *).
(BlockElim r, Monad r) =>
[MS (r Doc)] -> MS (r Doc)
G.multiBlock
instance BlockElim SwiftCode where
block :: SwiftCode Doc -> Doc
block = SwiftCode Doc -> Doc
forall a. SwiftCode a -> a
unSC
instance TypeSym SwiftCode where
bool :: VS (SwiftCode TypeData)
bool = VS (SwiftCode TypeData)
forall (r :: * -> *). Monad r => VS (r TypeData)
CS.bool
int :: VS (SwiftCode TypeData)
int = VS (SwiftCode TypeData)
forall (r :: * -> *). Monad r => VS (r TypeData)
swiftIntType
float :: VS (SwiftCode TypeData)
float = VS (SwiftCode TypeData)
forall (r :: * -> *). Monad r => VS (r TypeData)
CP.float
double :: VS (SwiftCode TypeData)
double = VS (SwiftCode TypeData)
forall (r :: * -> *). Monad r => VS (r TypeData)
CP.double
char :: VS (SwiftCode TypeData)
char = VS (SwiftCode TypeData)
forall (r :: * -> *). Monad r => VS (r TypeData)
swiftCharType
string :: VS (SwiftCode TypeData)
string = VS (SwiftCode TypeData)
forall (r :: * -> *). Monad r => VS (r TypeData)
CP.string'
infile :: VS (SwiftCode TypeData)
infile = VS (SwiftCode TypeData)
forall (r :: * -> *). Monad r => VS (r TypeData)
swiftFileType
outfile :: VS (SwiftCode TypeData)
outfile = VS (SwiftCode TypeData)
forall (r :: * -> *). Monad r => VS (r TypeData)
swiftFileHdlType
referenceType :: VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
referenceType = VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
forall a. a -> a
id
listType :: VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
listType = VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
swiftListType
arrayType :: VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
arrayType = VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType
setType :: VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
setType = VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType
innerType :: VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
innerType = VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
forall (r :: * -> *).
(TypeElim r, OOTypeSym r) =>
VS (r TypeData) -> VS (r TypeData)
CG.innerType
funcType :: [VS (SwiftCode TypeData)]
-> VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
funcType = [VS (SwiftCode TypeData)]
-> VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
swiftFuncType
void :: VS (SwiftCode TypeData)
void = VS (SwiftCode TypeData)
forall (r :: * -> *). Monad r => VS (r TypeData)
swiftVoidType
instance TypeElim SwiftCode where
getCodeType :: SwiftCode TypeData -> CodeType
getCodeType = TypeData -> CodeType
cType (TypeData -> CodeType)
-> (SwiftCode TypeData -> TypeData)
-> SwiftCode TypeData
-> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode TypeData -> TypeData
forall a. SwiftCode a -> a
unSC
instance OOTypeSym SwiftCode where
obj :: String -> VS (SwiftCode TypeData)
obj = String -> VS (SwiftCode TypeData)
forall (r :: * -> *). Monad r => String -> VS (r TypeData)
G.obj
instance RenderType SwiftCode where
multiType :: [VS (SwiftCode TypeData)] -> VS (SwiftCode TypeData)
multiType [VS (SwiftCode TypeData)]
ts = do
[SwiftCode TypeData]
typs <- [VS (SwiftCode TypeData)]
-> StateT ValueState Identity [SwiftCode TypeData]
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 (SwiftCode TypeData)]
ts
let mt :: String
mt = [String] -> String
tuple ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ (SwiftCode TypeData -> String) -> [SwiftCode TypeData] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map SwiftCode TypeData -> String
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> String
getTypeString [SwiftCode TypeData]
typs
CodeType -> String -> Doc -> VS (SwiftCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
Void String
mt (String -> Doc
text String
mt)
instance UnaryOpSym SwiftCode where
notOp :: VSUnOp SwiftCode
notOp = VSUnOp SwiftCode
forall (r :: * -> *). Monad r => VSOp r
C.notOp
negateOp :: VSUnOp SwiftCode
negateOp = VSUnOp SwiftCode
forall (r :: * -> *). Monad r => VSOp r
G.negateOp
sqrtOp :: VSUnOp SwiftCode
sqrtOp = String -> VSUnOp SwiftCode
forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.sqrt
absOp :: VSUnOp SwiftCode
absOp = String -> VSUnOp SwiftCode
forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.abs
logOp :: VSUnOp SwiftCode
logOp = String -> VSUnOp SwiftCode
forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.log10
lnOp :: VSUnOp SwiftCode
lnOp = String -> VSUnOp SwiftCode
forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.log
expOp :: VSUnOp SwiftCode
expOp = String -> VSUnOp SwiftCode
forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.exp
sinOp :: VSUnOp SwiftCode
sinOp = String -> VSUnOp SwiftCode
forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.sin
cosOp :: VSUnOp SwiftCode
cosOp = String -> VSUnOp SwiftCode
forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.cos
tanOp :: VSUnOp SwiftCode
tanOp = String -> VSUnOp SwiftCode
forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.tan
asinOp :: VSUnOp SwiftCode
asinOp = String -> VSUnOp SwiftCode
forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.asin
acosOp :: VSUnOp SwiftCode
acosOp = String -> VSUnOp SwiftCode
forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.acos
atanOp :: VSUnOp SwiftCode
atanOp = String -> VSUnOp SwiftCode
forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.atan
floorOp :: VSUnOp SwiftCode
floorOp = String -> VSUnOp SwiftCode
forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.floor
ceilOp :: VSUnOp SwiftCode
ceilOp = String -> VSUnOp SwiftCode
forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.ceil
instance BinaryOpSym SwiftCode where
equalOp :: VSUnOp SwiftCode
equalOp = VSUnOp SwiftCode
forall (r :: * -> *). Monad r => VSOp r
G.equalOp
notEqualOp :: VSUnOp SwiftCode
notEqualOp = VSUnOp SwiftCode
forall (r :: * -> *). Monad r => VSOp r
G.notEqualOp
greaterOp :: VSUnOp SwiftCode
greaterOp = VSUnOp SwiftCode
forall (r :: * -> *). Monad r => VSOp r
G.greaterOp
greaterEqualOp :: VSUnOp SwiftCode
greaterEqualOp = VSUnOp SwiftCode
forall (r :: * -> *). Monad r => VSOp r
G.greaterEqualOp
lessOp :: VSUnOp SwiftCode
lessOp = VSUnOp SwiftCode
forall (r :: * -> *). Monad r => VSOp r
G.lessOp
lessEqualOp :: VSUnOp SwiftCode
lessEqualOp = VSUnOp SwiftCode
forall (r :: * -> *). Monad r => VSOp r
G.lessEqualOp
plusOp :: VSUnOp SwiftCode
plusOp = VSUnOp SwiftCode
forall (r :: * -> *). Monad r => VSOp r
G.plusOp
minusOp :: VSUnOp SwiftCode
minusOp = VSUnOp SwiftCode
forall (r :: * -> *). Monad r => VSOp r
G.minusOp
multOp :: VSUnOp SwiftCode
multOp = VSUnOp SwiftCode
forall (r :: * -> *). Monad r => VSOp r
G.multOp
divideOp :: VSUnOp SwiftCode
divideOp = VSUnOp SwiftCode
forall (r :: * -> *). Monad r => VSOp r
G.divideOp
powerOp :: VSUnOp SwiftCode
powerOp = VSUnOp SwiftCode -> VSUnOp SwiftCode
forall a. VS a -> VS a
addMathImport (VSUnOp SwiftCode -> VSUnOp SwiftCode)
-> VSUnOp SwiftCode -> VSUnOp SwiftCode
forall a b. (a -> b) -> a -> b
$ String -> VSUnOp SwiftCode
forall (r :: * -> *). Monad r => String -> VSOp r
powerPrec String
R.pow
moduloOp :: VSUnOp SwiftCode
moduloOp = VSUnOp SwiftCode
forall (r :: * -> *). Monad r => VSOp r
G.moduloOp
andOp :: VSUnOp SwiftCode
andOp = VSUnOp SwiftCode
forall (r :: * -> *). Monad r => VSOp r
C.andOp
orOp :: VSUnOp SwiftCode
orOp = VSUnOp SwiftCode
forall (r :: * -> *). Monad r => VSOp r
C.orOp
instance OpElim SwiftCode where
uOp :: SwiftCode OpData -> Doc
uOp = OpData -> Doc
opDoc (OpData -> Doc)
-> (SwiftCode OpData -> OpData) -> SwiftCode OpData -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode OpData -> OpData
forall a. SwiftCode a -> a
unSC
bOp :: SwiftCode OpData -> Doc
bOp = OpData -> Doc
opDoc (OpData -> Doc)
-> (SwiftCode OpData -> OpData) -> SwiftCode OpData -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode OpData -> OpData
forall a. SwiftCode a -> a
unSC
uOpPrec :: SwiftCode OpData -> Int
uOpPrec = OpData -> Int
opPrec (OpData -> Int)
-> (SwiftCode OpData -> OpData) -> SwiftCode OpData -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode OpData -> OpData
forall a. SwiftCode a -> a
unSC
bOpPrec :: SwiftCode OpData -> Int
bOpPrec = OpData -> Int
opPrec (OpData -> Int)
-> (SwiftCode OpData -> OpData) -> SwiftCode OpData -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode OpData -> OpData
forall a. SwiftCode a -> a
unSC
instance ScopeSym SwiftCode where
global :: SwiftCode ScopeData
global = SwiftCode ScopeData
forall (r :: * -> *). Monad r => r ScopeData
CP.global
mainFn :: SwiftCode ScopeData
mainFn = SwiftCode ScopeData
forall (r :: * -> *). ScopeSym r => r ScopeData
global
local :: SwiftCode ScopeData
local = SwiftCode ScopeData
forall (r :: * -> *). Monad r => r ScopeData
G.local
instance ScopeElim SwiftCode where
scopeData :: SwiftCode ScopeData -> ScopeData
scopeData = SwiftCode ScopeData -> ScopeData
forall a. SwiftCode a -> a
unSC
instance VariableSym SwiftCode where
var :: String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
var = String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
RenderVariable r =>
String -> VS (r TypeData) -> SVariable r
G.var
constant :: String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
constant = String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var
extVar :: String -> String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
extVar String
_ = String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var
instance OOVariableSym SwiftCode where
classVar :: String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
classVar = String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
RenderVariable r =>
String -> VS (r TypeData) -> SVariable r
G.classVar
classConst :: String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
classConst = String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
OOVariableSym r =>
String -> VS (r TypeData) -> SVariable r
classVar
classVarAccess :: VS (SwiftCode TypeData)
-> SVariable SwiftCode -> SVariable SwiftCode
classVarAccess = (Doc -> Doc -> Doc)
-> VS (SwiftCode TypeData)
-> SVariable SwiftCode
-> SVariable SwiftCode
forall (r :: * -> *).
(InternalVarElim r, RenderVariable r, UnRepr r TypeData,
VariableElim r) =>
(Doc -> Doc -> Doc)
-> VS (r TypeData) -> SVariable r -> SVariable r
CP.classVarAccess Doc -> Doc -> Doc
R.classVarAccess
extClassVarAccess :: VS (SwiftCode TypeData)
-> SVariable SwiftCode -> SVariable SwiftCode
extClassVarAccess = VS (SwiftCode TypeData)
-> SVariable SwiftCode -> SVariable SwiftCode
forall (r :: * -> *).
OOVariableSym r =>
VS (r TypeData) -> SVariable r -> SVariable r
classVarAccess
instanceVarAccess :: SValue SwiftCode -> SVariable SwiftCode -> SVariable SwiftCode
instanceVarAccess = SValue SwiftCode -> SVariable SwiftCode -> SVariable SwiftCode
forall (r :: * -> *).
(InternalVarElim r, RenderVariable r, ValueElim r,
VariableElim r) =>
SValue r -> SVariable r -> SVariable r
G.instanceVarAccess
instance SelfSym SwiftCode where
self :: SVariable SwiftCode
self = SVariable SwiftCode
forall (r :: * -> *).
(OOTypeSym r, RenderVariable r) =>
SVariable r
CP.self
instance VariableElim SwiftCode where
variableName :: SwiftCode Variable -> String
variableName = Variable -> String
varName (Variable -> String)
-> (SwiftCode Variable -> Variable) -> SwiftCode Variable -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode Variable -> Variable
forall a. SwiftCode a -> a
unSC
variableType :: SwiftCode Variable -> SwiftCode TypeData
variableType = (Variable -> TypeData) -> SwiftCode Variable -> SwiftCode TypeData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue Variable -> TypeData
varType
instance InternalVarElim SwiftCode where
variableBind :: SwiftCode Variable -> AttachmentTag
variableBind = Variable -> AttachmentTag
varBind (Variable -> AttachmentTag)
-> (SwiftCode Variable -> Variable)
-> SwiftCode Variable
-> AttachmentTag
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode Variable -> Variable
forall a. SwiftCode a -> a
unSC
variable :: SwiftCode Variable -> Doc
variable = Variable -> Doc
varDoc (Variable -> Doc)
-> (SwiftCode Variable -> Variable) -> SwiftCode Variable -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode Variable -> Variable
forall a. SwiftCode a -> a
unSC
instance RenderVariable SwiftCode where
varFromData :: AttachmentTag
-> String -> VS (SwiftCode TypeData) -> Doc -> SVariable SwiftCode
varFromData AttachmentTag
b String
n VS (SwiftCode TypeData)
t' Doc
d = do
SwiftCode TypeData
t <- VS (SwiftCode TypeData)
t'
SwiftCode Variable -> SVariable SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SwiftCode Variable -> SVariable SwiftCode)
-> SwiftCode Variable -> SVariable SwiftCode
forall a b. (a -> b) -> a -> b
$ (TypeData -> Doc -> Variable)
-> SwiftCode TypeData -> SwiftCode Doc -> SwiftCode Variable
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues (AttachmentTag -> String -> TypeData -> Doc -> Variable
vard AttachmentTag
b String
n) SwiftCode TypeData
t (Doc -> SwiftCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
d)
instance ValueSym SwiftCode where
valueType :: SwiftCode Value -> SwiftCode TypeData
valueType = (Value -> TypeData) -> SwiftCode Value -> SwiftCode TypeData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue Value -> TypeData
valType
instance OOValueSym SwiftCode
instance Argument SwiftCode where
pointerArg :: SValue SwiftCode -> SValue SwiftCode
pointerArg = SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r
swiftArgVal
instance Literal SwiftCode where
litTrue :: SValue SwiftCode
litTrue = SValue SwiftCode
forall (r :: * -> *). (RenderValue r, TypeSym r) => SValue r
C.litTrue
litFalse :: SValue SwiftCode
litFalse = SValue SwiftCode
forall (r :: * -> *). (RenderValue r, TypeSym r) => SValue r
C.litFalse
litChar :: Char -> SValue SwiftCode
litChar = (Doc -> Doc) -> Char -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, TypeSym r) =>
(Doc -> Doc) -> Char -> SValue r
G.litChar Doc -> Doc
doubleQuotes
litDouble :: Double -> SValue SwiftCode
litDouble = Double -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, TypeSym r) =>
Double -> SValue r
G.litDouble
litFloat :: Float -> SValue SwiftCode
litFloat = Float -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, TypeSym r) =>
Float -> SValue r
swiftLitFloat
litInt :: Integer -> SValue SwiftCode
litInt = Integer -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, TypeSym r) =>
Integer -> SValue r
G.litInt
litString :: String -> SValue SwiftCode
litString = String -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, TypeSym r) =>
String -> SValue r
G.litString
litArray :: VS (SwiftCode TypeData) -> [SValue SwiftCode] -> SValue SwiftCode
litArray = (Doc -> Doc)
-> VS (SwiftCode TypeData)
-> [SValue SwiftCode]
-> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, TypeSym r, ValueElim r) =>
(Doc -> Doc) -> VS (r TypeData) -> [SValue r] -> SValue r
CP.litArray Doc -> Doc
brackets
litSet :: VS (SwiftCode TypeData) -> [SValue SwiftCode] -> SValue SwiftCode
litSet = VS (SwiftCode TypeData) -> [SValue SwiftCode] -> SValue SwiftCode
forall (r :: * -> *).
Literal r =>
VS (r TypeData) -> [SValue r] -> SValue r
litArray
litList :: VS (SwiftCode TypeData) -> [SValue SwiftCode] -> SValue SwiftCode
litList = VS (SwiftCode TypeData) -> [SValue SwiftCode] -> SValue SwiftCode
forall (r :: * -> *).
Literal r =>
VS (r TypeData) -> [SValue r] -> SValue r
litArray
instance MathConstant SwiftCode where
pi :: SValue SwiftCode
pi = VS (SwiftCode TypeData) -> Doc -> SValue SwiftCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
double Doc
swiftPi
instance VariableValue SwiftCode where
valueOf :: SVariable SwiftCode -> SValue SwiftCode
valueOf = SVariable SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(InternalVarElim r, RenderValue r, VariableElim r) =>
SVariable r -> SValue r
G.valueOf
instance OOVariableValue SwiftCode
instance CommandLineArgs SwiftCode where
arg :: Integer -> SValue SwiftCode
arg Integer
n = SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, TypeSym r, ValueElim r) =>
SValue r -> SValue r -> SValue r
G.arg (Integer -> SValue SwiftCode
forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
n) SValue SwiftCode
forall (r :: * -> *). CommandLineArgs r => SValue r
argsList
argsList :: SValue SwiftCode
argsList = String -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, TypeSym r) =>
String -> SValue r
G.argsList (String
swiftCommLine String -> String -> String
`access` String
swiftArgs)
argExists :: Integer -> SValue SwiftCode
argExists Integer
i = SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *) smt. List r smt => SValue r -> SValue r
listSize SValue SwiftCode
forall (r :: * -> *). CommandLineArgs r => SValue r
argsList SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?> Integer -> SValue SwiftCode
forall (r :: * -> *). Literal r => Integer -> SValue r
litInt (Integer -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i)
instance NumericExpression SwiftCode where
#~ :: SValue SwiftCode -> SValue SwiftCode
(#~) = VSUnOp SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr' VSUnOp SwiftCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
negateOp
#/^ :: SValue SwiftCode -> SValue SwiftCode
(#/^) = VSUnOp SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp SwiftCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
sqrtOp
#| :: SValue SwiftCode -> SValue SwiftCode
(#|) = VSUnOp SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp SwiftCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
absOp
#+ :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(#+) = (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftNumBinExpr (VSUnOp SwiftCode
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, TypeElim r, ValueElim r, ValueSym r) =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr VSUnOp SwiftCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
plusOp)
#- :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(#-) = (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftNumBinExpr (VSUnOp SwiftCode
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, TypeElim r, ValueElim r, ValueSym r) =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr VSUnOp SwiftCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
minusOp)
#* :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(#*) = (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftNumBinExpr (VSUnOp SwiftCode
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, TypeElim r, ValueElim r, ValueSym r) =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr VSUnOp SwiftCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
multOp)
#/ :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(#/) = (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftNumBinExpr (VSUnOp SwiftCode
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, TypeElim r, ValueElim r, ValueSym r) =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr VSUnOp SwiftCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
divideOp)
#% :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(#%) = VSUnOp SwiftCode
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, TypeElim r, ValueElim r, ValueSym r) =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr VSUnOp SwiftCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
moduloOp
#^ :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(#^) SValue SwiftCode
v1' SValue SwiftCode
v2' = do
SwiftCode Value
v1 <- SValue SwiftCode
v1'
SwiftCode Value
v2 <- SValue SwiftCode
v2'
let swiftPower :: CodeType -> CodeType -> SValue r -> SValue r -> SValue r
swiftPower CodeType
Integer CodeType
Integer SValue r
b SValue r
e = VS (r TypeData) -> SValue r -> SValue r
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> SValue r -> SValue r
cast VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
int (SValue r -> SValue r) -> SValue r -> SValue r
forall a b. (a -> b) -> a -> b
$ VSBinOp r -> SValue r -> SValue r -> SValue r
forall (r :: * -> *).
(OpElim r, RenderValue r, TypeElim r, ValueElim r, ValueSym r) =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr' VSBinOp r
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
powerOp
(VS (r TypeData) -> SValue r -> SValue r
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> SValue r -> SValue r
cast VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
double SValue r
b) (VS (r TypeData) -> SValue r -> SValue r
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> SValue r -> SValue r
cast VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
double SValue r
e)
swiftPower CodeType
_ CodeType
_ SValue r
b SValue r
e = VSBinOp r -> SValue r -> SValue r -> SValue r
forall (r :: * -> *).
(OpElim r, RenderValue r, TypeElim r, ValueElim r, ValueSym r) =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr' VSBinOp r
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
powerOp SValue r
b SValue r
e
CodeType
-> CodeType
-> SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
forall {r :: * -> *}.
(RenderValue r, OpElim r, TypeElim r, ValueElim r, ValueSym r,
BinaryOpSym r) =>
CodeType -> CodeType -> SValue r -> SValue r -> SValue r
swiftPower (SwiftCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (SwiftCode TypeData -> CodeType) -> SwiftCode TypeData -> CodeType
forall a b. (a -> b) -> a -> b
$ SwiftCode Value -> SwiftCode TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType SwiftCode Value
v1) (SwiftCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (SwiftCode TypeData -> CodeType) -> SwiftCode TypeData -> CodeType
forall a b. (a -> b) -> a -> b
$ SwiftCode Value -> SwiftCode TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType SwiftCode Value
v2) (SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v1)
(SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v2)
log :: SValue SwiftCode -> SValue SwiftCode
log = VSUnOp SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp SwiftCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
logOp
ln :: SValue SwiftCode -> SValue SwiftCode
ln = VSUnOp SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp SwiftCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
lnOp
exp :: SValue SwiftCode -> SValue SwiftCode
exp = VSUnOp SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp SwiftCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
expOp
sin :: SValue SwiftCode -> SValue SwiftCode
sin = VSUnOp SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp SwiftCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
sinOp
cos :: SValue SwiftCode -> SValue SwiftCode
cos = VSUnOp SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp SwiftCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
cosOp
tan :: SValue SwiftCode -> SValue SwiftCode
tan = VSUnOp SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp SwiftCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
tanOp
csc :: SValue SwiftCode -> SValue SwiftCode
csc = SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(Literal r, NumericExpression r, TypeElim r) =>
SValue r -> SValue r
G.csc
sec :: SValue SwiftCode -> SValue SwiftCode
sec = SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(Literal r, NumericExpression r, TypeElim r) =>
SValue r -> SValue r
G.sec
cot :: SValue SwiftCode -> SValue SwiftCode
cot = SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(Literal r, NumericExpression r, TypeElim r) =>
SValue r -> SValue r
G.cot
arcsin :: SValue SwiftCode -> SValue SwiftCode
arcsin = VSUnOp SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp SwiftCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
asinOp
arccos :: SValue SwiftCode -> SValue SwiftCode
arccos = VSUnOp SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp SwiftCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
acosOp
arctan :: SValue SwiftCode -> SValue SwiftCode
arctan = VSUnOp SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp SwiftCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
atanOp
floor :: SValue SwiftCode -> SValue SwiftCode
floor = VSUnOp SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp SwiftCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
floorOp
ceil :: SValue SwiftCode -> SValue SwiftCode
ceil = VSUnOp SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp SwiftCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
ceilOp
instance BooleanExpression SwiftCode where
?! :: SValue SwiftCode -> SValue SwiftCode
(?!) = VSUnOp SwiftCode
-> VS (SwiftCode TypeData) -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSUnOp r -> VS (r TypeData) -> SValue r -> SValue r
typeUnExpr VSUnOp SwiftCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
notOp VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool
?&& :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?&&) = VSUnOp SwiftCode
-> VS (SwiftCode TypeData)
-> SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp SwiftCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
andOp VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool
?|| :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?||) = VSUnOp SwiftCode
-> VS (SwiftCode TypeData)
-> SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp SwiftCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
orOp VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool
instance Comparison SwiftCode where
?< :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?<) = (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftNumBinExpr (VSUnOp SwiftCode
-> VS (SwiftCode TypeData)
-> SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp SwiftCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
lessOp VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool)
?<= :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?<=) = (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftNumBinExpr (VSUnOp SwiftCode
-> VS (SwiftCode TypeData)
-> SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp SwiftCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
lessEqualOp VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool)
?> :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?>) = (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftNumBinExpr (VSUnOp SwiftCode
-> VS (SwiftCode TypeData)
-> SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp SwiftCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
greaterOp VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool)
?>= :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?>=) = (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftNumBinExpr (VSUnOp SwiftCode
-> VS (SwiftCode TypeData)
-> SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp SwiftCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
greaterEqualOp VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool)
?== :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?==) = (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftNumBinExpr (VSUnOp SwiftCode
-> VS (SwiftCode TypeData)
-> SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp SwiftCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
equalOp VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool)
?!= :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?!=) = (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftNumBinExpr (VSUnOp SwiftCode
-> VS (SwiftCode TypeData)
-> SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp SwiftCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
notEqualOp VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool)
instance ValueExpression SwiftCode where
inlineIf :: SValue SwiftCode
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
inlineIf = SValue SwiftCode
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r -> SValue r -> SValue r
C.inlineIf
funcAppMixedArgs :: MixedCall SwiftCode
funcAppMixedArgs = MixedCall SwiftCode
forall (r :: * -> *). RenderValue r => MixedCall r
G.funcAppMixedArgs
extFuncAppMixedArgs :: String -> MixedCall SwiftCode
extFuncAppMixedArgs = String -> MixedCall SwiftCode
forall (r :: * -> *). RenderValue r => String -> MixedCall r
CS.extFuncAppMixedArgs
libFuncAppMixedArgs :: String -> MixedCall SwiftCode
libFuncAppMixedArgs = String -> MixedCall SwiftCode
forall (r :: * -> *). ValueExpression r => String -> MixedCall r
C.libFuncAppMixedArgs
lambda :: [VSBinder SwiftCode] -> SValue SwiftCode -> SValue SwiftCode
lambda = ([SwiftCode BinderD] -> SwiftCode Value -> Doc)
-> [VSBinder SwiftCode] -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(BinderElim r, RenderValue r, ValueSym r) =>
([r BinderD] -> r Value -> Doc)
-> [VSBinder r] -> SValue r -> SValue r
G.lambda [SwiftCode BinderD] -> SwiftCode Value -> Doc
swiftLambda
notNull :: SValue SwiftCode -> SValue SwiftCode
notNull = String -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(Comparison r, VariableValue r) =>
String -> SValue r -> SValue r
CP.notNull String
swiftNil
instance OOValueExpression SwiftCode where
newObjMixedArgs :: MixedCtorCall SwiftCode
newObjMixedArgs = MixedCall SwiftCode
forall (r :: * -> *).
(RenderValue r, UnRepr r TypeData) =>
String -> MixedCtorCall r
G.newObjMixedArgs String
""
extNewObjMixedArgs :: MixedCall SwiftCode
extNewObjMixedArgs String
m VS (SwiftCode TypeData)
tp [SValue SwiftCode]
vs NamedArgs SwiftCode
ns = do
SwiftCode TypeData
t <- VS (SwiftCode TypeData)
tp
Maybe String -> Maybe Doc -> MixedCall SwiftCode
forall (r :: * -> *).
RenderValue r =>
Maybe String -> Maybe Doc -> MixedCall r
call (String -> Maybe String
forall a. a -> Maybe a
Just String
m) Maybe Doc
forall a. Maybe a
Nothing (SwiftCode TypeData -> String
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> String
getTypeString SwiftCode TypeData
t) (SwiftCode TypeData -> VS (SwiftCode TypeData)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode TypeData
t) [SValue SwiftCode]
vs NamedArgs SwiftCode
ns
libNewObjMixedArgs :: MixedCall SwiftCode
libNewObjMixedArgs = MixedCall SwiftCode
forall (r :: * -> *).
OOValueExpression r =>
String -> MixedCtorCall r
C.libNewObjMixedArgs
instance RenderValue SwiftCode where
inputFunc :: SValue SwiftCode
inputFunc = VS (SwiftCode TypeData) -> Doc -> SValue SwiftCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string Doc
empty
printFunc :: SValue SwiftCode
printFunc = VS (SwiftCode TypeData) -> Doc -> SValue SwiftCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
empty
printLnFunc :: SValue SwiftCode
printLnFunc = VS (SwiftCode TypeData) -> Doc -> SValue SwiftCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
empty
printFileFunc :: SValue SwiftCode -> SValue SwiftCode
printFileFunc SValue SwiftCode
_ = VS (SwiftCode TypeData) -> Doc -> SValue SwiftCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
empty
printFileLnFunc :: SValue SwiftCode -> SValue SwiftCode
printFileLnFunc SValue SwiftCode
_ = VS (SwiftCode TypeData) -> Doc -> SValue SwiftCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
empty
cast :: VS (SwiftCode TypeData) -> SValue SwiftCode -> SValue SwiftCode
cast = VS (SwiftCode TypeData) -> SValue SwiftCode -> SValue SwiftCode
swiftCast
call :: Maybe String -> Maybe Doc -> MixedCall SwiftCode
call Maybe String
l Maybe Doc
o String
n VS (SwiftCode TypeData)
t [SValue SwiftCode]
as NamedArgs SwiftCode
ns = do
String
mn <- LensLike'
(Zoomed (StateT FileState Identity) String) ValueState FileState
-> StateT FileState Identity String
-> StateT ValueState Identity String
forall c.
LensLike'
(Zoomed (StateT FileState Identity) c) ValueState FileState
-> StateT FileState Identity c -> StateT ValueState 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) String) ValueState FileState
(FileState -> Focusing Identity String FileState)
-> ValueState -> Focusing Identity String ValueState
Lens' ValueState FileState
lensVStoFS StateT FileState Identity String
getModuleName
Map QualifiedName [ExceptionType]
mem <- VS (Map QualifiedName [ExceptionType])
getMethodExcMap
let f :: SValue SwiftCode -> SValue SwiftCode
f = if [ExceptionType] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([ExceptionType] -> Bool) -> [ExceptionType] -> Bool
forall a b. (a -> b) -> a -> b
$ [ExceptionType]
-> QualifiedName
-> Map QualifiedName [ExceptionType]
-> [ExceptionType]
forall k a. Ord k => a -> k -> Map k a -> a
findWithDefault [] (QualifiedName
-> (String -> QualifiedName) -> Maybe String -> QualifiedName
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> String -> QualifiedName
qualName String
mn String
n) (String -> String -> QualifiedName
`qualName` String
n)
Maybe String
l) Map QualifiedName [ExceptionType]
mem then SValue SwiftCode -> SValue SwiftCode
forall a. a -> a
id else SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r
swiftTryVal
SValue SwiftCode -> SValue SwiftCode
f (SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode
forall a b. (a -> b) -> a -> b
$ Doc -> Maybe String -> Maybe Doc -> MixedCall SwiftCode
forall (r :: * -> *).
(InternalVarElim r, RenderValue r, ValueElim r) =>
Doc -> Maybe String -> Maybe Doc -> MixedCall r
G.call Doc
swiftNamedArgSep Maybe String
forall a. Maybe a
Nothing Maybe Doc
o String
n VS (SwiftCode TypeData)
t [SValue SwiftCode]
as NamedArgs SwiftCode
ns
valFromData :: Maybe Int
-> Maybe Integer
-> VS (SwiftCode TypeData)
-> Doc
-> SValue SwiftCode
valFromData Maybe Int
p Maybe Integer
i VS (SwiftCode TypeData)
t' Doc
d = do
SwiftCode TypeData
t <- VS (SwiftCode TypeData)
t'
SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SwiftCode Value -> SValue SwiftCode)
-> SwiftCode Value -> SValue SwiftCode
forall a b. (a -> b) -> a -> b
$ (TypeData -> Doc -> Value)
-> SwiftCode TypeData -> SwiftCode Doc -> SwiftCode Value
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues (Maybe Int -> Maybe Integer -> TypeData -> Doc -> Value
vd Maybe Int
p Maybe Integer
i) SwiftCode TypeData
t (Doc -> SwiftCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
d)
instance ValueElim SwiftCode where
valuePrec :: SwiftCode Value -> Maybe Int
valuePrec = Value -> Maybe Int
valPrec (Value -> Maybe Int)
-> (SwiftCode Value -> Value) -> SwiftCode Value -> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode Value -> Value
forall a. SwiftCode a -> a
unSC
valueInt :: SwiftCode Value -> Maybe Integer
valueInt = Value -> Maybe Integer
valInt (Value -> Maybe Integer)
-> (SwiftCode Value -> Value) -> SwiftCode Value -> Maybe Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode Value -> Value
forall a. SwiftCode a -> a
unSC
value :: SwiftCode Value -> Doc
value = Value -> Doc
val (Value -> Doc)
-> (SwiftCode Value -> Value) -> SwiftCode Value -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode Value -> Value
forall a. SwiftCode a -> a
unSC
instance InternalValueExp SwiftCode where
objMethodCallMixedArgs' :: String
-> VS (SwiftCode TypeData)
-> SValue SwiftCode
-> [SValue SwiftCode]
-> NamedArgs SwiftCode
-> SValue SwiftCode
objMethodCallMixedArgs' = String
-> VS (SwiftCode TypeData)
-> SValue SwiftCode
-> [SValue SwiftCode]
-> NamedArgs SwiftCode
-> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueElim r) =>
String
-> VS (r TypeData)
-> SValue r
-> [SValue r]
-> NamedArgs r
-> SValue r
G.objMethodCall
classMethodCallMixedArgs' :: String -> VS (SwiftCode TypeData) -> MixedCtorCall SwiftCode
classMethodCallMixedArgs' = String -> VS (SwiftCode TypeData) -> MixedCtorCall SwiftCode
forall (r :: * -> *).
(RenderValue r, UnRepr r TypeData) =>
String
-> VS (r TypeData)
-> VS (r TypeData)
-> [SValue r]
-> NamedArgs r
-> SValue r
CG.classMethodCall
instance FunctionSym SwiftCode where
instance OOFunctionSym SwiftCode where
func :: String
-> VS (SwiftCode TypeData)
-> [SValue SwiftCode]
-> VS (SwiftCode FuncData)
func = String
-> VS (SwiftCode TypeData)
-> [SValue SwiftCode]
-> VS (SwiftCode FuncData)
forall (r :: * -> *).
(RenderFunction r, ValueElim r, ValueExpression r) =>
String -> VS (r TypeData) -> [SValue r] -> VS (r FuncData)
G.func
objAccess :: SValue SwiftCode -> VS (SwiftCode FuncData) -> SValue SwiftCode
objAccess = SValue SwiftCode -> VS (SwiftCode FuncData) -> SValue SwiftCode
forall (r :: * -> *).
(FunctionElim r, RenderValue r, ValueElim r) =>
SValue r -> VS (r FuncData) -> SValue r
G.objAccess
instance GetSet SwiftCode where
get :: SValue SwiftCode -> SVariable SwiftCode -> SValue SwiftCode
get = SValue SwiftCode -> SVariable SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(InternalGetSet r, OOFunctionSym r) =>
SValue r -> SVariable r -> SValue r
G.get
set :: SValue SwiftCode
-> SVariable SwiftCode -> SValue SwiftCode -> SValue SwiftCode
set = SValue SwiftCode
-> SVariable SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(InternalGetSet r, OOFunctionSym r) =>
SValue r -> SVariable r -> SValue r -> SValue r
G.set
instance IndexTranslator SwiftCode where
intToIndex :: SValue SwiftCode -> SValue SwiftCode
intToIndex = SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *). SValue r -> SValue r
CP.intToIndex
indexToInt :: SValue SwiftCode -> SValue SwiftCode
indexToInt = SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *). SValue r -> SValue r
CP.indexToInt
instance Reference SwiftCode where
makeRef :: SValue SwiftCode -> SValue SwiftCode
makeRef = SValue SwiftCode -> SValue SwiftCode
forall a. a -> a
id
maybeDeref :: SValue SwiftCode -> SValue SwiftCode
maybeDeref = SValue SwiftCode -> SValue SwiftCode
forall a. a -> a
id
instance Array SwiftCode where
arrayElem :: SValue SwiftCode -> SValue SwiftCode -> SVariable SwiftCode
arrayElem = SValue SwiftCode -> SValue SwiftCode -> SVariable SwiftCode
forall (r :: * -> *).
(IndexTranslator r, RenderVariable r, ValueElim r) =>
SValue r -> SValue r -> SVariable r
G.arrayElem
arrayLength :: SValue SwiftCode -> SValue SwiftCode
arrayLength = SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *) smt. List r smt => SValue r -> SValue r
listSize
arrayCopy :: SValue SwiftCode -> SValue SwiftCode
arrayCopy = SValue SwiftCode -> SValue SwiftCode
forall a. a -> a
id
instance List SwiftCode (Doc, Terminator) where
listSize :: SValue SwiftCode -> SValue SwiftCode
listSize = String -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(OOVariableSym r, VariableValue r) =>
String -> SValue r -> SValue r
C.listSize' String
swiftListSize
listAdd :: SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
listAdd SValue SwiftCode
list SValue SwiftCode
idx SValue SwiftCode
vl = let atArg :: SVariable SwiftCode
atArg = String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
swiftAt VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
int
in SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
StatementSym r smt =>
SValue r -> MS (r smt)
valStmt (SValue SwiftCode -> MS (SwiftCode (Doc, Terminator)))
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall a b. (a -> b) -> a -> b
$ VS (SwiftCode TypeData)
-> SValue SwiftCode
-> String
-> [SValue SwiftCode]
-> NamedArgs SwiftCode
-> SValue SwiftCode
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData)
-> SValue r -> String -> [SValue r] -> NamedArgs r -> SValue r
objMethodCallMixedArgs VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void SValue SwiftCode
list String
swiftListAdd [SValue SwiftCode
vl] [(SVariable SwiftCode
atArg, SValue SwiftCode
idx)]
listAppend :: SValue SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
listAppend = String
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(InternalValueExp r, StatementSym r smt) =>
String -> SValue r -> SValue r -> MS (r smt)
CG.listAppend String
swiftListAppend
listAccess :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
listAccess = SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(IndexTranslator r, InternalListFunc r, FunctionElim r,
RenderFunction r, RenderValue r, TypeElim r, ValueElim r) =>
SValue r -> SValue r -> SValue r
G.listAccess
listSet :: SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
listSet = SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(AssignStatement r smt, IndexTranslator r, RenderVariable r,
ValueElim r) =>
SValue r -> SValue r -> SValue r -> MS (r smt)
CP.listSet
indexOf :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
indexOf = SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftIndexOf
instance Set SwiftCode where
contains :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
contains = String -> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
OOFunctionSym r =>
String -> SValue r -> SValue r -> SValue r
CP.contains String
swiftContains
setAdd :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
setAdd = String -> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
InternalValueExp r =>
String -> SValue r -> SValue r -> SValue r
CP.setMethodCall String
swiftListAdd
setRemove :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
setRemove = String -> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
InternalValueExp r =>
String -> SValue r -> SValue r -> SValue r
CP.setMethodCall String
swiftListRemove
setUnion :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
setUnion = String -> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
InternalValueExp r =>
String -> SValue r -> SValue r -> SValue r
CP.setMethodCall String
swiftUnion
instance InternalList SwiftCode where
listSlice' :: Maybe (SValue SwiftCode)
-> Maybe (SValue SwiftCode)
-> Maybe (SValue SwiftCode)
-> SVariable SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode Doc)
listSlice' Maybe (SValue SwiftCode)
b Maybe (SValue SwiftCode)
e Maybe (SValue SwiftCode)
s SVariable SwiftCode
vn SValue SwiftCode
vo = SVariable SwiftCode
-> SValue SwiftCode
-> Maybe (SValue SwiftCode)
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> MS (SwiftCode Doc)
swiftListSlice SVariable SwiftCode
vn SValue SwiftCode
vo Maybe (SValue SwiftCode)
b Maybe (SValue SwiftCode)
e (SValue SwiftCode -> Maybe (SValue SwiftCode) -> SValue SwiftCode
forall a. a -> Maybe a -> a
fromMaybe (Integer -> SValue SwiftCode
forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
1) Maybe (SValue SwiftCode)
s)
instance InternalGetSet SwiftCode where
getFunc :: SVariable SwiftCode -> VS (SwiftCode FuncData)
getFunc = SVariable SwiftCode -> VS (SwiftCode FuncData)
forall (r :: * -> *).
(OOFunctionSym r, VariableElim r) =>
SVariable r -> VS (r FuncData)
G.getFunc
setFunc :: VS (SwiftCode TypeData)
-> SVariable SwiftCode
-> SValue SwiftCode
-> VS (SwiftCode FuncData)
setFunc = VS (SwiftCode TypeData)
-> SVariable SwiftCode
-> SValue SwiftCode
-> VS (SwiftCode FuncData)
forall (r :: * -> *).
(OOFunctionSym r, VariableElim r) =>
VS (r TypeData) -> SVariable r -> SValue r -> VS (r FuncData)
G.setFunc
instance InternalListFunc SwiftCode where
listAccessFunc :: VS (SwiftCode TypeData)
-> SValue SwiftCode -> VS (SwiftCode FuncData)
listAccessFunc = VS (SwiftCode TypeData)
-> SValue SwiftCode -> VS (SwiftCode FuncData)
forall (r :: * -> *).
(RenderFunction r, TypeElim r, ValueElim r, ValueSym r) =>
VS (r TypeData) -> SValue r -> VS (r FuncData)
CS.listAccessFunc
instance BinderSym SwiftCode where
binder :: String -> VS (SwiftCode TypeData) -> VSBinder SwiftCode
binder String
nm VS (SwiftCode TypeData)
tp = (TypeData -> BinderD) -> SwiftCode TypeData -> SwiftCode BinderD
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue (String -> TypeData -> BinderD
bindFormD String
nm) (SwiftCode TypeData -> SwiftCode BinderD)
-> VS (SwiftCode TypeData) -> VSBinder SwiftCode
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
<$> VS (SwiftCode TypeData)
tp
instance BinderElim SwiftCode where
binderName :: SwiftCode BinderD -> String
binderName = BinderD -> String
bindName (BinderD -> String)
-> (SwiftCode BinderD -> BinderD) -> SwiftCode BinderD -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode BinderD -> BinderD
forall a. SwiftCode a -> a
unSC
binderType :: SwiftCode BinderD -> SwiftCode TypeData
binderType = (BinderD -> TypeData) -> SwiftCode BinderD -> SwiftCode TypeData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue BinderD -> TypeData
bindType
instance InternalBinderElim SwiftCode where
binderElim :: SwiftCode BinderD -> Doc
binderElim = String -> Doc
text (String -> Doc)
-> (SwiftCode BinderD -> String) -> SwiftCode BinderD -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BinderD -> String
bindName (BinderD -> String)
-> (SwiftCode BinderD -> BinderD) -> SwiftCode BinderD -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode BinderD -> BinderD
forall a. SwiftCode a -> a
unSC
instance RenderFunction SwiftCode where
funcFromData :: Doc -> VS (SwiftCode TypeData) -> VS (SwiftCode FuncData)
funcFromData Doc
d = (SwiftCode TypeData -> SwiftCode FuncData)
-> VS (SwiftCode TypeData) -> VS (SwiftCode FuncData)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue ((TypeData -> FuncData) -> SwiftCode TypeData -> SwiftCode FuncData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue (TypeData -> Doc -> FuncData
`fd` Doc
d))
instance FunctionElim SwiftCode where
functionType :: SwiftCode FuncData -> SwiftCode TypeData
functionType = (FuncData -> TypeData) -> SwiftCode FuncData -> SwiftCode TypeData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue FuncData -> TypeData
fType
function :: SwiftCode FuncData -> Doc
function = FuncData -> Doc
funcDoc (FuncData -> Doc)
-> (SwiftCode FuncData -> FuncData) -> SwiftCode FuncData -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode FuncData -> FuncData
forall a. SwiftCode a -> a
unSC
instance InternalAssignStmt SwiftCode (Doc, Terminator) where
multiAssign :: [SVariable SwiftCode]
-> [SValue SwiftCode] -> MS (SwiftCode (Doc, Terminator))
multiAssign = (Doc -> Doc)
-> [SVariable SwiftCode]
-> [SValue SwiftCode]
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(AssignStatement r smt, InternalVarElim r, RenderValue r,
RenderVariable r, ValueElim r) =>
(Doc -> Doc) -> [SVariable r] -> [SValue r] -> MS (r smt)
CP.multiAssign Doc -> Doc
parens
instance InternalIOStmt SwiftCode (Doc, Terminator) where
printSt :: Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
printSt = Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
swiftPrint
instance InternalControlStmt SwiftCode (Doc, Terminator) where
multiReturn :: [SValue SwiftCode] -> MS (SwiftCode (Doc, Terminator))
multiReturn = (Doc -> Doc)
-> [SValue SwiftCode] -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(ControlStatement r smt, RenderValue r, ValueElim r) =>
(Doc -> Doc) -> [SValue r] -> MS (r smt)
CP.multiReturn Doc -> Doc
parens
instance RenderStatement SwiftCode (Doc, Terminator) where
stmt :: MS (SwiftCode (Doc, Terminator))
-> MS (SwiftCode (Doc, Terminator))
stmt = MS (SwiftCode (Doc, Terminator))
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(RenderStatement r smt, StatementElim r smt) =>
MS (r smt) -> MS (r smt)
G.stmt
loopStmt :: MS (SwiftCode (Doc, Terminator))
-> MS (SwiftCode (Doc, Terminator))
loopStmt = MS (SwiftCode (Doc, Terminator))
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(RenderStatement r smt, StatementElim r smt) =>
MS (r smt) -> MS (r smt)
G.loopStmt
stmtFromData :: Doc -> Terminator -> MS (SwiftCode (Doc, Terminator))
stmtFromData Doc
d Terminator
t = SwiftCode (Doc, Terminator) -> MS (SwiftCode (Doc, Terminator))
forall a s. a -> State s a
toState (SwiftCode (Doc, Terminator) -> MS (SwiftCode (Doc, Terminator)))
-> SwiftCode (Doc, Terminator) -> MS (SwiftCode (Doc, Terminator))
forall a b. (a -> b) -> a -> b
$ (Doc, Terminator) -> SwiftCode (Doc, Terminator)
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc
d, Terminator
t)
instance StatementElim SwiftCode (Doc, Terminator) where
statement :: SwiftCode (Doc, Terminator) -> Doc
statement = (Doc, Terminator) -> Doc
forall a b. (a, b) -> a
fst ((Doc, Terminator) -> Doc)
-> (SwiftCode (Doc, Terminator) -> (Doc, Terminator))
-> SwiftCode (Doc, Terminator)
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode (Doc, Terminator) -> (Doc, Terminator)
forall a. SwiftCode a -> a
unSC
statementTerm :: SwiftCode (Doc, Terminator) -> Terminator
statementTerm = (Doc, Terminator) -> Terminator
forall a b. (a, b) -> b
snd ((Doc, Terminator) -> Terminator)
-> (SwiftCode (Doc, Terminator) -> (Doc, Terminator))
-> SwiftCode (Doc, Terminator)
-> Terminator
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode (Doc, Terminator) -> (Doc, Terminator)
forall a. SwiftCode a -> a
unSC
instance StatementSym SwiftCode (Doc, Terminator) where
valStmt :: SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
valStmt = Terminator -> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(RenderStatement r smt, ValueElim r) =>
Terminator -> SValue r -> MS (r smt)
G.valStmt Terminator
Empty
emptyStmt :: MS (SwiftCode (Doc, Terminator))
emptyStmt = MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt. RenderStatement r smt => MS (r smt)
G.emptyStmt
multi :: [MS (SwiftCode (Doc, Terminator))]
-> MS (SwiftCode (Doc, Terminator))
multi = ([SwiftCode (Doc, Terminator)] -> SwiftCode (Doc, Terminator))
-> [MS (SwiftCode (Doc, Terminator))]
-> MS (SwiftCode (Doc, Terminator))
forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList (([(Doc, Terminator)] -> (Doc, Terminator))
-> [SwiftCode (Doc, Terminator)] -> SwiftCode (Doc, Terminator)
forall (m :: * -> *) a b. Monad m => ([a] -> b) -> [m a] -> m b
onCodeList [(Doc, Terminator)] -> (Doc, Terminator)
R.multiStmt)
instance AssignStatement SwiftCode (Doc, Terminator) where
assign :: SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
assign = Terminator
-> SVariable SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(InternalVarElim r, RenderStatement r smt, ValueElim r) =>
Terminator -> SVariable r -> SValue r -> MS (r smt)
G.assign Terminator
Empty
&-= :: SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
(&-=) = Terminator
-> SVariable SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(InternalVarElim r, RenderStatement r smt, ValueElim r) =>
Terminator -> SVariable r -> SValue r -> MS (r smt)
G.subAssign Terminator
Empty
&+= :: SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
(&+=) = SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(InternalVarElim r, RenderStatement r smt, ValueElim r) =>
SVariable r -> SValue r -> MS (r smt)
CS.increment
&++ :: SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
(&++) = SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(AssignStatement r smt, Literal r) =>
SVariable r -> MS (r smt)
M.increment1
&-- :: SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
(&--) = SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(AssignStatement r smt, Literal r) =>
SVariable r -> MS (r smt)
M.decrement1
instance DeclStatement SwiftCode (Doc, Terminator) where
varDec :: SVariable SwiftCode
-> SwiftCode ScopeData -> MS (SwiftCode (Doc, Terminator))
varDec = Doc
-> SVariable SwiftCode
-> SwiftCode ScopeData
-> MS (SwiftCode (Doc, Terminator))
swiftVarDec Doc
swiftVar
varDecDef :: SVariable SwiftCode
-> SwiftCode ScopeData
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
varDecDef = Terminator
-> SVariable SwiftCode
-> SwiftCode ScopeData
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(DeclStatement r smt, RenderStatement r smt, StatementElim r smt,
ValueElim r) =>
Terminator -> SVariable r -> r ScopeData -> SValue r -> MS (r smt)
C.varDecDef Terminator
Empty
setDecDef :: SVariable SwiftCode
-> SwiftCode ScopeData
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
setDecDef = Terminator
-> SVariable SwiftCode
-> SwiftCode ScopeData
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(DeclStatement r smt, RenderStatement r smt, StatementElim r smt,
ValueElim r) =>
Terminator -> SVariable r -> r ScopeData -> SValue r -> MS (r smt)
C.setDecDef Terminator
Empty
setDec :: SVariable SwiftCode
-> SwiftCode ScopeData -> MS (SwiftCode (Doc, Terminator))
setDec = Doc
-> SVariable SwiftCode
-> SwiftCode ScopeData
-> MS (SwiftCode (Doc, Terminator))
swiftSetDec Doc
swiftConst
listDec :: Integer
-> SVariable SwiftCode
-> SwiftCode ScopeData
-> MS (SwiftCode (Doc, Terminator))
listDec Integer
_ = SVariable SwiftCode
-> SwiftCode ScopeData -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(DeclStatement r smt, Literal r, VariableElim r) =>
SVariable r -> r ScopeData -> MS (r smt)
CP.listDec
listDecDef :: SVariable SwiftCode
-> SwiftCode ScopeData
-> [SValue SwiftCode]
-> MS (SwiftCode (Doc, Terminator))
listDecDef = SVariable SwiftCode
-> SwiftCode ScopeData
-> [SValue SwiftCode]
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(DeclStatement r smt, Literal r, VariableElim r) =>
SVariable r -> r ScopeData -> [SValue r] -> MS (r smt)
CP.listDecDef
arrayDec :: Integer
-> SValue SwiftCode
-> SVariable SwiftCode
-> SwiftCode ScopeData
-> MS (SwiftCode (Doc, Terminator))
arrayDec = Integer
-> SValue SwiftCode
-> SVariable SwiftCode
-> SwiftCode ScopeData
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(SharedStatement r smt, VariableElim r) =>
Integer -> SValue r -> SVariable r -> r ScopeData -> MS (r smt)
M.arrayDecAsList
arrayDecDef :: SVariable SwiftCode
-> SwiftCode ScopeData
-> [SValue SwiftCode]
-> MS (SwiftCode (Doc, Terminator))
arrayDecDef = SVariable SwiftCode
-> SwiftCode ScopeData
-> [SValue SwiftCode]
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
DeclStatement r smt =>
SVariable r -> r ScopeData -> [SValue r] -> MS (r smt)
listDecDef
constDecDef :: SVariable SwiftCode
-> SwiftCode ScopeData
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
constDecDef SVariable SwiftCode
vr SwiftCode ScopeData
scp SValue SwiftCode
vl' = do
SwiftCode (Doc, Terminator)
vdec <- Doc
-> SVariable SwiftCode
-> SwiftCode ScopeData
-> MS (SwiftCode (Doc, Terminator))
swiftVarDec Doc
swiftConst SVariable SwiftCode
vr SwiftCode ScopeData
scp
SwiftCode Value
vl <- LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode Value))
MethodState
ValueState
-> SValue SwiftCode
-> StateT MethodState Identity (SwiftCode 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) (SwiftCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode Value) ValueState)
-> MethodState -> Focusing Identity (SwiftCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue SwiftCode
vl'
Doc -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> MS (r smt)
mkStmtNoEnd (Doc -> MS (SwiftCode (Doc, Terminator)))
-> Doc -> MS (SwiftCode (Doc, Terminator))
forall a b. (a -> b) -> a -> b
$ SwiftCode (Doc, Terminator) -> Doc
forall (r :: * -> *) smt. StatementElim r smt => r smt -> Doc
RC.statement SwiftCode (Doc, Terminator)
vdec Doc -> Doc -> Doc
<+> Doc
equals Doc -> Doc -> Doc
<+> SwiftCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value SwiftCode Value
vl
funcDecDef :: SVariable SwiftCode
-> SwiftCode ScopeData
-> [SVariable SwiftCode]
-> MS (SwiftCode Doc)
-> MS (SwiftCode (Doc, Terminator))
funcDecDef = SVariable SwiftCode
-> SwiftCode ScopeData
-> [SVariable SwiftCode]
-> MS (SwiftCode Doc)
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) vis smt md svr att.
OORenderSym r vis smt md svr att =>
SVariable r
-> r ScopeData -> [SVariable r] -> MS (r Doc) -> MS (r smt)
CP.funcDecDef
instance OODeclStatement SwiftCode (Doc, Terminator) where
objDecDef :: SVariable SwiftCode
-> SwiftCode ScopeData
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
objDecDef = SVariable SwiftCode
-> SwiftCode ScopeData
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
DeclStatement r smt =>
SVariable r -> r ScopeData -> SValue r -> MS (r smt)
varDecDef
objDecNew :: SVariable SwiftCode
-> SwiftCode ScopeData
-> [SValue SwiftCode]
-> MS (SwiftCode (Doc, Terminator))
objDecNew = SVariable SwiftCode
-> SwiftCode ScopeData
-> [SValue SwiftCode]
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(DeclStatement r smt, OOValueExpression r, VariableElim r) =>
SVariable r -> r ScopeData -> [SValue r] -> MS (r smt)
G.objDecNew
extObjDecNew :: String
-> SVariable SwiftCode
-> SwiftCode ScopeData
-> [SValue SwiftCode]
-> MS (SwiftCode (Doc, Terminator))
extObjDecNew = String
-> SVariable SwiftCode
-> SwiftCode ScopeData
-> [SValue SwiftCode]
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(DeclStatement r smt, OOValueExpression r, VariableElim r) =>
String -> SVariable r -> r ScopeData -> [SValue r] -> MS (r smt)
C.extObjDecNew
instance IOStatement SwiftCode (Doc, Terminator) where
print :: SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
print = Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
swiftOut Bool
False Maybe (SValue SwiftCode)
forall a. Maybe a
Nothing SValue SwiftCode
forall (r :: * -> *). RenderValue r => SValue r
printFunc
printLn :: SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
printLn = Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
swiftOut Bool
True Maybe (SValue SwiftCode)
forall a. Maybe a
Nothing SValue SwiftCode
forall (r :: * -> *). RenderValue r => SValue r
printLnFunc
printStr :: String -> MS (SwiftCode (Doc, Terminator))
printStr = Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
swiftOut Bool
False Maybe (SValue SwiftCode)
forall a. Maybe a
Nothing SValue SwiftCode
forall (r :: * -> *). RenderValue r => SValue r
printFunc (SValue SwiftCode -> MS (SwiftCode (Doc, Terminator)))
-> (String -> SValue SwiftCode)
-> String
-> MS (SwiftCode (Doc, Terminator))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SValue SwiftCode
forall (r :: * -> *). Literal r => String -> SValue r
litString
printStrLn :: String -> MS (SwiftCode (Doc, Terminator))
printStrLn = Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
swiftOut Bool
True Maybe (SValue SwiftCode)
forall a. Maybe a
Nothing SValue SwiftCode
forall (r :: * -> *). RenderValue r => SValue r
printLnFunc (SValue SwiftCode -> MS (SwiftCode (Doc, Terminator)))
-> (String -> SValue SwiftCode)
-> String
-> MS (SwiftCode (Doc, Terminator))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SValue SwiftCode
forall (r :: * -> *). Literal r => String -> SValue r
litString
printFile :: SValue SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
printFile SValue SwiftCode
f = Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
swiftOut Bool
False (SValue SwiftCode -> Maybe (SValue SwiftCode)
forall a. a -> Maybe a
Just SValue SwiftCode
f) (SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *). RenderValue r => SValue r -> SValue r
printFileFunc SValue SwiftCode
f)
printFileLn :: SValue SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
printFileLn SValue SwiftCode
f = Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
swiftOut Bool
True (SValue SwiftCode -> Maybe (SValue SwiftCode)
forall a. a -> Maybe a
Just SValue SwiftCode
f) (SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *). RenderValue r => SValue r -> SValue r
printFileLnFunc SValue SwiftCode
f)
printFileStr :: SValue SwiftCode -> String -> MS (SwiftCode (Doc, Terminator))
printFileStr SValue SwiftCode
f = Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
swiftOut Bool
False (SValue SwiftCode -> Maybe (SValue SwiftCode)
forall a. a -> Maybe a
Just SValue SwiftCode
f) (SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *). RenderValue r => SValue r -> SValue r
printFileFunc SValue SwiftCode
f) (SValue SwiftCode -> MS (SwiftCode (Doc, Terminator)))
-> (String -> SValue SwiftCode)
-> String
-> MS (SwiftCode (Doc, Terminator))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SValue SwiftCode
forall (r :: * -> *). Literal r => String -> SValue r
litString
printFileStrLn :: SValue SwiftCode -> String -> MS (SwiftCode (Doc, Terminator))
printFileStrLn SValue SwiftCode
f = Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
swiftOut Bool
True (SValue SwiftCode -> Maybe (SValue SwiftCode)
forall a. a -> Maybe a
Just SValue SwiftCode
f) (SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *). RenderValue r => SValue r -> SValue r
printFileLnFunc SValue SwiftCode
f) (SValue SwiftCode -> MS (SwiftCode (Doc, Terminator)))
-> (String -> SValue SwiftCode)
-> String
-> MS (SwiftCode (Doc, Terminator))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SValue SwiftCode
forall (r :: * -> *). Literal r => String -> SValue r
litString
getInput :: SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
getInput SVariable SwiftCode
v = SVariable SwiftCode
v SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
AssignStatement r smt =>
SVariable r -> SValue r -> MS (r smt)
&= SVariable SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftInput SVariable SwiftCode
v SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueExpression r) =>
SValue r
swiftReadLineFunc
discardInput :: MS (SwiftCode (Doc, Terminator))
discardInput = SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
StatementSym r smt =>
SValue r -> MS (r smt)
valStmt SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueExpression r) =>
SValue r
swiftReadLineFunc
getFileInput :: SValue SwiftCode
-> SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
getFileInput SValue SwiftCode
_ SVariable SwiftCode
v = do
Integer
wi <- MS Integer
getWordIndex
Integer
li <- MS Integer
getLineIndex
(MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
incrementWord
SVariable SwiftCode
v SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
AssignStatement r smt =>
SVariable r -> SValue r -> MS (r smt)
&= SVariable SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftInput SVariable SwiftCode
v
(SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *) smt.
List r smt =>
SValue r -> SValue r -> SValue r
listAccess (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *) smt.
List r smt =>
SValue r -> SValue r -> SValue r
listAccess SValue SwiftCode
swiftContentsVal (Integer -> SValue SwiftCode
forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
li)) (Integer -> SValue SwiftCode
forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
wi))
discardFileInput :: SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
discardFileInput SValue SwiftCode
_ = (MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
incrementWord StateT MethodState Identity ()
-> MS (SwiftCode (Doc, Terminator))
-> MS (SwiftCode (Doc, Terminator))
forall a b.
StateT MethodState Identity a
-> StateT MethodState Identity b -> StateT MethodState Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt. StatementSym r smt => MS (r smt)
emptyStmt
openFileR :: SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
openFileR SVariable SwiftCode
v SValue SwiftCode
pth = do
SwiftCode Variable
v' <- LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode Variable))
MethodState
ValueState
-> SVariable SwiftCode
-> StateT MethodState Identity (SwiftCode 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) (SwiftCode Variable))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode Variable) ValueState)
-> MethodState
-> Focusing Identity (SwiftCode Variable) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable SwiftCode
v
ScopeData
scpData <- String -> MS ScopeData
getVarScope (String -> MS ScopeData) -> String -> MS ScopeData
forall a b. (a -> b) -> a -> b
$ SwiftCode Variable -> String
forall (r :: * -> *). VariableElim r => r Variable -> String
variableName SwiftCode Variable
v'
let scp :: SwiftCode ScopeData
scp = ScopeData -> SwiftCode ScopeData
forall (r :: * -> *). ScopeSym r => ScopeData -> r ScopeData
convScope ScopeData
scpData
[MS (SwiftCode (Doc, Terminator))]
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
StatementSym r smt =>
[MS (r smt)] -> MS (r smt)
multi [(SValue SwiftCode -> VS (SwiftCode TypeData) -> SValue SwiftCode)
-> SVariable SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
AssignStatement r smt =>
(SValue r -> VS (r TypeData) -> SValue r)
-> SVariable r -> SValue r -> MS (r smt)
CP.openFileR SValue SwiftCode -> VS (SwiftCode TypeData) -> SValue SwiftCode
swiftOpenFile SVariable SwiftCode
v SValue SwiftCode
pth,
SVariable SwiftCode
-> SwiftCode ScopeData -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
DeclStatement r smt =>
SVariable r -> r ScopeData -> MS (r smt)
varDec SVariable SwiftCode
swiftContentsVar SwiftCode ScopeData
scp, SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
swiftReadFile SVariable SwiftCode
swiftContentsVar (SVariable SwiftCode -> SValue SwiftCode
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable SwiftCode
v)]
openFileW :: SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
openFileW = Bool
-> SVariable SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
swiftOpenFileWA Bool
False
openFileA :: SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
openFileA = Bool
-> SVariable SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
swiftOpenFileWA Bool
True
closeFile :: SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
closeFile = SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
swiftCloseFile
getFileInputLine :: SValue SwiftCode
-> SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
getFileInputLine SValue SwiftCode
_ SVariable SwiftCode
v = do
SwiftCode Variable
v' <- LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode Variable))
MethodState
ValueState
-> SVariable SwiftCode
-> StateT MethodState Identity (SwiftCode 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) (SwiftCode Variable))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode Variable) ValueState)
-> MethodState
-> Focusing Identity (SwiftCode Variable) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable SwiftCode
v
ScopeData
scpData <- String -> MS ScopeData
getVarScope (String -> MS ScopeData) -> String -> MS ScopeData
forall a b. (a -> b) -> a -> b
$ SwiftCode Variable -> String
forall (r :: * -> *). VariableElim r => r Variable -> String
variableName SwiftCode Variable
v'
let scp :: SwiftCode ScopeData
scp = ScopeData -> SwiftCode ScopeData
forall (r :: * -> *). ScopeSym r => ScopeData -> r ScopeData
convScope ScopeData
scpData
Integer
wi <- MS Integer
getWordIndex
Integer
li <- MS Integer
getLineIndex
(MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
incrementLine
SwiftCode Doc
slc <- SVariable SwiftCode
-> SValue SwiftCode
-> Maybe (SValue SwiftCode)
-> Maybe (SValue SwiftCode)
-> Maybe (SValue SwiftCode)
-> MS (SwiftCode Doc)
forall (r :: * -> *).
InternalList r =>
SVariable r
-> SValue r
-> Maybe (SValue r)
-> Maybe (SValue r)
-> Maybe (SValue r)
-> MS (r Doc)
listSlice SVariable SwiftCode
swiftLineVar (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *) smt.
List r smt =>
SValue r -> SValue r -> SValue r
listAccess SValue SwiftCode
swiftContentsVal (Integer -> SValue SwiftCode
forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
li))
(SValue SwiftCode -> Maybe (SValue SwiftCode)
forall a. a -> Maybe a
Just (SValue SwiftCode -> Maybe (SValue SwiftCode))
-> SValue SwiftCode -> Maybe (SValue SwiftCode)
forall a b. (a -> b) -> a -> b
$ Integer -> SValue SwiftCode
forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
wi) Maybe (SValue SwiftCode)
forall a. Maybe a
Nothing Maybe (SValue SwiftCode)
forall a. Maybe a
Nothing
[MS (SwiftCode (Doc, Terminator))]
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
StatementSym r smt =>
[MS (r smt)] -> MS (r smt)
multi [SVariable SwiftCode
-> SwiftCode ScopeData -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
DeclStatement r smt =>
SVariable r -> r ScopeData -> MS (r smt)
varDec SVariable SwiftCode
swiftLineVar SwiftCode ScopeData
scp, Doc -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> MS (r smt)
mkStmtNoEnd (Doc -> MS (SwiftCode (Doc, Terminator)))
-> Doc -> MS (SwiftCode (Doc, Terminator))
forall a b. (a -> b) -> a -> b
$ SwiftCode Doc -> Doc
forall (r :: * -> *). BlockElim r => r Doc -> Doc
RC.block SwiftCode Doc
slc,
SVariable SwiftCode
v SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
AssignStatement r smt =>
SVariable r -> SValue r -> MS (r smt)
&= Char -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(InternalValueExp r, Literal r, VariableSym r) =>
Char -> SValue r -> SValue r
swiftJoinedFunc Char
' ' SValue SwiftCode
swiftLineVal]
discardFileLine :: SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
discardFileLine SValue SwiftCode
_ = (MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
incrementLine StateT MethodState Identity ()
-> MS (SwiftCode (Doc, Terminator))
-> MS (SwiftCode (Doc, Terminator))
forall a b.
StateT MethodState Identity a
-> StateT MethodState Identity b -> StateT MethodState Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt. StatementSym r smt => MS (r smt)
emptyStmt
getFileInputAll :: SValue SwiftCode
-> SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
getFileInputAll SValue SwiftCode
_ SVariable SwiftCode
v = do
Integer
li <- MS Integer
getLineIndex
let l_binder :: VSBinder SwiftCode
l_binder = String -> VS (SwiftCode TypeData) -> VSBinder SwiftCode
forall (r :: * -> *).
BinderSym r =>
String -> VS (r TypeData) -> VSBinder r
binder String
"l" (VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string)
l_var :: SVariable SwiftCode
l_var = String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
"l" (VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string)
SwiftCode Doc
slc <- SVariable SwiftCode
-> SValue SwiftCode
-> Maybe (SValue SwiftCode)
-> Maybe (SValue SwiftCode)
-> Maybe (SValue SwiftCode)
-> MS (SwiftCode Doc)
forall (r :: * -> *).
InternalList r =>
SVariable r
-> SValue r
-> Maybe (SValue r)
-> Maybe (SValue r)
-> Maybe (SValue r)
-> MS (r Doc)
listSlice SVariable SwiftCode
swiftContentsVar SValue SwiftCode
swiftContentsVal
(SValue SwiftCode -> Maybe (SValue SwiftCode)
forall a. a -> Maybe a
Just (SValue SwiftCode -> Maybe (SValue SwiftCode))
-> SValue SwiftCode -> Maybe (SValue SwiftCode)
forall a b. (a -> b) -> a -> b
$ Integer -> SValue SwiftCode
forall (r :: * -> *). Literal r => Integer -> SValue r
litInt (Integer
liInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
+Integer
1)) Maybe (SValue SwiftCode)
forall a. Maybe a
Nothing Maybe (SValue SwiftCode)
forall a. Maybe a
Nothing
[MS (SwiftCode (Doc, Terminator))]
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
StatementSym r smt =>
[MS (r smt)] -> MS (r smt)
multi [Doc -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> MS (r smt)
mkStmtNoEnd (Doc -> MS (SwiftCode (Doc, Terminator)))
-> Doc -> MS (SwiftCode (Doc, Terminator))
forall a b. (a -> b) -> a -> b
$ SwiftCode Doc -> Doc
forall (r :: * -> *). BlockElim r => r Doc -> Doc
RC.block SwiftCode Doc
slc,
SVariable SwiftCode
v SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
AssignStatement r smt =>
SVariable r -> SValue r -> MS (r smt)
&= SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
InternalValueExp r =>
SValue r -> SValue r -> SValue r
swiftMapFunc SValue SwiftCode
swiftContentsVal
([VSBinder SwiftCode] -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
ValueExpression r =>
[VSBinder r] -> SValue r -> SValue r
lambda [VSBinder SwiftCode
l_binder] (Char -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(InternalValueExp r, Literal r, VariableSym r) =>
Char -> SValue r -> SValue r
swiftJoinedFunc Char
' ' (SVariable SwiftCode -> SValue SwiftCode
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable SwiftCode
l_var)))]
instance StringStatement SwiftCode (Doc, Terminator) where
stringSplit :: Char
-> SVariable SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
stringSplit Char
d SVariable SwiftCode
vnew SValue SwiftCode
s = SVariable SwiftCode
vnew SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
AssignStatement r smt =>
SVariable r -> SValue r -> MS (r smt)
&= Char -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(InternalValueExp r, Literal r, VariableSym r) =>
Char -> SValue r -> SValue r
swiftSplitFunc Char
d SValue SwiftCode
s
stringListVals :: [SVariable SwiftCode]
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
stringListVals = [SVariable SwiftCode]
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(AssignStatement r smt, List r smt, Literal r, RenderValue r,
TypeElim r, VariableElim r) =>
[SVariable r] -> SValue r -> MS (r smt)
M.stringListVals
stringListLists :: [SVariable SwiftCode]
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
stringListLists = [SVariable SwiftCode]
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(RenderValue r, SharedStatement r smt, TypeElim r,
VariableElim r) =>
[SVariable r] -> SValue r -> MS (r smt)
M.stringListLists
instance FuncAppStatement SwiftCode (Doc, Terminator) where
inOutCall :: InOutCall SwiftCode (Doc, Terminator)
inOutCall = (String
-> VS (SwiftCode TypeData)
-> [SValue SwiftCode]
-> SValue SwiftCode)
-> InOutCall SwiftCode (Doc, Terminator)
forall (r :: * -> *) smt.
(InternalAssignStmt r smt, StatementSym r smt, VariableValue r) =>
(String -> VS (r TypeData) -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MS (r smt)
CP.inOutCall String
-> VS (SwiftCode TypeData)
-> [SValue SwiftCode]
-> SValue SwiftCode
forall (r :: * -> *). ValueExpression r => PosCall r
funcApp
extInOutCall :: String -> InOutCall SwiftCode (Doc, Terminator)
extInOutCall String
m = (String
-> VS (SwiftCode TypeData)
-> [SValue SwiftCode]
-> SValue SwiftCode)
-> InOutCall SwiftCode (Doc, Terminator)
forall (r :: * -> *) smt.
(InternalAssignStmt r smt, StatementSym r smt, VariableValue r) =>
(String -> VS (r TypeData) -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MS (r smt)
CP.inOutCall (String
-> String
-> VS (SwiftCode TypeData)
-> [SValue SwiftCode]
-> SValue SwiftCode
forall (r :: * -> *). ValueExpression r => String -> PosCall r
extFuncApp String
m)
instance OOFuncAppStatement SwiftCode (Doc, Terminator) where
selfInOutCall :: InOutCall SwiftCode (Doc, Terminator)
selfInOutCall = (String
-> VS (SwiftCode TypeData)
-> [SValue SwiftCode]
-> SValue SwiftCode)
-> InOutCall SwiftCode (Doc, Terminator)
forall (r :: * -> *) smt.
(InternalAssignStmt r smt, StatementSym r smt, VariableValue r) =>
(String -> VS (r TypeData) -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MS (r smt)
CP.inOutCall String
-> VS (SwiftCode TypeData)
-> [SValue SwiftCode]
-> SValue SwiftCode
forall (r :: * -> *).
(InternalValueExp r, VariableValue r, SelfSym r) =>
PosCall r
selfMethodCall
instance CommentStatement SwiftCode (Doc, Terminator) where
comment :: String -> MS (SwiftCode (Doc, Terminator))
comment = Doc -> String -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> String -> MS (r smt)
G.comment Doc
commentStart
instance ControlStatement SwiftCode (Doc, Terminator) where
break :: MS (SwiftCode (Doc, Terminator))
break = Doc -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> MS (r smt)
mkStmtNoEnd Doc
R.break
continue :: MS (SwiftCode (Doc, Terminator))
continue = Doc -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> MS (r smt)
mkStmtNoEnd Doc
R.continue
returnStmt :: SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
returnStmt = Terminator -> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(RenderStatement r smt, ValueElim r) =>
Terminator -> SValue r -> MS (r smt)
G.returnStmt Terminator
Empty
throw :: String -> MS (SwiftCode (Doc, Terminator))
throw String
msg = do
(MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
setThrowUsed
(SwiftCode Value -> Doc)
-> Terminator -> String -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(Literal r, RenderStatement r smt) =>
(r Value -> Doc) -> Terminator -> String -> MS (r smt)
G.throw SwiftCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
swiftThrowDoc Terminator
Empty String
msg
ifCond :: [(SValue SwiftCode, MS (SwiftCode Doc))]
-> MS (SwiftCode Doc) -> MS (SwiftCode (Doc, Terminator))
ifCond = (Doc -> Doc)
-> Doc
-> OptionalSpace
-> Doc
-> Doc
-> Doc
-> [(SValue SwiftCode, MS (SwiftCode Doc))]
-> MS (SwiftCode Doc)
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(BodyElim r, RenderStatement r smt, ValueElim r) =>
(Doc -> Doc)
-> Doc
-> OptionalSpace
-> Doc
-> Doc
-> Doc
-> [(SValue r, MS (r Doc))]
-> MS (r Doc)
-> MS (r smt)
G.ifCond Doc -> Doc
forall a. a -> a
id Doc
bodyStart OptionalSpace
G.defaultOptSpace Doc
elseIfLabel Doc
bodyEnd Doc
empty
switch :: SValue SwiftCode
-> [(SValue SwiftCode, MS (SwiftCode Doc))]
-> MS (SwiftCode Doc)
-> MS (SwiftCode (Doc, Terminator))
switch SValue SwiftCode
v [(SValue SwiftCode, MS (SwiftCode Doc))]
cs MS (SwiftCode Doc)
bod = do
SwiftCode (Doc, Terminator)
st <- MS (SwiftCode (Doc, Terminator))
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
MS (r smt) -> MS (r smt)
RC.stmt MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt. StatementSym r smt => MS (r smt)
emptyStmt
SwiftCode Value
vl <- LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode Value))
MethodState
ValueState
-> SValue SwiftCode
-> StateT MethodState Identity (SwiftCode 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) (SwiftCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode Value) ValueState)
-> MethodState -> Focusing Identity (SwiftCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue SwiftCode
v
[SwiftCode Value]
vals <- ((SValue SwiftCode, MS (SwiftCode Doc))
-> StateT MethodState Identity (SwiftCode Value))
-> [(SValue SwiftCode, MS (SwiftCode Doc))]
-> StateT MethodState Identity [SwiftCode Value]
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 ValueState Identity) (SwiftCode Value))
MethodState
ValueState
-> SValue SwiftCode
-> StateT MethodState Identity (SwiftCode 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) (SwiftCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode Value) ValueState)
-> MethodState -> Focusing Identity (SwiftCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS (SValue SwiftCode -> StateT MethodState Identity (SwiftCode Value))
-> ((SValue SwiftCode, MS (SwiftCode Doc)) -> SValue SwiftCode)
-> (SValue SwiftCode, MS (SwiftCode Doc))
-> StateT MethodState Identity (SwiftCode Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SValue SwiftCode, MS (SwiftCode Doc)) -> SValue SwiftCode
forall a b. (a, b) -> a
fst) [(SValue SwiftCode, MS (SwiftCode Doc))]
cs
[SwiftCode Doc]
bods <- ((SValue SwiftCode, MS (SwiftCode Doc)) -> MS (SwiftCode Doc))
-> [(SValue SwiftCode, MS (SwiftCode Doc))]
-> StateT MethodState Identity [SwiftCode Doc]
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 (SValue SwiftCode, MS (SwiftCode Doc)) -> MS (SwiftCode Doc)
forall a b. (a, b) -> b
snd [(SValue SwiftCode, MS (SwiftCode Doc))]
cs
SwiftCode Doc
dflt <- MS (SwiftCode Doc)
bod
Doc -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> MS (r smt)
mkStmtNoEnd (Doc -> MS (SwiftCode (Doc, Terminator)))
-> Doc -> MS (SwiftCode (Doc, Terminator))
forall a b. (a -> b) -> a -> b
$ (Doc -> Doc)
-> SwiftCode (Doc, Terminator)
-> SwiftCode Value
-> SwiftCode Doc
-> [(SwiftCode Value, SwiftCode Doc)]
-> Doc
forall (r :: * -> *) smt.
(BodyElim r, StatementElim r smt, ValueElim r) =>
(Doc -> Doc)
-> r smt -> r Value -> r Doc -> [(r Value, r Doc)] -> Doc
R.switch (Doc
space <>) SwiftCode (Doc, Terminator)
st SwiftCode Value
vl SwiftCode Doc
dflt ([SwiftCode Value]
-> [SwiftCode Doc] -> [(SwiftCode Value, SwiftCode Doc)]
forall a b. [a] -> [b] -> [(a, b)]
zip [SwiftCode Value]
vals [SwiftCode Doc]
bods)
ifExists :: SValue SwiftCode
-> MS (SwiftCode Doc)
-> MS (SwiftCode Doc)
-> MS (SwiftCode (Doc, Terminator))
ifExists = SValue SwiftCode
-> MS (SwiftCode Doc)
-> MS (SwiftCode Doc)
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(ControlStatement r smt, ValueExpression r) =>
SValue r -> MS (r Doc) -> MS (r Doc) -> MS (r smt)
M.ifExists
for :: MS (SwiftCode (Doc, Terminator))
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
-> MS (SwiftCode Doc)
-> MS (SwiftCode (Doc, Terminator))
for MS (SwiftCode (Doc, Terminator))
_ SValue SwiftCode
_ MS (SwiftCode (Doc, Terminator))
_ MS (SwiftCode Doc)
_ = String -> MS (SwiftCode (Doc, Terminator))
forall a. HasCallStack => String -> a
error (String -> MS (SwiftCode (Doc, Terminator)))
-> String -> MS (SwiftCode (Doc, Terminator))
forall a b. (a -> b) -> a -> b
$ String -> String
CP.forLoopError String
swiftName
forRange :: SVariable SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode Doc)
-> MS (SwiftCode (Doc, Terminator))
forRange SVariable SwiftCode
i SValue SwiftCode
initv SValue SwiftCode
finalv SValue SwiftCode
stepv = SVariable SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode Doc)
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
ControlStatement r smt =>
SVariable r -> SValue r -> MS (r Doc) -> MS (r smt)
forEach SVariable SwiftCode
i (SValue SwiftCode
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueExpression r) =>
SValue r -> SValue r -> SValue r -> SValue r
swiftStrideFunc SValue SwiftCode
initv SValue SwiftCode
finalv SValue SwiftCode
stepv)
forEach :: SVariable SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode Doc)
-> MS (SwiftCode (Doc, Terminator))
forEach = (SwiftCode Variable -> SwiftCode Value -> SwiftCode Doc -> Doc)
-> SVariable SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode Doc)
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
(r Variable -> r Value -> r Doc -> Doc)
-> SVariable r -> SValue r -> MS (r Doc) -> MS (r smt)
CS.forEach' SwiftCode Variable -> SwiftCode Value -> SwiftCode Doc -> Doc
forall (r :: * -> *).
(BodyElim r, InternalVarElim r, ValueElim r) =>
r Variable -> r Value -> r Doc -> Doc
swiftForEach
while :: SValue SwiftCode
-> MS (SwiftCode Doc) -> MS (SwiftCode (Doc, Terminator))
while = (Doc -> Doc)
-> Doc
-> Doc
-> SValue SwiftCode
-> MS (SwiftCode Doc)
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(BodyElim r, RenderStatement r smt, ValueElim r) =>
(Doc -> Doc) -> Doc -> Doc -> SValue r -> MS (r Doc) -> MS (r smt)
C.while Doc -> Doc
forall a. a -> a
id Doc
bodyStart Doc
bodyEnd
tryCatch :: MS (SwiftCode Doc)
-> MS (SwiftCode Doc) -> MS (SwiftCode (Doc, Terminator))
tryCatch = (SwiftCode Doc -> SwiftCode Doc -> Doc)
-> MS (SwiftCode Doc)
-> MS (SwiftCode Doc)
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
(r Doc -> r Doc -> Doc) -> MS (r Doc) -> MS (r Doc) -> MS (r smt)
G.tryCatch SwiftCode Doc -> SwiftCode Doc -> Doc
forall (r :: * -> *). BodyElim r => r Doc -> r Doc -> Doc
swiftTryCatch
assert :: SValue SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
assert SValue SwiftCode
condition SValue SwiftCode
errorMessage = do
SwiftCode Value
cond <- LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode Value))
MethodState
ValueState
-> SValue SwiftCode
-> StateT MethodState Identity (SwiftCode 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) (SwiftCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode Value) ValueState)
-> MethodState -> Focusing Identity (SwiftCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue SwiftCode
condition
SwiftCode Value
errMsg <- LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode Value))
MethodState
ValueState
-> SValue SwiftCode
-> StateT MethodState Identity (SwiftCode 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) (SwiftCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode Value) ValueState)
-> MethodState -> Focusing Identity (SwiftCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue SwiftCode
errorMessage
Doc -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> MS (r smt)
mkStmtNoEnd (SwiftCode Value -> SwiftCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> r Value -> Doc
swiftAssert SwiftCode Value
cond SwiftCode Value
errMsg)
instance ObserverPattern SwiftCode (Doc, Terminator) where
notifyObservers :: VS (SwiftCode FuncData)
-> VS (SwiftCode TypeData) -> MS (SwiftCode (Doc, Terminator))
notifyObservers = VS (SwiftCode FuncData)
-> VS (SwiftCode TypeData) -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
OOStatement r smt =>
VS (r FuncData) -> VS (r TypeData) -> MS (r smt)
M.notifyObservers'
instance StrategyPattern SwiftCode (Doc, Terminator) where
runStrategy :: String
-> [(String, MS (SwiftCode Doc))]
-> Maybe (SValue SwiftCode)
-> Maybe (SVariable SwiftCode)
-> MS (SwiftCode Doc)
runStrategy = String
-> [(String, MS (SwiftCode Doc))]
-> Maybe (SValue SwiftCode)
-> Maybe (SVariable SwiftCode)
-> MS (SwiftCode Doc)
forall (r :: * -> *) smt.
(AssignStatement r smt, BodyElim r, Monad r, RenderStatement r smt,
StatementElim r smt) =>
String
-> [(String, MS (r Doc))]
-> Maybe (SValue r)
-> Maybe (SVariable r)
-> MS (r Doc)
M.runStrategy
instance VisibilitySym SwiftCode Doc where
private :: SwiftCode Doc
private = Doc -> SwiftCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
R.private
public :: SwiftCode Doc
public = Doc -> SwiftCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
empty
instance RenderVisibility SwiftCode Doc where
visibilityFromData :: VisibilityTag -> Doc -> SwiftCode Doc
visibilityFromData VisibilityTag
_ = Doc -> SwiftCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode
instance VisibilityElim SwiftCode Doc where
visibility :: SwiftCode Doc -> Doc
visibility = SwiftCode Doc -> Doc
forall a. SwiftCode a -> a
unSC
instance MethodTypeSym SwiftCode where
mType :: VS (SwiftCode TypeData) -> MSMthdType SwiftCode
mType = LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode TypeData))
MethodState
ValueState
-> VS (SwiftCode TypeData) -> MSMthdType SwiftCode
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) (SwiftCode TypeData))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode TypeData) ValueState)
-> MethodState
-> Focusing Identity (SwiftCode TypeData) MethodState
Lens' MethodState ValueState
lensMStoVS
instance OOMethodTypeSym SwiftCode where
construct :: String -> MSMthdType SwiftCode
construct = String -> MSMthdType SwiftCode
forall (r :: * -> *). Monad r => String -> MS (r TypeData)
G.construct
instance ParameterSym SwiftCode where
param :: SVariable SwiftCode -> MS (SwiftCode ParamData)
param = (SwiftCode Variable -> Doc)
-> SVariable SwiftCode -> MS (SwiftCode ParamData)
forall (r :: * -> *).
(RenderParam r, VariableElim r) =>
(r Variable -> Doc) -> SVariable r -> MS (r ParamData)
G.param (Doc -> SwiftCode Variable -> Doc
swiftParam Doc
empty)
pointerParam :: SVariable SwiftCode -> MS (SwiftCode ParamData)
pointerParam = (SwiftCode Variable -> Doc)
-> SVariable SwiftCode -> MS (SwiftCode ParamData)
forall (r :: * -> *).
(RenderParam r, VariableElim r) =>
(r Variable -> Doc) -> SVariable r -> MS (r ParamData)
G.param (Doc -> SwiftCode Variable -> Doc
swiftParam Doc
swiftInOut)
instance RenderParam SwiftCode where
paramFromData :: SVariable SwiftCode -> Doc -> MS (SwiftCode ParamData)
paramFromData SVariable SwiftCode
v' Doc
d = do
SwiftCode Variable
v <- LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode Variable))
MethodState
ValueState
-> SVariable SwiftCode
-> StateT MethodState Identity (SwiftCode 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) (SwiftCode Variable))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode Variable) ValueState)
-> MethodState
-> Focusing Identity (SwiftCode Variable) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable SwiftCode
v'
SwiftCode ParamData -> MS (SwiftCode ParamData)
forall a s. a -> State s a
toState (SwiftCode ParamData -> MS (SwiftCode ParamData))
-> SwiftCode ParamData -> MS (SwiftCode ParamData)
forall a b. (a -> b) -> a -> b
$ (Variable -> Doc -> ParamData)
-> SwiftCode Variable -> SwiftCode Doc -> SwiftCode ParamData
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues Variable -> Doc -> ParamData
pd SwiftCode Variable
v (Doc -> SwiftCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
d)
instance ParamElim SwiftCode where
parameterName :: SwiftCode ParamData -> String
parameterName = SwiftCode Variable -> String
forall (r :: * -> *). VariableElim r => r Variable -> String
variableName (SwiftCode Variable -> String)
-> (SwiftCode ParamData -> SwiftCode Variable)
-> SwiftCode ParamData
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ParamData -> Variable)
-> SwiftCode ParamData -> SwiftCode Variable
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ParamData -> Variable
paramVar
parameterType :: SwiftCode ParamData -> SwiftCode TypeData
parameterType = SwiftCode Variable -> SwiftCode TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType (SwiftCode Variable -> SwiftCode TypeData)
-> (SwiftCode ParamData -> SwiftCode Variable)
-> SwiftCode ParamData
-> SwiftCode TypeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ParamData -> Variable)
-> SwiftCode ParamData -> SwiftCode Variable
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ParamData -> Variable
paramVar
parameter :: SwiftCode ParamData -> Doc
parameter = ParamData -> Doc
paramDoc (ParamData -> Doc)
-> (SwiftCode ParamData -> ParamData) -> SwiftCode ParamData -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode ParamData -> ParamData
forall a. SwiftCode a -> a
unSC
instance MethodSym SwiftCode Doc (Doc, Terminator) MethodData where
docMain :: MS (SwiftCode Doc) -> MS (SwiftCode MethodData)
docMain = MS (SwiftCode Doc) -> MS (SwiftCode MethodData)
forall (r :: * -> *) vis smt md.
MethodSym r vis smt md =>
MS (r Doc) -> MS (r md)
mainFunction
function :: String
-> SwiftCode Doc
-> VS (SwiftCode TypeData)
-> [MS (SwiftCode ParamData)]
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
function = String
-> SwiftCode Doc
-> VS (SwiftCode TypeData)
-> [MS (SwiftCode ParamData)]
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
forall (r :: * -> *) att vis md.
(AttachmentSym r att, OORenderMethod r vis md att) =>
String
-> r vis
-> VS (r TypeData)
-> [MS (r ParamData)]
-> MS (r Doc)
-> MS (r md)
G.function
mainFunction :: MS (SwiftCode Doc) -> MS (SwiftCode MethodData)
mainFunction = MS (SwiftCode Doc) -> MS (SwiftCode MethodData)
forall (r :: * -> *) md.
(BodyElim r, RenderMethod r md) =>
MS (r Doc) -> MS (r md)
CP.mainBody
docFunc :: String
-> [String]
-> Maybe String
-> MS (SwiftCode MethodData)
-> MS (SwiftCode MethodData)
docFunc = FuncDocRenderer
-> String
-> [String]
-> Maybe String
-> MS (SwiftCode MethodData)
-> MS (SwiftCode MethodData)
forall (r :: * -> *) md.
RenderMethod r md =>
FuncDocRenderer
-> String -> [String] -> Maybe String -> MS (r md) -> MS (r md)
G.docFunc FuncDocRenderer
CP.functionDoc
inOutFunc :: String -> SwiftCode Doc -> InOutFunc SwiftCode MethodData
inOutFunc String
n SwiftCode Doc
s = (VS (SwiftCode TypeData)
-> [MS (SwiftCode ParamData)]
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData))
-> InOutFunc SwiftCode MethodData
forall (r :: * -> *) smt md.
(InternalControlStmt r smt, SharedStatement r smt, RenderBody r,
RenderType r, VariableElim r) =>
(VS (r TypeData) -> [MS (r ParamData)] -> MS (r Doc) -> MS (r md))
-> [SVariable r]
-> [SVariable r]
-> [SVariable r]
-> MS (r Doc)
-> MS (r md)
CP.inOutFunc (String
-> SwiftCode Doc
-> VS (SwiftCode TypeData)
-> [MS (SwiftCode ParamData)]
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
forall (r :: * -> *) vis smt md.
MethodSym r vis smt md =>
String
-> r vis
-> VS (r TypeData)
-> [MS (r ParamData)]
-> MS (r Doc)
-> MS (r md)
function String
n SwiftCode Doc
s)
docInOutFunc :: String -> SwiftCode Doc -> DocInOutFunc SwiftCode MethodData
docInOutFunc String
n SwiftCode Doc
s = FuncDocRenderer
-> InOutFunc SwiftCode MethodData
-> DocInOutFunc SwiftCode MethodData
forall (r :: * -> *) md.
RenderMethod r md =>
FuncDocRenderer
-> ([SVariable r]
-> [SVariable r] -> [SVariable r] -> MS (r Doc) -> MS (r md))
-> String
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> MS (r Doc)
-> MS (r md)
CP.docInOutFunc' FuncDocRenderer
CP.functionDoc (String -> SwiftCode Doc -> InOutFunc SwiftCode MethodData
forall (r :: * -> *) vis smt md.
MethodSym r vis smt md =>
String -> r vis -> InOutFunc r md
inOutFunc String
n SwiftCode Doc
s)
instance OOMethodSym SwiftCode Doc (Doc, Terminator) MethodData Doc where
method :: String
-> SwiftCode Doc
-> SwiftCode Doc
-> VS (SwiftCode TypeData)
-> [MS (SwiftCode ParamData)]
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
method = String
-> SwiftCode Doc
-> SwiftCode Doc
-> VS (SwiftCode TypeData)
-> [MS (SwiftCode ParamData)]
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
forall (r :: * -> *) vis md att.
OORenderMethod r vis md att =>
String
-> r vis
-> r att
-> VS (r TypeData)
-> [MS (r ParamData)]
-> MS (r Doc)
-> MS (r md)
G.method
getMethod :: SVariable SwiftCode -> MS (SwiftCode MethodData)
getMethod = SVariable SwiftCode -> MS (SwiftCode MethodData)
forall (r :: * -> *) vis smt md svr att.
OORenderSym r vis smt md svr att =>
SVariable r -> MS (r md)
G.getMethod
setMethod :: SVariable SwiftCode -> MS (SwiftCode MethodData)
setMethod = SVariable SwiftCode -> MS (SwiftCode MethodData)
forall (r :: * -> *) vis smt md svr att.
OORenderSym r vis smt md svr att =>
SVariable r -> MS (r md)
G.setMethod
constructor :: [MS (SwiftCode ParamData)]
-> NamedArgs SwiftCode
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
constructor = [MS (SwiftCode ParamData)]
-> NamedArgs SwiftCode
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
swiftConstructor
inOutMethod :: String
-> SwiftCode Doc -> SwiftCode Doc -> InOutFunc SwiftCode MethodData
inOutMethod String
n SwiftCode Doc
s SwiftCode Doc
p = (VS (SwiftCode TypeData)
-> [MS (SwiftCode ParamData)]
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData))
-> InOutFunc SwiftCode MethodData
forall (r :: * -> *) smt md.
(InternalControlStmt r smt, SharedStatement r smt, RenderBody r,
RenderType r, VariableElim r) =>
(VS (r TypeData) -> [MS (r ParamData)] -> MS (r Doc) -> MS (r md))
-> [SVariable r]
-> [SVariable r]
-> [SVariable r]
-> MS (r Doc)
-> MS (r md)
CP.inOutFunc (String
-> SwiftCode Doc
-> SwiftCode Doc
-> VS (SwiftCode TypeData)
-> [MS (SwiftCode ParamData)]
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
forall (r :: * -> *) vis smt md att.
OOMethodSym r vis smt md att =>
String
-> r vis
-> r att
-> VS (r TypeData)
-> [MS (r ParamData)]
-> MS (r Doc)
-> MS (r md)
method String
n SwiftCode Doc
s SwiftCode Doc
p)
docInOutMethod :: String
-> SwiftCode Doc
-> SwiftCode Doc
-> DocInOutFunc SwiftCode MethodData
docInOutMethod String
n SwiftCode Doc
s SwiftCode Doc
p = FuncDocRenderer
-> InOutFunc SwiftCode MethodData
-> DocInOutFunc SwiftCode MethodData
forall (r :: * -> *) md.
RenderMethod r md =>
FuncDocRenderer
-> ([SVariable r]
-> [SVariable r] -> [SVariable r] -> MS (r Doc) -> MS (r md))
-> String
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> MS (r Doc)
-> MS (r md)
CP.docInOutFunc' FuncDocRenderer
CP.functionDoc (String
-> SwiftCode Doc -> SwiftCode Doc -> InOutFunc SwiftCode MethodData
forall (r :: * -> *) vis smt md att.
OOMethodSym r vis smt md att =>
String -> r vis -> r att -> InOutFunc r md
inOutMethod String
n SwiftCode Doc
s SwiftCode Doc
p)
instance RenderMethod SwiftCode MethodData where
commentedFunc :: MS (SwiftCode Doc)
-> MS (SwiftCode MethodData) -> MS (SwiftCode MethodData)
commentedFunc MS (SwiftCode Doc)
cmt MS (SwiftCode MethodData)
m = (SwiftCode MethodData
-> SwiftCode (Doc -> Doc) -> SwiftCode MethodData)
-> MS (SwiftCode MethodData)
-> State MethodState (SwiftCode (Doc -> Doc))
-> MS (SwiftCode MethodData)
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues ((MethodData -> (Doc -> Doc) -> MethodData)
-> SwiftCode MethodData
-> SwiftCode (Doc -> Doc)
-> SwiftCode MethodData
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues MethodData -> (Doc -> Doc) -> MethodData
updateMthd) MS (SwiftCode MethodData)
m
((SwiftCode Doc -> SwiftCode (Doc -> Doc))
-> MS (SwiftCode Doc) -> State MethodState (SwiftCode (Doc -> Doc))
forall a b s. (a -> b) -> State s a -> State s b
onStateValue ((Doc -> Doc -> Doc) -> SwiftCode Doc -> SwiftCode (Doc -> Doc)
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue Doc -> Doc -> Doc
R.commentedItem) MS (SwiftCode Doc)
cmt)
mthdFromData :: VisibilityTag -> Doc -> MS (SwiftCode MethodData)
mthdFromData VisibilityTag
_ Doc
d = SwiftCode MethodData -> MS (SwiftCode MethodData)
forall a s. a -> State s a
toState (SwiftCode MethodData -> MS (SwiftCode MethodData))
-> SwiftCode MethodData -> MS (SwiftCode MethodData)
forall a b. (a -> b) -> a -> b
$ MethodData -> SwiftCode MethodData
forall (r :: * -> *) a. Monad r => a -> r a
toCode (MethodData -> SwiftCode MethodData)
-> MethodData -> SwiftCode MethodData
forall a b. (a -> b) -> a -> b
$ Doc -> MethodData
mthd Doc
d
instance OORenderMethod SwiftCode Doc MethodData Doc where
intMethod :: Bool
-> String
-> SwiftCode Doc
-> SwiftCode Doc
-> MSMthdType SwiftCode
-> [MS (SwiftCode ParamData)]
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
intMethod Bool
_ = String
-> SwiftCode Doc
-> SwiftCode Doc
-> MSMthdType SwiftCode
-> [MS (SwiftCode ParamData)]
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
swiftMethod
intFunc :: Bool
-> String
-> SwiftCode Doc
-> SwiftCode Doc
-> MSMthdType SwiftCode
-> [MS (SwiftCode ParamData)]
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
intFunc Bool
_ String
n SwiftCode Doc
s SwiftCode Doc
_ = String
-> SwiftCode Doc
-> SwiftCode Doc
-> MSMthdType SwiftCode
-> [MS (SwiftCode ParamData)]
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
swiftMethod String
n SwiftCode Doc
s SwiftCode Doc
forall (r :: * -> *) att. AttachmentSym r att => r att
instanceLevel
destructor :: forall svr. [CSStateVar SwiftCode svr] -> MS (SwiftCode MethodData)
destructor [CSStateVar SwiftCode svr]
_ = String -> MS (SwiftCode MethodData)
forall a. HasCallStack => String -> a
error (String -> MS (SwiftCode MethodData))
-> String -> MS (SwiftCode MethodData)
forall a b. (a -> b) -> a -> b
$ String -> String
CP.destructorError String
swiftName
instance MethodElim SwiftCode MethodData where
method :: SwiftCode MethodData -> Doc
method = MethodData -> Doc
mthdDoc (MethodData -> Doc)
-> (SwiftCode MethodData -> MethodData)
-> SwiftCode MethodData
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode MethodData -> MethodData
forall a. SwiftCode a -> a
unSC
instance StateVarSym SwiftCode Doc Doc Doc where
stateVar :: SwiftCode Doc
-> SwiftCode Doc -> SVariable SwiftCode -> CSStateVar SwiftCode Doc
stateVar SwiftCode Doc
s SwiftCode Doc
p SVariable SwiftCode
vr = do
SwiftCode Variable
v <- LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode Variable))
ClassState
ValueState
-> SVariable SwiftCode
-> StateT ClassState Identity (SwiftCode Variable)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) ClassState ValueState
-> StateT ValueState Identity c -> StateT ClassState 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) (SwiftCode Variable))
ClassState
ValueState
(ValueState -> Focusing Identity (SwiftCode Variable) ValueState)
-> ClassState -> Focusing Identity (SwiftCode Variable) ClassState
Lens' ClassState ValueState
lensCStoVS SVariable SwiftCode
vr
SwiftCode Doc
-> SwiftCode Doc
-> SVariable SwiftCode
-> SValue SwiftCode
-> CSStateVar SwiftCode Doc
forall (r :: * -> *) vis svr att.
StateVarSym r vis svr att =>
r vis -> r att -> SVariable r -> SValue r -> CSStateVar r svr
stateVarDef SwiftCode Doc
s SwiftCode Doc
p SVariable SwiftCode
vr (CodeType -> SValue SwiftCode
forall (r :: * -> *).
(Literal r, OOTypeSym r) =>
CodeType -> SValue r
typeDfltVal (CodeType -> SValue SwiftCode) -> CodeType -> SValue SwiftCode
forall a b. (a -> b) -> a -> b
$ SwiftCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (SwiftCode TypeData -> CodeType) -> SwiftCode TypeData -> CodeType
forall a b. (a -> b) -> a -> b
$ SwiftCode Variable -> SwiftCode TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType SwiftCode Variable
v)
stateVarDef :: SwiftCode Doc
-> SwiftCode Doc
-> SVariable SwiftCode
-> SValue SwiftCode
-> CSStateVar SwiftCode Doc
stateVarDef = SwiftCode Doc
-> SwiftCode Doc
-> SVariable SwiftCode
-> SValue SwiftCode
-> CSStateVar SwiftCode Doc
forall (r :: * -> *) vis smt md svr att.
(OORenderSym r vis smt md svr att, Monad r) =>
r vis -> r att -> SVariable r -> SValue r -> CS (r Doc)
CP.stateVarDef
constVar :: SwiftCode Doc
-> SVariable SwiftCode
-> SValue SwiftCode
-> CSStateVar SwiftCode Doc
constVar = Doc
-> SwiftCode Doc
-> SVariable SwiftCode
-> SValue SwiftCode
-> CSStateVar SwiftCode Doc
forall (r :: * -> *) vis smt md.
(CommonRenderSym r vis smt md, Monad r) =>
Doc -> r vis -> SVariable r -> SValue r -> CS (r Doc)
CP.constVar (SwiftCode Doc -> Doc
forall (r :: * -> *) att. PermElim r att => r att -> Doc
RC.perm (SwiftCode Doc
forall (r :: * -> *) att. AttachmentSym r att => r att
classLevel :: SwiftCode Doc))
instance StateVarElim SwiftCode StateVar where
stateVar :: SwiftCode Doc -> Doc
stateVar = SwiftCode Doc -> Doc
forall a. SwiftCode a -> a
unSC
instance ClassSym SwiftCode Doc (Doc, Terminator) MethodData StateVar Doc where
buildClass :: Maybe String
-> [CSStateVar SwiftCode Doc]
-> [MS (SwiftCode MethodData)]
-> [MS (SwiftCode MethodData)]
-> CSStateVar SwiftCode Doc
buildClass = Maybe String
-> [CSStateVar SwiftCode Doc]
-> [MS (SwiftCode MethodData)]
-> [MS (SwiftCode MethodData)]
-> CSStateVar SwiftCode Doc
forall (r :: * -> *) vis md svr.
(RenderClass r vis md svr, VisibilitySym r vis) =>
Maybe String
-> [CSStateVar r svr] -> [MS (r md)] -> [MS (r md)] -> CS (r Doc)
G.buildClass
extraClass :: String
-> Maybe String
-> [CSStateVar SwiftCode Doc]
-> [MS (SwiftCode MethodData)]
-> [MS (SwiftCode MethodData)]
-> CSStateVar SwiftCode Doc
extraClass = String
-> Maybe String
-> [CSStateVar SwiftCode Doc]
-> [MS (SwiftCode MethodData)]
-> [MS (SwiftCode MethodData)]
-> CSStateVar SwiftCode Doc
forall (r :: * -> *) vis md svr.
(RenderClass r vis md svr, VisibilitySym r vis) =>
String
-> Maybe String
-> [CSStateVar r svr]
-> [MS (r md)]
-> [MS (r md)]
-> CS (r Doc)
CP.extraClass
implementingClass :: String
-> [String]
-> [CSStateVar SwiftCode Doc]
-> [MS (SwiftCode MethodData)]
-> [MS (SwiftCode MethodData)]
-> CSStateVar SwiftCode Doc
implementingClass = String
-> [String]
-> [CSStateVar SwiftCode Doc]
-> [MS (SwiftCode MethodData)]
-> [MS (SwiftCode MethodData)]
-> CSStateVar SwiftCode Doc
forall (r :: * -> *) vis md svr.
(RenderClass r vis md svr, VisibilitySym r vis) =>
String
-> [String]
-> [CSStateVar r svr]
-> [MS (r md)]
-> [MS (r md)]
-> CS (r Doc)
G.implementingClass
docClass :: String -> CSStateVar SwiftCode Doc -> CSStateVar SwiftCode Doc
docClass = ClassDocRenderer
-> String -> CSStateVar SwiftCode Doc -> CSStateVar SwiftCode Doc
forall (r :: * -> *) vis md svr.
RenderClass r vis md svr =>
ClassDocRenderer -> String -> CS (r Doc) -> CS (r Doc)
G.docClass ClassDocRenderer
swiftClassDoc
instance RenderClass SwiftCode Doc MethodData StateVar where
intClass :: String
-> SwiftCode Doc
-> SwiftCode Doc
-> [CSStateVar SwiftCode Doc]
-> [MS (SwiftCode MethodData)]
-> [MS (SwiftCode MethodData)]
-> CSStateVar SwiftCode Doc
intClass = (String -> Doc -> Doc -> Doc -> Doc -> Doc)
-> String
-> SwiftCode Doc
-> SwiftCode Doc
-> [CSStateVar SwiftCode Doc]
-> [MS (SwiftCode MethodData)]
-> [MS (SwiftCode MethodData)]
-> CSStateVar SwiftCode Doc
forall (r :: * -> *) md svr vis.
(MethodElim r md, Monad r, StateVarElim r svr,
VisibilityElim r vis) =>
(String -> Doc -> Doc -> Doc -> Doc -> Doc)
-> String
-> r vis
-> r Doc
-> [CSStateVar r svr]
-> [MS (r md)]
-> [MS (r md)]
-> CS (r Doc)
CP.intClass String -> Doc -> Doc -> Doc -> Doc -> Doc
R.class'
inherit :: Maybe String -> SwiftCode Doc
inherit = Maybe String -> SwiftCode Doc
forall (r :: * -> *). Monad r => Maybe String -> r Doc
CP.inherit
implements :: [String] -> SwiftCode Doc
implements = [String] -> SwiftCode Doc
forall (r :: * -> *). Monad r => [String] -> r Doc
CP.implements
commentedClass :: CSStateVar SwiftCode Doc
-> CSStateVar SwiftCode Doc -> CSStateVar SwiftCode Doc
commentedClass = CSStateVar SwiftCode Doc
-> CSStateVar SwiftCode Doc -> CSStateVar SwiftCode Doc
forall (r :: * -> *).
(BlockCommentElim r, ClassElim r, Monad r) =>
CS (r Doc) -> CS (r Doc) -> CS (r Doc)
G.commentedClass
instance ClassElim SwiftCode where
class' :: SwiftCode Doc -> Doc
class' = SwiftCode Doc -> Doc
forall a. SwiftCode a -> a
unSC
instance ModuleSym SwiftCode Doc (Doc, Terminator) MethodData StateVar Doc where
buildModule :: String
-> [String]
-> [MS (SwiftCode MethodData)]
-> [CSStateVar SwiftCode Doc]
-> FS (SwiftCode Module)
buildModule String
n [String]
is [MS (SwiftCode MethodData)]
fs [CSStateVar SwiftCode Doc]
cs = do
(FileState -> FileState) -> StateT FileState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> FileState -> FileState
setModuleName String
n)
[SwiftCode MethodData]
fns <- (MS (SwiftCode MethodData)
-> StateT FileState Identity (SwiftCode MethodData))
-> [MS (SwiftCode MethodData)]
-> StateT FileState Identity [SwiftCode 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) (SwiftCode MethodData))
FileState
MethodState
-> MS (SwiftCode MethodData)
-> StateT FileState Identity (SwiftCode 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) (SwiftCode MethodData))
FileState
MethodState
(MethodState
-> Focusing Identity (SwiftCode MethodData) MethodState)
-> FileState -> Focusing Identity (SwiftCode MethodData) FileState
Lens' FileState MethodState
lensFStoMS) [MS (SwiftCode MethodData)]
fs
[SwiftCode Doc]
cls <- (CSStateVar SwiftCode Doc -> FS (SwiftCode Doc))
-> [CSStateVar SwiftCode Doc]
-> StateT FileState Identity [SwiftCode Doc]
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 ClassState Identity) (SwiftCode Doc))
FileState
ClassState
-> CSStateVar SwiftCode Doc -> FS (SwiftCode Doc)
forall c.
LensLike'
(Zoomed (StateT ClassState Identity) c) FileState ClassState
-> StateT ClassState 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 ClassState Identity) (SwiftCode Doc))
FileState
ClassState
(ClassState -> Focusing Identity (SwiftCode Doc) ClassState)
-> FileState -> Focusing Identity (SwiftCode Doc) FileState
Lens' FileState ClassState
lensFStoCS) [CSStateVar SwiftCode Doc]
cs
Bool
mn <- FS Bool
getCurrMain
let modName :: String
modName = if Bool
mn then String
swiftMain else String
n
String
-> FS Doc
-> FS Doc
-> FS Doc
-> [MS (SwiftCode MethodData)]
-> [CSStateVar SwiftCode Doc]
-> FS (SwiftCode Module)
forall (r :: * -> *) md.
(ClassElim r, MethodElim r md, RenderMod r) =>
String
-> FS Doc
-> FS Doc
-> FS Doc
-> [MS (r md)]
-> [CS (r Doc)]
-> FS (r Module)
CP.buildModule String
modName (do
[String]
lis <- FS [String]
getLangImports
[String]
libis <- FS [String]
getLibImports
Doc -> FS Doc
forall a. a -> StateT FileState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Doc -> FS Doc) -> Doc -> FS Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (String -> Doc) -> [String] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (SwiftCode Doc -> Doc
forall (r :: * -> *). UnRepr r Doc => r Doc -> Doc
RC.import' (SwiftCode Doc -> Doc)
-> (String -> SwiftCode Doc) -> String -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(String -> SwiftCode Doc
forall (r :: * -> *). ImportSym r => String -> r Doc
langImport :: Label -> SwiftCode Doc))
([String] -> [String]
forall a. Ord a => [a] -> [a]
sort ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ [String]
lis [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
is [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
libis))
(LensLike'
(Zoomed (StateT MethodState Identity) Doc) FileState MethodState
-> StateT MethodState Identity Doc -> FS Doc
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) Doc) FileState MethodState
(MethodState -> Focusing Identity Doc MethodState)
-> FileState -> Focusing Identity Doc FileState
Lens' FileState MethodState
lensFStoMS StateT MethodState Identity Doc
swiftStringError) FS Doc
getMainDoc
((SwiftCode MethodData -> MS (SwiftCode MethodData))
-> [SwiftCode MethodData] -> [MS (SwiftCode MethodData)]
forall a b. (a -> b) -> [a] -> [b]
map SwiftCode MethodData -> MS (SwiftCode MethodData)
forall a. a -> StateT MethodState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [SwiftCode MethodData]
fns) ((SwiftCode Doc -> CSStateVar SwiftCode Doc)
-> [SwiftCode Doc] -> [CSStateVar SwiftCode Doc]
forall a b. (a -> b) -> [a] -> [b]
map SwiftCode Doc -> CSStateVar SwiftCode Doc
forall a. a -> StateT ClassState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [SwiftCode Doc]
cls)
instance RenderMod SwiftCode where
modFromData :: String -> FS Doc -> FS (SwiftCode Module)
modFromData String
n = String
-> (Doc -> SwiftCode Module) -> FS Doc -> FS (SwiftCode Module)
forall (r :: * -> *).
String -> (Doc -> r Module) -> FS Doc -> FS (r Module)
G.modFromData String
n (Module -> SwiftCode Module
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Module -> SwiftCode Module)
-> (Doc -> Module) -> Doc -> SwiftCode Module
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc -> Module
md String
n)
updateModuleDoc :: (Doc -> Doc) -> SwiftCode Module -> SwiftCode Module
updateModuleDoc Doc -> Doc
f = (Module -> Module) -> SwiftCode Module -> SwiftCode Module
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ((Doc -> Doc) -> Module -> Module
updateMod Doc -> Doc
f)
instance ModuleElim SwiftCode where
module' :: SwiftCode Module -> Doc
module' = Module -> Doc
modDoc (Module -> Doc)
-> (SwiftCode Module -> Module) -> SwiftCode Module -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode Module -> Module
forall a. SwiftCode a -> a
unSC
instance BlockCommentSym SwiftCode where
blockComment :: [String] -> SwiftCode Doc
blockComment [String]
lns = Doc -> SwiftCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> SwiftCode Doc) -> Doc -> SwiftCode Doc
forall a b. (a -> b) -> a -> b
$ [String] -> Doc -> Doc -> Doc
R.blockCmt [String]
lns Doc
blockCmtStart Doc
blockCmtEnd
docComment :: forall a. State a [String] -> State a (SwiftCode Doc)
docComment = ([String] -> SwiftCode Doc)
-> State a [String] -> State a (SwiftCode Doc)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue (\[String]
lns -> Doc -> SwiftCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> SwiftCode Doc) -> Doc -> SwiftCode Doc
forall a b. (a -> b) -> a -> b
$ [String] -> Doc -> Doc -> Doc
R.docCmt [String]
lns Doc
docCmtStart
Doc
blockCmtEnd)
instance BlockCommentElim SwiftCode where
blockComment' :: SwiftCode Doc -> Doc
blockComment' = SwiftCode Doc -> Doc
forall a. SwiftCode a -> a
unSC
addMathImport :: VS a -> VS a
addMathImport :: forall a. VS a -> VS a
addMathImport = StateT ValueState Identity ()
-> StateT ValueState Identity a -> StateT ValueState Identity a
forall a b.
StateT ValueState Identity a
-> StateT ValueState Identity b -> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
(>>) (StateT ValueState Identity ()
-> StateT ValueState Identity a -> StateT ValueState Identity a)
-> StateT ValueState Identity ()
-> StateT ValueState Identity a
-> StateT ValueState Identity a
forall a b. (a -> b) -> a -> b
$ (ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addLangImportVS String
swiftMath)
addFoundationImport :: VS a -> VS a
addFoundationImport :: forall a. VS a -> VS a
addFoundationImport = StateT ValueState Identity ()
-> StateT ValueState Identity a -> StateT ValueState Identity a
forall a b.
StateT ValueState Identity a
-> StateT ValueState Identity b -> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
(>>) (StateT ValueState Identity ()
-> StateT ValueState Identity a -> StateT ValueState Identity a)
-> StateT ValueState Identity ()
-> StateT ValueState Identity a
-> StateT ValueState Identity a
forall a b. (a -> b) -> a -> b
$ (ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addLangImportVS String
swiftFoundation)
swiftName, swiftVersion :: String
swiftName :: String
swiftName = String
"Swift"
swiftVersion :: String
swiftVersion = String
"5.2.4"
swiftUnwrapVal :: (RenderValue r, ValueElim r, ValueSym r) => SValue r -> SValue r
swiftUnwrapVal :: forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r
swiftUnwrapVal SValue r
v' = do
r Value
v <- SValue r
v'
r TypeData -> Doc -> SValue r
forall (r :: * -> *).
RenderValue r =>
r TypeData -> Doc -> SValue r
mkVal (r Value -> r TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType r Value
v) (r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
v Doc -> Doc -> Doc
<> Doc
swiftUnwrap')
swiftTryVal :: (RenderValue r, ValueElim r, ValueSym r) => SValue r -> SValue r
swiftTryVal :: forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r
swiftTryVal SValue r
v' = do
r Value
v <- SValue r
v'
r TypeData -> Doc -> SValue r
forall (r :: * -> *).
RenderValue r =>
r TypeData -> Doc -> SValue r
mkVal (r Value -> r TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType r Value
v) (Doc
tryLabel Doc -> Doc -> Doc
<+> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
v)
swiftArgVal :: (RenderValue r, ValueElim r, ValueSym r) => SValue r -> SValue r
swiftArgVal :: forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r
swiftArgVal SValue r
v' = do
r Value
v <- SValue r
v'
r TypeData -> Doc -> SValue r
forall (r :: * -> *).
RenderValue r =>
r TypeData -> Doc -> SValue r
mkVal (r Value -> r TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType r Value
v) (Doc
swiftInOutArg Doc -> Doc -> Doc
<> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
v)
swiftContentsVar, swiftLineVar :: SVariable SwiftCode
swiftContentsVar :: SVariable SwiftCode
swiftContentsVar = String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
"goolContents" (VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType (VS (SwiftCode TypeData) -> VS (SwiftCode TypeData))
-> VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
forall a b. (a -> b) -> a -> b
$ VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string)
swiftLineVar :: SVariable SwiftCode
swiftLineVar = String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
"goolLine" (VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string)
swiftContentsVal, swiftLineVal :: SValue SwiftCode
swiftContentsVal :: SValue SwiftCode
swiftContentsVal = SVariable SwiftCode -> SValue SwiftCode
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable SwiftCode
swiftContentsVar
swiftLineVal :: SValue SwiftCode
swiftLineVal = SVariable SwiftCode -> SValue SwiftCode
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable SwiftCode
swiftLineVar
swiftIntType :: (Monad r) => VS (r TypeData)
swiftIntType :: forall (r :: * -> *). Monad r => VS (r TypeData)
swiftIntType = CodeType -> String -> Doc -> VS (r TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
Integer String
swiftInt (String -> Doc
text String
swiftInt)
swiftCharType :: (Monad r) => VS (r TypeData)
swiftCharType :: forall (r :: * -> *). Monad r => VS (r TypeData)
swiftCharType = CodeType -> String -> Doc -> VS (r TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
Char String
swiftChar (String -> Doc
text String
swiftChar)
swiftFileType :: (Monad r) => VS (r TypeData)
swiftFileType :: forall (r :: * -> *). Monad r => VS (r TypeData)
swiftFileType = VS (r TypeData) -> VS (r TypeData)
forall a. VS a -> VS a
addFoundationImport (VS (r TypeData) -> VS (r TypeData))
-> VS (r TypeData) -> VS (r TypeData)
forall a b. (a -> b) -> a -> b
$ CodeType -> String -> Doc -> VS (r TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
InFile String
swiftURL
(String -> Doc
text String
swiftURL)
swiftFileHdlType :: (Monad r) => VS (r TypeData)
swiftFileHdlType :: forall (r :: * -> *). Monad r => VS (r TypeData)
swiftFileHdlType = VS (r TypeData) -> VS (r TypeData)
forall a. VS a -> VS a
addFoundationImport (VS (r TypeData) -> VS (r TypeData))
-> VS (r TypeData) -> VS (r TypeData)
forall a b. (a -> b) -> a -> b
$ CodeType -> String -> Doc -> VS (r TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
OutFile String
swiftFileHdl
(String -> Doc
text String
swiftFileHdl)
swiftListType :: VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
swiftListType :: VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
swiftListType VS (SwiftCode TypeData)
t' = do
SwiftCode TypeData
t <- VS (SwiftCode TypeData)
t'
CodeType -> String -> Doc -> VS (SwiftCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData (CodeType -> CodeType
List (CodeType -> CodeType) -> CodeType -> CodeType
forall a b. (a -> b) -> a -> b
$ SwiftCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType SwiftCode TypeData
t) (String
"[" String -> String -> String
forall a. [a] -> [a] -> [a]
++ SwiftCode TypeData -> String
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> String
getTypeString SwiftCode TypeData
t String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"]")
(Doc -> Doc
brackets (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ SwiftCode TypeData -> Doc
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> Doc
renderType SwiftCode TypeData
t)
swiftFuncType :: [VS (SwiftCode TypeData)] -> VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
swiftFuncType :: [VS (SwiftCode TypeData)]
-> VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
swiftFuncType [VS (SwiftCode TypeData)]
ps VS (SwiftCode TypeData)
r = do
[SwiftCode TypeData]
pts <- [VS (SwiftCode TypeData)]
-> StateT ValueState Identity [SwiftCode TypeData]
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 (SwiftCode TypeData)]
ps
SwiftCode TypeData
rt <- VS (SwiftCode TypeData)
r
CodeType -> String -> Doc -> VS (SwiftCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData ([CodeType] -> CodeType -> CodeType
Func ((SwiftCode TypeData -> CodeType)
-> [SwiftCode TypeData] -> [CodeType]
forall a b. (a -> b) -> [a] -> [b]
map SwiftCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType [SwiftCode TypeData]
pts) (SwiftCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType SwiftCode TypeData
rt))
(String
"(" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
listSep ((SwiftCode TypeData -> String) -> [SwiftCode TypeData] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map SwiftCode TypeData -> String
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> String
getTypeString [SwiftCode TypeData]
pts) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
")" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" " String -> String -> String
forall a. [a] -> [a] -> [a]
++
String
swiftRetType String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" " String -> String -> String
forall a. [a] -> [a] -> [a]
++ SwiftCode TypeData -> String
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> String
getTypeString SwiftCode TypeData
rt)
(Doc -> Doc
parens (Doc -> [Doc] -> Doc
hicat Doc
listSep' ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (SwiftCode TypeData -> Doc) -> [SwiftCode TypeData] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map SwiftCode TypeData -> Doc
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> Doc
renderType [SwiftCode TypeData]
pts) Doc -> Doc -> Doc
<+> Doc
swiftRetType' Doc -> Doc -> Doc
<+>
SwiftCode TypeData -> Doc
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> Doc
renderType SwiftCode TypeData
rt)
swiftVoidType :: (Monad r) => VS (r TypeData)
swiftVoidType :: forall (r :: * -> *). Monad r => VS (r TypeData)
swiftVoidType = CodeType -> String -> Doc -> VS (r TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
Void String
swiftVoid (String -> Doc
text String
swiftVoid)
swiftPi, swiftFirst, swiftDesc, swiftUTF8, swiftVar, swiftConst,
swiftDo, swiftFunc, swiftCtorName, swiftExtension, swiftInOut, swiftError,
swiftDocDir, swiftUTF8Enc, swiftUserMask, swiftInOutArg, swiftNamedArgSep,
swiftTypeSpec, swiftConforms, swiftNoLabel, swiftRetType', swiftUnwrap',
swiftRetroactive :: Doc
swiftPi :: Doc
swiftPi = String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ String
CP.doubleRender String -> String -> String
`access` String
piLabel
swiftFirst :: Doc
swiftFirst = String -> Doc
text String
"first"
swiftDesc :: Doc
swiftDesc = String -> Doc
text String
"description"
swiftUTF8 :: Doc
swiftUTF8 = String -> Doc
text String
"utf8"
swiftVar :: Doc
swiftVar = String -> Doc
text String
"var"
swiftConst :: Doc
swiftConst = String -> Doc
text String
"let"
swiftDo :: Doc
swiftDo = String -> Doc
text String
"do"
swiftFunc :: Doc
swiftFunc = String -> Doc
text String
"func"
swiftCtorName :: Doc
swiftCtorName = String -> Doc
text String
"init"
swiftExtension :: Doc
swiftExtension = String -> Doc
text String
"extension"
swiftInOut :: Doc
swiftInOut = String -> Doc
text String
"inout"
swiftError :: Doc
swiftError = String -> Doc
text String
"Error"
swiftDocDir :: Doc
swiftDocDir = String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ String
"" String -> String -> String
`access` String
"documentDirectory"
swiftUTF8Enc :: Doc
swiftUTF8Enc = String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ String
"" String -> String -> String
`access` String
"utf8"
swiftUserMask :: Doc
swiftUserMask = String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ String
"" String -> String -> String
`access` String
"userDomainMask"
swiftNamedArgSep :: Doc
swiftNamedArgSep = Doc
colon Doc -> Doc -> Doc
<> Doc
space
swiftInOutArg :: Doc
swiftInOutArg = String -> Doc
text String
"&"
swiftTypeSpec :: Doc
swiftTypeSpec = Doc
colon
swiftConforms :: Doc
swiftConforms = Doc
colon
swiftNoLabel :: Doc
swiftNoLabel = String -> Doc
text String
"_"
swiftRetType' :: Doc
swiftRetType' = String -> Doc
text String
swiftRetType
swiftUnwrap' :: Doc
swiftUnwrap' = String -> Doc
text String
swiftUnwrap
swiftRetroactive :: Doc
swiftRetroactive = String -> Doc
text String
"@retroactive"
swiftMain, swiftFoundation, swiftMath, swiftNil, swiftInt, swiftChar,
swiftURL, swiftFileHdl, swiftRetType, swiftVoid, swiftCommLine,
swiftSearchDir, swiftPathMask, swiftArgs, swiftWrite, swiftIndex,
swiftStride, swiftMap, swiftListAdd, swiftListSize, swiftListRemove,
swiftListAppend, swiftReadLine, swiftSeekEnd, swiftClose, swiftJoined,
swiftAppendPath, swiftUrls, swiftSplit, swiftData, swiftEncoding, swiftOf,
swiftFrom, swiftTo, swiftBy, swiftAt, swiftTerm, swiftFor, swiftIn,
swiftContentsOf, swiftWriteTo, swiftSep, swiftSepBy, swiftUnwrap,
swiftContains, swiftSet, swiftUnion :: String
swiftMain :: String
swiftMain = String
"main"
swiftFoundation :: String
swiftFoundation = String
"Foundation"
swiftMath :: String
swiftMath = String
swiftFoundation
swiftNil :: String
swiftNil = String
"nil"
swiftInt :: String
swiftInt = String
"Int"
swiftChar :: String
swiftChar = String
"Character"
swiftURL :: String
swiftURL = String
"URL"
swiftFileHdl :: String
swiftFileHdl = String
"FileHandle"
swiftRetType :: String
swiftRetType = String
"->"
swiftVoid :: String
swiftVoid = String
"Void"
swiftCommLine :: String
swiftCommLine = String
"CommandLine"
swiftSearchDir :: String
swiftSearchDir = String
"SearchPathDirectory"
swiftPathMask :: String
swiftPathMask = String
"SearchPathDomainMask"
swiftArgs :: String
swiftArgs = String
"arguments"
swiftWrite :: String
swiftWrite = String
"write"
swiftIndex :: String
swiftIndex = String
"firstIndex"
swiftStride :: String
swiftStride = String
"stride"
swiftMap :: String
swiftMap = String
"map"
swiftListAdd :: String
swiftListAdd = String
"insert"
swiftListSize :: String
swiftListSize = String
"count"
swiftListRemove :: String
swiftListRemove = String
"remove"
swiftListAppend :: String
swiftListAppend = String
"append"
swiftReadLine :: String
swiftReadLine = String
"readLine"
swiftSeekEnd :: String
swiftSeekEnd = String
"seekToEnd"
swiftClose :: String
swiftClose = String
"close"
swiftJoined :: String
swiftJoined = String
"joined"
swiftAppendPath :: String
swiftAppendPath = String
"appendingPathComponent"
swiftUrls :: String
swiftUrls = String
"FileManager" String -> String -> String
`access` String
"default" String -> String -> String
`access` String
"urls"
swiftSplit :: String
swiftSplit = String
"components"
swiftData :: String
swiftData = String
"Data"
swiftEncoding :: String
swiftEncoding = String
"Encoding"
swiftOf :: String
swiftOf = String
"of"
swiftFrom :: String
swiftFrom = String
"from"
swiftTo :: String
swiftTo = String
"to"
swiftBy :: String
swiftBy = String
"by"
swiftAt :: String
swiftAt = String
"at"
swiftTerm :: String
swiftTerm = String
"terminator"
swiftFor :: String
swiftFor = String
"for"
swiftIn :: String
swiftIn = String
"in"
swiftContentsOf :: String
swiftContentsOf = String
"contentsOf"
swiftWriteTo :: String
swiftWriteTo = String
"forWritingTo"
swiftSep :: String
swiftSep = String
"separator"
swiftSepBy :: String
swiftSepBy = String
"separatedBy"
swiftUnwrap :: String
swiftUnwrap = String
"!"
swiftContains :: String
swiftContains = String
"contains"
swiftSet :: String
swiftSet = String
"Set"
swiftUnion :: String
swiftUnion = String
"union"
swiftUnaryMath :: (Monad r) => String -> VSOp r
swiftUnaryMath :: forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath = VS (r OpData) -> VS (r OpData)
forall a. VS a -> VS a
addMathImport (VS (r OpData) -> VS (r OpData))
-> (String -> VS (r OpData)) -> String -> VS (r OpData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> VS (r OpData)
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec
swiftNumBinExpr :: (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode) ->
SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftNumBinExpr :: (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftNumBinExpr SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
f SValue SwiftCode
v1' SValue SwiftCode
v2' = do
SwiftCode Value
v1 <- SValue SwiftCode
v1'
SwiftCode Value
v2 <- SValue SwiftCode
v2'
let exprT :: CodeType -> CodeType -> SValue SwiftCode
exprT CodeType
t1 CodeType
t2 = if CodeType
t1 CodeType -> CodeType -> Bool
forall a. Eq a => a -> a -> Bool
== CodeType
t2 then SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
f (SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v1) (SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v2) else CodeType -> CodeType -> SValue SwiftCode
exprT' CodeType
t1 CodeType
t2
exprT' :: CodeType -> CodeType -> SValue SwiftCode
exprT' CodeType
Double CodeType
_ = SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
f (SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v1) (VS (SwiftCode TypeData) -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> SValue r -> SValue r
cast VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
double (SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode
forall a b. (a -> b) -> a -> b
$ SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v2)
exprT' CodeType
_ CodeType
Double = SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
f (VS (SwiftCode TypeData) -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> SValue r -> SValue r
cast VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
double (SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode
forall a b. (a -> b) -> a -> b
$ SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v1) (SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v2)
exprT' CodeType
Float CodeType
_ = SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
f (SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v1) (VS (SwiftCode TypeData) -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> SValue r -> SValue r
cast VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
float (SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode
forall a b. (a -> b) -> a -> b
$ SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v2)
exprT' CodeType
_ CodeType
Float = SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
f (VS (SwiftCode TypeData) -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> SValue r -> SValue r
cast VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
float (SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode
forall a b. (a -> b) -> a -> b
$ SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v1) (SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v2)
exprT' CodeType
_ CodeType
_ = SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
f (SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v1) (SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v2)
CodeType -> CodeType -> SValue SwiftCode
exprT (SwiftCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (SwiftCode TypeData -> CodeType) -> SwiftCode TypeData -> CodeType
forall a b. (a -> b) -> a -> b
$ SwiftCode Value -> SwiftCode TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType SwiftCode Value
v1) (SwiftCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (SwiftCode TypeData -> CodeType) -> SwiftCode TypeData -> CodeType
forall a b. (a -> b) -> a -> b
$ SwiftCode Value -> SwiftCode TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType SwiftCode Value
v2)
swiftLitFloat :: (RenderValue r, TypeSym r) => Float -> SValue r
swiftLitFloat :: forall (r :: * -> *).
(RenderValue r, TypeSym r) =>
Float -> SValue r
swiftLitFloat = VS (r TypeData) -> Doc -> SValue r
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
float (Doc -> SValue r) -> (Float -> Doc) -> Float -> SValue r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Doc
D.float
swiftLambda :: [SwiftCode BinderD] -> SwiftCode Value -> Doc
swiftLambda :: [SwiftCode BinderD] -> SwiftCode Value -> Doc
swiftLambda [SwiftCode BinderD]
ps SwiftCode Value
ex = Doc -> Doc
braces (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ Doc -> Doc
parens (Doc -> [Doc] -> Doc
hicat Doc
listSep'
((Doc -> Doc -> Doc) -> [Doc] -> [Doc] -> [Doc]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Doc
n Doc
t -> Doc
n Doc -> Doc -> Doc
<> Doc
swiftTypeSpec Doc -> Doc -> Doc
<+> Doc
t)
((SwiftCode BinderD -> Doc) -> [SwiftCode BinderD] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map SwiftCode BinderD -> Doc
forall (r :: * -> *). InternalBinderElim r => r BinderD -> Doc
RC.binderElim [SwiftCode BinderD]
ps)
((SwiftCode BinderD -> Doc) -> [SwiftCode BinderD] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (SwiftCode TypeData -> Doc
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> Doc
renderType (SwiftCode TypeData -> Doc)
-> (SwiftCode BinderD -> SwiftCode TypeData)
-> SwiftCode BinderD
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode BinderD -> SwiftCode TypeData
forall (r :: * -> *). BinderElim r => r BinderD -> r TypeData
binderType) [SwiftCode BinderD]
ps)))
Doc -> Doc -> Doc
<+> Doc
swiftRetType' Doc -> Doc -> Doc
<+> SwiftCode TypeData -> Doc
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> Doc
renderType (SwiftCode Value -> SwiftCode TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType SwiftCode Value
ex) Doc -> Doc -> Doc
<+> Doc
inLabel Doc -> Doc -> Doc
<+> SwiftCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value SwiftCode Value
ex
swiftReadableTypes :: [CodeType]
swiftReadableTypes :: [CodeType]
swiftReadableTypes = [CodeType
Integer, CodeType
Double, CodeType
Float, CodeType
Boolean, CodeType
Char]
swiftCast :: VS (SwiftCode TypeData) -> SValue SwiftCode -> SValue SwiftCode
swiftCast :: VS (SwiftCode TypeData) -> SValue SwiftCode -> SValue SwiftCode
swiftCast VS (SwiftCode TypeData)
t' SValue SwiftCode
v' = do
SwiftCode TypeData
t <- VS (SwiftCode TypeData)
t'
SwiftCode Value
v <- SValue SwiftCode
v'
let unwrap :: SValue SwiftCode -> SValue SwiftCode
unwrap = if SwiftCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType SwiftCode TypeData
t CodeType -> [CodeType] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [CodeType]
swiftReadableTypes Bool -> Bool -> Bool
&&
SwiftCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (SwiftCode Value -> SwiftCode TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType SwiftCode Value
v) CodeType -> CodeType -> Bool
forall a. Eq a => a -> a -> Bool
== CodeType
String then SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r
swiftUnwrapVal else SValue SwiftCode -> SValue SwiftCode
forall a. a -> a
id
SValue SwiftCode -> SValue SwiftCode
unwrap (SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode
forall a b. (a -> b) -> a -> b
$ VS (SwiftCode TypeData) -> Doc -> SValue SwiftCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal (SwiftCode TypeData -> VS (SwiftCode TypeData)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode TypeData
t) (Doc -> Doc -> Doc
R.castObj (SwiftCode TypeData -> Doc
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> Doc
renderType SwiftCode TypeData
t) (SwiftCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value SwiftCode Value
v))
swiftIndexFunc
:: (InternalValueExp r, VariableSym r) => SValue r -> SValue r -> SValue r
swiftIndexFunc :: forall (r :: * -> *).
(InternalValueExp r, VariableSym r) =>
SValue r -> SValue r -> SValue r
swiftIndexFunc SValue r
l SValue r
v' = do
r Value
v <- SValue r
v'
let t :: StateT ValueState Identity (r TypeData)
t = r TypeData -> StateT ValueState Identity (r TypeData)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (r TypeData -> StateT ValueState Identity (r TypeData))
-> r TypeData -> StateT ValueState Identity (r TypeData)
forall a b. (a -> b) -> a -> b
$ r Value -> r TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType r Value
v
ofArg :: SVariable r
ofArg = String -> StateT ValueState Identity (r TypeData) -> SVariable r
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
swiftOf StateT ValueState Identity (r TypeData)
t
StateT ValueState Identity (r TypeData)
-> SValue r -> String -> NamedArgs r -> SValue r
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData) -> SValue r -> String -> NamedArgs r -> SValue r
objMethodCallNamedArgs StateT ValueState Identity (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
int SValue r
l String
swiftIndex [(SVariable r
ofArg, r Value -> SValue r
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure r Value
v)]
swiftStrideFunc
:: (RenderValue r, ValueExpression r)
=> SValue r -> SValue r -> SValue r -> SValue r
swiftStrideFunc :: forall (r :: * -> *).
(RenderValue r, ValueExpression r) =>
SValue r -> SValue r -> SValue r -> SValue r
swiftStrideFunc SValue r
beg SValue r
end SValue r
step = let t :: VS (r TypeData)
t = VS (r TypeData) -> VS (r TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
int
fromArg :: SVariable r
fromArg = String -> VS (r TypeData) -> SVariable r
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
swiftFrom VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
int
toArg :: SVariable r
toArg = String -> VS (r TypeData) -> SVariable r
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
swiftTo VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
int
byArg :: SVariable r
byArg = String -> VS (r TypeData) -> SVariable r
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
swiftBy VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
int
in VS (r TypeData) -> SValue r -> SValue r
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> SValue r -> SValue r
cast VS (r TypeData)
t (String -> VS (r TypeData) -> NamedArgs r -> SValue r
forall (r :: * -> *).
ValueExpression r =>
String -> VS (r TypeData) -> NamedArgs r -> SValue r
funcAppNamedArgs String
swiftStride VS (r TypeData)
t
[(SVariable r
fromArg, SValue r
beg), (SVariable r
toArg, SValue r
end), (SVariable r
byArg, SValue r
step)])
swiftMapFunc :: (InternalValueExp r) => SValue r -> SValue r -> SValue r
swiftMapFunc :: forall (r :: * -> *).
InternalValueExp r =>
SValue r -> SValue r -> SValue r
swiftMapFunc SValue r
lst SValue r
f = VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
objMethodCall ((r Value -> r TypeData) -> SValue r -> VS (r TypeData)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue r Value -> r TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType SValue r
lst) SValue r
lst String
swiftMap [SValue r
f]
swiftWriteFunc :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftWriteFunc :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftWriteFunc SValue SwiftCode
v SValue SwiftCode
f = let contentsArg :: SVariable SwiftCode
contentsArg = String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
swiftContentsOf (String -> VS (SwiftCode TypeData)
forall (r :: * -> *). OOTypeSym r => String -> VS (r TypeData)
obj String
swiftData)
in SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r
swiftTryVal (SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode
forall a b. (a -> b) -> a -> b
$ VS (SwiftCode TypeData)
-> SValue SwiftCode
-> String
-> NamedArgs SwiftCode
-> SValue SwiftCode
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData) -> SValue r -> String -> NamedArgs r -> SValue r
objMethodCallNamedArgs VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void SValue SwiftCode
f String
swiftWrite
[(SVariable SwiftCode
contentsArg, VS (SwiftCode TypeData) -> [SValue SwiftCode] -> SValue SwiftCode
forall (r :: * -> *). OOValueExpression r => PosCtorCall r
newObj (String -> VS (SwiftCode TypeData)
forall (r :: * -> *). OOTypeSym r => String -> VS (r TypeData)
obj String
swiftData) [SValue SwiftCode
v SValue SwiftCode -> VS (SwiftCode FuncData) -> SValue SwiftCode
forall (r :: * -> *).
OOFunctionSym r =>
SValue r -> VS (r FuncData) -> SValue r
$. Doc -> VS (SwiftCode TypeData) -> VS (SwiftCode FuncData)
forall (r :: * -> *).
RenderFunction r =>
Doc -> VS (r TypeData) -> VS (r FuncData)
funcFromData (Doc -> Doc
R.func Doc
swiftUTF8)
(String -> VS (SwiftCode TypeData)
forall (r :: * -> *). OOTypeSym r => String -> VS (r TypeData)
obj String
swiftEncoding)])]
swiftReadLineFunc :: (RenderValue r, ValueElim r, ValueExpression r) => SValue r
swiftReadLineFunc :: forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueExpression r) =>
SValue r
swiftReadLineFunc = SValue r -> SValue r
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r
swiftUnwrapVal (SValue r -> SValue r) -> SValue r -> SValue r
forall a b. (a -> b) -> a -> b
$ PosCall r
forall (r :: * -> *). ValueExpression r => PosCall r
funcApp String
swiftReadLine VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string []
swiftReadFileFunc
:: (RenderValue r, ValueElim r, ValueExpression r)
=> SValue r -> SValue r
swiftReadFileFunc :: forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueExpression r) =>
SValue r -> SValue r
swiftReadFileFunc SValue r
v = SValue r -> SValue r
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r
swiftTryVal (SValue r -> SValue r) -> SValue r -> SValue r
forall a b. (a -> b) -> a -> b
$
String -> VS (r TypeData) -> NamedArgs r -> SValue r
forall (r :: * -> *).
ValueExpression r =>
String -> VS (r TypeData) -> NamedArgs r -> SValue r
funcAppNamedArgs String
CP.stringRender' VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string [(SVariable r, SValue r)
contentsArg, (SVariable r, SValue r)
encodingArg]
where
encVal :: SValue r
encVal = VS (r TypeData) -> Doc -> SValue r
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string Doc
swiftUTF8Enc
contentsArg :: (SVariable r, SValue r)
contentsArg = (String -> VS (r TypeData) -> SVariable r
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
swiftContentsOf VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
infile, SValue r
v)
encodingArg :: (SVariable r, SValue r)
encodingArg = (String -> VS (r TypeData) -> SVariable r
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
"encoding" VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string, SValue r
encVal)
swiftSplitFunc
:: (InternalValueExp r, Literal r, VariableSym r)
=> Char -> SValue r -> SValue r
swiftSplitFunc :: forall (r :: * -> *).
(InternalValueExp r, Literal r, VariableSym r) =>
Char -> SValue r -> SValue r
swiftSplitFunc Char
d SValue r
s = let sepArg :: SVariable r
sepArg = String -> VS (r TypeData) -> SVariable r
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
swiftSepBy VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
char
in VS (r TypeData) -> SValue r -> String -> NamedArgs r -> SValue r
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData) -> SValue r -> String -> NamedArgs r -> SValue r
objMethodCallNamedArgs (VS (r TypeData) -> VS (r TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string) SValue r
s String
swiftSplit [(SVariable r
sepArg, Char -> SValue r
forall (r :: * -> *). Literal r => Char -> SValue r
litChar Char
d)]
swiftJoinedFunc
:: (InternalValueExp r, Literal r, VariableSym r)
=> Char -> SValue r -> SValue r
swiftJoinedFunc :: forall (r :: * -> *).
(InternalValueExp r, Literal r, VariableSym r) =>
Char -> SValue r -> SValue r
swiftJoinedFunc Char
d SValue r
s = let sepArg :: SVariable r
sepArg = String -> VS (r TypeData) -> SVariable r
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
swiftSep VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
char
in VS (r TypeData) -> SValue r -> String -> NamedArgs r -> SValue r
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData) -> SValue r -> String -> NamedArgs r -> SValue r
objMethodCallNamedArgs VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string SValue r
s String
swiftJoined [(SVariable r
sepArg, Char -> SValue r
forall (r :: * -> *). Literal r => Char -> SValue r
litChar Char
d)]
swiftIndexOf :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftIndexOf :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftIndexOf = SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r
swiftUnwrapVal (SValue SwiftCode -> SValue SwiftCode)
-> (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
.: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(InternalValueExp r, VariableSym r) =>
SValue r -> SValue r -> SValue r
swiftIndexFunc
swiftListSlice
:: SVariable SwiftCode
-> SValue SwiftCode
-> Maybe (SValue SwiftCode)
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> MS (SwiftCode Block)
swiftListSlice :: SVariable SwiftCode
-> SValue SwiftCode
-> Maybe (SValue SwiftCode)
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> MS (SwiftCode Doc)
swiftListSlice SVariable SwiftCode
vn SValue SwiftCode
vo Maybe (SValue SwiftCode)
beg Maybe (SValue SwiftCode)
end SValue SwiftCode
step = do
SwiftCode Variable
vnew <- LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode Variable))
MethodState
ValueState
-> SVariable SwiftCode
-> StateT MethodState Identity (SwiftCode 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) (SwiftCode Variable))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode Variable) ValueState)
-> MethodState
-> Focusing Identity (SwiftCode Variable) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable SwiftCode
vn
ScopeData
scpData <- String -> MS ScopeData
getVarScope (String -> MS ScopeData) -> String -> MS ScopeData
forall a b. (a -> b) -> a -> b
$ SwiftCode Variable -> String
forall (r :: * -> *). VariableElim r => r Variable -> String
variableName SwiftCode Variable
vnew
let scp :: SwiftCode ScopeData
scp = ScopeData -> SwiftCode ScopeData
forall (r :: * -> *). ScopeSym r => ScopeData -> r ScopeData
convScope ScopeData
scpData
SwiftCode Value
stepV <- LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode Value))
MethodState
ValueState
-> SValue SwiftCode
-> StateT MethodState Identity (SwiftCode 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) (SwiftCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode Value) ValueState)
-> MethodState -> Focusing Identity (SwiftCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue SwiftCode
step
let mbStepV :: Maybe Integer
mbStepV = SwiftCode Value -> Maybe Integer
forall (r :: * -> *). ValueElim r => r Value -> Maybe Integer
valueInt SwiftCode Value
stepV
String
begName <- Bool -> String -> MS String
genVarNameIf (Maybe (SValue SwiftCode) -> Bool
forall a. Maybe a -> Bool
isNothing Maybe (SValue SwiftCode)
beg Bool -> Bool -> Bool
&& Maybe Integer -> Bool
forall a. Maybe a -> Bool
isNothing Maybe Integer
mbStepV) String
"begIdx"
String
endName <- Bool -> String -> MS String
genVarNameIf (Maybe (SValue SwiftCode) -> Bool
forall a. Maybe a -> Bool
isNothing Maybe (SValue SwiftCode)
end Bool -> Bool -> Bool
&& Maybe Integer -> Bool
forall a. Maybe a -> Bool
isNothing Maybe Integer
mbStepV) String
"endIdx"
let (MS (SwiftCode (Doc, Terminator))
setBeg, SValue SwiftCode
begVal) = String
-> SValue SwiftCode
-> Maybe Integer
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> SwiftCode ScopeData
-> (MS (SwiftCode (Doc, Terminator)), SValue SwiftCode)
forall (r :: * -> *) smt.
SharedStatement r smt =>
String
-> SValue r
-> Maybe Integer
-> Maybe (SValue r)
-> SValue r
-> SValue r
-> r ScopeData
-> (MS (r smt), SValue r)
M.makeSetterVal String
begName SValue SwiftCode
step Maybe Integer
mbStepV Maybe (SValue SwiftCode)
beg (Integer -> SValue SwiftCode
forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
0) (SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *) smt. List r smt => SValue r -> SValue r
listSize SValue SwiftCode
vo SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
NumericExpression r =>
SValue r -> SValue r -> SValue r
#- Integer -> SValue SwiftCode
forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
1) SwiftCode ScopeData
scp
(MS (SwiftCode (Doc, Terminator))
setEnd, SValue SwiftCode
endVal) = String
-> SValue SwiftCode
-> Maybe Integer
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> SwiftCode ScopeData
-> (MS (SwiftCode (Doc, Terminator)), SValue SwiftCode)
forall (r :: * -> *) smt.
SharedStatement r smt =>
String
-> SValue r
-> Maybe Integer
-> Maybe (SValue r)
-> SValue r
-> SValue r
-> r ScopeData
-> (MS (r smt), SValue r)
M.makeSetterVal String
endName SValue SwiftCode
step Maybe Integer
mbStepV Maybe (SValue SwiftCode)
end (SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *) smt. List r smt => SValue r -> SValue r
listSize SValue SwiftCode
vo) (Integer -> SValue SwiftCode
forall (r :: * -> *). Literal r => Integer -> SValue r
litInt (-Integer
1)) SwiftCode ScopeData
scp
i_binder :: VSBinder SwiftCode
i_binder = String -> VS (SwiftCode TypeData) -> VSBinder SwiftCode
forall (r :: * -> *).
BinderSym r =>
String -> VS (r TypeData) -> VSBinder r
binder String
"i" VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
int
i_var :: SVariable SwiftCode
i_var = String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
"i" VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
int
setToSlice :: MS (SwiftCode (Doc, Terminator))
setToSlice = SVariable SwiftCode
vn SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
AssignStatement r smt =>
SVariable r -> SValue r -> MS (r smt)
&= SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
InternalValueExp r =>
SValue r -> SValue r -> SValue r
swiftMapFunc (SValue SwiftCode
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueExpression r) =>
SValue r -> SValue r -> SValue r -> SValue r
swiftStrideFunc SValue SwiftCode
begVal SValue SwiftCode
endVal SValue SwiftCode
step) ([VSBinder SwiftCode] -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
ValueExpression r =>
[VSBinder r] -> SValue r -> SValue r
lambda [VSBinder SwiftCode
i_binder] (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *) smt.
List r smt =>
SValue r -> SValue r -> SValue r
listAccess SValue SwiftCode
vo (SVariable SwiftCode -> SValue SwiftCode
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable SwiftCode
i_var)))
[MS (SwiftCode (Doc, Terminator))] -> MS (SwiftCode Doc)
forall (r :: * -> *) smt.
BlockSym r smt =>
[MS (r smt)] -> MS (r Doc)
block [
MS (SwiftCode (Doc, Terminator))
setBeg,
MS (SwiftCode (Doc, Terminator))
setEnd,
MS (SwiftCode (Doc, Terminator))
setToSlice
]
swiftPrint :: Bool -> Maybe (SValue SwiftCode) -> SValue SwiftCode ->
SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
swiftPrint :: Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
swiftPrint Bool
newLn Maybe (SValue SwiftCode)
Nothing SValue SwiftCode
_ SValue SwiftCode
v = do
let s :: SValue SwiftCode
s = String -> SValue SwiftCode
forall (r :: * -> *). Literal r => String -> SValue r
litString String
"" :: SValue SwiftCode
nl :: NamedArgs SwiftCode
nl = [(String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
swiftTerm VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string, SValue SwiftCode
s) | Bool -> Bool
not Bool
newLn]
SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
StatementSym r smt =>
SValue r -> MS (r smt)
valStmt (SValue SwiftCode -> MS (SwiftCode (Doc, Terminator)))
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall a b. (a -> b) -> a -> b
$ MixedCall SwiftCode
forall (r :: * -> *). ValueExpression r => MixedCall r
funcAppMixedArgs String
printLabel VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void [SValue SwiftCode
v] NamedArgs SwiftCode
nl
swiftPrint Bool
newLn (Just SValue SwiftCode
f) SValue SwiftCode
_ SValue SwiftCode
v' = do
SwiftCode Value
v <- LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode Value))
MethodState
ValueState
-> SValue SwiftCode
-> StateT MethodState Identity (SwiftCode 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) (SwiftCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode Value) ValueState)
-> MethodState -> Focusing Identity (SwiftCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue SwiftCode
v'
let valToPrint :: CodeType -> SValue SwiftCode
valToPrint (List CodeType
_) = SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v SValue SwiftCode -> VS (SwiftCode FuncData) -> SValue SwiftCode
forall (r :: * -> *).
OOFunctionSym r =>
SValue r -> VS (r FuncData) -> SValue r
$. Doc -> VS (SwiftCode TypeData) -> VS (SwiftCode FuncData)
forall (r :: * -> *).
RenderFunction r =>
Doc -> VS (r TypeData) -> VS (r FuncData)
funcFromData (Doc -> Doc
R.func Doc
swiftDesc) VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string
valToPrint CodeType
String = SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v
valToPrint CodeType
_ = VS (SwiftCode TypeData) -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> SValue r -> SValue r
cast VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string (SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
v)
prNewLn :: MS (SwiftCode (Doc, Terminator))
prNewLn = if Bool
newLn then SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
StatementSym r smt =>
SValue r -> MS (r smt)
valStmt (SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftWriteFunc (String -> SValue SwiftCode
forall (r :: * -> *). Literal r => String -> SValue r
litString String
"\\n") SValue SwiftCode
f)
else MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt. StatementSym r smt => MS (r smt)
emptyStmt
MS (SwiftCode Doc)
-> MS (SwiftCode Doc) -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
ControlStatement r smt =>
MS (r Doc) -> MS (r Doc) -> MS (r smt)
tryCatch ([MS (SwiftCode (Doc, Terminator))] -> MS (SwiftCode Doc)
forall (r :: * -> *) smt.
BodySym r smt =>
[MS (r smt)] -> MS (r Doc)
bodyStatements
[SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
StatementSym r smt =>
SValue r -> MS (r smt)
valStmt (SValue SwiftCode -> MS (SwiftCode (Doc, Terminator)))
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall a b. (a -> b) -> a -> b
$ SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftWriteFunc (CodeType -> SValue SwiftCode
valToPrint (CodeType -> SValue SwiftCode) -> CodeType -> SValue SwiftCode
forall a b. (a -> b) -> a -> b
$ SwiftCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (SwiftCode TypeData -> CodeType) -> SwiftCode TypeData -> CodeType
forall a b. (a -> b) -> a -> b
$ SwiftCode Value -> SwiftCode TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType SwiftCode Value
v) SValue SwiftCode
f, MS (SwiftCode (Doc, Terminator))
prNewLn])
(MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc)
forall (r :: * -> *) smt. BodySym r smt => MS (r smt) -> MS (r Doc)
oneLiner (MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc))
-> MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc)
forall a b. (a -> b) -> a -> b
$ String -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
ControlStatement r smt =>
String -> MS (r smt)
throw String
"Error printing to file.")
swiftOut :: Bool -> Maybe (SValue SwiftCode) -> SValue SwiftCode ->
SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
swiftOut :: Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
swiftOut Bool
newLn Maybe (SValue SwiftCode)
f SValue SwiftCode
printFn SValue SwiftCode
v = LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode Value))
MethodState
ValueState
-> SValue SwiftCode
-> StateT MethodState Identity (SwiftCode 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) (SwiftCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode Value) ValueState)
-> MethodState -> Focusing Identity (SwiftCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue SwiftCode
v StateT MethodState Identity (SwiftCode Value)
-> (SwiftCode Value -> MS (SwiftCode (Doc, Terminator)))
-> MS (SwiftCode (Doc, Terminator))
forall a b.
StateT MethodState Identity a
-> (a -> StateT MethodState Identity b)
-> StateT MethodState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CodeType -> MS (SwiftCode (Doc, Terminator))
swOut (CodeType -> MS (SwiftCode (Doc, Terminator)))
-> (SwiftCode Value -> CodeType)
-> SwiftCode Value
-> MS (SwiftCode (Doc, Terminator))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (SwiftCode TypeData -> CodeType)
-> (SwiftCode Value -> SwiftCode TypeData)
-> SwiftCode Value
-> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode Value -> SwiftCode TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType
where swOut :: CodeType -> MS (SwiftCode (Doc, Terminator))
swOut (List CodeType
_) = Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
InternalIOStmt r smt =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r smt)
printSt Bool
newLn Maybe (SValue SwiftCode)
f SValue SwiftCode
printFn SValue SwiftCode
v
swOut CodeType
_ = Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(InternalIOStmt r smt, SharedStatement r smt, TypeElim r) =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r smt)
G.print Bool
newLn Maybe (SValue SwiftCode)
f SValue SwiftCode
printFn SValue SwiftCode
v
swiftInput :: SVariable SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftInput :: SVariable SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftInput SVariable SwiftCode
vr SValue SwiftCode
vl = do
SwiftCode Variable
vr' <- SVariable SwiftCode
vr
let swiftInput' :: CodeType -> SValue SwiftCode
swiftInput' CodeType
String = SValue SwiftCode
vl
swiftInput' CodeType
ct
| CodeType
ct CodeType -> [CodeType] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [CodeType]
swiftReadableTypes = VS (SwiftCode TypeData) -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> SValue r -> SValue r
cast (SwiftCode TypeData -> VS (SwiftCode TypeData)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SwiftCode TypeData -> VS (SwiftCode TypeData))
-> SwiftCode TypeData -> VS (SwiftCode TypeData)
forall a b. (a -> b) -> a -> b
$ SwiftCode Variable -> SwiftCode TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType SwiftCode Variable
vr') SValue SwiftCode
vl
| Bool
otherwise = String -> SValue SwiftCode
forall a. HasCallStack => String -> a
error String
"Attempt to read value of unreadable type"
CodeType -> SValue SwiftCode
swiftInput' (SwiftCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (SwiftCode TypeData -> CodeType) -> SwiftCode TypeData -> CodeType
forall a b. (a -> b) -> a -> b
$ SwiftCode Variable -> SwiftCode TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType SwiftCode Variable
vr')
swiftOpenFile :: SValue SwiftCode -> VS (SwiftCode TypeData) -> SValue SwiftCode
swiftOpenFile :: SValue SwiftCode -> VS (SwiftCode TypeData) -> SValue SwiftCode
swiftOpenFile SValue SwiftCode
n VS (SwiftCode TypeData)
t = let forArg :: SVariable SwiftCode
forArg = String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
swiftFor (String -> VS (SwiftCode TypeData)
forall (r :: * -> *). OOTypeSym r => String -> VS (r TypeData)
obj String
swiftSearchDir)
dirVal :: SValue SwiftCode
dirVal = VS (SwiftCode TypeData) -> Doc -> SValue SwiftCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal (String -> VS (SwiftCode TypeData)
forall (r :: * -> *). OOTypeSym r => String -> VS (r TypeData)
obj String
swiftSearchDir) Doc
swiftDocDir
inArg :: SVariable SwiftCode
inArg = String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
swiftIn (String -> VS (SwiftCode TypeData)
forall (r :: * -> *). OOTypeSym r => String -> VS (r TypeData)
obj String
swiftPathMask)
maskVal :: SValue SwiftCode
maskVal = VS (SwiftCode TypeData) -> Doc -> SValue SwiftCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal (String -> VS (SwiftCode TypeData)
forall (r :: * -> *). OOTypeSym r => String -> VS (r TypeData)
obj String
swiftPathMask) Doc
swiftUserMask
in VS (SwiftCode TypeData)
-> SValue SwiftCode
-> String
-> [SValue SwiftCode]
-> SValue SwiftCode
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
objMethodCall VS (SwiftCode TypeData)
t (SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r
swiftUnwrapVal (SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode
forall a b. (a -> b) -> a -> b
$
String
-> VS (SwiftCode TypeData)
-> NamedArgs SwiftCode
-> SValue SwiftCode
forall (r :: * -> *).
ValueExpression r =>
String -> VS (r TypeData) -> NamedArgs r -> SValue r
funcAppNamedArgs String
swiftUrls (VS (SwiftCode TypeData) -> VS (SwiftCode TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType VS (SwiftCode TypeData)
t) [(SVariable SwiftCode
forArg, SValue SwiftCode
dirVal), (SVariable SwiftCode
inArg, SValue SwiftCode
maskVal)]
SValue SwiftCode -> VS (SwiftCode FuncData) -> SValue SwiftCode
forall (r :: * -> *).
OOFunctionSym r =>
SValue r -> VS (r FuncData) -> SValue r
$. Doc -> VS (SwiftCode TypeData) -> VS (SwiftCode FuncData)
forall (r :: * -> *).
RenderFunction r =>
Doc -> VS (r TypeData) -> VS (r FuncData)
funcFromData (Doc -> Doc
R.func Doc
swiftFirst) VS (SwiftCode TypeData)
t) String
swiftAppendPath [SValue SwiftCode
n]
swiftOpenFileHdl :: SValue SwiftCode -> VS (SwiftCode TypeData) -> SValue SwiftCode
swiftOpenFileHdl :: SValue SwiftCode -> VS (SwiftCode TypeData) -> SValue SwiftCode
swiftOpenFileHdl SValue SwiftCode
n VS (SwiftCode TypeData)
t = let forWritingArg :: SVariable SwiftCode
forWritingArg = String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
swiftWriteTo VS (SwiftCode TypeData)
forall (r :: * -> *). Monad r => VS (r TypeData)
swiftFileType
in SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r
swiftTryVal (SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode
forall a b. (a -> b) -> a -> b
$ String
-> VS (SwiftCode TypeData)
-> NamedArgs SwiftCode
-> SValue SwiftCode
forall (r :: * -> *).
ValueExpression r =>
String -> VS (r TypeData) -> NamedArgs r -> SValue r
funcAppNamedArgs String
swiftFileHdl VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
outfile
[(SVariable SwiftCode
forWritingArg, SValue SwiftCode -> VS (SwiftCode TypeData) -> SValue SwiftCode
swiftOpenFile SValue SwiftCode
n VS (SwiftCode TypeData)
t)]
swiftOpenFileWA
:: Bool -> SVariable SwiftCode -> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
swiftOpenFileWA :: Bool
-> SVariable SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
swiftOpenFileWA Bool
app SVariable SwiftCode
f' SValue SwiftCode
n' = MS (SwiftCode Doc)
-> MS (SwiftCode Doc) -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
ControlStatement r smt =>
MS (r Doc) -> MS (r Doc) -> MS (r smt)
tryCatch
([MS (SwiftCode (Doc, Terminator))] -> MS (SwiftCode Doc)
forall (r :: * -> *) smt.
BodySym r smt =>
[MS (r smt)] -> MS (r Doc)
bodyStatements [(SValue SwiftCode
-> VS (SwiftCode TypeData) -> SValue SwiftCode -> SValue SwiftCode)
-> SVariable SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
(AssignStatement r smt, Literal r) =>
(SValue r -> VS (r TypeData) -> SValue r -> SValue r)
-> SVariable r -> SValue r -> MS (r smt)
CP.openFileW (\SValue SwiftCode
f VS (SwiftCode TypeData)
n SValue SwiftCode
_ -> SValue SwiftCode -> VS (SwiftCode TypeData) -> SValue SwiftCode
swiftOpenFileHdl SValue SwiftCode
f VS (SwiftCode TypeData)
n) SVariable SwiftCode
f' SValue SwiftCode
n',
if Bool
app
then SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
StatementSym r smt =>
SValue r -> MS (r smt)
valStmt (SValue SwiftCode -> MS (SwiftCode (Doc, Terminator)))
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall a b. (a -> b) -> a -> b
$ SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r
swiftTryVal (SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode
forall a b. (a -> b) -> a -> b
$ VS (SwiftCode TypeData)
-> SValue SwiftCode -> String -> SValue SwiftCode
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData) -> SValue r -> String -> SValue r
objMethodCallNoParams VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void (SVariable SwiftCode -> SValue SwiftCode
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable SwiftCode
f')
String
swiftSeekEnd
else MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt. StatementSym r smt => MS (r smt)
emptyStmt])
(MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc)
forall (r :: * -> *) smt. BodySym r smt => MS (r smt) -> MS (r Doc)
oneLiner (MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc))
-> MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc)
forall a b. (a -> b) -> a -> b
$ String -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
ControlStatement r smt =>
String -> MS (r smt)
throw String
"Error opening file.")
swiftCloseFile :: SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
swiftCloseFile :: SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
swiftCloseFile SValue SwiftCode
f' = do
SwiftCode Value
f <- LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode Value))
MethodState
ValueState
-> SValue SwiftCode
-> StateT MethodState Identity (SwiftCode 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) (SwiftCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode Value) ValueState)
-> MethodState -> Focusing Identity (SwiftCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue SwiftCode
f'
let swClose :: CodeType -> MS (SwiftCode (Doc, Terminator))
swClose CodeType
InFile = (MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
resetIndices StateT MethodState Identity ()
-> MS (SwiftCode (Doc, Terminator))
-> MS (SwiftCode (Doc, Terminator))
forall a b.
StateT MethodState Identity a
-> StateT MethodState Identity b -> StateT MethodState Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt. StatementSym r smt => MS (r smt)
emptyStmt
swClose CodeType
OutFile = MS (SwiftCode Doc)
-> MS (SwiftCode Doc) -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
ControlStatement r smt =>
MS (r Doc) -> MS (r Doc) -> MS (r smt)
tryCatch (MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc)
forall (r :: * -> *) smt. BodySym r smt => MS (r smt) -> MS (r Doc)
oneLiner (MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc))
-> MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc)
forall a b. (a -> b) -> a -> b
$ SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
StatementSym r smt =>
SValue r -> MS (r smt)
valStmt (SValue SwiftCode -> MS (SwiftCode (Doc, Terminator)))
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall a b. (a -> b) -> a -> b
$ SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r
swiftTryVal (SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode
forall a b. (a -> b) -> a -> b
$
VS (SwiftCode TypeData)
-> SValue SwiftCode -> String -> SValue SwiftCode
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData) -> SValue r -> String -> SValue r
objMethodCallNoParams VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void (SwiftCode Value -> SValue SwiftCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode Value
f) String
swiftClose)
(MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc)
forall (r :: * -> *) smt. BodySym r smt => MS (r smt) -> MS (r Doc)
oneLiner (MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc))
-> MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc)
forall a b. (a -> b) -> a -> b
$ String -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
ControlStatement r smt =>
String -> MS (r smt)
throw String
"Error closing file.")
swClose CodeType
_ = String -> MS (SwiftCode (Doc, Terminator))
forall a. HasCallStack => String -> a
error String
"closeFile called on non-file-typed value"
CodeType -> MS (SwiftCode (Doc, Terminator))
swClose (SwiftCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (SwiftCode TypeData -> CodeType) -> SwiftCode TypeData -> CodeType
forall a b. (a -> b) -> a -> b
$ SwiftCode Value -> SwiftCode TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType SwiftCode Value
f)
swiftReadFile
:: SVariable SwiftCode -> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
swiftReadFile :: SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
swiftReadFile SVariable SwiftCode
v SValue SwiftCode
f =
let l_binder :: VSBinder SwiftCode
l_binder = String -> VS (SwiftCode TypeData) -> VSBinder SwiftCode
forall (r :: * -> *).
BinderSym r =>
String -> VS (r TypeData) -> VSBinder r
binder String
"l" VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string
l_var :: SVariable SwiftCode
l_var = String -> VS (SwiftCode TypeData) -> SVariable SwiftCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var String
"l" VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string
in MS (SwiftCode Doc)
-> MS (SwiftCode Doc) -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
ControlStatement r smt =>
MS (r Doc) -> MS (r Doc) -> MS (r smt)
tryCatch
(MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc)
forall (r :: * -> *) smt. BodySym r smt => MS (r smt) -> MS (r Doc)
oneLiner (MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc))
-> MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc)
forall a b. (a -> b) -> a -> b
$ SVariable SwiftCode
v SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
AssignStatement r smt =>
SVariable r -> SValue r -> MS (r smt)
&= SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
InternalValueExp r =>
SValue r -> SValue r -> SValue r
swiftMapFunc (Char -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(InternalValueExp r, Literal r, VariableSym r) =>
Char -> SValue r -> SValue r
swiftSplitFunc Char
'\n' (SValue SwiftCode -> SValue SwiftCode)
-> SValue SwiftCode -> SValue SwiftCode
forall a b. (a -> b) -> a -> b
$ SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueExpression r) =>
SValue r -> SValue r
swiftReadFileFunc SValue SwiftCode
f)
([VSBinder SwiftCode] -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
ValueExpression r =>
[VSBinder r] -> SValue r -> SValue r
lambda [VSBinder SwiftCode
l_binder] (Char -> SValue SwiftCode -> SValue SwiftCode
forall (r :: * -> *).
(InternalValueExp r, Literal r, VariableSym r) =>
Char -> SValue r -> SValue r
swiftSplitFunc Char
' ' (SVariable SwiftCode -> SValue SwiftCode
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable SwiftCode
l_var))))
(MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc)
forall (r :: * -> *) smt. BodySym r smt => MS (r smt) -> MS (r Doc)
oneLiner (MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc))
-> MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc)
forall a b. (a -> b) -> a -> b
$ String -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
ControlStatement r smt =>
String -> MS (r smt)
throw String
"Error reading from file.")
swiftVarDec :: Doc -> SVariable SwiftCode -> SwiftCode ScopeData
-> MS (SwiftCode (Doc, Terminator))
swiftVarDec :: Doc
-> SVariable SwiftCode
-> SwiftCode ScopeData
-> MS (SwiftCode (Doc, Terminator))
swiftVarDec Doc
dec SVariable SwiftCode
v' SwiftCode ScopeData
scp = do
SwiftCode Variable
v <- LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode Variable))
MethodState
ValueState
-> SVariable SwiftCode
-> StateT MethodState Identity (SwiftCode 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) (SwiftCode Variable))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode Variable) ValueState)
-> MethodState
-> Focusing Identity (SwiftCode Variable) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable SwiftCode
v'
(MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((MethodState -> MethodState) -> StateT MethodState Identity ())
-> (MethodState -> MethodState) -> StateT MethodState Identity ()
forall a b. (a -> b) -> a -> b
$ String -> MethodState -> MethodState
useVarName (SwiftCode Variable -> String
forall (r :: * -> *). VariableElim r => r Variable -> String
variableName SwiftCode Variable
v)
(MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((MethodState -> MethodState) -> StateT MethodState Identity ())
-> (MethodState -> MethodState) -> StateT MethodState Identity ()
forall a b. (a -> b) -> a -> b
$ String -> ScopeData -> MethodState -> MethodState
setVarScope (SwiftCode Variable -> String
forall (r :: * -> *). VariableElim r => r Variable -> String
variableName SwiftCode Variable
v) (SwiftCode ScopeData -> ScopeData
forall (r :: * -> *). ScopeElim r => r ScopeData -> ScopeData
scopeData SwiftCode ScopeData
scp)
let bind :: AttachmentTag -> SwiftCode Doc
bind AttachmentTag
ClassLevel = SwiftCode Doc
forall (r :: * -> *) att. AttachmentSym r att => r att
classLevel :: SwiftCode Doc
bind AttachmentTag
InstanceLevel = SwiftCode Doc
forall (r :: * -> *) att. AttachmentSym r att => r att
instanceLevel :: SwiftCode Doc
p :: SwiftCode Doc
p = AttachmentTag -> SwiftCode Doc
bind (AttachmentTag -> SwiftCode Doc) -> AttachmentTag -> SwiftCode Doc
forall a b. (a -> b) -> a -> b
$ SwiftCode Variable -> AttachmentTag
forall (r :: * -> *).
InternalVarElim r =>
r Variable -> AttachmentTag
variableBind SwiftCode Variable
v
Doc -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> MS (r smt)
mkStmtNoEnd (SwiftCode Doc -> Doc
forall (r :: * -> *) att. PermElim r att => r att -> Doc
RC.perm SwiftCode Doc
p Doc -> Doc -> Doc
<+> Doc
dec Doc -> Doc -> Doc
<+> SwiftCode Variable -> Doc
forall (r :: * -> *). InternalVarElim r => r Variable -> Doc
RC.variable SwiftCode Variable
v Doc -> Doc -> Doc
<> Doc
swiftTypeSpec
Doc -> Doc -> Doc
<+> SwiftCode TypeData -> Doc
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> Doc
renderType (SwiftCode Variable -> SwiftCode TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType SwiftCode Variable
v))
swiftSetDec :: Doc -> SVariable SwiftCode -> SwiftCode ScopeData ->
MS (SwiftCode (Doc, Terminator))
swiftSetDec :: Doc
-> SVariable SwiftCode
-> SwiftCode ScopeData
-> MS (SwiftCode (Doc, Terminator))
swiftSetDec Doc
dec SVariable SwiftCode
v' SwiftCode ScopeData
scp = do
SwiftCode Variable
v <- LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode Variable))
MethodState
ValueState
-> SVariable SwiftCode
-> StateT MethodState Identity (SwiftCode 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) (SwiftCode Variable))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode Variable) ValueState)
-> MethodState
-> Focusing Identity (SwiftCode Variable) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable SwiftCode
v'
(MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((MethodState -> MethodState) -> StateT MethodState Identity ())
-> (MethodState -> MethodState) -> StateT MethodState Identity ()
forall a b. (a -> b) -> a -> b
$ String -> MethodState -> MethodState
useVarName (SwiftCode Variable -> String
forall (r :: * -> *). VariableElim r => r Variable -> String
variableName SwiftCode Variable
v)
(MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((MethodState -> MethodState) -> StateT MethodState Identity ())
-> (MethodState -> MethodState) -> StateT MethodState Identity ()
forall a b. (a -> b) -> a -> b
$ String -> ScopeData -> MethodState -> MethodState
setVarScope (SwiftCode Variable -> String
forall (r :: * -> *). VariableElim r => r Variable -> String
variableName SwiftCode Variable
v) (SwiftCode ScopeData -> ScopeData
forall (r :: * -> *). ScopeElim r => r ScopeData -> ScopeData
scopeData SwiftCode ScopeData
scp)
let bind :: AttachmentTag -> SwiftCode Doc
bind AttachmentTag
ClassLevel = SwiftCode Doc
forall (r :: * -> *) att. AttachmentSym r att => r att
classLevel :: SwiftCode Doc
bind AttachmentTag
InstanceLevel = SwiftCode Doc
forall (r :: * -> *) att. AttachmentSym r att => r att
instanceLevel :: SwiftCode Doc
p :: SwiftCode Doc
p = AttachmentTag -> SwiftCode Doc
bind (AttachmentTag -> SwiftCode Doc) -> AttachmentTag -> SwiftCode Doc
forall a b. (a -> b) -> a -> b
$ SwiftCode Variable -> AttachmentTag
forall (r :: * -> *).
InternalVarElim r =>
r Variable -> AttachmentTag
variableBind SwiftCode Variable
v
Doc -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> MS (r smt)
mkStmtNoEnd (SwiftCode Doc -> Doc
forall (r :: * -> *) att. PermElim r att => r att -> Doc
RC.perm SwiftCode Doc
p Doc -> Doc -> Doc
<+> Doc
dec Doc -> Doc -> Doc
<+> SwiftCode Variable -> Doc
forall (r :: * -> *). InternalVarElim r => r Variable -> Doc
RC.variable SwiftCode Variable
v Doc -> Doc -> Doc
<> Doc
swiftTypeSpec
Doc -> Doc -> Doc
<+> String -> Doc
text (String
swiftSet String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
replaceBrackets (SwiftCode TypeData -> String
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> String
getTypeString (SwiftCode Variable -> SwiftCode TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType SwiftCode Variable
v))))
replaceBrackets :: String -> String
replaceBrackets :: String -> String
replaceBrackets String
str = String
"<" String -> String -> String
forall a. [a] -> [a] -> [a]
++ (String -> String
forall a. HasCallStack => [a] -> [a]
init (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
forall a. HasCallStack => [a] -> [a]
tail) String
str String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
">"
swiftThrowDoc :: (ValueElim r) => r Value -> Doc
swiftThrowDoc :: forall (r :: * -> *). ValueElim r => r Value -> Doc
swiftThrowDoc r Value
errMsg = Doc
throwLabel Doc -> Doc -> Doc
<+> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
errMsg
swiftForEach
:: (BodyElim r, InternalVarElim r, ValueElim r)
=> r Variable -> r Value -> r Body -> Doc
swiftForEach :: forall (r :: * -> *).
(BodyElim r, InternalVarElim r, ValueElim r) =>
r Variable -> r Value -> r Doc -> Doc
swiftForEach r Variable
i r Value
lstVar r Doc
b = [Doc] -> Doc
vcat [
Doc
forLabel Doc -> Doc -> Doc
<+> r Variable -> Doc
forall (r :: * -> *). InternalVarElim r => r Variable -> Doc
RC.variable r Variable
i Doc -> Doc -> Doc
<+> Doc
inLabel Doc -> Doc -> Doc
<+> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
lstVar Doc -> Doc -> Doc
<+> Doc
bodyStart,
Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ r Doc -> Doc
forall (r :: * -> *). BodyElim r => r Doc -> Doc
RC.body r Doc
b,
Doc
bodyEnd]
swiftTryCatch :: (BodyElim r) => r Body -> r Body -> Doc
swiftTryCatch :: forall (r :: * -> *). BodyElim r => r Doc -> r Doc -> Doc
swiftTryCatch r Doc
tb r Doc
cb = [Doc] -> Doc
vcat [
Doc
swiftDo Doc -> Doc -> Doc
<+> Doc
lbrace,
Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ r Doc -> Doc
forall (r :: * -> *). BodyElim r => r Doc -> Doc
RC.body r Doc
tb,
Doc
rbrace Doc -> Doc -> Doc
<+> Doc
catchLabel Doc -> Doc -> Doc
<+> Doc
lbrace,
Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ r Doc -> Doc
forall (r :: * -> *). BodyElim r => r Doc -> Doc
RC.body r Doc
cb,
Doc
rbrace]
swiftAssert :: (ValueElim r) => r Value -> r Value -> Doc
swiftAssert :: forall (r :: * -> *). ValueElim r => r Value -> r Value -> Doc
swiftAssert r Value
condition r Value
errorMessage = [Doc] -> Doc
vcat [
String -> Doc
text String
"assert(" Doc -> Doc -> Doc
<+> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
condition Doc -> Doc -> Doc
<+> String -> Doc
text String
"," Doc -> Doc -> Doc
<+> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
errorMessage Doc -> Doc -> Doc
<> String -> Doc
text String
")"
]
swiftParam :: Doc -> SwiftCode Variable -> Doc
swiftParam :: Doc -> SwiftCode Variable -> Doc
swiftParam Doc
io SwiftCode Variable
v = Doc
swiftNoLabel Doc -> Doc -> Doc
<+> SwiftCode Variable -> Doc
forall (r :: * -> *). InternalVarElim r => r Variable -> Doc
RC.variable SwiftCode Variable
v Doc -> Doc -> Doc
<> Doc
swiftTypeSpec Doc -> Doc -> Doc
<+> Doc
io
Doc -> Doc -> Doc
<+> SwiftCode TypeData -> Doc
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> Doc
renderType (SwiftCode Variable -> SwiftCode TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType SwiftCode Variable
v)
swiftMethod :: Label -> SwiftCode Doc ->
SwiftCode Doc -> MSMthdType SwiftCode ->
[MS (SwiftCode ParamData)] -> MS (SwiftCode Body) -> MS (SwiftCode MethodData)
swiftMethod :: String
-> SwiftCode Doc
-> SwiftCode Doc
-> MSMthdType SwiftCode
-> [MS (SwiftCode ParamData)]
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
swiftMethod String
n SwiftCode Doc
s SwiftCode Doc
p MSMthdType SwiftCode
t [MS (SwiftCode ParamData)]
ps MS (SwiftCode Doc)
b = do
SwiftCode TypeData
tp <- MSMthdType SwiftCode
t
[SwiftCode ParamData]
pms <- [MS (SwiftCode ParamData)]
-> StateT MethodState Identity [SwiftCode 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 (SwiftCode ParamData)]
ps
SwiftCode Doc
bod <- MS (SwiftCode Doc)
b
Map QualifiedName [ExceptionType]
mem <- LensLike'
(Zoomed
(StateT ValueState Identity) (Map QualifiedName [ExceptionType]))
MethodState
ValueState
-> VS (Map QualifiedName [ExceptionType])
-> StateT MethodState Identity (Map QualifiedName [ExceptionType])
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) (Map QualifiedName [ExceptionType]))
MethodState
ValueState
(ValueState
-> Focusing
Identity (Map QualifiedName [ExceptionType]) ValueState)
-> MethodState
-> Focusing
Identity (Map QualifiedName [ExceptionType]) MethodState
Lens' MethodState ValueState
lensMStoVS VS (Map QualifiedName [ExceptionType])
getMethodExcMap
String
mn <- LensLike'
(Zoomed (StateT FileState Identity) String) MethodState FileState
-> StateT FileState Identity String -> MS String
forall c.
LensLike'
(Zoomed (StateT FileState Identity) c) MethodState FileState
-> StateT FileState 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 FileState Identity) String) MethodState FileState
(FileState -> Focusing Identity String FileState)
-> MethodState -> Focusing Identity String MethodState
Lens' MethodState FileState
lensMStoFS StateT FileState Identity String
getModuleName
let excs :: [ExceptionType]
excs = [ExceptionType]
-> QualifiedName
-> Map QualifiedName [ExceptionType]
-> [ExceptionType]
forall k a. Ord k => a -> k -> Map k a -> a
findWithDefault [] (String -> String -> QualifiedName
qualName String
mn String
n) Map QualifiedName [ExceptionType]
mem
VisibilityTag -> Doc -> MS (SwiftCode MethodData)
forall (r :: * -> *) md.
RenderMethod r md =>
VisibilityTag -> Doc -> MS (r md)
mthdFromData VisibilityTag
Pub ([Doc] -> Doc
vcat [
SwiftCode Doc -> Doc
forall (r :: * -> *) vis. VisibilityElim r vis => r vis -> Doc
RC.visibility SwiftCode Doc
s Doc -> Doc -> Doc
<+> SwiftCode Doc -> Doc
forall (r :: * -> *) att. PermElim r att => r att -> Doc
RC.perm SwiftCode Doc
p Doc -> Doc -> Doc
<+> Doc
swiftFunc Doc -> Doc -> Doc
<+> String -> Doc
text String
n Doc -> Doc -> Doc
<>
Doc -> Doc
parens ([SwiftCode ParamData] -> Doc
forall (r :: * -> *). ParamElim r => [r ParamData] -> Doc
parameterList [SwiftCode ParamData]
pms) Doc -> Doc -> Doc
<+> [ExceptionType] -> Doc -> Doc
forall a. [a] -> Doc -> Doc
emptyIfNull [ExceptionType]
excs Doc
throwsLabel Doc -> Doc -> Doc
<+>
Doc
swiftRetType' Doc -> Doc -> Doc
<+> SwiftCode TypeData -> Doc
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> Doc
renderType SwiftCode TypeData
tp Doc -> Doc -> Doc
<+> Doc
bodyStart,
Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ SwiftCode Doc -> Doc
forall (r :: * -> *). BodyElim r => r Doc -> Doc
RC.body SwiftCode Doc
bod,
Doc
bodyEnd])
swiftConstructor
:: [MS (SwiftCode ParamData)]
-> Initializers SwiftCode
-> MS (SwiftCode Body)
-> MS (SwiftCode MethodData)
swiftConstructor :: [MS (SwiftCode ParamData)]
-> NamedArgs SwiftCode
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
swiftConstructor [MS (SwiftCode ParamData)]
ps NamedArgs SwiftCode
is MS (SwiftCode Doc)
b = do
[SwiftCode ParamData]
pms <- [MS (SwiftCode ParamData)]
-> StateT MethodState Identity [SwiftCode 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 (SwiftCode ParamData)]
ps
SwiftCode Doc
bod <- [MS (SwiftCode Doc)] -> MS (SwiftCode Doc)
forall (r :: * -> *). RenderBody r => [MS (r Doc)] -> MS (r Doc)
multiBody [NamedArgs SwiftCode -> MS (SwiftCode Doc)
forall (r :: * -> *) smt.
OOStatement r smt =>
Initializers r -> MS (r Doc)
G.initStmts NamedArgs SwiftCode
is, MS (SwiftCode Doc)
b]
Map QualifiedName [ExceptionType]
mem <- LensLike'
(Zoomed
(StateT ValueState Identity) (Map QualifiedName [ExceptionType]))
MethodState
ValueState
-> VS (Map QualifiedName [ExceptionType])
-> StateT MethodState Identity (Map QualifiedName [ExceptionType])
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) (Map QualifiedName [ExceptionType]))
MethodState
ValueState
(ValueState
-> Focusing
Identity (Map QualifiedName [ExceptionType]) ValueState)
-> MethodState
-> Focusing
Identity (Map QualifiedName [ExceptionType]) MethodState
Lens' MethodState ValueState
lensMStoVS VS (Map QualifiedName [ExceptionType])
getMethodExcMap
String
mn <- LensLike'
(Zoomed (StateT FileState Identity) String) MethodState FileState
-> StateT FileState Identity String -> MS String
forall c.
LensLike'
(Zoomed (StateT FileState Identity) c) MethodState FileState
-> StateT FileState 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 FileState Identity) String) MethodState FileState
(FileState -> Focusing Identity String FileState)
-> MethodState -> Focusing Identity String MethodState
Lens' MethodState FileState
lensMStoFS StateT FileState Identity String
getModuleName
String
cn <- MS String
getClassName
let excs :: [ExceptionType]
excs = [ExceptionType]
-> QualifiedName
-> Map QualifiedName [ExceptionType]
-> [ExceptionType]
forall k a. Ord k => a -> k -> Map k a -> a
findWithDefault [] (String -> String -> QualifiedName
qualName String
mn String
cn) Map QualifiedName [ExceptionType]
mem
VisibilityTag -> Doc -> MS (SwiftCode MethodData)
forall (r :: * -> *) md.
RenderMethod r md =>
VisibilityTag -> Doc -> MS (r md)
mthdFromData VisibilityTag
Pub ([Doc] -> Doc
vcat [
Doc
swiftCtorName Doc -> Doc -> Doc
<> Doc -> Doc
parens ([SwiftCode ParamData] -> Doc
forall (r :: * -> *). ParamElim r => [r ParamData] -> Doc
parameterList [SwiftCode ParamData]
pms) Doc -> Doc -> Doc
<+>
[ExceptionType] -> Doc -> Doc
forall a. [a] -> Doc -> Doc
emptyIfNull [ExceptionType]
excs Doc
throwsLabel Doc -> Doc -> Doc
<+> Doc
bodyStart,
Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ SwiftCode Doc -> Doc
forall (r :: * -> *). BodyElim r => r Doc -> Doc
RC.body SwiftCode Doc
bod,
Doc
bodyEnd])
swiftStringError :: MS Doc
swiftStringError :: StateT MethodState Identity Doc
swiftStringError = do
Bool
tu <- MS Bool
getThrowUsed
Bool
errdef <- MS Bool
getErrorDefined
SwiftCode TypeData
str <- LensLike'
(Zoomed (StateT ValueState Identity) (SwiftCode TypeData))
MethodState
ValueState
-> VS (SwiftCode TypeData) -> MSMthdType SwiftCode
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) (SwiftCode TypeData))
MethodState
ValueState
(ValueState -> Focusing Identity (SwiftCode TypeData) ValueState)
-> MethodState
-> Focusing Identity (SwiftCode TypeData) MethodState
Lens' MethodState ValueState
lensMStoVS (VS (SwiftCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string :: VS (SwiftCode TypeData))
if Bool
tu Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
errdef then do
(MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
setErrorDefined
Doc -> StateT MethodState Identity Doc
forall a. a -> StateT MethodState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Doc
swiftExtension Doc -> Doc -> Doc
<+> SwiftCode TypeData -> Doc
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> Doc
renderType SwiftCode TypeData
str Doc -> Doc -> Doc
<> Doc
swiftConforms Doc -> Doc -> Doc
<+> Doc
swiftRetroactive
Doc -> Doc -> Doc
<+> Doc
swiftError Doc -> Doc -> Doc
<+> Doc
bodyStart Doc -> Doc -> Doc
<> Doc
bodyEnd)
else Doc -> StateT MethodState Identity Doc
forall a. a -> StateT MethodState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Doc
empty
swiftClassDoc :: ClassDocRenderer
swiftClassDoc :: ClassDocRenderer
swiftClassDoc String
desc = [String
desc | Bool -> Bool
not (String -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
desc)]
typeDfltVal :: (Literal r, OOTypeSym r) => CodeType -> SValue r
typeDfltVal :: forall (r :: * -> *).
(Literal r, OOTypeSym r) =>
CodeType -> SValue r
typeDfltVal CodeType
Boolean = SValue r
forall (r :: * -> *). Literal r => SValue r
litFalse
typeDfltVal CodeType
Integer = Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
0
typeDfltVal CodeType
Float = Float -> SValue r
forall (r :: * -> *). Literal r => Float -> SValue r
litFloat Float
0.0
typeDfltVal CodeType
Double = Double -> SValue r
forall (r :: * -> *). Literal r => Double -> SValue r
litDouble Double
0.0
typeDfltVal CodeType
Char = Char -> SValue r
forall (r :: * -> *). Literal r => Char -> SValue r
litChar Char
' '
typeDfltVal CodeType
String = String -> SValue r
forall (r :: * -> *). Literal r => String -> SValue r
litString String
""
typeDfltVal (List CodeType
t) = VS (r TypeData) -> [SValue r] -> SValue r
forall (r :: * -> *).
Literal r =>
VS (r TypeData) -> [SValue r] -> SValue r
litList (CodeType -> VS (r TypeData)
forall (r :: * -> *). OOTypeSym r => CodeType -> VS (r TypeData)
convTypeOO CodeType
t) []
typeDfltVal (Array CodeType
t) = VS (r TypeData) -> [SValue r] -> SValue r
forall (r :: * -> *).
Literal r =>
VS (r TypeData) -> [SValue r] -> SValue r
litArray (CodeType -> VS (r TypeData)
forall (r :: * -> *). OOTypeSym r => CodeType -> VS (r TypeData)
convTypeOO CodeType
t) []
typeDfltVal (Set CodeType
t) = VS (r TypeData) -> [SValue r] -> SValue r
forall (r :: * -> *).
Literal r =>
VS (r TypeData) -> [SValue r] -> SValue r
litSet (CodeType -> VS (r TypeData)
forall (r :: * -> *). OOTypeSym r => CodeType -> VS (r TypeData)
convTypeOO CodeType
t) []
typeDfltVal CodeType
_ = String -> SValue r
forall a. HasCallStack => String -> a
error String
"Attempt to get default value for type with none."