{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PostfixOperators #-}

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

import Utils.Drasil (indent)

import GOOL.Drasil.CodeType (CodeType(..))
import GOOL.Drasil.ClassInterface (Label, MSBody, MSBlock, VSType, SVariable, 
  SValue, MSStatement, MSParameter, SMethod, OOProg, Initializers,
  ProgramSym(..), FileSym(..), PermanenceSym(..), BodySym(..), oneLiner,
  bodyStatements, BlockSym(..), TypeSym(..), TypeElim(..), VariableSym(..),
  VariableElim(..), ValueSym(..), Argument(..), Literal(..), litZero,
  MathConstant(..), VariableValue(..), CommandLineArgs(..),
  NumericExpression(..), BooleanExpression(..), Comparison(..),
  ValueExpression(..), funcApp, funcAppNamedArgs, selfFuncApp, extFuncApp,
  newObj, InternalValueExp(..), objMethodCall, objMethodCallNamedArgs,
  objMethodCallNoParams, FunctionSym(..), ($.), GetSet(..), List(..),
  listSlice, InternalList(..), ThunkSym(..), VectorType(..), VectorDecl(..),
  VectorThunk(..), VectorExpression(..), ThunkAssign(..), StatementSym(..),
  AssignStatement(..), (&=), DeclStatement(..), IOStatement(..),
  StringStatement(..), FuncAppStatement(..), CommentStatement(..),
  ControlStatement(..), StatePattern(..), ObserverPattern(..),
  StrategyPattern(..), ScopeSym(..), ParameterSym(..), MethodSym(..),
  StateVarSym(..), ClassSym(..), ModuleSym(..), convType)
import GOOL.Drasil.RendererClasses (MSMthdType, RenderSym, 
  RenderFile(..), ImportSym(..), ImportElim, PermElim(binding), RenderBody(..), 
  BodyElim, RenderBlock(..), BlockElim, RenderType(..), InternalTypeElim, 
  UnaryOpSym(..), BinaryOpSym(..), OpElim(uOpPrec, bOpPrec), RenderVariable(..),
  InternalVarElim(variableBind), RenderValue(..), ValueElim(valuePrec), 
  InternalGetSet(..), InternalListFunc(..), RenderFunction(..), 
  FunctionElim(functionType), InternalAssignStmt(..), InternalIOStmt(..), 
  InternalControlStmt(..), RenderStatement(..), StatementElim(statementTerm), 
  RenderScope(..), ScopeElim, MethodTypeSym(..), RenderParam(..), 
  ParamElim(parameterName, parameterType), RenderMethod(..), MethodElim, 
  StateVarElim, RenderClass(..), ClassElim, RenderMod(..), ModuleElim, 
  BlockCommentSym(..), BlockCommentElim)
import qualified GOOL.Drasil.RendererClasses as RC (import', perm, body, block,
  type', uOp, bOp, variable, value, function, statement, scope, parameter,
  method, stateVar, class', module', blockComment')
import GOOL.Drasil.LanguageRenderer (dot, blockCmtStart, blockCmtEnd, 
  docCmtStart, bodyStart, bodyEnd, commentStart, elseIfLabel, forLabel, 
  inLabel, tryLabel, catchLabel, throwLabel, throwsLabel, importLabel, listSep',
  printLabel, listSep, piLabel, access, tuple, FuncDocRenderer, 
  ClassDocRenderer, parameterList)
import qualified GOOL.Drasil.LanguageRenderer as R (sqrt, abs, log10, log, exp, 
  sin, cos, tan, asin, acos, atan, floor, ceil, pow, class', multiStmt, body, 
  classVar, func, listSetFunc, castObj, static, dynamic, break, continue, 
  private, blockCmt, docCmt, addComments, commentedMod, commentedItem)
import GOOL.Drasil.LanguageRenderer.Constructors (mkStmtNoEnd, mkStateVal, 
  mkVal, VSOp, unOpPrec, powerPrec, unExpr, unExpr', typeUnExpr, binExpr, 
  binExpr', typeBinExpr)
import qualified GOOL.Drasil.LanguageRenderer.LanguagePolymorphic as G (
  multiBody, block, multiBlock, listInnerType, obj, csc, sec, cot, negateOp,
  equalOp, notEqualOp, greaterOp, greaterEqualOp, lessOp, lessEqualOp, plusOp,
  minusOp, multOp, divideOp, moduloOp, var, staticVar, objVar, arrayElem,
  litChar, litDouble, litInt, litString, valueOf, arg, argsList, objAccess,
  objMethodCall, call, funcAppMixedArgs, selfFuncAppMixedArgs, newObjMixedArgs,
  lambda, func, get, set, listAdd, listAppend, listAccess, listSet, getFunc,
  setFunc, listAppendFunc, stmt, loopStmt, emptyStmt, assign, subAssign,
  increment, objDecNew, print, returnStmt, valStmt, comment, throw, ifCond,
  tryCatch, construct, param, method, getMethod, setMethod, initStmts,
  function, docFunc, buildClass, implementingClass, docClass, commentedClass,
  modFromData, fileDoc, fileFromData, defaultOptSpace)
import qualified GOOL.Drasil.LanguageRenderer.CommonPseudoOO as CP (classVar, 
  objVarSelf, intClass, buildModule, docMod', bindingError, extFuncAppMixedArgs, 
  notNull, listDecDef, destructorError, stateVarDef, constVar, litArray, 
  listSetFunc, extraClass, listAccessFunc, doubleRender, double, openFileR, 
  openFileW, self, multiAssign, multiReturn, listDec, funcDecDef, 
  inOutCall, forLoopError, mainBody, inOutFunc, docInOutFunc', bool, float, 
  stringRender', string', inherit, implements)
import qualified GOOL.Drasil.LanguageRenderer.CLike as C (notOp, andOp, orOp, 
  litTrue, litFalse, inlineIf, libFuncAppMixedArgs, libNewObjMixedArgs, 
  listSize, varDecDef, extObjDecNew, switch, while)
import qualified GOOL.Drasil.LanguageRenderer.Macros as M (ifExists, decrement1,
  increment1, runStrategy, stringListVals, stringListLists, notifyObservers', 
  checkState)
import GOOL.Drasil.AST (Terminator(..), ScopeTag(..), qualName, FileType(..), 
  FileData(..), fileD, FuncData(..), fd, ModData(..), md, updateMod, 
  MethodData(..), mthd, updateMthd, OpData(..), ParamData(..), pd, ProgData(..),
  progD, TypeData(..), td, ValData(..), vd, Binding(..), VarData(..), vard,
  CommonThunk, pureValue, vectorize, vectorize2, sumComponents, commonVecIndex,
  commonThunkElim, commonThunkDim)
import GOOL.Drasil.Helpers (hicat, emptyIfNull, toCode, toState, onCodeValue, 
  onStateValue, on2CodeValues, on2StateValues, onCodeList, onStateList)
import GOOL.Drasil.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, genLoopIndex)

import Prelude hiding (break,print,(<>),sin,cos,tan,floor)
import Control.Applicative (liftA2)
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)
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
forall a. Eq a => SwiftCode a -> SwiftCode a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SwiftCode a -> SwiftCode a -> Bool
$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
Eq

instance Functor SwiftCode where
  fmap :: forall a b. (a -> b) -> SwiftCode a -> SwiftCode b
fmap a -> b
f (SC a
x) = forall a. a -> SwiftCode a
SC (a -> b
f a
x)

instance Applicative SwiftCode where
  pure :: forall a. a -> SwiftCode a
pure = forall a. a -> SwiftCode a
SC
  (SC a -> b
f) <*> :: forall a b. SwiftCode (a -> b) -> SwiftCode a -> SwiftCode b
<*> (SC a
x) = 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 where

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

instance RenderSym SwiftCode

instance FileSym SwiftCode where
  type File SwiftCode = FileData
  fileDoc :: FSModule SwiftCode -> SFile SwiftCode
fileDoc FSModule SwiftCode
m = do
    forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (FileType -> FileState -> FileState
setFileType FileType
Combined)
    forall (r :: * -> *).
RenderSym r =>
String
-> (r (Module r) -> r (Block r))
-> r (Block r)
-> FSModule r
-> SFile r
G.fileDoc String
swiftExt forall (r :: * -> *). RenderFile r => r (Module r) -> r (Block r)
top forall (r :: * -> *). RenderFile r => r (Block r)
bottom FSModule SwiftCode
m

  docMod :: String -> [String] -> String -> SFile SwiftCode -> SFile SwiftCode
docMod = forall (r :: * -> *).
RenderSym r =>
String -> String -> [String] -> String -> SFile r -> SFile r
CP.docMod' String
swiftExt

instance RenderFile SwiftCode where
  top :: SwiftCode (Module SwiftCode) -> SwiftCode (Block SwiftCode)
top SwiftCode (Module SwiftCode)
_ = forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
empty
  bottom :: SwiftCode (Block SwiftCode)
bottom = forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
empty

  commentedMod :: SFile SwiftCode
-> FS (SwiftCode (BlockComment SwiftCode)) -> SFile SwiftCode
commentedMod = forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues (forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues FileData -> Doc -> FileData
R.commentedMod)

  fileFromData :: String -> FSModule SwiftCode -> SFile SwiftCode
fileFromData = forall (r :: * -> *).
RenderSym r =>
(String -> r (Module r) -> r (File r))
-> String -> FSModule r -> SFile r
G.fileFromData (forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ModData -> FileData
fileD)

instance ImportSym SwiftCode where
  type Import SwiftCode = Doc
  langImport :: String -> SwiftCode (Import SwiftCode)
langImport String
n = forall (r :: * -> *) a. Monad r => a -> r a
toCode forall a b. (a -> b) -> a -> b
$ Doc
importLabel Doc -> Doc -> Doc
<+> String -> Doc
text String
n
  modImport :: String -> SwiftCode (Import SwiftCode)
modImport = forall (r :: * -> *). ImportSym r => String -> r (Import r)
langImport

instance ImportElim SwiftCode where
  import' :: SwiftCode (Import SwiftCode) -> Doc
import' = forall a. SwiftCode a -> a
unSC

instance PermanenceSym SwiftCode where
  type Permanence SwiftCode = Doc
  static :: SwiftCode (Permanence SwiftCode)
static = forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
R.static
  dynamic :: SwiftCode (Permanence SwiftCode)
dynamic = forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
R.dynamic

instance PermElim SwiftCode where
  perm :: SwiftCode (Permanence SwiftCode) -> Doc
perm = forall a. SwiftCode a -> a
unSC
  binding :: SwiftCode (Permanence SwiftCode) -> Binding
binding = forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String -> String
CP.bindingError String
swiftName

instance BodySym SwiftCode where
  type Body SwiftCode = Doc
  body :: [MSBlock SwiftCode] -> MSBody SwiftCode
body = forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList (forall (m :: * -> *) a b. Monad m => ([a] -> b) -> [m a] -> m b
onCodeList [Doc] -> Doc
R.body)

  addComments :: String -> MSBody SwiftCode -> MSBody SwiftCode
addComments String
s = forall a b s. (a -> b) -> State s a -> State s b
onStateValue (forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue (String -> Doc -> Doc -> Doc
R.addComments String
s Doc
commentStart))

instance RenderBody SwiftCode where
  multiBody :: [MSBody SwiftCode] -> MSBody SwiftCode
multiBody = forall (r :: * -> *).
(RenderSym r, Monad r) =>
[MSBody r] -> MS (r Doc)
G.multiBody 

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

instance BlockSym SwiftCode where
  type Block SwiftCode = Doc
  block :: [MSStatement SwiftCode] -> MSBlock SwiftCode
block = forall (r :: * -> *).
(RenderSym r, Monad r) =>
[MSStatement r] -> MS (r Doc)
G.block

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

instance BlockElim SwiftCode where
  block :: SwiftCode (Block SwiftCode) -> Doc
block = forall a. SwiftCode a -> a
unSC

instance TypeSym SwiftCode where
  type Type SwiftCode = TypeData
  bool :: VSType SwiftCode
bool = forall (r :: * -> *). RenderSym r => VSType r
CP.bool
  int :: VSType SwiftCode
int = forall (r :: * -> *). RenderSym r => VSType r
swiftIntType
  float :: VSType SwiftCode
float = forall (r :: * -> *). RenderSym r => VSType r
CP.float
  double :: VSType SwiftCode
double = forall (r :: * -> *). RenderSym r => VSType r
CP.double
  char :: VSType SwiftCode
char = forall (r :: * -> *). RenderSym r => VSType r
swiftCharType
  string :: VSType SwiftCode
string = forall (r :: * -> *). RenderSym r => VSType r
CP.string'
  infile :: VSType SwiftCode
infile = forall (r :: * -> *). RenderSym r => VSType r
swiftFileType 
  outfile :: VSType SwiftCode
outfile = forall (r :: * -> *). RenderSym r => VSType r
swiftFileHdlType
  listType :: VSType SwiftCode -> VSType SwiftCode
listType = forall (r :: * -> *). RenderSym r => VSType r -> VSType r
swiftListType
  arrayType :: VSType SwiftCode -> VSType SwiftCode
arrayType = forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listType -- For now, treating arrays and lists the same, like we do for Python
  listInnerType :: VSType SwiftCode -> VSType SwiftCode
listInnerType = forall (r :: * -> *). RenderSym r => VSType r -> VSType r
G.listInnerType
  obj :: String -> VSType SwiftCode
obj = forall (r :: * -> *). RenderSym r => String -> VSType r
G.obj
  funcType :: [VSType SwiftCode] -> VSType SwiftCode -> VSType SwiftCode
funcType = forall (r :: * -> *).
RenderSym r =>
[VSType r] -> VSType r -> VSType r
swiftFuncType
  void :: VSType SwiftCode
void = forall (r :: * -> *). RenderSym r => VSType r
swiftVoidType

instance TypeElim SwiftCode where
  getType :: SwiftCode (Type SwiftCode) -> CodeType
getType = TypeData -> CodeType
cType forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC
  getTypeString :: SwiftCode (Type SwiftCode) -> String
getTypeString = TypeData -> String
typeString forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC
  
instance RenderType SwiftCode where
  multiType :: [VSType SwiftCode] -> VSType SwiftCode
multiType [VSType SwiftCode]
ts = do
    [SwiftCode TypeData]
typs <- forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [VSType SwiftCode]
ts
    let mt :: String
mt = [String] -> String
tuple forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *). TypeElim r => r (Type r) -> String
getTypeString [SwiftCode TypeData]
typs
    forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData CodeType
Void String
mt (String -> Doc
text String
mt)
  typeFromData :: CodeType -> String -> Doc -> VSType SwiftCode
typeFromData CodeType
t String
s Doc
d = forall a s. a -> State s a
toState forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *) a. Monad r => a -> r a
toCode forall a b. (a -> b) -> a -> b
$ CodeType -> String -> Doc -> TypeData
td CodeType
t String
s Doc
d

instance InternalTypeElim SwiftCode where
  type' :: SwiftCode (Type SwiftCode) -> Doc
type' = TypeData -> Doc
typeDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC

instance UnaryOpSym SwiftCode where
  type UnaryOp SwiftCode = OpData
  notOp :: VSUnOp SwiftCode
notOp = forall (r :: * -> *). Monad r => VSOp r
C.notOp
  negateOp :: VSUnOp SwiftCode
negateOp = forall (r :: * -> *). Monad r => VSOp r
G.negateOp
  sqrtOp :: VSUnOp SwiftCode
sqrtOp = forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.sqrt
  absOp :: VSUnOp SwiftCode
absOp = forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.abs
  logOp :: VSUnOp SwiftCode
logOp = forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.log10
  lnOp :: VSUnOp SwiftCode
lnOp = forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.log
  expOp :: VSUnOp SwiftCode
expOp = forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.exp
  sinOp :: VSUnOp SwiftCode
sinOp = forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.sin
  cosOp :: VSUnOp SwiftCode
cosOp = forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.cos
  tanOp :: VSUnOp SwiftCode
tanOp = forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.tan
  asinOp :: VSUnOp SwiftCode
asinOp = forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.asin
  acosOp :: VSUnOp SwiftCode
acosOp = forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.acos
  atanOp :: VSUnOp SwiftCode
atanOp = forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.atan
  floorOp :: VSUnOp SwiftCode
floorOp = forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.floor
  ceilOp :: VSUnOp SwiftCode
ceilOp = forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath String
R.ceil

instance BinaryOpSym SwiftCode where
  type BinaryOp SwiftCode = OpData
  equalOp :: VSBinOp SwiftCode
equalOp = forall (r :: * -> *). Monad r => VSOp r
G.equalOp
  notEqualOp :: VSBinOp SwiftCode
notEqualOp = forall (r :: * -> *). Monad r => VSOp r
G.notEqualOp
  greaterOp :: VSBinOp SwiftCode
greaterOp = forall (r :: * -> *). Monad r => VSOp r
G.greaterOp
  greaterEqualOp :: VSBinOp SwiftCode
greaterEqualOp = forall (r :: * -> *). Monad r => VSOp r
G.greaterEqualOp
  lessOp :: VSBinOp SwiftCode
lessOp = forall (r :: * -> *). Monad r => VSOp r
G.lessOp
  lessEqualOp :: VSBinOp SwiftCode
lessEqualOp = forall (r :: * -> *). Monad r => VSOp r
G.lessEqualOp
  plusOp :: VSBinOp SwiftCode
plusOp = forall (r :: * -> *). Monad r => VSOp r
G.plusOp
  minusOp :: VSBinOp SwiftCode
minusOp = forall (r :: * -> *). Monad r => VSOp r
G.minusOp
  multOp :: VSBinOp SwiftCode
multOp = forall (r :: * -> *). Monad r => VSOp r
G.multOp
  divideOp :: VSBinOp SwiftCode
divideOp = forall (r :: * -> *). Monad r => VSOp r
G.divideOp
  powerOp :: VSBinOp SwiftCode
powerOp = forall a. VS a -> VS a
addMathImport forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). Monad r => String -> VSOp r
powerPrec String
R.pow
  moduloOp :: VSBinOp SwiftCode
moduloOp = forall (r :: * -> *). Monad r => VSOp r
G.moduloOp
  andOp :: VSBinOp SwiftCode
andOp = forall (r :: * -> *). Monad r => VSOp r
C.andOp
  orOp :: VSBinOp SwiftCode
orOp = forall (r :: * -> *). Monad r => VSOp r
C.orOp

instance OpElim SwiftCode where
  uOp :: SwiftCode (UnaryOp SwiftCode) -> Doc
uOp = OpData -> Doc
opDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC
  bOp :: SwiftCode (BinaryOp SwiftCode) -> Doc
bOp = OpData -> Doc
opDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC
  uOpPrec :: SwiftCode (UnaryOp SwiftCode) -> Int
uOpPrec = OpData -> Int
opPrec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC
  bOpPrec :: SwiftCode (BinaryOp SwiftCode) -> Int
bOpPrec = OpData -> Int
opPrec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC

instance VariableSym SwiftCode where
  type Variable SwiftCode = VarData
  var :: String -> VSType SwiftCode -> SVariable SwiftCode
var = forall (r :: * -> *).
RenderSym r =>
String -> VSType r -> SVariable r
G.var
  staticVar :: String -> VSType SwiftCode -> SVariable SwiftCode
staticVar = forall (r :: * -> *).
RenderSym r =>
String -> VSType r -> SVariable r
G.staticVar
  constant :: String -> VSType SwiftCode -> SVariable SwiftCode
constant = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var
  extVar :: String -> String -> VSType SwiftCode -> SVariable SwiftCode
extVar String
_ = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var
  self :: SVariable SwiftCode
self = forall (r :: * -> *). RenderSym r => SVariable r
CP.self
  classVar :: VSType SwiftCode -> SVariable SwiftCode -> SVariable SwiftCode
classVar = forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc -> Doc) -> VSType r -> SVariable r -> SVariable r
CP.classVar Doc -> Doc -> Doc
R.classVar
  extClassVar :: VSType SwiftCode -> SVariable SwiftCode -> SVariable SwiftCode
extClassVar = forall (r :: * -> *).
VariableSym r =>
VSType r -> SVariable r -> SVariable r
classVar
  objVar :: SVariable SwiftCode -> SVariable SwiftCode -> SVariable SwiftCode
objVar = forall (r :: * -> *).
RenderSym r =>
SVariable r -> SVariable r -> SVariable r
G.objVar
  objVarSelf :: SVariable SwiftCode -> SVariable SwiftCode
objVarSelf = forall (r :: * -> *). RenderSym r => SVariable r -> SVariable r
CP.objVarSelf
  arrayElem :: Integer -> SVariable SwiftCode -> SVariable SwiftCode
arrayElem Integer
i = forall (r :: * -> *).
RenderSym r =>
SValue r -> SVariable r -> SVariable r
G.arrayElem (forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
i)

instance VariableElim SwiftCode where
  variableName :: SwiftCode (Variable SwiftCode) -> String
variableName = VarData -> String
varName forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC
  variableType :: SwiftCode (Variable SwiftCode) -> SwiftCode (Type SwiftCode)
variableType = forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue VarData -> TypeData
varType

instance InternalVarElim SwiftCode where
  variableBind :: SwiftCode (Variable SwiftCode) -> Binding
variableBind = VarData -> Binding
varBind forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC
  variable :: SwiftCode (Variable SwiftCode) -> Doc
variable = VarData -> Doc
varDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC

instance RenderVariable SwiftCode where
  varFromData :: Binding -> String -> VSType SwiftCode -> Doc -> SVariable SwiftCode
varFromData Binding
b String
n VSType SwiftCode
t' Doc
d = do 
    SwiftCode TypeData
t <- VSType SwiftCode
t'
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues (Binding -> String -> TypeData -> Doc -> VarData
vard Binding
b String
n) SwiftCode TypeData
t (forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
d)

instance ValueSym SwiftCode where
  type Value SwiftCode = ValData
  valueType :: SwiftCode (Value SwiftCode) -> SwiftCode (Type SwiftCode)
valueType = forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ValData -> TypeData
valType

instance Argument SwiftCode where
  pointerArg :: SValue SwiftCode -> SValue SwiftCode
pointerArg = forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftArgVal

instance Literal SwiftCode where
  litTrue :: SValue SwiftCode
litTrue = forall (r :: * -> *). RenderSym r => SValue r
C.litTrue
  litFalse :: SValue SwiftCode
litFalse = forall (r :: * -> *). RenderSym r => SValue r
C.litFalse
  litChar :: Char -> SValue SwiftCode
litChar = forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc) -> Char -> SValue r
G.litChar Doc -> Doc
doubleQuotes
  litDouble :: Double -> SValue SwiftCode
litDouble = forall (r :: * -> *). RenderSym r => Double -> SValue r
G.litDouble
  litFloat :: Float -> SValue SwiftCode
litFloat = forall (r :: * -> *). RenderSym r => Float -> SValue r
swiftLitFloat
  litInt :: Integer -> SValue SwiftCode
litInt = forall (r :: * -> *). RenderSym r => Integer -> SValue r
G.litInt
  litString :: String -> SValue SwiftCode
litString = forall (r :: * -> *). RenderSym r => String -> SValue r
G.litString
  litArray :: VSType SwiftCode -> [SValue SwiftCode] -> SValue SwiftCode
litArray = forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc) -> VSType r -> [SValue r] -> SValue r
CP.litArray Doc -> Doc
brackets
  litList :: VSType SwiftCode -> [SValue SwiftCode] -> SValue SwiftCode
litList = forall (r :: * -> *).
Literal r =>
VSType r -> [SValue r] -> SValue r
litArray

instance MathConstant SwiftCode where
  pi :: SValue SwiftCode
pi = forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal forall (r :: * -> *). TypeSym r => VSType r
double Doc
swiftPi

instance VariableValue SwiftCode where
  valueOf :: SVariable SwiftCode -> SValue SwiftCode
valueOf = forall (r :: * -> *). RenderSym r => SVariable r -> SValue r
G.valueOf

instance CommandLineArgs SwiftCode where
  arg :: Integer -> SValue SwiftCode
arg Integer
n = forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
G.arg (forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
n) forall (r :: * -> *). CommandLineArgs r => SValue r
argsList
  argsList :: SValue SwiftCode
argsList = forall (r :: * -> *). RenderSym r => String -> SValue r
G.argsList (String
swiftCommLine String -> String -> String
`access` String
swiftArgs)
  argExists :: Integer -> SValue SwiftCode
argExists Integer
i = forall (r :: * -> *). List r => SValue r -> SValue r
listSize forall (r :: * -> *). CommandLineArgs r => SValue r
argsList forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?> forall (r :: * -> *). Literal r => Integer -> SValue r
litInt (forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i)

instance NumericExpression SwiftCode where
  #~ :: SValue SwiftCode -> SValue SwiftCode
(#~) = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr' forall (r :: * -> *). UnaryOpSym r => VSUnOp r
negateOp
  #/^ :: SValue SwiftCode -> SValue SwiftCode
(#/^) = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr forall (r :: * -> *). UnaryOpSym r => VSUnOp r
sqrtOp
  #| :: SValue SwiftCode -> SValue SwiftCode
(#|) = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr forall (r :: * -> *). UnaryOpSym r => VSUnOp r
absOp
  #+ :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(#+) = forall (r :: * -> *).
RenderSym r =>
(SValue r -> SValue r -> SValue r)
-> SValue r -> SValue r -> SValue r
swiftNumBinExpr (forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
plusOp)
  #- :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(#-) = forall (r :: * -> *).
RenderSym r =>
(SValue r -> SValue r -> SValue r)
-> SValue r -> SValue r -> SValue r
swiftNumBinExpr (forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
minusOp)
  #* :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(#*) = forall (r :: * -> *).
RenderSym r =>
(SValue r -> SValue r -> SValue r)
-> SValue r -> SValue r -> SValue r
swiftNumBinExpr (forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
multOp)
  #/ :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(#/) = forall (r :: * -> *).
RenderSym r =>
(SValue r -> SValue r -> SValue r)
-> SValue r -> SValue r -> SValue r
swiftNumBinExpr (forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
divideOp)
  #% :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(#%) = forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
moduloOp
  #^ :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(#^) SValue SwiftCode
v1' SValue SwiftCode
v2' = do
    SwiftCode ValData
v1 <- SValue SwiftCode
v1'
    SwiftCode ValData
v2 <- SValue SwiftCode
v2'
    let swiftPower :: CodeType
-> CodeType
-> VS (r (Value r))
-> VS (r (Value r))
-> VS (r (Value r))
swiftPower CodeType
Integer CodeType
Integer VS (r (Value r))
b VS (r (Value r))
e = forall (r :: * -> *).
RenderValue r =>
VSType r -> SValue r -> SValue r
cast forall (r :: * -> *). TypeSym r => VSType r
int forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr' forall (r :: * -> *). BinaryOpSym r => VSBinOp r
powerOp 
          (forall (r :: * -> *).
RenderValue r =>
VSType r -> SValue r -> SValue r
cast forall (r :: * -> *). TypeSym r => VSType r
double VS (r (Value r))
b) (forall (r :: * -> *).
RenderValue r =>
VSType r -> SValue r -> SValue r
cast forall (r :: * -> *). TypeSym r => VSType r
double VS (r (Value r))
e)
        swiftPower CodeType
_ CodeType
_ VS (r (Value r))
b VS (r (Value r))
e = forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr' forall (r :: * -> *). BinaryOpSym r => VSBinOp r
powerOp VS (r (Value r))
b VS (r (Value r))
e
    forall {r :: * -> *}.
RenderSym r =>
CodeType
-> CodeType
-> VS (r (Value r))
-> VS (r (Value r))
-> VS (r (Value r))
swiftPower (forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType SwiftCode ValData
v1) (forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType SwiftCode ValData
v2) (forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode ValData
v1) 
      (forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode ValData
v2)

  log :: SValue SwiftCode -> SValue SwiftCode
log = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr forall (r :: * -> *). UnaryOpSym r => VSUnOp r
logOp
  ln :: SValue SwiftCode -> SValue SwiftCode
ln = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr forall (r :: * -> *). UnaryOpSym r => VSUnOp r
lnOp
  exp :: SValue SwiftCode -> SValue SwiftCode
exp = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr forall (r :: * -> *). UnaryOpSym r => VSUnOp r
expOp
  sin :: SValue SwiftCode -> SValue SwiftCode
sin = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr forall (r :: * -> *). UnaryOpSym r => VSUnOp r
sinOp
  cos :: SValue SwiftCode -> SValue SwiftCode
cos = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr forall (r :: * -> *). UnaryOpSym r => VSUnOp r
cosOp
  tan :: SValue SwiftCode -> SValue SwiftCode
tan = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr forall (r :: * -> *). UnaryOpSym r => VSUnOp r
tanOp
  csc :: SValue SwiftCode -> SValue SwiftCode
csc = forall (r :: * -> *). RenderSym r => SValue r -> SValue r
G.csc
  sec :: SValue SwiftCode -> SValue SwiftCode
sec = forall (r :: * -> *). RenderSym r => SValue r -> SValue r
G.sec
  cot :: SValue SwiftCode -> SValue SwiftCode
cot = forall (r :: * -> *). RenderSym r => SValue r -> SValue r
G.cot
  arcsin :: SValue SwiftCode -> SValue SwiftCode
arcsin = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr forall (r :: * -> *). UnaryOpSym r => VSUnOp r
asinOp
  arccos :: SValue SwiftCode -> SValue SwiftCode
arccos = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr forall (r :: * -> *). UnaryOpSym r => VSUnOp r
acosOp
  arctan :: SValue SwiftCode -> SValue SwiftCode
arctan = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr forall (r :: * -> *). UnaryOpSym r => VSUnOp r
atanOp
  floor :: SValue SwiftCode -> SValue SwiftCode
floor = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr forall (r :: * -> *). UnaryOpSym r => VSUnOp r
floorOp
  ceil :: SValue SwiftCode -> SValue SwiftCode
ceil = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr forall (r :: * -> *). UnaryOpSym r => VSUnOp r
ceilOp

instance BooleanExpression SwiftCode where
  ?! :: SValue SwiftCode -> SValue SwiftCode
(?!) = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> VSType r -> SValue r -> SValue r
typeUnExpr forall (r :: * -> *). UnaryOpSym r => VSUnOp r
notOp forall (r :: * -> *). TypeSym r => VSType r
bool
  ?&& :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?&&) = forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> VSType r -> SValue r -> SValue r -> SValue r
typeBinExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
andOp forall (r :: * -> *). TypeSym r => VSType r
bool
  ?|| :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?||) = forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> VSType r -> SValue r -> SValue r -> SValue r
typeBinExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
orOp forall (r :: * -> *). TypeSym r => VSType r
bool

instance Comparison SwiftCode where
  ?< :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?<) = forall (r :: * -> *).
RenderSym r =>
(SValue r -> SValue r -> SValue r)
-> SValue r -> SValue r -> SValue r
swiftNumBinExpr (forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> VSType r -> SValue r -> SValue r -> SValue r
typeBinExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
lessOp forall (r :: * -> *). TypeSym r => VSType r
bool)
  ?<= :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?<=) = forall (r :: * -> *).
RenderSym r =>
(SValue r -> SValue r -> SValue r)
-> SValue r -> SValue r -> SValue r
swiftNumBinExpr (forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> VSType r -> SValue r -> SValue r -> SValue r
typeBinExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
lessEqualOp forall (r :: * -> *). TypeSym r => VSType r
bool)
  ?> :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?>) = forall (r :: * -> *).
RenderSym r =>
(SValue r -> SValue r -> SValue r)
-> SValue r -> SValue r -> SValue r
swiftNumBinExpr (forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> VSType r -> SValue r -> SValue r -> SValue r
typeBinExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
greaterOp forall (r :: * -> *). TypeSym r => VSType r
bool)
  ?>= :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?>=) = forall (r :: * -> *).
RenderSym r =>
(SValue r -> SValue r -> SValue r)
-> SValue r -> SValue r -> SValue r
swiftNumBinExpr (forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> VSType r -> SValue r -> SValue r -> SValue r
typeBinExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
greaterEqualOp forall (r :: * -> *). TypeSym r => VSType r
bool)
  ?== :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?==) = forall (r :: * -> *).
RenderSym r =>
(SValue r -> SValue r -> SValue r)
-> SValue r -> SValue r -> SValue r
swiftNumBinExpr (forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> VSType r -> SValue r -> SValue r -> SValue r
typeBinExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
equalOp forall (r :: * -> *). TypeSym r => VSType r
bool)
  ?!= :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
(?!=) = forall (r :: * -> *).
RenderSym r =>
(SValue r -> SValue r -> SValue r)
-> SValue r -> SValue r -> SValue r
swiftNumBinExpr (forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> VSType r -> SValue r -> SValue r -> SValue r
typeBinExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
notEqualOp forall (r :: * -> *). TypeSym r => VSType r
bool)

instance ValueExpression SwiftCode where
  inlineIf :: SValue SwiftCode
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
inlineIf = forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r -> SValue r
C.inlineIf

  funcAppMixedArgs :: MixedCall SwiftCode
funcAppMixedArgs = forall (r :: * -> *). RenderSym r => MixedCall r
G.funcAppMixedArgs
  selfFuncAppMixedArgs :: MixedCall SwiftCode
selfFuncAppMixedArgs = forall (r :: * -> *).
RenderSym r =>
Doc -> SVariable r -> MixedCall r
G.selfFuncAppMixedArgs Doc
dot forall (r :: * -> *). VariableSym r => SVariable r
self
  extFuncAppMixedArgs :: String -> MixedCall SwiftCode
extFuncAppMixedArgs = forall (r :: * -> *). RenderSym r => String -> MixedCall r
CP.extFuncAppMixedArgs
  libFuncAppMixedArgs :: String -> MixedCall SwiftCode
libFuncAppMixedArgs = forall (r :: * -> *). RenderSym r => String -> MixedCall r
C.libFuncAppMixedArgs
  newObjMixedArgs :: MixedCtorCall SwiftCode
newObjMixedArgs = forall (r :: * -> *). RenderSym r => MixedCall r
G.newObjMixedArgs String
""
  extNewObjMixedArgs :: MixedCall SwiftCode
extNewObjMixedArgs String
m VSType SwiftCode
tp [SValue SwiftCode]
vs NamedArgs SwiftCode
ns = do
    SwiftCode TypeData
t <- VSType SwiftCode
tp
    forall (r :: * -> *).
RenderValue r =>
Maybe String -> Maybe Doc -> MixedCall r
call (forall a. a -> Maybe a
Just String
m) forall a. Maybe a
Nothing (forall (r :: * -> *). TypeElim r => r (Type r) -> String
getTypeString SwiftCode TypeData
t) (forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode TypeData
t) [SValue SwiftCode]
vs NamedArgs SwiftCode
ns
  libNewObjMixedArgs :: MixedCall SwiftCode
libNewObjMixedArgs = forall (r :: * -> *). RenderSym r => MixedCall r
C.libNewObjMixedArgs

  lambda :: [SVariable SwiftCode] -> SValue SwiftCode -> SValue SwiftCode
lambda = forall (r :: * -> *).
RenderSym r =>
([r (Variable r)] -> r (Value r) -> Doc)
-> [SVariable r] -> SValue r -> SValue r
G.lambda forall (r :: * -> *).
RenderSym r =>
[r (Variable r)] -> r (Value r) -> Doc
swiftLambda

  notNull :: SValue SwiftCode -> SValue SwiftCode
notNull = forall (r :: * -> *). RenderSym r => String -> SValue r -> SValue r
CP.notNull String
swiftNil

instance RenderValue SwiftCode where
  inputFunc :: SValue SwiftCode
inputFunc = forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal forall (r :: * -> *). TypeSym r => VSType r
string Doc
empty
  printFunc :: SValue SwiftCode
printFunc = forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal forall (r :: * -> *). TypeSym r => VSType r
void Doc
empty
  printLnFunc :: SValue SwiftCode
printLnFunc = forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal forall (r :: * -> *). TypeSym r => VSType r
void Doc
empty
  printFileFunc :: SValue SwiftCode -> SValue SwiftCode
printFileFunc SValue SwiftCode
_ = forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal forall (r :: * -> *). TypeSym r => VSType r
void Doc
empty
  printFileLnFunc :: SValue SwiftCode -> SValue SwiftCode
printFileLnFunc SValue SwiftCode
_ = forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal forall (r :: * -> *). TypeSym r => VSType r
void Doc
empty
  
  cast :: VSType SwiftCode -> SValue SwiftCode -> SValue SwiftCode
cast = forall (r :: * -> *).
RenderSym r =>
VSType r -> SValue r -> SValue r
swiftCast

  call :: Maybe String -> Maybe Doc -> MixedCall SwiftCode
call Maybe String
l Maybe Doc
o String
n VSType SwiftCode
t [SValue SwiftCode]
as NamedArgs SwiftCode
ns = do
    String
mn <- forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' ValueState FileState
lensVStoFS FS String
getModuleName
    Map QualifiedName [ExceptionType]
mem <- VS (Map QualifiedName [ExceptionType])
getMethodExcMap
        -- If function being called throws exceptions, need to wrap call in try
    let f :: StateT ValueState Identity (SwiftCode ValData)
-> StateT ValueState Identity (SwiftCode ValData)
f = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => a -> k -> Map k a -> a
findWithDefault [] (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 forall a. a -> a
id else forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftTryVal 
    StateT ValueState Identity (SwiftCode ValData)
-> StateT ValueState Identity (SwiftCode ValData)
f forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
RenderSym r =>
Doc -> Maybe String -> Maybe Doc -> MixedCall r
G.call Doc
swiftNamedArgSep forall a. Maybe a
Nothing Maybe Doc
o String
n VSType SwiftCode
t [SValue SwiftCode]
as NamedArgs SwiftCode
ns
  
  valFromData :: Maybe Int -> VSType SwiftCode -> Doc -> SValue SwiftCode
valFromData Maybe Int
p VSType SwiftCode
t' Doc
d = do 
    SwiftCode TypeData
t <- VSType SwiftCode
t'
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues (Maybe Int -> TypeData -> Doc -> ValData
vd Maybe Int
p) SwiftCode TypeData
t (forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
d)
  
instance ValueElim SwiftCode where
  valuePrec :: SwiftCode (Value SwiftCode) -> Maybe Int
valuePrec = ValData -> Maybe Int
valPrec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC
  value :: SwiftCode (Value SwiftCode) -> Doc
value = ValData -> Doc
val forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC
  
instance InternalValueExp SwiftCode where
  objMethodCallMixedArgs' :: String
-> VSType SwiftCode
-> SValue SwiftCode
-> [SValue SwiftCode]
-> NamedArgs SwiftCode
-> SValue SwiftCode
objMethodCallMixedArgs' = forall (r :: * -> *).
RenderSym r =>
String
-> VSType r -> SValue r -> [SValue r] -> NamedArgs r -> SValue r
G.objMethodCall

instance FunctionSym SwiftCode where
  type Function SwiftCode = FuncData
  func :: String
-> VSType SwiftCode -> [SValue SwiftCode] -> VSFunction SwiftCode
func = forall (r :: * -> *).
RenderSym r =>
String -> VSType r -> [SValue r] -> VSFunction r
G.func
  objAccess :: SValue SwiftCode -> VSFunction SwiftCode -> SValue SwiftCode
objAccess = forall (r :: * -> *).
RenderSym r =>
SValue r -> VSFunction r -> SValue r
G.objAccess

instance GetSet SwiftCode where
  get :: SValue SwiftCode -> SVariable SwiftCode -> SValue SwiftCode
get = forall (r :: * -> *).
RenderSym r =>
SValue r -> SVariable r -> SValue r
G.get
  set :: SValue SwiftCode
-> SVariable SwiftCode -> SValue SwiftCode -> SValue SwiftCode
set = forall (r :: * -> *).
RenderSym r =>
SValue r -> SVariable r -> SValue r -> SValue r
G.set

instance List SwiftCode where
  listSize :: SValue SwiftCode -> SValue SwiftCode
listSize = forall (r :: * -> *). RenderSym r => SValue r -> SValue r
C.listSize
  listAdd :: SValue SwiftCode
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
listAdd = forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r -> SValue r
G.listAdd
  listAppend :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
listAppend = forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
G.listAppend
  listAccess :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
listAccess = forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
G.listAccess
  listSet :: SValue SwiftCode
-> SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
listSet = forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r -> SValue r
G.listSet
  indexOf :: SValue SwiftCode -> SValue SwiftCode -> SValue SwiftCode
indexOf = forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
swiftIndexOf
  
instance InternalList SwiftCode where
  listSlice' :: Maybe (SValue SwiftCode)
-> Maybe (SValue SwiftCode)
-> Maybe (SValue SwiftCode)
-> SVariable SwiftCode
-> SValue SwiftCode
-> MSBlock SwiftCode
listSlice' Maybe (SValue SwiftCode)
b Maybe (SValue SwiftCode)
e Maybe (SValue SwiftCode)
s SVariable SwiftCode
vn SValue SwiftCode
vo = forall (r :: * -> *).
RenderSym r =>
SVariable r
-> SValue r -> SValue r -> SValue r -> SValue r -> MSBlock r
swiftListSlice SVariable SwiftCode
vn SValue SwiftCode
vo (forall a. a -> Maybe a -> a
fromMaybe (forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
0) Maybe (SValue SwiftCode)
b) 
    (forall a. a -> Maybe a -> a
fromMaybe (forall (r :: * -> *). List r => SValue r -> SValue r
listSize SValue SwiftCode
vo) Maybe (SValue SwiftCode)
e) (forall a. a -> Maybe a -> a
fromMaybe (forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
1) Maybe (SValue SwiftCode)
s)

instance InternalGetSet SwiftCode where
  getFunc :: SVariable SwiftCode -> VSFunction SwiftCode
getFunc = forall (r :: * -> *). RenderSym r => SVariable r -> VSFunction r
G.getFunc
  setFunc :: VSType SwiftCode
-> SVariable SwiftCode -> SValue SwiftCode -> VSFunction SwiftCode
setFunc = forall (r :: * -> *).
RenderSym r =>
VSType r -> SVariable r -> SValue r -> VSFunction r
G.setFunc

instance InternalListFunc SwiftCode where
  listSizeFunc :: VSFunction SwiftCode
listSizeFunc = forall (r :: * -> *).
RenderFunction r =>
Doc -> VSType r -> VSFunction r
funcFromData (Doc -> Doc
R.func Doc
swiftListSize) forall (r :: * -> *). TypeSym r => VSType r
int
  listAddFunc :: SValue SwiftCode
-> SValue SwiftCode -> SValue SwiftCode -> VSFunction SwiftCode
listAddFunc SValue SwiftCode
_ SValue SwiftCode
i SValue SwiftCode
v = do
    SwiftCode ValData
f <- forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
swiftListAddFunc SValue SwiftCode
i SValue SwiftCode
v 
    forall (r :: * -> *).
RenderFunction r =>
Doc -> VSType r -> VSFunction r
funcFromData (Doc -> Doc
R.func (forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value SwiftCode ValData
f)) (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType SwiftCode ValData
f)
  listAppendFunc :: SValue SwiftCode -> VSFunction SwiftCode
listAppendFunc = forall (r :: * -> *).
RenderSym r =>
String -> SValue r -> VSFunction r
G.listAppendFunc String
swiftListAppend
  listAccessFunc :: VSType SwiftCode -> SValue SwiftCode -> VSFunction SwiftCode
listAccessFunc = forall (r :: * -> *).
RenderSym r =>
VSType r -> SValue r -> VSFunction r
CP.listAccessFunc
  listSetFunc :: SValue SwiftCode
-> SValue SwiftCode -> SValue SwiftCode -> VSFunction SwiftCode
listSetFunc = forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc -> Doc)
-> SValue r -> SValue r -> SValue r -> VSFunction r
CP.listSetFunc Doc -> Doc -> Doc
R.listSetFunc

instance ThunkSym SwiftCode where
  type Thunk SwiftCode = CommonThunk VS

instance ThunkAssign SwiftCode where
  thunkAssign :: SVariable SwiftCode -> VSThunk SwiftCode -> MSStatement SwiftCode
thunkAssign SVariable SwiftCode
v VSThunk SwiftCode
t = do
    String
iName <- MS String
genLoopIndex
    let
      i :: SVariable SwiftCode
i = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
iName forall (r :: * -> *). TypeSym r => VSType r
int
      dim :: StateT ValueState Identity (SwiftCode ValData)
dim = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ VSThunk SwiftCode
t forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (s :: * -> *).
(s ValData -> s ValData) -> CommonThunk s -> s ValData
commonThunkDim (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. SwiftCode a -> a
unSC forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). List r => SValue r -> SValue r
listSize forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) a. Applicative f => a -> f a
pure) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC
      loopInit :: MSStatement SwiftCode
loopInit = forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState ValueState
lensMStoVS (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. SwiftCode a -> a
unSC VSThunk SwiftCode
t) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (s :: * -> *) a.
(CommonThunk s -> a) -> (CommonThunk s -> a) -> CommonThunk s -> a
commonThunkElim
        (forall a b. a -> b -> a
const forall (r :: * -> *). RenderStatement r => MSStatement r
emptyStmt) (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
assign SVariable SwiftCode
v forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
(TypeElim r, Literal r) =>
VSType r -> SValue r
litZero forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType SVariable SwiftCode
v)
      loopBody :: MSStatement SwiftCode
loopBody = forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState ValueState
lensMStoVS (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. SwiftCode a -> a
unSC VSThunk SwiftCode
t) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (s :: * -> *) a.
(CommonThunk s -> a) -> (CommonThunk s -> a) -> CommonThunk s -> a
commonThunkElim
        (forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
valStmt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *).
List r =>
SValue r -> SValue r -> SValue r -> SValue r
listSet (forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable SwiftCode
v) (forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable SwiftCode
i) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *).
VectorExpression r =>
SValue r -> VSThunk r -> SValue r
vecIndex (forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable SwiftCode
i) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure)
        ((SVariable SwiftCode
v &+=) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *).
VectorExpression r =>
SValue r -> VSThunk r -> SValue r
vecIndex (forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable SwiftCode
i) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure)
    forall (r :: * -> *).
StatementSym r =>
[MSStatement r] -> MSStatement r
multi [MSStatement SwiftCode
loopInit,
      forall (r :: * -> *).
ControlStatement r =>
SVariable r
-> SValue r -> SValue r -> SValue r -> MSBody r -> MSStatement r
forRange SVariable SwiftCode
i (forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
0) StateT ValueState Identity (SwiftCode ValData)
dim (forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
1) forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). BodySym r => [MSBlock r] -> MSBody r
body [forall (r :: * -> *). BlockSym r => [MSStatement r] -> MSBlock r
block [MSStatement SwiftCode
loopBody]]]

instance VectorType SwiftCode where
  vecType :: VSType SwiftCode -> VSType SwiftCode
vecType = forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listType

instance VectorDecl SwiftCode where
  vecDec :: Integer -> SVariable SwiftCode -> MSStatement SwiftCode
vecDec = forall (r :: * -> *).
DeclStatement r =>
Integer -> SVariable r -> MSStatement r
listDec
  vecDecDef :: SVariable SwiftCode -> [SValue SwiftCode] -> MSStatement SwiftCode
vecDecDef = forall (r :: * -> *).
DeclStatement r =>
SVariable r -> [SValue r] -> MSStatement r
listDecDef

instance VectorThunk SwiftCode where
  vecThunk :: SVariable SwiftCode -> VSThunk SwiftCode
vecThunk = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (s :: * -> *). s ValData -> CommonThunk s
pureValue forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. SwiftCode a -> a
unSC forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf

instance VectorExpression SwiftCode where
  vecScale :: SValue SwiftCode -> VSThunk SwiftCode -> VSThunk SwiftCode
vecScale SValue SwiftCode
k = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a -> b) -> a -> b
$ forall (s :: * -> *).
(s ValData -> s ValData) -> CommonThunk s -> CommonThunk s
vectorize (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. SwiftCode a -> a
unSC forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SValue SwiftCode
k #*) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) a. Applicative f => a -> f a
pure)
  vecAdd :: VSThunk SwiftCode -> VSThunk SwiftCode -> VSThunk SwiftCode
vecAdd = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a b. (a -> b) -> a -> b
$ forall (s :: * -> *).
(s ValData -> s ValData -> s ValData)
-> CommonThunk s -> CommonThunk s -> CommonThunk s
vectorize2 (\StateT ValueState Identity ValData
v1 StateT ValueState Identity ValData
v2 -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. SwiftCode a -> a
unSC forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) a. Applicative f => a -> f a
pure StateT ValueState Identity ValData
v1 forall (r :: * -> *).
NumericExpression r =>
SValue r -> SValue r -> SValue r
#+ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) a. Applicative f => a -> f a
pure StateT ValueState Identity ValData
v2)
  vecIndex :: SValue SwiftCode -> VSThunk SwiftCode -> SValue SwiftCode
vecIndex SValue SwiftCode
i = (forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (s :: * -> *).
(s ValData -> s ValData) -> CommonThunk s -> s ValData
commonVecIndex (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. SwiftCode a -> a
unSC forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (r :: * -> *). List r => SValue r -> SValue r -> SValue r
listAccess SValue SwiftCode
i forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) a. Applicative f => a -> f a
pure) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC)
  vecDot :: VSThunk SwiftCode -> VSThunk SwiftCode -> VSThunk SwiftCode
vecDot = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (s :: * -> *). CommonThunk s -> CommonThunk s
sumComponents forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
<$> forall (s :: * -> *).
(s ValData -> s ValData -> s ValData)
-> CommonThunk s -> CommonThunk s -> CommonThunk s
vectorize2 (\StateT ValueState Identity ValData
v1 StateT ValueState Identity ValData
v2 -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. SwiftCode a -> a
unSC forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) a. Applicative f => a -> f a
pure StateT ValueState Identity ValData
v1 forall (r :: * -> *).
NumericExpression r =>
SValue r -> SValue r -> SValue r
#* forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) a. Applicative f => a -> f a
pure StateT ValueState Identity ValData
v2)

instance RenderFunction SwiftCode where
  funcFromData :: Doc -> VSType SwiftCode -> VSFunction SwiftCode
funcFromData Doc
d = forall a b s. (a -> b) -> State s a -> State s b
onStateValue (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 (Function SwiftCode) -> SwiftCode (Type SwiftCode)
functionType = forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue FuncData -> TypeData
fType
  function :: SwiftCode (Function SwiftCode) -> Doc
function = FuncData -> Doc
funcDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC

instance InternalAssignStmt SwiftCode where
  multiAssign :: [SVariable SwiftCode]
-> [SValue SwiftCode] -> MSStatement SwiftCode
multiAssign = forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc) -> [SVariable r] -> [SValue r] -> MSStatement r
CP.multiAssign Doc -> Doc
parens

instance InternalIOStmt SwiftCode where
  printSt :: Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MSStatement SwiftCode
printSt = Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MSStatement SwiftCode
swiftPrint
  
instance InternalControlStmt SwiftCode where
  multiReturn :: [SValue SwiftCode] -> MSStatement SwiftCode
multiReturn = forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc) -> [SValue r] -> MSStatement r
CP.multiReturn Doc -> Doc
parens

instance RenderStatement SwiftCode where
  stmt :: MSStatement SwiftCode -> MSStatement SwiftCode
stmt = forall (r :: * -> *). RenderSym r => MSStatement r -> MSStatement r
G.stmt
  loopStmt :: MSStatement SwiftCode -> MSStatement SwiftCode
loopStmt = forall (r :: * -> *). RenderSym r => MSStatement r -> MSStatement r
G.loopStmt

  emptyStmt :: MSStatement SwiftCode
emptyStmt = forall (r :: * -> *). RenderSym r => MSStatement r
G.emptyStmt
  
  stmtFromData :: Doc -> Terminator -> MSStatement SwiftCode
stmtFromData Doc
d Terminator
t = forall a s. a -> State s a
toState forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc
d, Terminator
t)

instance StatementElim SwiftCode where
  statement :: SwiftCode (Statement SwiftCode) -> Doc
statement = forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC
  statementTerm :: SwiftCode (Statement SwiftCode) -> Terminator
statementTerm = forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC

instance StatementSym SwiftCode where
  type Statement SwiftCode = (Doc, Terminator)
  valStmt :: SValue SwiftCode -> MSStatement SwiftCode
valStmt = forall (r :: * -> *).
RenderSym r =>
Terminator -> SValue r -> MSStatement r
G.valStmt Terminator
Empty
  multi :: [MSStatement SwiftCode] -> MSStatement SwiftCode
multi = forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList (forall (m :: * -> *) a b. Monad m => ([a] -> b) -> [m a] -> m b
onCodeList [(Doc, Terminator)] -> (Doc, Terminator)
R.multiStmt)

instance AssignStatement SwiftCode where
  assign :: SVariable SwiftCode -> SValue SwiftCode -> MSStatement SwiftCode
assign = forall (r :: * -> *).
RenderSym r =>
Terminator -> SVariable r -> SValue r -> MSStatement r
G.assign Terminator
Empty
  &-= :: SVariable SwiftCode -> SValue SwiftCode -> MSStatement SwiftCode
(&-=) = forall (r :: * -> *).
RenderSym r =>
Terminator -> SVariable r -> SValue r -> MSStatement r
G.subAssign Terminator
Empty
  &+= :: SVariable SwiftCode -> SValue SwiftCode -> MSStatement SwiftCode
(&+=) = forall (r :: * -> *).
RenderSym r =>
SVariable r -> SValue r -> MSStatement r
G.increment
  &++ :: SVariable SwiftCode -> MSStatement SwiftCode
(&++) = forall (r :: * -> *). RenderSym r => SVariable r -> MSStatement r
M.increment1
  &-- :: SVariable SwiftCode -> MSStatement SwiftCode
(&--) = forall (r :: * -> *). RenderSym r => SVariable r -> MSStatement r
M.decrement1

instance DeclStatement SwiftCode where
  varDec :: SVariable SwiftCode -> MSStatement SwiftCode
varDec = Doc -> SVariable SwiftCode -> MSStatement SwiftCode
swiftVarDec Doc
swiftVar
  varDecDef :: SVariable SwiftCode -> SValue SwiftCode -> MSStatement SwiftCode
varDecDef = forall (r :: * -> *).
RenderSym r =>
Terminator -> SVariable r -> SValue r -> MSStatement r
C.varDecDef Terminator
Empty
  listDec :: Integer -> SVariable SwiftCode -> MSStatement SwiftCode
listDec Integer
_ = forall (r :: * -> *). RenderSym r => SVariable r -> MSStatement r
CP.listDec
  listDecDef :: SVariable SwiftCode -> [SValue SwiftCode] -> MSStatement SwiftCode
listDecDef = forall (r :: * -> *).
RenderSym r =>
SVariable r -> [SValue r] -> MSStatement r
CP.listDecDef
  arrayDec :: Integer -> SVariable SwiftCode -> MSStatement SwiftCode
arrayDec = forall (r :: * -> *).
DeclStatement r =>
Integer -> SVariable r -> MSStatement r
listDec
  arrayDecDef :: SVariable SwiftCode -> [SValue SwiftCode] -> MSStatement SwiftCode
arrayDecDef = forall (r :: * -> *).
DeclStatement r =>
SVariable r -> [SValue r] -> MSStatement r
listDecDef
  objDecDef :: SVariable SwiftCode -> SValue SwiftCode -> MSStatement SwiftCode
objDecDef = forall (r :: * -> *).
DeclStatement r =>
SVariable r -> SValue r -> MSStatement r
varDecDef
  objDecNew :: SVariable SwiftCode -> [SValue SwiftCode] -> MSStatement SwiftCode
objDecNew = forall (r :: * -> *).
RenderSym r =>
SVariable r -> [SValue r] -> MSStatement r
G.objDecNew
  extObjDecNew :: String
-> SVariable SwiftCode
-> [SValue SwiftCode]
-> MSStatement SwiftCode
extObjDecNew = forall (r :: * -> *).
RenderSym r =>
String -> SVariable r -> [SValue r] -> MSStatement r
C.extObjDecNew
  constDecDef :: SVariable SwiftCode -> SValue SwiftCode -> MSStatement SwiftCode
constDecDef SVariable SwiftCode
vr SValue SwiftCode
vl' = do
    SwiftCode (Doc, Terminator)
vdec <- Doc -> SVariable SwiftCode -> MSStatement SwiftCode
swiftVarDec Doc
swiftConst SVariable SwiftCode
vr
    SwiftCode ValData
vl <- forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState ValueState
lensMStoVS SValue SwiftCode
vl' 
    forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmtNoEnd forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). StatementElim r => r (Statement r) -> Doc
RC.statement SwiftCode (Doc, Terminator)
vdec Doc -> Doc -> Doc
<+> Doc
equals Doc -> Doc -> Doc
<+> forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value SwiftCode ValData
vl
  funcDecDef :: SVariable SwiftCode
-> [SVariable SwiftCode]
-> MSBody SwiftCode
-> MSStatement SwiftCode
funcDecDef = forall (r :: * -> *).
RenderSym r =>
SVariable r -> [SVariable r] -> MSBody r -> MSStatement r
CP.funcDecDef

instance IOStatement SwiftCode where
  print :: SValue SwiftCode -> MSStatement SwiftCode
print      = forall (r :: * -> *).
RenderSym r =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MSStatement r
swiftOut Bool
False forall a. Maybe a
Nothing forall (r :: * -> *). RenderValue r => SValue r
printFunc
  printLn :: SValue SwiftCode -> MSStatement SwiftCode
printLn    = forall (r :: * -> *).
RenderSym r =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MSStatement r
swiftOut Bool
True  forall a. Maybe a
Nothing forall (r :: * -> *). RenderValue r => SValue r
printLnFunc
  printStr :: String -> MSStatement SwiftCode
printStr   = forall (r :: * -> *).
RenderSym r =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MSStatement r
swiftOut Bool
False forall a. Maybe a
Nothing forall (r :: * -> *). RenderValue r => SValue r
printFunc   forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). Literal r => String -> SValue r
litString
  printStrLn :: String -> MSStatement SwiftCode
printStrLn = forall (r :: * -> *).
RenderSym r =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MSStatement r
swiftOut Bool
True  forall a. Maybe a
Nothing forall (r :: * -> *). RenderValue r => SValue r
printLnFunc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). Literal r => String -> SValue r
litString

  printFile :: SValue SwiftCode -> SValue SwiftCode -> MSStatement SwiftCode
printFile SValue SwiftCode
f      = forall (r :: * -> *).
RenderSym r =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MSStatement r
swiftOut Bool
False (forall a. a -> Maybe a
Just SValue SwiftCode
f) (forall (r :: * -> *). RenderValue r => SValue r -> SValue r
printFileFunc SValue SwiftCode
f)
  printFileLn :: SValue SwiftCode -> SValue SwiftCode -> MSStatement SwiftCode
printFileLn SValue SwiftCode
f    = forall (r :: * -> *).
RenderSym r =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MSStatement r
swiftOut Bool
True  (forall a. a -> Maybe a
Just SValue SwiftCode
f) (forall (r :: * -> *). RenderValue r => SValue r -> SValue r
printFileLnFunc SValue SwiftCode
f)
  printFileStr :: SValue SwiftCode -> String -> MSStatement SwiftCode
printFileStr SValue SwiftCode
f   = forall (r :: * -> *).
RenderSym r =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MSStatement r
swiftOut Bool
False (forall a. a -> Maybe a
Just SValue SwiftCode
f) (forall (r :: * -> *). RenderValue r => SValue r -> SValue r
printFileFunc SValue SwiftCode
f)   forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). Literal r => String -> SValue r
litString
  printFileStrLn :: SValue SwiftCode -> String -> MSStatement SwiftCode
printFileStrLn SValue SwiftCode
f = forall (r :: * -> *).
RenderSym r =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MSStatement r
swiftOut Bool
True  (forall a. a -> Maybe a
Just SValue SwiftCode
f) (forall (r :: * -> *). RenderValue r => SValue r -> SValue r
printFileLnFunc SValue SwiftCode
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). Literal r => String -> SValue r
litString

  getInput :: SVariable SwiftCode -> MSStatement SwiftCode
getInput SVariable SwiftCode
v = SVariable SwiftCode
v forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= SVariable SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftInput SVariable SwiftCode
v forall (r :: * -> *). RenderSym r => SValue r
swiftReadLineFunc
  discardInput :: MSStatement SwiftCode
discardInput = forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
valStmt forall (r :: * -> *). RenderSym r => SValue r
swiftReadLineFunc
  getFileInput :: SValue SwiftCode -> SVariable SwiftCode -> MSStatement SwiftCode
getFileInput SValue SwiftCode
_ SVariable SwiftCode
v = do
    Integer
wi <- MS Integer
getWordIndex
    Integer
li <- MS Integer
getLineIndex
    forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
incrementWord
    SVariable SwiftCode
v forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= SVariable SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftInput SVariable SwiftCode
v
      (forall (r :: * -> *). List r => SValue r -> SValue r -> SValue r
listAccess (forall (r :: * -> *). List r => SValue r -> SValue r -> SValue r
listAccess SValue SwiftCode
swiftContentsVal (forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
li)) (forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
wi))
  discardFileInput :: SValue SwiftCode -> MSStatement SwiftCode
discardFileInput SValue SwiftCode
_ = forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
incrementWord forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (r :: * -> *). RenderStatement r => MSStatement r
emptyStmt

  openFileR :: SVariable SwiftCode -> SValue SwiftCode -> MSStatement SwiftCode
openFileR SVariable SwiftCode
v SValue SwiftCode
pth = forall (r :: * -> *).
StatementSym r =>
[MSStatement r] -> MSStatement r
multi [forall (r :: * -> *).
RenderSym r =>
(SValue r -> VSType r -> SValue r)
-> SVariable r -> SValue r -> MSStatement r
CP.openFileR forall (r :: * -> *).
RenderSym r =>
SValue r -> VSType r -> SValue r
swiftOpenFile SVariable SwiftCode
v SValue SwiftCode
pth, 
    forall (r :: * -> *).
DeclStatement r =>
SVariable r -> MSStatement r
varDec SVariable SwiftCode
swiftContentsVar, forall (r :: * -> *).
RenderSym r =>
SVariable r -> SValue r -> MSStatement r
swiftReadFile SVariable SwiftCode
swiftContentsVar (forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable SwiftCode
v)]
  openFileW :: SVariable SwiftCode -> SValue SwiftCode -> MSStatement SwiftCode
openFileW = forall (r :: * -> *).
RenderSym r =>
Bool -> SVariable r -> SValue r -> MSStatement r
swiftOpenFileWA Bool
False
  openFileA :: SVariable SwiftCode -> SValue SwiftCode -> MSStatement SwiftCode
openFileA = forall (r :: * -> *).
RenderSym r =>
Bool -> SVariable r -> SValue r -> MSStatement r
swiftOpenFileWA Bool
True
  closeFile :: SValue SwiftCode -> MSStatement SwiftCode
closeFile = forall (r :: * -> *). RenderSym r => SValue r -> MSStatement r
swiftCloseFile

  getFileInputLine :: SValue SwiftCode -> SVariable SwiftCode -> MSStatement SwiftCode
getFileInputLine SValue SwiftCode
_ SVariable SwiftCode
v = do
    Integer
wi <- MS Integer
getWordIndex
    Integer
li <- MS Integer
getLineIndex 
    forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
incrementLine
    SwiftCode Doc
slc <- forall (r :: * -> *).
InternalList r =>
SVariable r
-> SValue r
-> Maybe (SValue r)
-> Maybe (SValue r)
-> Maybe (SValue r)
-> MSBlock r
listSlice SVariable SwiftCode
swiftLineVar (forall (r :: * -> *). List r => SValue r -> SValue r -> SValue r
listAccess SValue SwiftCode
swiftContentsVal (forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
li)) 
      (forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
wi) forall a. Maybe a
Nothing forall a. Maybe a
Nothing
    forall (r :: * -> *).
StatementSym r =>
[MSStatement r] -> MSStatement r
multi [forall (r :: * -> *).
DeclStatement r =>
SVariable r -> MSStatement r
varDec SVariable SwiftCode
swiftLineVar, forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmtNoEnd forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). BlockElim r => r (Block r) -> Doc
RC.block SwiftCode Doc
slc, 
      SVariable SwiftCode
v forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= forall (r :: * -> *). RenderSym r => Char -> SValue r -> SValue r
swiftJoinedFunc Char
' ' SValue SwiftCode
swiftLineVal]
  discardFileLine :: SValue SwiftCode -> MSStatement SwiftCode
discardFileLine SValue SwiftCode
_ = forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
incrementLine forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (r :: * -> *). RenderStatement r => MSStatement r
emptyStmt
  getFileInputAll :: SValue SwiftCode -> SVariable SwiftCode -> MSStatement SwiftCode
getFileInputAll SValue SwiftCode
_ SVariable SwiftCode
v = do
    Integer
li <- MS Integer
getLineIndex
    let l :: SVariable SwiftCode
l = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
"l" (forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listType forall (r :: * -> *). TypeSym r => VSType r
string)
    SwiftCode Doc
slc <- forall (r :: * -> *).
InternalList r =>
SVariable r
-> SValue r
-> Maybe (SValue r)
-> Maybe (SValue r)
-> Maybe (SValue r)
-> MSBlock r
listSlice SVariable SwiftCode
swiftContentsVar SValue SwiftCode
swiftContentsVal 
      (forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). Literal r => Integer -> SValue r
litInt (Integer
liforall a. Num a => a -> a -> a
+Integer
1)) forall a. Maybe a
Nothing forall a. Maybe a
Nothing
    forall (r :: * -> *).
StatementSym r =>
[MSStatement r] -> MSStatement r
multi [forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmtNoEnd forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). BlockElim r => r (Block r) -> Doc
RC.block SwiftCode Doc
slc, 
      SVariable SwiftCode
v forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
swiftMapFunc SValue SwiftCode
swiftContentsVal 
        (forall (r :: * -> *).
ValueExpression r =>
[SVariable r] -> SValue r -> SValue r
lambda [SVariable SwiftCode
l] (forall (r :: * -> *). RenderSym r => Char -> SValue r -> SValue r
swiftJoinedFunc Char
' ' (forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable SwiftCode
l)))]

instance StringStatement SwiftCode where
  stringSplit :: Char
-> SVariable SwiftCode -> SValue SwiftCode -> MSStatement SwiftCode
stringSplit Char
d SVariable SwiftCode
vnew SValue SwiftCode
s = SVariable SwiftCode
vnew forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= forall (r :: * -> *). RenderSym r => Char -> SValue r -> SValue r
swiftSplitFunc Char
d SValue SwiftCode
s

  stringListVals :: [SVariable SwiftCode] -> SValue SwiftCode -> MSStatement SwiftCode
stringListVals = forall (r :: * -> *).
RenderSym r =>
[SVariable r] -> SValue r -> MSStatement r
M.stringListVals
  stringListLists :: [SVariable SwiftCode] -> SValue SwiftCode -> MSStatement SwiftCode
stringListLists = forall (r :: * -> *).
RenderSym r =>
[SVariable r] -> SValue r -> MSStatement r
M.stringListLists

instance FuncAppStatement SwiftCode where
  inOutCall :: InOutCall SwiftCode
inOutCall = forall (r :: * -> *).
RenderSym r =>
(String -> VSType r -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MSStatement r
CP.inOutCall forall (r :: * -> *). ValueExpression r => PosCall r
funcApp
  selfInOutCall :: InOutCall SwiftCode
selfInOutCall = forall (r :: * -> *).
RenderSym r =>
(String -> VSType r -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MSStatement r
CP.inOutCall forall (r :: * -> *). ValueExpression r => PosCall r
selfFuncApp
  extInOutCall :: String -> InOutCall SwiftCode
extInOutCall String
m = forall (r :: * -> *).
RenderSym r =>
(String -> VSType r -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MSStatement r
CP.inOutCall (forall (r :: * -> *). ValueExpression r => String -> PosCall r
extFuncApp String
m)

instance CommentStatement SwiftCode where
  comment :: String -> MSStatement SwiftCode
comment = forall (r :: * -> *). RenderSym r => Doc -> String -> MSStatement r
G.comment Doc
commentStart

instance ControlStatement SwiftCode where
  break :: MSStatement SwiftCode
break = forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmtNoEnd Doc
R.break
  continue :: MSStatement SwiftCode
continue = forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmtNoEnd Doc
R.continue

  returnStmt :: SValue SwiftCode -> MSStatement SwiftCode
returnStmt = forall (r :: * -> *).
RenderSym r =>
Terminator -> SValue r -> MSStatement r
G.returnStmt Terminator
Empty
  
  throw :: String -> MSStatement SwiftCode
throw String
msg = do
    forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
setThrowUsed
    forall (r :: * -> *).
RenderSym r =>
(r (Value r) -> Doc) -> Terminator -> String -> MSStatement r
G.throw forall (r :: * -> *). RenderSym r => r (Value r) -> Doc
swiftThrowDoc Terminator
Empty String
msg

  ifCond :: [(SValue SwiftCode, MSBody SwiftCode)]
-> MSBody SwiftCode -> MSStatement SwiftCode
ifCond = forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc)
-> Doc
-> OptionalSpace
-> Doc
-> Doc
-> [(SValue r, MSBody r)]
-> MSBody r
-> MSStatement r
G.ifCond forall a. a -> a
id Doc
bodyStart OptionalSpace
G.defaultOptSpace Doc
elseIfLabel Doc
bodyEnd
  switch :: SValue SwiftCode
-> [(SValue SwiftCode, MSBody SwiftCode)]
-> MSBody SwiftCode
-> MSStatement SwiftCode
switch = forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc)
-> MSStatement r
-> SValue r
-> [(SValue r, MSBody r)]
-> MSBody r
-> MSStatement r
C.switch (Doc
space <>) forall (r :: * -> *). RenderStatement r => MSStatement r
emptyStmt

  ifExists :: SValue SwiftCode
-> MSBody SwiftCode -> MSBody SwiftCode -> MSStatement SwiftCode
ifExists = forall (r :: * -> *).
RenderSym r =>
SValue r -> MSBody r -> MSBody r -> MSStatement r
M.ifExists

  for :: MSStatement SwiftCode
-> SValue SwiftCode
-> MSStatement SwiftCode
-> MSBody SwiftCode
-> MSStatement SwiftCode
for MSStatement SwiftCode
_ SValue SwiftCode
_ MSStatement SwiftCode
_ MSBody SwiftCode
_ = forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String -> String
CP.forLoopError String
swiftName
  forRange :: SVariable SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
-> SValue SwiftCode
-> MSBody SwiftCode
-> MSStatement SwiftCode
forRange SVariable SwiftCode
i SValue SwiftCode
initv SValue SwiftCode
finalv SValue SwiftCode
stepv = forall (r :: * -> *).
ControlStatement r =>
SVariable r -> SValue r -> MSBody r -> MSStatement r
forEach SVariable SwiftCode
i (forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r -> SValue r
swiftStrideFunc SValue SwiftCode
initv SValue SwiftCode
finalv SValue SwiftCode
stepv)
  forEach :: SVariable SwiftCode
-> SValue SwiftCode -> MSBody SwiftCode -> MSStatement SwiftCode
forEach = forall (r :: * -> *).
RenderSym r =>
SVariable r -> SValue r -> MSBody r -> MSStatement r
swiftForEach
  while :: SValue SwiftCode -> MSBody SwiftCode -> MSStatement SwiftCode
while = forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc) -> Doc -> Doc -> SValue r -> MSBody r -> MSStatement r
C.while forall a. a -> a
id Doc
bodyStart Doc
bodyEnd

  tryCatch :: MSBody SwiftCode -> MSBody SwiftCode -> MSStatement SwiftCode
tryCatch = forall (r :: * -> *).
RenderSym r =>
(r (Body r) -> r (Body r) -> Doc)
-> MSBody r -> MSBody r -> MSStatement r
G.tryCatch forall (r :: * -> *).
RenderSym r =>
r (Body r) -> r (Body r) -> Doc
swiftTryCatch

instance StatePattern SwiftCode where 
  checkState :: String
-> [(SValue SwiftCode, MSBody SwiftCode)]
-> MSBody SwiftCode
-> MSStatement SwiftCode
checkState = forall (r :: * -> *).
RenderSym r =>
String -> [(SValue r, MSBody r)] -> MSBody r -> MSStatement r
M.checkState

instance ObserverPattern SwiftCode where
  notifyObservers :: VSFunction SwiftCode -> VSType SwiftCode -> MSStatement SwiftCode
notifyObservers = forall (r :: * -> *).
RenderSym r =>
VSFunction r -> VSType r -> MSStatement r
M.notifyObservers'

instance StrategyPattern SwiftCode where
  runStrategy :: String
-> [(String, MSBody SwiftCode)]
-> Maybe (SValue SwiftCode)
-> Maybe (SVariable SwiftCode)
-> MSBlock SwiftCode
runStrategy = forall (r :: * -> *).
(RenderSym r, Monad r) =>
String
-> [(String, MSBody r)]
-> Maybe (SValue r)
-> Maybe (SVariable r)
-> MS (r Doc)
M.runStrategy

instance ScopeSym SwiftCode where
  type Scope SwiftCode = Doc
  private :: SwiftCode (Scope SwiftCode)
private = forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
R.private
  public :: SwiftCode (Scope SwiftCode)
public = forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
empty

instance RenderScope SwiftCode where
  scopeFromData :: ScopeTag -> Doc -> SwiftCode (Scope SwiftCode)
scopeFromData ScopeTag
_ = forall (r :: * -> *) a. Monad r => a -> r a
toCode
  
instance ScopeElim SwiftCode where
  scope :: SwiftCode (Scope SwiftCode) -> Doc
scope = forall a. SwiftCode a -> a
unSC

instance MethodTypeSym SwiftCode where
  type MethodType SwiftCode = TypeData
  mType :: VSType SwiftCode -> MSMthdType SwiftCode
mType = forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState ValueState
lensMStoVS 
  construct :: String -> MSMthdType SwiftCode
construct = forall (r :: * -> *). RenderSym r => String -> MS (r (Type r))
G.construct

instance ParameterSym SwiftCode where
  type Parameter SwiftCode = ParamData
  param :: SVariable SwiftCode -> MSParameter SwiftCode
param = forall (r :: * -> *).
RenderSym r =>
(r (Variable r) -> Doc) -> SVariable r -> MSParameter r
G.param (forall (r :: * -> *). RenderSym r => Doc -> r (Variable r) -> Doc
swiftParam Doc
empty)
  pointerParam :: SVariable SwiftCode -> MSParameter SwiftCode
pointerParam = forall (r :: * -> *).
RenderSym r =>
(r (Variable r) -> Doc) -> SVariable r -> MSParameter r
G.param (forall (r :: * -> *). RenderSym r => Doc -> r (Variable r) -> Doc
swiftParam Doc
swiftInOut)

instance RenderParam SwiftCode where
  paramFromData :: SVariable SwiftCode -> Doc -> MSParameter SwiftCode
paramFromData SVariable SwiftCode
v' Doc
d = do 
    SwiftCode VarData
v <- forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState ValueState
lensMStoVS SVariable SwiftCode
v'
    forall a s. a -> State s a
toState forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues VarData -> Doc -> ParamData
pd SwiftCode VarData
v (forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
d)

instance ParamElim SwiftCode where
  parameterName :: SwiftCode (Parameter SwiftCode) -> String
parameterName = forall (r :: * -> *). VariableElim r => r (Variable r) -> String
variableName forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ParamData -> VarData
paramVar
  parameterType :: SwiftCode (Parameter SwiftCode) -> SwiftCode (Type SwiftCode)
parameterType = forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ParamData -> VarData
paramVar
  parameter :: SwiftCode (Parameter SwiftCode) -> Doc
parameter = ParamData -> Doc
paramDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC

instance MethodSym SwiftCode where
  type Method SwiftCode = MethodData
  method :: String
-> SwiftCode (Scope SwiftCode)
-> SwiftCode (Permanence SwiftCode)
-> VSType SwiftCode
-> [MSParameter SwiftCode]
-> MSBody SwiftCode
-> SMethod SwiftCode
method = forall (r :: * -> *).
RenderSym r =>
String
-> r (Scope r)
-> r (Permanence r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
G.method
  getMethod :: SVariable SwiftCode -> SMethod SwiftCode
getMethod = forall (r :: * -> *). RenderSym r => SVariable r -> SMethod r
G.getMethod
  setMethod :: SVariable SwiftCode -> SMethod SwiftCode
setMethod = forall (r :: * -> *). RenderSym r => SVariable r -> SMethod r
G.setMethod
  constructor :: [MSParameter SwiftCode]
-> NamedArgs SwiftCode -> MSBody SwiftCode -> SMethod SwiftCode
constructor = forall (r :: * -> *).
RenderSym r =>
[MSParameter r] -> Initializers r -> MSBody r -> SMethod r
swiftConstructor

  docMain :: MSBody SwiftCode -> SMethod SwiftCode
docMain = forall (r :: * -> *). MethodSym r => MSBody r -> SMethod r
mainFunction
 
  function :: String
-> SwiftCode (Scope SwiftCode)
-> VSType SwiftCode
-> [MSParameter SwiftCode]
-> MSBody SwiftCode
-> SMethod SwiftCode
function = forall (r :: * -> *).
RenderSym r =>
String
-> r (Scope r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
G.function
  mainFunction :: MSBody SwiftCode -> SMethod SwiftCode
mainFunction = forall (r :: * -> *). RenderSym r => MSBody r -> SMethod r
CP.mainBody

  docFunc :: String
-> [String]
-> Maybe String
-> SMethod SwiftCode
-> SMethod SwiftCode
docFunc = forall (r :: * -> *).
RenderSym r =>
FuncDocRenderer
-> String -> [String] -> Maybe String -> SMethod r -> SMethod r
G.docFunc FuncDocRenderer
swiftFunctionDoc

  inOutMethod :: String
-> SwiftCode (Scope SwiftCode)
-> SwiftCode (Permanence SwiftCode)
-> InOutFunc SwiftCode
inOutMethod String
n SwiftCode (Scope SwiftCode)
s SwiftCode (Permanence SwiftCode)
p = forall (r :: * -> *).
RenderSym r =>
(VSType r -> [MSParameter r] -> MSBody r -> SMethod r)
-> [SVariable r]
-> [SVariable r]
-> [SVariable r]
-> MSBody r
-> SMethod r
CP.inOutFunc (forall (r :: * -> *).
MethodSym r =>
String
-> r (Scope r)
-> r (Permanence r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
method String
n SwiftCode (Scope SwiftCode)
s SwiftCode (Permanence SwiftCode)
p)

  docInOutMethod :: String
-> SwiftCode (Scope SwiftCode)
-> SwiftCode (Permanence SwiftCode)
-> DocInOutFunc SwiftCode
docInOutMethod String
n SwiftCode (Scope SwiftCode)
s SwiftCode (Permanence SwiftCode)
p = forall (r :: * -> *).
RenderSym r =>
FuncDocRenderer
-> ([SVariable r]
    -> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r)
-> String
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> MSBody r
-> SMethod r
CP.docInOutFunc' FuncDocRenderer
swiftFunctionDoc (forall (r :: * -> *).
MethodSym r =>
String -> r (Scope r) -> r (Permanence r) -> InOutFunc r
inOutMethod String
n SwiftCode (Scope SwiftCode)
s SwiftCode (Permanence SwiftCode)
p)

  inOutFunc :: String -> SwiftCode (Scope SwiftCode) -> InOutFunc SwiftCode
inOutFunc String
n SwiftCode (Scope SwiftCode)
s = forall (r :: * -> *).
RenderSym r =>
(VSType r -> [MSParameter r] -> MSBody r -> SMethod r)
-> [SVariable r]
-> [SVariable r]
-> [SVariable r]
-> MSBody r
-> SMethod r
CP.inOutFunc (forall (r :: * -> *).
MethodSym r =>
String
-> r (Scope r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
function String
n SwiftCode (Scope SwiftCode)
s)

  docInOutFunc :: String -> SwiftCode (Scope SwiftCode) -> DocInOutFunc SwiftCode
docInOutFunc String
n SwiftCode (Scope SwiftCode)
s = forall (r :: * -> *).
RenderSym r =>
FuncDocRenderer
-> ([SVariable r]
    -> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r)
-> String
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> MSBody r
-> SMethod r
CP.docInOutFunc' FuncDocRenderer
swiftFunctionDoc (forall (r :: * -> *).
MethodSym r =>
String -> r (Scope r) -> InOutFunc r
inOutFunc String
n SwiftCode (Scope SwiftCode)
s)

instance RenderMethod SwiftCode where
  intMethod :: Bool
-> String
-> SwiftCode (Scope SwiftCode)
-> SwiftCode (Permanence SwiftCode)
-> MSMthdType SwiftCode
-> [MSParameter SwiftCode]
-> MSBody SwiftCode
-> SMethod SwiftCode
intMethod Bool
_ = String
-> SwiftCode (Scope SwiftCode)
-> SwiftCode (Permanence SwiftCode)
-> MSMthdType SwiftCode
-> [MSParameter SwiftCode]
-> MSBody SwiftCode
-> SMethod SwiftCode
swiftMethod
  intFunc :: Bool
-> String
-> SwiftCode (Scope SwiftCode)
-> SwiftCode (Permanence SwiftCode)
-> MSMthdType SwiftCode
-> [MSParameter SwiftCode]
-> MSBody SwiftCode
-> SMethod SwiftCode
intFunc Bool
_ String
n SwiftCode (Scope SwiftCode)
s SwiftCode (Permanence SwiftCode)
_ = String
-> SwiftCode (Scope SwiftCode)
-> SwiftCode (Permanence SwiftCode)
-> MSMthdType SwiftCode
-> [MSParameter SwiftCode]
-> MSBody SwiftCode
-> SMethod SwiftCode
swiftMethod String
n SwiftCode (Scope SwiftCode)
s forall (r :: * -> *). PermanenceSym r => r (Permanence r)
dynamic
  commentedFunc :: MS (SwiftCode (BlockComment SwiftCode))
-> SMethod SwiftCode -> SMethod SwiftCode
commentedFunc MS (SwiftCode (BlockComment SwiftCode))
cmt SMethod SwiftCode
m = forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues (forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues MethodData -> (Doc -> Doc) -> MethodData
updateMthd) SMethod SwiftCode
m 
    (forall a b s. (a -> b) -> State s a -> State s b
onStateValue (forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue Doc -> Doc -> Doc
R.commentedItem) MS (SwiftCode (BlockComment SwiftCode))
cmt)
    
  destructor :: [CSStateVar SwiftCode] -> SMethod SwiftCode
destructor [CSStateVar SwiftCode]
_ = forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String -> String
CP.destructorError String
swiftName

  mthdFromData :: ScopeTag -> Doc -> SMethod SwiftCode
mthdFromData ScopeTag
_ Doc
d = forall a s. a -> State s a
toState forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *) a. Monad r => a -> r a
toCode forall a b. (a -> b) -> a -> b
$ Doc -> MethodData
mthd Doc
d
  
instance MethodElim SwiftCode where
  method :: SwiftCode (Method SwiftCode) -> Doc
method = MethodData -> Doc
mthdDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC

instance StateVarSym SwiftCode where
  type StateVar SwiftCode = Doc
  stateVar :: SwiftCode (Scope SwiftCode)
-> SwiftCode (Permanence SwiftCode)
-> SVariable SwiftCode
-> CSStateVar SwiftCode
stateVar SwiftCode (Scope SwiftCode)
s SwiftCode (Permanence SwiftCode)
p SVariable SwiftCode
vr = do
    SwiftCode VarData
v <- forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' ClassState ValueState
lensCStoVS SVariable SwiftCode
vr
    forall (r :: * -> *).
StateVarSym r =>
r (Scope r)
-> r (Permanence r) -> SVariable r -> SValue r -> CSStateVar r
stateVarDef SwiftCode (Scope SwiftCode)
s SwiftCode (Permanence SwiftCode)
p SVariable SwiftCode
vr (forall (r :: * -> *). RenderSym r => CodeType -> SValue r
typeDfltVal forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType SwiftCode VarData
v)
  stateVarDef :: SwiftCode (Scope SwiftCode)
-> SwiftCode (Permanence SwiftCode)
-> SVariable SwiftCode
-> SValue SwiftCode
-> CSStateVar SwiftCode
stateVarDef = forall (r :: * -> *).
(RenderSym r, Monad r) =>
r (Scope r)
-> r (Permanence r) -> SVariable r -> SValue r -> CS (r Doc)
CP.stateVarDef
  constVar :: SwiftCode (Scope SwiftCode)
-> SVariable SwiftCode -> SValue SwiftCode -> CSStateVar SwiftCode
constVar = forall (r :: * -> *).
(RenderSym r, Monad r) =>
Doc -> r (Scope r) -> SVariable r -> SValue r -> CS (r Doc)
CP.constVar (forall (r :: * -> *). PermElim r => r (Permanence r) -> Doc
RC.perm (forall (r :: * -> *). PermanenceSym r => r (Permanence r)
static :: SwiftCode (Permanence SwiftCode)))
  
instance StateVarElim SwiftCode where
  stateVar :: SwiftCode (StateVar SwiftCode) -> Doc
stateVar = forall a. SwiftCode a -> a
unSC

instance ClassSym SwiftCode where
  type Class SwiftCode = Doc
  buildClass :: Maybe String
-> [CSStateVar SwiftCode]
-> [SMethod SwiftCode]
-> SClass SwiftCode
buildClass = forall (r :: * -> *).
RenderSym r =>
Maybe String -> [CSStateVar r] -> [SMethod r] -> SClass r
G.buildClass
  extraClass :: String
-> Maybe String
-> [CSStateVar SwiftCode]
-> [SMethod SwiftCode]
-> SClass SwiftCode
extraClass = forall (r :: * -> *).
RenderSym r =>
String -> Maybe String -> [CSStateVar r] -> [SMethod r] -> SClass r
CP.extraClass 
  implementingClass :: String
-> [String]
-> [CSStateVar SwiftCode]
-> [SMethod SwiftCode]
-> SClass SwiftCode
implementingClass = forall (r :: * -> *).
RenderSym r =>
String -> [String] -> [CSStateVar r] -> [SMethod r] -> SClass r
G.implementingClass

  docClass :: String -> SClass SwiftCode -> SClass SwiftCode
docClass = forall (r :: * -> *).
RenderSym r =>
ClassDocRenderer -> String -> SClass r -> SClass r
G.docClass ClassDocRenderer
swiftClassDoc

instance RenderClass SwiftCode where
  intClass :: String
-> SwiftCode (Scope SwiftCode)
-> SwiftCode Doc
-> [CSStateVar SwiftCode]
-> [SMethod SwiftCode]
-> SClass SwiftCode
intClass = forall (r :: * -> *).
(RenderSym r, Monad r) =>
(String -> Doc -> Doc -> Doc -> Doc -> Doc)
-> String
-> r (Scope r)
-> r Doc
-> [CSStateVar r]
-> [SMethod r]
-> CS (r Doc)
CP.intClass String -> Doc -> Doc -> Doc -> Doc -> Doc
R.class'

  inherit :: Maybe String -> SwiftCode Doc
inherit = forall (r :: * -> *). Monad r => Maybe String -> r Doc
CP.inherit
  implements :: [String] -> SwiftCode Doc
implements = forall (r :: * -> *). Monad r => [String] -> r Doc
CP.implements

  commentedClass :: CS (SwiftCode (BlockComment SwiftCode))
-> SClass SwiftCode -> SClass SwiftCode
commentedClass = forall (r :: * -> *).
(RenderSym r, Monad r) =>
CS (r (BlockComment r)) -> SClass r -> CS (r Doc)
G.commentedClass
  
instance ClassElim SwiftCode where
  class' :: SwiftCode (Class SwiftCode) -> Doc
class' = forall a. SwiftCode a -> a
unSC

instance ModuleSym SwiftCode where
  type Module SwiftCode = ModData
  buildModule :: String
-> [String]
-> [SMethod SwiftCode]
-> [SClass SwiftCode]
-> FSModule SwiftCode
buildModule String
n [String]
is [SMethod SwiftCode]
fs [SClass SwiftCode]
cs = do
    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.
    [SwiftCode MethodData]
fns <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' FileState MethodState
lensFStoMS) [SMethod SwiftCode]
fs
    [SwiftCode Doc]
cls <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' FileState ClassState
lensFStoCS) [SClass SwiftCode]
cs
    Bool
mn <- FS Bool
getCurrMain
    let modName :: String
modName = if Bool
mn then String
swiftMain else String
n
    forall (r :: * -> *).
RenderSym r =>
String
-> FS Doc
-> FS Doc
-> FS Doc
-> [SMethod r]
-> [SClass r]
-> FSModule r
CP.buildModule String
modName (do
      [String]
lis <- FS [String]
getLangImports
      [String]
libis <- FS [String]
getLibImports
      forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vcat forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall (r :: * -> *). ImportElim r => r (Import r) -> Doc
RC.import' forall b c a. (b -> c) -> (a -> b) -> a -> c
. 
          (forall (r :: * -> *). ImportSym r => String -> r (Import r)
langImport :: Label -> SwiftCode (Import SwiftCode))) 
          (forall a. Ord a => [a] -> [a]
sort forall a b. (a -> b) -> a -> b
$ [String]
lis forall a. [a] -> [a] -> [a]
++ [String]
is forall a. [a] -> [a] -> [a]
++ [String]
libis)) 
      (forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' FileState MethodState
lensFStoMS MS Doc
swiftStringError) FS Doc
getMainDoc (forall a b. (a -> b) -> [a] -> [b]
map forall (f :: * -> *) a. Applicative f => a -> f a
pure [SwiftCode MethodData]
fns) 
        (forall a b. (a -> b) -> [a] -> [b]
map forall (f :: * -> *) a. Applicative f => a -> f a
pure [SwiftCode Doc]
cls)
  
instance RenderMod SwiftCode where
  modFromData :: String -> FS Doc -> FSModule SwiftCode
modFromData String
n = forall (r :: * -> *).
String -> (Doc -> r (Module r)) -> FS Doc -> FSModule r
G.modFromData String
n (forall (r :: * -> *) a. Monad r => a -> r a
toCode forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc -> ModData
md String
n)
  updateModuleDoc :: (Doc -> Doc)
-> SwiftCode (Module SwiftCode) -> SwiftCode (Module SwiftCode)
updateModuleDoc Doc -> Doc
f = forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ((Doc -> Doc) -> ModData -> ModData
updateMod Doc -> Doc
f)
  
instance ModuleElim SwiftCode where
  module' :: SwiftCode (Module SwiftCode) -> Doc
module' = ModData -> Doc
modDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SwiftCode a -> a
unSC

instance BlockCommentSym SwiftCode where
  type BlockComment SwiftCode = Doc
  blockComment :: [String] -> SwiftCode (BlockComment SwiftCode)
blockComment [String]
lns = forall (r :: * -> *) a. Monad r => a -> r a
toCode 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 (BlockComment SwiftCode))
docComment = forall a b s. (a -> b) -> State s a -> State s b
onStateValue (\[String]
lns -> forall (r :: * -> *) a. Monad r => a -> r a
toCode 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 (BlockComment SwiftCode) -> Doc
blockComment' = forall a. SwiftCode a -> a
unSC

addMathImport :: VS a -> VS a
addMathImport :: forall a. VS a -> VS a
addMathImport = forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
(>>) forall a b. (a -> b) -> a -> b
$ 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 = forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
(>>) forall a b. (a -> b) -> a -> b
$ 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 :: (RenderSym r) => SValue r -> SValue r
swiftUnwrapVal :: forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftUnwrapVal SValue r
v' = do
  r (Value r)
v <- SValue r
v'
  forall (r :: * -> *). RenderSym r => r (Type r) -> Doc -> SValue r
mkVal (forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType r (Value r)
v) (forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
v Doc -> Doc -> Doc
<> Doc
swiftUnwrap')

swiftTryVal :: (RenderSym r) => SValue r -> SValue r
swiftTryVal :: forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftTryVal SValue r
v' = do
  r (Value r)
v <- SValue r
v'
  forall (r :: * -> *). RenderSym r => r (Type r) -> Doc -> SValue r
mkVal (forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType r (Value r)
v) (Doc
tryLabel Doc -> Doc -> Doc
<+> forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
v)

swiftArgVal :: (RenderSym r) => SValue r -> SValue r
swiftArgVal :: forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftArgVal SValue r
v' = do
  r (Value r)
v <- SValue r
v'
  forall (r :: * -> *). RenderSym r => r (Type r) -> Doc -> SValue r
mkVal (forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType r (Value r)
v) (Doc
swiftInOutArg Doc -> Doc -> Doc
<> forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
v)

-- Putting "gool" in these names to avoid name conflicts
swiftContentsVar, swiftLineVar :: SVariable SwiftCode
swiftContentsVar :: SVariable SwiftCode
swiftContentsVar = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
"goolContents" (forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listType forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listType forall (r :: * -> *). TypeSym r => VSType r
string)
swiftLineVar :: SVariable SwiftCode
swiftLineVar = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
"goolLine" (forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listType forall (r :: * -> *). TypeSym r => VSType r
string)

swiftContentsVal, swiftLineVal :: SValue SwiftCode
swiftContentsVal :: SValue SwiftCode
swiftContentsVal = forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable SwiftCode
swiftContentsVar
swiftLineVal :: SValue SwiftCode
swiftLineVal = forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable SwiftCode
swiftLineVar

swiftIntType :: (RenderSym r) => VSType r
swiftIntType :: forall (r :: * -> *). RenderSym r => VSType r
swiftIntType = forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData CodeType
Integer String
swiftInt (String -> Doc
text String
swiftInt)

swiftCharType :: (RenderSym r) => VSType r
swiftCharType :: forall (r :: * -> *). RenderSym r => VSType r
swiftCharType = forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData CodeType
Char String
swiftChar (String -> Doc
text String
swiftChar)

swiftFileType :: (RenderSym r) => VSType r
swiftFileType :: forall (r :: * -> *). RenderSym r => VSType r
swiftFileType = forall a. VS a -> VS a
addFoundationImport forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData CodeType
InFile String
swiftURL 
  (String -> Doc
text String
swiftURL)

swiftFileHdlType :: (RenderSym r) => VSType r
swiftFileHdlType :: forall (r :: * -> *). RenderSym r => VSType r
swiftFileHdlType = forall a. VS a -> VS a
addFoundationImport forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData CodeType
OutFile String
swiftFileHdl 
  (String -> Doc
text String
swiftFileHdl)

swiftListType :: (RenderSym r) => VSType r -> VSType r
swiftListType :: forall (r :: * -> *). RenderSym r => VSType r -> VSType r
swiftListType VSType r
t' = do
  r (Type r)
t <- VSType r
t' 
  forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData (CodeType -> CodeType
List forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType r (Type r)
t) (String
"[" forall a. [a] -> [a] -> [a]
++ forall (r :: * -> *). TypeElim r => r (Type r) -> String
getTypeString r (Type r)
t forall a. [a] -> [a] -> [a]
++ String
"]")
    (Doc -> Doc
brackets forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' r (Type r)
t)

swiftFuncType :: (RenderSym r) => [VSType r] -> VSType r -> VSType r
swiftFuncType :: forall (r :: * -> *).
RenderSym r =>
[VSType r] -> VSType r -> VSType r
swiftFuncType [VSType r]
ps VSType r
r = do
  [r (Type r)]
pts <- forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [VSType r]
ps
  r (Type r)
rt <- VSType r
r
  forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData ([CodeType] -> CodeType -> CodeType
Func (forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType [r (Type r)]
pts) (forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType r (Type r)
rt))
    (String
"(" forall a. [a] -> [a] -> [a]
++ forall a. [a] -> [[a]] -> [a]
intercalate String
listSep (forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *). TypeElim r => r (Type r) -> String
getTypeString [r (Type r)]
pts) forall a. [a] -> [a] -> [a]
++ String
")" forall a. [a] -> [a] -> [a]
++ String
" " forall a. [a] -> [a] -> [a]
++ 
      String
swiftRetType forall a. [a] -> [a] -> [a]
++ String
" " forall a. [a] -> [a] -> [a]
++ forall (r :: * -> *). TypeElim r => r (Type r) -> String
getTypeString r (Type r)
rt)
    (Doc -> Doc
parens (Doc -> [Doc] -> Doc
hicat Doc
listSep' forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' [r (Type r)]
pts) Doc -> Doc -> Doc
<+> Doc
swiftRetType' Doc -> Doc -> Doc
<+> 
      forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' r (Type r)
rt)

swiftVoidType :: (RenderSym r) => VSType r
swiftVoidType :: forall (r :: * -> *). RenderSym r => VSType r
swiftVoidType = forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData CodeType
Void String
swiftVoid (String -> Doc
text String
swiftVoid)

swiftPi, swiftListSize, swiftFirst, swiftDesc, swiftUTF8, swiftVar, swiftConst, 
  swiftDo, swiftFunc, swiftCtorName, swiftExtension, swiftInOut, swiftError, 
  swiftDocDir, swiftUserMask, swiftInOutArg, swiftNamedArgSep, swiftTypeSpec, 
  swiftConforms, swiftNoLabel, swiftRetType', swiftUnwrap' :: Doc
swiftPi :: Doc
swiftPi = String -> Doc
text forall a b. (a -> b) -> a -> b
$ String
CP.doubleRender String -> String -> String
`access` String
piLabel
swiftListSize :: Doc
swiftListSize = String -> Doc
text String
"count"
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 forall a b. (a -> b) -> a -> b
$ String
"" String -> String -> String
`access` String
"documentDirectory"
swiftUserMask :: Doc
swiftUserMask = String -> Doc
text 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

swiftMain, swiftFoundation, swiftMath, swiftNil, swiftInt, swiftChar,
  swiftURL, swiftFileHdl, swiftRetType, swiftVoid, swiftCommLine, 
  swiftSearchDir, swiftPathMask, swiftArgs, swiftWrite, swiftIndex, 
  swiftStride, swiftMap, swiftListAdd, swiftListAppend, swiftReadLine, 
  swiftSeekEnd, swiftClose, swiftJoined, swiftAppendPath, swiftUrls, swiftSplit,
  swiftData, swiftEncoding, swiftOf, swiftFrom, swiftTo, swiftBy, swiftAt, 
  swiftTerm, swiftFor, swiftIn, swiftContentsOf, swiftWriteTo, swiftSep, 
  swiftSepBy, swiftUnwrap :: 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"
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
"!"

swiftUnaryMath :: (Monad r) => String -> VSOp r
swiftUnaryMath :: forall (r :: * -> *). Monad r => String -> VSOp r
swiftUnaryMath = forall a. VS a -> VS a
addMathImport forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec

swiftNumBinExpr :: (RenderSym r) => (SValue r -> SValue r -> SValue r) -> 
  SValue r -> SValue r -> SValue r
swiftNumBinExpr :: forall (r :: * -> *).
RenderSym r =>
(SValue r -> SValue r -> SValue r)
-> SValue r -> SValue r -> SValue r
swiftNumBinExpr SValue r -> SValue r -> SValue r
f SValue r
v1' SValue r
v2' = do
  r (Value r)
v1 <- SValue r
v1'
  r (Value r)
v2 <- SValue r
v2'
  let exprT :: CodeType -> CodeType -> SValue r
exprT CodeType
t1 CodeType
t2 = if CodeType
t1 forall a. Eq a => a -> a -> Bool
== CodeType
t2 then SValue r -> SValue r -> SValue r
f (forall (f :: * -> *) a. Applicative f => a -> f a
pure r (Value r)
v1) (forall (f :: * -> *) a. Applicative f => a -> f a
pure r (Value r)
v2) else CodeType -> CodeType -> SValue r
exprT' CodeType
t1 CodeType
t2
      exprT' :: CodeType -> CodeType -> SValue r
exprT' CodeType
Double CodeType
_ = SValue r -> SValue r -> SValue r
f (forall (f :: * -> *) a. Applicative f => a -> f a
pure r (Value r)
v1) (forall (r :: * -> *).
RenderValue r =>
VSType r -> SValue r -> SValue r
cast forall (r :: * -> *). TypeSym r => VSType r
double forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure r (Value r)
v2)
      exprT' CodeType
_ CodeType
Double = SValue r -> SValue r -> SValue r
f (forall (r :: * -> *).
RenderValue r =>
VSType r -> SValue r -> SValue r
cast forall (r :: * -> *). TypeSym r => VSType r
double forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure r (Value r)
v1) (forall (f :: * -> *) a. Applicative f => a -> f a
pure r (Value r)
v2)
      exprT' CodeType
Float CodeType
_  = SValue r -> SValue r -> SValue r
f (forall (f :: * -> *) a. Applicative f => a -> f a
pure r (Value r)
v1) (forall (r :: * -> *).
RenderValue r =>
VSType r -> SValue r -> SValue r
cast forall (r :: * -> *). TypeSym r => VSType r
float forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure r (Value r)
v2)
      exprT' CodeType
_ CodeType
Float  = SValue r -> SValue r -> SValue r
f (forall (r :: * -> *).
RenderValue r =>
VSType r -> SValue r -> SValue r
cast forall (r :: * -> *). TypeSym r => VSType r
float forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure r (Value r)
v1) (forall (f :: * -> *) a. Applicative f => a -> f a
pure r (Value r)
v2)
      exprT' CodeType
_ CodeType
_      = SValue r -> SValue r -> SValue r
f (forall (f :: * -> *) a. Applicative f => a -> f a
pure r (Value r)
v1) (forall (f :: * -> *) a. Applicative f => a -> f a
pure r (Value r)
v2)
  CodeType -> CodeType -> SValue r
exprT (forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType r (Value r)
v1) (forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType r (Value r)
v2)

swiftLitFloat :: (RenderSym r) => Float -> SValue r
swiftLitFloat :: forall (r :: * -> *). RenderSym r => Float -> SValue r
swiftLitFloat = forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal forall (r :: * -> *). TypeSym r => VSType r
float forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Doc
D.float

swiftLambda :: (RenderSym r) => [r (Variable r)] -> r (Value r) -> Doc
swiftLambda :: forall (r :: * -> *).
RenderSym r =>
[r (Variable r)] -> r (Value r) -> Doc
swiftLambda [r (Variable r)]
ps r (Value r)
ex = Doc -> Doc
braces forall a b. (a -> b) -> a -> b
$ Doc -> Doc
parens (Doc -> [Doc] -> Doc
hicat Doc
listSep' 
  (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) 
    (forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable [r (Variable r)]
ps) 
    (forall a b. (a -> b) -> [a] -> [b]
map (forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType) [r (Variable r)]
ps))) 
  Doc -> Doc -> Doc
<+> Doc
swiftRetType' Doc -> Doc -> Doc
<+> forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' (forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType r (Value r)
ex) Doc -> Doc -> Doc
<+> Doc
inLabel Doc -> Doc -> Doc
<+> forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
ex

swiftReadableTypes :: [CodeType]
swiftReadableTypes :: [CodeType]
swiftReadableTypes = [CodeType
Integer, CodeType
Double, CodeType
Float, CodeType
Boolean, CodeType
Char]

swiftCast :: (RenderSym r) => VSType r -> SValue r -> SValue r
swiftCast :: forall (r :: * -> *).
RenderSym r =>
VSType r -> SValue r -> SValue r
swiftCast VSType r
t' SValue r
v' = do
  r (Type r)
t <- VSType r
t'
  r (Value r)
v <- SValue r
v'
  let unwrap :: SValue r -> SValue r
unwrap = if (forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType r (Type r)
t forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [CodeType]
swiftReadableTypes) Bool -> Bool -> Bool
&& 
        (forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType (forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType r (Value r)
v) forall a. Eq a => a -> a -> Bool
== CodeType
String) then forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftUnwrapVal else forall a. a -> a
id
  SValue r -> SValue r
unwrap forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal (forall (f :: * -> *) a. Applicative f => a -> f a
pure r (Type r)
t) (Doc -> Doc -> Doc
R.castObj (forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' r (Type r)
t) (forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
v))

swiftIndexFunc :: (RenderSym r) => SValue r -> SValue r -> SValue r
swiftIndexFunc :: forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
swiftIndexFunc SValue r
l SValue r
v' = do
  r (Value r)
v <- SValue r
v'
  let t :: StateT ValueState Identity (r (Type r))
t = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType r (Value r)
v
      ofArg :: SVariable r
ofArg = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
swiftOf StateT ValueState Identity (r (Type r))
t
  forall (r :: * -> *).
InternalValueExp r =>
VSType r -> SValue r -> String -> NamedArgs r -> SValue r
objMethodCallNamedArgs forall (r :: * -> *). TypeSym r => VSType r
int SValue r
l String
swiftIndex [(SVariable r
ofArg, forall (f :: * -> *) a. Applicative f => a -> f a
pure r (Value r)
v)]

swiftStrideFunc :: (RenderSym r) => SValue r -> SValue r -> SValue r -> SValue r
swiftStrideFunc :: forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r -> SValue r
swiftStrideFunc SValue r
beg SValue r
end SValue r
step = let t :: VSType r
t = forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listType forall (r :: * -> *). TypeSym r => VSType r
int 
                                   fromArg :: SVariable r
fromArg = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
swiftFrom forall (r :: * -> *). TypeSym r => VSType r
int
                                   toArg :: SVariable r
toArg = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
swiftTo forall (r :: * -> *). TypeSym r => VSType r
int
                                   byArg :: SVariable r
byArg = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
swiftBy forall (r :: * -> *). TypeSym r => VSType r
int
  in forall (r :: * -> *).
RenderValue r =>
VSType r -> SValue r -> SValue r
cast VSType r
t (forall (r :: * -> *).
ValueExpression r =>
String -> VSType r -> NamedArgs r -> SValue r
funcAppNamedArgs String
swiftStride VSType r
t 
    [(SVariable r
fromArg, SValue r
beg), (SVariable r
toArg, SValue r
end), (SVariable r
byArg, SValue r
step)])

swiftMapFunc :: (RenderSym r) => SValue r -> SValue r -> SValue r
swiftMapFunc :: forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
swiftMapFunc SValue r
lst SValue r
f = forall (r :: * -> *).
InternalValueExp r =>
VSType r -> SValue r -> String -> [SValue r] -> SValue r
objMethodCall (forall a b s. (a -> b) -> State s a -> State s b
onStateValue forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType SValue r
lst) SValue r
lst String
swiftMap [SValue r
f]

swiftListAddFunc :: (RenderSym r) => SValue r -> SValue r -> SValue r
swiftListAddFunc :: forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
swiftListAddFunc SValue r
i SValue r
v = let atArg :: SVariable r
atArg = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
swiftAt forall (r :: * -> *). TypeSym r => VSType r
int
  in forall (r :: * -> *). ValueExpression r => MixedCall r
funcAppMixedArgs String
swiftListAdd (forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listType forall a b. (a -> b) -> a -> b
$ forall a b s. (a -> b) -> State s a -> State s b
onStateValue forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType SValue r
v) 
    [SValue r
v] [(SVariable r
atArg, SValue r
i)]

swiftWriteFunc :: (RenderSym r) => SValue r -> SValue r -> SValue r
swiftWriteFunc :: forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
swiftWriteFunc SValue r
v SValue r
f = let contentsArg :: SVariable r
contentsArg = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
swiftContentsOf (forall (r :: * -> *). TypeSym r => String -> VSType r
obj String
swiftData)
  in forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftTryVal forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
InternalValueExp r =>
VSType r -> SValue r -> String -> NamedArgs r -> SValue r
objMethodCallNamedArgs forall (r :: * -> *). TypeSym r => VSType r
void SValue r
f String
swiftWrite 
    [(SVariable r
contentsArg, forall (r :: * -> *). ValueExpression r => PosCtorCall r
newObj (forall (r :: * -> *). TypeSym r => String -> VSType r
obj String
swiftData) [SValue r
v forall (r :: * -> *).
FunctionSym r =>
SValue r -> VSFunction r -> SValue r
$. forall (r :: * -> *).
RenderFunction r =>
Doc -> VSType r -> VSFunction r
funcFromData (Doc -> Doc
R.func Doc
swiftUTF8) 
    (forall (r :: * -> *). TypeSym r => String -> VSType r
obj String
swiftEncoding)])]

swiftReadLineFunc :: (RenderSym r) => SValue r
swiftReadLineFunc :: forall (r :: * -> *). RenderSym r => SValue r
swiftReadLineFunc = forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftUnwrapVal forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). ValueExpression r => PosCall r
funcApp String
swiftReadLine forall (r :: * -> *). TypeSym r => VSType r
string []

swiftReadFileFunc :: (RenderSym r) => SValue r -> SValue r
swiftReadFileFunc :: forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftReadFileFunc SValue r
v = let contentsArg :: SVariable r
contentsArg = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
swiftContentsOf forall (r :: * -> *). TypeSym r => VSType r
infile 
  in forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftTryVal forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
ValueExpression r =>
String -> VSType r -> NamedArgs r -> SValue r
funcAppNamedArgs String
CP.stringRender' forall (r :: * -> *). TypeSym r => VSType r
string [(SVariable r
contentsArg, SValue r
v)]

swiftSplitFunc :: (RenderSym r) => Char -> SValue r -> SValue r
swiftSplitFunc :: forall (r :: * -> *). RenderSym r => Char -> SValue r -> SValue r
swiftSplitFunc Char
d SValue r
s = let sepArg :: SVariable r
sepArg = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
swiftSepBy forall (r :: * -> *). TypeSym r => VSType r
char
  in forall (r :: * -> *).
InternalValueExp r =>
VSType r -> SValue r -> String -> NamedArgs r -> SValue r
objMethodCallNamedArgs (forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listType forall (r :: * -> *). TypeSym r => VSType r
string) SValue r
s String
swiftSplit [(SVariable r
sepArg, forall (r :: * -> *). Literal r => Char -> SValue r
litChar Char
d)]

swiftJoinedFunc :: (RenderSym r) => Char -> SValue r -> SValue r
swiftJoinedFunc :: forall (r :: * -> *). RenderSym r => Char -> SValue r -> SValue r
swiftJoinedFunc Char
d SValue r
s = let sepArg :: SVariable r
sepArg = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
swiftSep forall (r :: * -> *). TypeSym r => VSType r
char 
  in forall (r :: * -> *).
InternalValueExp r =>
VSType r -> SValue r -> String -> NamedArgs r -> SValue r
objMethodCallNamedArgs forall (r :: * -> *). TypeSym r => VSType r
string SValue r
s String
swiftJoined [(SVariable r
sepArg, forall (r :: * -> *). Literal r => Char -> SValue r
litChar Char
d)]

swiftIndexOf :: (RenderSym r) => SValue r -> SValue r -> SValue r
swiftIndexOf :: forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
swiftIndexOf = forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftUnwrapVal forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
.: forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
swiftIndexFunc

swiftListSlice :: (RenderSym r) => SVariable r -> SValue r -> SValue r -> 
  SValue r -> SValue r -> MSBlock r
swiftListSlice :: forall (r :: * -> *).
RenderSym r =>
SVariable r
-> SValue r -> SValue r -> SValue r -> SValue r -> MSBlock r
swiftListSlice SVariable r
vn SValue r
vo SValue r
beg SValue r
end SValue r
step = let i :: SVariable r
i = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
"i" forall (r :: * -> *). TypeSym r => VSType r
int 
  in forall (r :: * -> *). BlockSym r => [MSStatement r] -> MSBlock r
block [SVariable r
vn forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
swiftMapFunc (forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r -> SValue r
swiftStrideFunc SValue r
beg SValue r
end SValue r
step) (forall (r :: * -> *).
ValueExpression r =>
[SVariable r] -> SValue r -> SValue r
lambda [SVariable r
i] 
    (forall (r :: * -> *). List r => SValue r -> SValue r -> SValue r
listAccess SValue r
vo (forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable r
i)))]

swiftPrint :: Bool -> Maybe (SValue SwiftCode) -> SValue SwiftCode -> 
  SValue SwiftCode -> MSStatement SwiftCode
swiftPrint :: Bool
-> Maybe (SValue SwiftCode)
-> SValue SwiftCode
-> SValue SwiftCode
-> MSStatement SwiftCode
swiftPrint Bool
newLn Maybe (SValue SwiftCode)
Nothing SValue SwiftCode
_ SValue SwiftCode
v = do
  let s :: SValue SwiftCode
s = forall (r :: * -> *). Literal r => String -> SValue r
litString String
"" :: SValue SwiftCode
      nl :: [(SVariable SwiftCode,
  StateT ValueState Identity (SwiftCode ValData))]
nl = [(forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
swiftTerm forall (r :: * -> *). TypeSym r => VSType r
string, StateT ValueState Identity (SwiftCode ValData)
s) | Bool -> Bool
not Bool
newLn]
  forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
valStmt forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). ValueExpression r => MixedCall r
funcAppMixedArgs String
printLabel forall (r :: * -> *). TypeSym r => VSType r
void [SValue SwiftCode
v] [(SVariable SwiftCode,
  StateT ValueState Identity (SwiftCode ValData))]
nl
swiftPrint Bool
newLn (Just SValue SwiftCode
f) SValue SwiftCode
_ SValue SwiftCode
v' = do
  SwiftCode ValData
v <- forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState ValueState
lensMStoVS SValue SwiftCode
v'
  let valToPrint :: CodeType -> SValue SwiftCode
valToPrint (List CodeType
_) = forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode ValData
v forall (r :: * -> *).
FunctionSym r =>
SValue r -> VSFunction r -> SValue r
$. forall (r :: * -> *).
RenderFunction r =>
Doc -> VSType r -> VSFunction r
funcFromData (Doc -> Doc
R.func Doc
swiftDesc) forall (r :: * -> *). TypeSym r => VSType r
string
      valToPrint CodeType
String = forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode ValData
v
      valToPrint CodeType
_ = forall (r :: * -> *).
RenderValue r =>
VSType r -> SValue r -> SValue r
cast forall (r :: * -> *). TypeSym r => VSType r
string (forall (f :: * -> *) a. Applicative f => a -> f a
pure SwiftCode ValData
v)
      prNewLn :: MSStatement SwiftCode
prNewLn = if Bool
newLn then forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
valStmt (forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
swiftWriteFunc (forall (r :: * -> *). Literal r => String -> SValue r
litString String
"\\n") SValue SwiftCode
f)
        else forall (r :: * -> *). RenderStatement r => MSStatement r
emptyStmt
  forall (r :: * -> *).
ControlStatement r =>
MSBody r -> MSBody r -> MSStatement r
tryCatch (forall (r :: * -> *). BodySym r => [MSStatement r] -> MSBody r
bodyStatements
    [forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
valStmt forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
swiftWriteFunc (CodeType -> SValue SwiftCode
valToPrint forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType SwiftCode ValData
v) SValue SwiftCode
f, MSStatement SwiftCode
prNewLn]) 
    (forall (r :: * -> *). BodySym r => MSStatement r -> MSBody r
oneLiner forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). ControlStatement r => String -> MSStatement r
throw String
"Error printing to file.")

-- swiftPrint can handle lists, so don't use G.print for lists.
swiftOut :: (RenderSym r) => Bool -> Maybe (SValue r) -> SValue r -> SValue r 
  -> MSStatement r
swiftOut :: forall (r :: * -> *).
RenderSym r =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MSStatement r
swiftOut Bool
newLn Maybe (SValue r)
f SValue r
printFn SValue r
v = forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState ValueState
lensMStoVS SValue r
v forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CodeType -> StateT MethodState Identity (r (Statement r))
swOut forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType
  where swOut :: CodeType -> StateT MethodState Identity (r (Statement r))
swOut (List CodeType
_) = forall (r :: * -> *).
InternalIOStmt r =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MSStatement r
printSt Bool
newLn Maybe (SValue r)
f SValue r
printFn SValue r
v
        swOut CodeType
_ = forall (r :: * -> *).
RenderSym r =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MSStatement r
G.print Bool
newLn Maybe (SValue r)
f SValue r
printFn SValue r
v

swiftInput :: SVariable SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftInput :: SVariable SwiftCode -> SValue SwiftCode -> SValue SwiftCode
swiftInput SVariable SwiftCode
vr SValue SwiftCode
vl = do
  SwiftCode VarData
vr' <- SVariable SwiftCode
vr
  let swiftInput' :: CodeType -> SValue SwiftCode
swiftInput' CodeType
String = SValue SwiftCode
vl
      swiftInput' CodeType
ct
        | CodeType
ct forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [CodeType]
swiftReadableTypes = forall (r :: * -> *).
RenderValue r =>
VSType r -> SValue r -> SValue r
cast (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType SwiftCode VarData
vr') SValue SwiftCode
vl
        | Bool
otherwise = forall a. HasCallStack => String -> a
error String
"Attempt to read value of unreadable type"
  CodeType -> SValue SwiftCode
swiftInput' (forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType SwiftCode VarData
vr')

swiftOpenFile :: (RenderSym r) => SValue r -> VSType r -> SValue r
swiftOpenFile :: forall (r :: * -> *).
RenderSym r =>
SValue r -> VSType r -> SValue r
swiftOpenFile SValue r
n VSType r
t = let forArg :: SVariable r
forArg = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
swiftFor (forall (r :: * -> *). TypeSym r => String -> VSType r
obj String
swiftSearchDir)
                        dirVal :: SValue r
dirVal = forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal (forall (r :: * -> *). TypeSym r => String -> VSType r
obj String
swiftSearchDir) Doc
swiftDocDir
                        inArg :: SVariable r
inArg = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
swiftIn (forall (r :: * -> *). TypeSym r => String -> VSType r
obj String
swiftPathMask)
                        maskVal :: SValue r
maskVal = forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal (forall (r :: * -> *). TypeSym r => String -> VSType r
obj String
swiftPathMask) Doc
swiftUserMask
  in forall (r :: * -> *).
InternalValueExp r =>
VSType r -> SValue r -> String -> [SValue r] -> SValue r
objMethodCall VSType r
t (forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftUnwrapVal forall a b. (a -> b) -> a -> b
$ 
    forall (r :: * -> *).
ValueExpression r =>
String -> VSType r -> NamedArgs r -> SValue r
funcAppNamedArgs String
swiftUrls (forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listType VSType r
t) [(SVariable r
forArg, SValue r
dirVal), (SVariable r
inArg, SValue r
maskVal)]
    forall (r :: * -> *).
FunctionSym r =>
SValue r -> VSFunction r -> SValue r
$. forall (r :: * -> *).
RenderFunction r =>
Doc -> VSType r -> VSFunction r
funcFromData (Doc -> Doc
R.func Doc
swiftFirst) VSType r
t) String
swiftAppendPath [SValue r
n]

swiftOpenFileHdl :: (RenderSym r) => SValue r -> VSType r -> SValue r
swiftOpenFileHdl :: forall (r :: * -> *).
RenderSym r =>
SValue r -> VSType r -> SValue r
swiftOpenFileHdl SValue r
n VSType r
t = let forWritingArg :: SVariable r
forWritingArg = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
swiftWriteTo forall (r :: * -> *). RenderSym r => VSType r
swiftFileType
  in forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftTryVal forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
ValueExpression r =>
String -> VSType r -> NamedArgs r -> SValue r
funcAppNamedArgs String
swiftFileHdl forall (r :: * -> *). TypeSym r => VSType r
outfile 
    [(SVariable r
forWritingArg, forall (r :: * -> *).
RenderSym r =>
SValue r -> VSType r -> SValue r
swiftOpenFile SValue r
n VSType r
t)]

swiftOpenFileWA :: (RenderSym r) => Bool -> SVariable r -> SValue r -> 
  MSStatement r
swiftOpenFileWA :: forall (r :: * -> *).
RenderSym r =>
Bool -> SVariable r -> SValue r -> MSStatement r
swiftOpenFileWA Bool
app SVariable r
f' SValue r
n' = forall (r :: * -> *).
ControlStatement r =>
MSBody r -> MSBody r -> MSStatement r
tryCatch
    (forall (r :: * -> *). BodySym r => [MSStatement r] -> MSBody r
bodyStatements [forall (r :: * -> *).
RenderSym r =>
(SValue r -> VSType r -> SValue r -> SValue r)
-> SVariable r -> SValue r -> MSStatement r
CP.openFileW (\SValue r
f VSType r
n SValue r
_ -> forall (r :: * -> *).
RenderSym r =>
SValue r -> VSType r -> SValue r
swiftOpenFileHdl SValue r
f VSType r
n) SVariable r
f' SValue r
n',
      if Bool
app 
        then forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
valStmt forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftTryVal forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
InternalValueExp r =>
VSType r -> SValue r -> String -> SValue r
objMethodCallNoParams forall (r :: * -> *). TypeSym r => VSType r
void (forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable r
f') 
          String
swiftSeekEnd 
        else forall (r :: * -> *). RenderStatement r => MSStatement r
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.
    (forall (r :: * -> *). BodySym r => MSStatement r -> MSBody r
oneLiner forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). ControlStatement r => String -> MSStatement r
throw String
"Error opening file.")

swiftCloseFile :: (RenderSym r) => SValue r -> MSStatement r
swiftCloseFile :: forall (r :: * -> *). RenderSym r => SValue r -> MSStatement r
swiftCloseFile SValue r
f' = do
  r (Value r)
f <- forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState ValueState
lensMStoVS SValue r
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 -> MSStatement r
swClose CodeType
InFile = forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
resetIndices forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (r :: * -> *). RenderStatement r => MSStatement r
emptyStmt 
      swClose CodeType
OutFile = forall (r :: * -> *).
ControlStatement r =>
MSBody r -> MSBody r -> MSStatement r
tryCatch (forall (r :: * -> *). BodySym r => MSStatement r -> MSBody r
oneLiner forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
valStmt forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftTryVal forall a b. (a -> b) -> a -> b
$
          forall (r :: * -> *).
InternalValueExp r =>
VSType r -> SValue r -> String -> SValue r
objMethodCallNoParams forall (r :: * -> *). TypeSym r => VSType r
void (forall (f :: * -> *) a. Applicative f => a -> f a
pure r (Value r)
f) String
swiftClose)
        (forall (r :: * -> *). BodySym r => MSStatement r -> MSBody r
oneLiner forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). ControlStatement r => String -> MSStatement r
throw String
"Error closing file.")
      swClose CodeType
_ = forall a. HasCallStack => String -> a
error String
"closeFile called on non-file-typed value"
  CodeType -> MSStatement r
swClose (forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType r (Value r)
f)

swiftReadFile :: (RenderSym r) => SVariable r -> SValue r -> MSStatement r
swiftReadFile :: forall (r :: * -> *).
RenderSym r =>
SVariable r -> SValue r -> MSStatement r
swiftReadFile SVariable r
v SValue r
f = let l :: SVariable r
l = forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
var String
"l" forall (r :: * -> *). TypeSym r => VSType r
string
  in forall (r :: * -> *).
ControlStatement r =>
MSBody r -> MSBody r -> MSStatement r
tryCatch 
  (forall (r :: * -> *). BodySym r => MSStatement r -> MSBody r
oneLiner forall a b. (a -> b) -> a -> b
$ SVariable r
v forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
swiftMapFunc (forall (r :: * -> *). RenderSym r => Char -> SValue r -> SValue r
swiftSplitFunc Char
'\n' forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). RenderSym r => SValue r -> SValue r
swiftReadFileFunc SValue r
f) 
    (forall (r :: * -> *).
ValueExpression r =>
[SVariable r] -> SValue r -> SValue r
lambda [SVariable r
l] (forall (r :: * -> *). RenderSym r => Char -> SValue r -> SValue r
swiftSplitFunc Char
' ' (forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable r
l))))
  (forall (r :: * -> *). BodySym r => MSStatement r -> MSBody r
oneLiner forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). ControlStatement r => String -> MSStatement r
throw String
"Error reading from file.")

swiftVarDec :: Doc -> SVariable SwiftCode -> MSStatement SwiftCode
swiftVarDec :: Doc -> SVariable SwiftCode -> MSStatement SwiftCode
swiftVarDec Doc
dec SVariable SwiftCode
v' = do
  SwiftCode VarData
v <- forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState ValueState
lensMStoVS SVariable SwiftCode
v'
  forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ String -> MethodState -> MethodState
useVarName (forall (r :: * -> *). VariableElim r => r (Variable r) -> String
variableName SwiftCode VarData
v)
  let bind :: Binding -> SwiftCode (Permanence SwiftCode)
bind Binding
Static = forall (r :: * -> *). PermanenceSym r => r (Permanence r)
static :: SwiftCode (Permanence SwiftCode)
      bind Binding
Dynamic = forall (r :: * -> *). PermanenceSym r => r (Permanence r)
dynamic :: SwiftCode (Permanence SwiftCode)
      p :: SwiftCode Doc
p = Binding -> SwiftCode Doc
bind forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
InternalVarElim r =>
r (Variable r) -> Binding
variableBind SwiftCode VarData
v
  forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmtNoEnd (forall (r :: * -> *). PermElim r => r (Permanence r) -> Doc
RC.perm SwiftCode Doc
p Doc -> Doc -> Doc
<+> Doc
dec Doc -> Doc -> Doc
<+> forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable SwiftCode VarData
v Doc -> Doc -> Doc
<> Doc
swiftTypeSpec 
    Doc -> Doc -> Doc
<+> forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' (forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType SwiftCode VarData
v))

swiftThrowDoc :: (RenderSym r) => r (Value r) -> Doc
swiftThrowDoc :: forall (r :: * -> *). RenderSym r => r (Value r) -> Doc
swiftThrowDoc r (Value r)
errMsg = Doc
throwLabel Doc -> Doc -> Doc
<+> forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
errMsg

swiftForEach :: (RenderSym r) => SVariable r -> SValue r -> MSBody r -> 
  MSStatement r
swiftForEach :: forall (r :: * -> *).
RenderSym r =>
SVariable r -> SValue r -> MSBody r -> MSStatement r
swiftForEach SVariable r
i' SValue r
lst' MSBody r
b' = do
  r (Variable r)
i <- forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState ValueState
lensMStoVS SVariable r
i'
  r (Value r)
lst <- forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState ValueState
lensMStoVS SValue r
lst'
  r (Body r)
b <- MSBody r
b'
  forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmtNoEnd forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vcat [
    Doc
forLabel Doc -> Doc -> Doc
<+> forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
i Doc -> Doc -> Doc
<+> Doc
inLabel Doc -> Doc -> Doc
<+> forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
lst Doc -> Doc -> Doc
<+> Doc
bodyStart,
    Doc -> Doc
indent forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body r (Body r)
b,
    Doc
bodyEnd]

swiftTryCatch :: (RenderSym r) => r (Body r) -> r (Body r) -> Doc
swiftTryCatch :: forall (r :: * -> *).
RenderSym r =>
r (Body r) -> r (Body r) -> Doc
swiftTryCatch r (Body r)
tb r (Body r)
cb = [Doc] -> Doc
vcat [
  Doc
swiftDo Doc -> Doc -> Doc
<+> Doc
lbrace,
  Doc -> Doc
indent forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body r (Body r)
tb,
  Doc
rbrace Doc -> Doc -> Doc
<+> Doc
catchLabel Doc -> Doc -> Doc
<+> Doc
lbrace,
  Doc -> Doc
indent forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body r (Body r)
cb,
  Doc
rbrace]

swiftParam :: (RenderSym r) => Doc -> r (Variable r) -> Doc
swiftParam :: forall (r :: * -> *). RenderSym r => Doc -> r (Variable r) -> Doc
swiftParam Doc
io r (Variable r)
v = Doc
swiftNoLabel Doc -> Doc -> Doc
<+> forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
v Doc -> Doc -> Doc
<> Doc
swiftTypeSpec Doc -> Doc -> Doc
<+> Doc
io
  Doc -> Doc -> Doc
<+> forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' (forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
v)

swiftMethod :: Label -> SwiftCode (Scope SwiftCode) -> 
  SwiftCode (Permanence SwiftCode) -> MSMthdType SwiftCode -> 
  [MSParameter SwiftCode] -> MSBody SwiftCode -> SMethod SwiftCode
swiftMethod :: String
-> SwiftCode (Scope SwiftCode)
-> SwiftCode (Permanence SwiftCode)
-> MSMthdType SwiftCode
-> [MSParameter SwiftCode]
-> MSBody SwiftCode
-> SMethod SwiftCode
swiftMethod String
n SwiftCode (Scope SwiftCode)
s SwiftCode (Permanence SwiftCode)
p MSMthdType SwiftCode
t [MSParameter SwiftCode]
ps MSBody SwiftCode
b = do
  SwiftCode TypeData
tp <- MSMthdType SwiftCode
t
  [SwiftCode ParamData]
pms <- forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [MSParameter SwiftCode]
ps
  SwiftCode Doc
bod <- MSBody SwiftCode
b
  Map QualifiedName [ExceptionType]
mem <- forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState ValueState
lensMStoVS VS (Map QualifiedName [ExceptionType])
getMethodExcMap
  String
mn <- forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState FileState
lensMStoFS FS String
getModuleName
  let excs :: [ExceptionType]
excs = forall k a. Ord k => a -> k -> Map k a -> a
findWithDefault [] (String -> String -> QualifiedName
qualName String
mn String
n) Map QualifiedName [ExceptionType]
mem
  forall (r :: * -> *).
RenderMethod r =>
ScopeTag -> Doc -> SMethod r
mthdFromData ScopeTag
Pub ([Doc] -> Doc
vcat [
    forall (r :: * -> *). ScopeElim r => r (Scope r) -> Doc
RC.scope SwiftCode (Scope SwiftCode)
s Doc -> Doc -> Doc
<+> forall (r :: * -> *). PermElim r => r (Permanence r) -> Doc
RC.perm SwiftCode (Permanence SwiftCode)
p Doc -> Doc -> Doc
<+> Doc
swiftFunc Doc -> Doc -> Doc
<+> String -> Doc
text String
n Doc -> Doc -> Doc
<> 
      Doc -> Doc
parens (forall (r :: * -> *). RenderSym r => [r (Parameter r)] -> Doc
parameterList [SwiftCode ParamData]
pms) Doc -> Doc -> Doc
<+> forall a. [a] -> Doc -> Doc
emptyIfNull [ExceptionType]
excs Doc
throwsLabel Doc -> Doc -> Doc
<+> 
      Doc
swiftRetType' Doc -> Doc -> Doc
<+> forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' SwiftCode TypeData
tp Doc -> Doc -> Doc
<+> Doc
bodyStart,
    Doc -> Doc
indent forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body SwiftCode Doc
bod,
    Doc
bodyEnd])
  
swiftConstructor :: (RenderSym r) => [MSParameter r] -> Initializers r -> 
  MSBody r -> SMethod r
swiftConstructor :: forall (r :: * -> *).
RenderSym r =>
[MSParameter r] -> Initializers r -> MSBody r -> SMethod r
swiftConstructor [MSParameter r]
ps Initializers r
is MSBody r
b = do
  [r (Parameter r)]
pms <- forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [MSParameter r]
ps
  r (Body r)
bod <- forall (r :: * -> *). RenderBody r => [MSBody r] -> MSBody r
multiBody [forall (r :: * -> *). RenderSym r => Initializers r -> MSBody r
G.initStmts Initializers r
is, MSBody r
b]
  Map QualifiedName [ExceptionType]
mem <- forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState ValueState
lensMStoVS VS (Map QualifiedName [ExceptionType])
getMethodExcMap
  String
mn <- forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState FileState
lensMStoFS FS String
getModuleName
  String
cn <- MS String
getClassName
  let excs :: [ExceptionType]
excs = forall k a. Ord k => a -> k -> Map k a -> a
findWithDefault [] (String -> String -> QualifiedName
qualName String
mn String
cn) Map QualifiedName [ExceptionType]
mem
  forall (r :: * -> *).
RenderMethod r =>
ScopeTag -> Doc -> SMethod r
mthdFromData ScopeTag
Pub ([Doc] -> Doc
vcat [
    Doc
swiftCtorName Doc -> Doc -> Doc
<> Doc -> Doc
parens (forall (r :: * -> *). RenderSym r => [r (Parameter r)] -> Doc
parameterList [r (Parameter r)]
pms) Doc -> Doc -> Doc
<+> 
      forall a. [a] -> Doc -> Doc
emptyIfNull [ExceptionType]
excs Doc
throwsLabel Doc -> Doc -> Doc
<+> Doc
bodyStart,
    Doc -> Doc
indent forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body r (Body r)
bod,
    Doc
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 :: MS Doc
swiftStringError = do
  Bool
tu <- MS Bool
getThrowUsed
  Bool
errdef <- MS Bool
getErrorDefined
  SwiftCode TypeData
str <- forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' MethodState ValueState
lensMStoVS (forall (r :: * -> *). TypeSym r => VSType r
string :: VSType SwiftCode)
  if Bool
tu Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
errdef then do
    forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
setErrorDefined 
    forall (f :: * -> *) a. Applicative f => a -> f a
pure (Doc
swiftExtension Doc -> Doc -> Doc
<+> forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' SwiftCode TypeData
str Doc -> Doc -> Doc
<> Doc
swiftConforms Doc -> Doc -> Doc
<+> Doc
swiftError Doc -> Doc -> Doc
<+> Doc
bodyStart Doc -> Doc -> Doc
<> Doc
bodyEnd)
  else forall (f :: * -> *) a. Applicative f => a -> f a
pure Doc
empty

swiftFunctionDoc :: FuncDocRenderer
swiftFunctionDoc :: FuncDocRenderer
swiftFunctionDoc String
desc [(String, String)]
params [String]
returns = [String
desc | Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
desc)]
  forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map (\(String
v, String
vDesc) -> String
swiftDocCommandInit forall a. [a] -> [a] -> [a]
++ String
swiftParamDoc forall a. [a] -> [a] -> [a]
++ String
" " forall a. [a] -> [a] -> [a]
++ 
    String
v forall a. [a] -> [a] -> [a]
++ String
swiftDocCommandSep forall a. [a] -> [a] -> [a]
++ String
vDesc) [(String, String)]
params
  forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map ((String
swiftDocCommandInit forall a. [a] -> [a] -> [a]
++ String
swiftRetDoc forall a. [a] -> [a] -> [a]
++ String
swiftDocCommandSep) ++) [String]
returns

swiftClassDoc :: ClassDocRenderer
swiftClassDoc :: ClassDocRenderer
swiftClassDoc String
desc = [String
desc | Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
desc)]

swiftDocCommandInit, swiftDocCommandSep, swiftParamDoc, swiftRetDoc :: String
swiftDocCommandInit :: String
swiftDocCommandInit = String
"- "
swiftDocCommandSep :: String
swiftDocCommandSep = String
": "
swiftParamDoc :: String
swiftParamDoc = String
"Parameter"
swiftRetDoc :: String
swiftRetDoc = String
"Returns"

typeDfltVal :: (RenderSym r) => CodeType -> SValue r
typeDfltVal :: forall (r :: * -> *). RenderSym r => CodeType -> SValue r
typeDfltVal CodeType
Boolean = forall (r :: * -> *). Literal r => SValue r
litFalse
typeDfltVal CodeType
Integer = forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
0
typeDfltVal CodeType
Float = forall (r :: * -> *). Literal r => Float -> SValue r
litFloat Float
0.0
typeDfltVal CodeType
Double = forall (r :: * -> *). Literal r => Double -> SValue r
litDouble Double
0.0
typeDfltVal CodeType
Char = forall (r :: * -> *). Literal r => Char -> SValue r
litChar Char
' '
typeDfltVal CodeType
String = forall (r :: * -> *). Literal r => String -> SValue r
litString String
""
typeDfltVal (List CodeType
t) = forall (r :: * -> *).
Literal r =>
VSType r -> [SValue r] -> SValue r
litList (forall (r :: * -> *). TypeSym r => CodeType -> VSType r
convType CodeType
t) []
typeDfltVal (Array CodeType
t) = forall (r :: * -> *).
Literal r =>
VSType r -> [SValue r] -> SValue r
litArray (forall (r :: * -> *). TypeSym r => CodeType -> VSType r
convType CodeType
t) []
typeDfltVal CodeType
_ = forall a. HasCallStack => String -> a
error String
"Attempt to get default value for type with none."