{-# LANGUAGE TypeFamilies #-}
-- | The logic to render Python code is contained in this module
module Drasil.GOOL.LanguageRenderer.PythonRenderer (
  -- * Python Code Configuration -- defines syntax of all Python code
  PythonCode(..), pyName, pyVersion
) where

import Drasil.FileHandling.Legacy (blank, indent)

import Drasil.Shared.CodeType (CodeType(..))
import Drasil.Shared.InterfaceCommon (UnRepr(..), Label, Library, Body, Block,
  Variable, Value, 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(..),
  ListStatement(..), Set(..), InternalList(..), EmptyStatement(..),
  MultiStatement(..), ValueStatement(..), AssignStatement(..), (&=),
  DeclStatement(..), PrintConsole(..), ReadConsole(..), FileHandling(..),
  PrintFile(..), ReadFile(..), StringStatement(..), FuncAppStatement(..),
  CommentStatement(..), ControlStatement(..), switchAsIf, ScopeSym(..),
  ParameterSym(..), BinderSym(..), BinderElim(..), MethodSym(..))
import Drasil.GOOL.InterfaceGOOL (OOProg, Class, StateVar, ProgramSym(..),
  FileSym(..), ModuleSym(..), ClassSym(..), OOTypeSym(..), OOVariableSym(..),
  SelfSym(..), StateVarSym(..), AttachmentSym(..), 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, FileData, ScopeData, Statement)
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 qualified Prelude as P ((<>))
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 OOProg PythonCode ProgData FileData ModData Class StateVar MethodData AttachmentData Doc ParamData Body Block Statement Variable ScopeData Value BinderD TypeData

instance ProgramSym PythonCode ProgData FileData where
  prog :: String
-> String
-> [FS (PythonCode FileData)]
-> GSProgram PythonCode ProgData
prog String
n String
st [FS (PythonCode FileData)]
files = do
    fs <- (FS (PythonCode FileData)
 -> StateT GOOLState Identity (PythonCode FileData))
-> [FS (PythonCode FileData)]
-> StateT GOOLState Identity [PythonCode FileData]
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 FileData))
  GOOLState
  FileState
-> FS (PythonCode FileData)
-> StateT GOOLState Identity (PythonCode FileData)
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 FileData))
  GOOLState
  FileState
(FileState -> Focusing Identity (PythonCode FileData) FileState)
-> GOOLState -> Focusing Identity (PythonCode FileData) GOOLState
Lens' GOOLState FileState
lensGStoFS) [FS (PythonCode FileData)]
files
    modify revFiles
    pure $ onCodeList (progD n st) fs

instance CommonRenderSym PythonCode MethodData Doc ParamData Body Block Statement Variable ScopeData Value BinderD TypeData
instance OORenderSym PythonCode FileData ModData Class StateVar MethodData AttachmentData Doc ParamData Body Block Statement Variable ScopeData Value BinderD TypeData

instance UnRepr PythonCode contents where
  unRepr :: PythonCode contents -> contents
unRepr = PythonCode contents -> contents
forall a. PythonCode a -> a
unPC

instance FileSym PythonCode FileData ModData where
  fileDoc :: FS (PythonCode ModData) -> FS (PythonCode FileData)
fileDoc FS (PythonCode ModData)
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 ModData -> PythonCode Body)
-> PythonCode Body
-> FS (PythonCode ModData)
-> FS (PythonCode FileData)
forall (r :: * -> *) block mod file.
(BlockElim r block, RenderMod r mod, RenderFile r file mod) =>
String
-> (r mod -> r block) -> r block -> FS (r mod) -> FS (r file)
G.fileDoc String
pyExt PythonCode ModData -> PythonCode Body
forall (r :: * -> *) file mod.
RenderFile r file mod =>
r mod -> r Body
top PythonCode Body
forall (r :: * -> *) file mod. RenderFile r file mod => r Body
bottom FS (PythonCode ModData)
m

  docMod :: String
-> String
-> [String]
-> String
-> FS (PythonCode FileData)
-> FS (PythonCode FileData)
docMod = String
-> String
-> String
-> [String]
-> String
-> FS (PythonCode FileData)
-> FS (PythonCode FileData)
forall (r :: * -> *) file mod.
(BlockCommentSym r, RenderFile r file mod) =>
String
-> String
-> String
-> [String]
-> String
-> FS (r file)
-> FS (r file)
CP.doxMod String
pyExt

instance RenderFile PythonCode FileData ModData where
  top :: PythonCode ModData -> PythonCode Body
top PythonCode ModData
_ = Body -> PythonCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode Body
empty
  bottom :: PythonCode Body
bottom = Body -> PythonCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode Body
empty

  commentedMod :: FS (PythonCode FileData)
-> FS (PythonCode Body) -> FS (PythonCode FileData)
commentedMod = (PythonCode FileData -> PythonCode Body -> PythonCode FileData)
-> FS (PythonCode FileData)
-> FS (PythonCode Body)
-> FS (PythonCode FileData)
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues ((FileData -> Body -> FileData)
-> PythonCode FileData -> PythonCode Body -> PythonCode FileData
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues FileData -> Body -> FileData
R.commentedMod)

  fileFromData :: String -> FS (PythonCode ModData) -> FS (PythonCode FileData)
fileFromData = (String -> PythonCode ModData -> PythonCode FileData)
-> String -> FS (PythonCode ModData) -> FS (PythonCode FileData)
forall {k} (r :: k -> *) (mod :: k) (file :: k).
ModuleElim r mod =>
(String -> r mod -> r file) -> String -> FS (r mod) -> FS (r file)
G.fileFromData ((ModData -> FileData) -> PythonCode ModData -> PythonCode FileData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ((ModData -> FileData)
 -> PythonCode ModData -> PythonCode FileData)
-> (String -> ModData -> FileData)
-> String
-> PythonCode ModData
-> PythonCode FileData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ModData -> FileData
fileD)

instance ImportSym PythonCode where
  langImport :: String -> PythonCode Body
langImport String
n = Body -> PythonCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Body -> PythonCode Body) -> Body -> PythonCode Body
forall a b. (a -> b) -> a -> b
$ Body
importLabel Body -> Body -> Body
<+> String -> Body
text String
n
  modImport :: String -> PythonCode Body
modImport = String -> PythonCode Body
forall (r :: * -> *). ImportSym r => String -> r Body
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 -> Body -> AttachmentData
ad AttachmentTag
ClassLevel Body
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 -> Body -> AttachmentData
ad AttachmentTag
InstanceLevel Body
R.instanceLevel

instance PermElim PythonCode AttachmentData where
  perm :: PythonCode AttachmentData -> Body
perm = AttachmentData -> Body
attachmentDoc (AttachmentData -> Body)
-> (PythonCode AttachmentData -> AttachmentData)
-> PythonCode AttachmentData
-> Body
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 Body Block where
  body :: [MS (PythonCode Body)] -> MS (PythonCode Body)
body = ([PythonCode Body] -> PythonCode Body)
-> [MS (PythonCode Body)] -> MS (PythonCode Body)
forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList (([Body] -> Body) -> [PythonCode Body] -> PythonCode Body
forall (m :: * -> *) a b. Monad m => ([a] -> b) -> [m a] -> m b
onCodeList [Body] -> Body
R.body)

  addComments :: String -> MS (PythonCode Body) -> MS (PythonCode Body)
addComments String
s = (PythonCode Body -> PythonCode Body)
-> MS (PythonCode Body) -> MS (PythonCode Body)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue ((Body -> Body) -> PythonCode Body -> PythonCode Body
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue (String -> Body -> Body -> Body
R.addComments String
s Body
pyCommentStart))

instance RenderBody PythonCode Body where
  multiBody :: [MS (PythonCode Body)] -> MS (PythonCode Body)
multiBody = [MS (PythonCode Body)] -> MS (PythonCode Body)
forall (r :: * -> *) bod.
(BodyElim r bod, Monad r) =>
[MS (r bod)] -> MS (r Body)
G.multiBody

instance BodyElim PythonCode Body where
  body :: PythonCode Body -> Body
body = PythonCode Body -> Body
forall a. PythonCode a -> a
unPC

instance BlockSym PythonCode Block Statement where
  block :: [MS (PythonCode Statement)] -> MS (PythonCode Body)
block = [MS (PythonCode Statement)] -> MS (PythonCode Body)
forall (r :: * -> *) stmt.
(Monad r, RenderStatement r stmt, StatementElim r stmt) =>
[MS (r stmt)] -> MS (r Body)
G.block

instance RenderBlock PythonCode Block where
  multiBlock :: [MS (PythonCode Body)] -> MS (PythonCode Body)
multiBlock = [MS (PythonCode Body)] -> MS (PythonCode Body)
forall (r :: * -> *) block.
(BlockElim r block, Monad r) =>
[MS (r block)] -> MS (r Body)
G.multiBlock

instance BlockElim PythonCode Block where
  block :: PythonCode Body -> Body
block = PythonCode Body -> Body
forall a. PythonCode a -> a
unPC

instance TypeSym PythonCode TypeData where
  bool :: VS (PythonCode TypeData)
bool = CodeType -> String -> Body -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Body -> VS (r TypeData)
typeFromData CodeType
Boolean String
"" Body
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 -> Body -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Body -> VS (r TypeData)
typeFromData CodeType
Double String
pyDouble (String -> Body
text String
pyDouble)
  char :: VS (PythonCode TypeData)
char = CodeType -> String -> Body -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Body -> VS (r TypeData)
typeFromData CodeType
Char String
"" Body
empty
  string :: VS (PythonCode TypeData)
string = VS (PythonCode TypeData)
forall (r :: * -> *). Monad r => VS (r TypeData)
pyStringType
  infile :: VS (PythonCode TypeData)
infile = CodeType -> String -> Body -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Body -> VS (r TypeData)
typeFromData CodeType
InFile String
"" Body
empty
  outfile :: VS (PythonCode TypeData)
outfile = CodeType -> String -> Body -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Body -> VS (r TypeData)
typeFromData CodeType
OutFile String
"" Body
empty
  referenceType :: VS (PythonCode TypeData) -> VS (PythonCode TypeData)
referenceType = VS (PythonCode TypeData) -> VS (PythonCode TypeData)
forall a. a -> a
id -- Ignore reference types in "high-level" langauges for now; later on think about using boxed/unboxed types
  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 -> Body -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Body -> VS (r TypeData)
typeFromData (CodeType -> CodeType
List (PythonCode TypeData -> CodeType
forall {k} (r :: k -> *) (typ :: k).
TypeElim r typ =>
r typ -> CodeType
getCodeType PythonCode TypeData
t)) String
"" Body
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 -> Body -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Body -> VS (r TypeData)
typeFromData (CodeType -> CodeType
Set (PythonCode TypeData -> CodeType
forall {k} (r :: k -> *) (typ :: k).
TypeElim r typ =>
r typ -> CodeType
getCodeType PythonCode TypeData
t)) String
"" Body
empty)
  arrayType :: VS (PythonCode TypeData) -> VS (PythonCode TypeData)
arrayType = VS (PythonCode TypeData) -> VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k).
TypeSym r typ =>
VS (r typ) -> VS (r typ)
listType
  innerType :: VS (PythonCode TypeData) -> VS (PythonCode TypeData)
innerType = VS (PythonCode TypeData) -> VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k).
(TypeElim r typ, TypeSym r typ, OOTypeSym r typ) =>
VS (r typ) -> VS (r typ)
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 TypeData) =>
[VS (r TypeData)] -> VS (r TypeData) -> VS (r TypeData)
CS.funcType
  void :: VS (PythonCode TypeData)
void = CodeType -> String -> Body -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Body -> VS (r TypeData)
typeFromData CodeType
Void String
pyVoid (String -> Body
text String
pyVoid)

instance TypeElim PythonCode TypeData 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 TypeData where
  obj :: String -> VS (PythonCode TypeData)
obj = String -> VS (PythonCode TypeData)
forall (r :: * -> *). Monad r => String -> VS (r TypeData)
G.obj

instance RenderType PythonCode TypeData where
  multiType :: [VS (PythonCode TypeData)] -> VS (PythonCode TypeData)
multiType [VS (PythonCode TypeData)]
_ = CodeType -> String -> Body -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Body -> VS (r TypeData)
typeFromData CodeType
Void String
"" Body
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 -> Body
uOp = OpData -> Body
opDoc (OpData -> Body)
-> (PythonCode OpData -> OpData) -> PythonCode OpData -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode OpData -> OpData
forall a. PythonCode a -> a
unPC
  bOp :: PythonCode OpData -> Body
bOp = OpData -> Body
opDoc (OpData -> Body)
-> (PythonCode OpData -> OpData) -> PythonCode OpData -> Body
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 ScopeData where
  global :: PythonCode ScopeData
global = PythonCode ScopeData
forall (r :: * -> *). Monad r => r ScopeData
CP.global
  mainFn :: PythonCode ScopeData
mainFn = PythonCode ScopeData
forall {k} (r :: k -> *) (scope :: k). ScopeSym r scope => r scope
global
  local :: PythonCode ScopeData
local = PythonCode ScopeData
forall (r :: * -> *). Monad r => r ScopeData
G.local

instance ScopeElim PythonCode ScopeData where
  scopeData :: PythonCode ScopeData -> ScopeData
scopeData = PythonCode ScopeData -> ScopeData
forall a. PythonCode a -> a
unPC

instance VariableSym PythonCode Variable TypeData where
  var :: String -> VS (PythonCode TypeData) -> VS (PythonCode Variable)
var          = String -> VS (PythonCode TypeData) -> VS (PythonCode Variable)
forall {k} (r :: k -> *) (var :: k) (typ :: k).
RenderVariable r var typ =>
String -> VS (r typ) -> VS (r var)
G.var
  constant :: String -> VS (PythonCode TypeData) -> VS (PythonCode Variable)
constant String
n   = String -> VS (PythonCode TypeData) -> VS (PythonCode Variable)
forall {k} (r :: k -> *) (var :: k) (typ :: k).
VariableSym r var typ =>
String -> VS (r typ) -> VS (r var)
var (String -> VS (PythonCode TypeData) -> VS (PythonCode Variable))
-> String -> VS (PythonCode TypeData) -> VS (PythonCode Variable)
forall a b. (a -> b) -> a -> b
$ String -> String
toConstName String
n
  extVar :: String
-> String -> VS (PythonCode TypeData) -> VS (PythonCode Variable)
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 ()
-> VS (PythonCode Variable) -> VS (PythonCode Variable)
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) -> VS (PythonCode Variable)
forall {k} (r :: k -> *) (var :: k) (typ :: k).
RenderVariable r var typ =>
String -> String -> VS (r typ) -> VS (r var)
CS.extVar String
l String
n VS (PythonCode TypeData)
t

instance OOVariableSym PythonCode Variable Value TypeData where
  classVar :: String -> VS (PythonCode TypeData) -> VS (PythonCode Variable)
classVar = String -> VS (PythonCode TypeData) -> VS (PythonCode Variable)
forall {k} (r :: k -> *) (var :: k) (typ :: k).
RenderVariable r var typ =>
String -> VS (r typ) -> VS (r var)
G.classVar
  classConst :: String -> VS (PythonCode TypeData) -> VS (PythonCode Variable)
classConst String
n VS (PythonCode TypeData)
t = String
-> VS (PythonCode TypeData) -> Body -> VS (PythonCode Variable)
forall {k} (r :: k -> *) (var :: k) (typ :: k).
RenderVariable r var typ =>
String -> VS (r typ) -> Body -> VS (r var)
mkClassVar String
n VS (PythonCode TypeData)
t (String -> Body
R.var (String -> String
toConstName String
n))
  classVarAccess :: VS (PythonCode TypeData)
-> VS (PythonCode Variable) -> VS (PythonCode Variable)
classVarAccess = (Body -> Body -> Body)
-> VS (PythonCode TypeData)
-> VS (PythonCode Variable)
-> VS (PythonCode Variable)
forall (r :: * -> *) var.
(InternalVarElim r var, RenderVariable r var TypeData,
 UnRepr r TypeData, VariableElim r var TypeData) =>
(Body -> Body -> Body)
-> VS (r TypeData) -> VS (r var) -> VS (r var)
CP.classVarAccess Body -> Body -> Body
R.classVarAccess
  extClassVarAccess :: VS (PythonCode TypeData)
-> VS (PythonCode Variable) -> VS (PythonCode Variable)
extClassVarAccess VS (PythonCode TypeData)
c VS (PythonCode Variable)
v = StateT ValueState Identity (VS (PythonCode Variable))
-> VS (PythonCode Variable)
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (StateT ValueState Identity (VS (PythonCode Variable))
 -> VS (PythonCode Variable))
-> StateT ValueState Identity (VS (PythonCode Variable))
-> VS (PythonCode Variable)
forall a b. (a -> b) -> a -> b
$ (PythonCode TypeData
 -> Map String String -> VS (PythonCode Variable))
-> VS (PythonCode TypeData)
-> State ValueState (Map String String)
-> StateT ValueState Identity (VS (PythonCode Variable))
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 -> (VS (PythonCode Variable) -> VS (PythonCode Variable))
-> (String -> VS (PythonCode Variable) -> VS (PythonCode Variable))
-> Maybe String
-> VS (PythonCode Variable)
-> VS (PythonCode Variable)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe VS (PythonCode Variable) -> VS (PythonCode Variable)
forall a. a -> a
id (StateT ValueState Identity ()
-> VS (PythonCode Variable) -> VS (PythonCode Variable)
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 ()
 -> VS (PythonCode Variable) -> VS (PythonCode Variable))
-> (String -> StateT ValueState Identity ())
-> String
-> VS (PythonCode Variable)
-> VS (PythonCode Variable)
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) (VS (PythonCode Variable) -> VS (PythonCode Variable))
-> VS (PythonCode Variable) -> VS (PythonCode Variable)
forall a b. (a -> b) -> a -> b
$
    (Body -> Body -> Body)
-> VS (PythonCode TypeData)
-> VS (PythonCode Variable)
-> VS (PythonCode Variable)
forall (r :: * -> *) var.
(InternalVarElim r var, RenderVariable r var TypeData,
 UnRepr r TypeData, VariableElim r var TypeData) =>
(Body -> Body -> Body)
-> VS (r TypeData) -> VS (r var) -> VS (r var)
CP.classVarAccess Body -> Body -> Body
pyClassVarAccess (PythonCode TypeData -> VS (PythonCode TypeData)
forall a s. a -> State s a
toState PythonCode TypeData
t) VS (PythonCode Variable)
v) VS (PythonCode TypeData)
c State ValueState (Map String String)
getClassMap
  instanceVarAccess :: VS (PythonCode Value)
-> VS (PythonCode Variable) -> VS (PythonCode Variable)
instanceVarAccess = VS (PythonCode Value)
-> VS (PythonCode Variable) -> VS (PythonCode Variable)
forall {k} (r :: k -> *) (var :: k) (typ :: k) (val :: k).
(InternalVarElim r var, RenderVariable r var typ, ValueElim r val,
 VariableElim r var typ) =>
VS (r val) -> VS (r var) -> VS (r var)
G.instanceVarAccess

instance SelfSym PythonCode Variable where
  self :: VS (PythonCode Variable)
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 -> VS (PythonCode Variable)) -> VS (PythonCode Variable)
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) -> Body -> VS (PythonCode Variable)
forall {k} (r :: k -> *) (var :: k) (typ :: k).
RenderVariable r var typ =>
String -> VS (r typ) -> Body -> VS (r var)
mkStateVar String
pySelf (String -> VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k).
OOTypeSym r typ =>
String -> VS (r typ)
obj String
l) (String -> Body
text String
pySelf))

instance VariableElim PythonCode Variable TypeData 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 Variable 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 -> Body
variable = Variable -> Body
varDoc (Variable -> Body)
-> (PythonCode Variable -> Variable) -> PythonCode Variable -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Variable -> Variable
forall a. PythonCode a -> a
unPC

instance RenderVariable PythonCode Variable TypeData where
  varFromData :: AttachmentTag
-> String
-> VS (PythonCode TypeData)
-> Body
-> VS (PythonCode Variable)
varFromData AttachmentTag
b String
n VS (PythonCode TypeData)
t' Body
d = do
    t <- VS (PythonCode TypeData)
t'
    toState $ on2CodeValues (vard b n) t (toCode d)

instance ValueSym PythonCode Value TypeData 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 Argument PythonCode Value where
  pointerArg :: VS (PythonCode Value) -> VS (PythonCode Value)
pointerArg = VS (PythonCode Value) -> VS (PythonCode Value)
forall a. a -> a
id

instance Literal PythonCode Value TypeData where
  litTrue :: VS (PythonCode Value)
litTrue = VS (PythonCode TypeData) -> Body -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r typ) -> Body -> VS (r val)
mkStateVal VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool Body
pyTrue
  litFalse :: VS (PythonCode Value)
litFalse = VS (PythonCode TypeData) -> Body -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r typ) -> Body -> VS (r val)
mkStateVal VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool Body
pyFalse
  litChar :: Char -> VS (PythonCode Value)
litChar = (Body -> Body) -> Char -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, TypeSym r typ) =>
(Body -> Body) -> Char -> VS (r val)
G.litChar Body -> Body
quotes
  litDouble :: Double -> VS (PythonCode Value)
litDouble = Double -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, TypeSym r typ) =>
Double -> VS (r val)
G.litDouble
  litFloat :: Float -> VS (PythonCode Value)
litFloat = String -> Float -> VS (PythonCode Value)
forall a. HasCallStack => String -> a
error String
pyFloatError
  litInt :: Integer -> VS (PythonCode Value)
litInt = Integer -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, TypeSym r typ) =>
Integer -> VS (r val)
G.litInt
  litString :: String -> VS (PythonCode Value)
litString = String -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, TypeSym r typ) =>
String -> VS (r val)
G.litString
  litArray :: VS (PythonCode TypeData)
-> [VS (PythonCode Value)] -> VS (PythonCode Value)
litArray = (Body -> Body)
-> VS (PythonCode TypeData)
-> [VS (PythonCode Value)]
-> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, TypeSym r typ, ValueElim r val) =>
(Body -> Body) -> VS (r typ) -> [VS (r val)] -> VS (r val)
CP.litArray Body -> Body
brackets
  litSet :: VS (PythonCode TypeData)
-> [VS (PythonCode Value)] -> VS (PythonCode Value)
litSet = (Body -> Body)
-> VS (PythonCode TypeData)
-> [VS (PythonCode Value)]
-> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, TypeSym r typ, ValueElim r val) =>
(Body -> Body) -> VS (r typ) -> [VS (r val)] -> VS (r val)
CP.litArray Body -> Body
braces
  litList :: VS (PythonCode TypeData)
-> [VS (PythonCode Value)] -> VS (PythonCode Value)
litList = VS (PythonCode TypeData)
-> [VS (PythonCode Value)] -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
VS (r typ) -> [VS (r val)] -> VS (r val)
litArray

instance MathConstant PythonCode Value where
  pi :: VS (PythonCode Value)
pi = VS (PythonCode Value) -> VS (PythonCode Value)
forall a. VS a -> VS a
addmathImport (VS (PythonCode Value) -> VS (PythonCode Value))
-> VS (PythonCode Value) -> VS (PythonCode Value)
forall a b. (a -> b) -> a -> b
$ VS (PythonCode TypeData) -> Body -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r typ) -> Body -> VS (r val)
mkStateVal VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
double Body
pyPi

instance VariableValue PythonCode Variable Value where
  valueOf :: VS (PythonCode Variable) -> VS (PythonCode Value)
valueOf = VS (PythonCode Variable) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(InternalVarElim r var, RenderValue r var val typ,
 VariableElim r var typ) =>
VS (r var) -> VS (r val)
G.valueOf

instance CommandLineArgs PythonCode Value where
  arg :: Integer -> VS (PythonCode Value)
arg Integer
n = VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, TypeSym r typ, ValueElim r val) =>
VS (r val) -> VS (r val) -> VS (r val)
G.arg (Integer -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
Integer -> VS (r val)
litInt (Integer -> VS (PythonCode Value))
-> Integer -> VS (PythonCode Value)
forall a b. (a -> b) -> a -> b
$ Integer
nInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
+Integer
1) VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k).
CommandLineArgs r val =>
VS (r val)
argsList
  argsList :: VS (PythonCode Value)
argsList = do
    (ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addLangImportVS String
pySys)
    String -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, TypeSym r typ) =>
String -> VS (r val)
G.argsList (String -> VS (PythonCode Value))
-> String -> VS (PythonCode Value)
forall a b. (a -> b) -> a -> b
$ String
pySys String -> String -> String
`access` String
argv
  argExists :: Integer -> VS (PythonCode Value)
argExists = Integer -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
(Literal r val typ, CommandLineArgs r val, Comparison r val,
 List r val) =>
Integer -> VS (r val)
CP.argExists

instance NumericExpression PythonCode Value where
  #~ :: VS (PythonCode Value) -> VS (PythonCode Value)
(#~) = VSUnOp PythonCode -> VS (PythonCode Value) -> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
 ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr' VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
negateOp
  #/^ :: VS (PythonCode Value) -> VS (PythonCode Value)
(#/^) = VSUnOp PythonCode -> VS (PythonCode Value) -> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
 ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
sqrtOp
  #| :: VS (PythonCode Value) -> VS (PythonCode Value)
(#|) = VSUnOp PythonCode -> VS (PythonCode Value) -> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
 ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
absOp
  #+ :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
(#+) = VSUnOp PythonCode
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, TypeElim r typ,
 ValueElim r val, ValueSym r val typ) =>
VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
binExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
plusOp
  #- :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
(#-) = VSUnOp PythonCode
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, TypeElim r typ,
 ValueElim r val, ValueSym r val typ) =>
VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
binExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
minusOp
  #* :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
(#*) = VSUnOp PythonCode
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, TypeElim r typ,
 ValueElim r val, ValueSym r val typ) =>
VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
binExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
multOp
  #/ :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
(#/) VS (PythonCode Value)
v1' VS (PythonCode Value)
v2' = do
    v1 <- VS (PythonCode Value)
v1'
    v2 <- v2'
    let pyDivision CodeType
Integer CodeType
Integer = VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, TypeElim r typ,
 ValueElim r val, ValueSym r val typ) =>
VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
binExpr (String -> VSBinOp r
forall (r :: * -> *). Monad r => String -> VSOp r
multPrec String
pyIntDiv)
        pyDivision CodeType
_ CodeType
_ = VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, TypeElim r typ,
 ValueElim r val, ValueSym r val typ) =>
VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
binExpr VSBinOp r
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
divideOp
    pyDivision (getCodeType $ valueType v1) (getCodeType $ valueType v2) (pure v1)
      (pure v2)
  #% :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
(#%) = VSUnOp PythonCode
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, TypeElim r typ,
 ValueElim r val, ValueSym r val typ) =>
VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
binExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
moduloOp
  #^ :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
(#^) = VSUnOp PythonCode
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, TypeElim r typ,
 ValueElim r val, ValueSym r val typ) =>
VSBinOp r -> VS (r val) -> VS (r val) -> VS (r val)
binExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
powerOp

  log :: VS (PythonCode Value) -> VS (PythonCode Value)
log = VSUnOp PythonCode -> VS (PythonCode Value) -> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
 ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
logOp
  ln :: VS (PythonCode Value) -> VS (PythonCode Value)
ln = VSUnOp PythonCode -> VS (PythonCode Value) -> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
 ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
lnOp
  exp :: VS (PythonCode Value) -> VS (PythonCode Value)
exp = VSUnOp PythonCode -> VS (PythonCode Value) -> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
 ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
expOp
  sin :: VS (PythonCode Value) -> VS (PythonCode Value)
sin = VSUnOp PythonCode -> VS (PythonCode Value) -> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
 ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
sinOp
  cos :: VS (PythonCode Value) -> VS (PythonCode Value)
cos = VSUnOp PythonCode -> VS (PythonCode Value) -> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
 ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
cosOp
  tan :: VS (PythonCode Value) -> VS (PythonCode Value)
tan = VSUnOp PythonCode -> VS (PythonCode Value) -> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
 ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
tanOp
  csc :: VS (PythonCode Value) -> VS (PythonCode Value)
csc = VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
(ValueSym r val typ, Literal r val typ, NumericExpression r val,
 TypeElim r typ) =>
VS (r val) -> VS (r val)
G.csc
  sec :: VS (PythonCode Value) -> VS (PythonCode Value)
sec = VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
(ValueSym r val typ, Literal r val typ, NumericExpression r val,
 TypeElim r typ) =>
VS (r val) -> VS (r val)
G.sec
  cot :: VS (PythonCode Value) -> VS (PythonCode Value)
cot = VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
(ValueSym r val typ, Literal r val typ, NumericExpression r val,
 TypeElim r typ) =>
VS (r val) -> VS (r val)
G.cot
  arcsin :: VS (PythonCode Value) -> VS (PythonCode Value)
arcsin = VSUnOp PythonCode -> VS (PythonCode Value) -> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
 ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
asinOp
  arccos :: VS (PythonCode Value) -> VS (PythonCode Value)
arccos = VSUnOp PythonCode -> VS (PythonCode Value) -> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
 ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
acosOp
  arctan :: VS (PythonCode Value) -> VS (PythonCode Value)
arctan = VSUnOp PythonCode -> VS (PythonCode Value) -> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
 ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
atanOp
  floor :: VS (PythonCode Value) -> VS (PythonCode Value)
floor = VSUnOp PythonCode -> VS (PythonCode Value) -> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
 ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
floorOp
  ceil :: VS (PythonCode Value) -> VS (PythonCode Value)
ceil = VSUnOp PythonCode -> VS (PythonCode Value) -> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val,
 ValueSym r val typ) =>
VSUnOp r -> VS (r val) -> VS (r val)
unExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
ceilOp

instance BooleanExpression PythonCode Value where
  ?! :: VS (PythonCode Value) -> VS (PythonCode Value)
(?!) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSUnOp r -> VS (r typ) -> VS (r val) -> VS (r val)
typeUnExpr VSUnOp PythonCode
forall (r :: * -> *). UnaryOpSym r => VSUnOp r
notOp VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool
  ?&& :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
(?&&) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
andOp VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool
  ?|| :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
(?||) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
orOp VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool

instance Comparison PythonCode Value where
  ?< :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
(?<) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
lessOp VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool
  ?<= :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
(?<=) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
lessEqualOp VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool
  ?> :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
(?>) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
greaterOp VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool
  ?>= :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
(?>=) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
greaterEqualOp VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool
  ?== :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
(?==) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
equalOp VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool
  ?!= :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
(?!=) = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr VSUnOp PythonCode
forall (r :: * -> *). BinaryOpSym r => VSBinOp r
notEqualOp VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool

instance ValueExpression PythonCode Variable Value BinderD TypeData where
  inlineIf :: VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
inlineIf = VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, ValueElim r val, ValueSym r val typ) =>
VS (r val) -> VS (r val) -> VS (r val) -> VS (r val)
pyInlineIf

  funcAppMixedArgs :: MixedCall PythonCode Variable Value TypeData
funcAppMixedArgs = MixedCall PythonCode Variable Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
MixedCall r var val typ
G.funcAppMixedArgs
  extFuncAppMixedArgs :: String -> MixedCall PythonCode Variable Value TypeData
extFuncAppMixedArgs String
l String
n VS (PythonCode TypeData)
t [VS (PythonCode Value)]
ps NamedArgs PythonCode Variable Value
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 Variable Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
String -> MixedCall r var val typ
CS.extFuncAppMixedArgs String
l String
n VS (PythonCode TypeData)
t [VS (PythonCode Value)]
ps NamedArgs PythonCode Variable Value
ns
  libFuncAppMixedArgs :: String -> MixedCall PythonCode Variable Value TypeData
libFuncAppMixedArgs String
l String
n VS (PythonCode TypeData)
t [VS (PythonCode Value)]
ps NamedArgs PythonCode Variable Value
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 Variable Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
String -> MixedCall r var val typ
CS.extFuncAppMixedArgs String
l String
n VS (PythonCode TypeData)
t [VS (PythonCode Value)]
ps NamedArgs PythonCode Variable Value
ns

  lambda :: [VS (PythonCode BinderD)]
-> VS (PythonCode Value) -> VS (PythonCode Value)
lambda = ([PythonCode BinderD] -> PythonCode Value -> Body)
-> [VS (PythonCode BinderD)]
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall {k} (r :: k -> *) (binder :: k) (typ :: k) (var :: k)
       (val :: k).
(BinderElim r binder typ, RenderValue r var val typ, TypeSym r typ,
 ValueSym r val typ) =>
([r binder] -> r val -> Body)
-> [VS (r binder)] -> VS (r val) -> VS (r val)
G.lambda [PythonCode BinderD] -> PythonCode Value -> Body
forall {k} (r :: k -> *) (binder :: k) (val :: k).
(InternalBinderElim r binder, ValueElim r val) =>
[r binder] -> r val -> Body
pyLambda

  notNull :: VS (PythonCode Value) -> VS (PythonCode Value)
notNull = String -> VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k) (var :: k).
(ValueSym r val typ, Comparison r val, VariableSym r var typ,
 VariableValue r var val) =>
String -> VS (r val) -> VS (r val)
CP.notNull String
pyNull

instance OOValueExpression PythonCode Variable Value TypeData where
  newObjMixedArgs :: MixedCtorCall PythonCode Variable Value TypeData
newObjMixedArgs = MixedCall PythonCode Variable Value TypeData
forall (r :: * -> *) var val.
(RenderValue r var val TypeData, UnRepr r TypeData) =>
String -> MixedCtorCall r var val TypeData
G.newObjMixedArgs String
""
  extNewObjMixedArgs :: MixedCall PythonCode Variable Value TypeData
extNewObjMixedArgs String
l VS (PythonCode TypeData)
tp [VS (PythonCode Value)]
ps NamedArgs PythonCode Variable Value
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 Variable Value TypeData
forall (r :: * -> *) var val.
(RenderValue r var val TypeData, UnRepr r TypeData) =>
String -> MixedCtorCall r var val TypeData
pyExtNewObjMixedArgs String
l VS (PythonCode TypeData)
tp [VS (PythonCode Value)]
ps NamedArgs PythonCode Variable Value
ns
  libNewObjMixedArgs :: MixedCall PythonCode Variable Value TypeData
libNewObjMixedArgs String
l VS (PythonCode TypeData)
tp [VS (PythonCode Value)]
ps NamedArgs PythonCode Variable Value
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 Variable Value TypeData
forall (r :: * -> *) var val.
(RenderValue r var val TypeData, UnRepr r TypeData) =>
String -> MixedCtorCall r var val TypeData
pyExtNewObjMixedArgs String
l VS (PythonCode TypeData)
tp [VS (PythonCode Value)]
ps NamedArgs PythonCode Variable Value
ns

instance RenderValue PythonCode Variable Value TypeData where
  inputFunc :: VS (PythonCode Value)
inputFunc = VS (PythonCode TypeData) -> Body -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r typ) -> Body -> VS (r val)
mkStateVal VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
string Body
pyInputFunc
  printFunc :: VS (PythonCode Value)
printFunc = VS (PythonCode TypeData) -> Body -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r typ) -> Body -> VS (r val)
mkStateVal VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
void Body
pyPrintFunc
  printLnFunc :: VS (PythonCode Value)
printLnFunc = VS (PythonCode TypeData) -> Body -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r typ) -> Body -> VS (r val)
mkStateVal VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
void Body
empty
  printFileFunc :: VS (PythonCode Value) -> VS (PythonCode Value)
printFileFunc VS (PythonCode Value)
_ = VS (PythonCode TypeData) -> Body -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r typ) -> Body -> VS (r val)
mkStateVal VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
void Body
empty
  printFileLnFunc :: VS (PythonCode Value) -> VS (PythonCode Value)
printFileLnFunc VS (PythonCode Value)
_ = VS (PythonCode TypeData) -> Body -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r typ) -> Body -> VS (r val)
mkStateVal VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
void Body
empty

  cast :: VS (PythonCode TypeData)
-> VS (PythonCode Value) -> VS (PythonCode Value)
cast = (PythonCode TypeData -> PythonCode Value -> VS (PythonCode Value))
-> VS (PythonCode TypeData)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
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 -> Body -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
r typ -> Body -> VS (r val)
mkVal PythonCode TypeData
t (Body -> VS (PythonCode Value))
-> (Body -> Body) -> Body -> VS (PythonCode Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Body -> Body -> Body
R.castObj (PythonCode TypeData -> Body
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> Body
renderType PythonCode TypeData
t)
    (Body -> VS (PythonCode Value)) -> Body -> VS (PythonCode Value)
forall a b. (a -> b) -> a -> b
$ PythonCode Value -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value PythonCode Value
v)

  call :: Maybe String
-> Maybe Body -> MixedCall PythonCode Variable Value TypeData
call = Body
-> Maybe String
-> Maybe Body
-> MixedCall PythonCode Variable Value TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(InternalVarElim r var, RenderValue r var val typ,
 ValueElim r val) =>
Body -> Maybe String -> Maybe Body -> MixedCall r var val typ
G.call Body
pyNamedArgSep

  valFromData :: Maybe Int
-> Maybe Integer
-> VS (PythonCode TypeData)
-> Body
-> VS (PythonCode Value)
valFromData Maybe Int
p Maybe Integer
i VS (PythonCode TypeData)
t' Body
d = do
    t <- VS (PythonCode TypeData)
t'
    toState $ on2CodeValues (vd p i) t (toCode d)

instance ValueElim PythonCode Value 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 -> Body
value = Value -> Body
val (Value -> Body)
-> (PythonCode Value -> Value) -> PythonCode Value -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Value -> Value
forall a. PythonCode a -> a
unPC

instance InternalValueExp PythonCode Variable Value TypeData where
  objMethodCallMixedArgs' :: String
-> VS (PythonCode TypeData)
-> VS (PythonCode Value)
-> [VS (PythonCode Value)]
-> NamedArgs PythonCode Variable Value
-> VS (PythonCode Value)
objMethodCallMixedArgs' = String
-> VS (PythonCode TypeData)
-> VS (PythonCode Value)
-> [VS (PythonCode Value)]
-> NamedArgs PythonCode Variable Value
-> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, ValueElim r val) =>
String
-> VS (r typ)
-> VS (r val)
-> [VS (r val)]
-> NamedArgs r var val
-> VS (r val)
G.objMethodCall
  classMethodCallMixedArgs' :: String
-> VS (PythonCode TypeData)
-> MixedCtorCall PythonCode Variable Value TypeData
classMethodCallMixedArgs' = String
-> VS (PythonCode TypeData)
-> MixedCtorCall PythonCode Variable Value TypeData
forall (r :: * -> *) var val.
(RenderValue r var val TypeData, UnRepr r TypeData) =>
String
-> VS (r TypeData)
-> VS (r TypeData)
-> [VS (r val)]
-> NamedArgs r var val
-> VS (r val)
CG.classMethodCall

instance OOFunctionSym PythonCode Value TypeData where
  func :: String
-> VS (PythonCode TypeData)
-> [VS (PythonCode Value)]
-> VS (PythonCode FuncData)
func = String
-> VS (PythonCode TypeData)
-> [VS (PythonCode Value)]
-> VS (PythonCode FuncData)
forall (r :: * -> *) typ val var binder.
(RenderFunction r typ, ValueElim r val,
 ValueExpression r var val binder typ) =>
String -> VS (r typ) -> [VS (r val)] -> VS (r FuncData)
G.func
  objAccess :: VS (PythonCode Value)
-> VS (PythonCode FuncData) -> VS (PythonCode Value)
objAccess = VS (PythonCode Value)
-> VS (PythonCode FuncData) -> VS (PythonCode Value)
forall (r :: * -> *) typ var val.
(FunctionElim r typ, RenderValue r var val typ, ValueElim r val) =>
VS (r val) -> VS (r FuncData) -> VS (r val)
G.objAccess

instance GetSet PythonCode Variable Value where
  get :: VS (PythonCode Value)
-> VS (PythonCode Variable) -> VS (PythonCode Value)
get = VS (PythonCode Value)
-> VS (PythonCode Variable) -> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(InternalGetSet r var val typ, OOFunctionSym r val typ) =>
VS (r val) -> VS (r var) -> VS (r val)
G.get
  set :: VS (PythonCode Value)
-> VS (PythonCode Variable)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
set = VS (PythonCode Value)
-> VS (PythonCode Variable)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) val typ var.
(ValueSym r val typ, InternalGetSet r var val typ,
 OOFunctionSym r val typ) =>
VS (r val) -> VS (r var) -> VS (r val) -> VS (r val)
G.set

instance IndexTranslator PythonCode Value where
  intToIndex :: VS (PythonCode Value) -> VS (PythonCode Value)
intToIndex = VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k). VS (r val) -> VS (r val)
CP.intToIndex
  indexToInt :: VS (PythonCode Value) -> VS (PythonCode Value)
indexToInt = VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k). VS (r val) -> VS (r val)
CP.indexToInt

instance Reference PythonCode Value where
  makeRef :: VS (PythonCode Value) -> VS (PythonCode Value)
makeRef = VS (PythonCode Value) -> VS (PythonCode Value)
forall a. a -> a
id
  maybeDeref :: VS (PythonCode Value) -> VS (PythonCode Value)
maybeDeref = VS (PythonCode Value) -> VS (PythonCode Value)
forall a. a -> a
id

instance Array PythonCode Variable Value where
  arrayElem :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Variable)
arrayElem = VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Variable)
forall {k} (r :: k -> *) (typ :: k) (val :: k) (var :: k).
(TypeSym r typ, ValueSym r val typ, IndexTranslator r val,
 RenderVariable r var typ, ValueElim r val) =>
VS (r val) -> VS (r val) -> VS (r var)
G.arrayElem
  arrayLength :: VS (PythonCode Value) -> VS (PythonCode Value)
arrayLength = VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k).
List r val =>
VS (r val) -> VS (r val)
listSize
  arrayCopy :: VS (PythonCode Value) -> VS (PythonCode Value)
arrayCopy VS (PythonCode Value)
arr = let
    arrTp :: VS (PythonCode TypeData)
arrTp = (PythonCode Value -> PythonCode TypeData)
-> VS (PythonCode Value) -> VS (PythonCode TypeData)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue PythonCode Value -> PythonCode TypeData
forall {k} (r :: k -> *) (val :: k) (typ :: k).
ValueSym r val typ =>
r val -> r typ
valueType VS (PythonCode Value)
arr
    in VS (PythonCode TypeData)
-> VS (PythonCode Value)
-> String
-> [VS (PythonCode Value)]
-> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
InternalValueExp r var val typ =>
VS (r typ) -> VS (r val) -> String -> [VS (r val)] -> VS (r val)
objMethodCall VS (PythonCode TypeData)
arrTp VS (PythonCode Value)
arr String
"copy" []

instance List PythonCode Value where
  listSize :: VS (PythonCode Value) -> VS (PythonCode Value)
listSize = String -> VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k)
       (binder :: k).
(TypeSym r typ, ValueExpression r var val binder typ) =>
String -> VS (r val) -> VS (r val)
CS.listSize String
pyListSize
  listAccess :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
listAccess = VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
forall (r :: * -> *) typ val var.
(TypeSym r typ, ValueSym r val typ, IndexTranslator r val,
 InternalListFunc r val typ, FunctionElim r typ,
 RenderFunction r typ, RenderValue r var val typ, TypeElim r typ,
 ValueElim r val) =>
VS (r val) -> VS (r val) -> VS (r val)
G.listAccess
  indexOf :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
indexOf = String
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) typ val.
(TypeSym r typ, IndexTranslator r val, OOFunctionSym r val typ) =>
String -> VS (r val) -> VS (r val) -> VS (r val)
CP.indexOf String
pyIndex

instance ListStatement PythonCode Statement Value where
  listAdd :: VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
listAdd = String
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (typ :: k) (val :: k) (var :: k)
       (stmt :: k).
(TypeSym r typ, IndexTranslator r val,
 InternalValueExp r var val typ, ValueStatement r stmt val) =>
String -> VS (r val) -> VS (r val) -> VS (r val) -> MS (r stmt)
CG.listAdd String
pyInsert
  listAppend :: VS (PythonCode Value)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
listAppend = String
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k)
       (stmt :: k).
(TypeSym r typ, InternalValueExp r var val typ,
 ValueStatement r stmt val) =>
String -> VS (r val) -> VS (r val) -> MS (r stmt)
CG.listAppend String
pyAppendFunc
  listSet :: VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
listSet = VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k)
       (typ :: k).
(AssignStatement r stmt var val, ValueSym r val typ,
 IndexTranslator r val, RenderVariable r var typ,
 ValueElim r val) =>
VS (r val) -> VS (r val) -> VS (r val) -> MS (r stmt)
CP.listSet

instance Set PythonCode Value where
  contains :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
contains VS (PythonCode Value)
a VS (PythonCode Value)
b = VSUnOp PythonCode
-> VS (PythonCode TypeData)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall (r :: * -> *) var val typ.
(OpElim r, RenderValue r var val typ, ValueElim r val) =>
VSBinOp r -> VS (r typ) -> VS (r val) -> VS (r val) -> VS (r val)
typeBinExpr (String -> VSUnOp PythonCode
forall (r :: * -> *). Monad r => String -> VSOp r
inPrec String
pyIn) VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
bool VS (PythonCode Value)
b VS (PythonCode Value)
a
  setAdd :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
setAdd = String
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall {k} (r :: k -> *) (typ :: k) (val :: k) (var :: k).
(TypeSym r typ, ValueSym r val typ,
 InternalValueExp r var val typ) =>
String -> VS (r val) -> VS (r val) -> VS (r val)
CP.setMethodCall String
pyAdd
  setRemove :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
setRemove = String
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall {k} (r :: k -> *) (typ :: k) (val :: k) (var :: k).
(TypeSym r typ, ValueSym r val typ,
 InternalValueExp r var val typ) =>
String -> VS (r val) -> VS (r val) -> VS (r val)
CP.setMethodCall String
pyRemove
  setUnion :: VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
setUnion = String
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall {k} (r :: k -> *) (typ :: k) (val :: k) (var :: k).
(TypeSym r typ, ValueSym r val typ,
 InternalValueExp r var val typ) =>
String -> VS (r val) -> VS (r val) -> VS (r val)
CP.setMethodCall String
pyUnion

instance InternalList PythonCode Block Variable Value where
  listSlice' :: Maybe (VS (PythonCode Value))
-> Maybe (VS (PythonCode Value))
-> Maybe (VS (PythonCode Value))
-> VS (PythonCode Variable)
-> VS (PythonCode Value)
-> MS (PythonCode Body)
listSlice' Maybe (VS (PythonCode Value))
b Maybe (VS (PythonCode Value))
e Maybe (VS (PythonCode Value))
s VS (PythonCode Variable)
vn VS (PythonCode Value)
vo = VS (PythonCode Variable)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> MS (PythonCode Body)
forall (r :: * -> *) var val.
(InternalVarElim r var, Monad r, ValueElim r val) =>
VS (r var)
-> VS (r val)
-> VS (r val)
-> VS (r val)
-> VS (r val)
-> MS (r Body)
pyListSlice VS (PythonCode Variable)
vn VS (PythonCode Value)
vo (Maybe (VS (PythonCode Value)) -> VS (PythonCode Value)
getVal Maybe (VS (PythonCode Value))
b) (Maybe (VS (PythonCode Value)) -> VS (PythonCode Value)
getVal Maybe (VS (PythonCode Value))
e) (Maybe (VS (PythonCode Value)) -> VS (PythonCode Value)
getVal Maybe (VS (PythonCode Value))
s)
    where getVal :: Maybe (VS (PythonCode Value)) -> VS (PythonCode Value)
getVal = VS (PythonCode Value)
-> Maybe (VS (PythonCode Value)) -> VS (PythonCode Value)
forall a. a -> Maybe a -> a
fromMaybe (VS (PythonCode TypeData) -> Body -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r typ) -> Body -> VS (r val)
mkStateVal VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
void Body
empty)

instance InternalGetSet PythonCode Variable Value TypeData where
  getFunc :: VS (PythonCode Variable) -> VS (PythonCode FuncData)
getFunc = VS (PythonCode Variable) -> VS (PythonCode FuncData)
forall (r :: * -> *) val typ var.
(OOFunctionSym r val typ, VariableElim r var typ) =>
VS (r var) -> VS (r FuncData)
G.getFunc
  setFunc :: VS (PythonCode TypeData)
-> VS (PythonCode Variable)
-> VS (PythonCode Value)
-> VS (PythonCode FuncData)
setFunc = VS (PythonCode TypeData)
-> VS (PythonCode Variable)
-> VS (PythonCode Value)
-> VS (PythonCode FuncData)
forall (r :: * -> *) val typ var.
(OOFunctionSym r val typ, VariableElim r var typ) =>
VS (r typ) -> VS (r var) -> VS (r val) -> VS (r FuncData)
G.setFunc

instance InternalListFunc PythonCode Value TypeData where
  listAccessFunc :: VS (PythonCode TypeData)
-> VS (PythonCode Value) -> VS (PythonCode FuncData)
listAccessFunc = VS (PythonCode TypeData)
-> VS (PythonCode Value) -> VS (PythonCode FuncData)
forall (r :: * -> *) typ val.
(RenderFunction r typ, TypeElim r typ, ValueElim r val,
 ValueSym r val typ) =>
VS (r typ) -> VS (r val) -> VS (r FuncData)
CS.listAccessFunc

instance BinderSym PythonCode BinderD TypeData where
  binder :: String -> VS (PythonCode TypeData) -> VS (PythonCode BinderD)
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) -> VS (PythonCode BinderD)
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
<$> VS (PythonCode TypeData)
tp

instance BinderElim PythonCode BinderD TypeData 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 BinderD where
  binderElim :: PythonCode BinderD -> Body
binderElim = String -> Body
text (String -> Body)
-> (PythonCode BinderD -> String) -> PythonCode BinderD -> Body
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 TypeData where
  funcFromData :: Body -> VS (PythonCode TypeData) -> VS (PythonCode FuncData)
funcFromData Body
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 -> Body -> FuncData
`fd` Body
d))

instance FunctionElim PythonCode TypeData 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 -> Body
function = FuncData -> Body
funcDoc (FuncData -> Body)
-> (PythonCode FuncData -> FuncData) -> PythonCode FuncData -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode FuncData -> FuncData
forall a. PythonCode a -> a
unPC

instance InternalAssignStmt PythonCode Statement Variable Value where
  multiAssign :: [VS (PythonCode Variable)]
-> [VS (PythonCode Value)] -> MS (PythonCode Statement)
multiAssign = (Body -> Body)
-> [VS (PythonCode Variable)]
-> [VS (PythonCode Value)]
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (typ :: k) (stmt :: k) (var :: k)
       (val :: k).
(TypeSym r typ, AssignStatement r stmt var val,
 InternalVarElim r var, RenderValue r var val typ,
 RenderVariable r var typ, ValueElim r val) =>
(Body -> Body) -> [VS (r var)] -> [VS (r val)] -> MS (r stmt)
CP.multiAssign Body -> Body
forall a. a -> a
id

instance InternalIOStmt PythonCode Statement Value where
  printSt :: Bool
-> Maybe (VS (PythonCode Value))
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
printSt = Bool
-> Maybe (VS (PythonCode Value))
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
pyPrint

instance InternalControlStmt PythonCode Statement Value where
  multiReturn :: [VS (PythonCode Value)] -> MS (PythonCode Statement)
multiReturn = (Body -> Body)
-> [VS (PythonCode Value)] -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (typ :: k) (bod :: k) (stmt :: k)
       (var :: k) (val :: k).
(TypeSym r typ, ControlStatement r bod stmt var val,
 RenderValue r var val typ, ValueElim r val) =>
(Body -> Body) -> [VS (r val)] -> MS (r stmt)
CP.multiReturn Body -> Body
forall a. a -> a
id

instance RenderStatement PythonCode Statement where
  stmt :: MS (PythonCode Statement) -> MS (PythonCode Statement)
stmt = MS (PythonCode Statement) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k).
(RenderStatement r stmt, StatementElim r stmt) =>
MS (r stmt) -> MS (r stmt)
G.stmt
  loopStmt :: MS (PythonCode Statement) -> MS (PythonCode Statement)
loopStmt = MS (PythonCode Statement) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k).
(RenderStatement r stmt, StatementElim r stmt) =>
MS (r stmt) -> MS (r stmt)
G.loopStmt
  stmtFromData :: Body -> Terminator -> MS (PythonCode Statement)
stmtFromData Body
d Terminator
t = PythonCode Statement -> MS (PythonCode Statement)
forall a s. a -> State s a
toState (PythonCode Statement -> MS (PythonCode Statement))
-> PythonCode Statement -> MS (PythonCode Statement)
forall a b. (a -> b) -> a -> b
$ Statement -> PythonCode Statement
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Body
d, Terminator
t)

instance StatementElim PythonCode Statement where
  statement :: PythonCode Statement -> Body
statement = Statement -> Body
forall a b. (a, b) -> a
fst (Statement -> Body)
-> (PythonCode Statement -> Statement)
-> PythonCode Statement
-> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Statement -> Statement
forall a. PythonCode a -> a
unPC
  statementTerm :: PythonCode Statement -> Terminator
statementTerm = Statement -> Terminator
forall a b. (a, b) -> b
snd (Statement -> Terminator)
-> (PythonCode Statement -> Statement)
-> PythonCode Statement
-> Terminator
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Statement -> Statement
forall a. PythonCode a -> a
unPC

instance EmptyStatement PythonCode Statement where
  emptyStmt :: MS (PythonCode Statement)
emptyStmt = MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k).
RenderStatement r stmt =>
MS (r stmt)
G.emptyStmt

instance MultiStatement PythonCode Statement where
  multi :: [MS (PythonCode Statement)] -> MS (PythonCode Statement)
multi = ([PythonCode Statement] -> PythonCode Statement)
-> [MS (PythonCode Statement)] -> MS (PythonCode Statement)
forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList (([Statement] -> Statement)
-> [PythonCode Statement] -> PythonCode Statement
forall (m :: * -> *) a b. Monad m => ([a] -> b) -> [m a] -> m b
onCodeList [Statement] -> Statement
R.multiStmt)

instance ValueStatement PythonCode Statement Value where
  valStmt :: VS (PythonCode Value) -> MS (PythonCode Statement)
valStmt = Terminator -> VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
(RenderStatement r stmt, ValueElim r val) =>
Terminator -> VS (r val) -> MS (r stmt)
G.valStmt Terminator
Empty

instance AssignStatement PythonCode Statement Variable Value where
  assign :: VS (PythonCode Variable)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
assign = Terminator
-> VS (PythonCode Variable)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (var :: k) (stmt :: k) (val :: k).
(InternalVarElim r var, RenderStatement r stmt, ValueElim r val) =>
Terminator -> VS (r var) -> VS (r val) -> MS (r stmt)
G.assign Terminator
Empty
  &-= :: VS (PythonCode Variable)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
(&-=) = Terminator
-> VS (PythonCode Variable)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (var :: k) (stmt :: k) (val :: k).
(InternalVarElim r var, RenderStatement r stmt, ValueElim r val) =>
Terminator -> VS (r var) -> VS (r val) -> MS (r stmt)
G.subAssign Terminator
Empty
  &+= :: VS (PythonCode Variable)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
(&+=) = VS (PythonCode Variable)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (var :: k) (stmt :: k) (val :: k).
(InternalVarElim r var, RenderStatement r stmt, ValueElim r val) =>
VS (r var) -> VS (r val) -> MS (r stmt)
CS.increment
  &++ :: VS (PythonCode Variable) -> MS (PythonCode Statement)
(&++) = VS (PythonCode Variable) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k)
       (typ :: k).
(AssignStatement r stmt var val, Literal r val typ) =>
VS (r var) -> MS (r stmt)
M.increment1
  &-- :: VS (PythonCode Variable) -> MS (PythonCode Statement)
(&--) = VS (PythonCode Variable) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k)
       (typ :: k).
(AssignStatement r stmt var val, Literal r val typ) =>
VS (r var) -> MS (r stmt)
M.decrement1

instance DeclStatement PythonCode Body Statement Variable ScopeData Value where
  varDec :: VS (PythonCode Variable)
-> PythonCode ScopeData -> MS (PythonCode Statement)
varDec VS (PythonCode Variable)
v PythonCode ScopeData
scp = VS (PythonCode Variable)
-> PythonCode ScopeData
-> Maybe (VS (PythonCode Value))
-> MS (PythonCode Statement)
forall (r :: * -> *) stmt var val typ.
(EmptyStatement r stmt, AssignStatement r stmt var val,
 ScopeElim r ScopeData, VariableElim r var typ) =>
VS (r var) -> r ScopeData -> Maybe (VS (r val)) -> MS (r stmt)
CS.varDecDef VS (PythonCode Variable)
v PythonCode ScopeData
scp Maybe (VS (PythonCode Value))
forall a. Maybe a
Nothing
  varDecDef :: VS (PythonCode Variable)
-> PythonCode ScopeData
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
varDecDef VS (PythonCode Variable)
v PythonCode ScopeData
scp VS (PythonCode Value)
e = VS (PythonCode Variable)
-> PythonCode ScopeData
-> Maybe (VS (PythonCode Value))
-> MS (PythonCode Statement)
forall (r :: * -> *) stmt var val typ.
(EmptyStatement r stmt, AssignStatement r stmt var val,
 ScopeElim r ScopeData, VariableElim r var typ) =>
VS (r var) -> r ScopeData -> Maybe (VS (r val)) -> MS (r stmt)
CS.varDecDef VS (PythonCode Variable)
v PythonCode ScopeData
scp (VS (PythonCode Value) -> Maybe (VS (PythonCode Value))
forall a. a -> Maybe a
Just VS (PythonCode Value)
e)
  setDec :: VS (PythonCode Variable)
-> PythonCode ScopeData -> MS (PythonCode Statement)
setDec = VS (PythonCode Variable)
-> PythonCode ScopeData -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
       (scope :: k) (val :: k).
DeclStatement r bod stmt var scope val =>
VS (r var) -> r scope -> MS (r stmt)
varDec
  setDecDef :: VS (PythonCode Variable)
-> PythonCode ScopeData
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
setDecDef = VS (PythonCode Variable)
-> PythonCode ScopeData
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
       (scope :: k) (val :: k).
DeclStatement r bod stmt var scope val =>
VS (r var) -> r scope -> VS (r val) -> MS (r stmt)
varDecDef
  listDec :: Integer
-> VS (PythonCode Variable)
-> PythonCode ScopeData
-> MS (PythonCode Statement)
listDec Integer
_ = VS (PythonCode Variable)
-> PythonCode ScopeData -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
       (scope :: k) (val :: k) (typ :: k).
(DeclStatement r bod stmt var scope val, TypeSym r typ,
 Literal r val typ, VariableElim r var typ) =>
VS (r var) -> r scope -> MS (r stmt)
CP.listDec
  listDecDef :: VS (PythonCode Variable)
-> PythonCode ScopeData
-> [VS (PythonCode Value)]
-> MS (PythonCode Statement)
listDecDef = VS (PythonCode Variable)
-> PythonCode ScopeData
-> [VS (PythonCode Value)]
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
       (scope :: k) (val :: k) (typ :: k).
(DeclStatement r bod stmt var scope val, TypeSym r typ,
 Literal r val typ, VariableElim r var typ) =>
VS (r var) -> r scope -> [VS (r val)] -> MS (r stmt)
CP.listDecDef
  arrayDec :: Integer
-> VS (PythonCode Value)
-> VS (PythonCode Variable)
-> PythonCode ScopeData
-> MS (PythonCode Statement)
arrayDec = Integer
-> VS (PythonCode Value)
-> VS (PythonCode Variable)
-> PythonCode ScopeData
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (block :: k) (stmt :: k)
       (var :: k) (scope :: k) (val :: k) (typ :: k).
(BodySym r bod block, BlockSym r block stmt, MultiStatement r stmt,
 DeclStatement r bod stmt var scope val,
 ControlStatement r bod stmt var val, TypeSym r typ,
 Literal r val typ, VariableSym r var typ, VariableValue r var val,
 ListStatement r stmt val, VariableElim r var typ) =>
Integer -> VS (r val) -> VS (r var) -> r scope -> MS (r stmt)
M.arrayDecAsList
  arrayDecDef :: VS (PythonCode Variable)
-> PythonCode ScopeData
-> [VS (PythonCode Value)]
-> MS (PythonCode Statement)
arrayDecDef = VS (PythonCode Variable)
-> PythonCode ScopeData
-> [VS (PythonCode Value)]
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
       (scope :: k) (val :: k).
DeclStatement r bod stmt var scope val =>
VS (r var) -> r scope -> [VS (r val)] -> MS (r stmt)
listDecDef
  constDecDef :: VS (PythonCode Variable)
-> PythonCode ScopeData
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
constDecDef VS (PythonCode Variable)
v PythonCode ScopeData
scp VS (PythonCode Value)
e = do
    v' <- LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Variable))
  MethodState
  ValueState
-> VS (PythonCode Variable)
-> 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 VS (PythonCode Variable)
v
    let n = String -> String
toConstName (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ PythonCode Variable -> String
forall {k} (r :: k -> *) (var :: k) (typ :: k).
VariableElim r var typ =>
r var -> String
variableName PythonCode Variable
v'
        newConst = String -> VS (PythonCode TypeData) -> VS (PythonCode Variable)
forall {k} (r :: k -> *) (var :: k) (typ :: k).
VariableSym r var typ =>
String -> VS (r typ) -> VS (r var)
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 {k} (r :: k -> *) (var :: k) (typ :: k).
VariableElim r var typ =>
r var -> r typ
variableType PythonCode Variable
v'))
    available <- varNameAvailable n
    if available
      then varDecDef newConst scp e
      else error "Cannot safely capitalize constant."
  funcDecDef :: VS (PythonCode Variable)
-> PythonCode ScopeData
-> [VS (PythonCode Variable)]
-> MS (PythonCode Body)
-> MS (PythonCode Statement)
funcDecDef = VS (PythonCode Variable)
-> PythonCode ScopeData
-> [VS (PythonCode Variable)]
-> MS (PythonCode Body)
-> MS (PythonCode Statement)
forall (r :: * -> *) file mod cls stvr mthd attch vis param bod
       block stmt var val binder typ.
OORenderSym
  r
  file
  mod
  cls
  stvr
  mthd
  attch
  vis
  param
  bod
  block
  stmt
  var
  ScopeData
  val
  binder
  typ =>
VS (r var)
-> r ScopeData -> [VS (r var)] -> MS (r bod) -> MS (r stmt)
CP.funcDecDef

instance OODeclStatement PythonCode Statement Variable ScopeData Value where
  objDecDef :: VS (PythonCode Variable)
-> PythonCode ScopeData
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
objDecDef = VS (PythonCode Variable)
-> PythonCode ScopeData
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
       (scope :: k) (val :: k).
DeclStatement r bod stmt var scope val =>
VS (r var) -> r scope -> VS (r val) -> MS (r stmt)
varDecDef
  objDecNew :: VS (PythonCode Variable)
-> PythonCode ScopeData
-> [VS (PythonCode Value)]
-> MS (PythonCode Statement)
objDecNew = VS (PythonCode Variable)
-> PythonCode ScopeData
-> [VS (PythonCode Value)]
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
       (scope :: k) (val :: k) (typ :: k).
(DeclStatement r bod stmt var scope val,
 OOValueExpression r var val typ, VariableElim r var typ) =>
VS (r var) -> r scope -> [VS (r val)] -> MS (r stmt)
G.objDecNew
  extObjDecNew :: String
-> VS (PythonCode Variable)
-> PythonCode ScopeData
-> [VS (PythonCode Value)]
-> MS (PythonCode Statement)
extObjDecNew String
lib VS (PythonCode Variable)
v PythonCode ScopeData
scp [VS (PythonCode Value)]
vs = do
    (MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> MethodState -> MethodState
addModuleImport String
lib)
    VS (PythonCode Variable)
-> PythonCode ScopeData
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
       (scope :: k) (val :: k).
DeclStatement r bod stmt var scope val =>
VS (r var) -> r scope -> VS (r val) -> MS (r stmt)
varDecDef VS (PythonCode Variable)
v PythonCode ScopeData
scp (String
-> VS (PythonCode TypeData)
-> [VS (PythonCode Value)]
-> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
OOValueExpression r var val typ =>
String -> PosCtorCall r val typ
extNewObj String
lib ((PythonCode Variable -> PythonCode TypeData)
-> VS (PythonCode Variable) -> VS (PythonCode TypeData)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue PythonCode Variable -> PythonCode TypeData
forall {k} (r :: k -> *) (var :: k) (typ :: k).
VariableElim r var typ =>
r var -> r typ
variableType VS (PythonCode Variable)
v) [VS (PythonCode Value)]
vs)

instance PrintConsole PythonCode Statement Value where
  print :: VS (PythonCode Value) -> MS (PythonCode Statement)
print      = Bool
-> Maybe (VS (PythonCode Value))
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (block :: k) (stmt :: k)
       (typ :: k) (val :: k) (var :: k) (scope :: k).
(BodySym r bod block, BlockSym r block stmt, TypeSym r typ,
 ValueSym r val typ, Literal r val typ, NumericExpression r val,
 Comparison r val, VariableSym r var typ, VariableValue r var val,
 List r val, ScopeSym r scope, MultiStatement r stmt,
 DeclStatement r bod stmt var scope val,
 AssignStatement r stmt var val,
 ControlStatement r bod stmt var val, PrintConsole r stmt val,
 PrintFile r stmt val, InternalIOStmt r stmt val, TypeElim r typ) =>
Bool
-> Maybe (VS (r val)) -> VS (r val) -> VS (r val) -> MS (r stmt)
pyOut Bool
False Maybe (VS (PythonCode Value))
forall a. Maybe a
Nothing VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r val)
printFunc
  printLn :: VS (PythonCode Value) -> MS (PythonCode Statement)
printLn    = Bool
-> Maybe (VS (PythonCode Value))
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (block :: k) (stmt :: k)
       (typ :: k) (val :: k) (var :: k) (scope :: k).
(BodySym r bod block, BlockSym r block stmt, TypeSym r typ,
 ValueSym r val typ, Literal r val typ, NumericExpression r val,
 Comparison r val, VariableSym r var typ, VariableValue r var val,
 List r val, ScopeSym r scope, MultiStatement r stmt,
 DeclStatement r bod stmt var scope val,
 AssignStatement r stmt var val,
 ControlStatement r bod stmt var val, PrintConsole r stmt val,
 PrintFile r stmt val, InternalIOStmt r stmt val, TypeElim r typ) =>
Bool
-> Maybe (VS (r val)) -> VS (r val) -> VS (r val) -> MS (r stmt)
pyOut Bool
True  Maybe (VS (PythonCode Value))
forall a. Maybe a
Nothing VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r val)
printFunc
  printStr :: String -> MS (PythonCode Statement)
printStr   = VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
PrintConsole r stmt val =>
VS (r val) -> MS (r stmt)
print   (VS (PythonCode Value) -> MS (PythonCode Statement))
-> (String -> VS (PythonCode Value))
-> String
-> MS (PythonCode Statement)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString
  printStrLn :: String -> MS (PythonCode Statement)
printStrLn = VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
PrintConsole r stmt val =>
VS (r val) -> MS (r stmt)
printLn (VS (PythonCode Value) -> MS (PythonCode Statement))
-> (String -> VS (PythonCode Value))
-> String
-> MS (PythonCode Statement)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString

instance ReadConsole PythonCode Statement Variable where
  getInput :: VS (PythonCode Variable) -> MS (PythonCode Statement)
getInput = VS (PythonCode Value)
-> VS (PythonCode Variable) -> MS (PythonCode Statement)
pyInput VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r val)
inputFunc
  discardInput :: MS (PythonCode Statement)
discardInput = VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
ValueStatement r stmt val =>
VS (r val) -> MS (r stmt)
valStmt VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r val)
inputFunc

instance FileHandling PythonCode Statement Variable Value where
  openFileR :: VS (PythonCode Variable)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
openFileR VS (PythonCode Variable)
f VS (PythonCode Value)
n = VS (PythonCode Variable)
f VS (PythonCode Variable)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
AssignStatement r stmt var val =>
VS (r var) -> VS (r val) -> MS (r stmt)
&= VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (typ :: k) (val :: k) (var :: k)
       (binder :: k).
(TypeSym r typ, Literal r val typ,
 ValueExpression r var val binder typ) =>
VS (r val) -> VS (r val)
CP.openFileR' VS (PythonCode Value)
n
  openFileW :: VS (PythonCode Variable)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
openFileW VS (PythonCode Variable)
f VS (PythonCode Value)
n = VS (PythonCode Variable)
f VS (PythonCode Variable)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
AssignStatement r stmt var val =>
VS (r var) -> VS (r val) -> MS (r stmt)
&= VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (typ :: k) (val :: k) (var :: k)
       (binder :: k).
(TypeSym r typ, Literal r val typ,
 ValueExpression r var val binder typ) =>
VS (r val) -> VS (r val)
CP.openFileW' VS (PythonCode Value)
n
  openFileA :: VS (PythonCode Variable)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
openFileA VS (PythonCode Variable)
f VS (PythonCode Value)
n = VS (PythonCode Variable)
f VS (PythonCode Variable)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
AssignStatement r stmt var val =>
VS (r var) -> VS (r val) -> MS (r stmt)
&= VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (typ :: k) (val :: k) (var :: k)
       (binder :: k).
(TypeSym r typ, Literal r val typ,
 ValueExpression r var val binder typ) =>
VS (r val) -> VS (r val)
CP.openFileA' VS (PythonCode Value)
n
  closeFile :: VS (PythonCode Value) -> MS (PythonCode Statement)
closeFile = String -> VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k)
       (stmt :: k).
(TypeSym r typ, InternalValueExp r var val typ,
 ValueStatement r stmt val) =>
String -> VS (r val) -> MS (r stmt)
G.closeFile String
pyClose

instance ReadFile PythonCode Statement Variable Value where
  getFileInput :: VS (PythonCode Value)
-> VS (PythonCode Variable) -> MS (PythonCode Statement)
getFileInput VS (PythonCode Value)
f = VS (PythonCode Value)
-> VS (PythonCode Variable) -> MS (PythonCode Statement)
pyInput (VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k).
(TypeSym r typ, InternalValueExp r var val typ) =>
VS (r val) -> VS (r val)
readline VS (PythonCode Value)
f)
  discardFileInput :: VS (PythonCode Value) -> MS (PythonCode Statement)
discardFileInput VS (PythonCode Value)
f = VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
ValueStatement r stmt val =>
VS (r val) -> MS (r stmt)
valStmt (VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k).
(TypeSym r typ, InternalValueExp r var val typ) =>
VS (r val) -> VS (r val)
readline VS (PythonCode Value)
f)
  getFileInputLine :: VS (PythonCode Value)
-> VS (PythonCode Variable) -> MS (PythonCode Statement)
getFileInputLine = VS (PythonCode Value)
-> VS (PythonCode Variable) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
ReadFile r stmt var val =>
VS (r val) -> VS (r var) -> MS (r stmt)
getFileInput
  discardFileLine :: VS (PythonCode Value) -> MS (PythonCode Statement)
discardFileLine = String -> VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k)
       (stmt :: k).
(TypeSym r typ, InternalValueExp r var val typ,
 ValueStatement r stmt val) =>
String -> VS (r val) -> MS (r stmt)
CP.discardFileLine String
pyReadline
  getFileInputAll :: VS (PythonCode Value)
-> VS (PythonCode Variable) -> MS (PythonCode Statement)
getFileInputAll VS (PythonCode Value)
f VS (PythonCode Variable)
v = VS (PythonCode Variable)
v VS (PythonCode Variable)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
AssignStatement r stmt var val =>
VS (r var) -> VS (r val) -> MS (r stmt)
&= VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k).
(TypeSym r typ, InternalValueExp r var val typ) =>
VS (r val) -> VS (r val)
readlines VS (PythonCode Value)
f

instance PrintFile PythonCode Statement Value where
  printFile :: VS (PythonCode Value)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
printFile VS (PythonCode Value)
f      = Bool
-> Maybe (VS (PythonCode Value))
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (block :: k) (stmt :: k)
       (typ :: k) (val :: k) (var :: k) (scope :: k).
(BodySym r bod block, BlockSym r block stmt, TypeSym r typ,
 ValueSym r val typ, Literal r val typ, NumericExpression r val,
 Comparison r val, VariableSym r var typ, VariableValue r var val,
 List r val, ScopeSym r scope, MultiStatement r stmt,
 DeclStatement r bod stmt var scope val,
 AssignStatement r stmt var val,
 ControlStatement r bod stmt var val, PrintConsole r stmt val,
 PrintFile r stmt val, InternalIOStmt r stmt val, TypeElim r typ) =>
Bool
-> Maybe (VS (r val)) -> VS (r val) -> VS (r val) -> MS (r stmt)
pyOut Bool
False (VS (PythonCode Value) -> Maybe (VS (PythonCode Value))
forall a. a -> Maybe a
Just VS (PythonCode Value)
f) VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r val)
printFunc
  printFileLn :: VS (PythonCode Value)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
printFileLn VS (PythonCode Value)
f    = Bool
-> Maybe (VS (PythonCode Value))
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (block :: k) (stmt :: k)
       (typ :: k) (val :: k) (var :: k) (scope :: k).
(BodySym r bod block, BlockSym r block stmt, TypeSym r typ,
 ValueSym r val typ, Literal r val typ, NumericExpression r val,
 Comparison r val, VariableSym r var typ, VariableValue r var val,
 List r val, ScopeSym r scope, MultiStatement r stmt,
 DeclStatement r bod stmt var scope val,
 AssignStatement r stmt var val,
 ControlStatement r bod stmt var val, PrintConsole r stmt val,
 PrintFile r stmt val, InternalIOStmt r stmt val, TypeElim r typ) =>
Bool
-> Maybe (VS (r val)) -> VS (r val) -> VS (r val) -> MS (r stmt)
pyOut Bool
True  (VS (PythonCode Value) -> Maybe (VS (PythonCode Value))
forall a. a -> Maybe a
Just VS (PythonCode Value)
f) VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r val)
printFunc
  printFileStr :: VS (PythonCode Value) -> String -> MS (PythonCode Statement)
printFileStr VS (PythonCode Value)
f   = VS (PythonCode Value)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
PrintFile r stmt val =>
VS (r val) -> VS (r val) -> MS (r stmt)
printFile VS (PythonCode Value)
f   (VS (PythonCode Value) -> MS (PythonCode Statement))
-> (String -> VS (PythonCode Value))
-> String
-> MS (PythonCode Statement)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString
  printFileStrLn :: VS (PythonCode Value) -> String -> MS (PythonCode Statement)
printFileStrLn VS (PythonCode Value)
f = VS (PythonCode Value)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
PrintFile r stmt val =>
VS (r val) -> VS (r val) -> MS (r stmt)
printFileLn VS (PythonCode Value)
f (VS (PythonCode Value) -> MS (PythonCode Statement))
-> (String -> VS (PythonCode Value))
-> String
-> MS (PythonCode Statement)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString

instance StringStatement PythonCode Statement Variable Value where
  stringSplit :: Char
-> VS (PythonCode Variable)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
stringSplit Char
d VS (PythonCode Variable)
vnew VS (PythonCode Value)
s = VS (PythonCode Variable)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
AssignStatement r stmt var val =>
VS (r var) -> VS (r val) -> MS (r stmt)
assign VS (PythonCode Variable)
vnew (VS (PythonCode Value)
-> VS (PythonCode FuncData) -> VS (PythonCode Value)
forall (r :: * -> *) val typ.
OOFunctionSym r val typ =>
VS (r val) -> VS (r FuncData) -> VS (r val)
objAccess VS (PythonCode Value)
s (Char -> VS (PythonCode FuncData)
forall (r :: * -> *) typ val.
(TypeSym r typ, Literal r val typ, OOFunctionSym r val typ) =>
Char -> VS (r FuncData)
splitFunc Char
d))

  stringListVals :: [VS (PythonCode Variable)]
-> VS (PythonCode Value) -> MS (PythonCode Statement)
stringListVals = [VS (PythonCode Variable)]
-> VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k)
       (typ :: k).
(MultiStatement r stmt, AssignStatement r stmt var val, List r val,
 ValueSym r val typ, Literal r val typ, RenderValue r var val typ,
 TypeElim r typ, VariableElim r var typ) =>
[VS (r var)] -> VS (r val) -> MS (r stmt)
M.stringListVals
  stringListLists :: [VS (PythonCode Variable)]
-> VS (PythonCode Value) -> MS (PythonCode Statement)
stringListLists = [VS (PythonCode Variable)]
-> VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (block :: k) (stmt :: k)
       (var :: k) (val :: k) (typ :: k).
(BodySym r bod block, BlockSym r block stmt,
 ControlStatement r bod stmt var val, TypeSym r typ,
 ValueSym r val typ, Literal r val typ, NumericExpression r val,
 VariableSym r var typ, VariableValue r var val, List r val,
 ListStatement r stmt val, TypeElim r typ, VariableElim r var typ,
 RenderValue r var val typ) =>
[VS (r var)] -> VS (r val) -> MS (r stmt)
M.stringListLists

instance FuncAppStatement PythonCode Statement Variable Value where
  inOutCall :: InOutCall PythonCode Statement Variable Value
inOutCall = (String
 -> VS (PythonCode TypeData)
 -> [VS (PythonCode Value)]
 -> VS (PythonCode Value))
-> InOutCall PythonCode Statement Variable Value
forall {k} (r :: k -> *) (typ :: k) (stmt :: k) (var :: k)
       (val :: k).
(TypeSym r typ, InternalAssignStmt r stmt var val,
 ValueStatement r stmt val, VariableValue r var val) =>
(String -> VS (r typ) -> [VS (r val)] -> VS (r val))
-> String
-> [VS (r val)]
-> [VS (r var)]
-> [VS (r var)]
-> MS (r stmt)
CP.inOutCall String
-> VS (PythonCode TypeData)
-> [VS (PythonCode Value)]
-> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
       (typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp
  extInOutCall :: String -> InOutCall PythonCode Statement Variable Value
extInOutCall String
m = (String
 -> VS (PythonCode TypeData)
 -> [VS (PythonCode Value)]
 -> VS (PythonCode Value))
-> InOutCall PythonCode Statement Variable Value
forall {k} (r :: k -> *) (typ :: k) (stmt :: k) (var :: k)
       (val :: k).
(TypeSym r typ, InternalAssignStmt r stmt var val,
 ValueStatement r stmt val, VariableValue r var val) =>
(String -> VS (r typ) -> [VS (r val)] -> VS (r val))
-> String
-> [VS (r val)]
-> [VS (r var)]
-> [VS (r var)]
-> MS (r stmt)
CP.inOutCall (String
-> String
-> VS (PythonCode TypeData)
-> [VS (PythonCode Value)]
-> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
       (typ :: k).
ValueExpression r var val binder typ =>
String -> PosCall r val typ
extFuncApp String
m)

instance OOFuncAppStatement PythonCode Statement Variable Value where
  selfInOutCall :: InOutCall PythonCode Statement Variable Value
selfInOutCall = (String
 -> VS (PythonCode TypeData)
 -> [VS (PythonCode Value)]
 -> VS (PythonCode Value))
-> InOutCall PythonCode Statement Variable Value
forall {k} (r :: k -> *) (typ :: k) (stmt :: k) (var :: k)
       (val :: k).
(TypeSym r typ, InternalAssignStmt r stmt var val,
 ValueStatement r stmt val, VariableValue r var val) =>
(String -> VS (r typ) -> [VS (r val)] -> VS (r val))
-> String
-> [VS (r val)]
-> [VS (r var)]
-> [VS (r var)]
-> MS (r stmt)
CP.inOutCall String
-> VS (PythonCode TypeData)
-> [VS (PythonCode Value)]
-> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(InternalValueExp r var val typ, VariableValue r var val,
 SelfSym r var) =>
PosCall r val typ
selfMethodCall

instance CommentStatement PythonCode Statement where
  comment :: String -> MS (PythonCode Statement)
comment = Body -> String -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k).
RenderStatement r stmt =>
Body -> String -> MS (r stmt)
G.comment Body
pyCommentStart

instance ControlStatement PythonCode Body Statement Variable Value where
  break :: MS (PythonCode Statement)
break = Body -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k).
RenderStatement r stmt =>
Body -> MS (r stmt)
mkStmtNoEnd Body
R.break
  continue :: MS (PythonCode Statement)
continue = Body -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k).
RenderStatement r stmt =>
Body -> MS (r stmt)
mkStmtNoEnd Body
R.continue

  returnStmt :: VS (PythonCode Value) -> MS (PythonCode Statement)
returnStmt = Terminator -> VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
(RenderStatement r stmt, ValueElim r val) =>
Terminator -> VS (r val) -> MS (r stmt)
G.returnStmt Terminator
Empty

  throw :: String -> MS (PythonCode Statement)
throw = (PythonCode Value -> Body)
-> Terminator -> String -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (val :: k) (typ :: k) (stmt :: k).
(Literal r val typ, RenderStatement r stmt) =>
(r val -> Body) -> Terminator -> String -> MS (r stmt)
G.throw PythonCode Value -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
pyThrow Terminator
Empty

  ifCond :: [(VS (PythonCode Value), MS (PythonCode Body))]
-> MS (PythonCode Body) -> MS (PythonCode Statement)
ifCond = (Body -> Body)
-> Body
-> OptionalSpace
-> Body
-> Body
-> Body
-> [(VS (PythonCode Value), MS (PythonCode Body))]
-> MS (PythonCode Body)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (val :: k).
(BodyElim r bod, RenderStatement r stmt, ValueElim r val) =>
(Body -> Body)
-> Body
-> OptionalSpace
-> Body
-> Body
-> Body
-> [(VS (r val), MS (r bod))]
-> MS (r bod)
-> MS (r stmt)
G.ifCond Body -> Body
forall a. a -> a
id Body
pyBodyStart OptionalSpace
pySpace Body
pyElseIf Body
pyBodyEnd Body
empty
  switch :: VS (PythonCode Value)
-> [(VS (PythonCode Value), MS (PythonCode Body))]
-> MS (PythonCode Body)
-> MS (PythonCode Statement)
switch = VS (PythonCode Value)
-> [(VS (PythonCode Value), MS (PythonCode Body))]
-> MS (PythonCode Body)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
       (val :: k).
(ControlStatement r bod stmt var val, Comparison r val) =>
VS (r val)
-> [(VS (r val), MS (r bod))] -> MS (r bod) -> MS (r stmt)
switchAsIf

  ifExists :: VS (PythonCode Value)
-> MS (PythonCode Body)
-> MS (PythonCode Body)
-> MS (PythonCode Statement)
ifExists = VS (PythonCode Value)
-> MS (PythonCode Body)
-> MS (PythonCode Body)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
       (val :: k) (binder :: k) (typ :: k).
(ControlStatement r bod stmt var val,
 ValueExpression r var val binder typ) =>
VS (r val) -> MS (r bod) -> MS (r bod) -> MS (r stmt)
M.ifExists

  for :: MS (PythonCode Statement)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
-> MS (PythonCode Body)
-> MS (PythonCode Statement)
for MS (PythonCode Statement)
_ VS (PythonCode Value)
_ MS (PythonCode Statement)
_ MS (PythonCode Body)
_ = String -> MS (PythonCode Statement)
forall a. HasCallStack => String -> a
error (String -> MS (PythonCode Statement))
-> String -> MS (PythonCode Statement)
forall a b. (a -> b) -> a -> b
$ String -> String
CP.forLoopError String
pyName
  forRange :: VS (PythonCode Variable)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> MS (PythonCode Body)
-> MS (PythonCode Statement)
forRange VS (PythonCode Variable)
i VS (PythonCode Value)
initv VS (PythonCode Value)
finalv VS (PythonCode Value)
stepv = VS (PythonCode Variable)
-> VS (PythonCode Value)
-> MS (PythonCode Body)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (bod :: k) (stmt :: k) (var :: k)
       (val :: k).
ControlStatement r bod stmt var val =>
VS (r var) -> VS (r val) -> MS (r bod) -> MS (r stmt)
forEach VS (PythonCode Variable)
i (VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> VS (PythonCode Value)
forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k)
       (binder :: k).
(TypeSym r typ, ValueExpression r var val binder typ) =>
VS (r val) -> VS (r val) -> VS (r val) -> VS (r val)
range VS (PythonCode Value)
initv VS (PythonCode Value)
finalv VS (PythonCode Value)
stepv)
  forEach :: VS (PythonCode Variable)
-> VS (PythonCode Value)
-> MS (PythonCode Body)
-> MS (PythonCode Statement)
forEach = (PythonCode Variable
 -> PythonCode Value -> PythonCode Body -> Body)
-> VS (PythonCode Variable)
-> VS (PythonCode Value)
-> MS (PythonCode Body)
-> MS (PythonCode Statement)
forall (r :: * -> *) stmt var val.
RenderStatement r stmt =>
(r var -> r val -> r Body -> Body)
-> VS (r var) -> VS (r val) -> MS (r Body) -> MS (r stmt)
CS.forEach' PythonCode Variable -> PythonCode Value -> PythonCode Body -> Body
forall {k} (r :: k -> *) (bod :: k) (var :: k) (val :: k).
(BodyElim r bod, InternalVarElim r var, ValueElim r val) =>
r var -> r val -> r bod -> Body
pyForEach
  while :: VS (PythonCode Value)
-> MS (PythonCode Body) -> MS (PythonCode Statement)
while VS (PythonCode Value)
v' MS (PythonCode Body)
b' = do
    v <- LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Value))
  MethodState
  ValueState
-> VS (PythonCode Value)
-> 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 VS (PythonCode Value)
v'
    b <- b'
    mkStmtNoEnd (pyWhile v b)

  tryCatch :: MS (PythonCode Body)
-> MS (PythonCode Body) -> MS (PythonCode Statement)
tryCatch = (PythonCode Body -> PythonCode Body -> Body)
-> MS (PythonCode Body)
-> MS (PythonCode Body)
-> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (bod :: k).
RenderStatement r stmt =>
(r bod -> r bod -> Body) -> MS (r bod) -> MS (r bod) -> MS (r stmt)
G.tryCatch PythonCode Body -> PythonCode Body -> Body
forall {k} (r :: k -> *) (bod :: k).
BodyElim r bod =>
r bod -> r bod -> Body
pyTryCatch

  assert :: VS (PythonCode Value)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
assert VS (PythonCode Value)
condition VS (PythonCode Value)
errorMessage = do
      cond <- LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Value))
  MethodState
  ValueState
-> VS (PythonCode Value)
-> 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 VS (PythonCode Value)
condition
      errMsg <- zoom lensMStoVS errorMessage
      mkStmtNoEnd (pyAssert cond errMsg)

instance ObserverPattern PythonCode Statement TypeData where
  notifyObservers :: VS (PythonCode FuncData)
-> VS (PythonCode TypeData) -> MS (PythonCode Statement)
notifyObservers = VS (PythonCode FuncData)
-> VS (PythonCode TypeData) -> MS (PythonCode Statement)
forall (r :: * -> *) bod block stmt val typ var.
(BodySym r bod block, BlockSym r block stmt,
 ValueStatement r stmt val, TypeSym r typ, Literal r val typ,
 VariableSym r var typ, VariableValue r var val, List r val,
 ControlStatement r bod stmt var val, OOFunctionSym r val typ) =>
VS (r FuncData) -> VS (r typ) -> MS (r stmt)
M.notifyObservers'

instance StrategyPattern PythonCode Body Block Variable Value where
  runStrategy :: String
-> [(String, MS (PythonCode Body))]
-> Maybe (VS (PythonCode Value))
-> Maybe (VS (PythonCode Variable))
-> MS (PythonCode Body)
runStrategy = String
-> [(String, MS (PythonCode Body))]
-> Maybe (VS (PythonCode Value))
-> Maybe (VS (PythonCode Variable))
-> MS (PythonCode Body)
forall (r :: * -> *) stmt var val bod.
(EmptyStatement r stmt, AssignStatement r stmt var val,
 BodyElim r bod, Monad r, RenderStatement r stmt,
 StatementElim r stmt) =>
String
-> [(String, MS (r bod))]
-> Maybe (VS (r val))
-> Maybe (VS (r var))
-> MS (r Body)
M.runStrategy

instance VisibilitySym PythonCode Doc where
  private :: PythonCode Body
private = Body -> PythonCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode Body
empty
  public :: PythonCode Body
public = Body -> PythonCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode Body
empty

instance RenderVisibility PythonCode Doc where
  visibilityFromData :: VisibilityTag -> Body -> PythonCode Body
visibilityFromData VisibilityTag
_ = Body -> PythonCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode

instance VisibilityElim PythonCode Doc where
  visibility :: PythonCode Body -> Body
visibility = PythonCode Body -> Body
forall a. PythonCode a -> a
unPC

instance MethodTypeSym PythonCode TypeData where
  mType :: VS (PythonCode TypeData) -> MS (PythonCode TypeData)
mType = LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode TypeData))
  MethodState
  ValueState
-> VS (PythonCode TypeData) -> MS (PythonCode TypeData)
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 TypeData where
  construct :: String -> MS (PythonCode TypeData)
construct = String -> MS (PythonCode TypeData)
forall (r :: * -> *). Monad r => String -> MS (r TypeData)
G.construct

instance ParameterSym PythonCode ParamData Variable where
  param :: VS (PythonCode Variable) -> MS (PythonCode ParamData)
param = (PythonCode Variable -> Body)
-> VS (PythonCode Variable) -> MS (PythonCode ParamData)
forall {k} (r :: k -> *) (param :: k) (var :: k) (typ :: k).
(RenderParam r param var, VariableElim r var typ) =>
(r var -> Body) -> VS (r var) -> MS (r param)
G.param PythonCode Variable -> Body
forall {k} (r :: k -> *) (var :: k).
InternalVarElim r var =>
r var -> Body
RC.variable
  pointerParam :: VS (PythonCode Variable) -> MS (PythonCode ParamData)
pointerParam = VS (PythonCode Variable) -> MS (PythonCode ParamData)
forall {k} (r :: k -> *) (param :: k) (var :: k).
ParameterSym r param var =>
VS (r var) -> MS (r param)
param

instance RenderParam PythonCode ParamData Variable where
  paramFromData :: VS (PythonCode Variable) -> Body -> MS (PythonCode ParamData)
paramFromData VS (PythonCode Variable)
v' Body
d = do
    v <- LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Variable))
  MethodState
  ValueState
-> VS (PythonCode Variable)
-> 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 VS (PythonCode Variable)
v'
    toState $ on2CodeValues pd v (toCode d)

instance ParamElim PythonCode ParamData TypeData where
  parameterName :: PythonCode ParamData -> String
parameterName = PythonCode Variable -> String
forall {k} (r :: k -> *) (var :: k) (typ :: k).
VariableElim r var typ =>
r var -> 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 {k} (r :: k -> *) (var :: k) (typ :: k).
VariableElim r var typ =>
r var -> r typ
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 -> Body
parameter = ParamData -> Body
paramDoc (ParamData -> Body)
-> (PythonCode ParamData -> ParamData)
-> PythonCode ParamData
-> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode ParamData -> ParamData
forall a. PythonCode a -> a
unPC

instance MethodSym PythonCode MethodData Doc ParamData Body Variable TypeData where
  docMain :: MS (PythonCode Body) -> MS (PythonCode MethodData)
docMain = MS (PythonCode Body) -> MS (PythonCode MethodData)
forall {k} (r :: k -> *) (mthd :: k) (vis :: k) (param :: k)
       (bod :: k) (var :: k) (typ :: k).
MethodSym r mthd vis param bod var typ =>
MS (r bod) -> MS (r mthd)
mainFunction
  function :: String
-> PythonCode Body
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Body)
-> MS (PythonCode MethodData)
function = String
-> PythonCode Body
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Body)
-> MS (PythonCode MethodData)
forall {k} (r :: k -> *) (attch :: k) (typ :: k) (mthd :: k)
       (vis :: k) (param :: k) (bod :: k).
(AttachmentSym r attch, MethodTypeSym r typ,
 OORenderMethod r mthd attch vis param bod typ) =>
String
-> r vis
-> VS (r typ)
-> [MS (r param)]
-> MS (r bod)
-> MS (r mthd)
G.function
  mainFunction :: MS (PythonCode Body) -> MS (PythonCode MethodData)
mainFunction = MS (PythonCode Body) -> MS (PythonCode MethodData)
forall (r :: * -> *) bod mthd.
(BodyElim r bod, RenderMethod r mthd) =>
MS (r bod) -> MS (r mthd)
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 :: * -> *) mthd.
(BlockCommentSym r, RenderMethod r mthd) =>
String -> [String] -> Maybe String -> MS (r mthd) -> MS (r mthd)
CP.doxFunc

  inOutFunc :: String
-> PythonCode Body -> InOutFunc PythonCode MethodData Body Variable
inOutFunc String
n PythonCode Body
s = (VS (PythonCode TypeData)
 -> [MS (PythonCode ParamData)]
 -> MS (PythonCode Body)
 -> MS (PythonCode MethodData))
-> InOutFunc PythonCode MethodData Body Variable
forall {k} (r :: k -> *) (var :: k) (val :: k) (param :: k)
       (typ :: k) (scope :: k) (bod :: k) (stmt :: k) (block :: k)
       (mthd :: k).
(VariableValue r var val, ParameterSym r param var, TypeSym r typ,
 ScopeSym r scope, DeclStatement r bod stmt var scope val,
 BlockSym r block stmt, BodySym r bod block, VariableElim r var typ,
 RenderBody r bod, RenderType r typ,
 InternalControlStmt r stmt val) =>
(VS (r typ) -> [MS (r param)] -> MS (r bod) -> MS (r mthd))
-> [VS (r var)]
-> [VS (r var)]
-> [VS (r var)]
-> MS (r bod)
-> MS (r mthd)
CP.inOutFunc (String
-> PythonCode Body
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Body)
-> MS (PythonCode MethodData)
forall {k} (r :: k -> *) (mthd :: k) (vis :: k) (param :: k)
       (bod :: k) (var :: k) (typ :: k).
MethodSym r mthd vis param bod var typ =>
String
-> r vis
-> VS (r typ)
-> [MS (r param)]
-> MS (r bod)
-> MS (r mthd)
function String
n PythonCode Body
s)
  docInOutFunc :: String
-> PythonCode Body
-> DocInOutFunc PythonCode MethodData Body Variable
docInOutFunc String
n PythonCode Body
s = FuncDocRenderer
-> InOutFunc PythonCode MethodData Body Variable
-> DocInOutFunc PythonCode MethodData Body Variable
forall (r :: * -> *) mthd var bod.
(BlockCommentSym r, RenderMethod r mthd) =>
FuncDocRenderer
-> ([VS (r var)]
    -> [VS (r var)] -> [VS (r var)] -> MS (r bod) -> MS (r mthd))
-> String
-> [(String, VS (r var))]
-> [(String, VS (r var))]
-> [(String, VS (r var))]
-> MS (r bod)
-> MS (r mthd)
CP.docInOutFunc' FuncDocRenderer
functionDox (String
-> PythonCode Body -> InOutFunc PythonCode MethodData Body Variable
forall {k} (r :: k -> *) (mthd :: k) (vis :: k) (param :: k)
       (bod :: k) (var :: k) (typ :: k).
MethodSym r mthd vis param bod var typ =>
String -> r vis -> InOutFunc r mthd bod var
inOutFunc String
n PythonCode Body
s)

instance OOMethodSym PythonCode MethodData AttachmentData Doc ParamData Body Variable Value TypeData where
  method :: String
-> PythonCode Body
-> PythonCode AttachmentData
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Body)
-> MS (PythonCode MethodData)
method = String
-> PythonCode Body
-> PythonCode AttachmentData
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Body)
-> MS (PythonCode MethodData)
forall {k} (r :: k -> *) (typ :: k) (mthd :: k) (attch :: k)
       (vis :: k) (param :: k) (bod :: k).
(MethodTypeSym r typ,
 OORenderMethod r mthd attch vis param bod typ) =>
String
-> r vis
-> r attch
-> VS (r typ)
-> [MS (r param)]
-> MS (r bod)
-> MS (r mthd)
G.method
  getMethod :: VS (PythonCode Variable) -> MS (PythonCode MethodData)
getMethod = VS (PythonCode Variable) -> MS (PythonCode MethodData)
forall (r :: * -> *) file mod cls stvr mthd attch vis param bod
       block stmt var scope val binder typ.
OORenderSym
  r
  file
  mod
  cls
  stvr
  mthd
  attch
  vis
  param
  bod
  block
  stmt
  var
  scope
  val
  binder
  typ =>
VS (r var) -> MS (r mthd)
G.getMethod
  setMethod :: VS (PythonCode Variable) -> MS (PythonCode MethodData)
setMethod = VS (PythonCode Variable) -> MS (PythonCode MethodData)
forall (r :: * -> *) file mod cls stvr mthd attch vis param bod
       block stmt var scope val binder typ.
OORenderSym
  r
  file
  mod
  cls
  stvr
  mthd
  attch
  vis
  param
  bod
  block
  stmt
  var
  scope
  val
  binder
  typ =>
VS (r var) -> MS (r mthd)
G.setMethod
  constructor :: [MS (PythonCode ParamData)]
-> NamedArgs PythonCode Variable Value
-> MS (PythonCode Body)
-> MS (PythonCode MethodData)
constructor = String
-> [MS (PythonCode ParamData)]
-> NamedArgs PythonCode Variable Value
-> MS (PythonCode Body)
-> MS (PythonCode MethodData)
forall (r :: * -> *) file mod cls stvr mthd attch vis param bod
       block stmt var scope val binder typ.
OORenderSym
  r
  file
  mod
  cls
  stvr
  mthd
  attch
  vis
  param
  bod
  block
  stmt
  var
  scope
  val
  binder
  typ =>
String
-> [MS (r param)]
-> Initializers r var val
-> MS (r bod)
-> MS (r mthd)
CP.constructor String
initName

  inOutMethod :: String
-> PythonCode Body
-> PythonCode AttachmentData
-> InOutFunc PythonCode MethodData Body Variable
inOutMethod String
n PythonCode Body
s PythonCode AttachmentData
p = (VS (PythonCode TypeData)
 -> [MS (PythonCode ParamData)]
 -> MS (PythonCode Body)
 -> MS (PythonCode MethodData))
-> InOutFunc PythonCode MethodData Body Variable
forall {k} (r :: k -> *) (var :: k) (val :: k) (param :: k)
       (typ :: k) (scope :: k) (bod :: k) (stmt :: k) (block :: k)
       (mthd :: k).
(VariableValue r var val, ParameterSym r param var, TypeSym r typ,
 ScopeSym r scope, DeclStatement r bod stmt var scope val,
 BlockSym r block stmt, BodySym r bod block, VariableElim r var typ,
 RenderBody r bod, RenderType r typ,
 InternalControlStmt r stmt val) =>
(VS (r typ) -> [MS (r param)] -> MS (r bod) -> MS (r mthd))
-> [VS (r var)]
-> [VS (r var)]
-> [VS (r var)]
-> MS (r bod)
-> MS (r mthd)
CP.inOutFunc (String
-> PythonCode Body
-> PythonCode AttachmentData
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Body)
-> MS (PythonCode MethodData)
forall {k} (r :: k -> *) (mthd :: k) (attch :: k) (vis :: k)
       (param :: k) (bod :: k) (var :: k) (val :: k) (typ :: k).
OOMethodSym r mthd attch vis param bod var val typ =>
String
-> r vis
-> r attch
-> VS (r typ)
-> [MS (r param)]
-> MS (r bod)
-> MS (r mthd)
method String
n PythonCode Body
s PythonCode AttachmentData
p)
  docInOutMethod :: String
-> PythonCode Body
-> PythonCode AttachmentData
-> DocInOutFunc PythonCode MethodData Body Variable
docInOutMethod String
n PythonCode Body
s PythonCode AttachmentData
p = FuncDocRenderer
-> InOutFunc PythonCode MethodData Body Variable
-> DocInOutFunc PythonCode MethodData Body Variable
forall (r :: * -> *) mthd var bod.
(BlockCommentSym r, RenderMethod r mthd) =>
FuncDocRenderer
-> ([VS (r var)]
    -> [VS (r var)] -> [VS (r var)] -> MS (r bod) -> MS (r mthd))
-> String
-> [(String, VS (r var))]
-> [(String, VS (r var))]
-> [(String, VS (r var))]
-> MS (r bod)
-> MS (r mthd)
CP.docInOutFunc' FuncDocRenderer
functionDox (String
-> PythonCode Body
-> PythonCode AttachmentData
-> InOutFunc PythonCode MethodData Body Variable
forall {k} (r :: k -> *) (mthd :: k) (attch :: k) (vis :: k)
       (param :: k) (bod :: k) (var :: k) (val :: k) (typ :: k).
OOMethodSym r mthd attch vis param bod var val typ =>
String -> r vis -> r attch -> InOutFunc r mthd bod var
inOutMethod String
n PythonCode Body
s PythonCode AttachmentData
p)

instance RenderMethod PythonCode MethodData where
  commentedFunc :: MS (PythonCode Body)
-> MS (PythonCode MethodData) -> MS (PythonCode MethodData)
commentedFunc MS (PythonCode Body)
cmt MS (PythonCode MethodData)
m = (PythonCode MethodData
 -> PythonCode (Body -> Body) -> PythonCode MethodData)
-> MS (PythonCode MethodData)
-> State MethodState (PythonCode (Body -> Body))
-> MS (PythonCode MethodData)
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues ((MethodData -> (Body -> Body) -> MethodData)
-> PythonCode MethodData
-> PythonCode (Body -> Body)
-> PythonCode MethodData
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues MethodData -> (Body -> Body) -> MethodData
updateMthd) MS (PythonCode MethodData)
m
    ((PythonCode Body -> PythonCode (Body -> Body))
-> MS (PythonCode Body)
-> State MethodState (PythonCode (Body -> Body))
forall a b s. (a -> b) -> State s a -> State s b
onStateValue ((Body -> Body -> Body)
-> PythonCode Body -> PythonCode (Body -> Body)
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue Body -> Body -> Body
R.commentedItem) MS (PythonCode Body)
cmt)

  mthdFromData :: VisibilityTag -> Body -> MS (PythonCode MethodData)
mthdFromData VisibilityTag
_ Body
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
$ String -> Body -> MethodData
mthd String
"" Body
d

instance OORenderMethod PythonCode MethodData AttachmentData Doc ParamData Body TypeData where
  intMethod :: Bool
-> String
-> PythonCode Body
-> PythonCode AttachmentData
-> MS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Body)
-> MS (PythonCode MethodData)
intMethod Bool
m String
n PythonCode Body
_ PythonCode AttachmentData
a MS (PythonCode TypeData)
_ [MS (PythonCode ParamData)]
ps MS (PythonCode Body)
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)
    sl <- LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Variable))
  MethodState
  ValueState
-> VS (PythonCode Variable)
-> 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 VS (PythonCode Variable)
forall {k} (r :: k -> *) (var :: k). SelfSym r var => VS (r var)
self
    pms <- sequence ps
    toCode . mthd n . pyMethod n a sl pms <$> b
  intFunc :: Bool
-> String
-> PythonCode Body
-> PythonCode AttachmentData
-> MS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Body)
-> MS (PythonCode MethodData)
intFunc Bool
m String
n PythonCode Body
_ PythonCode AttachmentData
_ MS (PythonCode TypeData)
_ [MS (PythonCode ParamData)]
ps MS (PythonCode Body)
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)
    bd <- MS (PythonCode Body)
b
    pms <- sequence ps
    pure $ toCode $ mthd n $ pyFunction n pms bd
  destructor :: forall stvr.
[CSStateVar PythonCode stvr] -> MS (PythonCode MethodData)
destructor [CSStateVar PythonCode stvr]
_ = 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 -> Body
method = MethodData -> Body
mthdDoc (MethodData -> Body)
-> (PythonCode MethodData -> MethodData)
-> PythonCode MethodData
-> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode MethodData -> MethodData
forall a. PythonCode a -> a
unPC

instance StateVarSym PythonCode Doc AttachmentData Doc Variable Value where
  stateVar :: PythonCode Body
-> PythonCode AttachmentData
-> VS (PythonCode Variable)
-> CSStateVar PythonCode Body
stateVar PythonCode Body
_ PythonCode AttachmentData
_ VS (PythonCode Variable)
_ = PythonCode Body -> CSStateVar PythonCode Body
forall a s. a -> State s a
toState (Body -> PythonCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode Body
empty)
  stateVarDef :: PythonCode Body
-> PythonCode AttachmentData
-> VS (PythonCode Variable)
-> VS (PythonCode Value)
-> CSStateVar PythonCode Body
stateVarDef = PythonCode Body
-> PythonCode AttachmentData
-> VS (PythonCode Variable)
-> VS (PythonCode Value)
-> CSStateVar PythonCode Body
forall (r :: * -> *) file mod cls stvr mthd attch vis param bod
       block stmt var scope val binder typ.
(OORenderSym
   r
   file
   mod
   cls
   stvr
   mthd
   attch
   vis
   param
   bod
   block
   stmt
   var
   scope
   val
   binder
   typ,
 Monad r) =>
r vis -> r attch -> VS (r var) -> VS (r val) -> CS (r Body)
CP.stateVarDef
  constVar :: PythonCode Body
-> VS (PythonCode Variable)
-> VS (PythonCode Value)
-> CSStateVar PythonCode Body
constVar = Body
-> PythonCode Body
-> VS (PythonCode Variable)
-> VS (PythonCode Value)
-> CSStateVar PythonCode Body
forall (r :: * -> *) mthd vis param bod block stmt var scope val
       binder typ.
(CommonRenderSym
   r mthd vis param bod block stmt var scope val binder typ,
 Monad r) =>
Body -> r vis -> VS (r var) -> VS (r val) -> CS (r Body)
CP.constVar (PythonCode AttachmentData -> Body
forall {k} (r :: k -> *) (attch :: k).
PermElim r attch =>
r attch -> Body
RC.perm
    (PythonCode AttachmentData
forall {k} (r :: k -> *) (attch :: k).
AttachmentSym r attch =>
r attch
classLevel :: PythonCode AttachmentData))

instance StateVarElim PythonCode StateVar where
  stateVar :: PythonCode Body -> Body
stateVar = PythonCode Body -> Body
forall a. PythonCode a -> a
unPC

instance ClassSym PythonCode Class StateVar MethodData where
  buildClass :: Maybe String
-> [CSStateVar PythonCode Body]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Body
buildClass Maybe String
par [CSStateVar PythonCode Body]
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 Body]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Body
forall (r :: * -> *) cls stvr mthd vis.
(RenderClass r cls stvr mthd vis, VisibilitySym r vis) =>
Maybe String
-> [CSStateVar r stvr]
-> [MS (r mthd)]
-> [MS (r mthd)]
-> CS (r cls)
G.buildClass Maybe String
par [CSStateVar PythonCode Body]
sVars [MS (PythonCode MethodData)]
cstrs
                                  else String
-> [MS (PythonCode MethodData)] -> CSStateVar PythonCode Body
forall a. HasCallStack => String -> a
error String
pyMultCstrsError
  extraClass :: String
-> Maybe String
-> [CSStateVar PythonCode Body]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Body
extraClass String
n Maybe String
par [CSStateVar PythonCode Body]
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 Body]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Body
forall (r :: * -> *) cls stvr mthd vis.
(RenderClass r cls stvr mthd vis, VisibilitySym r vis) =>
String
-> Maybe String
-> [CSStateVar r stvr]
-> [MS (r mthd)]
-> [MS (r mthd)]
-> CS (r cls)
CP.extraClass String
n Maybe String
par [CSStateVar PythonCode Body]
sVars [MS (PythonCode MethodData)]
cstrs
                                    else String
-> [MS (PythonCode MethodData)] -> CSStateVar PythonCode Body
forall a. HasCallStack => String -> a
error String
pyMultCstrsError
  implementingClass :: String
-> [String]
-> [CSStateVar PythonCode Body]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Body
implementingClass String
n [String]
iNms [CSStateVar PythonCode Body]
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 Body]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Body
forall (r :: * -> *) cls stvr mthd vis.
(RenderClass r cls stvr mthd vis, VisibilitySym r vis) =>
String
-> [String]
-> [CSStateVar r stvr]
-> [MS (r mthd)]
-> [MS (r mthd)]
-> CS (r cls)
G.implementingClass String
n [String]
iNms [CSStateVar PythonCode Body]
sVars [MS (PythonCode MethodData)]
cstrs
                                    else String
-> [MS (PythonCode MethodData)] -> CSStateVar PythonCode Body
forall a. HasCallStack => String -> a
error String
pyMultCstrsError

  docClass :: String -> CSStateVar PythonCode Body -> CSStateVar PythonCode Body
docClass = String -> CSStateVar PythonCode Body -> CSStateVar PythonCode Body
forall (r :: * -> *) cls stvr mthd vis.
(BlockCommentSym r, RenderClass r cls stvr mthd vis) =>
String -> CS (r cls) -> CS (r cls)
CP.doxClass

instance RenderClass PythonCode Class StateVar MethodData Doc where
  intClass :: String
-> PythonCode Body
-> PythonCode Body
-> [CSStateVar PythonCode Body]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Body
intClass = (String -> Body -> Body -> Body -> Body -> Body)
-> String
-> PythonCode Body
-> PythonCode Body
-> [CSStateVar PythonCode Body]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Body
forall (r :: * -> *) mthd stvr vis.
(MethodElim r mthd, Monad r, StateVarElim r stvr,
 VisibilityElim r vis) =>
(String -> Body -> Body -> Body -> Body -> Body)
-> String
-> r vis
-> r Body
-> [CSStateVar r stvr]
-> [MS (r mthd)]
-> [MS (r mthd)]
-> CS (r Body)
CP.intClass String -> Body -> Body -> Body -> Body -> Body
pyClass

  inherit :: Maybe String -> PythonCode Body
inherit Maybe String
n = Body -> PythonCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Body -> PythonCode Body) -> Body -> PythonCode Body
forall a b. (a -> b) -> a -> b
$ Body -> (String -> Body) -> Maybe String -> Body
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Body
empty (Body -> Body
parens (Body -> Body) -> (String -> Body) -> String -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Body
text) Maybe String
n
  implements :: [String] -> PythonCode Body
implements [String]
is = Body -> PythonCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Body -> PythonCode Body) -> Body -> PythonCode Body
forall a b. (a -> b) -> a -> b
$ Body -> Body
parens (String -> Body
text (String -> Body) -> String -> Body
forall a b. (a -> b) -> a -> b
$ String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
listSep [String]
is)

  commentedClass :: CSStateVar PythonCode Body
-> CSStateVar PythonCode Body -> CSStateVar PythonCode Body
commentedClass = CSStateVar PythonCode Body
-> CSStateVar PythonCode Body -> CSStateVar PythonCode Body
forall (r :: * -> *) cls.
(BlockCommentElim r, ClassElim r cls, Monad r) =>
CS (r Body) -> CS (r cls) -> CS (r Body)
G.commentedClass

instance ClassElim PythonCode Class where
  class' :: PythonCode Body -> Body
class' = PythonCode Body -> Body
forall a. PythonCode a -> a
unPC

instance ModuleSym PythonCode ModData Class MethodData where
  buildModule :: String
-> [String]
-> [MS (PythonCode MethodData)]
-> [CSStateVar PythonCode Body]
-> FS (PythonCode ModData)
buildModule String
n [String]
is = String
-> FS Body
-> FS Body
-> FS Body
-> [MS (PythonCode MethodData)]
-> [CSStateVar PythonCode Body]
-> FS (PythonCode ModData)
forall {k} (r :: k -> *) (cls :: k) (mthd :: k) (mod :: k).
(ClassElim r cls, MethodElim r mthd, RenderMod r mod) =>
String
-> FS Body
-> FS Body
-> FS Body
-> [MS (r mthd)]
-> [CS (r cls)]
-> FS (r mod)
CP.buildModule String
n (do
    lis <- FS [String]
getLangImports
    libis <- getLibImports
    mis <- getModuleImports
    pure $ vibcat [
      vcat (RC.import' .
        (langImport :: Label -> PythonCode Doc) <$> lis),
      vcat (RC.import' .
        (langImport :: Label -> PythonCode Doc) <$> sort (is P.<>
        libis)),
      vcat (RC.import' .
        (modImport :: Label -> PythonCode Doc) <$> mis)])
    (Body -> FS Body
forall a. a -> StateT FileState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Body
empty) FS Body
getMainDoc

instance RenderMod PythonCode ModData where
  modFromData :: String -> FS Body -> FS (PythonCode ModData)
modFromData String
n = String
-> (Body -> PythonCode ModData)
-> FS Body
-> FS (PythonCode ModData)
forall {k} (r :: k -> *) (mod :: k).
String -> (Body -> r mod) -> FS Body -> FS (r mod)
G.modFromData String
n (ModData -> PythonCode ModData
forall (r :: * -> *) a. Monad r => a -> r a
toCode (ModData -> PythonCode ModData)
-> (Body -> ModData) -> Body -> PythonCode ModData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Body -> ModData
md String
n)
  updateModuleDoc :: (Body -> Body) -> PythonCode ModData -> PythonCode ModData
updateModuleDoc Body -> Body
f = (ModData -> ModData) -> PythonCode ModData -> PythonCode ModData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ((Body -> Body) -> ModData -> ModData
updateMod Body -> Body
f)

instance ModuleElim PythonCode ModData where
  module' :: PythonCode ModData -> Body
module' = ModData -> Body
modDoc (ModData -> Body)
-> (PythonCode ModData -> ModData) -> PythonCode ModData -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode ModData -> ModData
forall a. PythonCode a -> a
unPC

instance BlockCommentSym PythonCode where
  blockComment :: [String] -> PythonCode Body
blockComment [String]
lns = Body -> PythonCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Body -> PythonCode Body) -> Body -> PythonCode Body
forall a b. (a -> b) -> a -> b
$ [String] -> Body -> Body
pyBlockComment [String]
lns Body
pyCommentStart
  docComment :: forall a. State a [String] -> State a (PythonCode Body)
docComment = ([String] -> PythonCode Body)
-> State a [String] -> State a (PythonCode Body)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue (\[String]
lns -> Body -> PythonCode Body
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Body -> PythonCode Body) -> Body -> PythonCode Body
forall a b. (a -> b) -> a -> b
$ [String] -> Body -> Body -> Body
pyDocComment [String]
lns Body
pyDocCommentStart
    Body
pyCommentStart)

instance BlockCommentElim PythonCode where
  blockComment' :: PythonCode Body -> Body
blockComment' = PythonCode Body -> Body
forall a. PythonCode a -> a
unPC

-- convenience
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' :: Body
pyNull' = String -> Body
text String
pyNull

pyTrue, pyFalse :: Doc
pyTrue :: Body
pyTrue = String -> Body
text String
"True"
pyFalse :: Body
pyFalse = String -> Body
text String
"False"

pyPi :: Doc
pyPi :: Body
pyPi = String -> Body
text (String -> Body) -> String -> Body
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 :: Body
pyInputFunc = String -> Body
text String
"input()" -- raw_input() for < Python 3.0
pyPrintFunc :: Body
pyPrintFunc = String -> Body
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 :: Body
pyDef = String -> Body
text String
"def"
pyLambdaDec :: Body
pyLambdaDec = String -> Body
text String
"lambda"
pyElseIf :: Body
pyElseIf = String -> Body
text String
"elif"
pyRaise :: Body
pyRaise = String -> Body
text String
"raise"
pyExcept :: Body
pyExcept = String -> Body
text String
"except"

pyBodyStart, pyBodyEnd, pyCommentStart, pyDocCommentStart, pyNamedArgSep :: Doc
pyBodyStart :: Body
pyBodyStart = Body
colon
pyBodyEnd :: Body
pyBodyEnd = Body
empty
pyCommentStart :: Body
pyCommentStart = String -> Body
text String
"#"
pyDocCommentStart :: Body
pyDocCommentStart = Body
pyCommentStart Body -> Body -> Body
<> Body
pyCommentStart
pyNamedArgSep :: Body
pyNamedArgSep = Body
equals

pySpace :: OptionalSpace
pySpace :: OptionalSpace
pySpace = OSpace {oSpace :: Body
oSpace = Body
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
  :: (TypeSym r typ, Literal r val typ, OOFunctionSym r val typ)
  => Char -> VS (r FuncData)
splitFunc :: forall (r :: * -> *) typ val.
(TypeSym r typ, Literal r val typ, OOFunctionSym r val typ) =>
Char -> VS (r FuncData)
splitFunc Char
d = String -> VS (r typ) -> [VS (r val)] -> VS (r FuncData)
forall (r :: * -> *) val typ.
OOFunctionSym r val typ =>
String -> VS (r typ) -> [VS (r val)] -> VS (r FuncData)
func String
pySplit (VS (r typ) -> VS (r typ)
forall {k} (r :: k -> *) (typ :: k).
TypeSym r typ =>
VS (r typ) -> VS (r typ)
listType VS (r typ)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
string) [String -> VS (r val)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString [Char
d]]

readline, readlines
  :: (TypeSym r typ, InternalValueExp r var val typ)
  => VS (r val) -> VS (r val)
readline :: forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k).
(TypeSym r typ, InternalValueExp r var val typ) =>
VS (r val) -> VS (r val)
readline VS (r val)
f = VS (r typ) -> VS (r val) -> String -> [VS (r val)] -> VS (r val)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
InternalValueExp r var val typ =>
VS (r typ) -> VS (r val) -> String -> [VS (r val)] -> VS (r val)
objMethodCall VS (r typ)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
string VS (r val)
f String
pyReadline []
readlines :: forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k).
(TypeSym r typ, InternalValueExp r var val typ) =>
VS (r val) -> VS (r val)
readlines VS (r val)
f = VS (r typ) -> VS (r val) -> String -> [VS (r val)] -> VS (r val)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
InternalValueExp r var val typ =>
VS (r typ) -> VS (r val) -> String -> [VS (r val)] -> VS (r val)
objMethodCall (VS (r typ) -> VS (r typ)
forall {k} (r :: k -> *) (typ :: k).
TypeSym r typ =>
VS (r typ) -> VS (r typ)
listType VS (r typ)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
string) VS (r val)
f String
pyReadlines []

readInt, readDouble
  :: (TypeSym r typ, ValueExpression r var val binder typ)
  => VS (r val) -> VS (r val)
readInt :: forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k)
       (binder :: k).
(TypeSym r typ, ValueExpression r var val binder typ) =>
VS (r val) -> VS (r val)
readInt VS (r val)
inSrc = PosCall r val typ
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
       (typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
pyInt VS (r typ)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
int [VS (r val)
inSrc]
readDouble :: forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k)
       (binder :: k).
(TypeSym r typ, ValueExpression r var val binder typ) =>
VS (r val) -> VS (r val)
readDouble VS (r val)
inSrc = PosCall r val typ
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
       (typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
pyDouble VS (r typ)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
double [VS (r val)
inSrc]

readString
  :: (TypeSym r typ, InternalValueExp r var val typ)
  => VS (r val) -> VS (r val)
readString :: forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k).
(TypeSym r typ, InternalValueExp r var val typ) =>
VS (r val) -> VS (r val)
readString VS (r val)
inSrc = VS (r typ) -> VS (r val) -> String -> [VS (r val)] -> VS (r val)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
InternalValueExp r var val typ =>
VS (r typ) -> VS (r val) -> String -> [VS (r val)] -> VS (r val)
objMethodCall VS (r typ)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
string VS (r val)
inSrc String
pyRstrip []

range
  :: (TypeSym r typ, ValueExpression r var val binder typ)
  => VS (r val) -> VS (r val) -> VS (r val) -> VS (r val)
range :: forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k)
       (binder :: k).
(TypeSym r typ, ValueExpression r var val binder typ) =>
VS (r val) -> VS (r val) -> VS (r val) -> VS (r val)
range VS (r val)
initv VS (r val)
finalv VS (r val)
stepv = PosCall r val typ
forall {k} (r :: k -> *) (var :: k) (val :: k) (binder :: k)
       (typ :: k).
ValueExpression r var val binder typ =>
PosCall r val typ
funcApp String
pyRange (VS (r typ) -> VS (r typ)
forall {k} (r :: k -> *) (typ :: k).
TypeSym r typ =>
VS (r typ) -> VS (r typ)
listType VS (r typ)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
int) [VS (r val)
initv, VS (r val)
finalv, VS (r val)
stepv]

pyClassVarAccess :: Doc -> Doc -> Doc
pyClassVarAccess :: Body -> Body -> Body
pyClassVarAccess Body
c Body
v = Body
c Body -> Body -> Body
<> Body
dot Body -> Body -> Body
<> Body
c Body -> Body -> Body
<> Body
dot Body -> Body -> Body
<> Body
v

pyInlineIf
  :: (RenderValue r var val typ, ValueElim r val, ValueSym r val typ)
  => VS (r val) -> VS (r val) -> VS (r val) -> VS (r val)
pyInlineIf :: forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
(RenderValue r var val typ, ValueElim r val, ValueSym r val typ) =>
VS (r val) -> VS (r val) -> VS (r val) -> VS (r val)
pyInlineIf VS (r val)
c' VS (r val)
v1' VS (r val)
v2' = do
  c <- VS (r val)
c'
  v1 <- v1'
  v2 <- v2'
  valFromData (valuePrec c) (valueInt c) (toState $ valueType v1)
    (RC.value v1 <+> ifLabel <+> RC.value c <+> elseLabel <+> RC.value v2)

pyLambda
  :: (InternalBinderElim r binder, ValueElim r val)
  => [r binder] -> r val -> Doc
pyLambda :: forall {k} (r :: k -> *) (binder :: k) (val :: k).
(InternalBinderElim r binder, ValueElim r val) =>
[r binder] -> r val -> Body
pyLambda [r binder]
ps r val
ex = Body
pyLambdaDec Body -> Body -> Body
<+> [r binder] -> Body
forall {k} (r :: k -> *) (binder :: k).
InternalBinderElim r binder =>
[r binder] -> Body
binderList [r binder]
ps Body -> Body -> Body
<> Body
colon Body -> Body -> Body
<+> r val -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value r val
ex

pyStringType :: (Monad r) => VS (r TypeData)
pyStringType :: forall (r :: * -> *). Monad r => VS (r TypeData)
pyStringType = CodeType -> String -> Body -> VS (r TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Body -> VS (r TypeData)
typeFromData CodeType
String String
pyString (String -> Body
text String
pyString)

pyExtNewObjMixedArgs
  :: (RenderValue r var val TypeData, UnRepr r TypeData)
  => Library -> MixedCtorCall r var val TypeData
pyExtNewObjMixedArgs :: forall (r :: * -> *) var val.
(RenderValue r var val TypeData, UnRepr r TypeData) =>
String -> MixedCtorCall r var val TypeData
pyExtNewObjMixedArgs String
l VS (r TypeData)
tp [VS (r val)]
vs NamedArgs r var val
ns = VS (r TypeData)
tp VS (r TypeData) -> (r TypeData -> VS (r val)) -> VS (r val)
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 Body -> MixedCall r var val TypeData
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
Maybe String -> Maybe Body -> MixedCall r var val typ
call (String -> Maybe String
forall a. a -> Maybe a
Just String
l) Maybe Body
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) [VS (r val)]
vs NamedArgs r var val
ns)

pyPrint
  :: Bool
  -> Maybe (VS (PythonCode Value))
  -> VS (PythonCode Value)
  -> VS (PythonCode Value)
  -> MS (PythonCode Statement)
pyPrint :: Bool
-> Maybe (VS (PythonCode Value))
-> VS (PythonCode Value)
-> VS (PythonCode Value)
-> MS (PythonCode Statement)
pyPrint Bool
newLn Maybe (VS (PythonCode Value))
f' VS (PythonCode Value)
p' VS (PythonCode Value)
v' = do
    f <- LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Value))
  MethodState
  ValueState
-> VS (PythonCode Value)
-> 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 (VS (PythonCode Value)
 -> StateT MethodState Identity (PythonCode Value))
-> VS (PythonCode Value)
-> StateT MethodState Identity (PythonCode Value)
forall a b. (a -> b) -> a -> b
$ VS (PythonCode Value)
-> Maybe (VS (PythonCode Value)) -> VS (PythonCode Value)
forall a. a -> Maybe a -> a
fromMaybe (VS (PythonCode TypeData) -> Body -> VS (PythonCode Value)
forall {k} (r :: k -> *) (var :: k) (val :: k) (typ :: k).
RenderValue r var val typ =>
VS (r typ) -> Body -> VS (r val)
mkStateVal VS (PythonCode TypeData)
forall {k} (r :: k -> *) (typ :: k). TypeSym r typ => VS (r typ)
void Body
empty) Maybe (VS (PythonCode Value))
f'
    prf <- zoom lensMStoVS p'
    v <- zoom lensMStoVS v'
    s <- zoom lensMStoVS (litString "" :: VS (PythonCode Value))
    let nl = if Bool
newLn then Body
empty else Body
listSep' Body -> Body -> Body
<> String -> Body
text String
"end" Body -> Body -> Body
<> Body
equals Body -> Body -> Body
<>
               PythonCode Value -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value PythonCode Value
s
        fl = Body -> Body -> Body
emptyIfEmpty (PythonCode Value -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value PythonCode Value
f) (Body -> Body) -> Body -> Body
forall a b. (a -> b) -> a -> b
$ Body
listSep' Body -> Body -> Body
<> String -> Body
text String
"file" Body -> Body -> Body
<> Body
equals
               Body -> Body -> Body
<> PythonCode Value -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value PythonCode Value
f
    mkStmtNoEnd $ RC.value prf <> parens (RC.value v <> nl <> fl)

pyOut
  ::
    ( BodySym r bod block
    , BlockSym r block stmt
    , TypeSym r typ
    , ValueSym r val typ
    , Literal r val typ
    , NumericExpression r val
    , Comparison r val
    , VariableSym r var typ
    , VariableValue r var val
    , List r val
    , ScopeSym r scope
    , MultiStatement r stmt
    , DeclStatement r bod stmt var scope val
    , AssignStatement r stmt var val
    , ControlStatement r bod stmt var val
    , PrintConsole r stmt val
    , PrintFile r stmt val
    , InternalIOStmt r stmt val
    , TypeElim r typ
    )
  => Bool -> Maybe (VS (r val)) -> VS (r val) -> VS (r val) -> MS (r stmt)
pyOut :: forall {k} (r :: k -> *) (bod :: k) (block :: k) (stmt :: k)
       (typ :: k) (val :: k) (var :: k) (scope :: k).
(BodySym r bod block, BlockSym r block stmt, TypeSym r typ,
 ValueSym r val typ, Literal r val typ, NumericExpression r val,
 Comparison r val, VariableSym r var typ, VariableValue r var val,
 List r val, ScopeSym r scope, MultiStatement r stmt,
 DeclStatement r bod stmt var scope val,
 AssignStatement r stmt var val,
 ControlStatement r bod stmt var val, PrintConsole r stmt val,
 PrintFile r stmt val, InternalIOStmt r stmt val, TypeElim r typ) =>
Bool
-> Maybe (VS (r val)) -> VS (r val) -> VS (r val) -> MS (r stmt)
pyOut Bool
newLn Maybe (VS (r val))
f VS (r val)
printFn VS (r val)
v = LensLike'
  (Zoomed (StateT ValueState Identity) (r val))
  MethodState
  ValueState
-> VS (r val) -> StateT MethodState Identity (r val)
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 val))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r val) ValueState)
-> MethodState -> Focusing Identity (r val) MethodState
Lens' MethodState ValueState
lensMStoVS VS (r val)
v StateT MethodState Identity (r val)
-> (r val -> StateT MethodState Identity (r stmt))
-> StateT MethodState Identity (r stmt)
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 stmt)
pyOut' (CodeType -> StateT MethodState Identity (r stmt))
-> (r val -> CodeType)
-> r val
-> StateT MethodState Identity (r stmt)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r typ -> CodeType
forall {k} (r :: k -> *) (typ :: k).
TypeElim r typ =>
r typ -> CodeType
getCodeType (r typ -> CodeType) -> (r val -> r typ) -> r val -> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r val -> r typ
forall {k} (r :: k -> *) (val :: k) (typ :: k).
ValueSym r val typ =>
r val -> r typ
valueType
  where pyOut' :: CodeType -> StateT MethodState Identity (r stmt)
pyOut' (List CodeType
_) = Bool
-> Maybe (VS (r val))
-> VS (r val)
-> VS (r val)
-> StateT MethodState Identity (r stmt)
forall {k} (r :: k -> *) (stmt :: k) (val :: k).
InternalIOStmt r stmt val =>
Bool
-> Maybe (VS (r val)) -> VS (r val) -> VS (r val) -> MS (r stmt)
printSt Bool
newLn Maybe (VS (r val))
f VS (r val)
printFn VS (r val)
v
        pyOut' CodeType
_ = Bool
-> Maybe (VS (r val))
-> VS (r val)
-> VS (r val)
-> StateT MethodState Identity (r stmt)
forall {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k)
       (val :: k) (scope :: k) (var :: k) (typ :: k).
(BlockSym r block stmt, BodySym r bod block, MultiStatement r stmt,
 PrintConsole r stmt val, PrintFile r stmt val, ScopeSym r scope,
 DeclStatement r bod stmt var scope val,
 AssignStatement r stmt var val,
 ControlStatement r bod stmt var val, ValueSym r val typ,
 Literal r val typ, NumericExpression r val, Comparison r val,
 VariableSym r var typ, VariableValue r var val, List r val,
 TypeSym r typ, TypeElim r typ, InternalIOStmt r stmt val) =>
Bool
-> Maybe (VS (r val)) -> VS (r val) -> VS (r val) -> MS (r stmt)
G.print Bool
newLn Maybe (VS (r val))
f VS (r val)
printFn VS (r val)
v

pyInput
  :: VS (PythonCode Value)
  -> VS (PythonCode Variable)
  -> MS (PythonCode Statement)
pyInput :: VS (PythonCode Value)
-> VS (PythonCode Variable) -> MS (PythonCode Statement)
pyInput VS (PythonCode Value)
inSrc VS (PythonCode Variable)
v = VS (PythonCode Variable)
v VS (PythonCode Variable)
-> VS (PythonCode Value) -> MS (PythonCode Statement)
forall {k} (r :: k -> *) (stmt :: k) (var :: k) (val :: k).
AssignStatement r stmt var val =>
VS (r var) -> VS (r val) -> MS (r stmt)
&= (VS (PythonCode Variable)
v VS (PythonCode Variable)
-> (PythonCode Variable -> VS (PythonCode Value))
-> VS (PythonCode Value)
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 -> VS (PythonCode Value)
pyInput' (CodeType -> VS (PythonCode Value))
-> (PythonCode Variable -> CodeType)
-> PythonCode Variable
-> VS (PythonCode Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode TypeData -> CodeType
forall {k} (r :: k -> *) (typ :: k).
TypeElim r typ =>
r typ -> 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 {k} (r :: k -> *) (var :: k) (typ :: k).
VariableElim r var typ =>
r var -> r typ
variableType)
  where pyInput' :: CodeType -> VS (PythonCode Value)
pyInput' CodeType
Integer = VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k)
       (binder :: k).
(TypeSym r typ, ValueExpression r var val binder typ) =>
VS (r val) -> VS (r val)
readInt VS (PythonCode Value)
inSrc
        pyInput' CodeType
Float = VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k)
       (binder :: k).
(TypeSym r typ, ValueExpression r var val binder typ) =>
VS (r val) -> VS (r val)
readDouble VS (PythonCode Value)
inSrc
        pyInput' CodeType
Double = VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k)
       (binder :: k).
(TypeSym r typ, ValueExpression r var val binder typ) =>
VS (r val) -> VS (r val)
readDouble VS (PythonCode Value)
inSrc
        pyInput' CodeType
Boolean = VS (PythonCode Value)
inSrc VS (PythonCode Value)
-> VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k).
Comparison r val =>
VS (r val) -> VS (r val) -> VS (r val)
?!= String -> VS (PythonCode Value)
forall {k} (r :: k -> *) (val :: k) (typ :: k).
Literal r val typ =>
String -> VS (r val)
litString String
"0"
        pyInput' CodeType
String = VS (PythonCode Value) -> VS (PythonCode Value)
forall {k} (r :: k -> *) (typ :: k) (var :: k) (val :: k).
(TypeSym r typ, InternalValueExp r var val typ) =>
VS (r val) -> VS (r val)
readString VS (PythonCode Value)
inSrc
        pyInput' CodeType
Char = VS (PythonCode Value)
inSrc
        pyInput' CodeType
_ = String -> VS (PythonCode Value)
forall a. HasCallStack => String -> a
error String
"Attempt to read a value of unreadable type"

pyThrow :: (ValueElim r val) => r val -> Doc
pyThrow :: forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
pyThrow r val
errMsg = Body
pyRaise Body -> Body -> Body
<+> Body
exceptionObj' Body -> Body -> Body
<> Body -> Body
parens (r val -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value r val
errMsg)

pyForEach
  :: (BodyElim r bod, InternalVarElim r var, ValueElim r val)
  => r var -> r val -> r bod -> Doc
pyForEach :: forall {k} (r :: k -> *) (bod :: k) (var :: k) (val :: k).
(BodyElim r bod, InternalVarElim r var, ValueElim r val) =>
r var -> r val -> r bod -> Body
pyForEach r var
i r val
lstVar r bod
b = [Body] -> Body
vcat [
  Body
forLabel Body -> Body -> Body
<+> r var -> Body
forall {k} (r :: k -> *) (var :: k).
InternalVarElim r var =>
r var -> Body
RC.variable r var
i Body -> Body -> Body
<+> Body
inLabel Body -> Body -> Body
<+> r val -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value r val
lstVar Body -> Body -> Body
<> Body
colon,
  Body -> Body
indent (Body -> Body) -> Body -> Body
forall a b. (a -> b) -> a -> b
$ r bod -> Body
forall {k} (r :: k -> *) (bod :: k).
BodyElim r bod =>
r bod -> Body
RC.body r bod
b]

pyWhile :: (BodyElim r bod, ValueElim r val) => r val -> r bod -> Doc
pyWhile :: forall {k} (r :: k -> *) (bod :: k) (val :: k).
(BodyElim r bod, ValueElim r val) =>
r val -> r bod -> Body
pyWhile r val
v r bod
b = [Body] -> Body
vcat [
  Body
whileLabel Body -> Body -> Body
<+> r val -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value r val
v Body -> Body -> Body
<> Body
colon,
  Body -> Body
indent (Body -> Body) -> Body -> Body
forall a b. (a -> b) -> a -> b
$ r bod -> Body
forall {k} (r :: k -> *) (bod :: k).
BodyElim r bod =>
r bod -> Body
RC.body r bod
b]

pyTryCatch :: (BodyElim r bod) => r bod -> r bod -> Doc
pyTryCatch :: forall {k} (r :: k -> *) (bod :: k).
BodyElim r bod =>
r bod -> r bod -> Body
pyTryCatch r bod
tryB r bod
catchB = [Body] -> Body
vcat [
  Body
tryLabel Body -> Body -> Body
<> Body
colon,
  Body -> Body
indent (Body -> Body) -> Body -> Body
forall a b. (a -> b) -> a -> b
$ r bod -> Body
forall {k} (r :: k -> *) (bod :: k).
BodyElim r bod =>
r bod -> Body
RC.body r bod
tryB,
  Body
pyExcept Body -> Body -> Body
<+> Body
exceptionObj' Body -> Body -> Body
<> Body
colon,
  Body -> Body
indent (Body -> Body) -> Body -> Body
forall a b. (a -> b) -> a -> b
$ r bod -> Body
forall {k} (r :: k -> *) (bod :: k).
BodyElim r bod =>
r bod -> Body
RC.body r bod
catchB]

pyAssert :: (ValueElim r val) => r val -> r val -> Doc
pyAssert :: forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> r val -> Body
pyAssert r val
condition r val
message = String -> Body
text String
"assert" Body -> Body -> Body
<+> r val -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value r val
condition Body -> Body -> Body
<> Body
comma Body -> Body -> Body
<+> r val -> Body
forall {k} (r :: k -> *) (val :: k).
ValueElim r val =>
r val -> Body
RC.value r val
message

pyListSlice
  :: (InternalVarElim r var, Monad r, ValueElim r val)
  => VS (r var)
  -> VS (r val)
  -> VS (r val)
  -> VS (r val)
  -> VS (r val)
  -> MS (r Doc)
pyListSlice :: forall (r :: * -> *) var val.
(InternalVarElim r var, Monad r, ValueElim r val) =>
VS (r var)
-> VS (r val)
-> VS (r val)
-> VS (r val)
-> VS (r val)
-> MS (r Body)
pyListSlice VS (r var)
vn VS (r val)
vo VS (r val)
beg VS (r val)
end VS (r val)
step = LensLike'
  (Zoomed (StateT ValueState Identity) (r Body))
  MethodState
  ValueState
-> StateT ValueState Identity (r Body)
-> StateT MethodState Identity (r Body)
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 Body))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r Body) ValueState)
-> MethodState -> Focusing Identity (r Body) MethodState
Lens' MethodState ValueState
lensMStoVS (StateT ValueState Identity (r Body)
 -> StateT MethodState Identity (r Body))
-> StateT ValueState Identity (r Body)
-> StateT MethodState Identity (r Body)
forall a b. (a -> b) -> a -> b
$ do
  vnew <- VS (r var)
vn
  vold <- vo
  b <- beg
  e <- end
  s <- step
  pure $ toCode $ RC.variable vnew <+> equals <+> RC.value vold <>
    brackets (RC.value b <> colon <> RC.value e <> colon <> RC.value s)

pyMethod
  :: Label
  -> PythonCode AttachmentData
  -> PythonCode Variable
  -> [PythonCode ParamData]
  -> PythonCode Body
  -> Doc
pyMethod :: String
-> PythonCode AttachmentData
-> PythonCode Variable
-> [PythonCode ParamData]
-> PythonCode Body
-> Body
pyMethod String
n PythonCode AttachmentData
attch PythonCode Variable
slf [PythonCode ParamData]
ps PythonCode Body
b = let
     decorator :: Body
decorator = case PythonCode AttachmentData -> AttachmentTag
forall {k} (r :: k -> *) (attch :: k).
PermElim r attch =>
r attch -> AttachmentTag
binding PythonCode AttachmentData
attch of
                   AttachmentTag
ClassLevel -> String -> Body
text String
"@staticmethod"
                   AttachmentTag
_          -> Body
empty
     pms :: Body
pms = [PythonCode ParamData] -> Body
forall {k} (r :: k -> *) (param :: k) (typ :: k).
ParamElim r param typ =>
[r param] -> Body
parameterList [PythonCode ParamData]
ps
     (Body
implicitParam, Body
implicitComma) = case PythonCode AttachmentData -> AttachmentTag
forall {k} (r :: k -> *) (attch :: k).
PermElim r attch =>
r attch -> AttachmentTag
binding PythonCode AttachmentData
attch of
                       AttachmentTag
InstanceLevel -> (PythonCode Variable -> Body
forall {k} (r :: k -> *) (var :: k).
InternalVarElim r var =>
r var -> Body
RC.variable PythonCode Variable
slf, Body -> Body -> Body
emptyIfEmpty Body
pms Body
listSep')
                       AttachmentTag
_             -> (Body
empty, Body
empty)
     bodyD :: Body
bodyD | Body -> Bool
isEmpty (PythonCode Body -> Body
forall {k} (r :: k -> *) (bod :: k).
BodyElim r bod =>
r bod -> Body
RC.body PythonCode Body
b) = Body
pyNull'
           | Bool
otherwise = PythonCode Body -> Body
forall {k} (r :: k -> *) (bod :: k).
BodyElim r bod =>
r bod -> Body
RC.body PythonCode Body
b
  in [Body] -> Body
vcat [
       Body
decorator,
       Body
pyDef Body -> Body -> Body
<+> String -> Body
text String
n Body -> Body -> Body
<> Body -> Body
parens (Body
implicitParam Body -> Body -> Body
<> Body
implicitComma Body -> Body -> Body
<> Body
pms) Body -> Body -> Body
<> Body
colon,
       Body -> Body
indent Body
bodyD]

pyFunction
  :: (BodyElim r bod, ParamElim r param typ) => Label -> [r param] -> r bod -> Doc
pyFunction :: forall {k} (r :: k -> *) (bod :: k) (param :: k) (typ :: k).
(BodyElim r bod, ParamElim r param typ) =>
String -> [r param] -> r bod -> Body
pyFunction String
n [r param]
ps r bod
b = [Body] -> Body
vcat [
  Body
pyDef Body -> Body -> Body
<+> String -> Body
text String
n Body -> Body -> Body
<> Body -> Body
parens ([r param] -> Body
forall {k} (r :: k -> *) (param :: k) (typ :: k).
ParamElim r param typ =>
[r param] -> Body
parameterList [r param]
ps) Body -> Body -> Body
<> Body
colon,
  Body -> Body
indent Body
bodyD]
  where bodyD :: Body
bodyD | Body -> Bool
isEmpty (r bod -> Body
forall {k} (r :: k -> *) (bod :: k).
BodyElim r bod =>
r bod -> Body
RC.body r bod
b) = Body
pyNull'
              | Bool
otherwise = r bod -> Body
forall {k} (r :: k -> *) (bod :: k).
BodyElim r bod =>
r bod -> Body
RC.body r bod
b

pyClass :: Label -> Doc -> Doc -> Doc -> Doc -> Doc
pyClass :: String -> Body -> Body -> Body -> Body -> Body
pyClass String
n Body
pn Body
s Body
vs Body
fs = [Body] -> Body
vcat [
  Body
s Body -> Body -> Body
<+> Body
classDec Body -> Body -> Body
<+> String -> Body
text String
n Body -> Body -> Body
<> Body
pn Body -> Body -> Body
<> Body
colon,
  Body -> Body
indent Body
funcSec]
  where funcSec :: Body
funcSec | Body -> Bool
isEmpty (Body
vs Body -> Body -> Body
<> Body
fs) = Body
pyNull'
                | Body -> Bool
isEmpty Body
vs = Body
fs
                | Body -> Bool
isEmpty Body
fs = Body
vs
                | Bool
otherwise = [Body] -> Body
vcat [Body
vs, Body
blank, Body
fs]

pyMultCstrsError :: String
pyMultCstrsError :: String
pyMultCstrsError = String
"Python classes cannot have multiple constructors"

pyBlockComment :: [String] -> Doc -> Doc
pyBlockComment :: [String] -> Body -> Body
pyBlockComment [String]
lns Body
cmt = [Body] -> Body
vcat ([Body] -> Body) -> [Body] -> Body
forall a b. (a -> b) -> a -> b
$ Body -> Body -> Body
(<+>) Body
cmt (Body -> Body) -> (String -> Body) -> String -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Body
text (String -> Body) -> [String] -> [Body]
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
<$> [String]
lns

pyDocComment :: [String] -> Doc -> Doc -> Doc
pyDocComment :: [String] -> Body -> Body -> Body
pyDocComment [] Body
_ Body
_ = Body
empty
pyDocComment (String
l:[String]
lns) Body
start Body
mid = [Body] -> Body
vcat ([Body] -> Body) -> [Body] -> Body
forall a b. (a -> b) -> a -> b
$ Body
start Body -> Body -> Body
<+> String -> Body
text String
l Body -> [Body] -> [Body]
forall a. a -> [a] -> [a]
: (String -> Body) -> [String] -> [Body]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Body -> Body -> Body
(<+>) Body
mid (Body -> Body) -> (String -> Body) -> String -> Body
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  String -> Body
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
""