-- | Implementations defined here are valid in some, but not all, language renderers
module GOOL.Drasil.LanguageRenderer.CommonPseudoOO (int, constructor, doxFunc, 
  doxClass, doxMod, extVar, classVar, objVarSelf, indexOf, listAddFunc, 
  discardFileLine, intClass, funcType, buildModule, arrayType, pi, printSt, 
  arrayDec, arrayDecDef, openFileA, forEach, docMain, mainFunction, 
  buildModule', call', listSizeFunc, listAccessFunc', string, constDecDef, 
  docInOutFunc, bindingError, extFuncAppMixedArgs, notNull, listDecDef, 
  destructorError, stateVarDef, constVar, litArray, listSetFunc, extraClass, 
  listAccessFunc, doubleRender, double, openFileR, openFileW, stateVar, self, 
  multiAssign, multiReturn, listDec, funcDecDef, inOutCall, forLoopError, 
  mainBody, inOutFunc, docInOutFunc', floatRender, float, stringRender', 
  string', inherit, implements
) where

import Utils.Drasil (indent)

import GOOL.Drasil.CodeType (CodeType(..))
import GOOL.Drasil.ClassInterface (Label, Library, SFile, MSBody, VSType, 
  SVariable, SValue, VSFunction, MSStatement, MSParameter, SMethod, CSStateVar, 
  SClass, FSModule, Initializers, MixedCall, PermanenceSym(..), bodyStatements, 
  oneLiner, TypeSym(infile, outfile, listInnerType, obj), 
  TypeElim(getType, getTypeString), VariableElim(variableName, variableType), 
  ValueSym(valueType), Comparison(..), objMethodCallNoParams, (&=), 
  ControlStatement(returnStmt), ScopeSym(..), MethodSym(function))
import qualified GOOL.Drasil.ClassInterface as S (
  TypeSym(int, double, string, listType, arrayType, void),
  VariableSym(var, self, objVar), Literal(litTrue, litFalse, litList), 
  VariableValue(valueOf), FunctionSym(func, objAccess), StatementSym(valStmt), 
  DeclStatement(varDec, varDecDef, constDecDef), 
  ParameterSym(param, pointerParam), MethodSym(mainFunction), 
  ClassSym(buildClass))
import GOOL.Drasil.RendererClasses (RenderSym, ImportSym(..), RenderBody(..), 
  RenderType(..), RenderVariable(varFromData), InternalVarElim(variableBind), 
  RenderFunction(funcFromData), MethodTypeSym(mType),
  RenderMethod(intMethod, commentedFunc, mthdFromData), ParentSpec, 
  BlockCommentSym(..))
import qualified GOOL.Drasil.RendererClasses as S (RenderBody(multiBody), 
  RenderValue(call), RenderStatement(stmt), InternalAssignStmt(multiAssign), 
  InternalControlStmt(multiReturn), MethodTypeSym(construct), 
  RenderMethod(intFunc), RenderClass(intClass, inherit), RenderMod(modFromData))
import qualified GOOL.Drasil.RendererClasses as RC (ImportElim(..), 
  PermElim(..), BodyElim(..), InternalTypeElim(..), InternalVarElim(variable), 
  ValueElim(value), StatementElim(statement), ScopeElim(..), MethodElim(..), 
  StateVarElim(..), ClassElim(..))
import GOOL.Drasil.Helpers (vibcat, toCode, toState, onCodeValue, onStateValue, 
  on2StateValues, onStateList)
import GOOL.Drasil.LanguageRenderer (array', new', args, array, listSep, access,
  mathFunc, FuncDocRenderer, functionDox, classDox, moduleDox, variableList, valueList, intValue)
import qualified GOOL.Drasil.LanguageRenderer as R (self, self', module', 
  print, stateVar, stateVarList, constDecDef, extVar, listAccessFunc)
import GOOL.Drasil.LanguageRenderer.Constructors (mkStmt, mkStmtNoEnd, 
  mkStateVal, mkStateVar)
import GOOL.Drasil.LanguageRenderer.LanguagePolymorphic (classVarCheckStatic,
  call, initStmts, docFunc, docFuncRepr, docClass, docMod)
import GOOL.Drasil.AST (ScopeTag(..))
import GOOL.Drasil.State (FS, CS, lensFStoCS, lensFStoMS, lensCStoMS, 
  lensMStoVS, lensVStoMS, currParameters, getClassName, getLangImports, 
  getLibImports, getModuleImports, setClassName, setCurrMain, setMainDoc)

import Prelude hiding (print,pi,(<>))
import Data.List (sort, intercalate)
import Control.Monad (join)
import Control.Monad.State (get, modify)
import Control.Lens ((^.))
import qualified Control.Lens as L (set)
import Control.Lens.Zoom (zoom)
import Text.PrettyPrint.HughesPJ (Doc, text, empty, render, (<>), (<+>), parens,
  brackets, braces, colon, vcat, equals)

-- Python, Java, C#, and C++ --

intRender :: String
intRender :: String
intRender = "int"

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

constructor :: (RenderSym r) => Label -> [MSParameter r] -> Initializers r -> 
  MSBody r -> SMethod r
constructor :: String
-> [MSParameter r] -> Initializers r -> MSBody r -> SMethod r
constructor fName :: String
fName ps :: [MSParameter r]
ps is :: Initializers r
is b :: MSBody r
b = MS String
getClassName MS String -> (String -> SMethod r) -> SMethod r
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\c :: String
c -> Bool
-> String
-> r (Scope r)
-> r (Permanence r)
-> MSMthdType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
forall (r :: * -> *).
RenderMethod r =>
Bool
-> String
-> r (Scope r)
-> r (Permanence r)
-> MSMthdType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
intMethod Bool
False String
fName 
  r (Scope r)
forall (r :: * -> *). ScopeSym r => r (Scope r)
public r (Permanence r)
forall (r :: * -> *). PermanenceSym r => r (Permanence r)
dynamic (String -> MSMthdType r
forall (r :: * -> *). MethodTypeSym r => String -> MSMthdType r
S.construct String
c) [MSParameter r]
ps ([MSBody r] -> MSBody r
forall (r :: * -> *). RenderBody r => [MSBody r] -> MSBody r
S.multiBody [Initializers r -> MSBody r
forall (r :: * -> *). RenderSym r => Initializers r -> MSBody r
initStmts Initializers r
is, MSBody r
b]))

doxFunc :: (RenderSym r) => String -> [String] -> Maybe String -> SMethod r -> 
  SMethod r
doxFunc :: String -> [String] -> Maybe String -> SMethod r -> SMethod r
doxFunc = FuncDocRenderer
-> String -> [String] -> Maybe String -> SMethod r -> SMethod r
forall (r :: * -> *).
RenderSym r =>
FuncDocRenderer
-> String -> [String] -> Maybe String -> SMethod r -> SMethod r
docFunc FuncDocRenderer
functionDox

doxClass :: (RenderSym r) => String -> SClass r -> SClass r
doxClass :: String -> SClass r -> SClass r
doxClass = ClassDocRenderer -> String -> SClass r -> SClass r
forall (r :: * -> *).
RenderSym r =>
ClassDocRenderer -> String -> SClass r -> SClass r
docClass ClassDocRenderer
classDox

doxMod :: (RenderSym r) => String -> String -> [String] -> String -> SFile r -> 
  SFile r
doxMod :: String -> String -> [String] -> String -> SFile r -> SFile r
doxMod = ModuleDocRenderer
-> String -> String -> [String] -> String -> SFile r -> SFile r
forall (r :: * -> *).
RenderSym r =>
ModuleDocRenderer
-> String -> String -> [String] -> String -> SFile r -> SFile r
docMod ModuleDocRenderer
moduleDox

-- Python, Java, and C# --

extVar :: (RenderSym r) => Label -> Label -> VSType r -> SVariable r
extVar :: String -> String -> VSType r -> SVariable r
extVar l :: String
l n :: String
n t :: VSType r
t = String -> VSType r -> Doc -> SVariable r
forall (r :: * -> *).
RenderSym r =>
String -> VSType r -> Doc -> SVariable r
mkStateVar (String
l String -> String -> String
`access` String
n) VSType r
t (String -> String -> Doc
R.extVar String
l String
n)

classVar :: (RenderSym r) => (Doc -> Doc -> Doc) -> VSType r -> SVariable r -> 
  SVariable r
classVar :: (Doc -> Doc -> Doc) -> VSType r -> SVariable r -> SVariable r
classVar f :: Doc -> Doc -> Doc
f c' :: VSType r
c' v' :: SVariable r
v'= do 
  r (Type r)
c <- VSType r
c'
  r (Variable r)
v <- SVariable r
v'
  r (Variable r)
vr <- Binding -> String -> VSType r -> Doc -> SVariable r
forall (r :: * -> *).
RenderVariable r =>
Binding -> String -> VSType r -> Doc -> SVariable r
varFromData 
    (r (Variable r) -> Binding
forall (r :: * -> *).
InternalVarElim r =>
r (Variable r) -> Binding
variableBind r (Variable r)
v) (r (Type r) -> String
forall (r :: * -> *). TypeElim r => r (Type r) -> String
getTypeString r (Type r)
c String -> String -> String
`access` r (Variable r) -> String
forall (r :: * -> *). VariableElim r => r (Variable r) -> String
variableName r (Variable r)
v) 
    (r (Type r) -> VSType r
forall a s. a -> State s a
toState (r (Type r) -> VSType r) -> r (Type r) -> VSType r
forall a b. (a -> b) -> a -> b
$ r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
v) (Doc -> Doc -> Doc
f (r (Type r) -> Doc
forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' r (Type r)
c) (r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
v))
  r (Variable r) -> SVariable r
forall a s. a -> State s a
toState (r (Variable r) -> SVariable r) -> r (Variable r) -> SVariable r
forall a b. (a -> b) -> a -> b
$ r (Variable r) -> r (Variable r)
forall (r :: * -> *).
RenderSym r =>
r (Variable r) -> r (Variable r)
classVarCheckStatic r (Variable r)
vr
  
objVarSelf :: (RenderSym r) => SVariable r -> SVariable r
objVarSelf :: SVariable r -> SVariable r
objVarSelf = SVariable r -> SVariable r -> SVariable r
forall (r :: * -> *).
VariableSym r =>
SVariable r -> SVariable r -> SVariable r
S.objVar SVariable r
forall (r :: * -> *). VariableSym r => SVariable r
S.self

indexOf :: (RenderSym r) => Label -> SValue r -> SValue r -> SValue r
indexOf :: String -> SValue r -> SValue r -> SValue r
indexOf f :: String
f l :: SValue r
l v :: SValue r
v = SValue r -> VSFunction r -> SValue r
forall (r :: * -> *).
FunctionSym r =>
SValue r -> VSFunction r -> SValue r
S.objAccess SValue r
l (String -> VSType r -> [SValue r] -> VSFunction r
forall (r :: * -> *).
FunctionSym r =>
String -> VSType r -> [SValue r] -> VSFunction r
S.func String
f VSType r
forall (r :: * -> *). TypeSym r => VSType r
S.int [SValue r
v])

listAddFunc :: (RenderSym r) => Label -> SValue r -> SValue r -> VSFunction r
listAddFunc :: String -> SValue r -> SValue r -> VSFunction r
listAddFunc f :: String
f i :: SValue r
i v :: SValue r
v = String -> VSType r -> [SValue r] -> VSFunction r
forall (r :: * -> *).
FunctionSym r =>
String -> VSType r -> [SValue r] -> VSFunction r
S.func String
f (VSType r -> VSType r
forall (r :: * -> *). TypeSym r => VSType r -> VSType r
S.listType (VSType r -> VSType r) -> VSType r -> VSType r
forall a b. (a -> b) -> a -> b
$ (r (Value r) -> r (Type r)) -> SValue r -> VSType r
forall a b s. (a -> b) -> State s a -> State s b
onStateValue r (Value r) -> r (Type r)
forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType SValue r
v) 
  [SValue r
i, SValue r
v]
  
discardFileLine :: (RenderSym r) => Label -> SValue r -> MSStatement r
discardFileLine :: String -> SValue r -> MSStatement r
discardFileLine n :: String
n f :: SValue r
f = SValue r -> MSStatement r
forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
S.valStmt (SValue r -> MSStatement r) -> SValue r -> MSStatement r
forall a b. (a -> b) -> a -> b
$ VSType r -> SValue r -> String -> SValue r
forall (r :: * -> *).
InternalValueExp r =>
VSType r -> SValue r -> String -> SValue r
objMethodCallNoParams VSType r
forall (r :: * -> *). TypeSym r => VSType r
S.string SValue r
f String
n 

intClass :: (RenderSym r, Monad r) => (Label -> Doc -> Doc -> Doc -> Doc -> 
  Doc) -> Label -> r (Scope r) -> r ParentSpec -> [CSStateVar r] -> [SMethod r] 
  -> CS (r Doc)
intClass :: (String -> Doc -> Doc -> Doc -> Doc -> Doc)
-> String
-> r (Scope r)
-> r Doc
-> [CSStateVar r]
-> [SMethod r]
-> CS (r Doc)
intClass f :: String -> Doc -> Doc -> Doc -> Doc -> Doc
f n :: String
n s :: r (Scope r)
s i :: r Doc
i svrs :: [CSStateVar r]
svrs mths :: [SMethod r]
mths = do
  (ClassState -> ClassState) -> StateT ClassState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ClassState -> ClassState
setClassName String
n) 
  Doc
svs <- ([r (StateVar r)] -> Doc) -> [CSStateVar r] -> State ClassState Doc
forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList ([Doc] -> Doc
R.stateVarList ([Doc] -> Doc)
-> ([r (StateVar r)] -> [Doc]) -> [r (StateVar r)] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r (StateVar r) -> Doc) -> [r (StateVar r)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map r (StateVar r) -> Doc
forall (r :: * -> *). StateVarElim r => r (StateVar r) -> Doc
RC.stateVar) [CSStateVar r]
svrs
  Doc
ms <- ([r (Method r)] -> Doc)
-> [State ClassState (r (Method r))] -> State ClassState Doc
forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList ([Doc] -> Doc
vibcat ([Doc] -> Doc)
-> ([r (Method r)] -> [Doc]) -> [r (Method r)] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r (Method r) -> Doc) -> [r (Method r)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map r (Method r) -> Doc
forall (r :: * -> *). MethodElim r => r (Method r) -> Doc
RC.method) ((SMethod r -> State ClassState (r (Method r)))
-> [SMethod r] -> [State ClassState (r (Method r))]
forall a b. (a -> b) -> [a] -> [b]
map (LensLike'
  (Zoomed (StateT MethodState Identity) (r (Method r)))
  ClassState
  MethodState
-> SMethod r -> State ClassState (r (Method r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT MethodState Identity) (r (Method r)))
  ClassState
  MethodState
Lens' ClassState MethodState
lensCStoMS) [SMethod r]
mths)
  r Doc -> CS (r Doc)
forall (m :: * -> *) a. Monad m => a -> m a
return (r Doc -> CS (r Doc)) -> r Doc -> CS (r Doc)
forall a b. (a -> b) -> a -> b
$ (Doc -> Doc) -> r Doc -> r Doc
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue (\p :: Doc
p -> String -> Doc -> Doc -> Doc -> Doc -> Doc
f String
n Doc
p (r (Scope r) -> Doc
forall (r :: * -> *). ScopeElim r => r (Scope r) -> Doc
RC.scope r (Scope r)
s) Doc
svs Doc
ms) r Doc
i 

-- Python, Java, and C++ --

funcType :: (RenderSym r) => [VSType r] -> VSType r -> VSType r
funcType :: [VSType r] -> VSType r -> VSType r
funcType ps' :: [VSType r]
ps' r' :: VSType r
r' =  do 
  [r (Type r)]
ps <- [VSType r] -> StateT ValueState Identity [r (Type r)]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [VSType r]
ps'
  r (Type r)
r <- VSType r
r'
  CodeType -> String -> Doc -> VSType r
forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData ([CodeType] -> CodeType -> CodeType
Func ((r (Type r) -> CodeType) -> [r (Type r)] -> [CodeType]
forall a b. (a -> b) -> [a] -> [b]
map r (Type r) -> CodeType
forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType [r (Type r)]
ps) (r (Type r) -> CodeType
forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType r (Type r)
r)) "" Doc
empty

-- Python and C++ --

-- Parameters: Module name, Doc for imports, Doc to put at top of module (but 
-- after imports), Doc to put at bottom of module, methods, classes
buildModule :: (RenderSym r) => Label -> FS Doc -> FS Doc -> FS Doc -> 
  [SMethod r] -> [SClass r] -> FSModule r
buildModule :: String
-> FS Doc
-> FS Doc
-> FS Doc
-> [SMethod r]
-> [SClass r]
-> FSModule r
buildModule n :: String
n imps :: FS Doc
imps top :: FS Doc
top bot :: FS Doc
bot fs :: [SMethod r]
fs cs :: [SClass r]
cs = String -> FS Doc -> FSModule r
forall (r :: * -> *). RenderMod r => String -> FS Doc -> FSModule r
S.modFromData String
n (do
  [r (Class r)]
cls <- (SClass r -> StateT FileState Identity (r (Class r)))
-> [SClass r] -> StateT FileState Identity [r (Class r)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (LensLike'
  (Zoomed (StateT ClassState Identity) (r (Class r)))
  FileState
  ClassState
-> SClass r -> StateT FileState Identity (r (Class r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ClassState Identity) (r (Class r)))
  FileState
  ClassState
Lens' FileState ClassState
lensFStoCS) [SClass r]
cs
  [r (Method r)]
fns <- (SMethod r -> StateT FileState Identity (r (Method r)))
-> [SMethod r] -> StateT FileState Identity [r (Method r)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (LensLike'
  (Zoomed (StateT MethodState Identity) (r (Method r)))
  FileState
  MethodState
-> SMethod r -> StateT FileState Identity (r (Method r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT MethodState Identity) (r (Method r)))
  FileState
  MethodState
Lens' FileState MethodState
lensFStoMS) [SMethod r]
fs
  Doc
is <- FS Doc
imps
  Doc
tp <- FS Doc
top
  Doc
bt <- FS Doc
bot
  Doc -> FS Doc
forall (m :: * -> *) a. Monad m => a -> m a
return (Doc -> FS Doc) -> Doc -> FS Doc
forall a b. (a -> b) -> a -> b
$ Doc -> Doc -> Doc -> Doc
R.module' Doc
is ([Doc] -> Doc
vibcat (Doc
tp Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
: (r (Class r) -> Doc) -> [r (Class r)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map r (Class r) -> Doc
forall (r :: * -> *). ClassElim r => r (Class r) -> Doc
RC.class' [r (Class r)]
cls)) 
    ([Doc] -> Doc
vibcat ((r (Method r) -> Doc) -> [r (Method r)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map r (Method r) -> Doc
forall (r :: * -> *). MethodElim r => r (Method r) -> Doc
RC.method [r (Method r)]
fns [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ [Doc
bt])))

-- Java and C# -- 

arrayType :: (RenderSym r) => VSType r -> VSType r
arrayType :: VSType r -> VSType r
arrayType t' :: VSType r
t' = do 
  r (Type r)
t <- VSType r
t'
  CodeType -> String -> Doc -> VSType r
forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData (CodeType -> CodeType
Array (r (Type r) -> CodeType
forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType r (Type r)
t)) 
    (r (Type r) -> String
forall (r :: * -> *). TypeElim r => r (Type r) -> String
getTypeString r (Type r)
t String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
array) (r (Type r) -> Doc
forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' r (Type r)
t Doc -> Doc -> Doc
<> Doc -> Doc
brackets Doc
empty)
  
pi :: (RenderSym r) => SValue r
pi :: SValue r
pi = VSType r -> Doc -> SValue r
forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal VSType r
forall (r :: * -> *). TypeSym r => VSType r
S.double (String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ String -> String
mathFunc "PI")

printSt :: (RenderSym r) => SValue r -> SValue r -> MSStatement r
printSt :: SValue r -> SValue r -> MSStatement r
printSt va' :: SValue r
va' vb' :: SValue r
vb' = do
  r (Value r)
va <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> SValue r -> StateT MethodState Identity (r (Value r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS SValue r
va'
  r (Value r)
vb <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> SValue r -> StateT MethodState Identity (r (Value r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS SValue r
vb' 
  Doc -> MSStatement r
forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmt (r (Value r) -> r (Value r) -> Doc
forall (r :: * -> *).
RenderSym r =>
r (Value r) -> r (Value r) -> Doc
R.print r (Value r)
va r (Value r)
vb)

arrayDec :: (RenderSym r) => SValue r -> SVariable r -> MSStatement r
arrayDec :: SValue r -> SVariable r -> MSStatement r
arrayDec n :: SValue r
n vr :: SVariable r
vr = do
  r (Value r)
sz <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> SValue r -> StateT MethodState Identity (r (Value r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS SValue r
n 
  r (Variable r)
v <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
-> SVariable r -> StateT MethodState Identity (r (Variable r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS SVariable r
vr 
  let tp :: r (Type r)
tp = r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
v
  r (Type r)
innerTp <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Type r)))
  MethodState
  ValueState
-> StateT ValueState Identity (r (Type r))
-> StateT MethodState Identity (r (Type r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Type r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS (StateT ValueState Identity (r (Type r))
 -> StateT MethodState Identity (r (Type r)))
-> StateT ValueState Identity (r (Type r))
-> StateT MethodState Identity (r (Type r))
forall a b. (a -> b) -> a -> b
$ StateT ValueState Identity (r (Type r))
-> StateT ValueState Identity (r (Type r))
forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listInnerType (StateT ValueState Identity (r (Type r))
 -> StateT ValueState Identity (r (Type r)))
-> StateT ValueState Identity (r (Type r))
-> StateT ValueState Identity (r (Type r))
forall a b. (a -> b) -> a -> b
$ r (Type r) -> StateT ValueState Identity (r (Type r))
forall (m :: * -> *) a. Monad m => a -> m a
return r (Type r)
tp
  Doc -> MSStatement r
forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmt (Doc -> MSStatement r) -> Doc -> MSStatement r
forall a b. (a -> b) -> a -> b
$ r (Type r) -> Doc
forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' r (Type r)
tp Doc -> Doc -> Doc
<+> r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
v Doc -> Doc -> Doc
<+> Doc
equals Doc -> Doc -> Doc
<+> Doc
new' Doc -> Doc -> Doc
<+> 
    r (Type r) -> Doc
forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' r (Type r)
innerTp Doc -> Doc -> Doc
<> Doc -> Doc
brackets (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
sz)

arrayDecDef :: (RenderSym r) => SVariable r -> [SValue r] -> MSStatement r
arrayDecDef :: SVariable r -> [SValue r] -> MSStatement r
arrayDecDef v' :: SVariable r
v' vals' :: [SValue r]
vals' = do 
  [r (Value r)]
vs <- (SValue r -> StateT MethodState Identity (r (Value r)))
-> [SValue r] -> StateT MethodState Identity [r (Value r)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> SValue r -> StateT MethodState Identity (r (Value r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS) [SValue r]
vals'
  r (Statement r)
vd <- SVariable r -> MSStatement r
forall (r :: * -> *).
DeclStatement r =>
SVariable r -> MSStatement r
S.varDec SVariable r
v'
  Doc -> MSStatement r
forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmt (r (Statement r) -> Doc
forall (r :: * -> *). StatementElim r => r (Statement r) -> Doc
RC.statement r (Statement r)
vd Doc -> Doc -> Doc
<+> Doc
equals Doc -> Doc -> Doc
<+> Doc -> Doc
braces ([r (Value r)] -> Doc
forall (r :: * -> *). RenderSym r => [r (Value r)] -> Doc
valueList [r (Value r)]
vs))

openFileA :: (RenderSym r) => (SValue r -> VSType r -> SValue r -> SValue r) -> 
  SVariable r -> SValue r -> MSStatement r
openFileA :: (SValue r -> VSType r -> SValue r -> SValue r)
-> SVariable r -> SValue r -> MSStatement r
openFileA f :: SValue r -> VSType r -> SValue r -> SValue r
f vr :: SVariable r
vr vl :: SValue r
vl = SVariable r
vr SVariable r -> SValue r -> MSStatement r
forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= SValue r -> VSType r -> SValue r -> SValue r
f SValue r
vl VSType r
forall (r :: * -> *). TypeSym r => VSType r
outfile SValue r
forall (r :: * -> *). Literal r => SValue r
S.litTrue

forEach :: (RenderSym r) => Doc -> Doc -> Doc -> Doc -> SVariable r -> SValue r 
  -> MSBody r -> MSStatement r
forEach :: Doc
-> Doc
-> Doc
-> Doc
-> SVariable r
-> SValue r
-> MSBody r
-> MSStatement r
forEach bStart :: Doc
bStart bEnd :: Doc
bEnd forEachLabel :: Doc
forEachLabel inLbl :: Doc
inLbl e' :: SVariable r
e' v' :: SValue r
v' b' :: MSBody r
b' = do
  r (Variable r)
e <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
-> SVariable r -> StateT MethodState Identity (r (Variable r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS SVariable r
e'
  r (Value r)
v <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> SValue r -> StateT MethodState Identity (r (Value r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS SValue r
v'
  r (Body r)
b <- MSBody r
b'
  Doc -> MSStatement r
forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmtNoEnd (Doc -> MSStatement r) -> Doc -> MSStatement r
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vcat [
    Doc
forEachLabel Doc -> Doc -> Doc
<+> Doc -> Doc
parens (r (Type r) -> Doc
forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' (r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
e) Doc -> Doc -> Doc
<+> r (Variable r) -> Doc
forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
e Doc -> Doc -> Doc
<+> 
      Doc
inLbl Doc -> Doc -> Doc
<+> r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
v) Doc -> Doc -> Doc
<+> Doc
bStart,
    Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ r (Body r) -> Doc
forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body r (Body r)
b,
    Doc
bEnd] 

mainDesc, argsDesc :: String
mainDesc :: String
mainDesc = "Controls the flow of the program" 
argsDesc :: String
argsDesc = "List of command-line arguments"

docMain :: (RenderSym r) => MSBody r -> SMethod r
docMain :: MSBody r -> SMethod r
docMain b :: MSBody r
b = MS (r (BlockComment r)) -> SMethod r -> SMethod r
forall (r :: * -> *).
RenderMethod r =>
MS (r (BlockComment r)) -> SMethod r -> SMethod r
commentedFunc (State MethodState [String] -> MS (r (BlockComment r))
forall (r :: * -> *) a.
BlockCommentSym r =>
State a [String] -> State a (r (BlockComment r))
docComment (State MethodState [String] -> MS (r (BlockComment r)))
-> State MethodState [String] -> MS (r (BlockComment r))
forall a b. (a -> b) -> a -> b
$ [String] -> State MethodState [String]
forall a s. a -> State s a
toState ([String] -> State MethodState [String])
-> [String] -> State MethodState [String]
forall a b. (a -> b) -> a -> b
$ FuncDocRenderer
functionDox 
  String
mainDesc [(String
args, String
argsDesc)] []) (MSBody r -> SMethod r
forall (r :: * -> *). MethodSym r => MSBody r -> SMethod r
S.mainFunction MSBody r
b)

mainFunction :: (RenderSym r) => VSType r -> Label -> MSBody r -> SMethod r
mainFunction :: VSType r -> String -> MSBody r -> SMethod r
mainFunction s :: VSType r
s n :: String
n = Bool
-> String
-> r (Scope r)
-> r (Permanence r)
-> MSMthdType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
forall (r :: * -> *).
RenderMethod r =>
Bool
-> String
-> r (Scope r)
-> r (Permanence r)
-> MSMthdType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
S.intFunc Bool
True String
n r (Scope r)
forall (r :: * -> *). ScopeSym r => r (Scope r)
public r (Permanence r)
forall (r :: * -> *). PermanenceSym r => r (Permanence r)
static (VSType r -> MSMthdType r
forall (r :: * -> *). MethodTypeSym r => VSType r -> MSMthdType r
mType VSType r
forall (r :: * -> *). TypeSym r => VSType r
S.void)
  [SVariable r -> MSParameter r
forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
S.param (String -> VSType r -> SVariable r
forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
S.var String
args (VSType r
s VSType r -> (r (Type r) -> VSType r) -> VSType r
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\argT :: r (Type r)
argT -> CodeType -> String -> Doc -> VSType r
forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData (CodeType -> CodeType
List CodeType
String) 
  (Doc -> String
render (r (Type r) -> Doc
forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' r (Type r)
argT) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
array) (r (Type r) -> Doc
forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' r (Type r)
argT Doc -> Doc -> Doc
<> Doc
array'))))]

buildModule' :: (RenderSym r) => Label -> (String -> r (Import r)) -> [Label] 
  -> [SMethod r] -> [SClass r] -> FSModule r
buildModule' :: String
-> (String -> r (Import r))
-> [String]
-> [SMethod r]
-> [SClass r]
-> FSModule r
buildModule' n :: String
n inc :: String -> r (Import r)
inc is :: [String]
is ms :: [SMethod r]
ms cs :: [SClass r]
cs = String -> FS Doc -> FSModule r
forall (r :: * -> *). RenderMod r => String -> FS Doc -> FSModule r
S.modFromData String
n (do
  [r (Class r)]
cls <- (SClass r -> StateT FileState Identity (r (Class r)))
-> [SClass r] -> StateT FileState Identity [r (Class r)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (LensLike'
  (Zoomed (StateT ClassState Identity) (r (Class r)))
  FileState
  ClassState
-> SClass r -> StateT FileState Identity (r (Class r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ClassState Identity) (r (Class r)))
  FileState
  ClassState
Lens' FileState ClassState
lensFStoCS) 
          (if [SMethod r] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [SMethod r]
ms then [SClass r]
cs else Maybe String -> [CSStateVar r] -> [SMethod r] -> SClass r
forall (r :: * -> *).
ClassSym r =>
Maybe String -> [CSStateVar r] -> [SMethod r] -> SClass r
S.buildClass Maybe String
forall a. Maybe a
Nothing [] [SMethod r]
ms SClass r -> [SClass r] -> [SClass r]
forall a. a -> [a] -> [a]
: [SClass r]
cs) 
  [String]
lis <- FS [String]
getLangImports
  [String]
libis <- FS [String]
getLibImports
  [String]
mis <- FS [String]
getModuleImports
  Doc -> FS Doc
forall (m :: * -> *) a. Monad m => a -> m a
return (Doc -> FS Doc) -> Doc -> FS Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vibcat [
    [Doc] -> Doc
vcat ((String -> Doc) -> [String] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (r (Import r) -> Doc
forall (r :: * -> *). ImportElim r => r (Import r) -> Doc
RC.import' (r (Import r) -> Doc) -> (String -> r (Import r)) -> String -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> r (Import r)
inc) ([String]
lis [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String] -> [String]
forall a. Ord a => [a] -> [a]
sort ([String]
is [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
libis) [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
mis)),
    [Doc] -> Doc
vibcat ((r (Class r) -> Doc) -> [r (Class r)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map r (Class r) -> Doc
forall (r :: * -> *). ClassElim r => r (Class r) -> Doc
RC.class' [r (Class r)]
cls)])

-- Java and C++ --

-- | First parameter is language name, rest similar to call from ClassInterface
call' :: (RenderSym r) => String -> Maybe Library -> Maybe Doc -> MixedCall r
call' :: String -> Maybe String -> Maybe Doc -> MixedCall r
call' l :: String
l _ _ _ _ _ (_:_) = String -> SValue r
forall a. HasCallStack => String -> a
error (String -> SValue r) -> String -> SValue r
forall a b. (a -> b) -> a -> b
$ String -> String
namedArgError String
l
call' _ l :: Maybe String
l o :: Maybe Doc
o n :: String
n t :: VSType r
t ps :: [SValue r]
ps ns :: [(SVariable r, SValue r)]
ns = Doc -> Maybe String -> Maybe Doc -> MixedCall r
forall (r :: * -> *).
RenderSym r =>
Doc -> Maybe String -> Maybe Doc -> MixedCall r
call Doc
empty Maybe String
l Maybe Doc
o String
n VSType r
t [SValue r]
ps [(SVariable r, SValue r)]
ns

namedArgError :: String -> String
namedArgError :: String -> String
namedArgError l :: String
l = "Named arguments not supported in " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
l 

listSizeFunc :: (RenderSym r) => VSFunction r
listSizeFunc :: VSFunction r
listSizeFunc = String -> VSType r -> [SValue r] -> VSFunction r
forall (r :: * -> *).
FunctionSym r =>
String -> VSType r -> [SValue r] -> VSFunction r
S.func "size" VSType r
forall (r :: * -> *). TypeSym r => VSType r
S.int []

listAccessFunc' :: (RenderSym r) => Label -> VSType r -> SValue r -> 
  VSFunction r
listAccessFunc' :: String -> VSType r -> SValue r -> VSFunction r
listAccessFunc' f :: String
f t :: VSType r
t i :: SValue r
i = String -> VSType r -> [SValue r] -> VSFunction r
forall (r :: * -> *).
FunctionSym r =>
String -> VSType r -> [SValue r] -> VSFunction r
S.func String
f VSType r
t [SValue r -> SValue r
forall (r :: * -> *). RenderSym r => SValue r -> SValue r
intValue SValue r
i]

-- C# and C++ --

stringRender :: String
stringRender :: String
stringRender = "string"

string :: (RenderSym r) => VSType r
string :: VSType r
string = CodeType -> String -> Doc -> VSType r
forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData CodeType
String String
stringRender (String -> Doc
text String
stringRender)

constDecDef :: (RenderSym r) => SVariable r -> SValue r -> MSStatement r
constDecDef :: SVariable r -> SValue r -> MSStatement r
constDecDef vr' :: SVariable r
vr' v' :: SValue r
v'= do
  r (Variable r)
vr <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
-> SVariable r -> StateT MethodState Identity (r (Variable r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS SVariable r
vr'
  r (Value r)
v <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> SValue r -> StateT MethodState Identity (r (Value r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS SValue r
v'
  Doc -> MSStatement r
forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmt (r (Variable r) -> r (Value r) -> Doc
forall (r :: * -> *).
RenderSym r =>
r (Variable r) -> r (Value r) -> Doc
R.constDecDef r (Variable r)
vr r (Value r)
v)
  
docInOutFunc :: (RenderSym r) => ([SVariable r] -> [SVariable r] -> 
    [SVariable r] -> MSBody r -> SMethod r) -> 
  String -> [(String, SVariable r)] -> [(String, SVariable r)] -> 
  [(String, SVariable r)] -> MSBody r -> SMethod r
docInOutFunc :: ([SVariable r]
 -> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r)
-> String
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> MSBody r
-> SMethod r
docInOutFunc f :: [SVariable r]
-> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r
f desc :: String
desc is :: [(String, SVariable r)]
is [o :: (String, SVariable r)
o] [] b :: MSBody r
b = FuncDocRenderer
-> String -> [String] -> [String] -> SMethod r -> SMethod r
forall (r :: * -> *).
RenderSym r =>
FuncDocRenderer
-> String -> [String] -> [String] -> SMethod r -> SMethod r
docFuncRepr FuncDocRenderer
functionDox String
desc (((String, SVariable r) -> String)
-> [(String, SVariable r)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String, SVariable r) -> String
forall a b. (a, b) -> a
fst [(String, SVariable r)]
is) 
  [(String, SVariable r) -> String
forall a b. (a, b) -> a
fst (String, SVariable r)
o] ([SVariable r]
-> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r
f (((String, SVariable r) -> SVariable r)
-> [(String, SVariable r)] -> [SVariable r]
forall a b. (a -> b) -> [a] -> [b]
map (String, SVariable r) -> SVariable r
forall a b. (a, b) -> b
snd [(String, SVariable r)]
is) [(String, SVariable r) -> SVariable r
forall a b. (a, b) -> b
snd (String, SVariable r)
o] [] MSBody r
b)
docInOutFunc f :: [SVariable r]
-> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r
f desc :: String
desc is :: [(String, SVariable r)]
is [] [both :: (String, SVariable r)
both] b :: MSBody r
b = FuncDocRenderer
-> String -> [String] -> [String] -> SMethod r -> SMethod r
forall (r :: * -> *).
RenderSym r =>
FuncDocRenderer
-> String -> [String] -> [String] -> SMethod r -> SMethod r
docFuncRepr FuncDocRenderer
functionDox String
desc (((String, SVariable r) -> String)
-> [(String, SVariable r)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String, SVariable r) -> String
forall a b. (a, b) -> a
fst ([(String, SVariable r)] -> [String])
-> [(String, SVariable r)] -> [String]
forall a b. (a -> b) -> a -> b
$ 
  (String, SVariable r)
both (String, SVariable r)
-> [(String, SVariable r)] -> [(String, SVariable r)]
forall a. a -> [a] -> [a]
: [(String, SVariable r)]
is) [(String, SVariable r) -> String
forall a b. (a, b) -> a
fst (String, SVariable r)
both] ([SVariable r]
-> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r
f (((String, SVariable r) -> SVariable r)
-> [(String, SVariable r)] -> [SVariable r]
forall a b. (a -> b) -> [a] -> [b]
map (String, SVariable r) -> SVariable r
forall a b. (a, b) -> b
snd [(String, SVariable r)]
is) [] [(String, SVariable r) -> SVariable r
forall a b. (a, b) -> b
snd (String, SVariable r)
both] MSBody r
b)
docInOutFunc f :: [SVariable r]
-> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r
f desc :: String
desc is :: [(String, SVariable r)]
is os :: [(String, SVariable r)]
os bs :: [(String, SVariable r)]
bs b :: MSBody r
b = FuncDocRenderer
-> String -> [String] -> [String] -> SMethod r -> SMethod r
forall (r :: * -> *).
RenderSym r =>
FuncDocRenderer
-> String -> [String] -> [String] -> SMethod r -> SMethod r
docFuncRepr FuncDocRenderer
functionDox String
desc (((String, SVariable r) -> String)
-> [(String, SVariable r)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String, SVariable r) -> String
forall a b. (a, b) -> a
fst ([(String, SVariable r)] -> [String])
-> [(String, SVariable r)] -> [String]
forall a b. (a -> b) -> a -> b
$ [(String, SVariable r)]
bs [(String, SVariable r)]
-> [(String, SVariable r)] -> [(String, SVariable r)]
forall a. [a] -> [a] -> [a]
++ 
  [(String, SVariable r)]
is [(String, SVariable r)]
-> [(String, SVariable r)] -> [(String, SVariable r)]
forall a. [a] -> [a] -> [a]
++ [(String, SVariable r)]
os) [] ([SVariable r]
-> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r
f (((String, SVariable r) -> SVariable r)
-> [(String, SVariable r)] -> [SVariable r]
forall a b. (a -> b) -> [a] -> [b]
map (String, SVariable r) -> SVariable r
forall a b. (a, b) -> b
snd [(String, SVariable r)]
is) (((String, SVariable r) -> SVariable r)
-> [(String, SVariable r)] -> [SVariable r]
forall a b. (a -> b) -> [a] -> [b]
map (String, SVariable r) -> SVariable r
forall a b. (a, b) -> b
snd [(String, SVariable r)]
os) (((String, SVariable r) -> SVariable r)
-> [(String, SVariable r)] -> [SVariable r]
forall a b. (a -> b) -> [a] -> [b]
map (String, SVariable r) -> SVariable r
forall a b. (a, b) -> b
snd [(String, SVariable r)]
bs) MSBody r
b)

-- Python, Java, C#, and Swift --

bindingError :: String -> String
bindingError :: String -> String
bindingError l :: String
l = "Binding unimplemented in " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
l

extFuncAppMixedArgs :: (RenderSym r) => Library -> MixedCall r
extFuncAppMixedArgs :: String -> MixedCall r
extFuncAppMixedArgs l :: String
l = Maybe String -> Maybe Doc -> MixedCall r
forall (r :: * -> *).
RenderValue r =>
Maybe String -> Maybe Doc -> MixedCall r
S.call (String -> Maybe String
forall a. a -> Maybe a
Just String
l) Maybe Doc
forall a. Maybe a
Nothing

notNull :: (RenderSym r) => String -> SValue r -> SValue r
notNull :: String -> SValue r -> SValue r
notNull nil :: String
nil v :: SValue r
v = SValue r
v SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?!= SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
S.valueOf (String -> VSType r -> SVariable r
forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
S.var String
nil (VSType r -> SVariable r) -> VSType r -> SVariable r
forall a b. (a -> b) -> a -> b
$ (r (Value r) -> r (Type r)) -> SValue r -> VSType r
forall a b s. (a -> b) -> State s a -> State s b
onStateValue r (Value r) -> r (Type r)
forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType SValue r
v)

listDecDef :: (RenderSym r) => SVariable r -> [SValue r] -> MSStatement r
listDecDef :: SVariable r -> [SValue r] -> MSStatement r
listDecDef v :: SVariable r
v vals :: [SValue r]
vals = do
  r (Variable r)
vr <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
-> SVariable r -> StateT MethodState Identity (r (Variable r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS SVariable r
v 
  let lst :: SValue r
lst = VSType r -> [SValue r] -> SValue r
forall (r :: * -> *).
Literal r =>
VSType r -> [SValue r] -> SValue r
S.litList (VSType r -> VSType r
forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listInnerType (VSType r -> VSType r) -> VSType r -> VSType r
forall a b. (a -> b) -> a -> b
$ r (Type r) -> VSType r
forall (m :: * -> *) a. Monad m => a -> m a
return (r (Type r) -> VSType r) -> r (Type r) -> VSType r
forall a b. (a -> b) -> a -> b
$ r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
vr) [SValue r]
vals
  SVariable r -> SValue r -> MSStatement r
forall (r :: * -> *).
DeclStatement r =>
SVariable r -> SValue r -> MSStatement r
S.varDecDef (r (Variable r) -> SVariable r
forall (m :: * -> *) a. Monad m => a -> m a
return r (Variable r)
vr) SValue r
lst

destructorError :: String -> String
destructorError :: String -> String
destructorError l :: String
l = "Destructors not allowed in " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
l

stateVarDef :: (RenderSym r, Monad r) => r (Scope r) -> r (Permanence r) -> 
  SVariable r -> SValue r -> CS (r Doc)
stateVarDef :: r (Scope r)
-> r (Permanence r) -> SVariable r -> SValue r -> CS (r Doc)
stateVarDef s :: r (Scope r)
s p :: r (Permanence r)
p vr :: SVariable r
vr vl :: SValue r
vl = LensLike'
  (Zoomed (StateT MethodState Identity) (r Doc))
  ClassState
  MethodState
-> StateT MethodState Identity (r Doc) -> CS (r Doc)
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT MethodState Identity) (r Doc))
  ClassState
  MethodState
Lens' ClassState MethodState
lensCStoMS (StateT MethodState Identity (r Doc) -> CS (r Doc))
-> StateT MethodState Identity (r Doc) -> CS (r Doc)
forall a b. (a -> b) -> a -> b
$ (r (Statement r) -> r Doc)
-> State MethodState (r (Statement r))
-> StateT MethodState Identity (r Doc)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue (Doc -> r Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> r Doc)
-> (r (Statement r) -> Doc) -> r (Statement r) -> r Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc -> Doc -> Doc
R.stateVar 
  (r (Scope r) -> Doc
forall (r :: * -> *). ScopeElim r => r (Scope r) -> Doc
RC.scope r (Scope r)
s) (r (Permanence r) -> Doc
forall (r :: * -> *). PermElim r => r (Permanence r) -> Doc
RC.perm r (Permanence r)
p) (Doc -> Doc) -> (r (Statement r) -> Doc) -> r (Statement r) -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r (Statement r) -> Doc
forall (r :: * -> *). StatementElim r => r (Statement r) -> Doc
RC.statement) (State MethodState (r (Statement r))
-> State MethodState (r (Statement r))
forall (r :: * -> *).
RenderStatement r =>
MSStatement r -> MSStatement r
S.stmt (State MethodState (r (Statement r))
 -> State MethodState (r (Statement r)))
-> State MethodState (r (Statement r))
-> State MethodState (r (Statement r))
forall a b. (a -> b) -> a -> b
$ SVariable r -> SValue r -> State MethodState (r (Statement r))
forall (r :: * -> *).
DeclStatement r =>
SVariable r -> SValue r -> MSStatement r
S.varDecDef SVariable r
vr SValue r
vl)
  
constVar :: (RenderSym r, Monad r) => Doc -> r (Scope r) -> SVariable r -> 
  SValue r -> CS (r Doc)
constVar :: Doc -> r (Scope r) -> SVariable r -> SValue r -> CS (r Doc)
constVar p :: Doc
p s :: r (Scope r)
s vr :: SVariable r
vr vl :: SValue r
vl = LensLike'
  (Zoomed (StateT MethodState Identity) (r Doc))
  ClassState
  MethodState
-> StateT MethodState Identity (r Doc) -> CS (r Doc)
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT MethodState Identity) (r Doc))
  ClassState
  MethodState
Lens' ClassState MethodState
lensCStoMS (StateT MethodState Identity (r Doc) -> CS (r Doc))
-> StateT MethodState Identity (r Doc) -> CS (r Doc)
forall a b. (a -> b) -> a -> b
$ (r (Statement r) -> r Doc)
-> State MethodState (r (Statement r))
-> StateT MethodState Identity (r Doc)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue (Doc -> r Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> r Doc)
-> (r (Statement r) -> Doc) -> r (Statement r) -> r Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc -> Doc -> Doc
R.stateVar 
  (r (Scope r) -> Doc
forall (r :: * -> *). ScopeElim r => r (Scope r) -> Doc
RC.scope r (Scope r)
s) Doc
p (Doc -> Doc) -> (r (Statement r) -> Doc) -> r (Statement r) -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r (Statement r) -> Doc
forall (r :: * -> *). StatementElim r => r (Statement r) -> Doc
RC.statement) (State MethodState (r (Statement r))
-> State MethodState (r (Statement r))
forall (r :: * -> *).
RenderStatement r =>
MSStatement r -> MSStatement r
S.stmt (State MethodState (r (Statement r))
 -> State MethodState (r (Statement r)))
-> State MethodState (r (Statement r))
-> State MethodState (r (Statement r))
forall a b. (a -> b) -> a -> b
$ SVariable r -> SValue r -> State MethodState (r (Statement r))
forall (r :: * -> *).
DeclStatement r =>
SVariable r -> SValue r -> MSStatement r
S.constDecDef SVariable r
vr SValue r
vl)

-- Python, Java, C++, and Swift --

litArray :: (RenderSym r) => (Doc -> Doc) -> VSType r -> [SValue r] -> SValue r
litArray :: (Doc -> Doc) -> VSType r -> [SValue r] -> SValue r
litArray f :: Doc -> Doc
f t :: VSType r
t es :: [SValue r]
es = [SValue r] -> StateT ValueState Identity [r (Value r)]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [SValue r]
es StateT ValueState Identity [r (Value r)]
-> ([r (Value r)] -> SValue r) -> SValue r
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\elems :: [r (Value r)]
elems -> VSType r -> Doc -> SValue r
forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal (VSType r -> VSType r
forall (r :: * -> *). TypeSym r => VSType r -> VSType r
S.arrayType VSType r
t) 
  (Doc -> Doc
f (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [r (Value r)] -> Doc
forall (r :: * -> *). RenderSym r => [r (Value r)] -> Doc
valueList [r (Value r)]
elems))

-- Python, C#, C++, and Swift --

listSetFunc :: (RenderSym r) => (Doc -> Doc -> Doc) -> SValue r -> SValue r -> 
  SValue r -> VSFunction r
listSetFunc :: (Doc -> Doc -> Doc)
-> SValue r -> SValue r -> SValue r -> VSFunction r
listSetFunc f :: Doc -> Doc -> Doc
f v :: SValue r
v idx :: SValue r
idx setVal :: SValue r
setVal = StateT ValueState Identity (VSFunction r) -> VSFunction r
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (StateT ValueState Identity (VSFunction r) -> VSFunction r)
-> StateT ValueState Identity (VSFunction r) -> VSFunction r
forall a b. (a -> b) -> a -> b
$ (r (Value r) -> r (Value r) -> VSFunction r)
-> SValue r
-> SValue r
-> StateT ValueState Identity (VSFunction r)
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues (\i :: r (Value r)
i toVal :: r (Value r)
toVal -> Doc -> VSType r -> VSFunction r
forall (r :: * -> *).
RenderFunction r =>
Doc -> VSType r -> VSFunction r
funcFromData 
  (Doc -> Doc -> Doc
f (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
i) (r (Value r) -> Doc
forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
toVal)) ((r (Value r) -> r (Type r)) -> SValue r -> VSType r
forall a b s. (a -> b) -> State s a -> State s b
onStateValue r (Value r) -> r (Type r)
forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType SValue r
v)) (SValue r -> SValue r
forall (r :: * -> *). RenderSym r => SValue r -> SValue r
intValue SValue r
idx) 
  SValue r
setVal

extraClass :: (RenderSym r) =>  Label -> Maybe Label -> [CSStateVar r] -> 
  [SMethod r] -> SClass r
extraClass :: String -> Maybe String -> [CSStateVar r] -> [SMethod r] -> SClass r
extraClass n :: String
n = String
-> r (Scope r)
-> r Doc
-> [CSStateVar r]
-> [SMethod r]
-> SClass r
forall (r :: * -> *).
RenderClass r =>
String
-> r (Scope r)
-> r Doc
-> [CSStateVar r]
-> [SMethod r]
-> SClass r
S.intClass String
n r (Scope r)
forall (r :: * -> *). ScopeSym r => r (Scope r)
public (r Doc -> [CSStateVar r] -> [SMethod r] -> SClass r)
-> (Maybe String -> r Doc)
-> Maybe String
-> [CSStateVar r]
-> [SMethod r]
-> SClass r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe String -> r Doc
forall (r :: * -> *). RenderClass r => Maybe String -> r Doc
S.inherit

-- Python, C#, and Swift --

listAccessFunc :: (RenderSym r) => VSType r -> SValue r -> VSFunction r
listAccessFunc :: VSType r -> SValue r -> VSFunction r
listAccessFunc t :: VSType r
t v :: SValue r
v = SValue r -> SValue r
forall (r :: * -> *). RenderSym r => SValue r -> SValue r
intValue SValue r
v SValue r -> (r (Value r) -> VSFunction r) -> VSFunction r
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ((Doc -> VSType r -> VSFunction r
forall (r :: * -> *).
RenderFunction r =>
Doc -> VSType r -> VSFunction r
`funcFromData` VSType r
t) (Doc -> VSFunction r)
-> (r (Value r) -> Doc) -> r (Value r) -> VSFunction r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r (Value r) -> Doc
forall (r :: * -> *). RenderSym r => r (Value r) -> Doc
R.listAccessFunc)

-- Java, C#, and Swift --

doubleRender :: String
doubleRender :: String
doubleRender = "Double"

double :: (RenderSym r) => VSType r
double :: VSType r
double = CodeType -> String -> Doc -> VSType r
forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData CodeType
Double String
doubleRender (String -> Doc
text String
doubleRender)

openFileR :: (RenderSym r) => (SValue r -> VSType r -> SValue r) -> SVariable r 
  -> SValue r -> MSStatement r
openFileR :: (SValue r -> VSType r -> SValue r)
-> SVariable r -> SValue r -> MSStatement r
openFileR f :: SValue r -> VSType r -> SValue r
f vr :: SVariable r
vr vl :: SValue r
vl = SVariable r
vr SVariable r -> SValue r -> MSStatement r
forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= SValue r -> VSType r -> SValue r
f SValue r
vl VSType r
forall (r :: * -> *). TypeSym r => VSType r
infile

openFileW :: (RenderSym r) => (SValue r -> VSType r -> SValue r -> SValue r) -> 
  SVariable r -> SValue r -> MSStatement r
openFileW :: (SValue r -> VSType r -> SValue r -> SValue r)
-> SVariable r -> SValue r -> MSStatement r
openFileW f :: SValue r -> VSType r -> SValue r -> SValue r
f vr :: SVariable r
vr vl :: SValue r
vl = SVariable r
vr SVariable r -> SValue r -> MSStatement r
forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= SValue r -> VSType r -> SValue r -> SValue r
f SValue r
vl VSType r
forall (r :: * -> *). TypeSym r => VSType r
outfile SValue r
forall (r :: * -> *). Literal r => SValue r
S.litFalse

stateVar :: (RenderSym r, Monad r) => r (Scope r) -> r (Permanence r) -> 
  SVariable r -> CS (r Doc)
stateVar :: r (Scope r) -> r (Permanence r) -> SVariable r -> CS (r Doc)
stateVar s :: r (Scope r)
s p :: r (Permanence r)
p v :: SVariable r
v = LensLike'
  (Zoomed (StateT MethodState Identity) (r Doc))
  ClassState
  MethodState
-> StateT MethodState Identity (r Doc) -> CS (r Doc)
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT MethodState Identity) (r Doc))
  ClassState
  MethodState
Lens' ClassState MethodState
lensCStoMS (StateT MethodState Identity (r Doc) -> CS (r Doc))
-> StateT MethodState Identity (r Doc) -> CS (r Doc)
forall a b. (a -> b) -> a -> b
$ (r (Statement r) -> r Doc)
-> State MethodState (r (Statement r))
-> StateT MethodState Identity (r Doc)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue (Doc -> r Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> r Doc)
-> (r (Statement r) -> Doc) -> r (Statement r) -> r Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc -> Doc -> Doc
R.stateVar 
  (r (Scope r) -> Doc
forall (r :: * -> *). ScopeElim r => r (Scope r) -> Doc
RC.scope r (Scope r)
s) (r (Permanence r) -> Doc
forall (r :: * -> *). PermElim r => r (Permanence r) -> Doc
RC.perm r (Permanence r)
p) (Doc -> Doc) -> (r (Statement r) -> Doc) -> r (Statement r) -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r (Statement r) -> Doc
forall (r :: * -> *). StatementElim r => r (Statement r) -> Doc
RC.statement) (State MethodState (r (Statement r))
-> State MethodState (r (Statement r))
forall (r :: * -> *).
RenderStatement r =>
MSStatement r -> MSStatement r
S.stmt (State MethodState (r (Statement r))
 -> State MethodState (r (Statement r)))
-> State MethodState (r (Statement r))
-> State MethodState (r (Statement r))
forall a b. (a -> b) -> a -> b
$ SVariable r -> State MethodState (r (Statement r))
forall (r :: * -> *).
DeclStatement r =>
SVariable r -> MSStatement r
S.varDec SVariable r
v)

-- Python and Swift --

self :: (RenderSym r) => SVariable r
self :: SVariable r
self = LensLike'
  (Zoomed (StateT MethodState Identity) String)
  ValueState
  MethodState
-> MS String -> StateT ValueState Identity String
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT MethodState Identity) String)
  ValueState
  MethodState
Lens' ValueState MethodState
lensVStoMS MS String
getClassName StateT ValueState Identity String
-> (String -> SVariable r) -> SVariable r
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\l :: String
l -> String -> VSType r -> Doc -> SVariable r
forall (r :: * -> *).
RenderSym r =>
String -> VSType r -> Doc -> SVariable r
mkStateVar String
R.self (String -> VSType r
forall (r :: * -> *). TypeSym r => String -> VSType r
obj String
l) 
  Doc
R.self')

multiAssign :: (RenderSym r) => (Doc -> Doc) -> [SVariable r] -> [SValue r] -> 
  MSStatement r
multiAssign :: (Doc -> Doc) -> [SVariable r] -> [SValue r] -> MSStatement r
multiAssign _ [] _ = String -> MSStatement r
forall a. HasCallStack => String -> a
error "Attempt to write assign statement for no variables."
multiAssign _ _ [] = String -> MSStatement r
forall a. HasCallStack => String -> a
error "Attempt to write assign statement with no values."
multiAssign f :: Doc -> Doc
f vars :: [SVariable r]
vars vals :: [SValue r]
vals = if [SValue r] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [SValue r]
vals Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= 1 Bool -> Bool -> Bool
&& [SVariable r] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [SVariable r]
vars Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= [SValue r] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [SValue r]
vals 
  then String -> MSStatement r
forall a. HasCallStack => String -> a
error (String -> MSStatement r) -> String -> MSStatement r
forall a b. (a -> b) -> a -> b
$ "Attempted multiple assign statement with different number " String -> String -> String
forall a. [a] -> [a] -> [a]
++
    "of variables than values"
  else do
  [r (Variable r)]
vrs <- (SVariable r -> StateT MethodState Identity (r (Variable r)))
-> [SVariable r] -> StateT MethodState Identity [r (Variable r)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
-> SVariable r -> StateT MethodState Identity (r (Variable r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS) [SVariable r]
vars
  [r (Value r)]
vls <- (SValue r -> StateT MethodState Identity (r (Value r)))
-> [SValue r] -> StateT MethodState Identity [r (Value r)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> SValue r -> StateT MethodState Identity (r (Value r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS) [SValue r]
vals
  let wrapIfMult :: [a] -> Doc -> Doc
      wrapIfMult :: [a] -> Doc -> Doc
wrapIfMult l :: [a]
l = if [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
l Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 1 then Doc -> Doc
f else Doc -> Doc
forall a. a -> a
id
  String -> VSType r -> Doc -> SVariable r
forall (r :: * -> *).
RenderSym r =>
String -> VSType r -> Doc -> SVariable r
mkStateVar "" VSType r
forall (r :: * -> *). TypeSym r => VSType r
S.void ([r (Variable r)] -> Doc -> Doc
forall a. [a] -> Doc -> Doc
wrapIfMult [r (Variable r)]
vrs ([r (Variable r)] -> Doc
forall (r :: * -> *). RenderSym r => [r (Variable r)] -> Doc
variableList [r (Variable r)]
vrs)) SVariable r -> SValue r -> MSStatement r
forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= 
    VSType r -> Doc -> SValue r
forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal VSType r
forall (r :: * -> *). TypeSym r => VSType r
S.void ([r (Value r)] -> Doc -> Doc
forall a. [a] -> Doc -> Doc
wrapIfMult [r (Value r)]
vls ([r (Value r)] -> Doc
forall (r :: * -> *). RenderSym r => [r (Value r)] -> Doc
valueList [r (Value r)]
vls))

multiReturn :: (RenderSym r) => (Doc -> Doc) -> [SValue r] -> MSStatement r
multiReturn :: (Doc -> Doc) -> [SValue r] -> MSStatement r
multiReturn _ [] = String -> MSStatement r
forall a. HasCallStack => String -> a
error "Attempt to write return statement with no values."
multiReturn _ [v :: SValue r
v] = SValue r -> MSStatement r
forall (r :: * -> *).
ControlStatement r =>
SValue r -> MSStatement r
returnStmt SValue r
v
multiReturn f :: Doc -> Doc
f vs :: [SValue r]
vs = do
  [r (Value r)]
vs' <- (SValue r -> StateT MethodState Identity (r (Value r)))
-> [SValue r] -> StateT MethodState Identity [r (Value r)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
-> SValue r -> StateT MethodState Identity (r (Value r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Value r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS) [SValue r]
vs
  SValue r -> MSStatement r
forall (r :: * -> *).
ControlStatement r =>
SValue r -> MSStatement r
returnStmt (SValue r -> MSStatement r) -> SValue r -> MSStatement r
forall a b. (a -> b) -> a -> b
$ VSType r -> Doc -> SValue r
forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal VSType r
forall (r :: * -> *). TypeSym r => VSType r
S.void (Doc -> SValue r) -> Doc -> SValue r
forall a b. (a -> b) -> a -> b
$ Doc -> Doc
f (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [r (Value r)] -> Doc
forall (r :: * -> *). RenderSym r => [r (Value r)] -> Doc
valueList [r (Value r)]
vs'

listDec :: (RenderSym r) => SVariable r -> MSStatement r
listDec :: SVariable r -> MSStatement r
listDec v :: SVariable r
v = SVariable r -> SValue r -> MSStatement r
forall (r :: * -> *).
DeclStatement r =>
SVariable r -> SValue r -> MSStatement r
S.varDecDef SVariable r
v (SValue r -> MSStatement r) -> SValue r -> MSStatement r
forall a b. (a -> b) -> a -> b
$ VSType r -> [SValue r] -> SValue r
forall (r :: * -> *).
Literal r =>
VSType r -> [SValue r] -> SValue r
S.litList ((r (Variable r) -> r (Type r)) -> SVariable r -> VSType r
forall a b s. (a -> b) -> State s a -> State s b
onStateValue r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType SVariable r
v) []

funcDecDef :: (RenderSym r) => SVariable r -> [SVariable r] -> MSBody r -> 
  MSStatement r
funcDecDef :: SVariable r -> [SVariable r] -> MSBody r -> MSStatement r
funcDecDef v :: SVariable r
v ps :: [SVariable r]
ps b :: MSBody r
b = do
  r (Variable r)
vr <- LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
-> SVariable r -> StateT MethodState Identity (r (Variable r))
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r (Variable r)))
  MethodState
  ValueState
Lens' MethodState ValueState
lensMStoVS SVariable r
v
  MethodState
s <- StateT MethodState Identity MethodState
forall s (m :: * -> *). MonadState s m => m s
get
  r (Method r)
f <- String
-> r (Scope r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
forall (r :: * -> *).
MethodSym r =>
String
-> r (Scope r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
function (r (Variable r) -> String
forall (r :: * -> *). VariableElim r => r (Variable r) -> String
variableName r (Variable r)
vr) r (Scope r)
forall (r :: * -> *). ScopeSym r => r (Scope r)
private (r (Type r) -> VSType r
forall (m :: * -> *) a. Monad m => a -> m a
return (r (Type r) -> VSType r) -> r (Type r) -> VSType r
forall a b. (a -> b) -> a -> b
$ r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
vr) 
    ((SVariable r -> MSParameter r) -> [SVariable r] -> [MSParameter r]
forall a b. (a -> b) -> [a] -> [b]
map SVariable r -> MSParameter r
forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
S.param [SVariable r]
ps) MSBody r
b
  (MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (ASetter MethodState MethodState [String] [String]
-> [String] -> MethodState -> MethodState
forall s t a b. ASetter s t a b -> b -> s -> t
L.set ASetter MethodState MethodState [String] [String]
Lens' MethodState [String]
currParameters (MethodState
s MethodState -> Getting [String] MethodState [String] -> [String]
forall s a. s -> Getting a s a -> a
^. Getting [String] MethodState [String]
Lens' MethodState [String]
currParameters))
  Doc -> MSStatement r
forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmtNoEnd (Doc -> MSStatement r) -> Doc -> MSStatement r
forall a b. (a -> b) -> a -> b
$ r (Method r) -> Doc
forall (r :: * -> *). MethodElim r => r (Method r) -> Doc
RC.method r (Method r)
f

inOutCall :: (RenderSym r) => (Label -> VSType r -> [SValue r] -> SValue r) -> 
  Label -> [SValue r] -> [SVariable r] -> [SVariable r] -> MSStatement r
inOutCall :: (String -> VSType r -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MSStatement r
inOutCall f :: String -> VSType r -> [SValue r] -> SValue r
f n :: String
n ins :: [SValue r]
ins [] [] = SValue r -> MSStatement r
forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
S.valStmt (SValue r -> MSStatement r) -> SValue r -> MSStatement r
forall a b. (a -> b) -> a -> b
$ String -> VSType r -> [SValue r] -> SValue r
f String
n VSType r
forall (r :: * -> *). TypeSym r => VSType r
S.void [SValue r]
ins
inOutCall f :: String -> VSType r -> [SValue r] -> SValue r
f n :: String
n ins :: [SValue r]
ins outs :: [SVariable r]
outs both :: [SVariable r]
both = [SVariable r] -> [SValue r] -> MSStatement r
forall (r :: * -> *).
InternalAssignStmt r =>
[SVariable r] -> [SValue r] -> MSStatement r
S.multiAssign [SVariable r]
rets [String -> VSType r -> [SValue r] -> SValue r
f String
n VSType r
forall (r :: * -> *). TypeSym r => VSType r
S.void ((SVariable r -> SValue r) -> [SVariable r] -> [SValue r]
forall a b. (a -> b) -> [a] -> [b]
map SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
S.valueOf 
  [SVariable r]
both [SValue r] -> [SValue r] -> [SValue r]
forall a. [a] -> [a] -> [a]
++ [SValue r]
ins)]
  where rets :: [SVariable r]
rets = [SVariable r]
both [SVariable r] -> [SVariable r] -> [SVariable r]
forall a. [a] -> [a] -> [a]
++ [SVariable r]
outs

forLoopError :: String -> String
forLoopError :: String -> String
forLoopError l :: String
l = "Classic for loops not available in " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
l String -> String -> String
forall a. [a] -> [a] -> [a]
++ ", use " String -> String -> String
forall a. [a] -> [a] -> [a]
++
  "forRange, forEach, or while instead"

mainBody :: (RenderSym r) => MSBody r -> SMethod r
mainBody :: MSBody r -> SMethod r
mainBody b :: MSBody r
b = do
  (MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
setCurrMain
  r (Body r)
bod <- MSBody r
b
  (MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (Doc -> MethodState -> MethodState
setMainDoc (Doc -> MethodState -> MethodState)
-> Doc -> MethodState -> MethodState
forall a b. (a -> b) -> a -> b
$ r (Body r) -> Doc
forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body r (Body r)
bod)
  ScopeTag -> Doc -> SMethod r
forall (r :: * -> *).
RenderMethod r =>
ScopeTag -> Doc -> SMethod r
mthdFromData ScopeTag
Pub Doc
empty

inOutFunc :: (RenderSym r) => (VSType r -> [MSParameter r] -> MSBody r -> 
  SMethod r) -> [SVariable r] -> [SVariable r] -> [SVariable r] -> MSBody r -> 
  SMethod r
inOutFunc :: (VSType r -> [MSParameter r] -> MSBody r -> SMethod r)
-> [SVariable r]
-> [SVariable r]
-> [SVariable r]
-> MSBody r
-> SMethod r
inOutFunc f :: VSType r -> [MSParameter r] -> MSBody r -> SMethod r
f ins :: [SVariable r]
ins [] [] b :: MSBody r
b = VSType r -> [MSParameter r] -> MSBody r -> SMethod r
f VSType r
forall (r :: * -> *). TypeSym r => VSType r
S.void ((SVariable r -> MSParameter r) -> [SVariable r] -> [MSParameter r]
forall a b. (a -> b) -> [a] -> [b]
map SVariable r -> MSParameter r
forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
S.param [SVariable r]
ins) MSBody r
b
inOutFunc f :: VSType r -> [MSParameter r] -> MSBody r -> SMethod r
f ins :: [SVariable r]
ins outs :: [SVariable r]
outs both :: [SVariable r]
both b :: MSBody r
b = VSType r -> [MSParameter r] -> MSBody r -> SMethod r
f 
  ([VSType r] -> VSType r
forall (r :: * -> *). RenderType r => [VSType r] -> VSType r
multiType ([VSType r] -> VSType r) -> [VSType r] -> VSType r
forall a b. (a -> b) -> a -> b
$ (SVariable r -> VSType r) -> [SVariable r] -> [VSType r]
forall a b. (a -> b) -> [a] -> [b]
map ((r (Variable r) -> r (Type r)) -> SVariable r -> VSType r
forall a b s. (a -> b) -> State s a -> State s b
onStateValue r (Variable r) -> r (Type r)
forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType) [SVariable r]
rets)  
  ((SVariable r -> MSParameter r) -> [SVariable r] -> [MSParameter r]
forall a b. (a -> b) -> [a] -> [b]
map SVariable r -> MSParameter r
forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
S.pointerParam [SVariable r]
both [MSParameter r] -> [MSParameter r] -> [MSParameter r]
forall a. [a] -> [a] -> [a]
++ (SVariable r -> MSParameter r) -> [SVariable r] -> [MSParameter r]
forall a b. (a -> b) -> [a] -> [b]
map SVariable r -> MSParameter r
forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
S.param [SVariable r]
ins) 
  ([MSBody r] -> MSBody r
forall (r :: * -> *). RenderBody r => [MSBody r] -> MSBody r
multiBody [[MSStatement r] -> MSBody r
forall (r :: * -> *). BodySym r => [MSStatement r] -> MSBody r
bodyStatements ([MSStatement r] -> MSBody r) -> [MSStatement r] -> MSBody r
forall a b. (a -> b) -> a -> b
$ (SVariable r -> MSStatement r) -> [SVariable r] -> [MSStatement r]
forall a b. (a -> b) -> [a] -> [b]
map SVariable r -> MSStatement r
forall (r :: * -> *).
DeclStatement r =>
SVariable r -> MSStatement r
S.varDec [SVariable r]
outs, MSBody r
b, MSStatement r -> MSBody r
forall (r :: * -> *). BodySym r => MSStatement r -> MSBody r
oneLiner (MSStatement r -> MSBody r) -> MSStatement r -> MSBody r
forall a b. (a -> b) -> a -> b
$ [SValue r] -> MSStatement r
forall (r :: * -> *).
InternalControlStmt r =>
[SValue r] -> MSStatement r
S.multiReturn ([SValue r] -> MSStatement r) -> [SValue r] -> MSStatement r
forall a b. (a -> b) -> a -> b
$ 
  (SVariable r -> SValue r) -> [SVariable r] -> [SValue r]
forall a b. (a -> b) -> [a] -> [b]
map SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
S.valueOf [SVariable r]
rets])
  where rets :: [SVariable r]
rets = [SVariable r]
both [SVariable r] -> [SVariable r] -> [SVariable r]
forall a. [a] -> [a] -> [a]
++ [SVariable r]
outs

docInOutFunc' :: (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
docInOutFunc' :: 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
docInOutFunc' dfr :: FuncDocRenderer
dfr f :: [SVariable r]
-> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r
f desc :: String
desc is :: [(String, SVariable r)]
is os :: [(String, SVariable r)]
os bs :: [(String, SVariable r)]
bs b :: MSBody r
b = FuncDocRenderer
-> String -> [String] -> [String] -> SMethod r -> SMethod r
forall (r :: * -> *).
RenderSym r =>
FuncDocRenderer
-> String -> [String] -> [String] -> SMethod r -> SMethod r
docFuncRepr FuncDocRenderer
dfr String
desc (((String, SVariable r) -> String)
-> [(String, SVariable r)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String, SVariable r) -> String
forall a b. (a, b) -> a
fst ([(String, SVariable r)] -> [String])
-> [(String, SVariable r)] -> [String]
forall a b. (a -> b) -> a -> b
$ [(String, SVariable r)]
bs [(String, SVariable r)]
-> [(String, SVariable r)] -> [(String, SVariable r)]
forall a. [a] -> [a] -> [a]
++ [(String, SVariable r)]
is)
  (((String, SVariable r) -> String)
-> [(String, SVariable r)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String, SVariable r) -> String
forall a b. (a, b) -> a
fst ([(String, SVariable r)] -> [String])
-> [(String, SVariable r)] -> [String]
forall a b. (a -> b) -> a -> b
$ [(String, SVariable r)]
bs [(String, SVariable r)]
-> [(String, SVariable r)] -> [(String, SVariable r)]
forall a. [a] -> [a] -> [a]
++ [(String, SVariable r)]
os) ([SVariable r]
-> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r
f (((String, SVariable r) -> SVariable r)
-> [(String, SVariable r)] -> [SVariable r]
forall a b. (a -> b) -> [a] -> [b]
map (String, SVariable r) -> SVariable r
forall a b. (a, b) -> b
snd [(String, SVariable r)]
is) (((String, SVariable r) -> SVariable r)
-> [(String, SVariable r)] -> [SVariable r]
forall a b. (a -> b) -> [a] -> [b]
map (String, SVariable r) -> SVariable r
forall a b. (a, b) -> b
snd [(String, SVariable r)]
os) (((String, SVariable r) -> SVariable r)
-> [(String, SVariable r)] -> [SVariable r]
forall a b. (a -> b) -> [a] -> [b]
map (String, SVariable r) -> SVariable r
forall a b. (a, b) -> b
snd [(String, SVariable r)]
bs) MSBody r
b)

-- Java and Swift --

floatRender :: String
floatRender :: String
floatRender = "Float"

float :: (RenderSym r) => VSType r
float :: VSType r
float = CodeType -> String -> Doc -> VSType r
forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData CodeType
Float String
floatRender (String -> Doc
text String
floatRender)

stringRender' :: String
stringRender' :: String
stringRender' = "String"

string' :: (RenderSym r) => VSType r
string' :: VSType r
string' = CodeType -> String -> Doc -> VSType r
forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData CodeType
String String
stringRender' (String -> Doc
text String
stringRender')

-- C# and Swift --

inherit :: (Monad r) => Maybe Label -> r ParentSpec
inherit :: Maybe String -> r Doc
inherit n :: Maybe String
n = Doc -> r Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> r Doc) -> Doc -> r Doc
forall a b. (a -> b) -> a -> b
$ Doc -> (String -> Doc) -> Maybe String -> Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
empty ((Doc
colon Doc -> Doc -> Doc
<+>) (Doc -> Doc) -> (String -> Doc) -> String -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc
text) Maybe String
n

implements :: (Monad r) => [Label] -> r ParentSpec
implements :: [String] -> r Doc
implements is :: [String]
is = Doc -> r Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> r Doc) -> Doc -> r Doc
forall a b. (a -> b) -> a -> b
$ Doc
colon Doc -> Doc -> Doc
<+> String -> Doc
text (String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
listSep [String]
is)