{-# LANGUAGE TypeFamilies #-}
-- | The logic to render Swift code is contained in this module
module Drasil.GOOL.LanguageRenderer.SwiftRenderer (
  -- * Swift Code Configuration -- defines syntax of all Swift code
  SwiftCode(..), swiftName, swiftVersion
) where

import Drasil.FileHandling.Legacy (indent)

import Drasil.Shared.CodeType (CodeType(..))
import Drasil.Shared.InterfaceCommon (UnRepr(..), 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(..), ListStatement(..), Set(..), listSlice, InternalList(..),
  EmptyStatement(..), MultiStatement(..), ValueStatement(..),
  AssignStatement(..), (&=), DeclStatement(..), PrintConsole(..),
  ReadConsole(..), FileHandling(..), PrintFile(..), ReadFile(..),
  StringStatement(..), FunctionSym, FuncAppStatement(..), CommentStatement(..),
  ControlStatement(..), ScopeSym(..), ParameterSym(..), BinderSym(..),
  BinderElim(..), MethodSym(..), convScope)
import Drasil.GOOL.InterfaceGOOL (OOProg, StateVar, 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, FileData)
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 OOProg SwiftCode Doc (Doc, Terminator) MethodData StateVar Doc ProgData FileData ModData Body Block

instance ProgramSym SwiftCode ProgData FileData where
  prog :: String
-> String
-> [FS (SwiftCode FileData)]
-> GSProgram SwiftCode ProgData
prog String
n String
st [FS (SwiftCode FileData)]
files = do
    fs <- (FS (SwiftCode FileData)
 -> StateT GOOLState Identity (SwiftCode FileData))
-> [FS (SwiftCode FileData)]
-> StateT GOOLState Identity [SwiftCode FileData]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (LensLike'
  (Zoomed (StateT FileState Identity) (SwiftCode FileData))
  GOOLState
  FileState
-> FS (SwiftCode FileData)
-> StateT GOOLState Identity (SwiftCode FileData)
forall c.
LensLike'
  (Zoomed (StateT FileState Identity) c) GOOLState FileState
-> StateT FileState Identity c -> StateT GOOLState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT FileState Identity) (SwiftCode FileData))
  GOOLState
  FileState
(FileState -> Focusing Identity (SwiftCode FileData) FileState)
-> GOOLState -> Focusing Identity (SwiftCode FileData) GOOLState
Lens' GOOLState FileState
lensGStoFS) [FS (SwiftCode FileData)]
files
    modify revFiles
    pure $ onCodeList (progD n st) fs

instance CommonRenderSym SwiftCode Doc (Doc, Terminator) MethodData Body Block
instance OORenderSym SwiftCode Doc (Doc, Terminator) MethodData StateVar Doc FileData ModData Body Block

instance UnRepr SwiftCode contents where
  unRepr :: SwiftCode contents -> contents
unRepr = SwiftCode contents -> contents
forall a. SwiftCode a -> a
unSC

instance FileSym SwiftCode FileData ModData where
  fileDoc :: FS (SwiftCode ModData) -> FS (SwiftCode FileData)
fileDoc FS (SwiftCode ModData)
m = do
    (FileState -> FileState) -> StateT FileState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (FileType -> FileState -> FileState
setFileType FileType
Combined)
    String
-> (SwiftCode ModData -> SwiftCode Doc)
-> SwiftCode Doc
-> FS (SwiftCode ModData)
-> FS (SwiftCode FileData)
forall (r :: * -> *) block mod file.
(BlockElim r block, RenderMod r mod, RenderFile r file mod) =>
String
-> (r mod -> r block) -> r block -> FS (r mod) -> FS (r file)
G.fileDoc String
swiftExt SwiftCode ModData -> SwiftCode Doc
forall (r :: * -> *) file mod.
RenderFile r file mod =>
r mod -> r Doc
top SwiftCode Doc
forall (r :: * -> *) file mod. RenderFile r file mod => r Doc
bottom FS (SwiftCode ModData)
m

  docMod :: String
-> String
-> [String]
-> String
-> FS (SwiftCode FileData)
-> FS (SwiftCode FileData)
docMod = ModuleDocRenderer
-> String
-> String
-> String
-> [String]
-> String
-> FS (SwiftCode FileData)
-> FS (SwiftCode FileData)
forall (r :: * -> *) file mod.
RenderFile r file mod =>
ModuleDocRenderer
-> String
-> String
-> String
-> [String]
-> String
-> FS (r file)
-> FS (r file)
G.docMod ModuleDocRenderer
CP.modDoc' String
swiftExt

instance RenderFile SwiftCode FileData ModData where
  top :: SwiftCode ModData -> SwiftCode Doc
top SwiftCode ModData
_ = 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 FileData)
-> FS (SwiftCode Doc) -> FS (SwiftCode FileData)
commentedMod = (SwiftCode FileData -> SwiftCode Doc -> SwiftCode FileData)
-> FS (SwiftCode FileData)
-> FS (SwiftCode Doc)
-> FS (SwiftCode FileData)
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues ((FileData -> Doc -> FileData)
-> SwiftCode FileData -> SwiftCode Doc -> SwiftCode FileData
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues FileData -> Doc -> FileData
R.commentedMod)

  fileFromData :: String -> FS (SwiftCode ModData) -> FS (SwiftCode FileData)
fileFromData = (String -> SwiftCode ModData -> SwiftCode FileData)
-> String -> FS (SwiftCode ModData) -> FS (SwiftCode FileData)
forall {k} (r :: k -> *) (mod :: k) (file :: k).
ModuleElim r mod =>
(String -> r mod -> r file) -> String -> FS (r mod) -> FS (r file)
G.fileFromData ((ModData -> FileData) -> SwiftCode ModData -> SwiftCode FileData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ((ModData -> FileData) -> SwiftCode ModData -> SwiftCode FileData)
-> (String -> ModData -> FileData)
-> String
-> SwiftCode ModData
-> SwiftCode FileData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ModData -> FileData
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 Body Block 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 Body where
  multiBody :: [MS (SwiftCode Doc)] -> MS (SwiftCode Doc)
multiBody = [MS (SwiftCode Doc)] -> MS (SwiftCode Doc)
forall (r :: * -> *) bod.
(BodyElim r bod, Monad r) =>
[MS (r bod)] -> MS (r Doc)
G.multiBody

instance BodyElim SwiftCode Body where
  body :: SwiftCode Doc -> Doc
body = SwiftCode Doc -> Doc
forall a. SwiftCode a -> a
unSC

instance BlockSym SwiftCode Block (Doc, Terminator) where
  block :: [MS (SwiftCode (Doc, Terminator))] -> MS (SwiftCode Doc)
block = [MS (SwiftCode (Doc, Terminator))] -> MS (SwiftCode Doc)
forall (r :: * -> *) stmt.
(Monad r, RenderStatement r stmt, StatementElim r stmt) =>
[MS (r stmt)] -> MS (r Doc)
G.block

instance RenderBlock SwiftCode Block where
  multiBlock :: [MS (SwiftCode Doc)] -> MS (SwiftCode Doc)
multiBlock = [MS (SwiftCode Doc)] -> MS (SwiftCode Doc)
forall (r :: * -> *) block.
(BlockElim r block, Monad r) =>
[MS (r block)] -> MS (r Doc)
G.multiBlock

instance BlockElim SwiftCode Block 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 -- Ignore reference types in "high-level" langauges for now; later on think about using boxed/unboxed types
  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 -- For now, treating arrays and lists the same, like we do for Python
  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
    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] -> 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
    typeFromData Void mt (text 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
    t <- VS (SwiftCode TypeData)
t'
    pure $ on2CodeValues (vard b n) t (toCode 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 :: * -> *). List r => 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
    v1 <- SValue SwiftCode
v1'
    v2 <- v2'
    let 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
    swiftPower (getCodeType $ valueType v1) (getCodeType $ valueType v2) (pure v1)
      (pure 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
    t <- VS (SwiftCode TypeData)
tp
    call (Just m) Nothing (getTypeString t) (pure t) vs 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
    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
    mem <- getMethodExcMap
        -- If function being called throws exceptions, need to wrap call in try
    let 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
    f $ G.call swiftNamedArgSep Nothing o n t as 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
    t <- VS (SwiftCode TypeData)
t'
    pure $ on2CodeValues (vd p i) t (toCode 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 :: * -> *). List r => SValue r -> SValue r
listSize
  arrayCopy :: SValue SwiftCode -> SValue SwiftCode
arrayCopy = SValue SwiftCode -> SValue SwiftCode
forall a. a -> a
id -- Swift uses value semantics for arrays

instance List SwiftCode 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
  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
  indexOf :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
indexOf = SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftIndexOf

instance ListStatement SwiftCode (Doc, Terminator) where
  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 :: * -> *) stmt.
ValueStatement r stmt =>
SValue r -> MS (r stmt)
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 :: * -> *) stmt.
(InternalValueExp r, ValueStatement r stmt) =>
String -> SValue r -> SValue r -> MS (r stmt)
CG.listAppend String
swiftListAppend
  listSet :: SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
listSet = SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(AssignStatement r stmt, IndexTranslator r, RenderVariable r,
 ValueElim r) =>
SValue r -> SValue r -> SValue r -> MS (r stmt)
CP.listSet

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 Block 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 :: * -> *) stmt.
(AssignStatement r stmt, InternalVarElim r, RenderValue r,
 RenderVariable r, ValueElim r) =>
(Doc -> Doc) -> [SVariable r] -> [SValue r] -> MS (r stmt)
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 :: * -> *) stmt bod.
(ControlStatement r stmt bod, RenderValue r, ValueElim r) =>
(Doc -> Doc) -> [SValue r] -> MS (r stmt)
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 {k} (r :: k -> *) (stmt :: k).
(RenderStatement r stmt, StatementElim r stmt) =>
MS (r stmt) -> MS (r stmt)
G.stmt
  loopStmt :: MS (SwiftCode (Doc, Terminator))
-> MS (SwiftCode (Doc, Terminator))
loopStmt = MS (SwiftCode (Doc, Terminator))
-> MS (SwiftCode (Doc, Terminator))
forall {k} (r :: k -> *) (stmt :: k).
(RenderStatement r stmt, StatementElim r stmt) =>
MS (r stmt) -> MS (r stmt)
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 EmptyStatement SwiftCode (Doc, Terminator) where
  emptyStmt :: MS (SwiftCode (Doc, Terminator))
emptyStmt = MS (SwiftCode (Doc, Terminator))
forall {k} (r :: k -> *) (stmt :: k).
RenderStatement r stmt =>
MS (r stmt)
G.emptyStmt

instance MultiStatement SwiftCode (Doc, Terminator) where
  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 ValueStatement SwiftCode (Doc, Terminator) where
  valStmt :: SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
valStmt = Terminator -> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(RenderStatement r stmt, ValueElim r) =>
Terminator -> SValue r -> MS (r stmt)
G.valStmt Terminator
Empty

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 :: * -> *) stmt.
(InternalVarElim r, RenderStatement r stmt, ValueElim r) =>
Terminator -> SVariable r -> SValue r -> MS (r stmt)
G.assign Terminator
Empty
  &-= :: SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
(&-=) = Terminator
-> SVariable SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(InternalVarElim r, RenderStatement r stmt, ValueElim r) =>
Terminator -> SVariable r -> SValue r -> MS (r stmt)
G.subAssign Terminator
Empty
  &+= :: SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
(&+=) = SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(InternalVarElim r, RenderStatement r stmt, ValueElim r) =>
SVariable r -> SValue r -> MS (r stmt)
CS.increment
  &++ :: SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
(&++) = SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(AssignStatement r stmt, Literal r) =>
SVariable r -> MS (r stmt)
M.increment1
  &-- :: SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
(&--) = SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(AssignStatement r stmt, Literal r) =>
SVariable r -> MS (r stmt)
M.decrement1

instance DeclStatement SwiftCode (Doc, Terminator) Body 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 :: * -> *) stmt bod.
(DeclStatement r stmt bod, RenderStatement r stmt,
 StatementElim r stmt, ValueElim r) =>
Terminator -> SVariable r -> r ScopeData -> SValue r -> MS (r stmt)
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 :: * -> *) stmt bod.
(DeclStatement r stmt bod, RenderStatement r stmt,
 StatementElim r stmt, ValueElim r) =>
Terminator -> SVariable r -> r ScopeData -> SValue r -> MS (r stmt)
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 :: * -> *) stmt bod.
(DeclStatement r stmt bod, Literal r, VariableElim r) =>
SVariable r -> r ScopeData -> MS (r stmt)
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 :: * -> *) stmt bod.
(DeclStatement r stmt bod, Literal r, VariableElim r) =>
SVariable r -> r ScopeData -> [SValue r] -> MS (r stmt)
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 :: * -> *) bod block stmt.
(BodySym r bod block, BlockSym r block stmt, MultiStatement r stmt,
 DeclStatement r stmt bod, ControlStatement r stmt bod, Literal r,
 VariableValue r, ListStatement r stmt, VariableElim r) =>
Integer -> SValue r -> SVariable r -> r ScopeData -> MS (r stmt)
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 :: * -> *) stmt bod.
DeclStatement r stmt bod =>
SVariable r -> r ScopeData -> [SValue r] -> MS (r stmt)
listDecDef
  constDecDef :: SVariable SwiftCode
-> SwiftCode ScopeData
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
constDecDef SVariable SwiftCode
vr SwiftCode ScopeData
scp SValue SwiftCode
vl' = do
    vdec <- Doc
-> SVariable SwiftCode
-> SwiftCode ScopeData
-> MS (SwiftCode (Doc, Terminator))
swiftVarDec Doc
swiftConst SVariable SwiftCode
vr SwiftCode ScopeData
scp
    vl <- zoom lensMStoVS vl'
    mkStmtNoEnd $ RC.statement vdec <+> equals <+> RC.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 stmt mthd stvr attch file mod bod block.
OORenderSym r vis stmt mthd stvr attch file mod bod block =>
SVariable r
-> r ScopeData -> [SVariable r] -> MS (r bod) -> MS (r stmt)
CP.funcDecDef

instance OODeclStatement SwiftCode (Doc, Terminator) Body 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 :: * -> *) stmt bod.
DeclStatement r stmt bod =>
SVariable r -> r ScopeData -> SValue r -> MS (r stmt)
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 :: * -> *) stmt bod.
(DeclStatement r stmt bod, OOValueExpression r, VariableElim r) =>
SVariable r -> r ScopeData -> [SValue r] -> MS (r stmt)
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 :: * -> *) stmt bod.
(DeclStatement r stmt bod, OOValueExpression r, VariableElim r) =>
String -> SVariable r -> r ScopeData -> [SValue r] -> MS (r stmt)
C.extObjDecNew

instance PrintConsole 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

instance ReadConsole SwiftCode (Doc, Terminator) where
  getInput :: SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
getInput SVariable SwiftCode
v = SVariable SwiftCode
v SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
&= 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 :: * -> *) stmt.
ValueStatement r stmt =>
SValue r -> MS (r stmt)
valStmt SValue SwiftCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueExpression r) =>
SValue r
swiftReadLineFunc

instance FileHandling SwiftCode (Doc, Terminator) where
  openFileR :: SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
openFileR SVariable SwiftCode
v SValue SwiftCode
pth = do
    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
    scpData <- getVarScope $ variableName v'
    let scp = ScopeData -> SwiftCode ScopeData
forall (r :: * -> *). ScopeSym r => ScopeData -> r ScopeData
convScope ScopeData
scpData
    multi [CP.openFileR swiftOpenFile v pth,
      varDec swiftContentsVar scp, swiftReadFile swiftContentsVar (valueOf 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

instance PrintFile SwiftCode (Doc, Terminator) where
  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

instance ReadFile SwiftCode (Doc, Terminator) where
  getFileInput :: SValue SwiftCode
-> SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
getFileInput SValue SwiftCode
_ SVariable SwiftCode
v = do
    wi <- MS Integer
getWordIndex
    li <- getLineIndex
    modify incrementWord
    v &= swiftInput v
      (listAccess (listAccess swiftContentsVal (litInt li)) (litInt 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 {k} (r :: k -> *) (stmt :: k).
EmptyStatement r stmt =>
MS (r stmt)
emptyStmt
  getFileInputLine :: SValue SwiftCode
-> SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
getFileInputLine SValue SwiftCode
_ SVariable SwiftCode
v = do
    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
    scpData <- getVarScope $ variableName v'
    let scp = ScopeData -> SwiftCode ScopeData
forall (r :: * -> *). ScopeSym r => ScopeData -> r ScopeData
convScope ScopeData
scpData
    wi <- getWordIndex
    li <- getLineIndex
    modify incrementLine
    slc <- listSlice swiftLineVar (listAccess swiftContentsVal (litInt li))
      (Just $ litInt wi) Nothing Nothing
    multi [varDec swiftLineVar scp, mkStmtNoEnd $ RC.block slc,
      v &= swiftJoinedFunc ' ' 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 {k} (r :: k -> *) (stmt :: k).
EmptyStatement r stmt =>
MS (r stmt)
emptyStmt
  getFileInputAll :: SValue SwiftCode
-> SVariable SwiftCode -> MS (SwiftCode (Doc, Terminator))
getFileInputAll SValue SwiftCode
_ SVariable SwiftCode
v = do
    li <- MS Integer
getLineIndex
    let 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 = 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)
    slc <- listSlice swiftContentsVar swiftContentsVal
      (Just $ litInt (li+1)) Nothing Nothing
    multi [mkStmtNoEnd $ RC.block slc,
      v &= swiftMapFunc swiftContentsVal
        (lambda [l_binder] (swiftJoinedFunc ' ' (valueOf 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 :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
&= 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 :: * -> *) stmt.
(MultiStatement r stmt, AssignStatement r stmt, List r, Literal r,
 RenderValue r, TypeElim r, VariableElim r) =>
[SVariable r] -> SValue r -> MS (r stmt)
M.stringListVals
  stringListLists :: [SVariable SwiftCode]
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
stringListLists = [SVariable SwiftCode]
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) bod block stmt.
(BodySym r bod block, BlockSym r block stmt,
 ControlStatement r stmt bod, Literal r, NumericExpression r,
 VariableValue r, List r, ListStatement r stmt, TypeElim r,
 VariableElim r, RenderValue r) =>
[SVariable r] -> SValue r -> MS (r stmt)
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 :: * -> *) stmt.
(InternalAssignStmt r stmt, ValueStatement r stmt,
 VariableValue r) =>
(String -> VS (r TypeData) -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MS (r stmt)
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 :: * -> *) stmt.
(InternalAssignStmt r stmt, ValueStatement r stmt,
 VariableValue r) =>
(String -> VS (r TypeData) -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MS (r stmt)
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 :: * -> *) stmt.
(InternalAssignStmt r stmt, ValueStatement r stmt,
 VariableValue r) =>
(String -> VS (r TypeData) -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MS (r stmt)
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 {k} (r :: k -> *) (stmt :: k).
RenderStatement r stmt =>
Doc -> String -> MS (r stmt)
G.comment Doc
commentStart

instance ControlStatement SwiftCode (Doc, Terminator) Body where
  break :: MS (SwiftCode (Doc, Terminator))
break = Doc -> MS (SwiftCode (Doc, Terminator))
forall {k} (r :: k -> *) (stmt :: k).
RenderStatement r stmt =>
Doc -> MS (r stmt)
mkStmtNoEnd Doc
R.break
  continue :: MS (SwiftCode (Doc, Terminator))
continue = Doc -> MS (SwiftCode (Doc, Terminator))
forall {k} (r :: k -> *) (stmt :: k).
RenderStatement r stmt =>
Doc -> MS (r stmt)
mkStmtNoEnd Doc
R.continue

  returnStmt :: SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
returnStmt = Terminator -> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(RenderStatement r stmt, ValueElim r) =>
Terminator -> SValue r -> MS (r stmt)
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 :: * -> *) stmt.
(Literal r, RenderStatement r stmt) =>
(r Value -> Doc) -> Terminator -> String -> MS (r stmt)
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 :: * -> *) bod stmt.
(BodyElim r bod, RenderStatement r stmt, ValueElim r) =>
(Doc -> Doc)
-> Doc
-> OptionalSpace
-> Doc
-> Doc
-> Doc
-> [(SValue r, MS (r bod))]
-> MS (r bod)
-> MS (r stmt)
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
    st <- MS (SwiftCode (Doc, Terminator))
-> MS (SwiftCode (Doc, Terminator))
forall {k} (r :: k -> *) (stmt :: k).
RenderStatement r stmt =>
MS (r stmt) -> MS (r stmt)
RC.stmt MS (SwiftCode (Doc, Terminator))
forall {k} (r :: k -> *) (stmt :: k).
EmptyStatement r stmt =>
MS (r stmt)
emptyStmt
    vl <- zoom lensMStoVS v
    vals <- mapM (zoom lensMStoVS . fst) cs
    bods <- mapM snd cs
    dflt <- bod
    mkStmtNoEnd $ R.switch (space <>) st vl dflt (zip vals 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 :: * -> *) stmt bod.
(ControlStatement r stmt bod, ValueExpression r) =>
SValue r -> MS (r bod) -> MS (r bod) -> MS (r stmt)
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 :: * -> *) stmt bod.
ControlStatement r stmt bod =>
SVariable r -> SValue r -> MS (r bod) -> MS (r stmt)
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 :: * -> *) stmt.
RenderStatement r stmt =>
(r Variable -> r Value -> r Doc -> Doc)
-> SVariable r -> SValue r -> MS (r Doc) -> MS (r stmt)
CS.forEach' SwiftCode Variable -> SwiftCode Value -> SwiftCode Doc -> Doc
forall (r :: * -> *) bod.
(BodyElim r bod, InternalVarElim r, ValueElim r) =>
r Variable -> r Value -> r bod -> 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 :: * -> *) bod stmt.
(BodyElim r bod, RenderStatement r stmt, ValueElim r) =>
(Doc -> Doc) -> Doc -> Doc -> SValue r -> MS (r bod) -> MS (r stmt)
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 {k} (r :: k -> *) (stmt :: k) (bod :: k).
RenderStatement r stmt =>
(r bod -> r bod -> Doc) -> MS (r bod) -> MS (r bod) -> MS (r stmt)
G.tryCatch SwiftCode Doc -> SwiftCode Doc -> Doc
forall {k} (r :: k -> *) (bod :: k).
BodyElim r bod =>
r bod -> r bod -> Doc
swiftTryCatch

  assert :: SValue SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
assert SValue SwiftCode
condition SValue SwiftCode
errorMessage = do
    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
    errMsg <- zoom lensMStoVS errorMessage
    mkStmtNoEnd (swiftAssert cond 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 :: * -> *) bod block stmt.
(BodySym r bod block, BlockSym r block stmt, ValueStatement r stmt,
 Literal r, VariableValue r, List r, ControlStatement r stmt bod,
 OOFunctionSym r) =>
VS (r FuncData) -> VS (r TypeData) -> MS (r stmt)
M.notifyObservers'

instance StrategyPattern SwiftCode Body Block 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 :: * -> *) stmt bod.
(EmptyStatement r stmt, AssignStatement r stmt, BodyElim r bod,
 Monad r, RenderStatement r stmt, StatementElim r stmt) =>
String
-> [(String, MS (r bod))]
-> 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
    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'
    toState $ on2CodeValues pd v (toCode 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 MethodData Body where
  docMain :: MS (SwiftCode Doc) -> MS (SwiftCode MethodData)
docMain = MS (SwiftCode Doc) -> MS (SwiftCode MethodData)
forall (r :: * -> *) vis mthd bod.
MethodSym r vis mthd bod =>
MS (r bod) -> MS (r mthd)
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 :: * -> *) attch vis mthd bod.
(AttachmentSym r attch, OORenderMethod r vis mthd attch bod) =>
String
-> r vis
-> VS (r TypeData)
-> [MS (r ParamData)]
-> MS (r bod)
-> MS (r mthd)
G.function
  mainFunction :: MS (SwiftCode Doc) -> MS (SwiftCode MethodData)
mainFunction = MS (SwiftCode Doc) -> MS (SwiftCode MethodData)
forall (r :: * -> *) bod mthd.
(BodyElim r bod, RenderMethod r mthd) =>
MS (r bod) -> MS (r mthd)
CP.mainBody
  docFunc :: String
-> [String]
-> Maybe String
-> MS (SwiftCode MethodData)
-> MS (SwiftCode MethodData)
docFunc = FuncDocRenderer
-> String
-> [String]
-> Maybe String
-> MS (SwiftCode MethodData)
-> MS (SwiftCode MethodData)
forall (r :: * -> *) mthd.
RenderMethod r mthd =>
FuncDocRenderer
-> String -> [String] -> Maybe String -> MS (r mthd) -> MS (r mthd)
G.docFunc FuncDocRenderer
CP.functionDoc

  inOutFunc :: String -> SwiftCode Doc -> InOutFunc SwiftCode MethodData Doc
inOutFunc String
n SwiftCode Doc
s = (VS (SwiftCode TypeData)
 -> [MS (SwiftCode ParamData)]
 -> MS (SwiftCode Doc)
 -> MS (SwiftCode MethodData))
-> InOutFunc SwiftCode MethodData Doc
forall (r :: * -> *) stmt bod block mthd.
(VariableValue r, ParameterSym r, DeclStatement r stmt bod,
 BlockSym r block stmt, BodySym r bod block, VariableElim r,
 RenderBody r bod, RenderType r, InternalControlStmt r stmt) =>
(VS (r TypeData)
 -> [MS (r ParamData)] -> MS (r bod) -> MS (r mthd))
-> [SVariable r]
-> [SVariable r]
-> [SVariable r]
-> MS (r bod)
-> MS (r mthd)
CP.inOutFunc (String
-> SwiftCode Doc
-> VS (SwiftCode TypeData)
-> [MS (SwiftCode ParamData)]
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
forall (r :: * -> *) vis mthd bod.
MethodSym r vis mthd bod =>
String
-> r vis
-> VS (r TypeData)
-> [MS (r ParamData)]
-> MS (r bod)
-> MS (r mthd)
function String
n SwiftCode Doc
s)

  docInOutFunc :: String -> SwiftCode Doc -> DocInOutFunc SwiftCode MethodData Doc
docInOutFunc String
n SwiftCode Doc
s = FuncDocRenderer
-> InOutFunc SwiftCode MethodData Doc
-> DocInOutFunc SwiftCode MethodData Doc
forall (r :: * -> *) mthd bod.
RenderMethod r mthd =>
FuncDocRenderer
-> ([SVariable r]
    -> [SVariable r] -> [SVariable r] -> MS (r bod) -> MS (r mthd))
-> String
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> MS (r bod)
-> MS (r mthd)
CP.docInOutFunc' FuncDocRenderer
CP.functionDoc (String -> SwiftCode Doc -> InOutFunc SwiftCode MethodData Doc
forall (r :: * -> *) vis mthd bod.
MethodSym r vis mthd bod =>
String -> r vis -> InOutFunc r mthd bod
inOutFunc String
n SwiftCode Doc
s)

instance OOMethodSym SwiftCode Doc MethodData Doc Body 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 mthd attch bod.
OORenderMethod r vis mthd attch bod =>
String
-> r vis
-> r attch
-> VS (r TypeData)
-> [MS (r ParamData)]
-> MS (r bod)
-> MS (r mthd)
G.method
  getMethod :: SVariable SwiftCode -> MS (SwiftCode MethodData)
getMethod = SVariable SwiftCode -> MS (SwiftCode MethodData)
forall (r :: * -> *) vis stmt mthd stvr attch file mod bod block.
OORenderSym r vis stmt mthd stvr attch file mod bod block =>
SVariable r -> MS (r mthd)
G.getMethod
  setMethod :: SVariable SwiftCode -> MS (SwiftCode MethodData)
setMethod = SVariable SwiftCode -> MS (SwiftCode MethodData)
forall (r :: * -> *) vis stmt mthd stvr attch file mod bod block.
OORenderSym r vis stmt mthd stvr attch file mod bod block =>
SVariable r -> MS (r mthd)
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 Doc
inOutMethod String
n SwiftCode Doc
s SwiftCode Doc
p = (VS (SwiftCode TypeData)
 -> [MS (SwiftCode ParamData)]
 -> MS (SwiftCode Doc)
 -> MS (SwiftCode MethodData))
-> InOutFunc SwiftCode MethodData Doc
forall (r :: * -> *) stmt bod block mthd.
(VariableValue r, ParameterSym r, DeclStatement r stmt bod,
 BlockSym r block stmt, BodySym r bod block, VariableElim r,
 RenderBody r bod, RenderType r, InternalControlStmt r stmt) =>
(VS (r TypeData)
 -> [MS (r ParamData)] -> MS (r bod) -> MS (r mthd))
-> [SVariable r]
-> [SVariable r]
-> [SVariable r]
-> MS (r bod)
-> MS (r mthd)
CP.inOutFunc (String
-> SwiftCode Doc
-> SwiftCode Doc
-> VS (SwiftCode TypeData)
-> [MS (SwiftCode ParamData)]
-> MS (SwiftCode Doc)
-> MS (SwiftCode MethodData)
forall (r :: * -> *) vis mthd attch bod.
OOMethodSym r vis mthd attch bod =>
String
-> r vis
-> r attch
-> VS (r TypeData)
-> [MS (r ParamData)]
-> MS (r bod)
-> MS (r mthd)
method String
n SwiftCode Doc
s SwiftCode Doc
p)
  docInOutMethod :: String
-> SwiftCode Doc
-> SwiftCode Doc
-> DocInOutFunc SwiftCode MethodData Doc
docInOutMethod String
n SwiftCode Doc
s SwiftCode Doc
p = FuncDocRenderer
-> InOutFunc SwiftCode MethodData Doc
-> DocInOutFunc SwiftCode MethodData Doc
forall (r :: * -> *) mthd bod.
RenderMethod r mthd =>
FuncDocRenderer
-> ([SVariable r]
    -> [SVariable r] -> [SVariable r] -> MS (r bod) -> MS (r mthd))
-> String
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> MS (r bod)
-> MS (r mthd)
CP.docInOutFunc' FuncDocRenderer
CP.functionDoc (String
-> SwiftCode Doc
-> SwiftCode Doc
-> InOutFunc SwiftCode MethodData Doc
forall (r :: * -> *) vis mthd attch bod.
OOMethodSym r vis mthd attch bod =>
String -> r vis -> r attch -> InOutFunc r mthd bod
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
$ String -> Doc -> MethodData
mthd String
"" Doc
d

instance OORenderMethod SwiftCode Doc MethodData Doc Body 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 {k} (r :: k -> *) (attch :: k).
AttachmentSym r attch =>
r attch
instanceLevel
  destructor :: forall stvr.
[CSStateVar SwiftCode stvr] -> MS (SwiftCode MethodData)
destructor [CSStateVar SwiftCode stvr]
_ = 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
    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
    stateVarDef s p vr (typeDfltVal $ getCodeType $ variableType 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 stmt mthd stvr attch file mod bod block.
(OORenderSym r vis stmt mthd stvr attch file mod bod block,
 Monad r) =>
r vis -> r attch -> 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 stmt mthd bod block.
(CommonRenderSym r vis stmt mthd bod block, Monad r) =>
Doc -> r vis -> SVariable r -> SValue r -> CS (r Doc)
CP.constVar (SwiftCode Doc -> Doc
forall {k} (r :: k -> *) (attch :: k).
PermElim r attch =>
r attch -> Doc
RC.perm (SwiftCode Doc
forall {k} (r :: k -> *) (attch :: k).
AttachmentSym r attch =>
r attch
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 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 mthd stvr.
(RenderClass r vis mthd stvr, VisibilitySym r vis) =>
Maybe String
-> [CSStateVar r stvr]
-> [MS (r mthd)]
-> [MS (r mthd)]
-> 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 mthd stvr.
(RenderClass r vis mthd stvr, VisibilitySym r vis) =>
String
-> Maybe String
-> [CSStateVar r stvr]
-> [MS (r mthd)]
-> [MS (r mthd)]
-> 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 mthd stvr.
(RenderClass r vis mthd stvr, VisibilitySym r vis) =>
String
-> [String]
-> [CSStateVar r stvr]
-> [MS (r mthd)]
-> [MS (r mthd)]
-> 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 mthd stvr.
RenderClass r vis mthd stvr =>
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 :: * -> *) mthd stvr vis.
(MethodElim r mthd, Monad r, StateVarElim r stvr,
 VisibilityElim r vis) =>
(String -> Doc -> Doc -> Doc -> Doc -> Doc)
-> String
-> r vis
-> r Doc
-> [CSStateVar r stvr]
-> [MS (r mthd)]
-> [MS (r mthd)]
-> 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 ModData MethodData where
  buildModule :: String
-> [String]
-> [MS (SwiftCode MethodData)]
-> [CSStateVar SwiftCode Doc]
-> FS (SwiftCode ModData)
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) -- This needs to be set before the functions/
                             -- classes are evaluated. CP.buildModule will
                             -- reset it to the proper name.
    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
    cls <- mapM (zoom lensFStoCS) cs
    mn <- getCurrMain
    let modName = if Bool
mn then String
swiftMain else String
n
    CP.buildModule modName (do
      lis <- getLangImports
      libis <- getLibImports
      pure $ vcat $ map (RC.import' .
          (langImport :: Label -> SwiftCode Doc))
          (sort $ lis ++ is ++ libis))
      (zoom lensFStoMS swiftStringError) getMainDoc
        (map pure fns) (map pure cls)

instance RenderMod SwiftCode ModData where
  modFromData :: String -> FS Doc -> FS (SwiftCode ModData)
modFromData String
n = String
-> (Doc -> SwiftCode ModData) -> FS Doc -> FS (SwiftCode ModData)
forall {k} (r :: k -> *) (mod :: k).
String -> (Doc -> r mod) -> FS Doc -> FS (r mod)
G.modFromData String
n (ModData -> SwiftCode ModData
forall (r :: * -> *) a. Monad r => a -> r a
toCode (ModData -> SwiftCode ModData)
-> (Doc -> ModData) -> Doc -> SwiftCode ModData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc -> ModData
md String
n)
  updateModuleDoc :: (Doc -> Doc) -> SwiftCode ModData -> SwiftCode ModData
updateModuleDoc Doc -> Doc
f = (ModData -> ModData) -> SwiftCode ModData -> SwiftCode ModData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ((Doc -> Doc) -> ModData -> ModData
updateMod Doc -> Doc
f)

instance ModuleElim SwiftCode ModData where
  module' :: SwiftCode ModData -> Doc
module' = ModData -> Doc
modDoc (ModData -> Doc)
-> (SwiftCode ModData -> ModData) -> SwiftCode ModData -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SwiftCode ModData -> ModData
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
  v <- SValue r
v'
  mkVal (valueType v) (RC.value v <> 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
  v <- SValue r
v'
  mkVal (valueType v) (tryLabel <+> RC.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
  v <- SValue r
v'
  mkVal (valueType v) (swiftInOutArg <> RC.value v)

-- Putting "gool" in these names to avoid name conflicts
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
  t <- VS (SwiftCode TypeData)
t'
  typeFromData (List $ getCodeType t) ("[" ++ getTypeString t ++ "]")
    (brackets $ renderType 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
  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
  rt <- r
  typeFromData (Func (map getCodeType pts) (getCodeType rt))
    ("(" ++ intercalate listSep (map getTypeString pts) ++ ")" ++ " " ++
      swiftRetType ++ " " ++ getTypeString rt)
    (parens (hicat listSep' $ map renderType pts) <+> swiftRetType' <+>
      renderType 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
  v1 <- SValue SwiftCode
v1'
  v2 <- v2'
  let 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
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)
  exprT (getCodeType $ valueType v1) (getCodeType $ valueType 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
  t <- VS (SwiftCode TypeData)
t'
  v <- v'
  let 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
  unwrap $ mkStateVal (pure t) (R.castObj (renderType t) (RC.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
  v <- SValue r
v'
  let 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 = 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
  objMethodCallNamedArgs int l swiftIndex [(ofArg, pure 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

-- | Swift's syntactic sugar for list slicing.
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

  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
  scpData <- getVarScope $ variableName vnew
  let scp = ScopeData -> SwiftCode ScopeData
forall (r :: * -> *). ScopeSym r => ScopeData -> r ScopeData
convScope ScopeData
scpData

  stepV <- zoom lensMStoVS step
  let mbStepV = SwiftCode Value -> Maybe Integer
forall (r :: * -> *). ValueElim r => r Value -> Maybe Integer
valueInt SwiftCode Value
stepV

  -- Generate fresh variable names if required
  begName <- genVarNameIf (isNothing beg && isNothing mbStepV) "begIdx"
  endName <- genVarNameIf (isNothing end && isNothing mbStepV) "endIdx"

  let (setBeg, begVal) = M.makeSetterVal begName step mbStepV beg (litInt 0)    (listSize vo #- litInt 1) scp
      (setEnd, endVal) = M.makeSetterVal endName step mbStepV end (listSize vo) (litInt (-1)) scp

      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 = 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 = SVariable SwiftCode
vn SVariable SwiftCode
-> SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
&= 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 :: * -> *). List r => 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)))
  block [
      setBeg,
      setEnd,
      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 :: * -> *) stmt.
ValueStatement r stmt =>
SValue r -> MS (r stmt)
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
  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 (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 = if Bool
newLn then SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) stmt.
ValueStatement r stmt =>
SValue r -> MS (r stmt)
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 {k} (r :: k -> *) (stmt :: k).
EmptyStatement r stmt =>
MS (r stmt)
emptyStmt
  tryCatch (bodyStatements
    [valStmt $ swiftWriteFunc (valToPrint $ getCodeType $ valueType v) f, prNewLn])
    (oneLiner $ throw "Error printing to file.")

-- swiftPrint can handle lists, so don't use G.print for lists.
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 :: * -> *) stmt.
InternalIOStmt r stmt =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r stmt)
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 :: * -> *) block stmt bod.
(BlockSym r block stmt, BodySym r bod block, MultiStatement r stmt,
 PrintConsole r stmt, PrintFile r stmt, DeclStatement r stmt bod,
 AssignStatement r stmt, ControlStatement r stmt bod, Literal r,
 NumericExpression r, Comparison r, VariableValue r, List r,
 TypeElim r, InternalIOStmt r stmt) =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r stmt)
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
  vr' <- SVariable SwiftCode
vr
  let 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"
  swiftInput' (getCodeType $ variableType 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 :: * -> *) stmt bod.
ControlStatement r stmt bod =>
MS (r bod) -> MS (r bod) -> MS (r stmt)
tryCatch
    ([MS (SwiftCode (Doc, Terminator))] -> MS (SwiftCode Doc)
forall {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k).
(BlockSym r block stmt, BodySym r bod block) =>
[MS (r stmt)] -> MS (r bod)
bodyStatements [(SValue SwiftCode
 -> VS (SwiftCode TypeData) -> SValue SwiftCode -> SValue SwiftCode)
-> SVariable SwiftCode
-> SValue SwiftCode
-> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(AssignStatement r stmt, Literal r) =>
(SValue r -> VS (r TypeData) -> SValue r -> SValue r)
-> SVariable r -> SValue r -> MS (r stmt)
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 :: * -> *) stmt.
ValueStatement r stmt =>
SValue r -> MS (r stmt)
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 {k} (r :: k -> *) (stmt :: k).
EmptyStatement r stmt =>
MS (r stmt)
emptyStmt])
    -- It's important for the catch case to throw, or else the swift compiler
    -- will have no guarantees that the file variable has been initialized.
    (MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc)
forall {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k).
(BlockSym r block stmt, BodySym r bod block) =>
MS (r stmt) -> MS (r bod)
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 :: * -> *) stmt bod.
ControlStatement r stmt bod =>
String -> MS (r stmt)
throw String
"Error opening file.")

swiftCloseFile :: SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
swiftCloseFile :: SValue SwiftCode -> MS (SwiftCode (Doc, Terminator))
swiftCloseFile SValue SwiftCode
f' = do
  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'
  -- How I've currently implemented file-reading, files don't need to be
  -- "closed", so InFile case is (correctly) just an empty stmt
  let 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 {k} (r :: k -> *) (stmt :: k).
EmptyStatement r stmt =>
MS (r stmt)
emptyStmt
      swClose CodeType
OutFile = MS (SwiftCode Doc)
-> MS (SwiftCode Doc) -> MS (SwiftCode (Doc, Terminator))
forall (r :: * -> *) stmt bod.
ControlStatement r stmt bod =>
MS (r bod) -> MS (r bod) -> MS (r stmt)
tryCatch (MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc)
forall {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k).
(BlockSym r block stmt, BodySym r bod block) =>
MS (r stmt) -> MS (r bod)
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 :: * -> *) stmt.
ValueStatement r stmt =>
SValue r -> MS (r stmt)
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 {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k).
(BlockSym r block stmt, BodySym r bod block) =>
MS (r stmt) -> MS (r bod)
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 :: * -> *) stmt bod.
ControlStatement r stmt bod =>
String -> MS (r stmt)
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"
  swClose (getCodeType $ valueType 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 :: * -> *) stmt bod.
ControlStatement r stmt bod =>
MS (r bod) -> MS (r bod) -> MS (r stmt)
tryCatch
  (MS (SwiftCode (Doc, Terminator)) -> MS (SwiftCode Doc)
forall {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k).
(BlockSym r block stmt, BodySym r bod block) =>
MS (r stmt) -> MS (r bod)
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 :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
&= 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 {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k).
(BlockSym r block stmt, BodySym r bod block) =>
MS (r stmt) -> MS (r bod)
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 :: * -> *) stmt bod.
ControlStatement r stmt bod =>
String -> MS (r stmt)
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
  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'
  modify $ useVarName (variableName v)
  modify $ setVarScope (variableName v) (scopeData scp)
  let bind AttachmentTag
ClassLevel = SwiftCode Doc
forall {k} (r :: k -> *) (attch :: k).
AttachmentSym r attch =>
r attch
classLevel :: SwiftCode Doc
      bind AttachmentTag
InstanceLevel = SwiftCode Doc
forall {k} (r :: k -> *) (attch :: k).
AttachmentSym r attch =>
r attch
instanceLevel :: 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
  mkStmtNoEnd (RC.perm p <+> dec <+> RC.variable v <> swiftTypeSpec
    <+> renderType (variableType 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
  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'
  innerTp <- zoom lensMStoVS (innerType $ return $ variableType v)
  modify $ useVarName (variableName v)
  modify $ setVarScope (variableName v) (scopeData scp)
  let bind AttachmentTag
ClassLevel = SwiftCode Doc
forall {k} (r :: k -> *) (attch :: k).
AttachmentSym r attch =>
r attch
classLevel :: SwiftCode Doc
      bind AttachmentTag
InstanceLevel = SwiftCode Doc
forall {k} (r :: k -> *) (attch :: k).
AttachmentSym r attch =>
r attch
instanceLevel :: 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
  mkStmtNoEnd (RC.perm p <+> dec <+> RC.variable v <> swiftTypeSpec
    <+> text (swiftSet ++ "<" ++ getTypeString innerTp ++ ">"))

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 bod, InternalVarElim r, ValueElim r)
  => r Variable -> r Value -> r bod -> Doc
swiftForEach :: forall (r :: * -> *) bod.
(BodyElim r bod, InternalVarElim r, ValueElim r) =>
r Variable -> r Value -> r bod -> Doc
swiftForEach r Variable
i r Value
lstVar r bod
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 bod -> Doc
forall {k} (r :: k -> *) (bod :: k). BodyElim r bod => r bod -> Doc
RC.body r bod
b,
  Doc
bodyEnd]

swiftTryCatch :: (BodyElim r bod) => r bod -> r bod -> Doc
swiftTryCatch :: forall {k} (r :: k -> *) (bod :: k).
BodyElim r bod =>
r bod -> r bod -> Doc
swiftTryCatch r bod
tb r bod
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 bod -> Doc
forall {k} (r :: k -> *) (bod :: k). BodyElim r bod => r bod -> Doc
RC.body r bod
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 bod -> Doc
forall {k} (r :: k -> *) (bod :: k). BodyElim r bod => r bod -> Doc
RC.body r bod
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
  tp <- MSMthdType SwiftCode
t
  pms <- sequence ps
  bod <- b
  mem <- zoom lensMStoVS getMethodExcMap
  mn <- zoom lensMStoFS getModuleName
  let 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
  mthdFromData Pub (vcat [
    RC.visibility s <+> RC.perm p <+> swiftFunc <+> text n <>
      parens (parameterList pms) <+> emptyIfNull excs throwsLabel <+>
      swiftRetType' <+> renderType tp <+> bodyStart,
    indent $ RC.body bod,
    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
  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
  bod <- multiBody [G.initStmts is, b]
  mem <- zoom lensMStoVS getMethodExcMap
  mn <- zoom lensMStoFS getModuleName
  cn <- getClassName
  let 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
  mthdFromData Pub (vcat [
    swiftCtorName <> parens (parameterList pms) <+>
      emptyIfNull excs throwsLabel <+> bodyStart,
    indent $ RC.body bod,
    bodyEnd])

-- If the program uses throw, then generate code that extends Strings with the
-- Error protocol. This line only needs to be generated once for the entire
-- program
swiftStringError :: MS Doc
swiftStringError :: StateT MethodState Identity Doc
swiftStringError = do
  tu <- MS Bool
getThrowUsed
  errdef <- getErrorDefined
  str <- zoom lensMStoVS (string :: VS (SwiftCode TypeData))
  if tu && not errdef then do
    modify setErrorDefined
    pure (swiftExtension <+> renderType str <> swiftConforms <+> swiftRetroactive
      <+> swiftError <+> bodyStart <> bodyEnd)
  else pure 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."