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

-- | The logic to render C# code is contained in this module
module GOOL.Drasil.LanguageRenderer.CSharpRenderer (
  -- * C# Code Configuration -- defines syntax of all C# code
  CSharpCode(..), csName, csVersion
) where

import Utils.Drasil (indent)

import GOOL.Drasil.CodeType (CodeType(..))
import GOOL.Drasil.ClassInterface (Label, MSBody, VSType, SVariable, SValue, 
  VSFunction, MSStatement, MSParameter, SMethod, OOProg, ProgramSym(..),
  FileSym(..), PermanenceSym(..), BodySym(..), oneLiner, BlockSym(..),
  TypeSym(..), TypeElim(..), VariableSym(..), VariableElim(..), ValueSym(..),
  Argument(..), Literal(..), litZero, MathConstant(..), VariableValue(..),
  CommandLineArgs(..), NumericExpression(..), BooleanExpression(..),
  Comparison(..), ValueExpression(..), funcApp, selfFuncApp, extFuncApp,
  newObj, InternalValueExp(..), objMethodCallNoParams, FunctionSym(..), ($.),
  GetSet(..), List(..), InternalList(..), ThunkSym(..), VectorType(..),
  VectorDecl(..), VectorThunk(..), VectorExpression(..), ThunkAssign(..),
  StatementSym(..), AssignStatement(..), (&=), DeclStatement(..),
  IOStatement(..), StringStatement(..), FuncAppStatement(..),
  CommentStatement(..), ControlStatement(..), StatePattern(..),
  ObserverPattern(..), StrategyPattern(..), ScopeSym(..), ParameterSym(..),
  MethodSym(..), StateVarSym(..), ClassSym(..), ModuleSym(..))
import GOOL.Drasil.RendererClasses (RenderSym, RenderFile(..), ImportSym(..), 
  ImportElim, PermElim(binding), RenderBody(..), BodyElim, RenderBlock(..), 
  BlockElim, RenderType(..), InternalTypeElim, UnaryOpSym(..), BinaryOpSym(..), 
  OpElim(uOpPrec, bOpPrec), RenderVariable(..), InternalVarElim(variableBind), 
  RenderValue(..), ValueElim(valuePrec), InternalGetSet(..),
  InternalListFunc(..),  RenderFunction(..), FunctionElim(functionType),
  InternalAssignStmt(..), InternalIOStmt(..), InternalControlStmt(..),
  RenderStatement(..), StatementElim(statementTerm), RenderScope(..),
  ScopeElim, MethodTypeSym(..), RenderParam(..), ParamElim(parameterName,
  parameterType), RenderMethod(..), MethodElim, StateVarElim, RenderClass(..),
  ClassElim, RenderMod(..), ModuleElim, BlockCommentSym(..), BlockCommentElim)
import qualified GOOL.Drasil.RendererClasses as RC (import', perm, body, block,
  type', uOp, bOp, variable, value, function, statement, scope, parameter,
  method, stateVar, class', module', blockComment')
import GOOL.Drasil.LanguageRenderer (new, dot, blockCmtStart, blockCmtEnd, 
  docCmtStart, bodyStart, bodyEnd, endStatement, commentStart, elseIfLabel, 
  inLabel, tryLabel, catchLabel, throwLabel, exceptionObj', new', listSep',
  args, nullLabel, listSep, access, containing, mathFunc, valueList, 
  variableList, appendToBody, surroundBody)
import qualified GOOL.Drasil.LanguageRenderer as R (class', multiStmt, body, 
  printFile, param, method, listDec, classVar, func, cast, listSetFunc, 
  castObj, static, dynamic, break, continue, private, public, blockCmt, docCmt, 
  addComments, commentedMod, commentedItem)
import GOOL.Drasil.LanguageRenderer.Constructors (mkStmt, 
  mkStateVal, mkVal, VSOp, unOpPrec, powerPrec, unExpr, unExpr', 
  unExprNumDbl, typeUnExpr, binExpr, binExprNumDbl', typeBinExpr)
import qualified GOOL.Drasil.LanguageRenderer.LanguagePolymorphic as G (
  multiBody, block, multiBlock, listInnerType, obj, csc, sec, cot, negateOp,
  equalOp, notEqualOp, greaterOp, greaterEqualOp, lessOp, lessEqualOp, plusOp,
  minusOp, multOp, divideOp, moduloOp, var, staticVar, objVar, arrayElem,
  litChar, litDouble, litInt, litString, valueOf, arg, argsList, objAccess,
  objMethodCall, call, funcAppMixedArgs, selfFuncAppMixedArgs, newObjMixedArgs,
  lambda, func, get, set, listAdd, listAppend, listAccess, listSet, getFunc,
  setFunc, listAppendFunc, stmt, loopStmt, emptyStmt, assign, subAssign,
  increment, objDecNew, print, closeFile, returnStmt, valStmt,
  comment, throw, ifCond, tryCatch, construct, param, method, getMethod,
  setMethod, function, buildClass, implementingClass, commentedClass,
  modFromData, fileDoc, fileFromData, defaultOptSpace)
import qualified GOOL.Drasil.LanguageRenderer.CommonPseudoOO as CP (int,
  constructor, doxFunc, doxClass, doxMod, extVar, classVar, objVarSelf,
  extFuncAppMixedArgs, indexOf, listAddFunc, discardFileLine, intClass, 
  arrayType, pi, printSt, arrayDec, arrayDecDef, openFileA, forEach, docMain, 
  mainFunction, buildModule', string, constDecDef, docInOutFunc, bindingError, 
  notNull, listDecDef, destructorError, stateVarDef, constVar, listSetFunc, 
  extraClass, listAccessFunc, doubleRender, openFileR, openFileW, stateVar, 
  inherit, implements)
import qualified GOOL.Drasil.LanguageRenderer.CLike as C (float, double, char, 
  listType, void, notOp, andOp, orOp, self, litTrue, litFalse, litFloat, 
  inlineIf, libFuncAppMixedArgs, libNewObjMixedArgs, listSize, increment1, 
  decrement1, varDec, varDecDef, listDec, extObjDecNew, switch, for, while, 
  intFunc, multiAssignError, multiReturnError, multiTypeError)
import qualified GOOL.Drasil.LanguageRenderer.Macros as M (ifExists, 
  runStrategy, listSlice, stringListVals, stringListLists, forRange, 
  notifyObservers, checkState)
import GOOL.Drasil.AST (Terminator(..), FileType(..), FileData(..), fileD, 
  FuncData(..), fd, ModData(..), md, updateMod, MethodData(..), mthd, 
  updateMthd, OpData(..), ParamData(..), pd, updateParam, ProgData(..), progD, 
  TypeData(..), td, ValData(..), vd, updateValDoc, Binding(..), VarData(..), 
  vard, CommonThunk, pureValue, vectorize, vectorize2, sumComponents,
  commonVecIndex, commonThunkElim, commonThunkDim)
import GOOL.Drasil.Helpers (angles, hicat, toCode, toState, onCodeValue, 
  onStateValue, on2CodeValues, on2StateValues, on3CodeValues, on3StateValues, 
  on2StateWrapped, onCodeList, onStateList)
import GOOL.Drasil.State (VS, lensGStoFS, lensMStoVS, modifyReturn, revFiles,
  addLangImport, addLangImportVS, setFileType, getClassName, setCurrMain,
  useVarName, genLoopIndex)

import Prelude hiding (break,print,(<>),sin,cos,tan,floor)
import Control.Applicative (liftA2)
import Control.Lens.Zoom (zoom)
import Control.Monad (join)
import Control.Monad.State (modify)
import Data.Composition ((.:))
import Data.List (intercalate)
import Text.PrettyPrint.HughesPJ (Doc, text, (<>), (<+>), ($$), parens, empty,
  equals, vcat, lbrace, rbrace, braces, colon, space, quotes)

csExt :: String
csExt :: String
csExt = String
"cs"

newtype CSharpCode a = CSC {forall a. CSharpCode a -> a
unCSC :: a} deriving CSharpCode a -> CSharpCode a -> Bool
forall a. Eq a => CSharpCode a -> CSharpCode a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CSharpCode a -> CSharpCode a -> Bool
$c/= :: forall a. Eq a => CSharpCode a -> CSharpCode a -> Bool
== :: CSharpCode a -> CSharpCode a -> Bool
$c== :: forall a. Eq a => CSharpCode a -> CSharpCode a -> Bool
Eq

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

instance Applicative CSharpCode where
  pure :: forall a. a -> CSharpCode a
pure = forall a. a -> CSharpCode a
CSC
  (CSC a -> b
f) <*> :: forall a b. CSharpCode (a -> b) -> CSharpCode a -> CSharpCode b
<*> (CSC a
x) = forall a. a -> CSharpCode a
CSC (a -> b
f a
x)

instance Monad CSharpCode where
  CSC a
x >>= :: forall a b. CSharpCode a -> (a -> CSharpCode b) -> CSharpCode b
>>= a -> CSharpCode b
f = a -> CSharpCode b
f a
x

instance OOProg CSharpCode where

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

instance RenderSym CSharpCode

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

  docMod :: String
-> [String] -> String -> SFile CSharpCode -> SFile CSharpCode
docMod = forall (r :: * -> *).
RenderSym r =>
String -> String -> [String] -> String -> SFile r -> SFile r
CP.doxMod String
csExt

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

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

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

instance ImportSym CSharpCode where
  type Import CSharpCode = Doc
  langImport :: String -> CSharpCode (Import CSharpCode)
langImport = forall (r :: * -> *) a. Monad r => a -> r a
toCode forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc
csImport
  modImport :: String -> CSharpCode (Import CSharpCode)
modImport = forall (r :: * -> *). ImportSym r => String -> r (Import r)
langImport

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

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

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

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

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

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

instance BodyElim CSharpCode where
  body :: CSharpCode (Body CSharpCode) -> Doc
body = forall a. CSharpCode a -> a
unCSC

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

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

instance BlockElim CSharpCode where
  block :: CSharpCode (Block CSharpCode) -> Doc
block = forall a. CSharpCode a -> a
unCSC

instance TypeSym CSharpCode where
  type Type CSharpCode = TypeData
  bool :: VSType CSharpCode
bool = forall a. VS a -> VS a
addSystemImport forall (r :: * -> *). RenderSym r => VSType r
csBoolType
  int :: VSType CSharpCode
int = forall (r :: * -> *). RenderSym r => VSType r
CP.int
  float :: VSType CSharpCode
float = forall (r :: * -> *). RenderSym r => VSType r
C.float
  double :: VSType CSharpCode
double = forall (r :: * -> *). RenderSym r => VSType r
C.double
  char :: VSType CSharpCode
char = forall (r :: * -> *). RenderSym r => VSType r
C.char
  string :: VSType CSharpCode
string = forall (r :: * -> *). RenderSym r => VSType r
CP.string
  infile :: VSType CSharpCode
infile = forall (r :: * -> *). RenderSym r => VSType r
csInfileType
  outfile :: VSType CSharpCode
outfile = forall (r :: * -> *). RenderSym r => VSType r
csOutfileType
  listType :: VSType CSharpCode -> VSType CSharpCode
listType VSType CSharpCode
t = do
    forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addLangImportVS String
csGeneric) 
    forall (r :: * -> *). RenderSym r => String -> VSType r -> VSType r
C.listType String
csList VSType CSharpCode
t
  arrayType :: VSType CSharpCode -> VSType CSharpCode
arrayType = forall (r :: * -> *). RenderSym r => VSType r -> VSType r
CP.arrayType
  listInnerType :: VSType CSharpCode -> VSType CSharpCode
listInnerType = forall (r :: * -> *). RenderSym r => VSType r -> VSType r
G.listInnerType
  obj :: String -> VSType CSharpCode
obj = forall (r :: * -> *). RenderSym r => String -> VSType r
G.obj
  funcType :: [VSType CSharpCode] -> VSType CSharpCode -> VSType CSharpCode
funcType = forall (r :: * -> *).
RenderSym r =>
[VSType r] -> VSType r -> VSType r
csFuncType
  void :: VSType CSharpCode
void = forall (r :: * -> *). RenderSym r => VSType r
C.void

instance TypeElim CSharpCode where
  getType :: CSharpCode (Type CSharpCode) -> CodeType
getType = TypeData -> CodeType
cType forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. CSharpCode a -> a
unCSC
  getTypeString :: CSharpCode (Type CSharpCode) -> String
getTypeString = TypeData -> String
typeString forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. CSharpCode a -> a
unCSC
  
instance RenderType CSharpCode where
  multiType :: [VSType CSharpCode] -> VSType CSharpCode
multiType [VSType CSharpCode]
_ = forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String -> String
C.multiTypeError String
csName
  typeFromData :: CodeType -> String -> Doc -> VSType CSharpCode
typeFromData CodeType
t String
s Doc
d = forall a s. a -> State s a
toState forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *) a. Monad r => a -> r a
toCode forall a b. (a -> b) -> a -> b
$ CodeType -> String -> Doc -> TypeData
td CodeType
t String
s Doc
d

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

instance UnaryOpSym CSharpCode where
  type UnaryOp CSharpCode = OpData
  notOp :: VSUnOp CSharpCode
notOp = forall (r :: * -> *). Monad r => VSOp r
C.notOp
  negateOp :: VSUnOp CSharpCode
negateOp = forall (r :: * -> *). Monad r => VSOp r
G.negateOp
  sqrtOp :: VSUnOp CSharpCode
sqrtOp = forall (r :: * -> *). Monad r => String -> VSOp r
csUnaryMath String
"Sqrt"
  absOp :: VSUnOp CSharpCode
absOp = forall (r :: * -> *). Monad r => String -> VSOp r
csUnaryMath String
"Abs"
  logOp :: VSUnOp CSharpCode
logOp = forall (r :: * -> *). Monad r => String -> VSOp r
csUnaryMath String
"Log10"
  lnOp :: VSUnOp CSharpCode
lnOp = forall (r :: * -> *). Monad r => String -> VSOp r
csUnaryMath String
"Log"
  expOp :: VSUnOp CSharpCode
expOp = forall (r :: * -> *). Monad r => String -> VSOp r
csUnaryMath String
"Exp"
  sinOp :: VSUnOp CSharpCode
sinOp = forall (r :: * -> *). Monad r => String -> VSOp r
csUnaryMath String
"Sin"
  cosOp :: VSUnOp CSharpCode
cosOp = forall (r :: * -> *). Monad r => String -> VSOp r
csUnaryMath String
"Cos"
  tanOp :: VSUnOp CSharpCode
tanOp = forall (r :: * -> *). Monad r => String -> VSOp r
csUnaryMath String
"Tan"
  asinOp :: VSUnOp CSharpCode
asinOp = forall (r :: * -> *). Monad r => String -> VSOp r
csUnaryMath String
"Asin"
  acosOp :: VSUnOp CSharpCode
acosOp = forall (r :: * -> *). Monad r => String -> VSOp r
csUnaryMath String
"Acos"
  atanOp :: VSUnOp CSharpCode
atanOp = forall (r :: * -> *). Monad r => String -> VSOp r
csUnaryMath String
"Atan"
  floorOp :: VSUnOp CSharpCode
floorOp = forall (r :: * -> *). Monad r => String -> VSOp r
csUnaryMath String
"Floor"
  ceilOp :: VSUnOp CSharpCode
ceilOp = forall (r :: * -> *). Monad r => String -> VSOp r
csUnaryMath String
"Ceiling"

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

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

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

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

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

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

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

instance Argument CSharpCode where
  pointerArg :: SValue CSharpCode -> SValue CSharpCode
pointerArg = forall a. a -> a
id

instance Literal CSharpCode where
  litTrue :: SValue CSharpCode
litTrue = forall (r :: * -> *). RenderSym r => SValue r
C.litTrue
  litFalse :: SValue CSharpCode
litFalse = forall (r :: * -> *). RenderSym r => SValue r
C.litFalse
  litChar :: Char -> SValue CSharpCode
litChar = forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc) -> Char -> SValue r
G.litChar Doc -> Doc
quotes
  litDouble :: Double -> SValue CSharpCode
litDouble = forall (r :: * -> *). RenderSym r => Double -> SValue r
G.litDouble
  litFloat :: Float -> SValue CSharpCode
litFloat = forall (r :: * -> *). RenderSym r => Float -> SValue r
C.litFloat
  litInt :: Integer -> SValue CSharpCode
litInt = forall (r :: * -> *). RenderSym r => Integer -> SValue r
G.litInt
  litString :: String -> SValue CSharpCode
litString = forall (r :: * -> *). RenderSym r => String -> SValue r
G.litString
  litArray :: VSType CSharpCode -> [SValue CSharpCode] -> SValue CSharpCode
litArray = forall (r :: * -> *).
RenderSym r =>
(VSType r -> VSType r) -> VSType r -> [SValue r] -> SValue r
csLitList forall (r :: * -> *). TypeSym r => VSType r -> VSType r
arrayType
  litList :: VSType CSharpCode -> [SValue CSharpCode] -> SValue CSharpCode
litList = forall (r :: * -> *).
RenderSym r =>
(VSType r -> VSType r) -> VSType r -> [SValue r] -> SValue r
csLitList forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listType

instance MathConstant CSharpCode where
  pi :: SValue CSharpCode
pi = forall (r :: * -> *). RenderSym r => SValue r
CP.pi

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

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

instance NumericExpression CSharpCode where
  #~ :: SValue CSharpCode -> SValue CSharpCode
(#~) = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr' forall (r :: * -> *). UnaryOpSym r => VSUnOp r
negateOp
  #/^ :: SValue CSharpCode -> SValue CSharpCode
(#/^) = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExprNumDbl forall (r :: * -> *). UnaryOpSym r => VSUnOp r
sqrtOp
  #| :: SValue CSharpCode -> SValue CSharpCode
(#|) = forall (r :: * -> *).
RenderSym r =>
VSUnOp r -> SValue r -> SValue r
unExpr forall (r :: * -> *). UnaryOpSym r => VSUnOp r
absOp
  #+ :: SValue CSharpCode -> SValue CSharpCode -> SValue CSharpCode
(#+) = forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
plusOp
  #- :: SValue CSharpCode -> SValue CSharpCode -> SValue CSharpCode
(#-) = forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
minusOp
  #* :: SValue CSharpCode -> SValue CSharpCode -> SValue CSharpCode
(#*) = forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
multOp
  #/ :: SValue CSharpCode -> SValue CSharpCode -> SValue CSharpCode
(#/) = forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
divideOp
  #% :: SValue CSharpCode -> SValue CSharpCode -> SValue CSharpCode
(#%) = forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr forall (r :: * -> *). BinaryOpSym r => VSBinOp r
moduloOp
  #^ :: SValue CSharpCode -> SValue CSharpCode -> SValue CSharpCode
(#^) = forall (r :: * -> *).
RenderSym r =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExprNumDbl' forall (r :: * -> *). BinaryOpSym r => VSBinOp r
powerOp

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

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

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

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

  funcAppMixedArgs :: MixedCall CSharpCode
funcAppMixedArgs = forall (r :: * -> *). RenderSym r => MixedCall r
G.funcAppMixedArgs
  selfFuncAppMixedArgs :: MixedCall CSharpCode
selfFuncAppMixedArgs = forall (r :: * -> *).
RenderSym r =>
Doc -> SVariable r -> MixedCall r
G.selfFuncAppMixedArgs Doc
dot forall (r :: * -> *). VariableSym r => SVariable r
self
  extFuncAppMixedArgs :: String -> MixedCall CSharpCode
extFuncAppMixedArgs = forall (r :: * -> *). RenderSym r => String -> MixedCall r
CP.extFuncAppMixedArgs
  libFuncAppMixedArgs :: String -> MixedCall CSharpCode
libFuncAppMixedArgs = forall (r :: * -> *). RenderSym r => String -> MixedCall r
C.libFuncAppMixedArgs
  newObjMixedArgs :: MixedCtorCall CSharpCode
newObjMixedArgs = forall (r :: * -> *). RenderSym r => MixedCall r
G.newObjMixedArgs (String
new forall a. [a] -> [a] -> [a]
++ String
" ")
  extNewObjMixedArgs :: MixedCall CSharpCode
extNewObjMixedArgs String
_ = forall (r :: * -> *). ValueExpression r => MixedCtorCall r
newObjMixedArgs
  libNewObjMixedArgs :: MixedCall CSharpCode
libNewObjMixedArgs = forall (r :: * -> *). RenderSym r => MixedCall r
C.libNewObjMixedArgs

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

  notNull :: SValue CSharpCode -> SValue CSharpCode
notNull = forall (r :: * -> *). RenderSym r => String -> SValue r -> SValue r
CP.notNull String
nullLabel

instance RenderValue CSharpCode where
  inputFunc :: SValue CSharpCode
inputFunc = forall a. VS a -> VS a
addSystemImport SValue CSharpCode
csReadLineFunc
  printFunc :: SValue CSharpCode
printFunc = forall a. VS a -> VS a
addSystemImport forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal forall (r :: * -> *). TypeSym r => VSType r
void (String -> Doc
text forall a b. (a -> b) -> a -> b
$ String
csConsole String -> String -> String
`access` 
    String
csWrite)
  printLnFunc :: SValue CSharpCode
printLnFunc = forall a. VS a -> VS a
addSystemImport forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal forall (r :: * -> *). TypeSym r => VSType r
void (String -> Doc
text forall a b. (a -> b) -> a -> b
$ String
csConsole String -> String -> String
`access` 
    String
csWriteLine)
  printFileFunc :: SValue CSharpCode -> SValue CSharpCode
printFileFunc SValue CSharpCode
w' = forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> m a -> m b -> m c
on2StateWrapped (\CSharpCode (Value CSharpCode)
w CSharpCode TypeData
vt -> 
    forall (r :: * -> *). RenderSym r => r (Type r) -> Doc -> SValue r
mkVal CSharpCode TypeData
vt forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc -> Doc
R.printFile String
csWrite forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value forall a b. (a -> b) -> a -> b
$ CSharpCode (Value CSharpCode)
w) SValue CSharpCode
w' forall (r :: * -> *). TypeSym r => VSType r
void
  printFileLnFunc :: SValue CSharpCode -> SValue CSharpCode
printFileLnFunc SValue CSharpCode
w' = forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> m a -> m b -> m c
on2StateWrapped (\CSharpCode (Value CSharpCode)
w CSharpCode TypeData
vt -> 
    forall (r :: * -> *). RenderSym r => r (Type r) -> Doc -> SValue r
mkVal CSharpCode TypeData
vt forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc -> Doc
R.printFile String
csWriteLine forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value forall a b. (a -> b) -> a -> b
$ CSharpCode (Value CSharpCode)
w) SValue CSharpCode
w' forall (r :: * -> *). TypeSym r => VSType r
void
  
  cast :: VSType CSharpCode -> SValue CSharpCode -> SValue CSharpCode
cast = VSType CSharpCode -> SValue CSharpCode -> SValue CSharpCode
csCast

  call :: Maybe String -> Maybe Doc -> MixedCall CSharpCode
call = forall (r :: * -> *).
RenderSym r =>
Doc -> Maybe String -> Maybe Doc -> MixedCall r
G.call Doc
csNamedArgSep
  
  valFromData :: Maybe Int -> VSType CSharpCode -> Doc -> SValue CSharpCode
valFromData Maybe Int
p VSType CSharpCode
t' Doc
d = do 
    CSharpCode TypeData
t <- VSType CSharpCode
t' 
    forall a s. a -> State s a
toState forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues (Maybe Int -> TypeData -> Doc -> ValData
vd Maybe Int
p) CSharpCode TypeData
t (forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
d)
  
instance ValueElim CSharpCode where
  valuePrec :: CSharpCode (Value CSharpCode) -> Maybe Int
valuePrec = ValData -> Maybe Int
valPrec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. CSharpCode a -> a
unCSC
  value :: CSharpCode (Value CSharpCode) -> Doc
value = ValData -> Doc
val forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. CSharpCode a -> a
unCSC
  
instance InternalValueExp CSharpCode where
  objMethodCallMixedArgs' :: String
-> VSType CSharpCode
-> SValue CSharpCode
-> [SValue CSharpCode]
-> NamedArgs CSharpCode
-> SValue CSharpCode
objMethodCallMixedArgs' = forall (r :: * -> *).
RenderSym r =>
String
-> VSType r -> SValue r -> [SValue r] -> NamedArgs r -> SValue r
G.objMethodCall

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

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

instance List CSharpCode where
  listSize :: SValue CSharpCode -> SValue CSharpCode
listSize = forall (r :: * -> *). RenderSym r => SValue r -> SValue r
C.listSize
  listAdd :: SValue CSharpCode
-> SValue CSharpCode -> SValue CSharpCode -> SValue CSharpCode
listAdd = forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r -> SValue r
G.listAdd
  listAppend :: SValue CSharpCode -> SValue CSharpCode -> SValue CSharpCode
listAppend = forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
G.listAppend
  listAccess :: SValue CSharpCode -> SValue CSharpCode -> SValue CSharpCode
listAccess = forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r
G.listAccess
  listSet :: SValue CSharpCode
-> SValue CSharpCode -> SValue CSharpCode -> SValue CSharpCode
listSet = forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> SValue r -> SValue r
G.listSet
  indexOf :: SValue CSharpCode -> SValue CSharpCode -> SValue CSharpCode
indexOf = forall (r :: * -> *).
RenderSym r =>
String -> SValue r -> SValue r -> SValue r
CP.indexOf String
csIndex
  
instance InternalList CSharpCode where
  listSlice' :: Maybe (SValue CSharpCode)
-> Maybe (SValue CSharpCode)
-> Maybe (SValue CSharpCode)
-> SVariable CSharpCode
-> SValue CSharpCode
-> MSBlock CSharpCode
listSlice' = forall (r :: * -> *).
RenderSym r =>
Maybe (SValue r)
-> Maybe (SValue r)
-> Maybe (SValue r)
-> SVariable r
-> SValue r
-> MSBlock r
M.listSlice

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

instance InternalListFunc CSharpCode where
  listSizeFunc :: VSFunction CSharpCode
listSizeFunc = forall (r :: * -> *).
RenderFunction r =>
Doc -> VSType r -> VSFunction r
funcFromData (Doc -> Doc
R.func Doc
csListSize) forall (r :: * -> *). TypeSym r => VSType r
int
  listAddFunc :: SValue CSharpCode
-> SValue CSharpCode -> SValue CSharpCode -> VSFunction CSharpCode
listAddFunc SValue CSharpCode
_ = forall (r :: * -> *).
RenderSym r =>
String -> SValue r -> SValue r -> VSFunction r
CP.listAddFunc String
csListAdd
  listAppendFunc :: SValue CSharpCode -> VSFunction CSharpCode
listAppendFunc = forall (r :: * -> *).
RenderSym r =>
String -> SValue r -> VSFunction r
G.listAppendFunc String
csListAppend
  listAccessFunc :: VSType CSharpCode -> SValue CSharpCode -> VSFunction CSharpCode
listAccessFunc = forall (r :: * -> *).
RenderSym r =>
VSType r -> SValue r -> VSFunction r
CP.listAccessFunc
  listSetFunc :: SValue CSharpCode
-> SValue CSharpCode -> SValue CSharpCode -> VSFunction CSharpCode
listSetFunc = forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc -> Doc)
-> SValue r -> SValue r -> SValue r -> VSFunction r
CP.listSetFunc Doc -> Doc -> Doc
R.listSetFunc

instance ThunkSym CSharpCode where
  type Thunk CSharpCode = CommonThunk VS

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

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

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

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

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

instance RenderFunction CSharpCode where
  funcFromData :: Doc -> VSType CSharpCode -> VSFunction CSharpCode
funcFromData Doc
d = forall a b s. (a -> b) -> State s a -> State s b
onStateValue (forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue (TypeData -> Doc -> FuncData
`fd` Doc
d))
  
instance FunctionElim CSharpCode where
  functionType :: CSharpCode (Function CSharpCode) -> CSharpCode (Type CSharpCode)
functionType = forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue FuncData -> TypeData
fType
  function :: CSharpCode (Function CSharpCode) -> Doc
function = FuncData -> Doc
funcDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. CSharpCode a -> a
unCSC

instance InternalAssignStmt CSharpCode where
  multiAssign :: [SVariable CSharpCode]
-> [SValue CSharpCode] -> MSStatement CSharpCode
multiAssign [SVariable CSharpCode]
_ [SValue CSharpCode]
_ = forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String -> String
C.multiAssignError String
csName

instance InternalIOStmt CSharpCode where
  printSt :: Bool
-> Maybe (SValue CSharpCode)
-> SValue CSharpCode
-> SValue CSharpCode
-> MSStatement CSharpCode
printSt Bool
_ Maybe (SValue CSharpCode)
_ = forall (r :: * -> *).
RenderSym r =>
SValue r -> SValue r -> MSStatement r
CP.printSt
  
instance InternalControlStmt CSharpCode where
  multiReturn :: [SValue CSharpCode] -> MSStatement CSharpCode
multiReturn [SValue CSharpCode]
_ = forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String -> String
C.multiReturnError String
csName 

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

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

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

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

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

instance DeclStatement CSharpCode where
  varDec :: SVariable CSharpCode -> MSStatement CSharpCode
varDec SVariable CSharpCode
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 CSharpCode
v forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\CSharpCode VarData
v' -> Binding -> MSStatement CSharpCode -> MSStatement CSharpCode
csVarDec (forall (r :: * -> *).
InternalVarElim r =>
r (Variable r) -> Binding
variableBind CSharpCode VarData
v') forall a b. (a -> b) -> a -> b
$ 
    forall (r :: * -> *).
RenderSym r =>
r (Permanence r)
-> r (Permanence r) -> Doc -> SVariable r -> MSStatement r
C.varDec forall (r :: * -> *). PermanenceSym r => r (Permanence r)
static forall (r :: * -> *). PermanenceSym r => r (Permanence r)
dynamic Doc
empty SVariable CSharpCode
v)
  varDecDef :: SVariable CSharpCode -> SValue CSharpCode -> MSStatement CSharpCode
varDecDef = forall (r :: * -> *).
RenderSym r =>
Terminator -> SVariable r -> SValue r -> MSStatement r
C.varDecDef Terminator
Semi
  listDec :: Integer -> SVariable CSharpCode -> MSStatement CSharpCode
listDec Integer
n SVariable CSharpCode
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 CSharpCode
v forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\CSharpCode VarData
v' -> forall (r :: * -> *).
RenderSym r =>
(r (Value r) -> Doc) -> SValue r -> SVariable r -> MSStatement r
C.listDec (forall (r :: * -> *).
RenderSym r =>
r (Variable r) -> r (Value r) -> Doc
R.listDec CSharpCode VarData
v') 
    (forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
n) SVariable CSharpCode
v)
  listDecDef :: SVariable CSharpCode
-> [SValue CSharpCode] -> MSStatement CSharpCode
listDecDef = forall (r :: * -> *).
RenderSym r =>
SVariable r -> [SValue r] -> MSStatement r
CP.listDecDef
  arrayDec :: Integer -> SVariable CSharpCode -> MSStatement CSharpCode
arrayDec Integer
n = forall (r :: * -> *).
RenderSym r =>
SValue r -> SVariable r -> MSStatement r
CP.arrayDec (forall (r :: * -> *). Literal r => Integer -> SValue r
litInt Integer
n)
  arrayDecDef :: SVariable CSharpCode
-> [SValue CSharpCode] -> MSStatement CSharpCode
arrayDecDef = forall (r :: * -> *).
RenderSym r =>
SVariable r -> [SValue r] -> MSStatement r
CP.arrayDecDef
  objDecDef :: SVariable CSharpCode -> SValue CSharpCode -> MSStatement CSharpCode
objDecDef = forall (r :: * -> *).
DeclStatement r =>
SVariable r -> SValue r -> MSStatement r
varDecDef
  objDecNew :: SVariable CSharpCode
-> [SValue CSharpCode] -> MSStatement CSharpCode
objDecNew = forall (r :: * -> *).
RenderSym r =>
SVariable r -> [SValue r] -> MSStatement r
G.objDecNew
  extObjDecNew :: String
-> SVariable CSharpCode
-> [SValue CSharpCode]
-> MSStatement CSharpCode
extObjDecNew = forall (r :: * -> *).
RenderSym r =>
String -> SVariable r -> [SValue r] -> MSStatement r
C.extObjDecNew
  constDecDef :: SVariable CSharpCode -> SValue CSharpCode -> MSStatement CSharpCode
constDecDef = forall (r :: * -> *).
RenderSym r =>
SVariable r -> SValue r -> MSStatement r
CP.constDecDef
  funcDecDef :: SVariable CSharpCode
-> [SVariable CSharpCode]
-> MSBody CSharpCode
-> MSStatement CSharpCode
funcDecDef = forall (r :: * -> *).
RenderSym r =>
SVariable r -> [SVariable r] -> MSBody r -> MSStatement r
csFuncDecDef

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

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

  getInput :: SVariable CSharpCode -> MSStatement CSharpCode
getInput SVariable CSharpCode
v = SVariable CSharpCode
v forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= VSType CSharpCode -> SValue CSharpCode -> SValue CSharpCode
csInput (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 CSharpCode
v) forall (r :: * -> *). RenderValue r => SValue r
inputFunc
  discardInput :: MSStatement CSharpCode
discardInput = SValue CSharpCode -> MSStatement CSharpCode
csDiscardInput forall (r :: * -> *). RenderValue r => SValue r
inputFunc
  getFileInput :: SValue CSharpCode -> SVariable CSharpCode -> MSStatement CSharpCode
getFileInput SValue CSharpCode
f SVariable CSharpCode
v = SVariable CSharpCode
v forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
&= VSType CSharpCode -> SValue CSharpCode -> SValue CSharpCode
csInput (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 CSharpCode
v) (forall (r :: * -> *). RenderSym r => SValue r -> SValue r
csFileInput SValue CSharpCode
f)
  discardFileInput :: SValue CSharpCode -> MSStatement CSharpCode
discardFileInput SValue CSharpCode
f = forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
valStmt forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). RenderSym r => SValue r -> SValue r
csFileInput SValue CSharpCode
f

  openFileR :: SVariable CSharpCode -> SValue CSharpCode -> MSStatement CSharpCode
openFileR = forall (r :: * -> *).
RenderSym r =>
(SValue r -> VSType r -> SValue r)
-> SVariable r -> SValue r -> MSStatement r
CP.openFileR forall (r :: * -> *).
RenderSym r =>
SValue r -> VSType r -> SValue r
csOpenFileR
  openFileW :: SVariable CSharpCode -> SValue CSharpCode -> MSStatement CSharpCode
openFileW = forall (r :: * -> *).
RenderSym r =>
(SValue r -> VSType r -> SValue r -> SValue r)
-> SVariable r -> SValue r -> MSStatement r
CP.openFileW forall (r :: * -> *).
RenderSym r =>
SValue r -> VSType r -> SValue r -> SValue r
csOpenFileWorA
  openFileA :: SVariable CSharpCode -> SValue CSharpCode -> MSStatement CSharpCode
openFileA = forall (r :: * -> *).
RenderSym r =>
(SValue r -> VSType r -> SValue r -> SValue r)
-> SVariable r -> SValue r -> MSStatement r
CP.openFileA forall (r :: * -> *).
RenderSym r =>
SValue r -> VSType r -> SValue r -> SValue r
csOpenFileWorA
  closeFile :: SValue CSharpCode -> MSStatement CSharpCode
closeFile = forall (r :: * -> *).
RenderSym r =>
String -> SValue r -> MSStatement r
G.closeFile String
csClose

  getFileInputLine :: SValue CSharpCode -> SVariable CSharpCode -> MSStatement CSharpCode
getFileInputLine = forall (r :: * -> *).
IOStatement r =>
SValue r -> SVariable r -> MSStatement r
getFileInput
  discardFileLine :: SValue CSharpCode -> MSStatement CSharpCode
discardFileLine = forall (r :: * -> *).
RenderSym r =>
String -> SValue r -> MSStatement r
CP.discardFileLine String
csReadLine
  getFileInputAll :: SValue CSharpCode -> SVariable CSharpCode -> MSStatement CSharpCode
getFileInputAll SValue CSharpCode
f SVariable CSharpCode
v = forall (r :: * -> *).
ControlStatement r =>
SValue r -> MSBody r -> MSStatement r
while ((SValue CSharpCode
f forall (r :: * -> *).
FunctionSym r =>
SValue r -> VSFunction r -> SValue r
$. forall (r :: * -> *).
RenderFunction r =>
Doc -> VSType r -> VSFunction r
funcFromData (Doc
dot Doc -> Doc -> Doc
<> String -> Doc
text String
csEOS) forall (r :: * -> *). TypeSym r => VSType r
bool) ?!)
    (forall (r :: * -> *). BodySym r => MSStatement r -> MSBody r
oneLiner forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
valStmt forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). List r => SValue r -> SValue r -> SValue r
listAppend (forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable CSharpCode
v) (forall (r :: * -> *). RenderSym r => SValue r -> SValue r
csFileInput SValue CSharpCode
f))

instance StringStatement CSharpCode where
  stringSplit :: Char
-> SVariable CSharpCode
-> SValue CSharpCode
-> MSStatement CSharpCode
stringSplit Char
d SVariable CSharpCode
vnew SValue CSharpCode
s = forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
assign SVariable CSharpCode
vnew forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). ValueExpression r => PosCtorCall r
newObj (forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listType forall (r :: * -> *). TypeSym r => VSType r
string) 
    [SValue CSharpCode
s forall (r :: * -> *).
FunctionSym r =>
SValue r -> VSFunction r -> SValue r
$. Char -> VSFunction CSharpCode
csSplitFunc Char
d]

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

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

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

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

  returnStmt :: SValue CSharpCode -> MSStatement CSharpCode
returnStmt = forall (r :: * -> *).
RenderSym r =>
Terminator -> SValue r -> MSStatement r
G.returnStmt Terminator
Semi
  
  throw :: String -> MSStatement CSharpCode
throw String
msg = do
    forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> MethodState -> MethodState
addLangImport String
csSystem)
    forall (r :: * -> *).
RenderSym r =>
(r (Value r) -> Doc) -> Terminator -> String -> MSStatement r
G.throw forall (r :: * -> *). RenderSym r => r (Value r) -> Doc
csThrowDoc Terminator
Semi String
msg

  ifCond :: [(SValue CSharpCode, MSBody CSharpCode)]
-> MSBody CSharpCode -> MSStatement CSharpCode
ifCond = forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc)
-> Doc
-> OptionalSpace
-> Doc
-> Doc
-> [(SValue r, MSBody r)]
-> MSBody r
-> MSStatement r
G.ifCond Doc -> Doc
parens Doc
bodyStart OptionalSpace
G.defaultOptSpace Doc
elseIfLabel Doc
bodyEnd
  switch :: SValue CSharpCode
-> [(SValue CSharpCode, MSBody CSharpCode)]
-> MSBody CSharpCode
-> MSStatement CSharpCode
switch = forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc)
-> MSStatement r
-> SValue r
-> [(SValue r, MSBody r)]
-> MSBody r
-> MSStatement r
C.switch Doc -> Doc
parens forall (r :: * -> *). ControlStatement r => MSStatement r
break

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

  for :: MSStatement CSharpCode
-> SValue CSharpCode
-> MSStatement CSharpCode
-> MSBody CSharpCode
-> MSStatement CSharpCode
for = forall (r :: * -> *).
RenderSym r =>
Doc
-> Doc
-> MSStatement r
-> SValue r
-> MSStatement r
-> MSBody r
-> MSStatement r
C.for Doc
bodyStart Doc
bodyEnd
  forRange :: SVariable CSharpCode
-> SValue CSharpCode
-> SValue CSharpCode
-> SValue CSharpCode
-> MSBody CSharpCode
-> MSStatement CSharpCode
forRange = forall (r :: * -> *).
RenderSym r =>
SVariable r
-> SValue r -> SValue r -> SValue r -> MSBody r -> MSStatement r
M.forRange
  forEach :: SVariable CSharpCode
-> SValue CSharpCode -> MSBody CSharpCode -> MSStatement CSharpCode
forEach = forall (r :: * -> *).
RenderSym r =>
Doc
-> Doc
-> Doc
-> Doc
-> SVariable r
-> SValue r
-> MSBody r
-> MSStatement r
CP.forEach Doc
bodyStart Doc
bodyEnd Doc
csForEach Doc
inLabel 
  while :: SValue CSharpCode -> MSBody CSharpCode -> MSStatement CSharpCode
while = forall (r :: * -> *).
RenderSym r =>
(Doc -> Doc) -> Doc -> Doc -> SValue r -> MSBody r -> MSStatement r
C.while Doc -> Doc
parens Doc
bodyStart Doc
bodyEnd

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

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

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

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

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

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

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

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

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

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

instance MethodSym CSharpCode where
  type Method CSharpCode = MethodData
  method :: String
-> CSharpCode (Scope CSharpCode)
-> CSharpCode (Permanence CSharpCode)
-> VSType CSharpCode
-> [MSParameter CSharpCode]
-> MSBody CSharpCode
-> SMethod CSharpCode
method = forall (r :: * -> *).
RenderSym r =>
String
-> r (Scope r)
-> r (Permanence r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
G.method
  getMethod :: SVariable CSharpCode -> SMethod CSharpCode
getMethod = forall (r :: * -> *). RenderSym r => SVariable r -> SMethod r
G.getMethod
  setMethod :: SVariable CSharpCode -> SMethod CSharpCode
setMethod = forall (r :: * -> *). RenderSym r => SVariable r -> SMethod r
G.setMethod
  constructor :: [MSParameter CSharpCode]
-> NamedArgs CSharpCode -> MSBody CSharpCode -> SMethod CSharpCode
constructor [MSParameter CSharpCode]
ps NamedArgs CSharpCode
is MSBody CSharpCode
b = MS String
getClassName forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\String
n -> forall (r :: * -> *).
RenderSym r =>
String
-> [MSParameter r] -> Initializers r -> MSBody r -> SMethod r
CP.constructor String
n [MSParameter CSharpCode]
ps NamedArgs CSharpCode
is MSBody CSharpCode
b)

  docMain :: MSBody CSharpCode -> SMethod CSharpCode
docMain = forall (r :: * -> *). RenderSym r => MSBody r -> SMethod r
CP.docMain
 
  function :: String
-> CSharpCode (Scope CSharpCode)
-> VSType CSharpCode
-> [MSParameter CSharpCode]
-> MSBody CSharpCode
-> SMethod CSharpCode
function = forall (r :: * -> *).
RenderSym r =>
String
-> r (Scope r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
G.function
  mainFunction :: MSBody CSharpCode -> SMethod CSharpCode
mainFunction = forall (r :: * -> *).
RenderSym r =>
VSType r -> String -> MSBody r -> SMethod r
CP.mainFunction forall (r :: * -> *). TypeSym r => VSType r
string String
csMain

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

  inOutMethod :: String
-> CSharpCode (Scope CSharpCode)
-> CSharpCode (Permanence CSharpCode)
-> InOutFunc CSharpCode
inOutMethod String
n CSharpCode (Scope CSharpCode)
s CSharpCode (Permanence CSharpCode)
p = (VSType CSharpCode
 -> [MSParameter CSharpCode]
 -> MSBody CSharpCode
 -> SMethod CSharpCode)
-> InOutFunc CSharpCode
csInOut (forall (r :: * -> *).
MethodSym r =>
String
-> r (Scope r)
-> r (Permanence r)
-> VSType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
method String
n CSharpCode (Scope CSharpCode)
s CSharpCode (Permanence CSharpCode)
p)

  docInOutMethod :: String
-> CSharpCode (Scope CSharpCode)
-> CSharpCode (Permanence CSharpCode)
-> DocInOutFunc CSharpCode
docInOutMethod String
n CSharpCode (Scope CSharpCode)
s CSharpCode (Permanence CSharpCode)
p = 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
CP.docInOutFunc (forall (r :: * -> *).
MethodSym r =>
String -> r (Scope r) -> r (Permanence r) -> InOutFunc r
inOutMethod String
n CSharpCode (Scope CSharpCode)
s CSharpCode (Permanence CSharpCode)
p)

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

  docInOutFunc :: String -> CSharpCode (Scope CSharpCode) -> DocInOutFunc CSharpCode
docInOutFunc String
n CSharpCode (Scope CSharpCode)
s = 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
CP.docInOutFunc (forall (r :: * -> *).
MethodSym r =>
String -> r (Scope r) -> InOutFunc r
inOutFunc String
n CSharpCode (Scope CSharpCode)
s)

instance RenderMethod CSharpCode where
  intMethod :: Bool
-> String
-> CSharpCode (Scope CSharpCode)
-> CSharpCode (Permanence CSharpCode)
-> MSMthdType CSharpCode
-> [MSParameter CSharpCode]
-> MSBody CSharpCode
-> SMethod CSharpCode
intMethod Bool
m String
n CSharpCode (Scope CSharpCode)
s CSharpCode (Permanence CSharpCode)
p MSMthdType CSharpCode
t [MSParameter CSharpCode]
ps MSBody CSharpCode
b = do
    forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (if Bool
m then MethodState -> MethodState
setCurrMain else forall a. a -> a
id)
    CSharpCode TypeData
tp <- MSMthdType CSharpCode
t
    [CSharpCode ParamData]
pms <- forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [MSParameter CSharpCode]
ps
    forall (r :: * -> *) a. Monad r => a -> r a
toCode forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> MethodData
mthd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *).
RenderSym r =>
String
-> r (Scope r)
-> r (Permanence r)
-> r (Type r)
-> [r (Parameter r)]
-> r (Body r)
-> Doc
R.method String
n CSharpCode (Scope CSharpCode)
s CSharpCode (Permanence CSharpCode)
p CSharpCode TypeData
tp [CSharpCode ParamData]
pms forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
<$> MSBody CSharpCode
b
  intFunc :: Bool
-> String
-> CSharpCode (Scope CSharpCode)
-> CSharpCode (Permanence CSharpCode)
-> MSMthdType CSharpCode
-> [MSParameter CSharpCode]
-> MSBody CSharpCode
-> SMethod CSharpCode
intFunc = forall (r :: * -> *).
RenderSym r =>
Bool
-> String
-> r (Scope r)
-> r (Permanence r)
-> MSMthdType r
-> [MSParameter r]
-> MSBody r
-> SMethod r
C.intFunc
  commentedFunc :: MS (CSharpCode (BlockComment CSharpCode))
-> SMethod CSharpCode -> SMethod CSharpCode
commentedFunc MS (CSharpCode (BlockComment CSharpCode))
cmt SMethod CSharpCode
m = forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues (forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues MethodData -> (Doc -> Doc) -> MethodData
updateMthd) SMethod CSharpCode
m 
    (forall a b s. (a -> b) -> State s a -> State s b
onStateValue (forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue Doc -> Doc -> Doc
R.commentedItem) MS (CSharpCode (BlockComment CSharpCode))
cmt)
    
  destructor :: [CSStateVar CSharpCode] -> SMethod CSharpCode
destructor [CSStateVar CSharpCode]
_ = forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String -> String
CP.destructorError String
csName
  
  mthdFromData :: ScopeTag -> Doc -> SMethod CSharpCode
mthdFromData ScopeTag
_ Doc
d = forall a s. a -> State s a
toState forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *) a. Monad r => a -> r a
toCode forall a b. (a -> b) -> a -> b
$ Doc -> MethodData
mthd Doc
d
  
instance MethodElim CSharpCode where
  method :: CSharpCode (Method CSharpCode) -> Doc
method = MethodData -> Doc
mthdDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. CSharpCode a -> a
unCSC

instance StateVarSym CSharpCode where
  type StateVar CSharpCode = Doc
  stateVar :: CSharpCode (Scope CSharpCode)
-> CSharpCode (Permanence CSharpCode)
-> SVariable CSharpCode
-> CSStateVar CSharpCode
stateVar = forall (r :: * -> *).
(RenderSym r, Monad r) =>
r (Scope r) -> r (Permanence r) -> SVariable r -> CS (r Doc)
CP.stateVar
  stateVarDef :: CSharpCode (Scope CSharpCode)
-> CSharpCode (Permanence CSharpCode)
-> SVariable CSharpCode
-> SValue CSharpCode
-> CSStateVar CSharpCode
stateVarDef = forall (r :: * -> *).
(RenderSym r, Monad r) =>
r (Scope r)
-> r (Permanence r) -> SVariable r -> SValue r -> CS (r Doc)
CP.stateVarDef
  constVar :: CSharpCode (Scope CSharpCode)
-> SVariable CSharpCode
-> SValue CSharpCode
-> CSStateVar CSharpCode
constVar = forall (r :: * -> *).
(RenderSym r, Monad r) =>
Doc -> r (Scope r) -> SVariable r -> SValue r -> CS (r Doc)
CP.constVar Doc
empty
  
instance StateVarElim CSharpCode where
  stateVar :: CSharpCode (StateVar CSharpCode) -> Doc
stateVar = forall a. CSharpCode a -> a
unCSC

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

  docClass :: String -> SClass CSharpCode -> SClass CSharpCode
docClass = forall (r :: * -> *). RenderSym r => String -> SClass r -> SClass r
CP.doxClass

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

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

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

instance ModuleSym CSharpCode where
  type Module CSharpCode = ModData
  buildModule :: String
-> [String]
-> [SMethod CSharpCode]
-> [SClass CSharpCode]
-> FSModule CSharpCode
buildModule String
n = forall (r :: * -> *).
RenderSym r =>
String
-> (String -> r (Import r))
-> [String]
-> [SMethod r]
-> [SClass r]
-> FSModule r
CP.buildModule' String
n forall (r :: * -> *). ImportSym r => String -> r (Import r)
langImport
  
instance RenderMod CSharpCode where
  modFromData :: String -> FS Doc -> FSModule CSharpCode
modFromData String
n = forall (r :: * -> *).
String -> (Doc -> r (Module r)) -> FS Doc -> FSModule r
G.modFromData String
n (forall (r :: * -> *) a. Monad r => a -> r a
toCode forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc -> ModData
md String
n)
  updateModuleDoc :: (Doc -> Doc)
-> CSharpCode (Module CSharpCode) -> CSharpCode (Module CSharpCode)
updateModuleDoc Doc -> Doc
f = forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ((Doc -> Doc) -> ModData -> ModData
updateMod Doc -> Doc
f)
  
instance ModuleElim CSharpCode where
  module' :: CSharpCode (Module CSharpCode) -> Doc
module' = ModData -> Doc
modDoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. CSharpCode a -> a
unCSC

instance BlockCommentSym CSharpCode where
  type BlockComment CSharpCode = Doc
  blockComment :: [String] -> CSharpCode (BlockComment CSharpCode)
blockComment [String]
lns = forall (r :: * -> *) a. Monad r => a -> r a
toCode forall a b. (a -> b) -> a -> b
$ [String] -> Doc -> Doc -> Doc
R.blockCmt [String]
lns Doc
blockCmtStart Doc
blockCmtEnd
  docComment :: forall a.
State a [String] -> State a (CSharpCode (BlockComment CSharpCode))
docComment = forall a b s. (a -> b) -> State s a -> State s b
onStateValue (\[String]
lns -> forall (r :: * -> *) a. Monad r => a -> r a
toCode forall a b. (a -> b) -> a -> b
$ [String] -> Doc -> Doc -> Doc
R.docCmt [String]
lns Doc
docCmtStart 
    Doc
blockCmtEnd)

instance BlockCommentElim CSharpCode where
  blockComment' :: CSharpCode (BlockComment CSharpCode) -> Doc
blockComment' = forall a. CSharpCode a -> a
unCSC

addSystemImport :: VS a -> VS a
addSystemImport :: forall a. VS a -> VS a
addSystemImport = forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
(>>) forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addLangImportVS String
csSystem)

csName, csVersion :: String
csName :: String
csName = String
"C#"
csVersion :: String
csVersion = String
"6.0"

csImport :: Label -> Doc
csImport :: String -> Doc
csImport String
n = String -> Doc
text (String
"using " forall a. [a] -> [a] -> [a]
++ String
n) Doc -> Doc -> Doc
<> Doc
endStatement

csBoolType :: (RenderSym r) => VSType r
csBoolType :: forall (r :: * -> *). RenderSym r => VSType r
csBoolType = forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData CodeType
Boolean String
csBool (String -> Doc
text String
csBool)

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

csListSize, csForEach, csNamedArgSep, csLambdaSep :: Doc
csListSize :: Doc
csListSize = String -> Doc
text String
"Count"
csForEach :: Doc
csForEach = String -> Doc
text String
"foreach"
csNamedArgSep :: Doc
csNamedArgSep = Doc
colon Doc -> Doc -> Doc
<> Doc
space
csLambdaSep :: Doc
csLambdaSep = String -> Doc
text String
"=>"

csSystem, csConsole, csGeneric, csIO, csList, csInt, csFloat, csBool, 
  csChar, csParse, csReader, csWriter, csReadLine, csWrite, csWriteLine, 
  csIndex, csListAdd, csListAppend, csClose, csEOS, csSplit, csMain,
  csFunc :: String
csSystem :: String
csSystem = String
"System"
csConsole :: String
csConsole = String
"Console"
csGeneric :: String
csGeneric = String -> String
csSysAccess forall a b. (a -> b) -> a -> b
$ String
"Collections" String -> String -> String
`access` String
"Generic"
csIO :: String
csIO = String -> String
csSysAccess String
"IO"
csList :: String
csList = String
"List"
csInt :: String
csInt = String
"Int32"
csFloat :: String
csFloat = String
"Single"
csBool :: String
csBool = String
"Boolean"
csChar :: String
csChar = String
"Char"
csParse :: String
csParse = String
"Parse"
csReader :: String
csReader = String
"StreamReader"
csWriter :: String
csWriter = String
"StreamWriter"
csReadLine :: String
csReadLine = String
"ReadLine"
csWrite :: String
csWrite = String
"Write"
csWriteLine :: String
csWriteLine = String
"WriteLine"
csIndex :: String
csIndex = String
"IndexOf"
csListAdd :: String
csListAdd = String
"Insert"
csListAppend :: String
csListAppend = String
"Add"
csClose :: String
csClose = String
"Close"
csEOS :: String
csEOS = String
"EndOfStream"
csSplit :: String
csSplit = String
"Split"
csMain :: String
csMain = String
"Main"
csFunc :: String
csFunc = String
"Func"

csSysAccess :: String -> String
csSysAccess :: String -> String
csSysAccess = String -> String -> String
access String
csSystem

csUnaryMath :: (Monad r) => String -> VSOp r
csUnaryMath :: forall (r :: * -> *). Monad r => String -> VSOp r
csUnaryMath = forall a. VS a -> VS a
addSystemImport forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
mathFunc

csInfileType :: (RenderSym r) => VSType r
csInfileType :: forall (r :: * -> *). RenderSym r => VSType r
csInfileType = forall (m :: * -> *) a. Monad m => m (m a) -> m a
join forall a b. (a -> b) -> a -> b
$ forall s a. (s -> s) -> a -> State s a
modifyReturn (String -> ValueState -> ValueState
addLangImportVS String
csIO) forall a b. (a -> b) -> a -> b
$ 
  forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData CodeType
InFile String
csReader (String -> Doc
text String
csReader)

csOutfileType :: (RenderSym r) => VSType r
csOutfileType :: forall (r :: * -> *). RenderSym r => VSType r
csOutfileType = forall (m :: * -> *) a. Monad m => m (m a) -> m a
join forall a b. (a -> b) -> a -> b
$ forall s a. (s -> s) -> a -> State s a
modifyReturn (String -> ValueState -> ValueState
addLangImportVS String
csIO) forall a b. (a -> b) -> a -> b
$ 
  forall (r :: * -> *).
RenderType r =>
CodeType -> String -> Doc -> VSType r
typeFromData CodeType
OutFile String
csWriter (String -> Doc
text String
csWriter)

csLitList :: (RenderSym r) => (VSType r -> VSType r) -> VSType r -> [SValue r] 
  -> SValue r
csLitList :: forall (r :: * -> *).
RenderSym r =>
(VSType r -> VSType r) -> VSType r -> [SValue r] -> SValue r
csLitList VSType r -> VSType r
f VSType r
t' [SValue r]
es' = do 
  [r (Value r)]
es <- forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [SValue r]
es' 
  r (Type r)
lt <- VSType r -> VSType r
f VSType r
t'
  forall (r :: * -> *). RenderSym r => r (Type r) -> Doc -> SValue r
mkVal r (Type r)
lt (Doc
new' Doc -> Doc -> Doc
<+> forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' r (Type r)
lt
    Doc -> Doc -> Doc
<+> Doc -> Doc
braces (forall (r :: * -> *). RenderSym r => [r (Value r)] -> Doc
valueList [r (Value r)]
es))

csLambda :: (RenderSym r) => [r (Variable r)] -> r (Value r) -> Doc
csLambda :: forall (r :: * -> *).
RenderSym r =>
[r (Variable r)] -> r (Value r) -> Doc
csLambda [r (Variable r)]
ps r (Value r)
ex = Doc -> Doc
parens (forall (r :: * -> *). RenderSym r => [r (Variable r)] -> Doc
variableList [r (Variable r)]
ps) Doc -> Doc -> Doc
<+> Doc
csLambdaSep Doc -> Doc -> Doc
<+> forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
ex

csReadLineFunc :: SValue CSharpCode
csReadLineFunc :: SValue CSharpCode
csReadLineFunc = forall (r :: * -> *). ValueExpression r => String -> PosCall r
extFuncApp String
csConsole String
csReadLine forall (r :: * -> *). TypeSym r => VSType r
string []

csIntParse :: SValue CSharpCode -> SValue CSharpCode
csIntParse :: SValue CSharpCode -> SValue CSharpCode
csIntParse SValue CSharpCode
v = forall (r :: * -> *). ValueExpression r => String -> PosCall r
extFuncApp String
csInt String
csParse forall (r :: * -> *). TypeSym r => VSType r
int [SValue CSharpCode
v] 

csFloatParse :: SValue CSharpCode -> SValue CSharpCode
csFloatParse :: SValue CSharpCode -> SValue CSharpCode
csFloatParse SValue CSharpCode
v = forall (r :: * -> *). ValueExpression r => String -> PosCall r
extFuncApp String
csFloat String
csParse forall (r :: * -> *). TypeSym r => VSType r
float [SValue CSharpCode
v] 

csDblParse :: SValue CSharpCode -> SValue CSharpCode
csDblParse :: SValue CSharpCode -> SValue CSharpCode
csDblParse SValue CSharpCode
v = forall (r :: * -> *). ValueExpression r => String -> PosCall r
extFuncApp String
CP.doubleRender String
csParse forall (r :: * -> *). TypeSym r => VSType r
double [SValue CSharpCode
v] 

csBoolParse :: SValue CSharpCode -> SValue CSharpCode
csBoolParse :: SValue CSharpCode -> SValue CSharpCode
csBoolParse SValue CSharpCode
v = forall (r :: * -> *). ValueExpression r => String -> PosCall r
extFuncApp String
csBool String
csParse forall (r :: * -> *). TypeSym r => VSType r
bool [SValue CSharpCode
v] 

csCharParse :: SValue CSharpCode -> SValue CSharpCode
csCharParse :: SValue CSharpCode -> SValue CSharpCode
csCharParse SValue CSharpCode
v = forall (r :: * -> *). ValueExpression r => String -> PosCall r
extFuncApp String
csChar String
csParse forall (r :: * -> *). TypeSym r => VSType r
char [SValue CSharpCode
v] 

csSplitFunc :: Char -> VSFunction CSharpCode
csSplitFunc :: Char -> VSFunction CSharpCode
csSplitFunc Char
d = forall (r :: * -> *).
FunctionSym r =>
String -> VSType r -> [SValue r] -> VSFunction r
func String
csSplit (forall (r :: * -> *). TypeSym r => VSType r -> VSType r
listType forall (r :: * -> *). TypeSym r => VSType r
string) [forall (r :: * -> *). Literal r => Char -> SValue r
litChar Char
d]

csCast :: VSType CSharpCode -> SValue CSharpCode -> SValue CSharpCode
csCast :: VSType CSharpCode -> SValue CSharpCode -> SValue CSharpCode
csCast = forall (m :: * -> *) a. Monad m => m (m a) -> m a
join forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
.: forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues (\CSharpCode TypeData
t CSharpCode ValData
v -> CodeType
-> CodeType
-> CSharpCode TypeData
-> CSharpCode ValData
-> StateT ValueState Identity (CSharpCode ValData)
csCast' (forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType CSharpCode TypeData
t) (forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType forall a b. (a -> b) -> a -> b
$ 
  forall (r :: * -> *). ValueSym r => r (Value r) -> r (Type r)
valueType CSharpCode ValData
v) CSharpCode TypeData
t CSharpCode ValData
v)
  where csCast' :: CodeType
-> CodeType
-> CSharpCode TypeData
-> CSharpCode ValData
-> SValue CSharpCode
csCast' CodeType
Double CodeType
String CSharpCode TypeData
_ CSharpCode ValData
v = SValue CSharpCode -> SValue CSharpCode
csDblParse (forall a s. a -> State s a
toState CSharpCode ValData
v)
        csCast' CodeType
Float CodeType
String CSharpCode TypeData
_ CSharpCode ValData
v = SValue CSharpCode -> SValue CSharpCode
csFloatParse (forall a s. a -> State s a
toState CSharpCode ValData
v)
        csCast' CodeType
_ CodeType
_ CSharpCode TypeData
t CSharpCode ValData
v = forall (r :: * -> *). RenderSym r => VSType r -> Doc -> SValue r
mkStateVal (forall a s. a -> State s a
toState CSharpCode TypeData
t) (Doc -> Doc -> Doc
R.castObj (Doc -> Doc
R.cast 
          (forall (r :: * -> *). InternalTypeElim r => r (Type r) -> Doc
RC.type' CSharpCode TypeData
t)) (forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value CSharpCode ValData
v))

-- This implementation generates a statement lambda to define the function. 
-- C# 7 supports local functions, which would be a cleaner way to implement
-- this, but the mcs compiler used in our Travis builds does not yet support 
-- all features of C# 7, so we cannot generate local functions.
-- If support for local functions is added to mcs in the future, this
-- should be re-written to generate a local function.
csFuncDecDef :: (RenderSym r) => SVariable r -> [SVariable r] -> MSBody r -> 
  MSStatement r
csFuncDecDef :: forall (r :: * -> *).
RenderSym r =>
SVariable r -> [SVariable r] -> MSBody r -> MSStatement r
csFuncDecDef SVariable r
v [SVariable r]
ps MSBody r
bod = 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
  [r (Variable r)]
pms <- 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]
ps
  r (Type r)
t <- 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 -> VSType r
funcType (forall a b. (a -> b) -> [a] -> [b]
map (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType) [r (Variable r)]
pms) 
    (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *).
VariableElim r =>
r (Variable r) -> r (Type r)
variableType r (Variable r)
vr)
  r (Body r)
b <- MSBody r
bod
  forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> MethodState -> MethodState
addLangImport String
csSystem)
  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)
t Doc -> Doc -> Doc
<+> String -> Doc
text (forall (r :: * -> *). VariableElim r => r (Variable r) -> String
variableName r (Variable r)
vr) Doc -> Doc -> Doc
<+> Doc
equals Doc -> Doc -> Doc
<+>
    Doc -> Doc
parens (forall (r :: * -> *). RenderSym r => [r (Variable r)] -> Doc
variableList [r (Variable r)]
pms) Doc -> Doc -> Doc
<+> Doc
csLambdaSep Doc -> Doc -> Doc
<+> Doc
bodyStart Doc -> Doc -> Doc
$$ 
    Doc -> Doc
indent (forall (r :: * -> *). BodyElim r => r (Body r) -> Doc
RC.body r (Body r)
b) Doc -> Doc -> Doc
$$ Doc
bodyEnd 

csThrowDoc :: (RenderSym r) => r (Value r) -> Doc
csThrowDoc :: forall (r :: * -> *). RenderSym r => r (Value r) -> Doc
csThrowDoc r (Value r)
errMsg = Doc
throwLabel Doc -> Doc -> Doc
<+> Doc
new' Doc -> Doc -> Doc
<+> Doc
exceptionObj' Doc -> Doc -> Doc
<> 
  Doc -> Doc
parens (forall (r :: * -> *). ValueElim r => r (Value r) -> Doc
RC.value r (Value r)
errMsg)

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

csDiscardInput :: SValue CSharpCode -> MSStatement CSharpCode
csDiscardInput :: SValue CSharpCode -> MSStatement CSharpCode
csDiscardInput = forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
valStmt

csFileInput :: (RenderSym r) => SValue r -> SValue r
csFileInput :: forall (r :: * -> *). RenderSym r => SValue r -> SValue r
csFileInput SValue r
f = forall (r :: * -> *).
InternalValueExp r =>
VSType r -> SValue r -> String -> SValue r
objMethodCallNoParams forall (r :: * -> *). TypeSym r => VSType r
string SValue r
f String
csReadLine 

csInput :: VSType CSharpCode -> SValue CSharpCode -> SValue CSharpCode
csInput :: VSType CSharpCode -> SValue CSharpCode -> SValue CSharpCode
csInput VSType CSharpCode
tp SValue CSharpCode
inFn = do
  CSharpCode TypeData
t <- VSType CSharpCode
tp
  forall {a}. CodeType -> VS a -> VS a
csInputImport (forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType CSharpCode TypeData
t) (CodeType
-> StateT ValueState Identity (CSharpCode ValData)
-> StateT ValueState Identity (CSharpCode ValData)
csInput' (forall (r :: * -> *). TypeElim r => r (Type r) -> CodeType
getType CSharpCode TypeData
t) SValue CSharpCode
inFn)
  where csInput' :: CodeType -> SValue CSharpCode -> SValue CSharpCode
csInput' CodeType
Integer = SValue CSharpCode -> SValue CSharpCode
csIntParse
        csInput' CodeType
Float = SValue CSharpCode -> SValue CSharpCode
csFloatParse
        csInput' CodeType
Double = SValue CSharpCode -> SValue CSharpCode
csDblParse
        csInput' CodeType
Boolean = SValue CSharpCode -> SValue CSharpCode
csBoolParse
        csInput' CodeType
String = forall a. a -> a
id
        csInput' CodeType
Char = SValue CSharpCode -> SValue CSharpCode
csCharParse
        csInput' CodeType
_ = forall a. HasCallStack => String -> a
error String
"Attempt to read value of unreadable type"
        csInputImport :: CodeType -> VS a -> VS a
csInputImport CodeType
t = if CodeType
t forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [CodeType
Integer, CodeType
Float, CodeType
Double, CodeType
Boolean, CodeType
Char] 
          then forall a. VS a -> VS a
addSystemImport else forall a. a -> a
id

csOpenFileR :: (RenderSym r) => SValue r -> VSType r -> SValue r
csOpenFileR :: forall (r :: * -> *).
RenderSym r =>
SValue r -> VSType r -> SValue r
csOpenFileR SValue r
n VSType r
r = forall (r :: * -> *). ValueExpression r => PosCtorCall r
newObj VSType r
r [SValue r
n]

csOpenFileWorA :: (RenderSym r) => SValue r -> VSType r -> SValue r -> SValue r
csOpenFileWorA :: forall (r :: * -> *).
RenderSym r =>
SValue r -> VSType r -> SValue r -> SValue r
csOpenFileWorA SValue r
n VSType r
w SValue r
a = forall (r :: * -> *). ValueExpression r => PosCtorCall r
newObj VSType r
w [SValue r
n, SValue r
a] 

csRef :: Doc -> Doc
csRef :: Doc -> Doc
csRef Doc
p = String -> Doc
text String
"ref" Doc -> Doc -> Doc
<+> Doc
p

csOut :: Doc -> Doc
csOut :: Doc -> Doc
csOut Doc
p = String -> Doc
text String
"out" Doc -> Doc -> Doc
<+> Doc
p

csInOutCall :: (Label -> VSType CSharpCode -> [SValue CSharpCode] -> 
  SValue CSharpCode) -> Label -> [SValue CSharpCode] -> [SVariable CSharpCode] 
  -> [SVariable CSharpCode] -> MSStatement CSharpCode
csInOutCall :: (String
 -> VSType CSharpCode -> [SValue CSharpCode] -> SValue CSharpCode)
-> InOutCall CSharpCode
csInOutCall String
-> VSType CSharpCode -> [SValue CSharpCode] -> SValue CSharpCode
f String
n [SValue CSharpCode]
ins [SVariable CSharpCode
out] [] = forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
assign SVariable CSharpCode
out forall a b. (a -> b) -> a -> b
$ String
-> VSType CSharpCode -> [SValue CSharpCode] -> SValue CSharpCode
f String
n (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 CSharpCode
out) 
  [SValue CSharpCode]
ins
csInOutCall String
-> VSType CSharpCode -> [SValue CSharpCode] -> SValue CSharpCode
f String
n [SValue CSharpCode]
ins [] [SVariable CSharpCode
out] = forall (r :: * -> *).
AssignStatement r =>
SVariable r -> SValue r -> MSStatement r
assign SVariable CSharpCode
out forall a b. (a -> b) -> a -> b
$ String
-> VSType CSharpCode -> [SValue CSharpCode] -> SValue CSharpCode
f String
n (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 CSharpCode
out) 
  (forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable CSharpCode
out forall a. a -> [a] -> [a]
: [SValue CSharpCode]
ins)
csInOutCall String
-> VSType CSharpCode -> [SValue CSharpCode] -> SValue CSharpCode
f String
n [SValue CSharpCode]
ins [SVariable CSharpCode]
outs [SVariable CSharpCode]
both = forall (r :: * -> *). StatementSym r => SValue r -> MSStatement r
valStmt forall a b. (a -> b) -> a -> b
$ String
-> VSType CSharpCode -> [SValue CSharpCode] -> SValue CSharpCode
f String
n forall (r :: * -> *). TypeSym r => VSType r
void (forall a b. (a -> b) -> [a] -> [b]
map (forall a b s. (a -> b) -> State s a -> State s b
onStateValue 
  (forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ((Doc -> Doc) -> ValData -> ValData
updateValDoc Doc -> Doc
csRef)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf) [SVariable CSharpCode]
both forall a. [a] -> [a] -> [a]
++ [SValue CSharpCode]
ins forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map 
  (forall a b s. (a -> b) -> State s a -> State s b
onStateValue (forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ((Doc -> Doc) -> ValData -> ValData
updateValDoc Doc -> Doc
csOut)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf) [SVariable CSharpCode]
outs)

csVarDec :: Binding -> MSStatement CSharpCode -> MSStatement CSharpCode
csVarDec :: Binding -> MSStatement CSharpCode -> MSStatement CSharpCode
csVarDec Binding
Static MSStatement CSharpCode
_ = forall a. HasCallStack => String -> a
error String
"Static variables can't be declared locally to a function in C#. Use stateVar to make a static state variable instead."
csVarDec Binding
Dynamic MSStatement CSharpCode
d = MSStatement CSharpCode
d

csInOut :: (VSType CSharpCode -> [MSParameter CSharpCode] -> MSBody CSharpCode -> 
    SMethod CSharpCode) -> 
  [SVariable CSharpCode] -> [SVariable CSharpCode] -> [SVariable CSharpCode] -> 
  MSBody CSharpCode -> SMethod CSharpCode
csInOut :: (VSType CSharpCode
 -> [MSParameter CSharpCode]
 -> MSBody CSharpCode
 -> SMethod CSharpCode)
-> InOutFunc CSharpCode
csInOut VSType CSharpCode
-> [MSParameter CSharpCode]
-> MSBody CSharpCode
-> SMethod CSharpCode
f [SVariable CSharpCode]
ins [SVariable CSharpCode
v] [] MSBody CSharpCode
b = VSType CSharpCode
-> [MSParameter CSharpCode]
-> MSBody CSharpCode
-> SMethod CSharpCode
f (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 CSharpCode
v) (forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
param [SVariable CSharpCode]
ins)
  (forall a b c d s.
(a -> b -> c -> d)
-> State s a -> State s b -> State s c -> State s d
on3StateValues (forall (r :: * -> *) a b c d.
Applicative r =>
(a -> b -> c -> d) -> r a -> r b -> r c -> r d
on3CodeValues (Doc, Terminator) -> Doc -> (Doc, Terminator) -> Doc
surroundBody) (forall (r :: * -> *).
DeclStatement r =>
SVariable r -> MSStatement r
varDec SVariable CSharpCode
v) MSBody CSharpCode
b (forall (r :: * -> *).
ControlStatement r =>
SValue r -> MSStatement r
returnStmt forall a b. (a -> b) -> a -> b
$ 
  forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable CSharpCode
v))
csInOut VSType CSharpCode
-> [MSParameter CSharpCode]
-> MSBody CSharpCode
-> SMethod CSharpCode
f [SVariable CSharpCode]
ins [] [SVariable CSharpCode
v] MSBody CSharpCode
b = VSType CSharpCode
-> [MSParameter CSharpCode]
-> MSBody CSharpCode
-> SMethod CSharpCode
f (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 CSharpCode
v) 
  (forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
param forall a b. (a -> b) -> a -> b
$ SVariable CSharpCode
v forall a. a -> [a] -> [a]
: [SVariable CSharpCode]
ins) (forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues (forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues Doc -> (Doc, Terminator) -> Doc
appendToBody) MSBody CSharpCode
b 
  (forall (r :: * -> *).
ControlStatement r =>
SValue r -> MSStatement r
returnStmt forall a b. (a -> b) -> a -> b
$ forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
valueOf SVariable CSharpCode
v))
csInOut VSType CSharpCode
-> [MSParameter CSharpCode]
-> MSBody CSharpCode
-> SMethod CSharpCode
f [SVariable CSharpCode]
ins [SVariable CSharpCode]
outs [SVariable CSharpCode]
both MSBody CSharpCode
b = VSType CSharpCode
-> [MSParameter CSharpCode]
-> MSBody CSharpCode
-> SMethod CSharpCode
f forall (r :: * -> *). TypeSym r => VSType r
void (forall a b. (a -> b) -> [a] -> [b]
map (forall a b s. (a -> b) -> State s a -> State s b
onStateValue (forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue 
  ((Doc -> Doc) -> ParamData -> ParamData
updateParam Doc -> Doc
csRef)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
param) [SVariable CSharpCode]
both forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
param [SVariable CSharpCode]
ins forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map (forall a b s. (a -> b) -> State s a -> State s b
onStateValue 
  (forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ((Doc -> Doc) -> ParamData -> ParamData
updateParam Doc -> Doc
csOut)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MSParameter r
param) [SVariable CSharpCode]
outs) MSBody CSharpCode
b