module GOOL.Drasil.LanguageRenderer.CommonPseudoOO (int, constructor, doxFunc,
doxClass, doxMod, docMod', 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', boolRender, bool, floatRender, float, stringRender',
string', inherit, implements
) where
import Utils.Drasil (indent, stringList)
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, ModuleDocRenderer, 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,
useVarName)
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)
import Metadata.Drasil.DrasilMetaCall (watermark)
intRender :: String
intRender :: String
intRender = String
"int"
int :: (RenderSym r) => VSType r
int :: forall (r :: * -> *). RenderSym r => VSType r
int = 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 :: forall (r :: * -> *).
RenderSym r =>
String
-> [MSParameter r] -> Initializers r -> MSBody r -> SMethod r
constructor String
fName [MSParameter r]
ps Initializers r
is MSBody r
b = MS String
getClassName forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\String
c -> 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
forall (r :: * -> *). ScopeSym r => r (Scope r)
public forall (r :: * -> *). PermanenceSym r => r (Permanence r)
dynamic (forall (r :: * -> *). MethodTypeSym r => String -> MSMthdType r
S.construct String
c) [MSParameter r]
ps (forall (r :: * -> *). RenderBody r => [MSBody r] -> MSBody r
S.multiBody [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 :: forall (r :: * -> *).
RenderSym r =>
String -> [String] -> Maybe String -> SMethod r -> SMethod r
doxFunc = 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 :: forall (r :: * -> *). RenderSym r => String -> SClass r -> SClass r
doxClass = 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 :: forall (r :: * -> *).
RenderSym r =>
String -> String -> [String] -> String -> SFile r -> SFile r
doxMod = forall (r :: * -> *).
RenderSym r =>
ModuleDocRenderer
-> String -> String -> [String] -> String -> SFile r -> SFile r
docMod ModuleDocRenderer
moduleDox
extVar :: (RenderSym r) => Label -> Label -> VSType r -> SVariable r
extVar :: forall (r :: * -> *).
RenderSym r =>
String -> String -> VSType r -> SVariable r
extVar String
l String
n VSType r
t = 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 :: forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc -> Doc) -> VSType r -> SVariable r -> SVariable r
classVar Doc -> Doc -> Doc
f VSType r
c' SVariable r
v'= do
r (Type r)
c <- VSType r
c'
r (Variable r)
v <- SVariable r
v'
r (Variable r)
vr <- forall (r :: * -> *).
RenderVariable r =>
Binding -> String -> VSType r -> Doc -> SVariable r
varFromData
(forall (r :: * -> *).
InternalVarElim r =>
r (Variable r) -> Binding
variableBind r (Variable r)
v) (forall (r :: * -> *). TypeElim r => r (Type r) -> String
getTypeString r (Type r)
c String -> String -> String
`access` forall (r :: * -> *). VariableElim r => r (Variable r) -> String
variableName r (Variable r)
v)
(forall a s. a -> State s a
toState forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
v) (Doc -> Doc -> Doc
f (forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' r (Type r)
c) (forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
v))
forall a s. a -> State s a
toState forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
RenderSym r =>
r (Variable r) -> r (Variable r)
classVarCheckStatic r (Variable r)
vr
objVarSelf :: (RenderSym r) => SVariable r -> SVariable r
objVarSelf :: forall (r :: * -> *). RenderSym r => SVariable r -> SVariable r
objVarSelf = forall (r :: * -> *).
VariableSym r =>
SVariable r -> SVariable r -> SVariable r
S.objVar forall (r :: * -> *). VariableSym r => SVariable r
S.self
indexOf :: (RenderSym r) => Label -> SValue r -> SValue r -> SValue r
indexOf :: forall (r :: * -> *).
RenderSym r =>
String -> SValue r -> SValue r -> SValue r
indexOf String
f SValue r
l SValue r
v = forall (r :: * -> *).
FunctionSym r =>
SValue r -> VSFunction r -> SValue r
S.objAccess SValue r
l (forall (r :: * -> *).
FunctionSym r =>
String -> VSType r -> [SValue r] -> VSFunction r
S.func String
f forall (r :: * -> *). TypeSym r => VSType r
S.int [SValue r
v])
listAddFunc :: (RenderSym r) => Label -> SValue r -> SValue r -> VSFunction r
listAddFunc :: forall (r :: * -> *).
RenderSym r =>
String -> SValue r -> SValue r -> VSFunction r
listAddFunc String
f SValue r
i SValue r
v = forall (r :: * -> *).
FunctionSym r =>
String -> VSType r -> [SValue r] -> VSFunction r
S.func String
f (forall (r :: * -> *). TypeSym r => VSType r -> VSType r
S.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
i, SValue r
v]
discardFileLine :: (RenderSym r) => Label -> SValue r -> MSStatement r
discardFileLine :: forall (r :: * -> *).
RenderSym r =>
String -> SValue r -> MSStatement r
discardFileLine String
n SValue r
f = forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
S.valStmt 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
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 :: 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)
intClass String -> Doc -> Doc -> Doc -> Doc -> Doc
f String
n r (Scope r)
s r Doc
i [CSStateVar r]
svrs [SMethod r]
mths = do
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ClassState -> ClassState
setClassName String
n)
Doc
svs <- forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList ([Doc] -> Doc
R.stateVarList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *). StateVarElim r => r (StateVar r) -> Doc
RC.stateVar) [CSStateVar r]
svrs
Doc
ms <- forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList ([Doc] -> Doc
vibcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *). MethodElim r => r (Method r) -> Doc
RC.method) (forall a b. (a -> b) -> [a] -> [b]
map (forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' ClassState MethodState
lensCStoMS) [SMethod r]
mths)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue (\Doc
p -> String -> Doc -> Doc -> Doc -> Doc -> Doc
f String
n Doc
p (forall (r :: * -> *). ScopeElim r => r (Scope r) -> Doc
RC.scope r (Scope r)
s) Doc
svs Doc
ms) r Doc
i
funcType :: (RenderSym r) => [VSType r] -> VSType r -> VSType r
funcType :: forall (r :: * -> *).
RenderSym r =>
[VSType r] -> VSType r -> VSType r
funcType [VSType r]
ps' VSType r
r' = do
[r (Type r)]
ps <- 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'
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)]
ps) (forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType r (Type r)
r)) String
"" Doc
empty
buildModule :: (RenderSym r) => Label -> FS Doc -> FS Doc -> FS Doc ->
[SMethod r] -> [SClass r] -> FSModule r
buildModule :: forall (r :: * -> *).
RenderSym r =>
String
-> FS Doc
-> FS Doc
-> FS Doc
-> [SMethod r]
-> [SClass r]
-> FSModule r
buildModule String
n FS Doc
imps FS Doc
top FS Doc
bot [SMethod r]
fs [SClass r]
cs = forall (r :: * -> *). RenderMod r => String -> FS Doc -> FSModule r
S.modFromData String
n (do
[r (Class r)]
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 r]
cs
[r (Method r)]
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 r]
fs
Doc
is <- FS Doc
imps
Doc
tp <- FS Doc
top
Doc
bt <- FS Doc
bot
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Doc -> Doc -> Doc -> Doc
R.module' Doc
is ([Doc] -> Doc
vibcat (Doc
tp forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *). ClassElim r => r (Class r) -> Doc
RC.class' [r (Class r)]
cls))
([Doc] -> Doc
vibcat (forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *). MethodElim r => r (Method r) -> Doc
RC.method [r (Method r)]
fns forall a. [a] -> [a] -> [a]
++ [Doc
bt])))
arrayType :: (RenderSym r) => VSType r -> VSType r
arrayType :: forall (r :: * -> *). RenderSym r => VSType r -> VSType r
arrayType VSType r
t' = do
r (Type r)
t <- VSType r
t'
forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData (CodeType -> CodeType
Array (forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType r (Type r)
t))
(forall (r :: * -> *). TypeElim r => r (Type r) -> String
getTypeString r (Type r)
t forall a. [a] -> [a] -> [a]
++ String
array) (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 :: forall (r :: * -> *). RenderSym r => SValue r
pi = forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal forall (r :: * -> *). TypeSym r => VSType r
S.double (String -> Doc
text forall a b. (a -> b) -> a -> b
$ String -> String
mathFunc String
"PI")
printSt :: (RenderSym r) => SValue r -> SValue r -> MSStatement r
printSt :: forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> MSStatement r
printSt SValue r
va' SValue r
vb' = do
r (Value r)
va <- 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
va'
r (Value r)
vb <- 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
vb'
forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmt (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 :: forall (r :: * -> *).
RenderSym r =>
SValue r -> SVariable r -> MSStatement r
arrayDec SValue r
n SVariable r
vr = do
r (Value r)
sz <- 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
n
r (Variable 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 SVariable r
vr
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ String -> MethodState -> MethodState
useVarName forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). VariableElim r => r (Variable r) -> String
variableName r (Variable r)
v
let tp :: r (Type r)
tp = forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
v
r (Type r)
innerTp <- 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 a b. (a -> b) -> a -> b
$ forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listInnerType forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return r (Type r)
tp
forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmt forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' r (Type r)
tp Doc -> Doc -> 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
<+>
forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' r (Type r)
innerTp Doc -> Doc -> Doc
<> Doc -> Doc
brackets (forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
sz)
arrayDecDef :: (RenderSym r) => SVariable r -> [SValue r] -> MSStatement r
arrayDecDef :: forall (r :: * -> *).
RenderSym r =>
SVariable r -> [SValue r] -> MSStatement r
arrayDecDef SVariable r
v' [SValue r]
vals' = do
[r (Value r)]
vs <- 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' MethodState ValueState
lensMStoVS) [SValue r]
vals'
r (Statement r)
vd <- forall (r :: * -> *).
DeclStatement r =>
SVariable r -> MSStatement r
S.varDec SVariable r
v'
forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmt (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 (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 :: forall (r :: * -> *).
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
f SVariable r
vr SValue r
vl = SVariable r
vr forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= SValue r -> VSType r -> SValue r -> SValue r
f SValue r
vl forall (r :: * -> *). TypeSym r => VSType r
outfile forall (r :: * -> *). Literal r => SValue r
S.litTrue
forEach :: (RenderSym r) => Doc -> Doc -> Doc -> Doc -> SVariable r -> SValue r
-> MSBody r -> MSStatement r
forEach :: forall (r :: * -> *).
RenderSym r =>
Doc
-> Doc
-> Doc
-> Doc
-> SVariable r
-> SValue r
-> MSBody r
-> MSStatement r
forEach Doc
bStart Doc
bEnd Doc
forEachLabel Doc
inLbl SVariable r
e' SValue r
v' MSBody r
b' = do
r (Variable r)
e <- 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
e'
r (Value 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'
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
forEachLabel Doc -> Doc -> Doc
<+> Doc -> Doc
parens (forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' (forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
e) Doc -> Doc -> Doc
<+> forall (r :: * -> *). InternalVarElim r => r (Variable r) -> Doc
RC.variable r (Variable r)
e Doc -> Doc -> Doc
<+>
Doc
inLbl Doc -> Doc -> Doc
<+> forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
v) Doc -> Doc -> Doc
<+> Doc
bStart,
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
bEnd]
mainDesc, argsDesc :: String
mainDesc :: String
mainDesc = String
"Controls the flow of the program"
argsDesc :: String
argsDesc = String
"List of command-line arguments"
docMain :: (RenderSym r) => MSBody r -> SMethod r
docMain :: forall (r :: * -> *). RenderSym r => MSBody r -> SMethod r
docMain MSBody r
b = forall (r :: * -> *).
RenderMethod r =>
MS (r (BlockComment r)) -> SMethod r -> SMethod r
commentedFunc (forall (r :: * -> *) a.
BlockCommentSym r =>
State a [String] -> State a (r (BlockComment r))
docComment forall a b. (a -> b) -> a -> b
$ forall a s. a -> State s a
toState forall a b. (a -> b) -> a -> b
$ FuncDocRenderer
functionDox
String
mainDesc [(String
args, String
argsDesc)] []) (forall (r :: * -> *). MethodSym r => MSBody r -> SMethod r
S.mainFunction MSBody r
b)
mainFunction :: (RenderSym r) => VSType r -> Label -> MSBody r -> SMethod r
mainFunction :: forall (r :: * -> *).
RenderSym r =>
VSType r -> String -> MSBody r -> SMethod r
mainFunction VSType r
s String
n = 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 forall (r :: * -> *). ScopeSym r => r (Scope r)
public forall (r :: * -> *). PermanenceSym r => r (Permanence r)
static (forall (r :: * -> *). MethodTypeSym r => VSType r -> MSMthdType r
mType forall (r :: * -> *). TypeSym r => VSType r
S.void)
[forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
S.param (forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
S.var String
args (VSType r
s forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\r (Type r)
argT -> forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData (CodeType -> CodeType
List CodeType
String)
(Doc -> String
render (forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' r (Type r)
argT) forall a. [a] -> [a] -> [a]
++ String
array) (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' :: forall (r :: * -> *).
RenderSym r =>
String
-> (String -> r (Import r))
-> [String]
-> [SMethod r]
-> [SClass r]
-> FSModule r
buildModule' String
n String -> r (Import r)
inc [String]
is [SMethod r]
ms [SClass r]
cs = forall (r :: * -> *). RenderMod r => String -> FS Doc -> FSModule r
S.modFromData String
n (do
[r (Class r)]
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)
(if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [SMethod r]
ms then [SClass r]
cs else forall (r :: * -> *).
ClassSym r =>
Maybe String -> [CSStateVar r] -> [SMethod r] -> SClass r
S.buildClass forall a. Maybe a
Nothing [] [SMethod r]
ms forall a. a -> [a] -> [a]
: [SClass r]
cs)
[String]
lis <- FS [String]
getLangImports
[String]
libis <- FS [String]
getLibImports
[String]
mis <- FS [String]
getModuleImports
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vibcat [
[Doc] -> Doc
vcat (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
. String -> r (Import r)
inc) ([String]
lis forall a. [a] -> [a] -> [a]
++ forall a. Ord a => [a] -> [a]
sort ([String]
is forall a. [a] -> [a] -> [a]
++ [String]
libis) forall a. [a] -> [a] -> [a]
++ [String]
mis)),
[Doc] -> Doc
vibcat (forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *). ClassElim r => r (Class r) -> Doc
RC.class' [r (Class r)]
cls)])
call' :: (RenderSym r) => String -> Maybe Library -> Maybe Doc -> MixedCall r
call' :: forall (r :: * -> *).
RenderSym r =>
String -> Maybe String -> Maybe Doc -> MixedCall r
call' String
l Maybe String
_ Maybe Doc
_ String
_ VSType r
_ [SValue r]
_ ((SVariable r, SValue r)
_:[(SVariable r, SValue r)]
_) = forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String -> String
namedArgError String
l
call' String
_ Maybe String
l Maybe Doc
o String
n VSType r
t [SValue r]
ps [(SVariable r, SValue r)]
ns = 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 String
l = String
"Named arguments not supported in " forall a. [a] -> [a] -> [a]
++ String
l
listSizeFunc :: (RenderSym r) => VSFunction r
listSizeFunc :: forall (r :: * -> *). RenderSym r => VSFunction r
listSizeFunc = forall (r :: * -> *).
FunctionSym r =>
String -> VSType r -> [SValue r] -> VSFunction r
S.func String
"size" forall (r :: * -> *). TypeSym r => VSType r
S.int []
listAccessFunc' :: (RenderSym r) => Label -> VSType r -> SValue r ->
VSFunction r
listAccessFunc' :: forall (r :: * -> *).
RenderSym r =>
String -> VSType r -> SValue r -> VSFunction r
listAccessFunc' String
f VSType r
t SValue r
i = forall (r :: * -> *).
FunctionSym r =>
String -> VSType r -> [SValue r] -> VSFunction r
S.func String
f VSType r
t [forall (r :: * -> *). RenderSym r => SValue r -> SValue r
intValue SValue r
i]
stringRender :: String
stringRender :: String
stringRender = String
"string"
string :: (RenderSym r) => VSType r
string :: forall (r :: * -> *). RenderSym r => VSType r
string = 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 :: forall (r :: * -> *).
RenderSym r =>
SVariable r -> SValue r -> MSStatement r
constDecDef SVariable r
vr' SValue r
v'= do
r (Variable r)
vr <- 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
vr'
r (Value 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 s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ String -> MethodState -> MethodState
useVarName forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). VariableElim r => r (Variable r) -> String
variableName r (Variable r)
vr
forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmt (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 :: forall (r :: * -> *).
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
f String
desc [(String, SVariable r)]
is [(String, SVariable r)
o] [] MSBody r
b = forall (r :: * -> *).
RenderSym r =>
FuncDocRenderer
-> String -> [String] -> [String] -> SMethod r -> SMethod r
docFuncRepr FuncDocRenderer
functionDox String
desc (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst [(String, SVariable r)]
is)
[forall a b. (a, b) -> a
fst (String, SVariable r)
o] ([SVariable r]
-> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r
f (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd [(String, SVariable r)]
is) [forall a b. (a, b) -> b
snd (String, SVariable r)
o] [] MSBody r
b)
docInOutFunc [SVariable r]
-> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r
f String
desc [(String, SVariable r)]
is [] [(String, SVariable r)
both] MSBody r
b = forall (r :: * -> *).
RenderSym r =>
FuncDocRenderer
-> String -> [String] -> [String] -> SMethod r -> SMethod r
docFuncRepr FuncDocRenderer
functionDox String
desc (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$
(String, SVariable r)
both forall a. a -> [a] -> [a]
: [(String, SVariable r)]
is) [forall a b. (a, b) -> a
fst (String, SVariable r)
both] ([SVariable r]
-> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r
f (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd [(String, SVariable r)]
is) [] [forall a b. (a, b) -> b
snd (String, SVariable r)
both] MSBody r
b)
docInOutFunc [SVariable r]
-> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r
f String
desc [(String, SVariable r)]
is [(String, SVariable r)]
os [(String, SVariable r)]
bs MSBody r
b = forall (r :: * -> *).
RenderSym r =>
FuncDocRenderer
-> String -> [String] -> [String] -> SMethod r -> SMethod r
docFuncRepr FuncDocRenderer
functionDox String
desc (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ [(String, SVariable r)]
bs forall a. [a] -> [a] -> [a]
++
[(String, SVariable r)]
is forall a. [a] -> [a] -> [a]
++ [(String, SVariable r)]
os) [] ([SVariable r]
-> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r
f (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd [(String, SVariable r)]
is) (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd [(String, SVariable r)]
os) (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd [(String, SVariable r)]
bs) MSBody r
b)
bindingError :: String -> String
bindingError :: String -> String
bindingError String
l = String
"Binding unimplemented in " forall a. [a] -> [a] -> [a]
++ String
l
extFuncAppMixedArgs :: (RenderSym r) => Library -> MixedCall r
extFuncAppMixedArgs :: forall (r :: * -> *). RenderSym r => String -> MixedCall r
extFuncAppMixedArgs String
l = forall (r :: * -> *).
RenderValue r =>
Maybe String -> Maybe Doc -> MixedCall r
S.call (forall a. a -> Maybe a
Just String
l) forall a. Maybe a
Nothing
notNull :: (RenderSym r) => String -> SValue r -> SValue r
notNull :: forall (r :: * -> *). RenderSym r => String -> SValue r -> SValue r
notNull String
nil SValue r
v = SValue r
v forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?!= forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
S.valueOf (forall (r :: * -> *).
VariableSym r =>
String -> VSType r -> SVariable r
S.var String
nil 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)
listDecDef :: (RenderSym r) => SVariable r -> [SValue r] -> MSStatement r
listDecDef :: forall (r :: * -> *).
RenderSym r =>
SVariable r -> [SValue r] -> MSStatement r
listDecDef SVariable r
v [SValue r]
vals = do
r (Variable r)
vr <- 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
v
let lst :: SValue r
lst = forall (r :: * -> *).
Literal r =>
VSType r -> [SValue r] -> SValue r
S.litList (forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listInnerType forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
vr) [SValue r]
vals
forall (r :: * -> *).
DeclStatement r =>
SVariable r -> SValue r -> MSStatement r
S.varDecDef (forall (m :: * -> *) a. Monad m => a -> m a
return r (Variable r)
vr) SValue r
lst
destructorError :: String -> String
destructorError :: String -> String
destructorError String
l = String
"Destructors not allowed in " 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 :: forall (r :: * -> *).
(RenderSym r, Monad r) =>
r (Scope r)
-> r (Permanence r) -> SVariable r -> SValue r -> CS (r Doc)
stateVarDef r (Scope r)
s r (Permanence r)
p SVariable r
vr SValue r
vl = forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' ClassState MethodState
lensCStoMS forall a b. (a -> b) -> a -> b
$ forall a b s. (a -> b) -> State s a -> State s b
onStateValue (forall (r :: * -> *) a. Monad r => a -> r a
toCode forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc -> Doc -> Doc
R.stateVar
(forall (r :: * -> *). ScopeElim r => r (Scope r) -> Doc
RC.scope r (Scope r)
s) (forall (r :: * -> *). PermElim r => r (Permanence r) -> Doc
RC.perm r (Permanence r)
p) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). StatementElim r => r (Statement r) -> Doc
RC.statement) (forall (r :: * -> *).
RenderStatement r =>
MSStatement r -> MSStatement r
S.stmt forall a b. (a -> b) -> a -> b
$ 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 :: forall (r :: * -> *).
(RenderSym r, Monad r) =>
Doc -> r (Scope r) -> SVariable r -> SValue r -> CS (r Doc)
constVar Doc
p r (Scope r)
s SVariable r
vr SValue r
vl = forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' ClassState MethodState
lensCStoMS forall a b. (a -> b) -> a -> b
$ forall a b s. (a -> b) -> State s a -> State s b
onStateValue (forall (r :: * -> *) a. Monad r => a -> r a
toCode forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc -> Doc -> Doc
R.stateVar
(forall (r :: * -> *). ScopeElim r => r (Scope r) -> Doc
RC.scope r (Scope r)
s) Doc
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). StatementElim r => r (Statement r) -> Doc
RC.statement) (forall (r :: * -> *).
RenderStatement r =>
MSStatement r -> MSStatement r
S.stmt forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
DeclStatement r =>
SVariable r -> SValue r -> MSStatement r
S.constDecDef SVariable r
vr SValue r
vl)
litArray :: (RenderSym r) => (Doc -> Doc) -> VSType r -> [SValue r] -> SValue r
litArray :: forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc) -> VSType r -> [SValue r] -> SValue r
litArray Doc -> Doc
f VSType r
t [SValue r]
es = forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [SValue r]
es forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\[r (Value r)]
elems -> forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal (forall (r :: * -> *). TypeSym r => VSType r -> VSType r
S.arrayType VSType r
t)
(Doc -> Doc
f forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). RenderSym r => [r (Value r)] -> Doc
valueList [r (Value r)]
elems))
listSetFunc :: (RenderSym r) => (Doc -> Doc -> Doc) -> SValue r -> SValue r ->
SValue r -> VSFunction r
listSetFunc :: forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc -> Doc)
-> SValue r -> SValue r -> SValue r -> VSFunction r
listSetFunc Doc -> Doc -> Doc
f SValue r
v SValue r
idx SValue r
setVal = forall (m :: * -> *) a. Monad m => m (m a) -> m a
join forall a b. (a -> b) -> a -> b
$ forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues (\r (Value r)
i r (Value r)
toVal -> forall (r :: * -> *).
RenderFunction r =>
Doc -> VSType r -> VSFunction r
funcFromData
(Doc -> Doc -> Doc
f (forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
i) (forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
toVal)) (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)) (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
String
n = forall (r :: * -> *).
RenderClass r =>
String
-> r (Scope r)
-> r Doc
-> [CSStateVar r]
-> [SMethod r]
-> SClass r
S.intClass String
n forall (r :: * -> *). ScopeSym r => r (Scope r)
public forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). RenderClass r => Maybe String -> r Doc
S.inherit
listAccessFunc :: (RenderSym r) => VSType r -> SValue r -> VSFunction r
listAccessFunc :: forall (r :: * -> *).
RenderSym r =>
VSType r -> SValue r -> VSFunction r
listAccessFunc VSType r
t SValue r
v = forall (r :: * -> *). RenderSym r => SValue r -> SValue r
intValue SValue r
v forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ((forall (r :: * -> *).
RenderFunction r =>
Doc -> VSType r -> VSFunction r
`funcFromData` VSType r
t) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). RenderSym r => r (Value r) -> Doc
R.listAccessFunc)
doubleRender :: String
doubleRender :: String
doubleRender = String
"Double"
double :: (RenderSym r) => VSType r
double :: forall (r :: * -> *). RenderSym r => VSType r
double = 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 :: forall (r :: * -> *).
RenderSym r =>
(SValue r -> VSType r -> SValue r)
-> SVariable r -> SValue r -> MSStatement r
openFileR SValue r -> VSType r -> SValue r
f SVariable r
vr SValue r
vl = SVariable r
vr forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= SValue r -> VSType r -> SValue r
f SValue r
vl 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 :: forall (r :: * -> *).
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
f SVariable r
vr SValue r
vl = SVariable r
vr forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= SValue r -> VSType r -> SValue r -> SValue r
f SValue r
vl forall (r :: * -> *). TypeSym r => VSType r
outfile 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 :: forall (r :: * -> *).
(RenderSym r, Monad r) =>
r (Scope r) -> r (Permanence r) -> SVariable r -> CS (r Doc)
stateVar r (Scope r)
s r (Permanence r)
p SVariable 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' ClassState MethodState
lensCStoMS forall a b. (a -> b) -> a -> b
$ forall a b s. (a -> b) -> State s a -> State s b
onStateValue (forall (r :: * -> *) a. Monad r => a -> r a
toCode forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc -> Doc -> Doc
R.stateVar
(forall (r :: * -> *). ScopeElim r => r (Scope r) -> Doc
RC.scope r (Scope r)
s) (forall (r :: * -> *). PermElim r => r (Permanence r) -> Doc
RC.perm r (Permanence r)
p) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). StatementElim r => r (Statement r) -> Doc
RC.statement) (forall (r :: * -> *).
RenderStatement r =>
MSStatement r -> MSStatement r
S.stmt forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
DeclStatement r =>
SVariable r -> MSStatement r
S.varDec SVariable r
v)
self :: (RenderSym r) => SVariable r
self :: forall (r :: * -> *). RenderSym r => SVariable r
self = forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom Lens' ValueState MethodState
lensVStoMS MS String
getClassName forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\String
l -> forall (r :: * -> *).
RenderSym r =>
String -> VSType r -> Doc -> SVariable r
mkStateVar String
R.self (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 :: forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc) -> [SVariable r] -> [SValue r] -> MSStatement r
multiAssign Doc -> Doc
_ [] [SValue r]
_ = forall a. HasCallStack => String -> a
error String
"Attempt to write assign statement for no variables."
multiAssign Doc -> Doc
_ [SVariable r]
_ [] = forall a. HasCallStack => String -> a
error String
"Attempt to write assign statement with no values."
multiAssign Doc -> Doc
f [SVariable r]
vars [SValue r]
vals = if forall (t :: * -> *) a. Foldable t => t a -> Int
length [SValue r]
vals forall a. Eq a => a -> a -> Bool
/= Int
1 Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => t a -> Int
length [SVariable r]
vars forall a. Eq a => a -> a -> Bool
/= forall (t :: * -> *) a. Foldable t => t a -> Int
length [SValue r]
vals
then forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String
"Attempted multiple assign statement with different number " forall a. [a] -> [a] -> [a]
++
String
"of variables than values"
else do
[r (Variable r)]
vrs <- 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' MethodState ValueState
lensMStoVS) [SVariable r]
vars
[r (Value r)]
vls <- 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' MethodState ValueState
lensMStoVS) [SValue r]
vals
let wrapIfMult :: [a] -> Doc -> Doc
wrapIfMult :: forall a. [a] -> Doc -> Doc
wrapIfMult [a]
l = if forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
l forall a. Ord a => a -> a -> Bool
> Int
1 then Doc -> Doc
f else forall a. a -> a
id
forall (r :: * -> *).
RenderSym r =>
String -> VSType r -> Doc -> SVariable r
mkStateVar String
"" forall (r :: * -> *). TypeSym r => VSType r
S.void (forall a. [a] -> Doc -> Doc
wrapIfMult [r (Variable r)]
vrs (forall (r :: * -> *). RenderSym r => [r (Variable r)] -> Doc
variableList [r (Variable r)]
vrs)) forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&=
forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal forall (r :: * -> *). TypeSym r => VSType r
S.void (forall a. [a] -> Doc -> Doc
wrapIfMult [r (Value r)]
vls (forall (r :: * -> *). RenderSym r => [r (Value r)] -> Doc
valueList [r (Value r)]
vls))
multiReturn :: (RenderSym r) => (Doc -> Doc) -> [SValue r] -> MSStatement r
multiReturn :: forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc) -> [SValue r] -> MSStatement r
multiReturn Doc -> Doc
_ [] = forall a. HasCallStack => String -> a
error String
"Attempt to write return statement with no values."
multiReturn Doc -> Doc
_ [SValue r
v] = forall (r :: * -> *).
ControlStatement r =>
SValue r -> MSStatement r
returnStmt SValue r
v
multiReturn Doc -> Doc
f [SValue r]
vs = do
[r (Value r)]
vs' <- 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' MethodState ValueState
lensMStoVS) [SValue r]
vs
forall (r :: * -> *).
ControlStatement r =>
SValue r -> MSStatement r
returnStmt forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal forall (r :: * -> *). TypeSym r => VSType r
S.void forall a b. (a -> b) -> a -> b
$ Doc -> Doc
f forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). RenderSym r => [r (Value r)] -> Doc
valueList [r (Value r)]
vs'
listDec :: (RenderSym r) => SVariable r -> MSStatement r
listDec :: forall (r :: * -> *). RenderSym r => SVariable r -> MSStatement r
listDec SVariable r
v = forall (r :: * -> *).
DeclStatement r =>
SVariable r -> SValue r -> MSStatement r
S.varDecDef SVariable r
v forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
Literal r =>
VSType r -> [SValue r] -> SValue r
S.litList (forall a b s. (a -> b) -> State s a -> State s b
onStateValue 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 :: forall (r :: * -> *).
RenderSym r =>
SVariable r -> [SVariable r] -> MSBody r -> MSStatement r
funcDecDef SVariable r
v [SVariable r]
ps MSBody r
b = do
r (Variable r)
vr <- 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
v
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ String -> MethodState -> MethodState
useVarName forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). VariableElim r => r (Variable r) -> String
variableName r (Variable r)
vr
MethodState
s <- forall s (m :: * -> *). MonadState s m => m s
get
r (Method r)
f <- forall (r :: * -> *).
MethodSym r =>
String
-> r (Scope r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
function (forall (r :: * -> *). VariableElim r => r (Variable r) -> String
variableName r (Variable r)
vr) forall (r :: * -> *). ScopeSym r => r (Scope r)
private (forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
vr)
(forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
S.param [SVariable r]
ps) MSBody r
b
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (forall s t a b. ASetter s t a b -> b -> s -> t
L.set Lens' MethodState [String]
currParameters (MethodState
s forall s a. s -> Getting a s a -> a
^. Lens' MethodState [String]
currParameters))
forall (r :: * -> *). RenderSym r => Doc -> MSStatement r
mkStmtNoEnd forall a b. (a -> b) -> a -> b
$ 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 :: forall (r :: * -> *).
RenderSym r =>
(String -> VSType r -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MSStatement r
inOutCall String -> VSType r -> [SValue r] -> SValue r
f String
n [SValue r]
ins [] [] = forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
S.valStmt forall a b. (a -> b) -> a -> b
$ String -> VSType r -> [SValue r] -> SValue r
f String
n forall (r :: * -> *). TypeSym r => VSType r
S.void [SValue r]
ins
inOutCall String -> VSType r -> [SValue r] -> SValue r
f String
n [SValue r]
ins [SVariable r]
outs [SVariable r]
both = 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 forall (r :: * -> *). TypeSym r => VSType r
S.void (forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
S.valueOf
[SVariable r]
both forall a. [a] -> [a] -> [a]
++ [SValue r]
ins)]
where rets :: [SVariable r]
rets = [SVariable r]
both forall a. [a] -> [a] -> [a]
++ [SVariable r]
outs
forLoopError :: String -> String
forLoopError :: String -> String
forLoopError String
l = String
"Classic for loops not available in " forall a. [a] -> [a] -> [a]
++ String
l forall a. [a] -> [a] -> [a]
++ String
", use " forall a. [a] -> [a] -> [a]
++
String
"forRange, forEach, or while instead"
mainBody :: (RenderSym r) => MSBody r -> SMethod r
mainBody :: forall (r :: * -> *). RenderSym r => MSBody r -> SMethod r
mainBody MSBody r
b = do
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify MethodState -> MethodState
setCurrMain
r (Body r)
bod <- MSBody r
b
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (Doc -> MethodState -> MethodState
setMainDoc forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body r (Body r)
bod)
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 :: forall (r :: * -> *).
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
f [SVariable r]
ins [] [] MSBody r
b = VSType r -> [MSParameter r] -> MSBody r -> SMethod r
f forall (r :: * -> *). TypeSym r => VSType r
S.void (forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
S.param [SVariable r]
ins) MSBody r
b
inOutFunc VSType r -> [MSParameter r] -> MSBody r -> SMethod r
f [SVariable r]
ins [SVariable r]
outs [SVariable r]
both MSBody r
b = VSType r -> [MSParameter r] -> MSBody r -> SMethod r
f
(forall (r :: * -> *). RenderType r => [VSType r] -> VSType r
multiType forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall a b s. (a -> b) -> State s a -> State s b
onStateValue forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType) [SVariable r]
rets)
(forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
S.pointerParam [SVariable r]
both forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
S.param [SVariable r]
ins)
(forall (r :: * -> *). RenderBody r => [MSBody r] -> MSBody r
multiBody [forall (r :: * -> *). BodySym r => [MSStatement r] -> MSBody r
bodyStatements forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *).
DeclStatement r =>
SVariable r -> MSStatement r
S.varDec [SVariable r]
outs, MSBody r
b, forall (r :: * -> *). BodySym r => MSStatement r -> MSBody r
oneLiner forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
InternalControlStmt r =>
[SValue r] -> MSStatement r
S.multiReturn forall a b. (a -> b) -> a -> b
$
forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
S.valueOf [SVariable r]
rets])
where rets :: [SVariable r]
rets = [SVariable r]
both 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' :: 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
docInOutFunc' FuncDocRenderer
dfr [SVariable r]
-> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r
f String
desc [(String, SVariable r)]
is [(String, SVariable r)]
os [(String, SVariable r)]
bs MSBody r
b = forall (r :: * -> *).
RenderSym r =>
FuncDocRenderer
-> String -> [String] -> [String] -> SMethod r -> SMethod r
docFuncRepr FuncDocRenderer
dfr String
desc (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ [(String, SVariable r)]
bs forall a. [a] -> [a] -> [a]
++ [(String, SVariable r)]
is)
(forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ [(String, SVariable r)]
bs forall a. [a] -> [a] -> [a]
++ [(String, SVariable r)]
os) ([SVariable r]
-> [SVariable r] -> [SVariable r] -> MSBody r -> SMethod r
f (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd [(String, SVariable r)]
is) (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd [(String, SVariable r)]
os) (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd [(String, SVariable r)]
bs) MSBody r
b)
floatRender :: String
floatRender :: String
floatRender = String
"Float"
float :: (RenderSym r) => VSType r
float :: forall (r :: * -> *). RenderSym r => VSType r
float = 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"
string' :: (RenderSym r) => VSType r
string' :: forall (r :: * -> *). RenderSym r => VSType r
string' = forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData CodeType
String String
stringRender' (String -> Doc
text String
stringRender')
inherit :: (Monad r) => Maybe Label -> r ParentSpec
inherit :: forall (r :: * -> *). Monad r => Maybe String -> r Doc
inherit Maybe String
n = forall (r :: * -> *) a. Monad r => a -> r a
toCode forall a b. (a -> b) -> a -> b
$ forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
empty ((Doc
colon Doc -> Doc -> Doc
<+>) forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc
text) Maybe String
n
implements :: (Monad r) => [Label] -> r ParentSpec
implements :: forall (r :: * -> *). Monad r => [String] -> r Doc
implements [String]
is = forall (r :: * -> *) a. Monad r => a -> r a
toCode forall a b. (a -> b) -> a -> b
$ Doc
colon Doc -> Doc -> Doc
<+> String -> Doc
text (forall a. [a] -> [[a]] -> [a]
intercalate String
listSep [String]
is)
boolRender :: String
boolRender :: String
boolRender = String
"Bool"
bool :: (RenderSym r) => VSType r
bool :: forall (r :: * -> *). RenderSym r => VSType r
bool = forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData CodeType
Boolean String
boolRender (String -> Doc
text String
boolRender)
docMod' :: (RenderSym r) => String -> String -> [String] -> String -> SFile r -> SFile r
docMod' :: forall (r :: * -> *).
RenderSym r =>
String -> String -> [String] -> String -> SFile r -> SFile r
docMod' = forall (r :: * -> *).
RenderSym r =>
ModuleDocRenderer
-> String -> String -> [String] -> String -> SFile r -> SFile r
docMod ModuleDocRenderer
modDoc'
modDoc' :: ModuleDocRenderer
modDoc' :: ModuleDocRenderer
modDoc' String
desc [String]
as String
date String
m = String
m forall a. a -> [a] -> [a]
: [String
desc | Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
desc)] forall a. [a] -> [a] -> [a]
++
[String -> String -> String
docField String
authorDoc ([String] -> String
stringList [String]
as) | Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
as)] forall a. [a] -> [a] -> [a]
++
[String -> String -> String
docField String
dateDoc String
date | Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
date)] forall a. [a] -> [a] -> [a]
++
[String -> String -> String
docField String
noteDoc String
watermark]
docField :: String -> String -> String
docField :: String -> String -> String
docField String
ty String
info = String
docCommandInit forall a. [a] -> [a] -> [a]
++ String
ty forall a. [a] -> [a] -> [a]
++ String
docCommandSep forall a. [a] -> [a] -> [a]
++ String
info
docCommandInit, docCommandSep, authorDoc, dateDoc, noteDoc :: String
docCommandInit :: String
docCommandInit = String
"- "
docCommandSep :: String
docCommandSep = String
": "
authorDoc :: String
authorDoc = String
"Authors"
dateDoc :: String
dateDoc = String
"Date"
noteDoc :: String
noteDoc = String
"Note"