{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleContexts #-}
module Drasil.GOOL.LanguageRenderer.PythonRenderer (
PythonCode(..), pyName, pyVersion
) where
import Drasil.FileHandling.Legacy (blank, indent)
import Drasil.Shared.CodeType (CodeType(..))
import Drasil.Shared.InterfaceCommon (UnRepr(..), SharedProg, SharedStatement,
Label, Library, Body, Variable, SVariable, Value, SValue, MixedCtorCall,
BodySym(..), BlockSym(..), TypeSym(..), TypeElim(..), getTypeString,
VariableSym(..), VisibilitySym(..), VariableElim(..), ValueSym(..),
Argument(..), Literal(..), MathConstant(..), VariableValue(..),
CommandLineArgs(..), NumericExpression(..), BooleanExpression(..),
Comparison(..), ValueExpression(..), funcApp, extFuncApp, IndexTranslator(..),
Reference(..), Array(..), List(..), Set(..), InternalList(..),
StatementSym(..), AssignStatement(..), (&=), DeclStatement(..),
IOStatement(..), StringStatement(..), FunctionSym, FuncAppStatement(..),
CommentStatement(..), ControlStatement(..), switchAsIf, ScopeSym(..),
ParameterSym(..), BinderSym(..), BinderElim(..), MethodSym(..))
import Drasil.GOOL.InterfaceGOOL (OOProg, StateVar, OOStatement, ProgramSym(..),
FileSym(..), ModuleSym(..), ClassSym(..), OOTypeSym(..), OOVariableSym(..),
SelfSym(..), StateVarSym(..), AttachmentSym(..), OOValueSym, OOVariableValue,
InternalValueExp(..), extNewObj, objMethodCall, OOFunctionSym(..), GetSet(..),
OOValueExpression(..), selfMethodCall, OODeclStatement(..),
OOFuncAppStatement(..), ObserverPattern(..), StrategyPattern(..),
OOMethodSym(..))
import Drasil.Shared.RendererClassesCommon (CommonRenderSym, ImportSym(..),
RenderBody(..), BodyElim, RenderBlock(..), BlockElim, RenderType(..),
UnaryOpSym(..), BinaryOpSym(..), OpElim(uOpPrec, bOpPrec), RenderVariable(..),
InternalVarElim(variableBind), RenderValue(..), ValueElim(valuePrec, valueInt),
InternalListFunc(..), RenderFunction(..), FunctionElim(functionType),
InternalAssignStmt(..), InternalIOStmt(..), InternalControlStmt(..),
RenderStatement(..), StatementElim(statementTerm), RenderVisibility(..),
VisibilityElim, MethodTypeSym(..), RenderParam(..),
ParamElim(parameterName, parameterType), RenderMethod(..), MethodElim,
BlockCommentSym(..), BlockCommentElim, ScopeElim(..), InternalBinderElim(..))
import qualified Drasil.Shared.RendererClassesCommon as RC (import', body, block,
uOp, bOp, variable, value, function, statement, visibility, parameter, method,
blockComment')
import Drasil.GOOL.RendererClassesOO (OORenderSym, RenderFile(..),
PermElim(binding), InternalGetSet(..), OOMethodTypeSym(..),
OORenderMethod(..), StateVarElim, RenderClass(..), ClassElim, RenderMod(..),
ModuleElim)
import qualified Drasil.GOOL.RendererClassesOO as RC (perm, stateVar, class',
module')
import Drasil.Shared.LanguageRenderer (classDec, dot, ifLabel, elseLabel,
forLabel, inLabel, whileLabel, tryLabel, importLabel, exceptionObj', listSep',
argv, printLabel, listSep, piLabel, access, functionDox, binderList,
parameterList)
import qualified Drasil.Shared.LanguageRenderer as R (sqrt, fabs, log10,
log, exp, sin, cos, tan, asin, acos, atan, floor, ceil, multiStmt, body,
classVarAccess, castObj, instanceLevel, break, continue, addComments,
commentedMod, commentedItem, var)
import Drasil.GOOL.Renderers (renderType)
import Drasil.Shared.LanguageRenderer.Constructors (mkStmtNoEnd, mkStateVal,
mkVal, mkStateVar, typeFromData, VSOp, unOpPrec, powerPrec, multPrec, andPrec,
orPrec, inPrec, unExpr, unExpr', typeUnExpr, binExpr, typeBinExpr, mkClassVar,
typeFromData)
import qualified Drasil.Shared.LanguageRenderer.LanguagePolymorphic as G (
multiBody, block, multiBlock, obj, negateOp, csc, sec, cot, equalOp,
notEqualOp, greaterOp, greaterEqualOp, lessOp, lessEqualOp, plusOp, minusOp,
multOp, divideOp, moduloOp, var, classVar, instanceVarAccess, arrayElem,
litChar, litDouble, litInt, litString, valueOf, arg, argsList, objAccess,
objMethodCall, call, funcAppMixedArgs, newObjMixedArgs, lambda, func, get, set,
listAccess, getFunc, setFunc, stmt, loopStmt, emptyStmt, assign,
subAssign, objDecNew, print, closeFile, returnStmt, valStmt, comment, throw,
ifCond, tryCatch, construct, param, method, getMethod, setMethod, function,
buildClass, implementingClass, commentedClass, modFromData, fileDoc,
fileFromData, local)
import qualified Drasil.Shared.LanguageRenderer.CommonPseudoOO as CP
import qualified Drasil.Shared.LanguageRenderer.Macros as M (ifExists,
decrement1, increment1, runStrategy, stringListVals, stringListLists,
notifyObservers', arrayDecAsList)
import qualified Drasil.GOOL.LanguageRenderer.CommonGOOL as CG (classMethodCall,
listAppend, listAdd, innerType)
import Drasil.Shared.AST (Terminator(..), FileType(..), fileD, FuncData(..), fd,
ModData(..), md, updateMod, MethodData(..), mthd, updateMthd, OpData(..),
ParamData(..), pd, ProgData(..), progD, TypeData(..), ValData(..), vd,
VarData(..), vard, BinderD(..), bindFormD, AttachmentTag(..),
AttachmentData(..), ad)
import Drasil.Shared.Helpers (vibcat, emptyIfEmpty, toCode, toState, onCodeValue,
onStateValue, on2CodeValues, on2StateValues, onCodeList, onStateList,
on2StateWrapped)
import Drasil.Shared.State (MS, VS, lensGStoFS, lensMStoVS, lensVStoMS, revFiles,
addLangImportVS, getLangImports, addLibImportVS, getLibImports, addModuleImport,
addModuleImportVS, getModuleImports, setFileType, getClassName, setCurrMain,
getClassMap, getMainDoc, varNameAvailable)
import Prelude hiding (break,print,sin,cos,tan,floor,(<>))
import Data.Maybe (fromMaybe)
import Control.Lens.Zoom (zoom)
import Control.Monad (join)
import Control.Monad.State (modify)
import Data.List (intercalate, sort)
import Data.Char (toUpper, isUpper, isLower)
import qualified Data.Map as Map (lookup)
import Text.PrettyPrint.HughesPJ (Doc, text, (<>), (<+>), parens, empty, equals,
vcat, colon, brackets, isEmpty, quotes, comma, braces)
import Drasil.Shared.LanguageRenderer.LanguagePolymorphic (OptionalSpace(..))
import qualified Drasil.Shared.LanguageRenderer.Common as CS
pyExt :: String
pyExt :: String
pyExt = String
"py"
newtype PythonCode a = PC {forall a. PythonCode a -> a
unPC :: a}
instance Functor PythonCode where
fmap :: forall a b. (a -> b) -> PythonCode a -> PythonCode b
fmap a -> b
f (PC a
x) = b -> PythonCode b
forall a. a -> PythonCode a
PC (a -> b
f a
x)
instance Applicative PythonCode where
pure :: forall a. a -> PythonCode a
pure = a -> PythonCode a
forall a. a -> PythonCode a
PC
(PC a -> b
f) <*> :: forall a b. PythonCode (a -> b) -> PythonCode a -> PythonCode b
<*> (PC a
x) = b -> PythonCode b
forall a. a -> PythonCode a
PC (a -> b
f a
x)
instance Monad PythonCode where
PC a
x >>= :: forall a b. PythonCode a -> (a -> PythonCode b) -> PythonCode b
>>= a -> PythonCode b
f = a -> PythonCode b
f a
x
instance SharedProg PythonCode Doc (Doc, Terminator) MethodData
instance SharedStatement PythonCode (Doc, Terminator)
instance OOStatement PythonCode (Doc, Terminator)
instance OOProg PythonCode Doc (Doc, Terminator) MethodData StateVar AttachmentData ProgData
instance ProgramSym PythonCode Doc (Doc, Terminator) MethodData StateVar AttachmentData ProgData where
prog :: String
-> String
-> [FS (PythonCode File)]
-> GSProgram PythonCode ProgData
prog String
n String
st [FS (PythonCode File)]
files = do
[PythonCode File]
fs <- (FS (PythonCode File)
-> StateT GOOLState Identity (PythonCode File))
-> [FS (PythonCode File)]
-> StateT GOOLState Identity [PythonCode File]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (LensLike'
(Zoomed (StateT FileState Identity) (PythonCode File))
GOOLState
FileState
-> FS (PythonCode File)
-> StateT GOOLState Identity (PythonCode File)
forall c.
LensLike'
(Zoomed (StateT FileState Identity) c) GOOLState FileState
-> StateT FileState Identity c -> StateT GOOLState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT FileState Identity) (PythonCode File))
GOOLState
FileState
(FileState -> Focusing Identity (PythonCode File) FileState)
-> GOOLState -> Focusing Identity (PythonCode File) GOOLState
Lens' GOOLState FileState
lensGStoFS) [FS (PythonCode File)]
files
(GOOLState -> GOOLState) -> StateT GOOLState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify GOOLState -> GOOLState
revFiles
PythonCode ProgData -> GSProgram PythonCode ProgData
forall a. a -> StateT GOOLState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PythonCode ProgData -> GSProgram PythonCode ProgData)
-> PythonCode ProgData -> GSProgram PythonCode ProgData
forall a b. (a -> b) -> a -> b
$ ([File] -> ProgData) -> [PythonCode File] -> PythonCode ProgData
forall (m :: * -> *) a b. Monad m => ([a] -> b) -> [m a] -> m b
onCodeList (String -> String -> [File] -> ProgData
progD String
n String
st) [PythonCode File]
fs
instance CommonRenderSym PythonCode Doc (Doc, Terminator) MethodData
instance OORenderSym PythonCode Doc (Doc, Terminator) MethodData StateVar AttachmentData
instance UnRepr PythonCode contents where
unRepr :: PythonCode contents -> contents
unRepr = PythonCode contents -> contents
forall a. PythonCode a -> a
unPC
instance FileSym PythonCode Doc (Doc, Terminator) MethodData StateVar AttachmentData where
fileDoc :: FS (PythonCode Module) -> FS (PythonCode File)
fileDoc FS (PythonCode Module)
m = do
(FileState -> FileState) -> StateT FileState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (FileType -> FileState -> FileState
setFileType FileType
Combined)
String
-> (PythonCode Module -> PythonCode Doc)
-> PythonCode Doc
-> FS (PythonCode Module)
-> FS (PythonCode File)
forall (r :: * -> *).
(BlockElim r, RenderMod r, RenderFile r) =>
String
-> (r Module -> r Doc) -> r Doc -> FS (r Module) -> FS (r File)
G.fileDoc String
pyExt PythonCode Module -> PythonCode Doc
forall (r :: * -> *). RenderFile r => r Module -> r Doc
top PythonCode Doc
forall (r :: * -> *). RenderFile r => r Doc
bottom FS (PythonCode Module)
m
docMod :: String
-> String
-> [String]
-> String
-> FS (PythonCode File)
-> FS (PythonCode File)
docMod = String
-> String
-> String
-> [String]
-> String
-> FS (PythonCode File)
-> FS (PythonCode File)
forall (r :: * -> *).
RenderFile r =>
String
-> String
-> String
-> [String]
-> String
-> FS (r File)
-> FS (r File)
CP.doxMod String
pyExt
instance RenderFile PythonCode where
top :: PythonCode Module -> PythonCode Doc
top PythonCode Module
_ = Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
empty
bottom :: PythonCode Doc
bottom = Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
empty
commentedMod :: FS (PythonCode File) -> FS (PythonCode Doc) -> FS (PythonCode File)
commentedMod = (PythonCode File -> PythonCode Doc -> PythonCode File)
-> FS (PythonCode File)
-> FS (PythonCode Doc)
-> FS (PythonCode File)
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues ((File -> Doc -> File)
-> PythonCode File -> PythonCode Doc -> PythonCode File
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues File -> Doc -> File
R.commentedMod)
fileFromData :: String -> FS (PythonCode Module) -> FS (PythonCode File)
fileFromData = (String -> PythonCode Module -> PythonCode File)
-> String -> FS (PythonCode Module) -> FS (PythonCode File)
forall (r :: * -> *).
ModuleElim r =>
(String -> r Module -> r File)
-> String -> FS (r Module) -> FS (r File)
G.fileFromData ((Module -> File) -> PythonCode Module -> PythonCode File
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ((Module -> File) -> PythonCode Module -> PythonCode File)
-> (String -> Module -> File)
-> String
-> PythonCode Module
-> PythonCode File
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Module -> File
fileD)
instance ImportSym PythonCode where
langImport :: String -> PythonCode Doc
langImport String
n = Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> PythonCode Doc) -> Doc -> PythonCode Doc
forall a b. (a -> b) -> a -> b
$ Doc
importLabel Doc -> Doc -> Doc
<+> String -> Doc
text String
n
modImport :: String -> PythonCode Doc
modImport = String -> PythonCode Doc
forall (r :: * -> *). ImportSym r => String -> r Doc
langImport
instance AttachmentSym PythonCode AttachmentData where
classLevel :: PythonCode AttachmentData
classLevel = AttachmentData -> PythonCode AttachmentData
forall (r :: * -> *) a. Monad r => a -> r a
toCode (AttachmentData -> PythonCode AttachmentData)
-> AttachmentData -> PythonCode AttachmentData
forall a b. (a -> b) -> a -> b
$ AttachmentTag -> Doc -> AttachmentData
ad AttachmentTag
ClassLevel Doc
empty
instanceLevel :: PythonCode AttachmentData
instanceLevel = AttachmentData -> PythonCode AttachmentData
forall (r :: * -> *) a. Monad r => a -> r a
toCode (AttachmentData -> PythonCode AttachmentData)
-> AttachmentData -> PythonCode AttachmentData
forall a b. (a -> b) -> a -> b
$ AttachmentTag -> Doc -> AttachmentData
ad AttachmentTag
InstanceLevel Doc
R.instanceLevel
instance PermElim PythonCode AttachmentData where
perm :: PythonCode AttachmentData -> Doc
perm = AttachmentData -> Doc
attachmentDoc (AttachmentData -> Doc)
-> (PythonCode AttachmentData -> AttachmentData)
-> PythonCode AttachmentData
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode AttachmentData -> AttachmentData
forall a. PythonCode a -> a
unPC
binding :: PythonCode AttachmentData -> AttachmentTag
binding = AttachmentData -> AttachmentTag
attachment (AttachmentData -> AttachmentTag)
-> (PythonCode AttachmentData -> AttachmentData)
-> PythonCode AttachmentData
-> AttachmentTag
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode AttachmentData -> AttachmentData
forall a. PythonCode a -> a
unPC
instance BodySym PythonCode (Doc, Terminator) where
body :: [MS (PythonCode Doc)] -> MS (PythonCode Doc)
body = ([PythonCode Doc] -> PythonCode Doc)
-> [MS (PythonCode Doc)] -> MS (PythonCode Doc)
forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList (([Doc] -> Doc) -> [PythonCode Doc] -> PythonCode Doc
forall (m :: * -> *) a b. Monad m => ([a] -> b) -> [m a] -> m b
onCodeList [Doc] -> Doc
R.body)
addComments :: String -> MS (PythonCode Doc) -> MS (PythonCode Doc)
addComments String
s = (PythonCode Doc -> PythonCode Doc)
-> MS (PythonCode Doc) -> MS (PythonCode Doc)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue ((Doc -> Doc) -> PythonCode Doc -> PythonCode Doc
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue (String -> Doc -> Doc -> Doc
R.addComments String
s Doc
pyCommentStart))
instance RenderBody PythonCode where
multiBody :: [MS (PythonCode Doc)] -> MS (PythonCode Doc)
multiBody = [MS (PythonCode Doc)] -> MS (PythonCode Doc)
forall (r :: * -> *).
(BodyElim r, Monad r) =>
[MS (r Doc)] -> MS (r Doc)
G.multiBody
instance BodyElim PythonCode where
body :: PythonCode Doc -> Doc
body = PythonCode Doc -> Doc
forall a. PythonCode a -> a
unPC
instance BlockSym PythonCode (Doc, Terminator) where
block :: [MS (PythonCode (Doc, Terminator))] -> MS (PythonCode Doc)
block = [MS (PythonCode (Doc, Terminator))] -> MS (PythonCode Doc)
forall (r :: * -> *) smt.
(Monad r, RenderStatement r smt, StatementElim r smt) =>
[MS (r smt)] -> MS (r Doc)
G.block
instance RenderBlock PythonCode where
multiBlock :: [MS (PythonCode Doc)] -> MS (PythonCode Doc)
multiBlock = [MS (PythonCode Doc)] -> MS (PythonCode Doc)
forall (r :: * -> *).
(BlockElim r, Monad r) =>
[MS (r Doc)] -> MS (r Doc)
G.multiBlock
instance BlockElim PythonCode where
block :: PythonCode Doc -> Doc
block = PythonCode Doc -> Doc
forall a. PythonCode a -> a
unPC
instance TypeSym PythonCode where
bool :: VS (PythonCode TypeData)
bool = CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
Boolean String
"" Doc
empty
int :: VS (PythonCode TypeData)
int = VS (PythonCode TypeData)
forall (r :: * -> *). Monad r => VS (r TypeData)
CP.int
float :: VS (PythonCode TypeData)
float = String -> VS (PythonCode TypeData)
forall a. HasCallStack => String -> a
error String
pyFloatError
double :: VS (PythonCode TypeData)
double = CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
Double String
pyDouble (String -> Doc
text String
pyDouble)
char :: VS (PythonCode TypeData)
char = CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
Char String
"" Doc
empty
string :: VS (PythonCode TypeData)
string = VS (PythonCode TypeData)
forall (r :: * -> *). Monad r => VS (r TypeData)
pyStringType
infile :: VS (PythonCode TypeData)
infile = CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
InFile String
"" Doc
empty
outfile :: VS (PythonCode TypeData)
outfile = CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
OutFile String
"" Doc
empty
referenceType :: VS (PythonCode TypeData) -> VS (PythonCode TypeData)
referenceType = VS (PythonCode TypeData) -> VS (PythonCode TypeData)
forall a. a -> a
id
listType :: VS (PythonCode TypeData) -> VS (PythonCode TypeData)
listType VS (PythonCode TypeData)
t' = VS (PythonCode TypeData)
t' VS (PythonCode TypeData)
-> (PythonCode TypeData -> VS (PythonCode TypeData))
-> VS (PythonCode TypeData)
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=(\PythonCode TypeData
t -> CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData (CodeType -> CodeType
List (PythonCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType PythonCode TypeData
t)) String
"" Doc
empty)
setType :: VS (PythonCode TypeData) -> VS (PythonCode TypeData)
setType VS (PythonCode TypeData)
t' = VS (PythonCode TypeData)
t' VS (PythonCode TypeData)
-> (PythonCode TypeData -> VS (PythonCode TypeData))
-> VS (PythonCode TypeData)
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=(\PythonCode TypeData
t -> CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData (CodeType -> CodeType
Set (PythonCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType PythonCode TypeData
t)) String
"" Doc
empty)
arrayType :: VS (PythonCode TypeData) -> VS (PythonCode TypeData)
arrayType = VS (PythonCode TypeData) -> VS (PythonCode TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType
innerType :: VS (PythonCode TypeData) -> VS (PythonCode TypeData)
innerType = VS (PythonCode TypeData) -> VS (PythonCode TypeData)
forall (r :: * -> *).
(TypeElim r, OOTypeSym r) =>
VS (r TypeData) -> VS (r TypeData)
CG.innerType
funcType :: [VS (PythonCode TypeData)]
-> VS (PythonCode TypeData) -> VS (PythonCode TypeData)
funcType = [VS (PythonCode TypeData)]
-> VS (PythonCode TypeData) -> VS (PythonCode TypeData)
forall (r :: * -> *).
(Monad r, TypeElim r) =>
[VS (r TypeData)] -> VS (r TypeData) -> VS (r TypeData)
CS.funcType
void :: VS (PythonCode TypeData)
void = CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
Void String
pyVoid (String -> Doc
text String
pyVoid)
instance TypeElim PythonCode where
getCodeType :: PythonCode TypeData -> CodeType
getCodeType = TypeData -> CodeType
cType (TypeData -> CodeType)
-> (PythonCode TypeData -> TypeData)
-> PythonCode TypeData
-> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode TypeData -> TypeData
forall a. PythonCode a -> a
unPC
instance OOTypeSym PythonCode where
obj :: String -> VS (PythonCode TypeData)
obj = String -> VS (PythonCode TypeData)
forall (r :: * -> *). Monad r => String -> VS (r TypeData)
G.obj
instance RenderType PythonCode where
multiType :: [VS (PythonCode TypeData)] -> VS (PythonCode TypeData)
multiType [VS (PythonCode TypeData)]
_ = CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
Void String
"" Doc
empty
instance UnaryOpSym PythonCode where
notOp :: VSUnOp PythonCode
notOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyNotOp
negateOp :: VSUnOp PythonCode
negateOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.negateOp
sqrtOp :: VSUnOp PythonCode
sqrtOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pySqrtOp
absOp :: VSUnOp PythonCode
absOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyAbsOp
logOp :: VSUnOp PythonCode
logOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyLogOp
lnOp :: VSUnOp PythonCode
lnOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyLnOp
expOp :: VSUnOp PythonCode
expOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyExpOp
sinOp :: VSUnOp PythonCode
sinOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pySinOp
cosOp :: VSUnOp PythonCode
cosOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyCosOp
tanOp :: VSUnOp PythonCode
tanOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyTanOp
asinOp :: VSUnOp PythonCode
asinOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyAsinOp
acosOp :: VSUnOp PythonCode
acosOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyAcosOp
atanOp :: VSUnOp PythonCode
atanOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyAtanOp
floorOp :: VSUnOp PythonCode
floorOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyFloorOp
ceilOp :: VSUnOp PythonCode
ceilOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyCeilOp
instance BinaryOpSym PythonCode where
equalOp :: VSUnOp PythonCode
equalOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.equalOp
notEqualOp :: VSUnOp PythonCode
notEqualOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.notEqualOp
greaterOp :: VSUnOp PythonCode
greaterOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.greaterOp
greaterEqualOp :: VSUnOp PythonCode
greaterEqualOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.greaterEqualOp
lessOp :: VSUnOp PythonCode
lessOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.lessOp
lessEqualOp :: VSUnOp PythonCode
lessEqualOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.lessEqualOp
plusOp :: VSUnOp PythonCode
plusOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.plusOp
minusOp :: VSUnOp PythonCode
minusOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.minusOp
multOp :: VSUnOp PythonCode
multOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.multOp
divideOp :: VSUnOp PythonCode
divideOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.divideOp
powerOp :: VSUnOp PythonCode
powerOp = String -> VSUnOp PythonCode
forall (r :: * -> *). Monad r => String -> VSOp r
powerPrec String
pyPower
moduloOp :: VSUnOp PythonCode
moduloOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.moduloOp
andOp :: VSUnOp PythonCode
andOp = String -> VSUnOp PythonCode
forall (r :: * -> *). Monad r => String -> VSOp r
andPrec String
pyAnd
orOp :: VSUnOp PythonCode
orOp = String -> VSUnOp PythonCode
forall (r :: * -> *). Monad r => String -> VSOp r
orPrec String
pyOr
instance OpElim PythonCode where
uOp :: PythonCode OpData -> Doc
uOp = OpData -> Doc
opDoc (OpData -> Doc)
-> (PythonCode OpData -> OpData) -> PythonCode OpData -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode OpData -> OpData
forall a. PythonCode a -> a
unPC
bOp :: PythonCode OpData -> Doc
bOp = OpData -> Doc
opDoc (OpData -> Doc)
-> (PythonCode OpData -> OpData) -> PythonCode OpData -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode OpData -> OpData
forall a. PythonCode a -> a
unPC
uOpPrec :: PythonCode OpData -> Int
uOpPrec = OpData -> Int
opPrec (OpData -> Int)
-> (PythonCode OpData -> OpData) -> PythonCode OpData -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode OpData -> OpData
forall a. PythonCode a -> a
unPC
bOpPrec :: PythonCode OpData -> Int
bOpPrec = OpData -> Int
opPrec (OpData -> Int)
-> (PythonCode OpData -> OpData) -> PythonCode OpData -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode OpData -> OpData
forall a. PythonCode a -> a
unPC
instance ScopeSym PythonCode where
global :: PythonCode ScopeData
global = PythonCode ScopeData
forall (r :: * -> *). Monad r => r ScopeData
CP.global
mainFn :: PythonCode ScopeData
mainFn = PythonCode ScopeData
forall (r :: * -> *). ScopeSym r => r ScopeData
global
local :: PythonCode ScopeData
local = PythonCode ScopeData
forall (r :: * -> *). Monad r => r ScopeData
G.local
instance ScopeElim PythonCode where
scopeData :: PythonCode ScopeData -> ScopeData
scopeData = PythonCode ScopeData -> ScopeData
forall a. PythonCode a -> a
unPC
instance VariableSym PythonCode where
var :: String -> VS (PythonCode TypeData) -> SVariable PythonCode
var = String -> VS (PythonCode TypeData) -> SVariable PythonCode
forall (r :: * -> *).
RenderVariable r =>
String -> VS (r TypeData) -> SVariable r
G.var
constant :: String -> VS (PythonCode TypeData) -> SVariable PythonCode
constant String
n = String -> VS (PythonCode TypeData) -> SVariable PythonCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var (String -> VS (PythonCode TypeData) -> SVariable PythonCode)
-> String -> VS (PythonCode TypeData) -> SVariable PythonCode
forall a b. (a -> b) -> a -> b
$ String -> String
toConstName String
n
extVar :: String
-> String -> VS (PythonCode TypeData) -> SVariable PythonCode
extVar String
l String
n VS (PythonCode TypeData)
t = (ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addModuleImportVS String
l) StateT ValueState Identity ()
-> SVariable PythonCode -> SVariable PythonCode
forall a b.
StateT ValueState Identity a
-> StateT ValueState Identity b -> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String
-> String -> VS (PythonCode TypeData) -> SVariable PythonCode
forall (r :: * -> *).
RenderVariable r =>
String -> String -> VS (r TypeData) -> SVariable r
CS.extVar String
l String
n VS (PythonCode TypeData)
t
instance OOVariableSym PythonCode where
classVar :: String -> VS (PythonCode TypeData) -> SVariable PythonCode
classVar = String -> VS (PythonCode TypeData) -> SVariable PythonCode
forall (r :: * -> *).
RenderVariable r =>
String -> VS (r TypeData) -> SVariable r
G.classVar
classConst :: String -> VS (PythonCode TypeData) -> SVariable PythonCode
classConst String
n VS (PythonCode TypeData)
t = String -> VS (PythonCode TypeData) -> Doc -> SVariable PythonCode
forall (r :: * -> *).
RenderVariable r =>
String -> VS (r TypeData) -> Doc -> SVariable r
mkClassVar String
n VS (PythonCode TypeData)
t (String -> Doc
R.var (String -> String
toConstName String
n))
classVarAccess :: VS (PythonCode TypeData)
-> SVariable PythonCode -> SVariable PythonCode
classVarAccess = (Doc -> Doc -> Doc)
-> VS (PythonCode TypeData)
-> SVariable PythonCode
-> SVariable PythonCode
forall (r :: * -> *).
(InternalVarElim r, RenderVariable r, UnRepr r TypeData,
VariableElim r) =>
(Doc -> Doc -> Doc)
-> VS (r TypeData) -> SVariable r -> SVariable r
CP.classVarAccess Doc -> Doc -> Doc
R.classVarAccess
extClassVarAccess :: VS (PythonCode TypeData)
-> SVariable PythonCode -> SVariable PythonCode
extClassVarAccess VS (PythonCode TypeData)
c SVariable PythonCode
v = StateT ValueState Identity (SVariable PythonCode)
-> SVariable PythonCode
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (StateT ValueState Identity (SVariable PythonCode)
-> SVariable PythonCode)
-> StateT ValueState Identity (SVariable PythonCode)
-> SVariable PythonCode
forall a b. (a -> b) -> a -> b
$ (PythonCode TypeData -> Map String String -> SVariable PythonCode)
-> VS (PythonCode TypeData)
-> State ValueState (Map String String)
-> StateT ValueState Identity (SVariable PythonCode)
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues (\PythonCode TypeData
t Map String String
cm -> (SVariable PythonCode -> SVariable PythonCode)
-> (String -> SVariable PythonCode -> SVariable PythonCode)
-> Maybe String
-> SVariable PythonCode
-> SVariable PythonCode
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SVariable PythonCode -> SVariable PythonCode
forall a. a -> a
id (StateT ValueState Identity ()
-> SVariable PythonCode -> SVariable PythonCode
forall a b.
StateT ValueState Identity a
-> StateT ValueState Identity b -> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
(>>) (StateT ValueState Identity ()
-> SVariable PythonCode -> SVariable PythonCode)
-> (String -> StateT ValueState Identity ())
-> String
-> SVariable PythonCode
-> SVariable PythonCode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((ValueState -> ValueState) -> StateT ValueState Identity ())
-> (String -> ValueState -> ValueState)
-> String
-> StateT ValueState Identity ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
String -> ValueState -> ValueState
addModuleImportVS) (String -> Map String String -> Maybe String
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (PythonCode TypeData -> String
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> String
getTypeString PythonCode TypeData
t) Map String String
cm) (SVariable PythonCode -> SVariable PythonCode)
-> SVariable PythonCode -> SVariable PythonCode
forall a b. (a -> b) -> a -> b
$
(Doc -> Doc -> Doc)
-> VS (PythonCode TypeData)
-> SVariable PythonCode
-> SVariable PythonCode
forall (r :: * -> *).
(InternalVarElim r, RenderVariable r, UnRepr r TypeData,
VariableElim r) =>
(Doc -> Doc -> Doc)
-> VS (r TypeData) -> SVariable r -> SVariable r
CP.classVarAccess Doc -> Doc -> Doc
pyClassVarAccess (PythonCode TypeData -> VS (PythonCode TypeData)
forall a s. a -> State s a
toState PythonCode TypeData
t) SVariable PythonCode
v) VS (PythonCode TypeData)
c State ValueState (Map String String)
getClassMap
instanceVarAccess :: SValue PythonCode -> SVariable PythonCode -> SVariable PythonCode
instanceVarAccess = SValue PythonCode -> SVariable PythonCode -> SVariable PythonCode
forall (r :: * -> *).
(InternalVarElim r, RenderVariable r, ValueElim r,
VariableElim r) =>
SValue r -> SVariable r -> SVariable r
G.instanceVarAccess
instance SelfSym PythonCode where
self :: SVariable PythonCode
self = LensLike'
(Zoomed (StateT MethodState Identity) String)
ValueState
MethodState
-> StateT MethodState Identity String
-> StateT ValueState Identity String
forall c.
LensLike'
(Zoomed (StateT MethodState Identity) c) ValueState MethodState
-> StateT MethodState Identity c -> StateT ValueState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT MethodState Identity) String)
ValueState
MethodState
(MethodState -> Focusing Identity String MethodState)
-> ValueState -> Focusing Identity String ValueState
Lens' ValueState MethodState
lensVStoMS StateT MethodState Identity String
getClassName StateT ValueState Identity String
-> (String -> SVariable PythonCode) -> SVariable PythonCode
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\String
l -> String -> VS (PythonCode TypeData) -> Doc -> SVariable PythonCode
forall (r :: * -> *).
RenderVariable r =>
String -> VS (r TypeData) -> Doc -> SVariable r
mkStateVar String
pySelf (String -> VS (PythonCode TypeData)
forall (r :: * -> *). OOTypeSym r => String -> VS (r TypeData)
obj String
l) (String -> Doc
text String
pySelf))
instance VariableElim PythonCode where
variableName :: PythonCode Variable -> String
variableName = Variable -> String
varName (Variable -> String)
-> (PythonCode Variable -> Variable)
-> PythonCode Variable
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Variable -> Variable
forall a. PythonCode a -> a
unPC
variableType :: PythonCode Variable -> PythonCode TypeData
variableType = (Variable -> TypeData)
-> PythonCode Variable -> PythonCode TypeData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue Variable -> TypeData
varType
instance InternalVarElim PythonCode where
variableBind :: PythonCode Variable -> AttachmentTag
variableBind = Variable -> AttachmentTag
varBind (Variable -> AttachmentTag)
-> (PythonCode Variable -> Variable)
-> PythonCode Variable
-> AttachmentTag
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Variable -> Variable
forall a. PythonCode a -> a
unPC
variable :: PythonCode Variable -> Doc
variable = Variable -> Doc
varDoc (Variable -> Doc)
-> (PythonCode Variable -> Variable) -> PythonCode Variable -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Variable -> Variable
forall a. PythonCode a -> a
unPC
instance RenderVariable PythonCode where
varFromData :: AttachmentTag
-> String
-> VS (PythonCode TypeData)
-> Doc
-> SVariable PythonCode
varFromData AttachmentTag
b String
n VS (PythonCode TypeData)
t' Doc
d = do
PythonCode TypeData
t <- VS (PythonCode TypeData)
t'
PythonCode Variable -> SVariable PythonCode
forall a s. a -> State s a
toState (PythonCode Variable -> SVariable PythonCode)
-> PythonCode Variable -> SVariable PythonCode
forall a b. (a -> b) -> a -> b
$ (TypeData -> Doc -> Variable)
-> PythonCode TypeData -> PythonCode Doc -> PythonCode Variable
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues (AttachmentTag -> String -> TypeData -> Doc -> Variable
vard AttachmentTag
b String
n) PythonCode TypeData
t (Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
d)
instance ValueSym PythonCode where
valueType :: PythonCode Value -> PythonCode TypeData
valueType = (Value -> TypeData) -> PythonCode Value -> PythonCode TypeData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue Value -> TypeData
valType
instance OOValueSym PythonCode
instance Argument PythonCode where
pointerArg :: SValue PythonCode -> SValue PythonCode
pointerArg = SValue PythonCode -> SValue PythonCode
forall a. a -> a
id
instance Literal PythonCode where
litTrue :: SValue PythonCode
litTrue = VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool Doc
pyTrue
litFalse :: SValue PythonCode
litFalse = VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool Doc
pyFalse
litChar :: Char -> SValue PythonCode
litChar = (Doc -> Doc) -> Char -> SValue PythonCode
forall (r :: * -> *).
(RenderValue r, TypeSym r) =>
(Doc -> Doc) -> Char -> SValue r
G.litChar Doc -> Doc
quotes
litDouble :: Double -> SValue PythonCode
litDouble = Double -> SValue PythonCode
forall (r :: * -> *).
(RenderValue r, TypeSym r) =>
Double -> SValue r
G.litDouble
litFloat :: Float -> SValue PythonCode
litFloat = String -> Float -> SValue PythonCode
forall a. HasCallStack => String -> a
error String
pyFloatError
litInt :: Integer -> SValue PythonCode
litInt = Integer -> SValue PythonCode
forall (r :: * -> *).
(RenderValue r, TypeSym r) =>
Integer -> SValue r
G.litInt
litString :: String -> SValue PythonCode
litString = String -> SValue PythonCode
forall (r :: * -> *).
(RenderValue r, TypeSym r) =>
String -> SValue r
G.litString
litArray :: VS (PythonCode TypeData)
-> [SValue PythonCode] -> SValue PythonCode
litArray = (Doc -> Doc)
-> VS (PythonCode TypeData)
-> [SValue PythonCode]
-> SValue PythonCode
forall (r :: * -> *).
(RenderValue r, TypeSym r, ValueElim r) =>
(Doc -> Doc) -> VS (r TypeData) -> [SValue r] -> SValue r
CP.litArray Doc -> Doc
brackets
litSet :: VS (PythonCode TypeData)
-> [SValue PythonCode] -> SValue PythonCode
litSet = (Doc -> Doc)
-> VS (PythonCode TypeData)
-> [SValue PythonCode]
-> SValue PythonCode
forall (r :: * -> *).
(RenderValue r, TypeSym r, ValueElim r) =>
(Doc -> Doc) -> VS (r TypeData) -> [SValue r] -> SValue r
CP.litArray Doc -> Doc
braces
litList :: VS (PythonCode TypeData)
-> [SValue PythonCode] -> SValue PythonCode
litList = VS (PythonCode TypeData)
-> [SValue PythonCode] -> SValue PythonCode
forall (r :: * -> *).
Literal r =>
VS (r TypeData) -> [SValue r] -> SValue r
litArray
instance MathConstant PythonCode where
pi :: SValue PythonCode
pi = SValue PythonCode -> SValue PythonCode
forall a. VS a -> VS a
addmathImport (SValue PythonCode -> SValue PythonCode)
-> SValue PythonCode -> SValue PythonCode
forall a b. (a -> b) -> a -> b
$ VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
double Doc
pyPi
instance VariableValue PythonCode where
valueOf :: SVariable PythonCode -> SValue PythonCode
valueOf = SVariable PythonCode -> SValue PythonCode
forall (r :: * -> *).
(InternalVarElim r, RenderValue r, VariableElim r) =>
SVariable r -> SValue r
G.valueOf
instance OOVariableValue PythonCode
instance CommandLineArgs PythonCode where
arg :: Integer -> SValue PythonCode
arg Integer
n = SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(RenderValue r, TypeSym r, ValueElim r) =>
SValue r -> SValue r -> SValue r
G.arg (Integer -> SValue PythonCode
forall (r :: * -> *). Literal r => Integer -> SValue r
litInt (Integer -> SValue PythonCode) -> Integer -> SValue PythonCode
forall a b. (a -> b) -> a -> b
$ Integer
nInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
+Integer
1) SValue PythonCode
forall (r :: * -> *). CommandLineArgs r => SValue r
argsList
argsList :: SValue PythonCode
argsList = do
(ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addLangImportVS String
pySys)
String -> SValue PythonCode
forall (r :: * -> *).
(RenderValue r, TypeSym r) =>
String -> SValue r
G.argsList (String -> SValue PythonCode) -> String -> SValue PythonCode
forall a b. (a -> b) -> a -> b
$ String
pySys String -> String -> String
`access` String
argv
argExists :: Integer -> SValue PythonCode
argExists = Integer -> SValue PythonCode
forall (r :: * -> *) smt.
SharedStatement r smt =>
Integer -> SValue r
CP.argExists
instance NumericExpression PythonCode where
#~ :: SValue PythonCode -> SValue PythonCode
(#~) = VSUnOp PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr' VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
negateOp
#/^ :: SValue PythonCode -> SValue PythonCode
(#/^) = VSUnOp PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
sqrtOp
#| :: SValue PythonCode -> SValue PythonCode
(#|) = VSUnOp PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
absOp
#+ :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
(#+) = VSUnOp PythonCode
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, TypeElim r, ValueElim r, ValueSym r) =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
plusOp
#- :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
(#-) = VSUnOp PythonCode
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, TypeElim r, ValueElim r, ValueSym r) =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
minusOp
#* :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
(#*) = VSUnOp PythonCode
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, TypeElim r, ValueElim r, ValueSym r) =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
multOp
#/ :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
(#/) SValue PythonCode
v1' SValue PythonCode
v2' = do
PythonCode Value
v1 <- SValue PythonCode
v1'
PythonCode Value
v2 <- SValue PythonCode
v2'
let pyDivision :: CodeType -> CodeType -> SValue r -> SValue r -> SValue r
pyDivision CodeType
Integer CodeType
Integer = VSBinOp r -> SValue r -> SValue r -> SValue r
forall (r :: * -> *).
(OpElim r, RenderValue r, TypeElim r, ValueElim r, ValueSym r) =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr (String -> VSBinOp r
forall (r :: * -> *). Monad r => String -> VSOp r
multPrec String
pyIntDiv)
pyDivision CodeType
_ CodeType
_ = VSBinOp r -> SValue r -> SValue r -> SValue r
forall (r :: * -> *).
(OpElim r, RenderValue r, TypeElim r, ValueElim r, ValueSym r) =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr VSBinOp r
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
divideOp
CodeType
-> CodeType
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
forall {r :: * -> *}.
(OpElim r, RenderValue r, TypeElim r, ValueElim r, ValueSym r,
Monad r, BinaryOpSym r) =>
CodeType -> CodeType -> SValue r -> SValue r -> SValue r
pyDivision (PythonCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (PythonCode TypeData -> CodeType)
-> PythonCode TypeData -> CodeType
forall a b. (a -> b) -> a -> b
$ PythonCode Value -> PythonCode TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType PythonCode Value
v1) (PythonCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (PythonCode TypeData -> CodeType)
-> PythonCode TypeData -> CodeType
forall a b. (a -> b) -> a -> b
$ PythonCode Value -> PythonCode TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType PythonCode Value
v2) (PythonCode Value -> SValue PythonCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PythonCode Value
v1)
(PythonCode Value -> SValue PythonCode
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PythonCode Value
v2)
#% :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
(#%) = VSUnOp PythonCode
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, TypeElim r, ValueElim r, ValueSym r) =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
moduloOp
#^ :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
(#^) = VSUnOp PythonCode
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, TypeElim r, ValueElim r, ValueSym r) =>
VSBinOp r -> SValue r -> SValue r -> SValue r
binExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
powerOp
log :: SValue PythonCode -> SValue PythonCode
log = VSUnOp PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
logOp
ln :: SValue PythonCode -> SValue PythonCode
ln = VSUnOp PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
lnOp
exp :: SValue PythonCode -> SValue PythonCode
exp = VSUnOp PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
expOp
sin :: SValue PythonCode -> SValue PythonCode
sin = VSUnOp PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
sinOp
cos :: SValue PythonCode -> SValue PythonCode
cos = VSUnOp PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
cosOp
tan :: SValue PythonCode -> SValue PythonCode
tan = VSUnOp PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
tanOp
csc :: SValue PythonCode -> SValue PythonCode
csc = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(Literal r, NumericExpression r, TypeElim r) =>
SValue r -> SValue r
G.csc
sec :: SValue PythonCode -> SValue PythonCode
sec = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(Literal r, NumericExpression r, TypeElim r) =>
SValue r -> SValue r
G.sec
cot :: SValue PythonCode -> SValue PythonCode
cot = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(Literal r, NumericExpression r, TypeElim r) =>
SValue r -> SValue r
G.cot
arcsin :: SValue PythonCode -> SValue PythonCode
arcsin = VSUnOp PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
asinOp
arccos :: SValue PythonCode -> SValue PythonCode
arccos = VSUnOp PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
acosOp
arctan :: SValue PythonCode -> SValue PythonCode
arctan = VSUnOp PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
atanOp
floor :: SValue PythonCode -> SValue PythonCode
floor = VSUnOp PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
floorOp
ceil :: SValue PythonCode -> SValue PythonCode
ceil = VSUnOp PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r, ValueSym r) =>
VSUnOp r -> SValue r -> SValue r
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
ceilOp
instance BooleanExpression PythonCode where
?! :: SValue PythonCode -> SValue PythonCode
(?!) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSUnOp r -> VS (r TypeData) -> SValue r -> SValue r
typeUnExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
notOp VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool
?&& :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
(?&&) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
andOp VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool
?|| :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
(?||) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
orOp VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool
instance Comparison PythonCode where
?< :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
(?<) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
lessOp VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool
?<= :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
(?<=) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
lessEqualOp VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool
?> :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
(?>) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
greaterOp VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool
?>= :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
(?>=) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
greaterEqualOp VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool
?== :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
(?==) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
equalOp VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool
?!= :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
(?!=) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
notEqualOp VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool
instance ValueExpression PythonCode where
inlineIf :: SValue PythonCode
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
inlineIf = SValue PythonCode
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r -> SValue r -> SValue r
pyInlineIf
funcAppMixedArgs :: MixedCall PythonCode
funcAppMixedArgs = MixedCall PythonCode
forall (r :: * -> *). RenderValue r => MixedCall r
G.funcAppMixedArgs
extFuncAppMixedArgs :: String -> MixedCall PythonCode
extFuncAppMixedArgs String
l String
n VS (PythonCode TypeData)
t [SValue PythonCode]
ps NamedArgs PythonCode
ns = do
(ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addModuleImportVS String
l)
String -> MixedCall PythonCode
forall (r :: * -> *). RenderValue r => String -> MixedCall r
CS.extFuncAppMixedArgs String
l String
n VS (PythonCode TypeData)
t [SValue PythonCode]
ps NamedArgs PythonCode
ns
libFuncAppMixedArgs :: String -> MixedCall PythonCode
libFuncAppMixedArgs String
l String
n VS (PythonCode TypeData)
t [SValue PythonCode]
ps NamedArgs PythonCode
ns = do
(ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addLibImportVS String
l)
String -> MixedCall PythonCode
forall (r :: * -> *). RenderValue r => String -> MixedCall r
CS.extFuncAppMixedArgs String
l String
n VS (PythonCode TypeData)
t [SValue PythonCode]
ps NamedArgs PythonCode
ns
lambda :: [VSBinder PythonCode] -> SValue PythonCode -> SValue PythonCode
lambda = ([PythonCode BinderD] -> PythonCode Value -> Doc)
-> [VSBinder PythonCode] -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(BinderElim r, RenderValue r, ValueSym r) =>
([r BinderD] -> r Value -> Doc)
-> [VSBinder r] -> SValue r -> SValue r
G.lambda [PythonCode BinderD] -> PythonCode Value -> Doc
forall (r :: * -> *).
(InternalBinderElim r, ValueElim r) =>
[r BinderD] -> r Value -> Doc
pyLambda
notNull :: SValue PythonCode -> SValue PythonCode
notNull = String -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(Comparison r, VariableValue r) =>
String -> SValue r -> SValue r
CP.notNull String
pyNull
instance OOValueExpression PythonCode where
newObjMixedArgs :: MixedCtorCall PythonCode
newObjMixedArgs = MixedCall PythonCode
forall (r :: * -> *).
(RenderValue r, UnRepr r TypeData) =>
String -> MixedCtorCall r
G.newObjMixedArgs String
""
extNewObjMixedArgs :: MixedCall PythonCode
extNewObjMixedArgs String
l VS (PythonCode TypeData)
tp [SValue PythonCode]
ps NamedArgs PythonCode
ns = do
(ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addModuleImportVS String
l)
MixedCall PythonCode
forall (r :: * -> *).
(RenderValue r, UnRepr r TypeData) =>
String -> MixedCtorCall r
pyExtNewObjMixedArgs String
l VS (PythonCode TypeData)
tp [SValue PythonCode]
ps NamedArgs PythonCode
ns
libNewObjMixedArgs :: MixedCall PythonCode
libNewObjMixedArgs String
l VS (PythonCode TypeData)
tp [SValue PythonCode]
ps NamedArgs PythonCode
ns = do
(ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addLibImportVS String
l)
MixedCall PythonCode
forall (r :: * -> *).
(RenderValue r, UnRepr r TypeData) =>
String -> MixedCtorCall r
pyExtNewObjMixedArgs String
l VS (PythonCode TypeData)
tp [SValue PythonCode]
ps NamedArgs PythonCode
ns
instance RenderValue PythonCode where
inputFunc :: SValue PythonCode
inputFunc = VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string Doc
pyInputFunc
printFunc :: SValue PythonCode
printFunc = VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
pyPrintFunc
printLnFunc :: SValue PythonCode
printLnFunc = VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
empty
printFileFunc :: SValue PythonCode -> SValue PythonCode
printFileFunc SValue PythonCode
_ = VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
empty
printFileLnFunc :: SValue PythonCode -> SValue PythonCode
printFileLnFunc SValue PythonCode
_ = VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
empty
cast :: VS (PythonCode TypeData) -> SValue PythonCode -> SValue PythonCode
cast = (PythonCode TypeData -> PythonCode Value -> SValue PythonCode)
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> SValue PythonCode
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> m a -> m b -> m c
on2StateWrapped (\PythonCode TypeData
t PythonCode Value
v-> PythonCode TypeData -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
r TypeData -> Doc -> SValue r
mkVal PythonCode TypeData
t (Doc -> SValue PythonCode)
-> (Doc -> Doc) -> Doc -> SValue PythonCode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc -> Doc
R.castObj (PythonCode TypeData -> Doc
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> Doc
renderType PythonCode TypeData
t)
(Doc -> SValue PythonCode) -> Doc -> SValue PythonCode
forall a b. (a -> b) -> a -> b
$ PythonCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value PythonCode Value
v)
call :: Maybe String -> Maybe Doc -> MixedCall PythonCode
call = Doc -> Maybe String -> Maybe Doc -> MixedCall PythonCode
forall (r :: * -> *).
(InternalVarElim r, RenderValue r, ValueElim r) =>
Doc -> Maybe String -> Maybe Doc -> MixedCall r
G.call Doc
pyNamedArgSep
valFromData :: Maybe Int
-> Maybe Integer
-> VS (PythonCode TypeData)
-> Doc
-> SValue PythonCode
valFromData Maybe Int
p Maybe Integer
i VS (PythonCode TypeData)
t' Doc
d = do
PythonCode TypeData
t <- VS (PythonCode TypeData)
t'
PythonCode Value -> SValue PythonCode
forall a s. a -> State s a
toState (PythonCode Value -> SValue PythonCode)
-> PythonCode Value -> SValue PythonCode
forall a b. (a -> b) -> a -> b
$ (TypeData -> Doc -> Value)
-> PythonCode TypeData -> PythonCode Doc -> PythonCode Value
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues (Maybe Int -> Maybe Integer -> TypeData -> Doc -> Value
vd Maybe Int
p Maybe Integer
i) PythonCode TypeData
t (Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
d)
instance ValueElim PythonCode where
valuePrec :: PythonCode Value -> Maybe Int
valuePrec = Value -> Maybe Int
valPrec (Value -> Maybe Int)
-> (PythonCode Value -> Value) -> PythonCode Value -> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Value -> Value
forall a. PythonCode a -> a
unPC
valueInt :: PythonCode Value -> Maybe Integer
valueInt = Value -> Maybe Integer
valInt (Value -> Maybe Integer)
-> (PythonCode Value -> Value) -> PythonCode Value -> Maybe Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Value -> Value
forall a. PythonCode a -> a
unPC
value :: PythonCode Value -> Doc
value = Value -> Doc
val (Value -> Doc)
-> (PythonCode Value -> Value) -> PythonCode Value -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Value -> Value
forall a. PythonCode a -> a
unPC
instance InternalValueExp PythonCode where
objMethodCallMixedArgs' :: String
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> [SValue PythonCode]
-> NamedArgs PythonCode
-> SValue PythonCode
objMethodCallMixedArgs' = String
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> [SValue PythonCode]
-> NamedArgs PythonCode
-> SValue PythonCode
forall (r :: * -> *).
(RenderValue r, ValueElim r) =>
String
-> VS (r TypeData)
-> SValue r
-> [SValue r]
-> NamedArgs r
-> SValue r
G.objMethodCall
classMethodCallMixedArgs' :: String -> VS (PythonCode TypeData) -> MixedCtorCall PythonCode
classMethodCallMixedArgs' = String -> VS (PythonCode TypeData) -> MixedCtorCall PythonCode
forall (r :: * -> *).
(RenderValue r, UnRepr r TypeData) =>
String
-> VS (r TypeData)
-> VS (r TypeData)
-> [SValue r]
-> NamedArgs r
-> SValue r
CG.classMethodCall
instance FunctionSym PythonCode where
instance OOFunctionSym PythonCode where
func :: String
-> VS (PythonCode TypeData)
-> [SValue PythonCode]
-> VS (PythonCode FuncData)
func = String
-> VS (PythonCode TypeData)
-> [SValue PythonCode]
-> VS (PythonCode FuncData)
forall (r :: * -> *).
(RenderFunction r, ValueElim r, ValueExpression r) =>
String -> VS (r TypeData) -> [SValue r] -> VS (r FuncData)
G.func
objAccess :: SValue PythonCode -> VS (PythonCode FuncData) -> SValue PythonCode
objAccess = SValue PythonCode -> VS (PythonCode FuncData) -> SValue PythonCode
forall (r :: * -> *).
(FunctionElim r, RenderValue r, ValueElim r) =>
SValue r -> VS (r FuncData) -> SValue r
G.objAccess
instance GetSet PythonCode where
get :: SValue PythonCode -> SVariable PythonCode -> SValue PythonCode
get = SValue PythonCode -> SVariable PythonCode -> SValue PythonCode
forall (r :: * -> *).
(InternalGetSet r, OOFunctionSym r) =>
SValue r -> SVariable r -> SValue r
G.get
set :: SValue PythonCode
-> SVariable PythonCode -> SValue PythonCode -> SValue PythonCode
set = SValue PythonCode
-> SVariable PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(InternalGetSet r, OOFunctionSym r) =>
SValue r -> SVariable r -> SValue r -> SValue r
G.set
instance IndexTranslator PythonCode where
intToIndex :: SValue PythonCode -> SValue PythonCode
intToIndex = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). SValue r -> SValue r
CP.intToIndex
indexToInt :: SValue PythonCode -> SValue PythonCode
indexToInt = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). SValue r -> SValue r
CP.indexToInt
instance Reference PythonCode where
makeRef :: SValue PythonCode -> SValue PythonCode
makeRef = SValue PythonCode -> SValue PythonCode
forall a. a -> a
id
maybeDeref :: SValue PythonCode -> SValue PythonCode
maybeDeref = SValue PythonCode -> SValue PythonCode
forall a. a -> a
id
instance Array PythonCode where
arrayElem :: SValue PythonCode -> SValue PythonCode -> SVariable PythonCode
arrayElem = SValue PythonCode -> SValue PythonCode -> SVariable PythonCode
forall (r :: * -> *).
(IndexTranslator r, RenderVariable r, ValueElim r) =>
SValue r -> SValue r -> SVariable r
G.arrayElem
arrayLength :: SValue PythonCode -> SValue PythonCode
arrayLength = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *) smt. List r smt => SValue r -> SValue r
listSize
arrayCopy :: SValue PythonCode -> SValue PythonCode
arrayCopy SValue PythonCode
arr = let
arrTp :: VS (PythonCode TypeData)
arrTp = (PythonCode Value -> PythonCode TypeData)
-> SValue PythonCode -> VS (PythonCode TypeData)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue PythonCode Value -> PythonCode TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType SValue PythonCode
arr
in VS (PythonCode TypeData)
-> SValue PythonCode
-> String
-> [SValue PythonCode]
-> SValue PythonCode
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
objMethodCall VS (PythonCode TypeData)
arrTp SValue PythonCode
arr String
"copy" []
instance List PythonCode (Doc, Terminator) where
listSize :: SValue PythonCode -> SValue PythonCode
listSize = String -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
ValueExpression r =>
String -> SValue r -> SValue r
CS.listSize String
pyListSize
listAdd :: SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
listAdd = String
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(IndexTranslator r, InternalValueExp r, StatementSym r smt) =>
String -> SValue r -> SValue r -> SValue r -> MS (r smt)
CG.listAdd String
pyInsert
listAppend :: SValue PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
listAppend = String
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(InternalValueExp r, StatementSym r smt) =>
String -> SValue r -> SValue r -> MS (r smt)
CG.listAppend String
pyAppendFunc
listAccess :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
listAccess = SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(IndexTranslator r, InternalListFunc r, FunctionElim r,
RenderFunction r, RenderValue r, TypeElim r, ValueElim r) =>
SValue r -> SValue r -> SValue r
G.listAccess
listSet :: SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
listSet = SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(AssignStatement r smt, IndexTranslator r, RenderVariable r,
ValueElim r) =>
SValue r -> SValue r -> SValue r -> MS (r smt)
CP.listSet
indexOf :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
indexOf = String
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(IndexTranslator r, OOFunctionSym r) =>
String -> SValue r -> SValue r -> SValue r
CP.indexOf String
pyIndex
instance Set PythonCode where
contains :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
contains SValue PythonCode
a SValue PythonCode
b = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
forall (r :: * -> *).
(OpElim r, RenderValue r, ValueElim r) =>
VSBinOp r -> VS (r TypeData) -> SValue r -> SValue r -> SValue r
typeBinExpr (String -> VSUnOp PythonCode
forall (r :: * -> *). Monad r => String -> VSOp r
inPrec String
pyIn) VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
bool SValue PythonCode
b SValue PythonCode
a
setAdd :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
setAdd = String
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
InternalValueExp r =>
String -> SValue r -> SValue r -> SValue r
CP.setMethodCall String
pyAdd
setRemove :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
setRemove = String
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
InternalValueExp r =>
String -> SValue r -> SValue r -> SValue r
CP.setMethodCall String
pyRemove
setUnion :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
setUnion = String
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
InternalValueExp r =>
String -> SValue r -> SValue r -> SValue r
CP.setMethodCall String
pyUnion
instance InternalList PythonCode where
listSlice' :: Maybe (SValue PythonCode)
-> Maybe (SValue PythonCode)
-> Maybe (SValue PythonCode)
-> SVariable PythonCode
-> SValue PythonCode
-> MS (PythonCode Doc)
listSlice' Maybe (SValue PythonCode)
b Maybe (SValue PythonCode)
e Maybe (SValue PythonCode)
s SVariable PythonCode
vn SValue PythonCode
vo = SVariable PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode Doc)
forall (r :: * -> *).
(InternalVarElim r, Monad r, ValueElim r) =>
SVariable r
-> SValue r -> SValue r -> SValue r -> SValue r -> MS (r Doc)
pyListSlice SVariable PythonCode
vn SValue PythonCode
vo (Maybe (SValue PythonCode) -> SValue PythonCode
getVal Maybe (SValue PythonCode)
b) (Maybe (SValue PythonCode) -> SValue PythonCode
getVal Maybe (SValue PythonCode)
e) (Maybe (SValue PythonCode) -> SValue PythonCode
getVal Maybe (SValue PythonCode)
s)
where getVal :: Maybe (SValue PythonCode) -> SValue PythonCode
getVal = SValue PythonCode -> Maybe (SValue PythonCode) -> SValue PythonCode
forall a. a -> Maybe a -> a
fromMaybe (VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
empty)
instance InternalGetSet PythonCode where
getFunc :: SVariable PythonCode -> VS (PythonCode FuncData)
getFunc = SVariable PythonCode -> VS (PythonCode FuncData)
forall (r :: * -> *).
(OOFunctionSym r, VariableElim r) =>
SVariable r -> VS (r FuncData)
G.getFunc
setFunc :: VS (PythonCode TypeData)
-> SVariable PythonCode
-> SValue PythonCode
-> VS (PythonCode FuncData)
setFunc = VS (PythonCode TypeData)
-> SVariable PythonCode
-> SValue PythonCode
-> VS (PythonCode FuncData)
forall (r :: * -> *).
(OOFunctionSym r, VariableElim r) =>
VS (r TypeData) -> SVariable r -> SValue r -> VS (r FuncData)
G.setFunc
instance InternalListFunc PythonCode where
listAccessFunc :: VS (PythonCode TypeData)
-> SValue PythonCode -> VS (PythonCode FuncData)
listAccessFunc = VS (PythonCode TypeData)
-> SValue PythonCode -> VS (PythonCode FuncData)
forall (r :: * -> *).
(RenderFunction r, TypeElim r, ValueElim r, ValueSym r) =>
VS (r TypeData) -> SValue r -> VS (r FuncData)
CS.listAccessFunc
instance BinderSym PythonCode where
binder :: String -> VS (PythonCode TypeData) -> VSBinder PythonCode
binder String
nm VS (PythonCode TypeData)
tp = (TypeData -> BinderD) -> PythonCode TypeData -> PythonCode BinderD
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue (String -> TypeData -> BinderD
bindFormD String
nm) (PythonCode TypeData -> PythonCode BinderD)
-> VS (PythonCode TypeData) -> VSBinder PythonCode
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
<$> VS (PythonCode TypeData)
tp
instance BinderElim PythonCode where
binderName :: PythonCode BinderD -> String
binderName = BinderD -> String
bindName (BinderD -> String)
-> (PythonCode BinderD -> BinderD) -> PythonCode BinderD -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode BinderD -> BinderD
forall a. PythonCode a -> a
unPC
binderType :: PythonCode BinderD -> PythonCode TypeData
binderType = (BinderD -> TypeData) -> PythonCode BinderD -> PythonCode TypeData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue BinderD -> TypeData
bindType
instance InternalBinderElim PythonCode where
binderElim :: PythonCode BinderD -> Doc
binderElim = String -> Doc
text (String -> Doc)
-> (PythonCode BinderD -> String) -> PythonCode BinderD -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BinderD -> String
bindName (BinderD -> String)
-> (PythonCode BinderD -> BinderD) -> PythonCode BinderD -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode BinderD -> BinderD
forall a. PythonCode a -> a
unPC
instance RenderFunction PythonCode where
funcFromData :: Doc -> VS (PythonCode TypeData) -> VS (PythonCode FuncData)
funcFromData Doc
d = (PythonCode TypeData -> PythonCode FuncData)
-> VS (PythonCode TypeData) -> VS (PythonCode FuncData)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue ((TypeData -> FuncData)
-> PythonCode TypeData -> PythonCode FuncData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue (TypeData -> Doc -> FuncData
`fd` Doc
d))
instance FunctionElim PythonCode where
functionType :: PythonCode FuncData -> PythonCode TypeData
functionType = (FuncData -> TypeData)
-> PythonCode FuncData -> PythonCode TypeData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue FuncData -> TypeData
fType
function :: PythonCode FuncData -> Doc
function = FuncData -> Doc
funcDoc (FuncData -> Doc)
-> (PythonCode FuncData -> FuncData) -> PythonCode FuncData -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode FuncData -> FuncData
forall a. PythonCode a -> a
unPC
instance InternalAssignStmt PythonCode (Doc, Terminator) where
multiAssign :: [SVariable PythonCode]
-> [SValue PythonCode] -> MS (PythonCode (Doc, Terminator))
multiAssign = (Doc -> Doc)
-> [SVariable PythonCode]
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(AssignStatement r smt, InternalVarElim r, RenderValue r,
RenderVariable r, ValueElim r) =>
(Doc -> Doc) -> [SVariable r] -> [SValue r] -> MS (r smt)
CP.multiAssign Doc -> Doc
forall a. a -> a
id
instance InternalIOStmt PythonCode (Doc, Terminator) where
printSt :: Bool
-> Maybe (SValue PythonCode)
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
printSt = Bool
-> Maybe (SValue PythonCode)
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
pyPrint
instance InternalControlStmt PythonCode (Doc, Terminator) where
multiReturn :: [SValue PythonCode] -> MS (PythonCode (Doc, Terminator))
multiReturn = (Doc -> Doc)
-> [SValue PythonCode] -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(ControlStatement r smt, RenderValue r, ValueElim r) =>
(Doc -> Doc) -> [SValue r] -> MS (r smt)
CP.multiReturn Doc -> Doc
forall a. a -> a
id
instance RenderStatement PythonCode (Doc, Terminator) where
stmt :: MS (PythonCode (Doc, Terminator))
-> MS (PythonCode (Doc, Terminator))
stmt = MS (PythonCode (Doc, Terminator))
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(RenderStatement r smt, StatementElim r smt) =>
MS (r smt) -> MS (r smt)
G.stmt
loopStmt :: MS (PythonCode (Doc, Terminator))
-> MS (PythonCode (Doc, Terminator))
loopStmt = MS (PythonCode (Doc, Terminator))
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(RenderStatement r smt, StatementElim r smt) =>
MS (r smt) -> MS (r smt)
G.loopStmt
stmtFromData :: Doc -> Terminator -> MS (PythonCode (Doc, Terminator))
stmtFromData Doc
d Terminator
t = PythonCode (Doc, Terminator) -> MS (PythonCode (Doc, Terminator))
forall a s. a -> State s a
toState (PythonCode (Doc, Terminator) -> MS (PythonCode (Doc, Terminator)))
-> PythonCode (Doc, Terminator)
-> MS (PythonCode (Doc, Terminator))
forall a b. (a -> b) -> a -> b
$ (Doc, Terminator) -> PythonCode (Doc, Terminator)
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc
d, Terminator
t)
instance StatementElim PythonCode (Doc, Terminator) where
statement :: PythonCode (Doc, Terminator) -> Doc
statement = (Doc, Terminator) -> Doc
forall a b. (a, b) -> a
fst ((Doc, Terminator) -> Doc)
-> (PythonCode (Doc, Terminator) -> (Doc, Terminator))
-> PythonCode (Doc, Terminator)
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode (Doc, Terminator) -> (Doc, Terminator)
forall a. PythonCode a -> a
unPC
statementTerm :: PythonCode (Doc, Terminator) -> Terminator
statementTerm = (Doc, Terminator) -> Terminator
forall a b. (a, b) -> b
snd ((Doc, Terminator) -> Terminator)
-> (PythonCode (Doc, Terminator) -> (Doc, Terminator))
-> PythonCode (Doc, Terminator)
-> Terminator
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode (Doc, Terminator) -> (Doc, Terminator)
forall a. PythonCode a -> a
unPC
instance StatementSym PythonCode (Doc, Terminator) where
valStmt :: SValue PythonCode -> MS (PythonCode (Doc, Terminator))
valStmt = Terminator
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(RenderStatement r smt, ValueElim r) =>
Terminator -> SValue r -> MS (r smt)
G.valStmt Terminator
Empty
emptyStmt :: MS (PythonCode (Doc, Terminator))
emptyStmt = MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt. RenderStatement r smt => MS (r smt)
G.emptyStmt
multi :: [MS (PythonCode (Doc, Terminator))]
-> MS (PythonCode (Doc, Terminator))
multi = ([PythonCode (Doc, Terminator)] -> PythonCode (Doc, Terminator))
-> [MS (PythonCode (Doc, Terminator))]
-> MS (PythonCode (Doc, Terminator))
forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList (([(Doc, Terminator)] -> (Doc, Terminator))
-> [PythonCode (Doc, Terminator)] -> PythonCode (Doc, Terminator)
forall (m :: * -> *) a b. Monad m => ([a] -> b) -> [m a] -> m b
onCodeList [(Doc, Terminator)] -> (Doc, Terminator)
R.multiStmt)
instance AssignStatement PythonCode (Doc, Terminator) where
assign :: SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
assign = Terminator
-> SVariable PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(InternalVarElim r, RenderStatement r smt, ValueElim r) =>
Terminator -> SVariable r -> SValue r -> MS (r smt)
G.assign Terminator
Empty
&-= :: SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
(&-=) = Terminator
-> SVariable PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(InternalVarElim r, RenderStatement r smt, ValueElim r) =>
Terminator -> SVariable r -> SValue r -> MS (r smt)
G.subAssign Terminator
Empty
&+= :: SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
(&+=) = SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(InternalVarElim r, RenderStatement r smt, ValueElim r) =>
SVariable r -> SValue r -> MS (r smt)
CS.increment
&++ :: SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
(&++) = SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(AssignStatement r smt, Literal r) =>
SVariable r -> MS (r smt)
M.increment1
&-- :: SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
(&--) = SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(AssignStatement r smt, Literal r) =>
SVariable r -> MS (r smt)
M.decrement1
instance DeclStatement PythonCode (Doc, Terminator) where
varDec :: SVariable PythonCode
-> PythonCode ScopeData -> MS (PythonCode (Doc, Terminator))
varDec SVariable PythonCode
v PythonCode ScopeData
scp = SVariable PythonCode
-> PythonCode ScopeData
-> Maybe (SValue PythonCode)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(AssignStatement r smt, ScopeElim r, VariableElim r) =>
SVariable r -> r ScopeData -> Maybe (SValue r) -> MS (r smt)
CS.varDecDef SVariable PythonCode
v PythonCode ScopeData
scp Maybe (SValue PythonCode)
forall a. Maybe a
Nothing
varDecDef :: SVariable PythonCode
-> PythonCode ScopeData
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
varDecDef SVariable PythonCode
v PythonCode ScopeData
scp SValue PythonCode
e = SVariable PythonCode
-> PythonCode ScopeData
-> Maybe (SValue PythonCode)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(AssignStatement r smt, ScopeElim r, VariableElim r) =>
SVariable r -> r ScopeData -> Maybe (SValue r) -> MS (r smt)
CS.varDecDef SVariable PythonCode
v PythonCode ScopeData
scp (SValue PythonCode -> Maybe (SValue PythonCode)
forall a. a -> Maybe a
Just SValue PythonCode
e)
setDec :: SVariable PythonCode
-> PythonCode ScopeData -> MS (PythonCode (Doc, Terminator))
setDec = SVariable PythonCode
-> PythonCode ScopeData -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
DeclStatement r smt =>
SVariable r -> r ScopeData -> MS (r smt)
varDec
setDecDef :: SVariable PythonCode
-> PythonCode ScopeData
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
setDecDef = SVariable PythonCode
-> PythonCode ScopeData
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
DeclStatement r smt =>
SVariable r -> r ScopeData -> SValue r -> MS (r smt)
varDecDef
listDec :: Integer
-> SVariable PythonCode
-> PythonCode ScopeData
-> MS (PythonCode (Doc, Terminator))
listDec Integer
_ = SVariable PythonCode
-> PythonCode ScopeData -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(DeclStatement r smt, Literal r, VariableElim r) =>
SVariable r -> r ScopeData -> MS (r smt)
CP.listDec
listDecDef :: SVariable PythonCode
-> PythonCode ScopeData
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
listDecDef = SVariable PythonCode
-> PythonCode ScopeData
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(DeclStatement r smt, Literal r, VariableElim r) =>
SVariable r -> r ScopeData -> [SValue r] -> MS (r smt)
CP.listDecDef
arrayDec :: Integer
-> SValue PythonCode
-> SVariable PythonCode
-> PythonCode ScopeData
-> MS (PythonCode (Doc, Terminator))
arrayDec = Integer
-> SValue PythonCode
-> SVariable PythonCode
-> PythonCode ScopeData
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(SharedStatement r smt, VariableElim r) =>
Integer -> SValue r -> SVariable r -> r ScopeData -> MS (r smt)
M.arrayDecAsList
arrayDecDef :: SVariable PythonCode
-> PythonCode ScopeData
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
arrayDecDef = SVariable PythonCode
-> PythonCode ScopeData
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
DeclStatement r smt =>
SVariable r -> r ScopeData -> [SValue r] -> MS (r smt)
listDecDef
constDecDef :: SVariable PythonCode
-> PythonCode ScopeData
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
constDecDef SVariable PythonCode
v PythonCode ScopeData
scp SValue PythonCode
e = do
PythonCode Variable
v' <- LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Variable))
MethodState
ValueState
-> SVariable PythonCode
-> StateT MethodState Identity (PythonCode Variable)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Variable))
MethodState
ValueState
(ValueState -> Focusing Identity (PythonCode Variable) ValueState)
-> MethodState
-> Focusing Identity (PythonCode Variable) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable PythonCode
v
let n :: String
n = String -> String
toConstName (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ PythonCode Variable -> String
forall (r :: * -> *). VariableElim r => r Variable -> String
variableName PythonCode Variable
v'
newConst :: SVariable PythonCode
newConst = String -> VS (PythonCode TypeData) -> SVariable PythonCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
constant String
n (PythonCode TypeData -> VS (PythonCode TypeData)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PythonCode Variable -> PythonCode TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType PythonCode Variable
v'))
Bool
available <- String -> MS Bool
varNameAvailable String
n
if Bool
available
then SVariable PythonCode
-> PythonCode ScopeData
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
DeclStatement r smt =>
SVariable r -> r ScopeData -> SValue r -> MS (r smt)
varDecDef SVariable PythonCode
newConst PythonCode ScopeData
scp SValue PythonCode
e
else String -> MS (PythonCode (Doc, Terminator))
forall a. HasCallStack => String -> a
error String
"Cannot safely capitalize constant."
funcDecDef :: SVariable PythonCode
-> PythonCode ScopeData
-> [SVariable PythonCode]
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
funcDecDef = SVariable PythonCode
-> PythonCode ScopeData
-> [SVariable PythonCode]
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) vis smt md svr att.
OORenderSym r vis smt md svr att =>
SVariable r
-> r ScopeData -> [SVariable r] -> MS (r Doc) -> MS (r smt)
CP.funcDecDef
instance OODeclStatement PythonCode (Doc, Terminator) where
objDecDef :: SVariable PythonCode
-> PythonCode ScopeData
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
objDecDef = SVariable PythonCode
-> PythonCode ScopeData
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
DeclStatement r smt =>
SVariable r -> r ScopeData -> SValue r -> MS (r smt)
varDecDef
objDecNew :: SVariable PythonCode
-> PythonCode ScopeData
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
objDecNew = SVariable PythonCode
-> PythonCode ScopeData
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(DeclStatement r smt, OOValueExpression r, VariableElim r) =>
SVariable r -> r ScopeData -> [SValue r] -> MS (r smt)
G.objDecNew
extObjDecNew :: String
-> SVariable PythonCode
-> PythonCode ScopeData
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
extObjDecNew String
lib SVariable PythonCode
v PythonCode ScopeData
scp [SValue PythonCode]
vs = do
(MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> MethodState -> MethodState
addModuleImport String
lib)
SVariable PythonCode
-> PythonCode ScopeData
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
DeclStatement r smt =>
SVariable r -> r ScopeData -> SValue r -> MS (r smt)
varDecDef SVariable PythonCode
v PythonCode ScopeData
scp (String
-> VS (PythonCode TypeData)
-> [SValue PythonCode]
-> SValue PythonCode
forall (r :: * -> *).
OOValueExpression r =>
String -> PosCtorCall r
extNewObj String
lib ((PythonCode Variable -> PythonCode TypeData)
-> SVariable PythonCode -> VS (PythonCode TypeData)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue PythonCode Variable -> PythonCode TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType SVariable PythonCode
v) [SValue PythonCode]
vs)
instance IOStatement PythonCode (Doc, Terminator) where
print :: SValue PythonCode -> MS (PythonCode (Doc, Terminator))
print = Bool
-> Maybe (SValue PythonCode)
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(InternalIOStmt r smt, SharedStatement r smt, TypeElim r) =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r smt)
pyOut Bool
False Maybe (SValue PythonCode)
forall a. Maybe a
Nothing SValue PythonCode
forall (r :: * -> *). RenderValue r => SValue r
printFunc
printLn :: SValue PythonCode -> MS (PythonCode (Doc, Terminator))
printLn = Bool
-> Maybe (SValue PythonCode)
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(InternalIOStmt r smt, SharedStatement r smt, TypeElim r) =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r smt)
pyOut Bool
True Maybe (SValue PythonCode)
forall a. Maybe a
Nothing SValue PythonCode
forall (r :: * -> *). RenderValue r => SValue r
printFunc
printStr :: String -> MS (PythonCode (Doc, Terminator))
printStr = SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
IOStatement r smt =>
SValue r -> MS (r smt)
print (SValue PythonCode -> MS (PythonCode (Doc, Terminator)))
-> (String -> SValue PythonCode)
-> String
-> MS (PythonCode (Doc, Terminator))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SValue PythonCode
forall (r :: * -> *). Literal r => String -> SValue r
litString
printStrLn :: String -> MS (PythonCode (Doc, Terminator))
printStrLn = SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
IOStatement r smt =>
SValue r -> MS (r smt)
printLn (SValue PythonCode -> MS (PythonCode (Doc, Terminator)))
-> (String -> SValue PythonCode)
-> String
-> MS (PythonCode (Doc, Terminator))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SValue PythonCode
forall (r :: * -> *). Literal r => String -> SValue r
litString
printFile :: SValue PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
printFile SValue PythonCode
f = Bool
-> Maybe (SValue PythonCode)
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(InternalIOStmt r smt, SharedStatement r smt, TypeElim r) =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r smt)
pyOut Bool
False (SValue PythonCode -> Maybe (SValue PythonCode)
forall a. a -> Maybe a
Just SValue PythonCode
f) SValue PythonCode
forall (r :: * -> *). RenderValue r => SValue r
printFunc
printFileLn :: SValue PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
printFileLn SValue PythonCode
f = Bool
-> Maybe (SValue PythonCode)
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(InternalIOStmt r smt, SharedStatement r smt, TypeElim r) =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r smt)
pyOut Bool
True (SValue PythonCode -> Maybe (SValue PythonCode)
forall a. a -> Maybe a
Just SValue PythonCode
f) SValue PythonCode
forall (r :: * -> *). RenderValue r => SValue r
printFunc
printFileStr :: SValue PythonCode -> String -> MS (PythonCode (Doc, Terminator))
printFileStr SValue PythonCode
f = SValue PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
IOStatement r smt =>
SValue r -> SValue r -> MS (r smt)
printFile SValue PythonCode
f (SValue PythonCode -> MS (PythonCode (Doc, Terminator)))
-> (String -> SValue PythonCode)
-> String
-> MS (PythonCode (Doc, Terminator))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SValue PythonCode
forall (r :: * -> *). Literal r => String -> SValue r
litString
printFileStrLn :: SValue PythonCode -> String -> MS (PythonCode (Doc, Terminator))
printFileStrLn SValue PythonCode
f = SValue PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
IOStatement r smt =>
SValue r -> SValue r -> MS (r smt)
printFileLn SValue PythonCode
f (SValue PythonCode -> MS (PythonCode (Doc, Terminator)))
-> (String -> SValue PythonCode)
-> String
-> MS (PythonCode (Doc, Terminator))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SValue PythonCode
forall (r :: * -> *). Literal r => String -> SValue r
litString
getInput :: SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
getInput = SValue PythonCode
-> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
pyInput SValue PythonCode
forall (r :: * -> *). RenderValue r => SValue r
inputFunc
discardInput :: MS (PythonCode (Doc, Terminator))
discardInput = SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
StatementSym r smt =>
SValue r -> MS (r smt)
valStmt SValue PythonCode
forall (r :: * -> *). RenderValue r => SValue r
inputFunc
getFileInput :: SValue PythonCode
-> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
getFileInput SValue PythonCode
f = SValue PythonCode
-> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
pyInput (SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). InternalValueExp r => SValue r -> SValue r
readline SValue PythonCode
f)
discardFileInput :: SValue PythonCode -> MS (PythonCode (Doc, Terminator))
discardFileInput SValue PythonCode
f = SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
StatementSym r smt =>
SValue r -> MS (r smt)
valStmt (SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). InternalValueExp r => SValue r -> SValue r
readline SValue PythonCode
f)
openFileR :: SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
openFileR SVariable PythonCode
f SValue PythonCode
n = SVariable PythonCode
f SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
AssignStatement r smt =>
SVariable r -> SValue r -> MS (r smt)
&= SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(Literal r, ValueExpression r) =>
SValue r -> SValue r
CP.openFileR' SValue PythonCode
n
openFileW :: SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
openFileW SVariable PythonCode
f SValue PythonCode
n = SVariable PythonCode
f SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
AssignStatement r smt =>
SVariable r -> SValue r -> MS (r smt)
&= SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(Literal r, ValueExpression r) =>
SValue r -> SValue r
CP.openFileW' SValue PythonCode
n
openFileA :: SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
openFileA SVariable PythonCode
f SValue PythonCode
n = SVariable PythonCode
f SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
AssignStatement r smt =>
SVariable r -> SValue r -> MS (r smt)
&= SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(Literal r, ValueExpression r) =>
SValue r -> SValue r
CP.openFileA' SValue PythonCode
n
closeFile :: SValue PythonCode -> MS (PythonCode (Doc, Terminator))
closeFile = String -> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(InternalValueExp r, StatementSym r smt) =>
String -> SValue r -> MS (r smt)
G.closeFile String
pyClose
getFileInputLine :: SValue PythonCode
-> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
getFileInputLine = SValue PythonCode
-> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
IOStatement r smt =>
SValue r -> SVariable r -> MS (r smt)
getFileInput
discardFileLine :: SValue PythonCode -> MS (PythonCode (Doc, Terminator))
discardFileLine = String -> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(InternalValueExp r, StatementSym r smt) =>
String -> SValue r -> MS (r smt)
CP.discardFileLine String
pyReadline
getFileInputAll :: SValue PythonCode
-> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
getFileInputAll SValue PythonCode
f SVariable PythonCode
v = SVariable PythonCode
v SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
AssignStatement r smt =>
SVariable r -> SValue r -> MS (r smt)
&= SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). InternalValueExp r => SValue r -> SValue r
readlines SValue PythonCode
f
instance StringStatement PythonCode (Doc, Terminator) where
stringSplit :: Char
-> SVariable PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
stringSplit Char
d SVariable PythonCode
vnew SValue PythonCode
s = SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
AssignStatement r smt =>
SVariable r -> SValue r -> MS (r smt)
assign SVariable PythonCode
vnew (SValue PythonCode -> VS (PythonCode FuncData) -> SValue PythonCode
forall (r :: * -> *).
OOFunctionSym r =>
SValue r -> VS (r FuncData) -> SValue r
objAccess SValue PythonCode
s (Char -> VS (PythonCode FuncData)
forall (r :: * -> *).
(Literal r, OOFunctionSym r) =>
Char -> VS (r FuncData)
splitFunc Char
d))
stringListVals :: [SVariable PythonCode]
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
stringListVals = [SVariable PythonCode]
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(AssignStatement r smt, List r smt, Literal r, RenderValue r,
TypeElim r, VariableElim r) =>
[SVariable r] -> SValue r -> MS (r smt)
M.stringListVals
stringListLists :: [SVariable PythonCode]
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
stringListLists = [SVariable PythonCode]
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(RenderValue r, SharedStatement r smt, TypeElim r,
VariableElim r) =>
[SVariable r] -> SValue r -> MS (r smt)
M.stringListLists
instance FuncAppStatement PythonCode (Doc, Terminator) where
inOutCall :: InOutCall PythonCode (Doc, Terminator)
inOutCall = (String
-> VS (PythonCode TypeData)
-> [SValue PythonCode]
-> SValue PythonCode)
-> InOutCall PythonCode (Doc, Terminator)
forall (r :: * -> *) smt.
(InternalAssignStmt r smt, StatementSym r smt, VariableValue r) =>
(String -> VS (r TypeData) -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MS (r smt)
CP.inOutCall String
-> VS (PythonCode TypeData)
-> [SValue PythonCode]
-> SValue PythonCode
forall (r :: * -> *). ValueExpression r => PosCall r
funcApp
extInOutCall :: String -> InOutCall PythonCode (Doc, Terminator)
extInOutCall String
m = (String
-> VS (PythonCode TypeData)
-> [SValue PythonCode]
-> SValue PythonCode)
-> InOutCall PythonCode (Doc, Terminator)
forall (r :: * -> *) smt.
(InternalAssignStmt r smt, StatementSym r smt, VariableValue r) =>
(String -> VS (r TypeData) -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MS (r smt)
CP.inOutCall (String
-> String
-> VS (PythonCode TypeData)
-> [SValue PythonCode]
-> SValue PythonCode
forall (r :: * -> *). ValueExpression r => String -> PosCall r
extFuncApp String
m)
instance OOFuncAppStatement PythonCode (Doc, Terminator) where
selfInOutCall :: InOutCall PythonCode (Doc, Terminator)
selfInOutCall = (String
-> VS (PythonCode TypeData)
-> [SValue PythonCode]
-> SValue PythonCode)
-> InOutCall PythonCode (Doc, Terminator)
forall (r :: * -> *) smt.
(InternalAssignStmt r smt, StatementSym r smt, VariableValue r) =>
(String -> VS (r TypeData) -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MS (r smt)
CP.inOutCall String
-> VS (PythonCode TypeData)
-> [SValue PythonCode]
-> SValue PythonCode
forall (r :: * -> *).
(InternalValueExp r, VariableValue r, SelfSym r) =>
PosCall r
selfMethodCall
instance CommentStatement PythonCode (Doc, Terminator) where
comment :: String -> MS (PythonCode (Doc, Terminator))
comment = Doc -> String -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> String -> MS (r smt)
G.comment Doc
pyCommentStart
instance ControlStatement PythonCode (Doc, Terminator) where
break :: MS (PythonCode (Doc, Terminator))
break = Doc -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> MS (r smt)
mkStmtNoEnd Doc
R.break
continue :: MS (PythonCode (Doc, Terminator))
continue = Doc -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> MS (r smt)
mkStmtNoEnd Doc
R.continue
returnStmt :: SValue PythonCode -> MS (PythonCode (Doc, Terminator))
returnStmt = Terminator
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(RenderStatement r smt, ValueElim r) =>
Terminator -> SValue r -> MS (r smt)
G.returnStmt Terminator
Empty
throw :: String -> MS (PythonCode (Doc, Terminator))
throw = (PythonCode Value -> Doc)
-> Terminator -> String -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(Literal r, RenderStatement r smt) =>
(r Value -> Doc) -> Terminator -> String -> MS (r smt)
G.throw PythonCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
pyThrow Terminator
Empty
ifCond :: [(SValue PythonCode, MS (PythonCode Doc))]
-> MS (PythonCode Doc) -> MS (PythonCode (Doc, Terminator))
ifCond = (Doc -> Doc)
-> Doc
-> OptionalSpace
-> Doc
-> Doc
-> Doc
-> [(SValue PythonCode, MS (PythonCode Doc))]
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(BodyElim r, RenderStatement r smt, ValueElim r) =>
(Doc -> Doc)
-> Doc
-> OptionalSpace
-> Doc
-> Doc
-> Doc
-> [(SValue r, MS (r Doc))]
-> MS (r Doc)
-> MS (r smt)
G.ifCond Doc -> Doc
forall a. a -> a
id Doc
pyBodyStart OptionalSpace
pySpace Doc
pyElseIf Doc
pyBodyEnd Doc
empty
switch :: SValue PythonCode
-> [(SValue PythonCode, MS (PythonCode Doc))]
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
switch = SValue PythonCode
-> [(SValue PythonCode, MS (PythonCode Doc))]
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(ControlStatement r smt, Comparison r) =>
SValue r -> [(SValue r, MS (r Doc))] -> MS (r Doc) -> MS (r smt)
switchAsIf
ifExists :: SValue PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
ifExists = SValue PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
(ControlStatement r smt, ValueExpression r) =>
SValue r -> MS (r Doc) -> MS (r Doc) -> MS (r smt)
M.ifExists
for :: MS (PythonCode (Doc, Terminator))
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
for MS (PythonCode (Doc, Terminator))
_ SValue PythonCode
_ MS (PythonCode (Doc, Terminator))
_ MS (PythonCode Doc)
_ = String -> MS (PythonCode (Doc, Terminator))
forall a. HasCallStack => String -> a
error (String -> MS (PythonCode (Doc, Terminator)))
-> String -> MS (PythonCode (Doc, Terminator))
forall a b. (a -> b) -> a -> b
$ String -> String
CP.forLoopError String
pyName
forRange :: SVariable PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forRange SVariable PythonCode
i SValue PythonCode
initv SValue PythonCode
finalv SValue PythonCode
stepv = SVariable PythonCode
-> SValue PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
ControlStatement r smt =>
SVariable r -> SValue r -> MS (r Doc) -> MS (r smt)
forEach SVariable PythonCode
i (SValue PythonCode
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
ValueExpression r =>
SValue r -> SValue r -> SValue r -> SValue r
range SValue PythonCode
initv SValue PythonCode
finalv SValue PythonCode
stepv)
forEach :: SVariable PythonCode
-> SValue PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forEach = (PythonCode Variable -> PythonCode Value -> PythonCode Doc -> Doc)
-> SVariable PythonCode
-> SValue PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
(r Variable -> r Value -> r Doc -> Doc)
-> SVariable r -> SValue r -> MS (r Doc) -> MS (r smt)
CS.forEach' PythonCode Variable -> PythonCode Value -> PythonCode Doc -> Doc
forall (r :: * -> *).
(BodyElim r, InternalVarElim r, ValueElim r) =>
r Variable -> r Value -> r Doc -> Doc
pyForEach
while :: SValue PythonCode
-> MS (PythonCode Doc) -> MS (PythonCode (Doc, Terminator))
while SValue PythonCode
v' MS (PythonCode Doc)
b' = do
PythonCode Value
v <- LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Value))
MethodState
ValueState
-> SValue PythonCode
-> StateT MethodState Identity (PythonCode Value)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (PythonCode Value) ValueState)
-> MethodState -> Focusing Identity (PythonCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue PythonCode
v'
PythonCode Doc
b <- MS (PythonCode Doc)
b'
Doc -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> MS (r smt)
mkStmtNoEnd (PythonCode Value -> PythonCode Doc -> Doc
forall (r :: * -> *).
(BodyElim r, ValueElim r) =>
r Value -> r Doc -> Doc
pyWhile PythonCode Value
v PythonCode Doc
b)
tryCatch :: MS (PythonCode Doc)
-> MS (PythonCode Doc) -> MS (PythonCode (Doc, Terminator))
tryCatch = (PythonCode Doc -> PythonCode Doc -> Doc)
-> MS (PythonCode Doc)
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
(r Doc -> r Doc -> Doc) -> MS (r Doc) -> MS (r Doc) -> MS (r smt)
G.tryCatch PythonCode Doc -> PythonCode Doc -> Doc
forall (r :: * -> *). BodyElim r => r Doc -> r Doc -> Doc
pyTryCatch
assert :: SValue PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
assert SValue PythonCode
condition SValue PythonCode
errorMessage = do
PythonCode Value
cond <- LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Value))
MethodState
ValueState
-> SValue PythonCode
-> StateT MethodState Identity (PythonCode Value)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (PythonCode Value) ValueState)
-> MethodState -> Focusing Identity (PythonCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue PythonCode
condition
PythonCode Value
errMsg <- LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Value))
MethodState
ValueState
-> SValue PythonCode
-> StateT MethodState Identity (PythonCode Value)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (PythonCode Value) ValueState)
-> MethodState -> Focusing Identity (PythonCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue PythonCode
errorMessage
Doc -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> MS (r smt)
mkStmtNoEnd (PythonCode Value -> PythonCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> r Value -> Doc
pyAssert PythonCode Value
cond PythonCode Value
errMsg)
instance ObserverPattern PythonCode (Doc, Terminator) where
notifyObservers :: VS (PythonCode FuncData)
-> VS (PythonCode TypeData) -> MS (PythonCode (Doc, Terminator))
notifyObservers = VS (PythonCode FuncData)
-> VS (PythonCode TypeData) -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
OOStatement r smt =>
VS (r FuncData) -> VS (r TypeData) -> MS (r smt)
M.notifyObservers'
instance StrategyPattern PythonCode (Doc, Terminator) where
runStrategy :: String
-> [(String, MS (PythonCode Doc))]
-> Maybe (SValue PythonCode)
-> Maybe (SVariable PythonCode)
-> MS (PythonCode Doc)
runStrategy = String
-> [(String, MS (PythonCode Doc))]
-> Maybe (SValue PythonCode)
-> Maybe (SVariable PythonCode)
-> MS (PythonCode Doc)
forall (r :: * -> *) smt.
(AssignStatement r smt, BodyElim r, Monad r, RenderStatement r smt,
StatementElim r smt) =>
String
-> [(String, MS (r Doc))]
-> Maybe (SValue r)
-> Maybe (SVariable r)
-> MS (r Doc)
M.runStrategy
instance VisibilitySym PythonCode Doc where
private :: PythonCode Doc
private = Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
empty
public :: PythonCode Doc
public = Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
empty
instance RenderVisibility PythonCode Doc where
visibilityFromData :: VisibilityTag -> Doc -> PythonCode Doc
visibilityFromData VisibilityTag
_ = Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode
instance VisibilityElim PythonCode Doc where
visibility :: PythonCode Doc -> Doc
visibility = PythonCode Doc -> Doc
forall a. PythonCode a -> a
unPC
instance MethodTypeSym PythonCode where
mType :: VS (PythonCode TypeData) -> MSMthdType PythonCode
mType = LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode TypeData))
MethodState
ValueState
-> VS (PythonCode TypeData) -> MSMthdType PythonCode
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode TypeData))
MethodState
ValueState
(ValueState -> Focusing Identity (PythonCode TypeData) ValueState)
-> MethodState
-> Focusing Identity (PythonCode TypeData) MethodState
Lens' MethodState ValueState
lensMStoVS
instance OOMethodTypeSym PythonCode where
construct :: String -> MSMthdType PythonCode
construct = String -> MSMthdType PythonCode
forall (r :: * -> *). Monad r => String -> MS (r TypeData)
G.construct
instance ParameterSym PythonCode where
param :: SVariable PythonCode -> MS (PythonCode ParamData)
param = (PythonCode Variable -> Doc)
-> SVariable PythonCode -> MS (PythonCode ParamData)
forall (r :: * -> *).
(RenderParam r, VariableElim r) =>
(r Variable -> Doc) -> SVariable r -> MS (r ParamData)
G.param PythonCode Variable -> Doc
forall (r :: * -> *). InternalVarElim r => r Variable -> Doc
RC.variable
pointerParam :: SVariable PythonCode -> MS (PythonCode ParamData)
pointerParam = SVariable PythonCode -> MS (PythonCode ParamData)
forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MS (r ParamData)
param
instance RenderParam PythonCode where
paramFromData :: SVariable PythonCode -> Doc -> MS (PythonCode ParamData)
paramFromData SVariable PythonCode
v' Doc
d = do
PythonCode Variable
v <- LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Variable))
MethodState
ValueState
-> SVariable PythonCode
-> StateT MethodState Identity (PythonCode Variable)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Variable))
MethodState
ValueState
(ValueState -> Focusing Identity (PythonCode Variable) ValueState)
-> MethodState
-> Focusing Identity (PythonCode Variable) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable PythonCode
v'
PythonCode ParamData -> MS (PythonCode ParamData)
forall a s. a -> State s a
toState (PythonCode ParamData -> MS (PythonCode ParamData))
-> PythonCode ParamData -> MS (PythonCode ParamData)
forall a b. (a -> b) -> a -> b
$ (Variable -> Doc -> ParamData)
-> PythonCode Variable -> PythonCode Doc -> PythonCode ParamData
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues Variable -> Doc -> ParamData
pd PythonCode Variable
v (Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
d)
instance ParamElim PythonCode where
parameterName :: PythonCode ParamData -> String
parameterName = PythonCode Variable -> String
forall (r :: * -> *). VariableElim r => r Variable -> String
variableName (PythonCode Variable -> String)
-> (PythonCode ParamData -> PythonCode Variable)
-> PythonCode ParamData
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ParamData -> Variable)
-> PythonCode ParamData -> PythonCode Variable
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ParamData -> Variable
paramVar
parameterType :: PythonCode ParamData -> PythonCode TypeData
parameterType = PythonCode Variable -> PythonCode TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType (PythonCode Variable -> PythonCode TypeData)
-> (PythonCode ParamData -> PythonCode Variable)
-> PythonCode ParamData
-> PythonCode TypeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ParamData -> Variable)
-> PythonCode ParamData -> PythonCode Variable
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ParamData -> Variable
paramVar
parameter :: PythonCode ParamData -> Doc
parameter = ParamData -> Doc
paramDoc (ParamData -> Doc)
-> (PythonCode ParamData -> ParamData)
-> PythonCode ParamData
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode ParamData -> ParamData
forall a. PythonCode a -> a
unPC
instance MethodSym PythonCode Doc (Doc, Terminator) MethodData where
docMain :: MS (PythonCode Doc) -> MS (PythonCode MethodData)
docMain = MS (PythonCode Doc) -> MS (PythonCode MethodData)
forall (r :: * -> *) vis smt md.
MethodSym r vis smt md =>
MS (r Doc) -> MS (r md)
mainFunction
function :: String
-> PythonCode Doc
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
function = String
-> PythonCode Doc
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
forall (r :: * -> *) att vis md.
(AttachmentSym r att, OORenderMethod r vis md att) =>
String
-> r vis
-> VS (r TypeData)
-> [MS (r ParamData)]
-> MS (r Doc)
-> MS (r md)
G.function
mainFunction :: MS (PythonCode Doc) -> MS (PythonCode MethodData)
mainFunction = MS (PythonCode Doc) -> MS (PythonCode MethodData)
forall (r :: * -> *) md.
(BodyElim r, RenderMethod r md) =>
MS (r Doc) -> MS (r md)
CP.mainBody
docFunc :: String
-> [String]
-> Maybe String
-> MS (PythonCode MethodData)
-> MS (PythonCode MethodData)
docFunc = String
-> [String]
-> Maybe String
-> MS (PythonCode MethodData)
-> MS (PythonCode MethodData)
forall (r :: * -> *) md.
RenderMethod r md =>
String -> [String] -> Maybe String -> MS (r md) -> MS (r md)
CP.doxFunc
inOutFunc :: String -> PythonCode Doc -> InOutFunc PythonCode MethodData
inOutFunc String
n PythonCode Doc
s = (VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData))
-> InOutFunc PythonCode MethodData
forall (r :: * -> *) smt md.
(InternalControlStmt r smt, SharedStatement r smt, RenderBody r,
RenderType r, VariableElim r) =>
(VS (r TypeData) -> [MS (r ParamData)] -> MS (r Doc) -> MS (r md))
-> [SVariable r]
-> [SVariable r]
-> [SVariable r]
-> MS (r Doc)
-> MS (r md)
CP.inOutFunc (String
-> PythonCode Doc
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
forall (r :: * -> *) vis smt md.
MethodSym r vis smt md =>
String
-> r vis
-> VS (r TypeData)
-> [MS (r ParamData)]
-> MS (r Doc)
-> MS (r md)
function String
n PythonCode Doc
s)
docInOutFunc :: String -> PythonCode Doc -> DocInOutFunc PythonCode MethodData
docInOutFunc String
n PythonCode Doc
s = FuncDocRenderer
-> InOutFunc PythonCode MethodData
-> DocInOutFunc PythonCode MethodData
forall (r :: * -> *) md.
RenderMethod r md =>
FuncDocRenderer
-> ([SVariable r]
-> [SVariable r] -> [SVariable r] -> MS (r Doc) -> MS (r md))
-> String
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> MS (r Doc)
-> MS (r md)
CP.docInOutFunc' FuncDocRenderer
functionDox (String -> PythonCode Doc -> InOutFunc PythonCode MethodData
forall (r :: * -> *) vis smt md.
MethodSym r vis smt md =>
String -> r vis -> InOutFunc r md
inOutFunc String
n PythonCode Doc
s)
instance OOMethodSym PythonCode Doc (Doc, Terminator) MethodData AttachmentData where
method :: String
-> PythonCode Doc
-> PythonCode AttachmentData
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
method = String
-> PythonCode Doc
-> PythonCode AttachmentData
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
forall (r :: * -> *) vis md att.
OORenderMethod r vis md att =>
String
-> r vis
-> r att
-> VS (r TypeData)
-> [MS (r ParamData)]
-> MS (r Doc)
-> MS (r md)
G.method
getMethod :: SVariable PythonCode -> MS (PythonCode MethodData)
getMethod = SVariable PythonCode -> MS (PythonCode MethodData)
forall (r :: * -> *) vis smt md svr att.
OORenderSym r vis smt md svr att =>
SVariable r -> MS (r md)
G.getMethod
setMethod :: SVariable PythonCode -> MS (PythonCode MethodData)
setMethod = SVariable PythonCode -> MS (PythonCode MethodData)
forall (r :: * -> *) vis smt md svr att.
OORenderSym r vis smt md svr att =>
SVariable r -> MS (r md)
G.setMethod
constructor :: [MS (PythonCode ParamData)]
-> NamedArgs PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
constructor = String
-> [MS (PythonCode ParamData)]
-> NamedArgs PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
forall (r :: * -> *) vis smt md svr att.
(OORenderSym r vis smt md svr att, OOStatement r smt) =>
String
-> [MS (r ParamData)] -> Initializers r -> MS (r Doc) -> MS (r md)
CP.constructor String
initName
inOutMethod :: String
-> PythonCode Doc
-> PythonCode AttachmentData
-> InOutFunc PythonCode MethodData
inOutMethod String
n PythonCode Doc
s PythonCode AttachmentData
p = (VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData))
-> InOutFunc PythonCode MethodData
forall (r :: * -> *) smt md.
(InternalControlStmt r smt, SharedStatement r smt, RenderBody r,
RenderType r, VariableElim r) =>
(VS (r TypeData) -> [MS (r ParamData)] -> MS (r Doc) -> MS (r md))
-> [SVariable r]
-> [SVariable r]
-> [SVariable r]
-> MS (r Doc)
-> MS (r md)
CP.inOutFunc (String
-> PythonCode Doc
-> PythonCode AttachmentData
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
forall (r :: * -> *) vis smt md att.
OOMethodSym r vis smt md att =>
String
-> r vis
-> r att
-> VS (r TypeData)
-> [MS (r ParamData)]
-> MS (r Doc)
-> MS (r md)
method String
n PythonCode Doc
s PythonCode AttachmentData
p)
docInOutMethod :: String
-> PythonCode Doc
-> PythonCode AttachmentData
-> DocInOutFunc PythonCode MethodData
docInOutMethod String
n PythonCode Doc
s PythonCode AttachmentData
p = FuncDocRenderer
-> InOutFunc PythonCode MethodData
-> DocInOutFunc PythonCode MethodData
forall (r :: * -> *) md.
RenderMethod r md =>
FuncDocRenderer
-> ([SVariable r]
-> [SVariable r] -> [SVariable r] -> MS (r Doc) -> MS (r md))
-> String
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> MS (r Doc)
-> MS (r md)
CP.docInOutFunc' FuncDocRenderer
functionDox (String
-> PythonCode Doc
-> PythonCode AttachmentData
-> InOutFunc PythonCode MethodData
forall (r :: * -> *) vis smt md att.
OOMethodSym r vis smt md att =>
String -> r vis -> r att -> InOutFunc r md
inOutMethod String
n PythonCode Doc
s PythonCode AttachmentData
p)
instance RenderMethod PythonCode MethodData where
commentedFunc :: MS (PythonCode Doc)
-> MS (PythonCode MethodData) -> MS (PythonCode MethodData)
commentedFunc MS (PythonCode Doc)
cmt MS (PythonCode MethodData)
m = (PythonCode MethodData
-> PythonCode (Doc -> Doc) -> PythonCode MethodData)
-> MS (PythonCode MethodData)
-> State MethodState (PythonCode (Doc -> Doc))
-> MS (PythonCode MethodData)
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues ((MethodData -> (Doc -> Doc) -> MethodData)
-> PythonCode MethodData
-> PythonCode (Doc -> Doc)
-> PythonCode MethodData
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues MethodData -> (Doc -> Doc) -> MethodData
updateMthd) MS (PythonCode MethodData)
m
((PythonCode Doc -> PythonCode (Doc -> Doc))
-> MS (PythonCode Doc)
-> State MethodState (PythonCode (Doc -> Doc))
forall a b s. (a -> b) -> State s a -> State s b
onStateValue ((Doc -> Doc -> Doc) -> PythonCode Doc -> PythonCode (Doc -> Doc)
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue Doc -> Doc -> Doc
R.commentedItem) MS (PythonCode Doc)
cmt)
mthdFromData :: VisibilityTag -> Doc -> MS (PythonCode MethodData)
mthdFromData VisibilityTag
_ Doc
d = PythonCode MethodData -> MS (PythonCode MethodData)
forall a s. a -> State s a
toState (PythonCode MethodData -> MS (PythonCode MethodData))
-> PythonCode MethodData -> MS (PythonCode MethodData)
forall a b. (a -> b) -> a -> b
$ MethodData -> PythonCode MethodData
forall (r :: * -> *) a. Monad r => a -> r a
toCode (MethodData -> PythonCode MethodData)
-> MethodData -> PythonCode MethodData
forall a b. (a -> b) -> a -> b
$ Doc -> MethodData
mthd Doc
d
instance OORenderMethod PythonCode Doc MethodData AttachmentData where
intMethod :: Bool
-> String
-> PythonCode Doc
-> PythonCode AttachmentData
-> MSMthdType PythonCode
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
intMethod Bool
m String
n PythonCode Doc
_ PythonCode AttachmentData
a MSMthdType PythonCode
_ [MS (PythonCode ParamData)]
ps MS (PythonCode Doc)
b = do
(MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (if Bool
m then MethodState -> MethodState
setCurrMain else MethodState -> MethodState
forall a. a -> a
id)
PythonCode Variable
sl <- LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Variable))
MethodState
ValueState
-> SVariable PythonCode
-> StateT MethodState Identity (PythonCode Variable)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Variable))
MethodState
ValueState
(ValueState -> Focusing Identity (PythonCode Variable) ValueState)
-> MethodState
-> Focusing Identity (PythonCode Variable) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable PythonCode
forall (r :: * -> *). SelfSym r => SVariable r
self
[PythonCode ParamData]
pms <- [MS (PythonCode ParamData)]
-> StateT MethodState Identity [PythonCode ParamData]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence [MS (PythonCode ParamData)]
ps
MethodData -> PythonCode MethodData
forall (r :: * -> *) a. Monad r => a -> r a
toCode (MethodData -> PythonCode MethodData)
-> (PythonCode Doc -> MethodData)
-> PythonCode Doc
-> PythonCode MethodData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> MethodData
mthd (Doc -> MethodData)
-> (PythonCode Doc -> Doc) -> PythonCode Doc -> MethodData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String
-> PythonCode AttachmentData
-> PythonCode Variable
-> [PythonCode ParamData]
-> PythonCode Doc
-> Doc
pyMethod String
n PythonCode AttachmentData
a PythonCode Variable
sl [PythonCode ParamData]
pms (PythonCode Doc -> PythonCode MethodData)
-> MS (PythonCode Doc) -> MS (PythonCode MethodData)
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
<$> MS (PythonCode Doc)
b
intFunc :: Bool
-> String
-> PythonCode Doc
-> PythonCode AttachmentData
-> MSMthdType PythonCode
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
intFunc Bool
m String
n PythonCode Doc
_ PythonCode AttachmentData
_ MSMthdType PythonCode
_ [MS (PythonCode ParamData)]
ps MS (PythonCode Doc)
b = do
(MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (if Bool
m then MethodState -> MethodState
setCurrMain else MethodState -> MethodState
forall a. a -> a
id)
PythonCode Doc
bd <- MS (PythonCode Doc)
b
[PythonCode ParamData]
pms <- [MS (PythonCode ParamData)]
-> StateT MethodState Identity [PythonCode ParamData]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence [MS (PythonCode ParamData)]
ps
PythonCode MethodData -> MS (PythonCode MethodData)
forall a. a -> StateT MethodState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PythonCode MethodData -> MS (PythonCode MethodData))
-> PythonCode MethodData -> MS (PythonCode MethodData)
forall a b. (a -> b) -> a -> b
$ MethodData -> PythonCode MethodData
forall (r :: * -> *) a. Monad r => a -> r a
toCode (MethodData -> PythonCode MethodData)
-> MethodData -> PythonCode MethodData
forall a b. (a -> b) -> a -> b
$ Doc -> MethodData
mthd (Doc -> MethodData) -> Doc -> MethodData
forall a b. (a -> b) -> a -> b
$ String -> [PythonCode ParamData] -> PythonCode Doc -> Doc
forall (r :: * -> *).
(BodyElim r, ParamElim r) =>
String -> [r ParamData] -> r Doc -> Doc
pyFunction String
n [PythonCode ParamData]
pms PythonCode Doc
bd
destructor :: forall svr.
[CSStateVar PythonCode svr] -> MS (PythonCode MethodData)
destructor [CSStateVar PythonCode svr]
_ = String -> MS (PythonCode MethodData)
forall a. HasCallStack => String -> a
error (String -> MS (PythonCode MethodData))
-> String -> MS (PythonCode MethodData)
forall a b. (a -> b) -> a -> b
$ String -> String
CP.destructorError String
pyName
instance MethodElim PythonCode MethodData where
method :: PythonCode MethodData -> Doc
method = MethodData -> Doc
mthdDoc (MethodData -> Doc)
-> (PythonCode MethodData -> MethodData)
-> PythonCode MethodData
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode MethodData -> MethodData
forall a. PythonCode a -> a
unPC
instance StateVarSym PythonCode Doc Doc AttachmentData where
stateVar :: PythonCode Doc
-> PythonCode AttachmentData
-> SVariable PythonCode
-> CSStateVar PythonCode Doc
stateVar PythonCode Doc
_ PythonCode AttachmentData
_ SVariable PythonCode
_ = PythonCode Doc -> CSStateVar PythonCode Doc
forall a s. a -> State s a
toState (Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
empty)
stateVarDef :: PythonCode Doc
-> PythonCode AttachmentData
-> SVariable PythonCode
-> SValue PythonCode
-> CSStateVar PythonCode Doc
stateVarDef = PythonCode Doc
-> PythonCode AttachmentData
-> SVariable PythonCode
-> SValue PythonCode
-> CSStateVar PythonCode Doc
forall (r :: * -> *) vis smt md svr att.
(OORenderSym r vis smt md svr att, Monad r) =>
r vis -> r att -> SVariable r -> SValue r -> CS (r Doc)
CP.stateVarDef
constVar :: PythonCode Doc
-> SVariable PythonCode
-> SValue PythonCode
-> CSStateVar PythonCode Doc
constVar = Doc
-> PythonCode Doc
-> SVariable PythonCode
-> SValue PythonCode
-> CSStateVar PythonCode Doc
forall (r :: * -> *) vis smt md.
(CommonRenderSym r vis smt md, Monad r) =>
Doc -> r vis -> SVariable r -> SValue r -> CS (r Doc)
CP.constVar (PythonCode AttachmentData -> Doc
forall (r :: * -> *) att. PermElim r att => r att -> Doc
RC.perm
(PythonCode AttachmentData
forall (r :: * -> *) att. AttachmentSym r att => r att
classLevel :: PythonCode AttachmentData))
instance StateVarElim PythonCode StateVar where
stateVar :: PythonCode Doc -> Doc
stateVar = PythonCode Doc -> Doc
forall a. PythonCode a -> a
unPC
instance ClassSym PythonCode Doc (Doc, Terminator) MethodData StateVar AttachmentData where
buildClass :: Maybe String
-> [CSStateVar PythonCode Doc]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Doc
buildClass Maybe String
par [CSStateVar PythonCode Doc]
sVars [MS (PythonCode MethodData)]
cstrs = if [MS (PythonCode MethodData)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [MS (PythonCode MethodData)]
cstrs Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
1
then Maybe String
-> [CSStateVar PythonCode Doc]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Doc
forall (r :: * -> *) vis md svr.
(RenderClass r vis md svr, VisibilitySym r vis) =>
Maybe String
-> [CSStateVar r svr] -> [MS (r md)] -> [MS (r md)] -> CS (r Doc)
G.buildClass Maybe String
par [CSStateVar PythonCode Doc]
sVars [MS (PythonCode MethodData)]
cstrs
else String -> [MS (PythonCode MethodData)] -> CSStateVar PythonCode Doc
forall a. HasCallStack => String -> a
error String
pyMultCstrsError
extraClass :: String
-> Maybe String
-> [CSStateVar PythonCode Doc]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Doc
extraClass String
n Maybe String
par [CSStateVar PythonCode Doc]
sVars [MS (PythonCode MethodData)]
cstrs = if
[MS (PythonCode MethodData)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [MS (PythonCode MethodData)]
cstrs Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
1
then String
-> Maybe String
-> [CSStateVar PythonCode Doc]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Doc
forall (r :: * -> *) vis md svr.
(RenderClass r vis md svr, VisibilitySym r vis) =>
String
-> Maybe String
-> [CSStateVar r svr]
-> [MS (r md)]
-> [MS (r md)]
-> CS (r Doc)
CP.extraClass String
n Maybe String
par [CSStateVar PythonCode Doc]
sVars [MS (PythonCode MethodData)]
cstrs
else String -> [MS (PythonCode MethodData)] -> CSStateVar PythonCode Doc
forall a. HasCallStack => String -> a
error String
pyMultCstrsError
implementingClass :: String
-> [String]
-> [CSStateVar PythonCode Doc]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Doc
implementingClass String
n [String]
iNms [CSStateVar PythonCode Doc]
sVars [MS (PythonCode MethodData)]
cstrs = if
[MS (PythonCode MethodData)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [MS (PythonCode MethodData)]
cstrs Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
1
then String
-> [String]
-> [CSStateVar PythonCode Doc]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Doc
forall (r :: * -> *) vis md svr.
(RenderClass r vis md svr, VisibilitySym r vis) =>
String
-> [String]
-> [CSStateVar r svr]
-> [MS (r md)]
-> [MS (r md)]
-> CS (r Doc)
G.implementingClass String
n [String]
iNms [CSStateVar PythonCode Doc]
sVars [MS (PythonCode MethodData)]
cstrs
else String -> [MS (PythonCode MethodData)] -> CSStateVar PythonCode Doc
forall a. HasCallStack => String -> a
error String
pyMultCstrsError
docClass :: String -> CSStateVar PythonCode Doc -> CSStateVar PythonCode Doc
docClass = String -> CSStateVar PythonCode Doc -> CSStateVar PythonCode Doc
forall (r :: * -> *) vis md svr.
RenderClass r vis md svr =>
String -> CS (r Doc) -> CS (r Doc)
CP.doxClass
instance RenderClass PythonCode Doc MethodData StateVar where
intClass :: String
-> PythonCode Doc
-> PythonCode Doc
-> [CSStateVar PythonCode Doc]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Doc
intClass = (String -> Doc -> Doc -> Doc -> Doc -> Doc)
-> String
-> PythonCode Doc
-> PythonCode Doc
-> [CSStateVar PythonCode Doc]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Doc
forall (r :: * -> *) md svr vis.
(MethodElim r md, Monad r, StateVarElim r svr,
VisibilityElim r vis) =>
(String -> Doc -> Doc -> Doc -> Doc -> Doc)
-> String
-> r vis
-> r Doc
-> [CSStateVar r svr]
-> [MS (r md)]
-> [MS (r md)]
-> CS (r Doc)
CP.intClass String -> Doc -> Doc -> Doc -> Doc -> Doc
pyClass
inherit :: Maybe String -> PythonCode Doc
inherit Maybe String
n = Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> PythonCode Doc) -> Doc -> PythonCode Doc
forall a b. (a -> b) -> a -> b
$ Doc -> (String -> Doc) -> Maybe String -> Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
empty (Doc -> Doc
parens (Doc -> Doc) -> (String -> Doc) -> String -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc
text) Maybe String
n
implements :: [String] -> PythonCode Doc
implements [String]
is = Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> PythonCode Doc) -> Doc -> PythonCode Doc
forall a b. (a -> b) -> a -> b
$ Doc -> Doc
parens (String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
listSep [String]
is)
commentedClass :: CSStateVar PythonCode Doc
-> CSStateVar PythonCode Doc -> CSStateVar PythonCode Doc
commentedClass = CSStateVar PythonCode Doc
-> CSStateVar PythonCode Doc -> CSStateVar PythonCode Doc
forall (r :: * -> *).
(BlockCommentElim r, ClassElim r, Monad r) =>
CS (r Doc) -> CS (r Doc) -> CS (r Doc)
G.commentedClass
instance ClassElim PythonCode where
class' :: PythonCode Doc -> Doc
class' = PythonCode Doc -> Doc
forall a. PythonCode a -> a
unPC
instance ModuleSym PythonCode Doc (Doc, Terminator) MethodData StateVar AttachmentData where
buildModule :: String
-> [String]
-> [MS (PythonCode MethodData)]
-> [CSStateVar PythonCode Doc]
-> FS (PythonCode Module)
buildModule String
n [String]
is = String
-> FS Doc
-> FS Doc
-> FS Doc
-> [MS (PythonCode MethodData)]
-> [CSStateVar PythonCode Doc]
-> FS (PythonCode Module)
forall (r :: * -> *) md.
(ClassElim r, MethodElim r md, RenderMod r) =>
String
-> FS Doc
-> FS Doc
-> FS Doc
-> [MS (r md)]
-> [CS (r Doc)]
-> FS (r Module)
CP.buildModule String
n (do
[String]
lis <- FS [String]
getLangImports
[String]
libis <- FS [String]
getLibImports
[String]
mis <- FS [String]
getModuleImports
Doc -> FS Doc
forall a. a -> StateT FileState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Doc -> FS Doc) -> Doc -> FS Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vibcat [
[Doc] -> Doc
vcat ((String -> Doc) -> [String] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (PythonCode Doc -> Doc
forall (r :: * -> *). UnRepr r Doc => r Doc -> Doc
RC.import' (PythonCode Doc -> Doc)
-> (String -> PythonCode Doc) -> String -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(String -> PythonCode Doc
forall (r :: * -> *). ImportSym r => String -> r Doc
langImport :: Label -> PythonCode Doc)) [String]
lis),
[Doc] -> Doc
vcat ((String -> Doc) -> [String] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (PythonCode Doc -> Doc
forall (r :: * -> *). UnRepr r Doc => r Doc -> Doc
RC.import' (PythonCode Doc -> Doc)
-> (String -> PythonCode Doc) -> String -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(String -> PythonCode Doc
forall (r :: * -> *). ImportSym r => String -> r Doc
langImport :: Label -> PythonCode Doc)) ([String] -> [String]
forall a. Ord a => [a] -> [a]
sort ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ [String]
is [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++
[String]
libis)),
[Doc] -> Doc
vcat ((String -> Doc) -> [String] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (PythonCode Doc -> Doc
forall (r :: * -> *). UnRepr r Doc => r Doc -> Doc
RC.import' (PythonCode Doc -> Doc)
-> (String -> PythonCode Doc) -> String -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(String -> PythonCode Doc
forall (r :: * -> *). ImportSym r => String -> r Doc
modImport :: Label -> PythonCode Doc)) [String]
mis)])
(Doc -> FS Doc
forall a. a -> StateT FileState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Doc
empty) FS Doc
getMainDoc
instance RenderMod PythonCode where
modFromData :: String -> FS Doc -> FS (PythonCode Module)
modFromData String
n = String
-> (Doc -> PythonCode Module) -> FS Doc -> FS (PythonCode Module)
forall (r :: * -> *).
String -> (Doc -> r Module) -> FS Doc -> FS (r Module)
G.modFromData String
n (Module -> PythonCode Module
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Module -> PythonCode Module)
-> (Doc -> Module) -> Doc -> PythonCode Module
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc -> Module
md String
n)
updateModuleDoc :: (Doc -> Doc) -> PythonCode Module -> PythonCode Module
updateModuleDoc Doc -> Doc
f = (Module -> Module) -> PythonCode Module -> PythonCode Module
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ((Doc -> Doc) -> Module -> Module
updateMod Doc -> Doc
f)
instance ModuleElim PythonCode where
module' :: PythonCode Module -> Doc
module' = Module -> Doc
modDoc (Module -> Doc)
-> (PythonCode Module -> Module) -> PythonCode Module -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Module -> Module
forall a. PythonCode a -> a
unPC
instance BlockCommentSym PythonCode where
blockComment :: [String] -> PythonCode Doc
blockComment [String]
lns = Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> PythonCode Doc) -> Doc -> PythonCode Doc
forall a b. (a -> b) -> a -> b
$ [String] -> Doc -> Doc
pyBlockComment [String]
lns Doc
pyCommentStart
docComment :: forall a. State a [String] -> State a (PythonCode Doc)
docComment = ([String] -> PythonCode Doc)
-> State a [String] -> State a (PythonCode Doc)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue (\[String]
lns -> Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> PythonCode Doc) -> Doc -> PythonCode Doc
forall a b. (a -> b) -> a -> b
$ [String] -> Doc -> Doc -> Doc
pyDocComment [String]
lns Doc
pyDocCommentStart
Doc
pyCommentStart)
instance BlockCommentElim PythonCode where
blockComment' :: PythonCode Doc -> Doc
blockComment' = PythonCode Doc -> Doc
forall a. PythonCode a -> a
unPC
initName :: Label
initName :: String
initName = String
"__init__"
pyName, pyVersion :: String
pyName :: String
pyName = String
"Python"
pyVersion :: String
pyVersion = String
"3.5.1"
pyInt, pyDouble, pyString, pyVoid :: String
pyInt :: String
pyInt = String
"int"
pyDouble :: String
pyDouble = String
"float"
pyString :: String
pyString = String
"str"
pyVoid :: String
pyVoid = String
"NoneType"
pyFloatError :: String
pyFloatError :: String
pyFloatError = String
"Floats unavailable in Python, use Doubles instead"
pyPower, pyAnd, pyOr, pyIntDiv :: String
pyPower :: String
pyPower = String
"**"
pyAnd :: String
pyAnd = String
"and"
pyOr :: String
pyOr = String
"or"
pyIntDiv :: String
pyIntDiv = String
"//"
pySelf, pyNull :: String
pySelf :: String
pySelf = String
"self"
pyNull :: String
pyNull = String
"None"
pyNull' :: Doc
pyNull' :: Doc
pyNull' = String -> Doc
text String
pyNull
pyTrue, pyFalse :: Doc
pyTrue :: Doc
pyTrue = String -> Doc
text String
"True"
pyFalse :: Doc
pyFalse = String -> Doc
text String
"False"
pyPi :: Doc
pyPi :: Doc
pyPi = String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ String
pyMath String -> String -> String
`access` String
piLabel
pySys :: String
pySys :: String
pySys = String
"sys"
pyInputFunc, pyPrintFunc :: Doc
pyInputFunc :: Doc
pyInputFunc = String -> Doc
text String
"input()"
pyPrintFunc :: Doc
pyPrintFunc = String -> Doc
text String
printLabel
pyListSize, pyIndex, pyInsert, pyAppendFunc, pyReadline, pyReadlines, pyClose,
pySplit, pyRange, pyRstrip, pyMath, pyIn, pyAdd, pyRemove, pyUnion :: String
pyListSize :: String
pyListSize = String
"len"
pyIndex :: String
pyIndex = String
"index"
pyInsert :: String
pyInsert = String
"insert"
pyAppendFunc :: String
pyAppendFunc = String
"append"
pyReadline :: String
pyReadline = String
"readline"
pyReadlines :: String
pyReadlines = String
"readlines"
pyClose :: String
pyClose = String
"close"
pySplit :: String
pySplit = String
"split"
pyRange :: String
pyRange = String
"range"
pyRstrip :: String
pyRstrip = String
"rstrip"
pyMath :: String
pyMath = String
"math"
pyIn :: String
pyIn = String
"in"
pyAdd :: String
pyAdd = String
"add"
pyRemove :: String
pyRemove = String
"remove"
pyUnion :: String
pyUnion = String
"union"
pyDef, pyLambdaDec, pyElseIf, pyRaise, pyExcept :: Doc
pyDef :: Doc
pyDef = String -> Doc
text String
"def"
pyLambdaDec :: Doc
pyLambdaDec = String -> Doc
text String
"lambda"
pyElseIf :: Doc
pyElseIf = String -> Doc
text String
"elif"
pyRaise :: Doc
pyRaise = String -> Doc
text String
"raise"
pyExcept :: Doc
pyExcept = String -> Doc
text String
"except"
pyBodyStart, pyBodyEnd, pyCommentStart, pyDocCommentStart, pyNamedArgSep :: Doc
pyBodyStart :: Doc
pyBodyStart = Doc
colon
pyBodyEnd :: Doc
pyBodyEnd = Doc
empty
= String -> Doc
text String
"#"
= Doc
pyCommentStart Doc -> Doc -> Doc
<> Doc
pyCommentStart
pyNamedArgSep :: Doc
pyNamedArgSep = Doc
equals
pySpace :: OptionalSpace
pySpace :: OptionalSpace
pySpace = OSpace {oSpace :: Doc
oSpace = Doc
empty}
pyNotOp :: (Monad r) => VSOp r
pyNotOp :: forall (r :: * -> *). Monad r => VSOp r
pyNotOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
"not"
pySqrtOp :: (Monad r) => VSOp r
pySqrtOp :: forall (r :: * -> *). Monad r => VSOp r
pySqrtOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.sqrt
pyAbsOp :: (Monad r) => VSOp r
pyAbsOp :: forall (r :: * -> *). Monad r => VSOp r
pyAbsOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.fabs
pyLogOp :: (Monad r) => VSOp r
pyLogOp :: forall (r :: * -> *). Monad r => VSOp r
pyLogOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.log10
pyLnOp :: (Monad r) => VSOp r
pyLnOp :: forall (r :: * -> *). Monad r => VSOp r
pyLnOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.log
pyExpOp :: (Monad r) => VSOp r
pyExpOp :: forall (r :: * -> *). Monad r => VSOp r
pyExpOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.exp
pySinOp :: (Monad r) => VSOp r
pySinOp :: forall (r :: * -> *). Monad r => VSOp r
pySinOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.sin
pyCosOp :: (Monad r) => VSOp r
pyCosOp :: forall (r :: * -> *). Monad r => VSOp r
pyCosOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.cos
pyTanOp :: (Monad r) => VSOp r
pyTanOp :: forall (r :: * -> *). Monad r => VSOp r
pyTanOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.tan
pyAsinOp :: (Monad r) => VSOp r
pyAsinOp :: forall (r :: * -> *). Monad r => VSOp r
pyAsinOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.asin
pyAcosOp :: (Monad r) => VSOp r
pyAcosOp :: forall (r :: * -> *). Monad r => VSOp r
pyAcosOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.acos
pyAtanOp :: (Monad r) => VSOp r
pyAtanOp :: forall (r :: * -> *). Monad r => VSOp r
pyAtanOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.atan
pyFloorOp :: (Monad r) => VSOp r
pyFloorOp :: forall (r :: * -> *). Monad r => VSOp r
pyFloorOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.floor
pyCeilOp :: (Monad r) => VSOp r
pyCeilOp :: forall (r :: * -> *). Monad r => VSOp r
pyCeilOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.ceil
addmathImport :: VS a -> VS a
addmathImport :: forall a. VS a -> VS a
addmathImport = StateT ValueState Identity ()
-> StateT ValueState Identity a -> StateT ValueState Identity a
forall a b.
StateT ValueState Identity a
-> StateT ValueState Identity b -> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
(>>) (StateT ValueState Identity ()
-> StateT ValueState Identity a -> StateT ValueState Identity a)
-> StateT ValueState Identity ()
-> StateT ValueState Identity a
-> StateT ValueState Identity a
forall a b. (a -> b) -> a -> b
$ (ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addLangImportVS String
pyMath)
mathFunc :: (Monad r) => String -> VSOp r
mathFunc :: forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc = VS (r OpData) -> VS (r OpData)
forall a. VS a -> VS a
addmathImport (VS (r OpData) -> VS (r OpData))
-> (String -> VS (r OpData)) -> String -> VS (r OpData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> VS (r OpData)
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec (String -> VS (r OpData))
-> (String -> String) -> String -> VS (r OpData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String -> String
access String
pyMath
splitFunc :: (Literal r, OOFunctionSym r) => Char -> VS (r FuncData)
splitFunc :: forall (r :: * -> *).
(Literal r, OOFunctionSym r) =>
Char -> VS (r FuncData)
splitFunc Char
d = String -> VS (r TypeData) -> [SValue r] -> VS (r FuncData)
forall (r :: * -> *).
OOFunctionSym r =>
String -> VS (r TypeData) -> [SValue r] -> VS (r FuncData)
func String
pySplit (VS (r TypeData) -> VS (r TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string) [String -> SValue r
forall (r :: * -> *). Literal r => String -> SValue r
litString [Char
d]]
readline, readlines :: (InternalValueExp r) => SValue r -> SValue r
readline :: forall (r :: * -> *). InternalValueExp r => SValue r -> SValue r
readline SValue r
f = VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
objMethodCall VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string SValue r
f String
pyReadline []
readlines :: forall (r :: * -> *). InternalValueExp r => SValue r -> SValue r
readlines SValue r
f = VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
objMethodCall (VS (r TypeData) -> VS (r TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string) SValue r
f String
pyReadlines []
readInt, readDouble :: (ValueExpression r) => SValue r -> SValue r
readInt :: forall (r :: * -> *). ValueExpression r => SValue r -> SValue r
readInt SValue r
inSrc = PosCall r
forall (r :: * -> *). ValueExpression r => PosCall r
funcApp String
pyInt VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
int [SValue r
inSrc]
readDouble :: forall (r :: * -> *). ValueExpression r => SValue r -> SValue r
readDouble SValue r
inSrc = PosCall r
forall (r :: * -> *). ValueExpression r => PosCall r
funcApp String
pyDouble VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
double [SValue r
inSrc]
readString :: (InternalValueExp r) => SValue r -> SValue r
readString :: forall (r :: * -> *). InternalValueExp r => SValue r -> SValue r
readString SValue r
inSrc = VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
objMethodCall VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string SValue r
inSrc String
pyRstrip []
range :: (ValueExpression r) => SValue r -> SValue r -> SValue r -> SValue r
range :: forall (r :: * -> *).
ValueExpression r =>
SValue r -> SValue r -> SValue r -> SValue r
range SValue r
initv SValue r
finalv SValue r
stepv = PosCall r
forall (r :: * -> *). ValueExpression r => PosCall r
funcApp String
pyRange (VS (r TypeData) -> VS (r TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
int) [SValue r
initv, SValue r
finalv, SValue r
stepv]
pyClassVarAccess :: Doc -> Doc -> Doc
pyClassVarAccess :: Doc -> Doc -> Doc
pyClassVarAccess Doc
c Doc
v = Doc
c Doc -> Doc -> Doc
<> Doc
dot Doc -> Doc -> Doc
<> Doc
c Doc -> Doc -> Doc
<> Doc
dot Doc -> Doc -> Doc
<> Doc
v
pyInlineIf
:: (RenderValue r, ValueElim r, ValueSym r)
=> SValue r -> SValue r -> SValue r -> SValue r
pyInlineIf :: forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r -> SValue r -> SValue r
pyInlineIf SValue r
c' SValue r
v1' SValue r
v2' = do
r Value
c <- SValue r
c'
r Value
v1 <- SValue r
v1'
r Value
v2 <- SValue r
v2'
Maybe Int -> Maybe Integer -> VS (r TypeData) -> Doc -> SValue r
forall (r :: * -> *).
RenderValue r =>
Maybe Int -> Maybe Integer -> VS (r TypeData) -> Doc -> SValue r
valFromData (r Value -> Maybe Int
forall (r :: * -> *). ValueElim r => r Value -> Maybe Int
valuePrec r Value
c) (r Value -> Maybe Integer
forall (r :: * -> *). ValueElim r => r Value -> Maybe Integer
valueInt r Value
c) (r TypeData -> VS (r TypeData)
forall a s. a -> State s a
toState (r TypeData -> VS (r TypeData)) -> r TypeData -> VS (r TypeData)
forall a b. (a -> b) -> a -> b
$ r Value -> r TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType r Value
v1)
(r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
v1 Doc -> Doc -> Doc
<+> Doc
ifLabel Doc -> Doc -> Doc
<+> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
c Doc -> Doc -> Doc
<+> Doc
elseLabel Doc -> Doc -> Doc
<+> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
v2)
pyLambda
:: (InternalBinderElim r, ValueElim r)
=> [r BinderD] -> r Value -> Doc
pyLambda :: forall (r :: * -> *).
(InternalBinderElim r, ValueElim r) =>
[r BinderD] -> r Value -> Doc
pyLambda [r BinderD]
ps r Value
ex = Doc
pyLambdaDec Doc -> Doc -> Doc
<+> [r BinderD] -> Doc
forall (r :: * -> *). InternalBinderElim r => [r BinderD] -> Doc
binderList [r BinderD]
ps Doc -> Doc -> Doc
<> Doc
colon Doc -> Doc -> Doc
<+> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
ex
pyStringType :: (Monad r) => VS (r TypeData)
pyStringType :: forall (r :: * -> *). Monad r => VS (r TypeData)
pyStringType = CodeType -> String -> Doc -> VS (r TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
String String
pyString (String -> Doc
text String
pyString)
pyExtNewObjMixedArgs
:: (RenderValue r, UnRepr r TypeData)
=> Library -> MixedCtorCall r
pyExtNewObjMixedArgs :: forall (r :: * -> *).
(RenderValue r, UnRepr r TypeData) =>
String -> MixedCtorCall r
pyExtNewObjMixedArgs String
l VS (r TypeData)
tp [SValue r]
vs NamedArgs r
ns = VS (r TypeData)
tp VS (r TypeData) -> (r TypeData -> SValue r) -> SValue r
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\r TypeData
t -> Maybe String -> Maybe Doc -> MixedCall r
forall (r :: * -> *).
RenderValue r =>
Maybe String -> Maybe Doc -> MixedCall r
call (String -> Maybe String
forall a. a -> Maybe a
Just String
l) Maybe Doc
forall a. Maybe a
Nothing
(r TypeData -> String
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> String
getTypeString r TypeData
t) (r TypeData -> VS (r TypeData)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure r TypeData
t) [SValue r]
vs NamedArgs r
ns)
pyPrint :: Bool -> Maybe (SValue PythonCode) -> SValue PythonCode ->
SValue PythonCode -> MS (PythonCode (Doc, Terminator))
pyPrint :: Bool
-> Maybe (SValue PythonCode)
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
pyPrint Bool
newLn Maybe (SValue PythonCode)
f' SValue PythonCode
p' SValue PythonCode
v' = do
PythonCode Value
f <- LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Value))
MethodState
ValueState
-> SValue PythonCode
-> StateT MethodState Identity (PythonCode Value)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (PythonCode Value) ValueState)
-> MethodState -> Focusing Identity (PythonCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS (SValue PythonCode
-> StateT MethodState Identity (PythonCode Value))
-> SValue PythonCode
-> StateT MethodState Identity (PythonCode Value)
forall a b. (a -> b) -> a -> b
$ SValue PythonCode -> Maybe (SValue PythonCode) -> SValue PythonCode
forall a. a -> Maybe a -> a
fromMaybe (VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
empty) Maybe (SValue PythonCode)
f'
PythonCode Value
prf <- LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Value))
MethodState
ValueState
-> SValue PythonCode
-> StateT MethodState Identity (PythonCode Value)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (PythonCode Value) ValueState)
-> MethodState -> Focusing Identity (PythonCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue PythonCode
p'
PythonCode Value
v <- LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Value))
MethodState
ValueState
-> SValue PythonCode
-> StateT MethodState Identity (PythonCode Value)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (PythonCode Value) ValueState)
-> MethodState -> Focusing Identity (PythonCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue PythonCode
v'
PythonCode Value
s <- LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Value))
MethodState
ValueState
-> SValue PythonCode
-> StateT MethodState Identity (PythonCode Value)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (PythonCode Value))
MethodState
ValueState
(ValueState -> Focusing Identity (PythonCode Value) ValueState)
-> MethodState -> Focusing Identity (PythonCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS (String -> SValue PythonCode
forall (r :: * -> *). Literal r => String -> SValue r
litString String
"" :: SValue PythonCode)
let nl :: Doc
nl = if Bool
newLn then Doc
empty else Doc
listSep' Doc -> Doc -> Doc
<> String -> Doc
text String
"end" Doc -> Doc -> Doc
<> Doc
equals Doc -> Doc -> Doc
<>
PythonCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value PythonCode Value
s
fl :: Doc
fl = Doc -> Doc -> Doc
emptyIfEmpty (PythonCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value PythonCode Value
f) (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ Doc
listSep' Doc -> Doc -> Doc
<> String -> Doc
text String
"file" Doc -> Doc -> Doc
<> Doc
equals
Doc -> Doc -> Doc
<> PythonCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value PythonCode Value
f
Doc -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
RenderStatement r smt =>
Doc -> MS (r smt)
mkStmtNoEnd (Doc -> MS (PythonCode (Doc, Terminator)))
-> Doc -> MS (PythonCode (Doc, Terminator))
forall a b. (a -> b) -> a -> b
$ PythonCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value PythonCode Value
prf Doc -> Doc -> Doc
<> Doc -> Doc
parens (PythonCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value PythonCode Value
v Doc -> Doc -> Doc
<> Doc
nl Doc -> Doc -> Doc
<> Doc
fl)
pyOut
:: (InternalIOStmt r smt, SharedStatement r smt, TypeElim r)
=> Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r smt)
pyOut :: forall (r :: * -> *) smt.
(InternalIOStmt r smt, SharedStatement r smt, TypeElim r) =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r smt)
pyOut Bool
newLn Maybe (SValue r)
f SValue r
printFn SValue r
v = LensLike'
(Zoomed (StateT ValueState Identity) (r Value))
MethodState
ValueState
-> SValue r -> StateT MethodState Identity (r Value)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (r Value))
MethodState
ValueState
(ValueState -> Focusing Identity (r Value) ValueState)
-> MethodState -> Focusing Identity (r Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue r
v StateT MethodState Identity (r Value)
-> (r Value -> StateT MethodState Identity (r smt))
-> StateT MethodState Identity (r smt)
forall a b.
StateT MethodState Identity a
-> (a -> StateT MethodState Identity b)
-> StateT MethodState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CodeType -> StateT MethodState Identity (r smt)
pyOut' (CodeType -> StateT MethodState Identity (r smt))
-> (r Value -> CodeType)
-> r Value
-> StateT MethodState Identity (r smt)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (r TypeData -> CodeType)
-> (r Value -> r TypeData) -> r Value -> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r Value -> r TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType
where pyOut' :: CodeType -> StateT MethodState Identity (r smt)
pyOut' (List CodeType
_) = Bool
-> Maybe (SValue r)
-> SValue r
-> SValue r
-> StateT MethodState Identity (r smt)
forall (r :: * -> *) smt.
InternalIOStmt r smt =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r smt)
printSt Bool
newLn Maybe (SValue r)
f SValue r
printFn SValue r
v
pyOut' CodeType
_ = Bool
-> Maybe (SValue r)
-> SValue r
-> SValue r
-> StateT MethodState Identity (r smt)
forall (r :: * -> *) smt.
(InternalIOStmt r smt, SharedStatement r smt, TypeElim r) =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r smt)
G.print Bool
newLn Maybe (SValue r)
f SValue r
printFn SValue r
v
pyInput :: SValue PythonCode -> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
pyInput :: SValue PythonCode
-> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
pyInput SValue PythonCode
inSrc SVariable PythonCode
v = SVariable PythonCode
v SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) smt.
AssignStatement r smt =>
SVariable r -> SValue r -> MS (r smt)
&= (SVariable PythonCode
v SVariable PythonCode
-> (PythonCode Variable -> SValue PythonCode) -> SValue PythonCode
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CodeType -> SValue PythonCode
pyInput' (CodeType -> SValue PythonCode)
-> (PythonCode Variable -> CodeType)
-> PythonCode Variable
-> SValue PythonCode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (PythonCode TypeData -> CodeType)
-> (PythonCode Variable -> PythonCode TypeData)
-> PythonCode Variable
-> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Variable -> PythonCode TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType)
where pyInput' :: CodeType -> SValue PythonCode
pyInput' CodeType
Integer = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). ValueExpression r => SValue r -> SValue r
readInt SValue PythonCode
inSrc
pyInput' CodeType
Float = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). ValueExpression r => SValue r -> SValue r
readDouble SValue PythonCode
inSrc
pyInput' CodeType
Double = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). ValueExpression r => SValue r -> SValue r
readDouble SValue PythonCode
inSrc
pyInput' CodeType
Boolean = SValue PythonCode
inSrc SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?!= String -> SValue PythonCode
forall (r :: * -> *). Literal r => String -> SValue r
litString String
"0"
pyInput' CodeType
String = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). InternalValueExp r => SValue r -> SValue r
readString SValue PythonCode
inSrc
pyInput' CodeType
Char = SValue PythonCode
inSrc
pyInput' CodeType
_ = String -> SValue PythonCode
forall a. HasCallStack => String -> a
error String
"Attempt to read a value of unreadable type"
pyThrow :: (ValueElim r) => r Value -> Doc
pyThrow :: forall (r :: * -> *). ValueElim r => r Value -> Doc
pyThrow r Value
errMsg = Doc
pyRaise Doc -> Doc -> Doc
<+> Doc
exceptionObj' Doc -> Doc -> Doc
<> Doc -> Doc
parens (r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
errMsg)
pyForEach
:: (BodyElim r, InternalVarElim r, ValueElim r)
=> r Variable -> r Value -> r Body -> Doc
pyForEach :: forall (r :: * -> *).
(BodyElim r, InternalVarElim r, ValueElim r) =>
r Variable -> r Value -> r Doc -> Doc
pyForEach r Variable
i r Value
lstVar r Doc
b = [Doc] -> Doc
vcat [
Doc
forLabel Doc -> Doc -> Doc
<+> r Variable -> Doc
forall (r :: * -> *). InternalVarElim r => r Variable -> Doc
RC.variable r Variable
i Doc -> Doc -> Doc
<+> Doc
inLabel Doc -> Doc -> Doc
<+> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
lstVar Doc -> Doc -> Doc
<> Doc
colon,
Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ r Doc -> Doc
forall (r :: * -> *). BodyElim r => r Doc -> Doc
RC.body r Doc
b]
pyWhile :: (BodyElim r, ValueElim r) => r Value -> r Body -> Doc
pyWhile :: forall (r :: * -> *).
(BodyElim r, ValueElim r) =>
r Value -> r Doc -> Doc
pyWhile r Value
v r Doc
b = [Doc] -> Doc
vcat [
Doc
whileLabel Doc -> Doc -> Doc
<+> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
v Doc -> Doc -> Doc
<> Doc
colon,
Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ r Doc -> Doc
forall (r :: * -> *). BodyElim r => r Doc -> Doc
RC.body r Doc
b]
pyTryCatch :: (BodyElim r) => r Body -> r Body -> Doc
pyTryCatch :: forall (r :: * -> *). BodyElim r => r Doc -> r Doc -> Doc
pyTryCatch r Doc
tryB r Doc
catchB = [Doc] -> Doc
vcat [
Doc
tryLabel Doc -> Doc -> Doc
<> Doc
colon,
Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ r Doc -> Doc
forall (r :: * -> *). BodyElim r => r Doc -> Doc
RC.body r Doc
tryB,
Doc
pyExcept Doc -> Doc -> Doc
<+> Doc
exceptionObj' Doc -> Doc -> Doc
<> Doc
colon,
Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ r Doc -> Doc
forall (r :: * -> *). BodyElim r => r Doc -> Doc
RC.body r Doc
catchB]
pyAssert :: (ValueElim r) => r Value -> r Value -> Doc
pyAssert :: forall (r :: * -> *). ValueElim r => r Value -> r Value -> Doc
pyAssert r Value
condition r Value
message = String -> Doc
text String
"assert" Doc -> Doc -> Doc
<+> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
condition Doc -> Doc -> Doc
<> Doc
comma Doc -> Doc -> Doc
<+> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
message
pyListSlice :: (InternalVarElim r, Monad r, ValueElim r) => SVariable r ->
SValue r -> SValue r -> SValue r -> SValue r -> MS (r Doc)
pyListSlice :: forall (r :: * -> *).
(InternalVarElim r, Monad r, ValueElim r) =>
SVariable r
-> SValue r -> SValue r -> SValue r -> SValue r -> MS (r Doc)
pyListSlice SVariable r
vn SValue r
vo SValue r
beg SValue r
end SValue r
step = LensLike'
(Zoomed (StateT ValueState Identity) (r Doc))
MethodState
ValueState
-> StateT ValueState Identity (r Doc)
-> StateT MethodState Identity (r Doc)
forall c.
LensLike'
(Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
(Zoomed (StateT ValueState Identity) (r Doc))
MethodState
ValueState
(ValueState -> Focusing Identity (r Doc) ValueState)
-> MethodState -> Focusing Identity (r Doc) MethodState
Lens' MethodState ValueState
lensMStoVS (StateT ValueState Identity (r Doc)
-> StateT MethodState Identity (r Doc))
-> StateT ValueState Identity (r Doc)
-> StateT MethodState Identity (r Doc)
forall a b. (a -> b) -> a -> b
$ do
r Variable
vnew <- SVariable r
vn
r Value
vold <- SValue r
vo
r Value
b <- SValue r
beg
r Value
e <- SValue r
end
r Value
s <- SValue r
step
r Doc -> StateT ValueState Identity (r Doc)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (r Doc -> StateT ValueState Identity (r Doc))
-> r Doc -> StateT ValueState Identity (r Doc)
forall a b. (a -> b) -> a -> b
$ Doc -> r Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> r Doc) -> Doc -> r Doc
forall a b. (a -> b) -> a -> b
$ r Variable -> Doc
forall (r :: * -> *). InternalVarElim r => r Variable -> Doc
RC.variable r Variable
vnew Doc -> Doc -> Doc
<+> Doc
equals Doc -> Doc -> Doc
<+> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
vold Doc -> Doc -> Doc
<>
Doc -> Doc
brackets (r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
b Doc -> Doc -> Doc
<> Doc
colon Doc -> Doc -> Doc
<> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
e Doc -> Doc -> Doc
<> Doc
colon Doc -> Doc -> Doc
<> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
s)
pyMethod
:: Label
-> PythonCode AttachmentData
-> PythonCode Variable
-> [PythonCode ParamData]
-> PythonCode Body
-> Doc
pyMethod :: String
-> PythonCode AttachmentData
-> PythonCode Variable
-> [PythonCode ParamData]
-> PythonCode Doc
-> Doc
pyMethod String
n PythonCode AttachmentData
attch PythonCode Variable
slf [PythonCode ParamData]
ps PythonCode Doc
b = let
decorator :: Doc
decorator = case PythonCode AttachmentData -> AttachmentTag
forall (r :: * -> *) att. PermElim r att => r att -> AttachmentTag
binding PythonCode AttachmentData
attch of
AttachmentTag
ClassLevel -> String -> Doc
text String
"@staticmethod"
AttachmentTag
_ -> Doc
empty
pms :: Doc
pms = [PythonCode ParamData] -> Doc
forall (r :: * -> *). ParamElim r => [r ParamData] -> Doc
parameterList [PythonCode ParamData]
ps
(Doc
implicitParam, Doc
implicitComma) = case PythonCode AttachmentData -> AttachmentTag
forall (r :: * -> *) att. PermElim r att => r att -> AttachmentTag
binding PythonCode AttachmentData
attch of
AttachmentTag
InstanceLevel -> (PythonCode Variable -> Doc
forall (r :: * -> *). InternalVarElim r => r Variable -> Doc
RC.variable PythonCode Variable
slf, Doc -> Doc -> Doc
emptyIfEmpty Doc
pms Doc
listSep')
AttachmentTag
_ -> (Doc
empty, Doc
empty)
bodyD :: Doc
bodyD | Doc -> Bool
isEmpty (PythonCode Doc -> Doc
forall (r :: * -> *). BodyElim r => r Doc -> Doc
RC.body PythonCode Doc
b) = Doc
pyNull'
| Bool
otherwise = PythonCode Doc -> Doc
forall (r :: * -> *). BodyElim r => r Doc -> Doc
RC.body PythonCode Doc
b
in [Doc] -> Doc
vcat [
Doc
decorator,
Doc
pyDef Doc -> Doc -> Doc
<+> String -> Doc
text String
n Doc -> Doc -> Doc
<> Doc -> Doc
parens (Doc
implicitParam Doc -> Doc -> Doc
<> Doc
implicitComma Doc -> Doc -> Doc
<> Doc
pms) Doc -> Doc -> Doc
<> Doc
colon,
Doc -> Doc
indent Doc
bodyD]
pyFunction :: (BodyElim r, ParamElim r) => Label ->
[r ParamData] -> r Body -> Doc
pyFunction :: forall (r :: * -> *).
(BodyElim r, ParamElim r) =>
String -> [r ParamData] -> r Doc -> Doc
pyFunction String
n [r ParamData]
ps r Doc
b = [Doc] -> Doc
vcat [
Doc
pyDef Doc -> Doc -> Doc
<+> String -> Doc
text String
n Doc -> Doc -> Doc
<> Doc -> Doc
parens ([r ParamData] -> Doc
forall (r :: * -> *). ParamElim r => [r ParamData] -> Doc
parameterList [r ParamData]
ps) Doc -> Doc -> Doc
<> Doc
colon,
Doc -> Doc
indent Doc
bodyD]
where bodyD :: Doc
bodyD | Doc -> Bool
isEmpty (r Doc -> Doc
forall (r :: * -> *). BodyElim r => r Doc -> Doc
RC.body r Doc
b) = Doc
pyNull'
| Bool
otherwise = r Doc -> Doc
forall (r :: * -> *). BodyElim r => r Doc -> Doc
RC.body r Doc
b
pyClass :: Label -> Doc -> Doc -> Doc -> Doc -> Doc
pyClass :: String -> Doc -> Doc -> Doc -> Doc -> Doc
pyClass String
n Doc
pn Doc
s Doc
vs Doc
fs = [Doc] -> Doc
vcat [
Doc
s Doc -> Doc -> Doc
<+> Doc
classDec Doc -> Doc -> Doc
<+> String -> Doc
text String
n Doc -> Doc -> Doc
<> Doc
pn Doc -> Doc -> Doc
<> Doc
colon,
Doc -> Doc
indent Doc
funcSec]
where funcSec :: Doc
funcSec | Doc -> Bool
isEmpty (Doc
vs Doc -> Doc -> Doc
<> Doc
fs) = Doc
pyNull'
| Doc -> Bool
isEmpty Doc
vs = Doc
fs
| Doc -> Bool
isEmpty Doc
fs = Doc
vs
| Bool
otherwise = [Doc] -> Doc
vcat [Doc
vs, Doc
blank, Doc
fs]
pyMultCstrsError :: String
pyMultCstrsError :: String
pyMultCstrsError = String
"Python classes cannot have multiple constructors"
pyBlockComment :: [String] -> Doc -> Doc
[String]
lns Doc
cmt = [Doc] -> Doc
vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (String -> Doc) -> [String] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Doc -> Doc -> Doc
(<+>) Doc
cmt (Doc -> Doc) -> (String -> Doc) -> String -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc
text) [String]
lns
pyDocComment :: [String] -> Doc -> Doc -> Doc
[] Doc
_ Doc
_ = Doc
empty
pyDocComment (String
l:[String]
lns) Doc
start Doc
mid = [Doc] -> Doc
vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ Doc
start Doc -> Doc -> Doc
<+> String -> Doc
text String
l Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
: (String -> Doc) -> [String] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Doc -> Doc -> Doc
(<+>) Doc
mid (Doc -> Doc) -> (String -> Doc) -> String -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
String -> Doc
text) [String]
lns
toConstName :: String -> String
toConstName :: String -> String
toConstName (Char
s:Char
s':String
ss) = if Char -> Bool
isLower Char
s Bool -> Bool -> Bool
&& Char -> Bool
isUpper Char
s'
then Char -> Char
toUpper Char
s Char -> String -> String
forall a. a -> [a] -> [a]
: Char
'_' Char -> String -> String
forall a. a -> [a] -> [a]
: Char
s' Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
toConstName String
ss
else Char -> Char
toUpper Char
s Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
toConstName (Char
s' Char -> String -> String
forall a. a -> [a] -> [a]
: String
ss)
toConstName (Char
s:String
ss) = Char -> Char
toUpper Char
s Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
toConstName String
ss
toConstName String
"" = String
""