{-# 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, SVariable, Value, SValue, MixedCtorCall, BodySym(..), BlockSym(..),
  TypeSym(..), TypeElim(..), getTypeString, VariableSym(..), VisibilitySym(..),
  VariableElim(..), ValueSym(..), Argument(..), Literal(..), MathConstant(..),
  VariableValue(..), CommandLineArgs(..), NumericExpression(..),
  BooleanExpression(..), Comparison(..), ValueExpression(..), funcApp,
  extFuncApp, IndexTranslator(..), Reference(..), Array(..), List(..),
  ListStatement(..), Set(..), InternalList(..), EmptyStatement(..),
  MultiStatement(..), ValueStatement(..), AssignStatement(..), (&=),
  DeclStatement(..), PrintConsole(..), ReadConsole(..), FileHandling(..),
  PrintFile(..), ReadFile(..), StringStatement(..), FunctionSym,
  FuncAppStatement(..), CommentStatement(..), ControlStatement(..), switchAsIf,
  ScopeSym(..), ParameterSym(..), BinderSym(..), BinderElim(..), MethodSym(..))
import Drasil.GOOL.InterfaceGOOL (OOProg, StateVar, ProgramSym(..), FileSym(..),
  ModuleSym(..), ClassSym(..), OOTypeSym(..), OOVariableSym(..), SelfSym(..),
  StateVarSym(..), AttachmentSym(..), OOValueSym, OOVariableValue,
  InternalValueExp(..), extNewObj, objMethodCall, OOFunctionSym(..), GetSet(..),
  OOValueExpression(..), selfMethodCall, OODeclStatement(..),
  OOFuncAppStatement(..), ObserverPattern(..), StrategyPattern(..),
  OOMethodSym(..))
import Drasil.Shared.RendererClassesCommon (CommonRenderSym, ImportSym(..),
  RenderBody(..), BodyElim, RenderBlock(..), BlockElim, RenderType(..),
  UnaryOpSym(..), BinaryOpSym(..), OpElim(uOpPrec, bOpPrec), RenderVariable(..),
  InternalVarElim(variableBind), RenderValue(..), ValueElim(valuePrec, valueInt),
  InternalListFunc(..), RenderFunction(..), FunctionElim(functionType),
  InternalAssignStmt(..), InternalIOStmt(..), InternalControlStmt(..),
  RenderStatement(..), StatementElim(statementTerm), RenderVisibility(..),
  VisibilityElim, MethodTypeSym(..), RenderParam(..),
  ParamElim(parameterName, parameterType), RenderMethod(..), MethodElim,
  BlockCommentSym(..), BlockCommentElim, ScopeElim(..), InternalBinderElim(..))
import qualified Drasil.Shared.RendererClassesCommon as RC (import', body, block,
  uOp, bOp, variable, value, function, statement, visibility, parameter, method,
  blockComment')
import Drasil.GOOL.RendererClassesOO (OORenderSym, RenderFile(..),
  PermElim(binding), InternalGetSet(..), OOMethodTypeSym(..),
  OORenderMethod(..), StateVarElim, RenderClass(..), ClassElim, RenderMod(..),
  ModuleElim)
import qualified Drasil.GOOL.RendererClassesOO as RC (perm, stateVar, class',
  module')
import Drasil.Shared.LanguageRenderer (classDec, dot, ifLabel, elseLabel,
  forLabel, inLabel, whileLabel, tryLabel, importLabel, exceptionObj', listSep',
  argv, printLabel, listSep, piLabel, access, functionDox, binderList,
  parameterList)
import qualified Drasil.Shared.LanguageRenderer as R (sqrt, fabs, log10,
  log, exp, sin, cos, tan, asin, acos, atan, floor, ceil, multiStmt, body,
  classVarAccess, castObj, instanceLevel, break, continue, addComments,
  commentedMod, commentedItem, var)
import Drasil.GOOL.Renderers (renderType)
import Drasil.Shared.LanguageRenderer.Constructors (mkStmtNoEnd, mkStateVal,
  mkVal, mkStateVar, typeFromData, VSOp, unOpPrec, powerPrec, multPrec, andPrec,
  orPrec, inPrec, unExpr, unExpr', typeUnExpr, binExpr, typeBinExpr, mkClassVar,
  typeFromData)
import qualified Drasil.Shared.LanguageRenderer.LanguagePolymorphic as G (
  multiBody, block, multiBlock, obj, negateOp, csc, sec, cot, equalOp,
  notEqualOp, greaterOp, greaterEqualOp, lessOp, lessEqualOp, plusOp, minusOp,
  multOp, divideOp, moduloOp, var, classVar, instanceVarAccess, arrayElem,
  litChar, litDouble, litInt, litString, valueOf, arg, argsList, objAccess,
  objMethodCall, call, funcAppMixedArgs, newObjMixedArgs, lambda, func, get, set,
  listAccess, getFunc, setFunc, stmt, loopStmt, emptyStmt, assign,
  subAssign, objDecNew, print, closeFile, returnStmt, valStmt, comment, throw,
  ifCond, tryCatch, construct, param, method, getMethod, setMethod, function,
  buildClass, implementingClass, commentedClass, modFromData, fileDoc,
  fileFromData, local)
import qualified Drasil.Shared.LanguageRenderer.CommonPseudoOO as CP
import qualified Drasil.Shared.LanguageRenderer.Macros as M (ifExists,
  decrement1, increment1, runStrategy, stringListVals, stringListLists,
  notifyObservers', arrayDecAsList)
import qualified Drasil.GOOL.LanguageRenderer.CommonGOOL as CG (classMethodCall,
  listAppend, listAdd, innerType)
import Drasil.Shared.AST (Terminator(..), FileType(..), fileD, FuncData(..), fd,
  ModData(..), md, updateMod, MethodData(..), mthd, updateMthd, OpData(..),
  ParamData(..), pd, ProgData(..), progD, TypeData(..), ValData(..), vd,
  VarData(..), vard, BinderD(..), bindFormD, AttachmentTag(..),
  AttachmentData(..), ad, FileData)
import Drasil.Shared.Helpers (vibcat, emptyIfEmpty, toCode, toState, onCodeValue,
  onStateValue, on2CodeValues, on2StateValues, onCodeList, onStateList,
  on2StateWrapped)
import Drasil.Shared.State (MS, VS, lensGStoFS, lensMStoVS, lensVStoMS, revFiles,
  addLangImportVS, getLangImports, addLibImportVS, getLibImports, addModuleImport,
  addModuleImportVS, getModuleImports, setFileType, getClassName, setCurrMain,
  getClassMap, getMainDoc, varNameAvailable)

import Prelude hiding (break,print,sin,cos,tan,floor,(<>))
import Data.Maybe (fromMaybe)
import Control.Lens.Zoom (zoom)
import Control.Monad (join)
import Control.Monad.State (modify)
import Data.List (intercalate, sort)
import Data.Char (toUpper, isUpper, isLower)
import qualified Data.Map as Map (lookup)
import Text.PrettyPrint.HughesPJ (Doc, text, (<>), (<+>), parens, empty, equals,
  vcat, colon, brackets, isEmpty, quotes, comma, braces)
import Drasil.Shared.LanguageRenderer.LanguagePolymorphic (OptionalSpace(..))

import qualified Drasil.Shared.LanguageRenderer.Common as CS

pyExt :: String
pyExt :: String
pyExt = String
"py"

newtype PythonCode a = PC {forall a. PythonCode a -> a
unPC :: a}

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

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

instance Monad PythonCode where
  PC a
x >>= :: forall a b. PythonCode a -> (a -> PythonCode b) -> PythonCode b
>>= a -> PythonCode b
f = a -> PythonCode b
f a
x

instance OOProg PythonCode Doc (Doc, Terminator) MethodData StateVar AttachmentData ProgData FileData ModData Body Block

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 Doc (Doc, Terminator) MethodData Body Block
instance OORenderSym PythonCode Doc (Doc, Terminator) MethodData StateVar AttachmentData FileData ModData Body Block

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 Doc)
-> PythonCode Doc
-> 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 Doc
forall (r :: * -> *) file mod.
RenderFile r file mod =>
r mod -> r Doc
top PythonCode Doc
forall (r :: * -> *) file mod. RenderFile r file mod => r Doc
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.
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 Doc
top PythonCode ModData
_ = Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
empty
  bottom :: PythonCode Doc
bottom = Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
empty

  commentedMod :: FS (PythonCode FileData)
-> FS (PythonCode Doc) -> FS (PythonCode FileData)
commentedMod = (PythonCode FileData -> PythonCode Doc -> PythonCode FileData)
-> FS (PythonCode FileData)
-> FS (PythonCode Doc)
-> FS (PythonCode FileData)
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues ((FileData -> Doc -> FileData)
-> PythonCode FileData -> PythonCode Doc -> PythonCode FileData
forall (r :: * -> *) a b c.
Applicative r =>
(a -> b -> c) -> r a -> r b -> r c
on2CodeValues FileData -> Doc -> 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 Doc
langImport String
n = Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> PythonCode Doc) -> Doc -> PythonCode Doc
forall a b. (a -> b) -> a -> b
$ Doc
importLabel Doc -> Doc -> Doc
<+> String -> Doc
text String
n
  modImport :: String -> PythonCode Doc
modImport = String -> PythonCode Doc
forall (r :: * -> *). ImportSym r => String -> r Doc
langImport

instance AttachmentSym PythonCode AttachmentData where
  classLevel :: PythonCode AttachmentData
classLevel = AttachmentData -> PythonCode AttachmentData
forall (r :: * -> *) a. Monad r => a -> r a
toCode (AttachmentData -> PythonCode AttachmentData)
-> AttachmentData -> PythonCode AttachmentData
forall a b. (a -> b) -> a -> b
$ AttachmentTag -> Doc -> AttachmentData
ad AttachmentTag
ClassLevel Doc
empty
  instanceLevel :: PythonCode AttachmentData
instanceLevel = AttachmentData -> PythonCode AttachmentData
forall (r :: * -> *) a. Monad r => a -> r a
toCode (AttachmentData -> PythonCode AttachmentData)
-> AttachmentData -> PythonCode AttachmentData
forall a b. (a -> b) -> a -> b
$ AttachmentTag -> Doc -> AttachmentData
ad AttachmentTag
InstanceLevel Doc
R.instanceLevel

instance PermElim PythonCode AttachmentData where
  perm :: PythonCode AttachmentData -> Doc
perm = AttachmentData -> Doc
attachmentDoc (AttachmentData -> Doc)
-> (PythonCode AttachmentData -> AttachmentData)
-> PythonCode AttachmentData
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode AttachmentData -> AttachmentData
forall a. PythonCode a -> a
unPC
  binding :: PythonCode AttachmentData -> AttachmentTag
binding = AttachmentData -> AttachmentTag
attachment (AttachmentData -> AttachmentTag)
-> (PythonCode AttachmentData -> AttachmentData)
-> PythonCode AttachmentData
-> AttachmentTag
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode AttachmentData -> AttachmentData
forall a. PythonCode a -> a
unPC

instance BodySym PythonCode Body Block where
  body :: [MS (PythonCode Doc)] -> MS (PythonCode Doc)
body = ([PythonCode Doc] -> PythonCode Doc)
-> [MS (PythonCode Doc)] -> MS (PythonCode Doc)
forall a b s. ([a] -> b) -> [State s a] -> State s b
onStateList (([Doc] -> Doc) -> [PythonCode Doc] -> PythonCode Doc
forall (m :: * -> *) a b. Monad m => ([a] -> b) -> [m a] -> m b
onCodeList [Doc] -> Doc
R.body)

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

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

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

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

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

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

instance TypeSym PythonCode where
  bool :: VS (PythonCode TypeData)
bool = CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
Boolean String
"" Doc
empty
  int :: VS (PythonCode TypeData)
int = VS (PythonCode TypeData)
forall (r :: * -> *). Monad r => VS (r TypeData)
CP.int
  float :: VS (PythonCode TypeData)
float = String -> VS (PythonCode TypeData)
forall a. HasCallStack => String -> a
error String
pyFloatError
  double :: VS (PythonCode TypeData)
double = CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
Double String
pyDouble (String -> Doc
text String
pyDouble)
  char :: VS (PythonCode TypeData)
char = CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
Char String
"" Doc
empty
  string :: VS (PythonCode TypeData)
string = VS (PythonCode TypeData)
forall (r :: * -> *). Monad r => VS (r TypeData)
pyStringType
  infile :: VS (PythonCode TypeData)
infile = CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
InFile String
"" Doc
empty
  outfile :: VS (PythonCode TypeData)
outfile = CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
OutFile String
"" Doc
empty
  referenceType :: VS (PythonCode TypeData) -> VS (PythonCode TypeData)
referenceType = VS (PythonCode TypeData) -> VS (PythonCode TypeData)
forall a. a -> a
id -- 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 -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData (CodeType -> CodeType
List (PythonCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType PythonCode TypeData
t)) String
"" Doc
empty)
  setType :: VS (PythonCode TypeData) -> VS (PythonCode TypeData)
setType VS (PythonCode TypeData)
t' = VS (PythonCode TypeData)
t' VS (PythonCode TypeData)
-> (PythonCode TypeData -> VS (PythonCode TypeData))
-> VS (PythonCode TypeData)
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=(\PythonCode TypeData
t -> CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData (CodeType -> CodeType
Set (PythonCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType PythonCode TypeData
t)) String
"" Doc
empty)
  arrayType :: VS (PythonCode TypeData) -> VS (PythonCode TypeData)
arrayType = VS (PythonCode TypeData) -> VS (PythonCode TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType
  innerType :: VS (PythonCode TypeData) -> VS (PythonCode TypeData)
innerType = VS (PythonCode TypeData) -> VS (PythonCode TypeData)
forall (r :: * -> *).
(TypeElim r, OOTypeSym r) =>
VS (r TypeData) -> VS (r TypeData)
CG.innerType
  funcType :: [VS (PythonCode TypeData)]
-> VS (PythonCode TypeData) -> VS (PythonCode TypeData)
funcType = [VS (PythonCode TypeData)]
-> VS (PythonCode TypeData) -> VS (PythonCode TypeData)
forall (r :: * -> *).
(Monad r, TypeElim r) =>
[VS (r TypeData)] -> VS (r TypeData) -> VS (r TypeData)
CS.funcType
  void :: VS (PythonCode TypeData)
void = CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
Void String
pyVoid (String -> Doc
text String
pyVoid)

instance TypeElim PythonCode where
  getCodeType :: PythonCode TypeData -> CodeType
getCodeType = TypeData -> CodeType
cType (TypeData -> CodeType)
-> (PythonCode TypeData -> TypeData)
-> PythonCode TypeData
-> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode TypeData -> TypeData
forall a. PythonCode a -> a
unPC

instance OOTypeSym PythonCode where
  obj :: String -> VS (PythonCode TypeData)
obj = String -> VS (PythonCode TypeData)
forall (r :: * -> *). Monad r => String -> VS (r TypeData)
G.obj

instance RenderType PythonCode where
  multiType :: [VS (PythonCode TypeData)] -> VS (PythonCode TypeData)
multiType [VS (PythonCode TypeData)]
_ = CodeType -> String -> Doc -> VS (PythonCode TypeData)
forall (r :: * -> *).
Monad r =>
CodeType -> String -> Doc -> VS (r TypeData)
typeFromData CodeType
Void String
"" Doc
empty

instance UnaryOpSym PythonCode where
  notOp :: VSUnOp PythonCode
notOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyNotOp
  negateOp :: VSUnOp PythonCode
negateOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.negateOp
  sqrtOp :: VSUnOp PythonCode
sqrtOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pySqrtOp
  absOp :: VSUnOp PythonCode
absOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyAbsOp
  logOp :: VSUnOp PythonCode
logOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyLogOp
  lnOp :: VSUnOp PythonCode
lnOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyLnOp
  expOp :: VSUnOp PythonCode
expOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyExpOp
  sinOp :: VSUnOp PythonCode
sinOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pySinOp
  cosOp :: VSUnOp PythonCode
cosOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyCosOp
  tanOp :: VSUnOp PythonCode
tanOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyTanOp
  asinOp :: VSUnOp PythonCode
asinOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyAsinOp
  acosOp :: VSUnOp PythonCode
acosOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyAcosOp
  atanOp :: VSUnOp PythonCode
atanOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyAtanOp
  floorOp :: VSUnOp PythonCode
floorOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyFloorOp
  ceilOp :: VSUnOp PythonCode
ceilOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
pyCeilOp

instance BinaryOpSym PythonCode where
  equalOp :: VSUnOp PythonCode
equalOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.equalOp
  notEqualOp :: VSUnOp PythonCode
notEqualOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.notEqualOp
  greaterOp :: VSUnOp PythonCode
greaterOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.greaterOp
  greaterEqualOp :: VSUnOp PythonCode
greaterEqualOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.greaterEqualOp
  lessOp :: VSUnOp PythonCode
lessOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.lessOp
  lessEqualOp :: VSUnOp PythonCode
lessEqualOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.lessEqualOp
  plusOp :: VSUnOp PythonCode
plusOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.plusOp
  minusOp :: VSUnOp PythonCode
minusOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.minusOp
  multOp :: VSUnOp PythonCode
multOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.multOp
  divideOp :: VSUnOp PythonCode
divideOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.divideOp
  powerOp :: VSUnOp PythonCode
powerOp = String -> VSUnOp PythonCode
forall (r :: * -> *). Monad r => String -> VSOp r
powerPrec String
pyPower
  moduloOp :: VSUnOp PythonCode
moduloOp = VSUnOp PythonCode
forall (r :: * -> *). Monad r => VSOp r
G.moduloOp
  andOp :: VSUnOp PythonCode
andOp = String -> VSUnOp PythonCode
forall (r :: * -> *). Monad r => String -> VSOp r
andPrec String
pyAnd
  orOp :: VSUnOp PythonCode
orOp = String -> VSUnOp PythonCode
forall (r :: * -> *). Monad r => String -> VSOp r
orPrec String
pyOr

instance OpElim PythonCode where
  uOp :: PythonCode OpData -> Doc
uOp = OpData -> Doc
opDoc (OpData -> Doc)
-> (PythonCode OpData -> OpData) -> PythonCode OpData -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode OpData -> OpData
forall a. PythonCode a -> a
unPC
  bOp :: PythonCode OpData -> Doc
bOp = OpData -> Doc
opDoc (OpData -> Doc)
-> (PythonCode OpData -> OpData) -> PythonCode OpData -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode OpData -> OpData
forall a. PythonCode a -> a
unPC
  uOpPrec :: PythonCode OpData -> Int
uOpPrec = OpData -> Int
opPrec (OpData -> Int)
-> (PythonCode OpData -> OpData) -> PythonCode OpData -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode OpData -> OpData
forall a. PythonCode a -> a
unPC
  bOpPrec :: PythonCode OpData -> Int
bOpPrec = OpData -> Int
opPrec (OpData -> Int)
-> (PythonCode OpData -> OpData) -> PythonCode OpData -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode OpData -> OpData
forall a. PythonCode a -> a
unPC

instance ScopeSym PythonCode where
  global :: PythonCode ScopeData
global = PythonCode ScopeData
forall (r :: * -> *). Monad r => r ScopeData
CP.global
  mainFn :: PythonCode ScopeData
mainFn = PythonCode ScopeData
forall (r :: * -> *). ScopeSym r => r ScopeData
global
  local :: PythonCode ScopeData
local = PythonCode ScopeData
forall (r :: * -> *). Monad r => r ScopeData
G.local

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

instance VariableSym PythonCode where
  var :: String -> VS (PythonCode TypeData) -> SVariable PythonCode
var          = String -> VS (PythonCode TypeData) -> SVariable PythonCode
forall (r :: * -> *).
RenderVariable r =>
String -> VS (r TypeData) -> SVariable r
G.var
  constant :: String -> VS (PythonCode TypeData) -> SVariable PythonCode
constant String
n   = String -> VS (PythonCode TypeData) -> SVariable PythonCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
var (String -> VS (PythonCode TypeData) -> SVariable PythonCode)
-> String -> VS (PythonCode TypeData) -> SVariable PythonCode
forall a b. (a -> b) -> a -> b
$ String -> String
toConstName String
n
  extVar :: String
-> String -> VS (PythonCode TypeData) -> SVariable PythonCode
extVar String
l String
n VS (PythonCode TypeData)
t = (ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addModuleImportVS String
l) StateT ValueState Identity ()
-> SVariable PythonCode -> SVariable PythonCode
forall a b.
StateT ValueState Identity a
-> StateT ValueState Identity b -> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String
-> String -> VS (PythonCode TypeData) -> SVariable PythonCode
forall (r :: * -> *).
RenderVariable r =>
String -> String -> VS (r TypeData) -> SVariable r
CS.extVar String
l String
n VS (PythonCode TypeData)
t

instance OOVariableSym PythonCode where
  classVar :: String -> VS (PythonCode TypeData) -> SVariable PythonCode
classVar = String -> VS (PythonCode TypeData) -> SVariable PythonCode
forall (r :: * -> *).
RenderVariable r =>
String -> VS (r TypeData) -> SVariable r
G.classVar
  classConst :: String -> VS (PythonCode TypeData) -> SVariable PythonCode
classConst String
n VS (PythonCode TypeData)
t = String -> VS (PythonCode TypeData) -> Doc -> SVariable PythonCode
forall (r :: * -> *).
RenderVariable r =>
String -> VS (r TypeData) -> Doc -> SVariable r
mkClassVar String
n VS (PythonCode TypeData)
t (String -> Doc
R.var (String -> String
toConstName String
n))
  classVarAccess :: VS (PythonCode TypeData)
-> SVariable PythonCode -> SVariable PythonCode
classVarAccess = (Doc -> Doc -> Doc)
-> VS (PythonCode TypeData)
-> SVariable PythonCode
-> SVariable PythonCode
forall (r :: * -> *).
(InternalVarElim r, RenderVariable r, UnRepr r TypeData,
 VariableElim r) =>
(Doc -> Doc -> Doc)
-> VS (r TypeData) -> SVariable r -> SVariable r
CP.classVarAccess Doc -> Doc -> Doc
R.classVarAccess
  extClassVarAccess :: VS (PythonCode TypeData)
-> SVariable PythonCode -> SVariable PythonCode
extClassVarAccess VS (PythonCode TypeData)
c SVariable PythonCode
v = StateT ValueState Identity (SVariable PythonCode)
-> SVariable PythonCode
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (StateT ValueState Identity (SVariable PythonCode)
 -> SVariable PythonCode)
-> StateT ValueState Identity (SVariable PythonCode)
-> SVariable PythonCode
forall a b. (a -> b) -> a -> b
$ (PythonCode TypeData -> Map String String -> SVariable PythonCode)
-> VS (PythonCode TypeData)
-> State ValueState (Map String String)
-> StateT ValueState Identity (SVariable PythonCode)
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues (\PythonCode TypeData
t Map String String
cm -> (SVariable PythonCode -> SVariable PythonCode)
-> (String -> SVariable PythonCode -> SVariable PythonCode)
-> Maybe String
-> SVariable PythonCode
-> SVariable PythonCode
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SVariable PythonCode -> SVariable PythonCode
forall a. a -> a
id (StateT ValueState Identity ()
-> SVariable PythonCode -> SVariable PythonCode
forall a b.
StateT ValueState Identity a
-> StateT ValueState Identity b -> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
(>>) (StateT ValueState Identity ()
 -> SVariable PythonCode -> SVariable PythonCode)
-> (String -> StateT ValueState Identity ())
-> String
-> SVariable PythonCode
-> SVariable PythonCode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((ValueState -> ValueState) -> StateT ValueState Identity ())
-> (String -> ValueState -> ValueState)
-> String
-> StateT ValueState Identity ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
    String -> ValueState -> ValueState
addModuleImportVS) (String -> Map String String -> Maybe String
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (PythonCode TypeData -> String
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> String
getTypeString PythonCode TypeData
t) Map String String
cm) (SVariable PythonCode -> SVariable PythonCode)
-> SVariable PythonCode -> SVariable PythonCode
forall a b. (a -> b) -> a -> b
$
    (Doc -> Doc -> Doc)
-> VS (PythonCode TypeData)
-> SVariable PythonCode
-> SVariable PythonCode
forall (r :: * -> *).
(InternalVarElim r, RenderVariable r, UnRepr r TypeData,
 VariableElim r) =>
(Doc -> Doc -> Doc)
-> VS (r TypeData) -> SVariable r -> SVariable r
CP.classVarAccess Doc -> Doc -> Doc
pyClassVarAccess (PythonCode TypeData -> VS (PythonCode TypeData)
forall a s. a -> State s a
toState PythonCode TypeData
t) SVariable PythonCode
v) VS (PythonCode TypeData)
c State ValueState (Map String String)
getClassMap
  instanceVarAccess :: SValue PythonCode -> SVariable PythonCode -> SVariable PythonCode
instanceVarAccess = SValue PythonCode -> SVariable PythonCode -> SVariable PythonCode
forall (r :: * -> *).
(InternalVarElim r, RenderVariable r, ValueElim r,
 VariableElim r) =>
SValue r -> SVariable r -> SVariable r
G.instanceVarAccess

instance SelfSym PythonCode where
  self :: SVariable PythonCode
self = LensLike'
  (Zoomed (StateT MethodState Identity) String)
  ValueState
  MethodState
-> StateT MethodState Identity String
-> StateT ValueState Identity String
forall c.
LensLike'
  (Zoomed (StateT MethodState Identity) c) ValueState MethodState
-> StateT MethodState Identity c -> StateT ValueState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT MethodState Identity) String)
  ValueState
  MethodState
(MethodState -> Focusing Identity String MethodState)
-> ValueState -> Focusing Identity String ValueState
Lens' ValueState MethodState
lensVStoMS StateT MethodState Identity String
getClassName StateT ValueState Identity String
-> (String -> SVariable PythonCode) -> SVariable PythonCode
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\String
l -> String -> VS (PythonCode TypeData) -> Doc -> SVariable PythonCode
forall (r :: * -> *).
RenderVariable r =>
String -> VS (r TypeData) -> Doc -> SVariable r
mkStateVar String
pySelf (String -> VS (PythonCode TypeData)
forall (r :: * -> *). OOTypeSym r => String -> VS (r TypeData)
obj String
l) (String -> Doc
text String
pySelf))

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

instance InternalVarElim PythonCode where
  variableBind :: PythonCode Variable -> AttachmentTag
variableBind = Variable -> AttachmentTag
varBind (Variable -> AttachmentTag)
-> (PythonCode Variable -> Variable)
-> PythonCode Variable
-> AttachmentTag
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Variable -> Variable
forall a. PythonCode a -> a
unPC
  variable :: PythonCode Variable -> Doc
variable = Variable -> Doc
varDoc (Variable -> Doc)
-> (PythonCode Variable -> Variable) -> PythonCode Variable -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Variable -> Variable
forall a. PythonCode a -> a
unPC

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

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

instance OOValueSym PythonCode

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

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

instance MathConstant PythonCode where
  pi :: SValue PythonCode
pi = SValue PythonCode -> SValue PythonCode
forall a. VS a -> VS a
addmathImport (SValue PythonCode -> SValue PythonCode)
-> SValue PythonCode -> SValue PythonCode
forall a b. (a -> b) -> a -> b
$ VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
double Doc
pyPi

instance VariableValue PythonCode where
  valueOf :: SVariable PythonCode -> SValue PythonCode
valueOf = SVariable PythonCode -> SValue PythonCode
forall (r :: * -> *).
(InternalVarElim r, RenderValue r, VariableElim r) =>
SVariable r -> SValue r
G.valueOf

instance OOVariableValue PythonCode

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

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

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

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

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

instance ValueExpression PythonCode where
  inlineIf :: SValue PythonCode
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
inlineIf = SValue PythonCode
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r -> SValue r -> SValue r
pyInlineIf

  funcAppMixedArgs :: MixedCall PythonCode
funcAppMixedArgs = MixedCall PythonCode
forall (r :: * -> *). RenderValue r => MixedCall r
G.funcAppMixedArgs
  extFuncAppMixedArgs :: String -> MixedCall PythonCode
extFuncAppMixedArgs String
l String
n VS (PythonCode TypeData)
t [SValue PythonCode]
ps NamedArgs PythonCode
ns = do
    (ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addModuleImportVS String
l)
    String -> MixedCall PythonCode
forall (r :: * -> *). RenderValue r => String -> MixedCall r
CS.extFuncAppMixedArgs String
l String
n VS (PythonCode TypeData)
t [SValue PythonCode]
ps NamedArgs PythonCode
ns
  libFuncAppMixedArgs :: String -> MixedCall PythonCode
libFuncAppMixedArgs String
l String
n VS (PythonCode TypeData)
t [SValue PythonCode]
ps NamedArgs PythonCode
ns = do
    (ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addLibImportVS String
l)
    String -> MixedCall PythonCode
forall (r :: * -> *). RenderValue r => String -> MixedCall r
CS.extFuncAppMixedArgs String
l String
n VS (PythonCode TypeData)
t [SValue PythonCode]
ps NamedArgs PythonCode
ns

  lambda :: [VSBinder PythonCode] -> SValue PythonCode -> SValue PythonCode
lambda = ([PythonCode BinderD] -> PythonCode Value -> Doc)
-> [VSBinder PythonCode] -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(BinderElim r, RenderValue r, ValueSym r) =>
([r BinderD] -> r Value -> Doc)
-> [VSBinder r] -> SValue r -> SValue r
G.lambda [PythonCode BinderD] -> PythonCode Value -> Doc
forall (r :: * -> *).
(InternalBinderElim r, ValueElim r) =>
[r BinderD] -> r Value -> Doc
pyLambda

  notNull :: SValue PythonCode -> SValue PythonCode
notNull = String -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(Comparison r, VariableValue r) =>
String -> SValue r -> SValue r
CP.notNull String
pyNull

instance OOValueExpression PythonCode where
  newObjMixedArgs :: MixedCtorCall PythonCode
newObjMixedArgs = MixedCall PythonCode
forall (r :: * -> *).
(RenderValue r, UnRepr r TypeData) =>
String -> MixedCtorCall r
G.newObjMixedArgs String
""
  extNewObjMixedArgs :: MixedCall PythonCode
extNewObjMixedArgs String
l VS (PythonCode TypeData)
tp [SValue PythonCode]
ps NamedArgs PythonCode
ns = do
    (ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addModuleImportVS String
l)
    MixedCall PythonCode
forall (r :: * -> *).
(RenderValue r, UnRepr r TypeData) =>
String -> MixedCtorCall r
pyExtNewObjMixedArgs String
l VS (PythonCode TypeData)
tp [SValue PythonCode]
ps NamedArgs PythonCode
ns
  libNewObjMixedArgs :: MixedCall PythonCode
libNewObjMixedArgs String
l VS (PythonCode TypeData)
tp [SValue PythonCode]
ps NamedArgs PythonCode
ns = do
    (ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addLibImportVS String
l)
    MixedCall PythonCode
forall (r :: * -> *).
(RenderValue r, UnRepr r TypeData) =>
String -> MixedCtorCall r
pyExtNewObjMixedArgs String
l VS (PythonCode TypeData)
tp [SValue PythonCode]
ps NamedArgs PythonCode
ns

instance RenderValue PythonCode where
  inputFunc :: SValue PythonCode
inputFunc = VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string Doc
pyInputFunc
  printFunc :: SValue PythonCode
printFunc = VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
pyPrintFunc
  printLnFunc :: SValue PythonCode
printLnFunc = VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
empty
  printFileFunc :: SValue PythonCode -> SValue PythonCode
printFileFunc SValue PythonCode
_ = VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
empty
  printFileLnFunc :: SValue PythonCode -> SValue PythonCode
printFileLnFunc SValue PythonCode
_ = VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
empty

  cast :: VS (PythonCode TypeData) -> SValue PythonCode -> SValue PythonCode
cast = (PythonCode TypeData -> PythonCode Value -> SValue PythonCode)
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> SValue PythonCode
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> m a -> m b -> m c
on2StateWrapped (\PythonCode TypeData
t PythonCode Value
v-> PythonCode TypeData -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
r TypeData -> Doc -> SValue r
mkVal PythonCode TypeData
t (Doc -> SValue PythonCode)
-> (Doc -> Doc) -> Doc -> SValue PythonCode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc -> Doc
R.castObj (PythonCode TypeData -> Doc
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> Doc
renderType PythonCode TypeData
t)
    (Doc -> SValue PythonCode) -> Doc -> SValue PythonCode
forall a b. (a -> b) -> a -> b
$ PythonCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value PythonCode Value
v)

  call :: Maybe String -> Maybe Doc -> MixedCall PythonCode
call = Doc -> Maybe String -> Maybe Doc -> MixedCall PythonCode
forall (r :: * -> *).
(InternalVarElim r, RenderValue r, ValueElim r) =>
Doc -> Maybe String -> Maybe Doc -> MixedCall r
G.call Doc
pyNamedArgSep

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

instance ValueElim PythonCode where
  valuePrec :: PythonCode Value -> Maybe Int
valuePrec = Value -> Maybe Int
valPrec (Value -> Maybe Int)
-> (PythonCode Value -> Value) -> PythonCode Value -> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Value -> Value
forall a. PythonCode a -> a
unPC
  valueInt :: PythonCode Value -> Maybe Integer
valueInt = Value -> Maybe Integer
valInt (Value -> Maybe Integer)
-> (PythonCode Value -> Value) -> PythonCode Value -> Maybe Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Value -> Value
forall a. PythonCode a -> a
unPC
  value :: PythonCode Value -> Doc
value = Value -> Doc
val (Value -> Doc)
-> (PythonCode Value -> Value) -> PythonCode Value -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Value -> Value
forall a. PythonCode a -> a
unPC

instance InternalValueExp PythonCode where
  objMethodCallMixedArgs' :: String
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> [SValue PythonCode]
-> NamedArgs PythonCode
-> SValue PythonCode
objMethodCallMixedArgs' = String
-> VS (PythonCode TypeData)
-> SValue PythonCode
-> [SValue PythonCode]
-> NamedArgs PythonCode
-> SValue PythonCode
forall (r :: * -> *).
(RenderValue r, ValueElim r) =>
String
-> VS (r TypeData)
-> SValue r
-> [SValue r]
-> NamedArgs r
-> SValue r
G.objMethodCall
  classMethodCallMixedArgs' :: String -> VS (PythonCode TypeData) -> MixedCtorCall PythonCode
classMethodCallMixedArgs' = String -> VS (PythonCode TypeData) -> MixedCtorCall PythonCode
forall (r :: * -> *).
(RenderValue r, UnRepr r TypeData) =>
String
-> VS (r TypeData)
-> VS (r TypeData)
-> [SValue r]
-> NamedArgs r
-> SValue r
CG.classMethodCall

instance FunctionSym PythonCode where

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

instance GetSet PythonCode where
  get :: SValue PythonCode -> SVariable PythonCode -> SValue PythonCode
get = SValue PythonCode -> SVariable PythonCode -> SValue PythonCode
forall (r :: * -> *).
(InternalGetSet r, OOFunctionSym r) =>
SValue r -> SVariable r -> SValue r
G.get
  set :: SValue PythonCode
-> SVariable PythonCode -> SValue PythonCode -> SValue PythonCode
set = SValue PythonCode
-> SVariable PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(InternalGetSet r, OOFunctionSym r) =>
SValue r -> SVariable r -> SValue r -> SValue r
G.set

instance IndexTranslator PythonCode where
  intToIndex :: SValue PythonCode -> SValue PythonCode
intToIndex = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). SValue r -> SValue r
CP.intToIndex
  indexToInt :: SValue PythonCode -> SValue PythonCode
indexToInt = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). SValue r -> SValue r
CP.indexToInt

instance Reference PythonCode where
  makeRef :: SValue PythonCode -> SValue PythonCode
makeRef = SValue PythonCode -> SValue PythonCode
forall a. a -> a
id
  maybeDeref :: SValue PythonCode -> SValue PythonCode
maybeDeref = SValue PythonCode -> SValue PythonCode
forall a. a -> a
id

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

instance List PythonCode where
  listSize :: SValue PythonCode -> SValue PythonCode
listSize = String -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
ValueExpression r =>
String -> SValue r -> SValue r
CS.listSize String
pyListSize
  listAccess :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
listAccess = SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(IndexTranslator r, InternalListFunc r, FunctionElim r,
 RenderFunction r, RenderValue r, TypeElim r, ValueElim r) =>
SValue r -> SValue r -> SValue r
G.listAccess
  indexOf :: SValue PythonCode -> SValue PythonCode -> SValue PythonCode
indexOf = String
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(IndexTranslator r, OOFunctionSym r) =>
String -> SValue r -> SValue r -> SValue r
CP.indexOf String
pyIndex

instance ListStatement PythonCode (Doc, Terminator) where
  listAdd :: SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
listAdd = String
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(IndexTranslator r, InternalValueExp r, ValueStatement r stmt) =>
String -> SValue r -> SValue r -> SValue r -> MS (r stmt)
CG.listAdd String
pyInsert
  listAppend :: SValue PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
listAppend = String
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(InternalValueExp r, ValueStatement r stmt) =>
String -> SValue r -> SValue r -> MS (r stmt)
CG.listAppend String
pyAppendFunc
  listSet :: SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
listSet = SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(AssignStatement r stmt, IndexTranslator r, RenderVariable r,
 ValueElim r) =>
SValue r -> SValue r -> SValue r -> MS (r stmt)
CP.listSet

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

instance InternalList PythonCode Block where
  listSlice' :: Maybe (SValue PythonCode)
-> Maybe (SValue PythonCode)
-> Maybe (SValue PythonCode)
-> SVariable PythonCode
-> SValue PythonCode
-> MS (PythonCode Doc)
listSlice' Maybe (SValue PythonCode)
b Maybe (SValue PythonCode)
e Maybe (SValue PythonCode)
s SVariable PythonCode
vn SValue PythonCode
vo = SVariable PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode Doc)
forall (r :: * -> *).
(InternalVarElim r, Monad r, ValueElim r) =>
SVariable r
-> SValue r -> SValue r -> SValue r -> SValue r -> MS (r Doc)
pyListSlice SVariable PythonCode
vn SValue PythonCode
vo (Maybe (SValue PythonCode) -> SValue PythonCode
getVal Maybe (SValue PythonCode)
b) (Maybe (SValue PythonCode) -> SValue PythonCode
getVal Maybe (SValue PythonCode)
e) (Maybe (SValue PythonCode) -> SValue PythonCode
getVal Maybe (SValue PythonCode)
s)
    where getVal :: Maybe (SValue PythonCode) -> SValue PythonCode
getVal = SValue PythonCode -> Maybe (SValue PythonCode) -> SValue PythonCode
forall a. a -> Maybe a -> a
fromMaybe (VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
empty)

instance InternalGetSet PythonCode where
  getFunc :: SVariable PythonCode -> VS (PythonCode FuncData)
getFunc = SVariable PythonCode -> VS (PythonCode FuncData)
forall (r :: * -> *).
(OOFunctionSym r, VariableElim r) =>
SVariable r -> VS (r FuncData)
G.getFunc
  setFunc :: VS (PythonCode TypeData)
-> SVariable PythonCode
-> SValue PythonCode
-> VS (PythonCode FuncData)
setFunc = VS (PythonCode TypeData)
-> SVariable PythonCode
-> SValue PythonCode
-> VS (PythonCode FuncData)
forall (r :: * -> *).
(OOFunctionSym r, VariableElim r) =>
VS (r TypeData) -> SVariable r -> SValue r -> VS (r FuncData)
G.setFunc

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

instance BinderSym PythonCode where
  binder :: String -> VS (PythonCode TypeData) -> VSBinder PythonCode
binder String
nm VS (PythonCode TypeData)
tp = (TypeData -> BinderD) -> PythonCode TypeData -> PythonCode BinderD
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue (String -> TypeData -> BinderD
bindFormD String
nm) (PythonCode TypeData -> PythonCode BinderD)
-> VS (PythonCode TypeData) -> VSBinder PythonCode
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
<$> VS (PythonCode TypeData)
tp

instance BinderElim PythonCode where
  binderName :: PythonCode BinderD -> String
binderName = BinderD -> String
bindName (BinderD -> String)
-> (PythonCode BinderD -> BinderD) -> PythonCode BinderD -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode BinderD -> BinderD
forall a. PythonCode a -> a
unPC
  binderType :: PythonCode BinderD -> PythonCode TypeData
binderType = (BinderD -> TypeData) -> PythonCode BinderD -> PythonCode TypeData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue BinderD -> TypeData
bindType

instance InternalBinderElim PythonCode where
  binderElim :: PythonCode BinderD -> Doc
binderElim = String -> Doc
text (String -> Doc)
-> (PythonCode BinderD -> String) -> PythonCode BinderD -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BinderD -> String
bindName (BinderD -> String)
-> (PythonCode BinderD -> BinderD) -> PythonCode BinderD -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode BinderD -> BinderD
forall a. PythonCode a -> a
unPC

instance RenderFunction PythonCode where
  funcFromData :: Doc -> VS (PythonCode TypeData) -> VS (PythonCode FuncData)
funcFromData Doc
d = (PythonCode TypeData -> PythonCode FuncData)
-> VS (PythonCode TypeData) -> VS (PythonCode FuncData)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue ((TypeData -> FuncData)
-> PythonCode TypeData -> PythonCode FuncData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue (TypeData -> Doc -> FuncData
`fd` Doc
d))

instance FunctionElim PythonCode where
  functionType :: PythonCode FuncData -> PythonCode TypeData
functionType = (FuncData -> TypeData)
-> PythonCode FuncData -> PythonCode TypeData
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue FuncData -> TypeData
fType
  function :: PythonCode FuncData -> Doc
function = FuncData -> Doc
funcDoc (FuncData -> Doc)
-> (PythonCode FuncData -> FuncData) -> PythonCode FuncData -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode FuncData -> FuncData
forall a. PythonCode a -> a
unPC

instance InternalAssignStmt PythonCode (Doc, Terminator) where
  multiAssign :: [SVariable PythonCode]
-> [SValue PythonCode] -> MS (PythonCode (Doc, Terminator))
multiAssign = (Doc -> Doc)
-> [SVariable PythonCode]
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(AssignStatement r stmt, InternalVarElim r, RenderValue r,
 RenderVariable r, ValueElim r) =>
(Doc -> Doc) -> [SVariable r] -> [SValue r] -> MS (r stmt)
CP.multiAssign Doc -> Doc
forall a. a -> a
id

instance InternalIOStmt PythonCode (Doc, Terminator) where
  printSt :: Bool
-> Maybe (SValue PythonCode)
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
printSt = Bool
-> Maybe (SValue PythonCode)
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
pyPrint

instance InternalControlStmt PythonCode (Doc, Terminator) where
  multiReturn :: [SValue PythonCode] -> MS (PythonCode (Doc, Terminator))
multiReturn = (Doc -> Doc)
-> [SValue PythonCode] -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt bod.
(ControlStatement r stmt bod, RenderValue r, ValueElim r) =>
(Doc -> Doc) -> [SValue r] -> MS (r stmt)
CP.multiReturn Doc -> Doc
forall a. a -> a
id

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

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

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

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

instance ValueStatement PythonCode (Doc, Terminator) where
  valStmt :: SValue PythonCode -> MS (PythonCode (Doc, Terminator))
valStmt = Terminator
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(RenderStatement r stmt, ValueElim r) =>
Terminator -> SValue r -> MS (r stmt)
G.valStmt Terminator
Empty

instance AssignStatement PythonCode (Doc, Terminator) where
  assign :: SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
assign = Terminator
-> SVariable PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(InternalVarElim r, RenderStatement r stmt, ValueElim r) =>
Terminator -> SVariable r -> SValue r -> MS (r stmt)
G.assign Terminator
Empty
  &-= :: SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
(&-=) = Terminator
-> SVariable PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(InternalVarElim r, RenderStatement r stmt, ValueElim r) =>
Terminator -> SVariable r -> SValue r -> MS (r stmt)
G.subAssign Terminator
Empty
  &+= :: SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
(&+=) = SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(InternalVarElim r, RenderStatement r stmt, ValueElim r) =>
SVariable r -> SValue r -> MS (r stmt)
CS.increment
  &++ :: SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
(&++) = SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(AssignStatement r stmt, Literal r) =>
SVariable r -> MS (r stmt)
M.increment1
  &-- :: SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
(&--) = SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(AssignStatement r stmt, Literal r) =>
SVariable r -> MS (r stmt)
M.decrement1

instance DeclStatement PythonCode (Doc, Terminator) Body where
  varDec :: SVariable PythonCode
-> PythonCode ScopeData -> MS (PythonCode (Doc, Terminator))
varDec SVariable PythonCode
v PythonCode ScopeData
scp = SVariable PythonCode
-> PythonCode ScopeData
-> Maybe (SValue PythonCode)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(EmptyStatement r stmt, AssignStatement r stmt, ScopeElim r,
 VariableElim r) =>
SVariable r -> r ScopeData -> Maybe (SValue r) -> MS (r stmt)
CS.varDecDef SVariable PythonCode
v PythonCode ScopeData
scp Maybe (SValue PythonCode)
forall a. Maybe a
Nothing
  varDecDef :: SVariable PythonCode
-> PythonCode ScopeData
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
varDecDef SVariable PythonCode
v PythonCode ScopeData
scp SValue PythonCode
e = SVariable PythonCode
-> PythonCode ScopeData
-> Maybe (SValue PythonCode)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(EmptyStatement r stmt, AssignStatement r stmt, ScopeElim r,
 VariableElim r) =>
SVariable r -> r ScopeData -> Maybe (SValue r) -> MS (r stmt)
CS.varDecDef SVariable PythonCode
v PythonCode ScopeData
scp (SValue PythonCode -> Maybe (SValue PythonCode)
forall a. a -> Maybe a
Just SValue PythonCode
e)
  setDec :: SVariable PythonCode
-> PythonCode ScopeData -> MS (PythonCode (Doc, Terminator))
setDec = SVariable PythonCode
-> PythonCode ScopeData -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt bod.
DeclStatement r stmt bod =>
SVariable r -> r ScopeData -> MS (r stmt)
varDec
  setDecDef :: SVariable PythonCode
-> PythonCode ScopeData
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
setDecDef = SVariable PythonCode
-> PythonCode ScopeData
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt bod.
DeclStatement r stmt bod =>
SVariable r -> r ScopeData -> SValue r -> MS (r stmt)
varDecDef
  listDec :: Integer
-> SVariable PythonCode
-> PythonCode ScopeData
-> MS (PythonCode (Doc, Terminator))
listDec Integer
_ = SVariable PythonCode
-> PythonCode ScopeData -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt bod.
(DeclStatement r stmt bod, Literal r, VariableElim r) =>
SVariable r -> r ScopeData -> MS (r stmt)
CP.listDec
  listDecDef :: SVariable PythonCode
-> PythonCode ScopeData
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
listDecDef = SVariable PythonCode
-> PythonCode ScopeData
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt bod.
(DeclStatement r stmt bod, Literal r, VariableElim r) =>
SVariable r -> r ScopeData -> [SValue r] -> MS (r stmt)
CP.listDecDef
  arrayDec :: Integer
-> SValue PythonCode
-> SVariable PythonCode
-> PythonCode ScopeData
-> MS (PythonCode (Doc, Terminator))
arrayDec = Integer
-> SValue PythonCode
-> SVariable PythonCode
-> PythonCode ScopeData
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) bod block stmt.
(BodySym r bod block, BlockSym r block stmt, MultiStatement r stmt,
 DeclStatement r stmt bod, ControlStatement r stmt bod, Literal r,
 VariableValue r, ListStatement r stmt, VariableElim r) =>
Integer -> SValue r -> SVariable r -> r ScopeData -> MS (r stmt)
M.arrayDecAsList
  arrayDecDef :: SVariable PythonCode
-> PythonCode ScopeData
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
arrayDecDef = SVariable PythonCode
-> PythonCode ScopeData
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt bod.
DeclStatement r stmt bod =>
SVariable r -> r ScopeData -> [SValue r] -> MS (r stmt)
listDecDef
  constDecDef :: SVariable PythonCode
-> PythonCode ScopeData
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
constDecDef SVariable PythonCode
v PythonCode ScopeData
scp SValue PythonCode
e = do
    v' <- LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Variable))
  MethodState
  ValueState
-> SVariable PythonCode
-> StateT MethodState Identity (PythonCode Variable)
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Variable))
  MethodState
  ValueState
(ValueState -> Focusing Identity (PythonCode Variable) ValueState)
-> MethodState
-> Focusing Identity (PythonCode Variable) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable PythonCode
v
    let n = String -> String
toConstName (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ PythonCode Variable -> String
forall (r :: * -> *). VariableElim r => r Variable -> String
variableName PythonCode Variable
v'
        newConst = String -> VS (PythonCode TypeData) -> SVariable PythonCode
forall (r :: * -> *).
VariableSym r =>
String -> VS (r TypeData) -> SVariable r
constant String
n (PythonCode TypeData -> VS (PythonCode TypeData)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PythonCode Variable -> PythonCode TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType PythonCode Variable
v'))
    available <- varNameAvailable n
    if available
      then varDecDef newConst scp e
      else error "Cannot safely capitalize constant."
  funcDecDef :: SVariable PythonCode
-> PythonCode ScopeData
-> [SVariable PythonCode]
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
funcDecDef = SVariable PythonCode
-> PythonCode ScopeData
-> [SVariable PythonCode]
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) vis stmt mthd stvr attch file mod bod block.
OORenderSym r vis stmt mthd stvr attch file mod bod block =>
SVariable r
-> r ScopeData -> [SVariable r] -> MS (r bod) -> MS (r stmt)
CP.funcDecDef

instance OODeclStatement PythonCode (Doc, Terminator) Body where
  objDecDef :: SVariable PythonCode
-> PythonCode ScopeData
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
objDecDef = SVariable PythonCode
-> PythonCode ScopeData
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt bod.
DeclStatement r stmt bod =>
SVariable r -> r ScopeData -> SValue r -> MS (r stmt)
varDecDef
  objDecNew :: SVariable PythonCode
-> PythonCode ScopeData
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
objDecNew = SVariable PythonCode
-> PythonCode ScopeData
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt bod.
(DeclStatement r stmt bod, OOValueExpression r, VariableElim r) =>
SVariable r -> r ScopeData -> [SValue r] -> MS (r stmt)
G.objDecNew
  extObjDecNew :: String
-> SVariable PythonCode
-> PythonCode ScopeData
-> [SValue PythonCode]
-> MS (PythonCode (Doc, Terminator))
extObjDecNew String
lib SVariable PythonCode
v PythonCode ScopeData
scp [SValue PythonCode]
vs = do
    (MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> MethodState -> MethodState
addModuleImport String
lib)
    SVariable PythonCode
-> PythonCode ScopeData
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt bod.
DeclStatement r stmt bod =>
SVariable r -> r ScopeData -> SValue r -> MS (r stmt)
varDecDef SVariable PythonCode
v PythonCode ScopeData
scp (String
-> VS (PythonCode TypeData)
-> [SValue PythonCode]
-> SValue PythonCode
forall (r :: * -> *).
OOValueExpression r =>
String -> PosCtorCall r
extNewObj String
lib ((PythonCode Variable -> PythonCode TypeData)
-> SVariable PythonCode -> VS (PythonCode TypeData)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue PythonCode Variable -> PythonCode TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType SVariable PythonCode
v) [SValue PythonCode]
vs)

instance PrintConsole PythonCode (Doc, Terminator) where
  print :: SValue PythonCode -> MS (PythonCode (Doc, Terminator))
print      = Bool
-> Maybe (SValue PythonCode)
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) bod block stmt.
(BodySym r bod block, BlockSym r block stmt, Literal r,
 NumericExpression r, Comparison r, VariableValue r, List r,
 MultiStatement r stmt, DeclStatement r stmt bod,
 AssignStatement r stmt, ControlStatement r stmt bod,
 PrintConsole r stmt, PrintFile r stmt, InternalIOStmt r stmt,
 TypeElim r) =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r stmt)
pyOut Bool
False Maybe (SValue PythonCode)
forall a. Maybe a
Nothing SValue PythonCode
forall (r :: * -> *). RenderValue r => SValue r
printFunc
  printLn :: SValue PythonCode -> MS (PythonCode (Doc, Terminator))
printLn    = Bool
-> Maybe (SValue PythonCode)
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) bod block stmt.
(BodySym r bod block, BlockSym r block stmt, Literal r,
 NumericExpression r, Comparison r, VariableValue r, List r,
 MultiStatement r stmt, DeclStatement r stmt bod,
 AssignStatement r stmt, ControlStatement r stmt bod,
 PrintConsole r stmt, PrintFile r stmt, InternalIOStmt r stmt,
 TypeElim r) =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r stmt)
pyOut Bool
True  Maybe (SValue PythonCode)
forall a. Maybe a
Nothing SValue PythonCode
forall (r :: * -> *). RenderValue r => SValue r
printFunc
  printStr :: String -> MS (PythonCode (Doc, Terminator))
printStr   = SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
PrintConsole r stmt =>
SValue r -> MS (r stmt)
print   (SValue PythonCode -> MS (PythonCode (Doc, Terminator)))
-> (String -> SValue PythonCode)
-> String
-> MS (PythonCode (Doc, Terminator))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SValue PythonCode
forall (r :: * -> *). Literal r => String -> SValue r
litString
  printStrLn :: String -> MS (PythonCode (Doc, Terminator))
printStrLn = SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
PrintConsole r stmt =>
SValue r -> MS (r stmt)
printLn (SValue PythonCode -> MS (PythonCode (Doc, Terminator)))
-> (String -> SValue PythonCode)
-> String
-> MS (PythonCode (Doc, Terminator))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SValue PythonCode
forall (r :: * -> *). Literal r => String -> SValue r
litString

instance ReadConsole PythonCode (Doc, Terminator) where
  getInput :: SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
getInput = SValue PythonCode
-> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
pyInput SValue PythonCode
forall (r :: * -> *). RenderValue r => SValue r
inputFunc
  discardInput :: MS (PythonCode (Doc, Terminator))
discardInput = SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
ValueStatement r stmt =>
SValue r -> MS (r stmt)
valStmt SValue PythonCode
forall (r :: * -> *). RenderValue r => SValue r
inputFunc

instance FileHandling PythonCode (Doc, Terminator) where
  openFileR :: SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
openFileR SVariable PythonCode
f SValue PythonCode
n = SVariable PythonCode
f SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
&= SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(Literal r, ValueExpression r) =>
SValue r -> SValue r
CP.openFileR' SValue PythonCode
n
  openFileW :: SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
openFileW SVariable PythonCode
f SValue PythonCode
n = SVariable PythonCode
f SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
&= SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(Literal r, ValueExpression r) =>
SValue r -> SValue r
CP.openFileW' SValue PythonCode
n
  openFileA :: SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
openFileA SVariable PythonCode
f SValue PythonCode
n = SVariable PythonCode
f SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
&= SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
(Literal r, ValueExpression r) =>
SValue r -> SValue r
CP.openFileA' SValue PythonCode
n
  closeFile :: SValue PythonCode -> MS (PythonCode (Doc, Terminator))
closeFile = String -> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(InternalValueExp r, ValueStatement r stmt) =>
String -> SValue r -> MS (r stmt)
G.closeFile String
pyClose

instance ReadFile PythonCode (Doc, Terminator) where
  getFileInput :: SValue PythonCode
-> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
getFileInput SValue PythonCode
f = SValue PythonCode
-> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
pyInput (SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). InternalValueExp r => SValue r -> SValue r
readline SValue PythonCode
f)
  discardFileInput :: SValue PythonCode -> MS (PythonCode (Doc, Terminator))
discardFileInput SValue PythonCode
f = SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
ValueStatement r stmt =>
SValue r -> MS (r stmt)
valStmt (SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). InternalValueExp r => SValue r -> SValue r
readline SValue PythonCode
f)
  getFileInputLine :: SValue PythonCode
-> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
getFileInputLine = SValue PythonCode
-> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
ReadFile r stmt =>
SValue r -> SVariable r -> MS (r stmt)
getFileInput
  discardFileLine :: SValue PythonCode -> MS (PythonCode (Doc, Terminator))
discardFileLine = String -> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(InternalValueExp r, ValueStatement r stmt) =>
String -> SValue r -> MS (r stmt)
CP.discardFileLine String
pyReadline
  getFileInputAll :: SValue PythonCode
-> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
getFileInputAll SValue PythonCode
f SVariable PythonCode
v = SVariable PythonCode
v SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
&= SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). InternalValueExp r => SValue r -> SValue r
readlines SValue PythonCode
f

instance PrintFile PythonCode (Doc, Terminator) where
  printFile :: SValue PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
printFile SValue PythonCode
f      = Bool
-> Maybe (SValue PythonCode)
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) bod block stmt.
(BodySym r bod block, BlockSym r block stmt, Literal r,
 NumericExpression r, Comparison r, VariableValue r, List r,
 MultiStatement r stmt, DeclStatement r stmt bod,
 AssignStatement r stmt, ControlStatement r stmt bod,
 PrintConsole r stmt, PrintFile r stmt, InternalIOStmt r stmt,
 TypeElim r) =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r stmt)
pyOut Bool
False (SValue PythonCode -> Maybe (SValue PythonCode)
forall a. a -> Maybe a
Just SValue PythonCode
f) SValue PythonCode
forall (r :: * -> *). RenderValue r => SValue r
printFunc
  printFileLn :: SValue PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
printFileLn SValue PythonCode
f    = Bool
-> Maybe (SValue PythonCode)
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) bod block stmt.
(BodySym r bod block, BlockSym r block stmt, Literal r,
 NumericExpression r, Comparison r, VariableValue r, List r,
 MultiStatement r stmt, DeclStatement r stmt bod,
 AssignStatement r stmt, ControlStatement r stmt bod,
 PrintConsole r stmt, PrintFile r stmt, InternalIOStmt r stmt,
 TypeElim r) =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r stmt)
pyOut Bool
True  (SValue PythonCode -> Maybe (SValue PythonCode)
forall a. a -> Maybe a
Just SValue PythonCode
f) SValue PythonCode
forall (r :: * -> *). RenderValue r => SValue r
printFunc
  printFileStr :: SValue PythonCode -> String -> MS (PythonCode (Doc, Terminator))
printFileStr SValue PythonCode
f   = SValue PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
PrintFile r stmt =>
SValue r -> SValue r -> MS (r stmt)
printFile SValue PythonCode
f   (SValue PythonCode -> MS (PythonCode (Doc, Terminator)))
-> (String -> SValue PythonCode)
-> String
-> MS (PythonCode (Doc, Terminator))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SValue PythonCode
forall (r :: * -> *). Literal r => String -> SValue r
litString
  printFileStrLn :: SValue PythonCode -> String -> MS (PythonCode (Doc, Terminator))
printFileStrLn SValue PythonCode
f = SValue PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
PrintFile r stmt =>
SValue r -> SValue r -> MS (r stmt)
printFileLn SValue PythonCode
f (SValue PythonCode -> MS (PythonCode (Doc, Terminator)))
-> (String -> SValue PythonCode)
-> String
-> MS (PythonCode (Doc, Terminator))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SValue PythonCode
forall (r :: * -> *). Literal r => String -> SValue r
litString

instance StringStatement PythonCode (Doc, Terminator) where
  stringSplit :: Char
-> SVariable PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
stringSplit Char
d SVariable PythonCode
vnew SValue PythonCode
s = SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
assign SVariable PythonCode
vnew (SValue PythonCode -> VS (PythonCode FuncData) -> SValue PythonCode
forall (r :: * -> *).
OOFunctionSym r =>
SValue r -> VS (r FuncData) -> SValue r
objAccess SValue PythonCode
s (Char -> VS (PythonCode FuncData)
forall (r :: * -> *).
(Literal r, OOFunctionSym r) =>
Char -> VS (r FuncData)
splitFunc Char
d))

  stringListVals :: [SVariable PythonCode]
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
stringListVals = [SVariable PythonCode]
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(MultiStatement r stmt, AssignStatement r stmt, List r, Literal r,
 RenderValue r, TypeElim r, VariableElim r) =>
[SVariable r] -> SValue r -> MS (r stmt)
M.stringListVals
  stringListLists :: [SVariable PythonCode]
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
stringListLists = [SVariable PythonCode]
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) bod block stmt.
(BodySym r bod block, BlockSym r block stmt,
 ControlStatement r stmt bod, Literal r, NumericExpression r,
 VariableValue r, List r, ListStatement r stmt, TypeElim r,
 VariableElim r, RenderValue r) =>
[SVariable r] -> SValue r -> MS (r stmt)
M.stringListLists

instance FuncAppStatement PythonCode (Doc, Terminator) where
  inOutCall :: InOutCall PythonCode (Doc, Terminator)
inOutCall = (String
 -> VS (PythonCode TypeData)
 -> [SValue PythonCode]
 -> SValue PythonCode)
-> InOutCall PythonCode (Doc, Terminator)
forall (r :: * -> *) stmt.
(InternalAssignStmt r stmt, ValueStatement r stmt,
 VariableValue r) =>
(String -> VS (r TypeData) -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MS (r stmt)
CP.inOutCall String
-> VS (PythonCode TypeData)
-> [SValue PythonCode]
-> SValue PythonCode
forall (r :: * -> *). ValueExpression r => PosCall r
funcApp
  extInOutCall :: String -> InOutCall PythonCode (Doc, Terminator)
extInOutCall String
m = (String
 -> VS (PythonCode TypeData)
 -> [SValue PythonCode]
 -> SValue PythonCode)
-> InOutCall PythonCode (Doc, Terminator)
forall (r :: * -> *) stmt.
(InternalAssignStmt r stmt, ValueStatement r stmt,
 VariableValue r) =>
(String -> VS (r TypeData) -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MS (r stmt)
CP.inOutCall (String
-> String
-> VS (PythonCode TypeData)
-> [SValue PythonCode]
-> SValue PythonCode
forall (r :: * -> *). ValueExpression r => String -> PosCall r
extFuncApp String
m)

instance OOFuncAppStatement PythonCode (Doc, Terminator) where
  selfInOutCall :: InOutCall PythonCode (Doc, Terminator)
selfInOutCall = (String
 -> VS (PythonCode TypeData)
 -> [SValue PythonCode]
 -> SValue PythonCode)
-> InOutCall PythonCode (Doc, Terminator)
forall (r :: * -> *) stmt.
(InternalAssignStmt r stmt, ValueStatement r stmt,
 VariableValue r) =>
(String -> VS (r TypeData) -> [SValue r] -> SValue r)
-> String
-> [SValue r]
-> [SVariable r]
-> [SVariable r]
-> MS (r stmt)
CP.inOutCall String
-> VS (PythonCode TypeData)
-> [SValue PythonCode]
-> SValue PythonCode
forall (r :: * -> *).
(InternalValueExp r, VariableValue r, SelfSym r) =>
PosCall r
selfMethodCall

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

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

  returnStmt :: SValue PythonCode -> MS (PythonCode (Doc, Terminator))
returnStmt = Terminator
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(RenderStatement r stmt, ValueElim r) =>
Terminator -> SValue r -> MS (r stmt)
G.returnStmt Terminator
Empty

  throw :: String -> MS (PythonCode (Doc, Terminator))
throw = (PythonCode Value -> Doc)
-> Terminator -> String -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
(Literal r, RenderStatement r stmt) =>
(r Value -> Doc) -> Terminator -> String -> MS (r stmt)
G.throw PythonCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
pyThrow Terminator
Empty

  ifCond :: [(SValue PythonCode, MS (PythonCode Doc))]
-> MS (PythonCode Doc) -> MS (PythonCode (Doc, Terminator))
ifCond = (Doc -> Doc)
-> Doc
-> OptionalSpace
-> Doc
-> Doc
-> Doc
-> [(SValue PythonCode, MS (PythonCode Doc))]
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) bod stmt.
(BodyElim r bod, RenderStatement r stmt, ValueElim r) =>
(Doc -> Doc)
-> Doc
-> OptionalSpace
-> Doc
-> Doc
-> Doc
-> [(SValue r, MS (r bod))]
-> MS (r bod)
-> MS (r stmt)
G.ifCond Doc -> Doc
forall a. a -> a
id Doc
pyBodyStart OptionalSpace
pySpace Doc
pyElseIf Doc
pyBodyEnd Doc
empty
  switch :: SValue PythonCode
-> [(SValue PythonCode, MS (PythonCode Doc))]
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
switch = SValue PythonCode
-> [(SValue PythonCode, MS (PythonCode Doc))]
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt bod.
(ControlStatement r stmt bod, Comparison r) =>
SValue r -> [(SValue r, MS (r bod))] -> MS (r bod) -> MS (r stmt)
switchAsIf

  ifExists :: SValue PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
ifExists = SValue PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt bod.
(ControlStatement r stmt bod, ValueExpression r) =>
SValue r -> MS (r bod) -> MS (r bod) -> MS (r stmt)
M.ifExists

  for :: MS (PythonCode (Doc, Terminator))
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
for MS (PythonCode (Doc, Terminator))
_ SValue PythonCode
_ MS (PythonCode (Doc, Terminator))
_ MS (PythonCode Doc)
_ = String -> MS (PythonCode (Doc, Terminator))
forall a. HasCallStack => String -> a
error (String -> MS (PythonCode (Doc, Terminator)))
-> String -> MS (PythonCode (Doc, Terminator))
forall a b. (a -> b) -> a -> b
$ String -> String
CP.forLoopError String
pyName
  forRange :: SVariable PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forRange SVariable PythonCode
i SValue PythonCode
initv SValue PythonCode
finalv SValue PythonCode
stepv = SVariable PythonCode
-> SValue PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt bod.
ControlStatement r stmt bod =>
SVariable r -> SValue r -> MS (r bod) -> MS (r stmt)
forEach SVariable PythonCode
i (SValue PythonCode
-> SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
ValueExpression r =>
SValue r -> SValue r -> SValue r -> SValue r
range SValue PythonCode
initv SValue PythonCode
finalv SValue PythonCode
stepv)
  forEach :: SVariable PythonCode
-> SValue PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forEach = (PythonCode Variable -> PythonCode Value -> PythonCode Doc -> Doc)
-> SVariable PythonCode
-> SValue PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
RenderStatement r stmt =>
(r Variable -> r Value -> r Doc -> Doc)
-> SVariable r -> SValue r -> MS (r Doc) -> MS (r stmt)
CS.forEach' PythonCode Variable -> PythonCode Value -> PythonCode Doc -> Doc
forall (r :: * -> *) bod.
(BodyElim r bod, InternalVarElim r, ValueElim r) =>
r Variable -> r Value -> r bod -> Doc
pyForEach
  while :: SValue PythonCode
-> MS (PythonCode Doc) -> MS (PythonCode (Doc, Terminator))
while SValue PythonCode
v' MS (PythonCode Doc)
b' = do
    v <- LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Value))
  MethodState
  ValueState
-> SValue PythonCode
-> StateT MethodState Identity (PythonCode Value)
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Value))
  MethodState
  ValueState
(ValueState -> Focusing Identity (PythonCode Value) ValueState)
-> MethodState -> Focusing Identity (PythonCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue PythonCode
v'
    b <- b'
    mkStmtNoEnd (pyWhile v b)

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

  assert :: SValue PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
assert SValue PythonCode
condition SValue PythonCode
errorMessage = do
      cond <- LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Value))
  MethodState
  ValueState
-> SValue PythonCode
-> StateT MethodState Identity (PythonCode Value)
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Value))
  MethodState
  ValueState
(ValueState -> Focusing Identity (PythonCode Value) ValueState)
-> MethodState -> Focusing Identity (PythonCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue PythonCode
condition
      errMsg <- zoom lensMStoVS errorMessage
      mkStmtNoEnd (pyAssert cond errMsg)

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

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

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

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

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

instance MethodTypeSym PythonCode where
  mType :: VS (PythonCode TypeData) -> MSMthdType PythonCode
mType = LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode TypeData))
  MethodState
  ValueState
-> VS (PythonCode TypeData) -> MSMthdType PythonCode
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode TypeData))
  MethodState
  ValueState
(ValueState -> Focusing Identity (PythonCode TypeData) ValueState)
-> MethodState
-> Focusing Identity (PythonCode TypeData) MethodState
Lens' MethodState ValueState
lensMStoVS

instance OOMethodTypeSym PythonCode where
  construct :: String -> MSMthdType PythonCode
construct = String -> MSMthdType PythonCode
forall (r :: * -> *). Monad r => String -> MS (r TypeData)
G.construct

instance ParameterSym PythonCode where
  param :: SVariable PythonCode -> MS (PythonCode ParamData)
param = (PythonCode Variable -> Doc)
-> SVariable PythonCode -> MS (PythonCode ParamData)
forall (r :: * -> *).
(RenderParam r, VariableElim r) =>
(r Variable -> Doc) -> SVariable r -> MS (r ParamData)
G.param PythonCode Variable -> Doc
forall (r :: * -> *). InternalVarElim r => r Variable -> Doc
RC.variable
  pointerParam :: SVariable PythonCode -> MS (PythonCode ParamData)
pointerParam = SVariable PythonCode -> MS (PythonCode ParamData)
forall (r :: * -> *).
ParameterSym r =>
SVariable r -> MS (r ParamData)
param

instance RenderParam PythonCode where
  paramFromData :: SVariable PythonCode -> Doc -> MS (PythonCode ParamData)
paramFromData SVariable PythonCode
v' Doc
d = do
    v <- LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Variable))
  MethodState
  ValueState
-> SVariable PythonCode
-> StateT MethodState Identity (PythonCode Variable)
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Variable))
  MethodState
  ValueState
(ValueState -> Focusing Identity (PythonCode Variable) ValueState)
-> MethodState
-> Focusing Identity (PythonCode Variable) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable PythonCode
v'
    toState $ on2CodeValues pd v (toCode d)

instance ParamElim PythonCode where
  parameterName :: PythonCode ParamData -> String
parameterName = PythonCode Variable -> String
forall (r :: * -> *). VariableElim r => r Variable -> String
variableName (PythonCode Variable -> String)
-> (PythonCode ParamData -> PythonCode Variable)
-> PythonCode ParamData
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ParamData -> Variable)
-> PythonCode ParamData -> PythonCode Variable
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ParamData -> Variable
paramVar
  parameterType :: PythonCode ParamData -> PythonCode TypeData
parameterType = PythonCode Variable -> PythonCode TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType (PythonCode Variable -> PythonCode TypeData)
-> (PythonCode ParamData -> PythonCode Variable)
-> PythonCode ParamData
-> PythonCode TypeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ParamData -> Variable)
-> PythonCode ParamData -> PythonCode Variable
forall (r :: * -> *) a b. Functor r => (a -> b) -> r a -> r b
onCodeValue ParamData -> Variable
paramVar
  parameter :: PythonCode ParamData -> Doc
parameter = ParamData -> Doc
paramDoc (ParamData -> Doc)
-> (PythonCode ParamData -> ParamData)
-> PythonCode ParamData
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode ParamData -> ParamData
forall a. PythonCode a -> a
unPC

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

  inOutFunc :: String -> PythonCode Doc -> InOutFunc PythonCode MethodData Doc
inOutFunc String
n PythonCode Doc
s = (VS (PythonCode TypeData)
 -> [MS (PythonCode ParamData)]
 -> MS (PythonCode Doc)
 -> MS (PythonCode MethodData))
-> InOutFunc PythonCode MethodData Doc
forall (r :: * -> *) stmt bod block mthd.
(VariableValue r, ParameterSym r, DeclStatement r stmt bod,
 BlockSym r block stmt, BodySym r bod block, VariableElim r,
 RenderBody r bod, RenderType r, InternalControlStmt r stmt) =>
(VS (r TypeData)
 -> [MS (r ParamData)] -> MS (r bod) -> MS (r mthd))
-> [SVariable r]
-> [SVariable r]
-> [SVariable r]
-> MS (r bod)
-> MS (r mthd)
CP.inOutFunc (String
-> PythonCode Doc
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
forall (r :: * -> *) vis mthd bod.
MethodSym r vis mthd bod =>
String
-> r vis
-> VS (r TypeData)
-> [MS (r ParamData)]
-> MS (r bod)
-> MS (r mthd)
function String
n PythonCode Doc
s)
  docInOutFunc :: String -> PythonCode Doc -> DocInOutFunc PythonCode MethodData Doc
docInOutFunc String
n PythonCode Doc
s = FuncDocRenderer
-> InOutFunc PythonCode MethodData Doc
-> DocInOutFunc PythonCode MethodData Doc
forall (r :: * -> *) mthd bod.
RenderMethod r mthd =>
FuncDocRenderer
-> ([SVariable r]
    -> [SVariable r] -> [SVariable r] -> MS (r bod) -> MS (r mthd))
-> String
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> MS (r bod)
-> MS (r mthd)
CP.docInOutFunc' FuncDocRenderer
functionDox (String -> PythonCode Doc -> InOutFunc PythonCode MethodData Doc
forall (r :: * -> *) vis mthd bod.
MethodSym r vis mthd bod =>
String -> r vis -> InOutFunc r mthd bod
inOutFunc String
n PythonCode Doc
s)

instance OOMethodSym PythonCode Doc MethodData AttachmentData Body where
  method :: String
-> PythonCode Doc
-> PythonCode AttachmentData
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
method = String
-> PythonCode Doc
-> PythonCode AttachmentData
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
forall (r :: * -> *) vis mthd attch bod.
OORenderMethod r vis mthd attch bod =>
String
-> r vis
-> r attch
-> VS (r TypeData)
-> [MS (r ParamData)]
-> MS (r bod)
-> MS (r mthd)
G.method
  getMethod :: SVariable PythonCode -> MS (PythonCode MethodData)
getMethod = SVariable PythonCode -> MS (PythonCode MethodData)
forall (r :: * -> *) vis stmt mthd stvr attch file mod bod block.
OORenderSym r vis stmt mthd stvr attch file mod bod block =>
SVariable r -> MS (r mthd)
G.getMethod
  setMethod :: SVariable PythonCode -> MS (PythonCode MethodData)
setMethod = SVariable PythonCode -> MS (PythonCode MethodData)
forall (r :: * -> *) vis stmt mthd stvr attch file mod bod block.
OORenderSym r vis stmt mthd stvr attch file mod bod block =>
SVariable r -> MS (r mthd)
G.setMethod
  constructor :: [MS (PythonCode ParamData)]
-> NamedArgs PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
constructor = String
-> [MS (PythonCode ParamData)]
-> NamedArgs PythonCode
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
forall (r :: * -> *) vis stmt mthd stvr attch file mod bod block.
OORenderSym r vis stmt mthd stvr attch file mod bod block =>
String
-> [MS (r ParamData)]
-> Initializers r
-> MS (r bod)
-> MS (r mthd)
CP.constructor String
initName

  inOutMethod :: String
-> PythonCode Doc
-> PythonCode AttachmentData
-> InOutFunc PythonCode MethodData Doc
inOutMethod String
n PythonCode Doc
s PythonCode AttachmentData
p = (VS (PythonCode TypeData)
 -> [MS (PythonCode ParamData)]
 -> MS (PythonCode Doc)
 -> MS (PythonCode MethodData))
-> InOutFunc PythonCode MethodData Doc
forall (r :: * -> *) stmt bod block mthd.
(VariableValue r, ParameterSym r, DeclStatement r stmt bod,
 BlockSym r block stmt, BodySym r bod block, VariableElim r,
 RenderBody r bod, RenderType r, InternalControlStmt r stmt) =>
(VS (r TypeData)
 -> [MS (r ParamData)] -> MS (r bod) -> MS (r mthd))
-> [SVariable r]
-> [SVariable r]
-> [SVariable r]
-> MS (r bod)
-> MS (r mthd)
CP.inOutFunc (String
-> PythonCode Doc
-> PythonCode AttachmentData
-> VS (PythonCode TypeData)
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
forall (r :: * -> *) vis mthd attch bod.
OOMethodSym r vis mthd attch bod =>
String
-> r vis
-> r attch
-> VS (r TypeData)
-> [MS (r ParamData)]
-> MS (r bod)
-> MS (r mthd)
method String
n PythonCode Doc
s PythonCode AttachmentData
p)
  docInOutMethod :: String
-> PythonCode Doc
-> PythonCode AttachmentData
-> DocInOutFunc PythonCode MethodData Doc
docInOutMethod String
n PythonCode Doc
s PythonCode AttachmentData
p = FuncDocRenderer
-> InOutFunc PythonCode MethodData Doc
-> DocInOutFunc PythonCode MethodData Doc
forall (r :: * -> *) mthd bod.
RenderMethod r mthd =>
FuncDocRenderer
-> ([SVariable r]
    -> [SVariable r] -> [SVariable r] -> MS (r bod) -> MS (r mthd))
-> String
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> [(String, SVariable r)]
-> MS (r bod)
-> MS (r mthd)
CP.docInOutFunc' FuncDocRenderer
functionDox (String
-> PythonCode Doc
-> PythonCode AttachmentData
-> InOutFunc PythonCode MethodData Doc
forall (r :: * -> *) vis mthd attch bod.
OOMethodSym r vis mthd attch bod =>
String -> r vis -> r attch -> InOutFunc r mthd bod
inOutMethod String
n PythonCode Doc
s PythonCode AttachmentData
p)

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

  mthdFromData :: VisibilityTag -> Doc -> MS (PythonCode MethodData)
mthdFromData VisibilityTag
_ Doc
d = PythonCode MethodData -> MS (PythonCode MethodData)
forall a s. a -> State s a
toState (PythonCode MethodData -> MS (PythonCode MethodData))
-> PythonCode MethodData -> MS (PythonCode MethodData)
forall a b. (a -> b) -> a -> b
$ MethodData -> PythonCode MethodData
forall (r :: * -> *) a. Monad r => a -> r a
toCode (MethodData -> PythonCode MethodData)
-> MethodData -> PythonCode MethodData
forall a b. (a -> b) -> a -> b
$ String -> Doc -> MethodData
mthd String
"" Doc
d

instance OORenderMethod PythonCode Doc MethodData AttachmentData Body where
  intMethod :: Bool
-> String
-> PythonCode Doc
-> PythonCode AttachmentData
-> MSMthdType PythonCode
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
intMethod Bool
m String
n PythonCode Doc
_ PythonCode AttachmentData
a MSMthdType PythonCode
_ [MS (PythonCode ParamData)]
ps MS (PythonCode Doc)
b = do
    (MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (if Bool
m then MethodState -> MethodState
setCurrMain else MethodState -> MethodState
forall a. a -> a
id)
    sl <- LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Variable))
  MethodState
  ValueState
-> SVariable PythonCode
-> StateT MethodState Identity (PythonCode Variable)
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Variable))
  MethodState
  ValueState
(ValueState -> Focusing Identity (PythonCode Variable) ValueState)
-> MethodState
-> Focusing Identity (PythonCode Variable) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable PythonCode
forall (r :: * -> *). SelfSym r => SVariable r
self
    pms <- sequence ps
    toCode . mthd n . pyMethod n a sl pms <$> b
  intFunc :: Bool
-> String
-> PythonCode Doc
-> PythonCode AttachmentData
-> MSMthdType PythonCode
-> [MS (PythonCode ParamData)]
-> MS (PythonCode Doc)
-> MS (PythonCode MethodData)
intFunc Bool
m String
n PythonCode Doc
_ PythonCode AttachmentData
_ MSMthdType PythonCode
_ [MS (PythonCode ParamData)]
ps MS (PythonCode Doc)
b = do
    (MethodState -> MethodState) -> StateT MethodState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (if Bool
m then MethodState -> MethodState
setCurrMain else MethodState -> MethodState
forall a. a -> a
id)
    bd <- MS (PythonCode Doc)
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 -> Doc
method = MethodData -> Doc
mthdDoc (MethodData -> Doc)
-> (PythonCode MethodData -> MethodData)
-> PythonCode MethodData
-> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode MethodData -> MethodData
forall a. PythonCode a -> a
unPC

instance StateVarSym PythonCode Doc Doc AttachmentData where
  stateVar :: PythonCode Doc
-> PythonCode AttachmentData
-> SVariable PythonCode
-> CSStateVar PythonCode Doc
stateVar PythonCode Doc
_ PythonCode AttachmentData
_ SVariable PythonCode
_ = PythonCode Doc -> CSStateVar PythonCode Doc
forall a s. a -> State s a
toState (Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode Doc
empty)
  stateVarDef :: PythonCode Doc
-> PythonCode AttachmentData
-> SVariable PythonCode
-> SValue PythonCode
-> CSStateVar PythonCode Doc
stateVarDef = PythonCode Doc
-> PythonCode AttachmentData
-> SVariable PythonCode
-> SValue PythonCode
-> CSStateVar PythonCode Doc
forall (r :: * -> *) vis stmt mthd stvr attch file mod bod block.
(OORenderSym r vis stmt mthd stvr attch file mod bod block,
 Monad r) =>
r vis -> r attch -> SVariable r -> SValue r -> CS (r Doc)
CP.stateVarDef
  constVar :: PythonCode Doc
-> SVariable PythonCode
-> SValue PythonCode
-> CSStateVar PythonCode Doc
constVar = Doc
-> PythonCode Doc
-> SVariable PythonCode
-> SValue PythonCode
-> CSStateVar PythonCode Doc
forall (r :: * -> *) vis stmt mthd bod block.
(CommonRenderSym r vis stmt mthd bod block, Monad r) =>
Doc -> r vis -> SVariable r -> SValue r -> CS (r Doc)
CP.constVar (PythonCode AttachmentData -> Doc
forall {k} (r :: k -> *) (attch :: k).
PermElim r attch =>
r attch -> Doc
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 Doc -> Doc
stateVar = PythonCode Doc -> Doc
forall a. PythonCode a -> a
unPC

instance ClassSym PythonCode Doc MethodData StateVar AttachmentData where
  buildClass :: Maybe String
-> [CSStateVar PythonCode Doc]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Doc
buildClass Maybe String
par [CSStateVar PythonCode Doc]
sVars [MS (PythonCode MethodData)]
cstrs = if [MS (PythonCode MethodData)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [MS (PythonCode MethodData)]
cstrs Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
1
                                  then Maybe String
-> [CSStateVar PythonCode Doc]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Doc
forall (r :: * -> *) vis mthd stvr.
(RenderClass r vis mthd stvr, VisibilitySym r vis) =>
Maybe String
-> [CSStateVar r stvr]
-> [MS (r mthd)]
-> [MS (r mthd)]
-> CS (r Doc)
G.buildClass Maybe String
par [CSStateVar PythonCode Doc]
sVars [MS (PythonCode MethodData)]
cstrs
                                  else String -> [MS (PythonCode MethodData)] -> CSStateVar PythonCode Doc
forall a. HasCallStack => String -> a
error String
pyMultCstrsError
  extraClass :: String
-> Maybe String
-> [CSStateVar PythonCode Doc]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Doc
extraClass String
n Maybe String
par [CSStateVar PythonCode Doc]
sVars [MS (PythonCode MethodData)]
cstrs = if
                                  [MS (PythonCode MethodData)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [MS (PythonCode MethodData)]
cstrs Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
1
                                    then String
-> Maybe String
-> [CSStateVar PythonCode Doc]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Doc
forall (r :: * -> *) vis mthd stvr.
(RenderClass r vis mthd stvr, VisibilitySym r vis) =>
String
-> Maybe String
-> [CSStateVar r stvr]
-> [MS (r mthd)]
-> [MS (r mthd)]
-> CS (r Doc)
CP.extraClass String
n Maybe String
par [CSStateVar PythonCode Doc]
sVars [MS (PythonCode MethodData)]
cstrs
                                    else String -> [MS (PythonCode MethodData)] -> CSStateVar PythonCode Doc
forall a. HasCallStack => String -> a
error String
pyMultCstrsError
  implementingClass :: String
-> [String]
-> [CSStateVar PythonCode Doc]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Doc
implementingClass String
n [String]
iNms [CSStateVar PythonCode Doc]
sVars [MS (PythonCode MethodData)]
cstrs = if
                                  [MS (PythonCode MethodData)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [MS (PythonCode MethodData)]
cstrs Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
1
                                    then String
-> [String]
-> [CSStateVar PythonCode Doc]
-> [MS (PythonCode MethodData)]
-> [MS (PythonCode MethodData)]
-> CSStateVar PythonCode Doc
forall (r :: * -> *) vis mthd stvr.
(RenderClass r vis mthd stvr, VisibilitySym r vis) =>
String
-> [String]
-> [CSStateVar r stvr]
-> [MS (r mthd)]
-> [MS (r mthd)]
-> CS (r Doc)
G.implementingClass String
n [String]
iNms [CSStateVar PythonCode Doc]
sVars [MS (PythonCode MethodData)]
cstrs
                                    else String -> [MS (PythonCode MethodData)] -> CSStateVar PythonCode Doc
forall a. HasCallStack => String -> a
error String
pyMultCstrsError

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

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

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

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

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

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

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

instance ModuleElim PythonCode ModData where
  module' :: PythonCode ModData -> Doc
module' = ModData -> Doc
modDoc (ModData -> Doc)
-> (PythonCode ModData -> ModData) -> PythonCode ModData -> Doc
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 Doc
blockComment [String]
lns = Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> PythonCode Doc) -> Doc -> PythonCode Doc
forall a b. (a -> b) -> a -> b
$ [String] -> Doc -> Doc
pyBlockComment [String]
lns Doc
pyCommentStart
  docComment :: forall a. State a [String] -> State a (PythonCode Doc)
docComment = ([String] -> PythonCode Doc)
-> State a [String] -> State a (PythonCode Doc)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue (\[String]
lns -> Doc -> PythonCode Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> PythonCode Doc) -> Doc -> PythonCode Doc
forall a b. (a -> b) -> a -> b
$ [String] -> Doc -> Doc -> Doc
pyDocComment [String]
lns Doc
pyDocCommentStart
    Doc
pyCommentStart)

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

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

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

pyPi :: Doc
pyPi :: Doc
pyPi = String -> Doc
text (String -> Doc) -> String -> Doc
forall a b. (a -> b) -> a -> b
$ String
pyMath String -> String -> String
`access` String
piLabel

pySys :: String
pySys :: String
pySys = String
"sys"

pyInputFunc, pyPrintFunc :: Doc
pyInputFunc :: Doc
pyInputFunc = String -> Doc
text String
"input()" -- raw_input() for < Python 3.0
pyPrintFunc :: Doc
pyPrintFunc = String -> Doc
text String
printLabel

pyListSize, pyIndex, pyInsert, pyAppendFunc, pyReadline, pyReadlines, pyClose,
  pySplit, pyRange, pyRstrip, pyMath, pyIn, pyAdd, pyRemove, pyUnion :: String
pyListSize :: String
pyListSize = String
"len"
pyIndex :: String
pyIndex = String
"index"
pyInsert :: String
pyInsert = String
"insert"
pyAppendFunc :: String
pyAppendFunc = String
"append"
pyReadline :: String
pyReadline = String
"readline"
pyReadlines :: String
pyReadlines = String
"readlines"
pyClose :: String
pyClose = String
"close"
pySplit :: String
pySplit = String
"split"
pyRange :: String
pyRange = String
"range"
pyRstrip :: String
pyRstrip = String
"rstrip"
pyMath :: String
pyMath = String
"math"
pyIn :: String
pyIn = String
"in"
pyAdd :: String
pyAdd = String
"add"
pyRemove :: String
pyRemove = String
"remove"
pyUnion :: String
pyUnion = String
"union"

pyDef, pyLambdaDec, pyElseIf, pyRaise, pyExcept :: Doc
pyDef :: Doc
pyDef = String -> Doc
text String
"def"
pyLambdaDec :: Doc
pyLambdaDec = String -> Doc
text String
"lambda"
pyElseIf :: Doc
pyElseIf = String -> Doc
text String
"elif"
pyRaise :: Doc
pyRaise = String -> Doc
text String
"raise"
pyExcept :: Doc
pyExcept = String -> Doc
text String
"except"

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

pySpace :: OptionalSpace
pySpace :: OptionalSpace
pySpace = OSpace {oSpace :: Doc
oSpace = Doc
empty}

pyNotOp :: (Monad r) => VSOp r
pyNotOp :: forall (r :: * -> *). Monad r => VSOp r
pyNotOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec String
"not"

pySqrtOp :: (Monad r) => VSOp r
pySqrtOp :: forall (r :: * -> *). Monad r => VSOp r
pySqrtOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.sqrt

pyAbsOp :: (Monad r) => VSOp r
pyAbsOp :: forall (r :: * -> *). Monad r => VSOp r
pyAbsOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.fabs

pyLogOp :: (Monad r) => VSOp r
pyLogOp :: forall (r :: * -> *). Monad r => VSOp r
pyLogOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.log10

pyLnOp :: (Monad r) => VSOp r
pyLnOp :: forall (r :: * -> *). Monad r => VSOp r
pyLnOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.log

pyExpOp :: (Monad r) => VSOp r
pyExpOp :: forall (r :: * -> *). Monad r => VSOp r
pyExpOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.exp

pySinOp :: (Monad r) => VSOp r
pySinOp :: forall (r :: * -> *). Monad r => VSOp r
pySinOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.sin

pyCosOp :: (Monad r) => VSOp r
pyCosOp :: forall (r :: * -> *). Monad r => VSOp r
pyCosOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.cos

pyTanOp :: (Monad r) => VSOp r
pyTanOp :: forall (r :: * -> *). Monad r => VSOp r
pyTanOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.tan

pyAsinOp :: (Monad r) => VSOp r
pyAsinOp :: forall (r :: * -> *). Monad r => VSOp r
pyAsinOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.asin

pyAcosOp :: (Monad r) => VSOp r
pyAcosOp :: forall (r :: * -> *). Monad r => VSOp r
pyAcosOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.acos

pyAtanOp :: (Monad r) => VSOp r
pyAtanOp :: forall (r :: * -> *). Monad r => VSOp r
pyAtanOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.atan

pyFloorOp :: (Monad r) => VSOp r
pyFloorOp :: forall (r :: * -> *). Monad r => VSOp r
pyFloorOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.floor

pyCeilOp :: (Monad r) => VSOp r
pyCeilOp :: forall (r :: * -> *). Monad r => VSOp r
pyCeilOp = String -> VSOp r
forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc String
R.ceil

addmathImport :: VS a -> VS a
addmathImport :: forall a. VS a -> VS a
addmathImport = StateT ValueState Identity ()
-> StateT ValueState Identity a -> StateT ValueState Identity a
forall a b.
StateT ValueState Identity a
-> StateT ValueState Identity b -> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
(>>) (StateT ValueState Identity ()
 -> StateT ValueState Identity a -> StateT ValueState Identity a)
-> StateT ValueState Identity ()
-> StateT ValueState Identity a
-> StateT ValueState Identity a
forall a b. (a -> b) -> a -> b
$ (ValueState -> ValueState) -> StateT ValueState Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (String -> ValueState -> ValueState
addLangImportVS String
pyMath)

mathFunc :: (Monad r) => String -> VSOp r
mathFunc :: forall (r :: * -> *). Monad r => String -> VSOp r
mathFunc = VS (r OpData) -> VS (r OpData)
forall a. VS a -> VS a
addmathImport (VS (r OpData) -> VS (r OpData))
-> (String -> VS (r OpData)) -> String -> VS (r OpData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> VS (r OpData)
forall (r :: * -> *). Monad r => String -> VSOp r
unOpPrec (String -> VS (r OpData))
-> (String -> String) -> String -> VS (r OpData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String -> String
access String
pyMath

splitFunc :: (Literal r, OOFunctionSym r) => Char -> VS (r FuncData)
splitFunc :: forall (r :: * -> *).
(Literal r, OOFunctionSym r) =>
Char -> VS (r FuncData)
splitFunc Char
d = String -> VS (r TypeData) -> [SValue r] -> VS (r FuncData)
forall (r :: * -> *).
OOFunctionSym r =>
String -> VS (r TypeData) -> [SValue r] -> VS (r FuncData)
func String
pySplit (VS (r TypeData) -> VS (r TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string) [String -> SValue r
forall (r :: * -> *). Literal r => String -> SValue r
litString [Char
d]]

readline, readlines :: (InternalValueExp r) => SValue r -> SValue r
readline :: forall (r :: * -> *). InternalValueExp r => SValue r -> SValue r
readline SValue r
f = VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
objMethodCall VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string SValue r
f String
pyReadline []
readlines :: forall (r :: * -> *). InternalValueExp r => SValue r -> SValue r
readlines SValue r
f = VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
objMethodCall (VS (r TypeData) -> VS (r TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string) SValue r
f String
pyReadlines []

readInt, readDouble :: (ValueExpression r) => SValue r -> SValue r
readInt :: forall (r :: * -> *). ValueExpression r => SValue r -> SValue r
readInt SValue r
inSrc = PosCall r
forall (r :: * -> *). ValueExpression r => PosCall r
funcApp String
pyInt VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
int [SValue r
inSrc]
readDouble :: forall (r :: * -> *). ValueExpression r => SValue r -> SValue r
readDouble SValue r
inSrc = PosCall r
forall (r :: * -> *). ValueExpression r => PosCall r
funcApp String
pyDouble VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
double [SValue r
inSrc]

readString :: (InternalValueExp r) => SValue r -> SValue r
readString :: forall (r :: * -> *). InternalValueExp r => SValue r -> SValue r
readString SValue r
inSrc = VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
forall (r :: * -> *).
InternalValueExp r =>
VS (r TypeData) -> SValue r -> String -> [SValue r] -> SValue r
objMethodCall VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
string SValue r
inSrc String
pyRstrip []

range :: (ValueExpression r) => SValue r -> SValue r -> SValue r -> SValue r
range :: forall (r :: * -> *).
ValueExpression r =>
SValue r -> SValue r -> SValue r -> SValue r
range SValue r
initv SValue r
finalv SValue r
stepv = PosCall r
forall (r :: * -> *). ValueExpression r => PosCall r
funcApp String
pyRange (VS (r TypeData) -> VS (r TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
listType VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
int) [SValue r
initv, SValue r
finalv, SValue r
stepv]

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

pyInlineIf
  :: (RenderValue r, ValueElim r, ValueSym r)
  => SValue r -> SValue r -> SValue r -> SValue r
pyInlineIf :: forall (r :: * -> *).
(RenderValue r, ValueElim r, ValueSym r) =>
SValue r -> SValue r -> SValue r -> SValue r
pyInlineIf SValue r
c' SValue r
v1' SValue r
v2' = do
  c <- SValue r
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, ValueElim r)
  => [r BinderD] -> r Value -> Doc
pyLambda :: forall (r :: * -> *).
(InternalBinderElim r, ValueElim r) =>
[r BinderD] -> r Value -> Doc
pyLambda [r BinderD]
ps r Value
ex = Doc
pyLambdaDec Doc -> Doc -> Doc
<+> [r BinderD] -> Doc
forall (r :: * -> *). InternalBinderElim r => [r BinderD] -> Doc
binderList [r BinderD]
ps Doc -> Doc -> Doc
<> Doc
colon Doc -> Doc -> Doc
<+> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
ex

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

pyExtNewObjMixedArgs
  :: (RenderValue r, UnRepr r TypeData)
  => Library -> MixedCtorCall r
pyExtNewObjMixedArgs :: forall (r :: * -> *).
(RenderValue r, UnRepr r TypeData) =>
String -> MixedCtorCall r
pyExtNewObjMixedArgs String
l VS (r TypeData)
tp [SValue r]
vs NamedArgs r
ns = VS (r TypeData)
tp VS (r TypeData) -> (r TypeData -> SValue r) -> SValue r
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\r TypeData
t -> Maybe String -> Maybe Doc -> MixedCall r
forall (r :: * -> *).
RenderValue r =>
Maybe String -> Maybe Doc -> MixedCall r
call (String -> Maybe String
forall a. a -> Maybe a
Just String
l) Maybe Doc
forall a. Maybe a
Nothing
  (r TypeData -> String
forall (r :: * -> *). UnRepr r TypeData => r TypeData -> String
getTypeString r TypeData
t) (r TypeData -> VS (r TypeData)
forall a. a -> StateT ValueState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure r TypeData
t) [SValue r]
vs NamedArgs r
ns)

pyPrint :: Bool -> Maybe (SValue PythonCode) -> SValue PythonCode ->
  SValue PythonCode -> MS (PythonCode (Doc, Terminator))
pyPrint :: Bool
-> Maybe (SValue PythonCode)
-> SValue PythonCode
-> SValue PythonCode
-> MS (PythonCode (Doc, Terminator))
pyPrint Bool
newLn Maybe (SValue PythonCode)
f' SValue PythonCode
p' SValue PythonCode
v' = do
    f <- LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Value))
  MethodState
  ValueState
-> SValue PythonCode
-> StateT MethodState Identity (PythonCode Value)
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (PythonCode Value))
  MethodState
  ValueState
(ValueState -> Focusing Identity (PythonCode Value) ValueState)
-> MethodState -> Focusing Identity (PythonCode Value) MethodState
Lens' MethodState ValueState
lensMStoVS (SValue PythonCode
 -> StateT MethodState Identity (PythonCode Value))
-> SValue PythonCode
-> StateT MethodState Identity (PythonCode Value)
forall a b. (a -> b) -> a -> b
$ SValue PythonCode -> Maybe (SValue PythonCode) -> SValue PythonCode
forall a. a -> Maybe a -> a
fromMaybe (VS (PythonCode TypeData) -> Doc -> SValue PythonCode
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> Doc -> SValue r
mkStateVal VS (PythonCode TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
void Doc
empty) Maybe (SValue PythonCode)
f'
    prf <- zoom lensMStoVS p'
    v <- zoom lensMStoVS v'
    s <- zoom lensMStoVS (litString "" :: SValue PythonCode)
    let nl = if Bool
newLn then Doc
empty else Doc
listSep' Doc -> Doc -> Doc
<> String -> Doc
text String
"end" Doc -> Doc -> Doc
<> Doc
equals Doc -> Doc -> Doc
<>
               PythonCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value PythonCode Value
s
        fl = Doc -> Doc -> Doc
emptyIfEmpty (PythonCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value PythonCode Value
f) (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ Doc
listSep' Doc -> Doc -> Doc
<> String -> Doc
text String
"file" Doc -> Doc -> Doc
<> Doc
equals
               Doc -> Doc -> Doc
<> PythonCode Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value PythonCode Value
f
    mkStmtNoEnd $ RC.value prf <> parens (RC.value v <> nl <> fl)

pyOut
  ::
    ( BodySym r bod block
    , BlockSym r block stmt
    , Literal r
    , NumericExpression r
    , Comparison r
    , VariableValue r
    , List r
    , MultiStatement r stmt
    , DeclStatement r stmt bod
    , AssignStatement r stmt
    , ControlStatement r stmt bod
    , PrintConsole r stmt
    , PrintFile r stmt
    , InternalIOStmt r stmt
    , TypeElim r
    )
  => Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r stmt)
pyOut :: forall (r :: * -> *) bod block stmt.
(BodySym r bod block, BlockSym r block stmt, Literal r,
 NumericExpression r, Comparison r, VariableValue r, List r,
 MultiStatement r stmt, DeclStatement r stmt bod,
 AssignStatement r stmt, ControlStatement r stmt bod,
 PrintConsole r stmt, PrintFile r stmt, InternalIOStmt r stmt,
 TypeElim r) =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r stmt)
pyOut Bool
newLn Maybe (SValue r)
f SValue r
printFn SValue r
v = LensLike'
  (Zoomed (StateT ValueState Identity) (r Value))
  MethodState
  ValueState
-> SValue r -> StateT MethodState Identity (r Value)
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r Value))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r Value) ValueState)
-> MethodState -> Focusing Identity (r Value) MethodState
Lens' MethodState ValueState
lensMStoVS SValue r
v StateT MethodState Identity (r Value)
-> (r Value -> StateT MethodState Identity (r 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 Value -> CodeType)
-> r Value
-> StateT MethodState Identity (r stmt)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (r TypeData -> CodeType)
-> (r Value -> r TypeData) -> r Value -> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r Value -> r TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType
  where pyOut' :: CodeType -> StateT MethodState Identity (r stmt)
pyOut' (List CodeType
_) = Bool
-> Maybe (SValue r)
-> SValue r
-> SValue r
-> StateT MethodState Identity (r stmt)
forall (r :: * -> *) stmt.
InternalIOStmt r stmt =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r stmt)
printSt Bool
newLn Maybe (SValue r)
f SValue r
printFn SValue r
v
        pyOut' CodeType
_ = Bool
-> Maybe (SValue r)
-> SValue r
-> SValue r
-> StateT MethodState Identity (r stmt)
forall (r :: * -> *) block stmt bod.
(BlockSym r block stmt, BodySym r bod block, MultiStatement r stmt,
 PrintConsole r stmt, PrintFile r stmt, DeclStatement r stmt bod,
 AssignStatement r stmt, ControlStatement r stmt bod, Literal r,
 NumericExpression r, Comparison r, VariableValue r, List r,
 TypeElim r, InternalIOStmt r stmt) =>
Bool -> Maybe (SValue r) -> SValue r -> SValue r -> MS (r stmt)
G.print Bool
newLn Maybe (SValue r)
f SValue r
printFn SValue r
v

pyInput :: SValue PythonCode -> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
pyInput :: SValue PythonCode
-> SVariable PythonCode -> MS (PythonCode (Doc, Terminator))
pyInput SValue PythonCode
inSrc SVariable PythonCode
v = SVariable PythonCode
v SVariable PythonCode
-> SValue PythonCode -> MS (PythonCode (Doc, Terminator))
forall (r :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
&= (SVariable PythonCode
v SVariable PythonCode
-> (PythonCode Variable -> SValue PythonCode) -> SValue PythonCode
forall a b.
StateT ValueState Identity a
-> (a -> StateT ValueState Identity b)
-> StateT ValueState Identity b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CodeType -> SValue PythonCode
pyInput' (CodeType -> SValue PythonCode)
-> (PythonCode Variable -> CodeType)
-> PythonCode Variable
-> SValue PythonCode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (PythonCode TypeData -> CodeType)
-> (PythonCode Variable -> PythonCode TypeData)
-> PythonCode Variable
-> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PythonCode Variable -> PythonCode TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType)
  where pyInput' :: CodeType -> SValue PythonCode
pyInput' CodeType
Integer = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). ValueExpression r => SValue r -> SValue r
readInt SValue PythonCode
inSrc
        pyInput' CodeType
Float = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). ValueExpression r => SValue r -> SValue r
readDouble SValue PythonCode
inSrc
        pyInput' CodeType
Double = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). ValueExpression r => SValue r -> SValue r
readDouble SValue PythonCode
inSrc
        pyInput' CodeType
Boolean = SValue PythonCode
inSrc SValue PythonCode -> SValue PythonCode -> SValue PythonCode
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?!= String -> SValue PythonCode
forall (r :: * -> *). Literal r => String -> SValue r
litString String
"0"
        pyInput' CodeType
String = SValue PythonCode -> SValue PythonCode
forall (r :: * -> *). InternalValueExp r => SValue r -> SValue r
readString SValue PythonCode
inSrc
        pyInput' CodeType
Char = SValue PythonCode
inSrc
        pyInput' CodeType
_ = String -> SValue PythonCode
forall a. HasCallStack => String -> a
error String
"Attempt to read a value of unreadable type"

pyThrow :: (ValueElim r) => r Value -> Doc
pyThrow :: forall (r :: * -> *). ValueElim r => r Value -> Doc
pyThrow r Value
errMsg = Doc
pyRaise Doc -> Doc -> Doc
<+> Doc
exceptionObj' Doc -> Doc -> Doc
<> Doc -> Doc
parens (r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
errMsg)

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

pyWhile :: (BodyElim r bod, ValueElim r) => r Value -> r bod -> Doc
pyWhile :: forall (r :: * -> *) bod.
(BodyElim r bod, ValueElim r) =>
r Value -> r bod -> Doc
pyWhile r Value
v r bod
b = [Doc] -> Doc
vcat [
  Doc
whileLabel Doc -> Doc -> Doc
<+> r Value -> Doc
forall (r :: * -> *). ValueElim r => r Value -> Doc
RC.value r Value
v Doc -> Doc -> Doc
<> Doc
colon,
  Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ r bod -> Doc
forall {k} (r :: k -> *) (bod :: k). BodyElim r bod => r bod -> Doc
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 -> Doc
pyTryCatch r bod
tryB r bod
catchB = [Doc] -> Doc
vcat [
  Doc
tryLabel Doc -> Doc -> Doc
<> Doc
colon,
  Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ r bod -> Doc
forall {k} (r :: k -> *) (bod :: k). BodyElim r bod => r bod -> Doc
RC.body r bod
tryB,
  Doc
pyExcept Doc -> Doc -> Doc
<+> Doc
exceptionObj' Doc -> Doc -> Doc
<> Doc
colon,
  Doc -> Doc
indent (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ r bod -> Doc
forall {k} (r :: k -> *) (bod :: k). BodyElim r bod => r bod -> Doc
RC.body r bod
catchB]

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

pyListSlice :: (InternalVarElim r, Monad r, ValueElim r) => SVariable r ->
  SValue r -> SValue r -> SValue r -> SValue r -> MS (r Doc)
pyListSlice :: forall (r :: * -> *).
(InternalVarElim r, Monad r, ValueElim r) =>
SVariable r
-> SValue r -> SValue r -> SValue r -> SValue r -> MS (r Doc)
pyListSlice SVariable r
vn SValue r
vo SValue r
beg SValue r
end SValue r
step = LensLike'
  (Zoomed (StateT ValueState Identity) (r Doc))
  MethodState
  ValueState
-> StateT ValueState Identity (r Doc)
-> StateT MethodState Identity (r Doc)
forall c.
LensLike'
  (Zoomed (StateT ValueState Identity) c) MethodState ValueState
-> StateT ValueState Identity c -> StateT MethodState Identity c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
zoom LensLike'
  (Zoomed (StateT ValueState Identity) (r Doc))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r Doc) ValueState)
-> MethodState -> Focusing Identity (r Doc) MethodState
Lens' MethodState ValueState
lensMStoVS (StateT ValueState Identity (r Doc)
 -> StateT MethodState Identity (r Doc))
-> StateT ValueState Identity (r Doc)
-> StateT MethodState Identity (r Doc)
forall a b. (a -> b) -> a -> b
$ do
  vnew <- SVariable r
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 Doc
-> Doc
pyMethod String
n PythonCode AttachmentData
attch PythonCode Variable
slf [PythonCode ParamData]
ps PythonCode Doc
b = let
     decorator :: Doc
decorator = case PythonCode AttachmentData -> AttachmentTag
forall {k} (r :: k -> *) (attch :: k).
PermElim r attch =>
r attch -> AttachmentTag
binding PythonCode AttachmentData
attch of
                   AttachmentTag
ClassLevel -> String -> Doc
text String
"@staticmethod"
                   AttachmentTag
_          -> Doc
empty
     pms :: Doc
pms = [PythonCode ParamData] -> Doc
forall (r :: * -> *). ParamElim r => [r ParamData] -> Doc
parameterList [PythonCode ParamData]
ps
     (Doc
implicitParam, Doc
implicitComma) = case PythonCode AttachmentData -> AttachmentTag
forall {k} (r :: k -> *) (attch :: k).
PermElim r attch =>
r attch -> AttachmentTag
binding PythonCode AttachmentData
attch of
                       AttachmentTag
InstanceLevel -> (PythonCode Variable -> Doc
forall (r :: * -> *). InternalVarElim r => r Variable -> Doc
RC.variable PythonCode Variable
slf, Doc -> Doc -> Doc
emptyIfEmpty Doc
pms Doc
listSep')
                       AttachmentTag
_             -> (Doc
empty, Doc
empty)
     bodyD :: Doc
bodyD | Doc -> Bool
isEmpty (PythonCode Doc -> Doc
forall {k} (r :: k -> *) (bod :: k). BodyElim r bod => r bod -> Doc
RC.body PythonCode Doc
b) = Doc
pyNull'
           | Bool
otherwise = PythonCode Doc -> Doc
forall {k} (r :: k -> *) (bod :: k). BodyElim r bod => r bod -> Doc
RC.body PythonCode Doc
b
  in [Doc] -> Doc
vcat [
       Doc
decorator,
       Doc
pyDef Doc -> Doc -> Doc
<+> String -> Doc
text String
n Doc -> Doc -> Doc
<> Doc -> Doc
parens (Doc
implicitParam Doc -> Doc -> Doc
<> Doc
implicitComma Doc -> Doc -> Doc
<> Doc
pms) Doc -> Doc -> Doc
<> Doc
colon,
       Doc -> Doc
indent Doc
bodyD]

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

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

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

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

pyDocComment :: [String] -> Doc -> Doc -> Doc
pyDocComment :: [String] -> Doc -> Doc -> Doc
pyDocComment [] Doc
_ Doc
_ = Doc
empty
pyDocComment (String
l:[String]
lns) Doc
start Doc
mid = [Doc] -> Doc
vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ Doc
start Doc -> Doc -> Doc
<+> String -> Doc
text String
l Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
: (String -> Doc) -> [String] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Doc -> Doc -> Doc
(<+>) Doc
mid (Doc -> Doc) -> (String -> Doc) -> String -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  String -> Doc
text) [String]
lns

toConstName :: String -> String
toConstName :: String -> String
toConstName (Char
s:Char
s':String
ss) = if Char -> Bool
isLower Char
s Bool -> Bool -> Bool
&& Char -> Bool
isUpper Char
s'
                          then Char -> Char
toUpper Char
s Char -> String -> String
forall a. a -> [a] -> [a]
: Char
'_' Char -> String -> String
forall a. a -> [a] -> [a]
: Char
s' Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
toConstName String
ss
                          else Char -> Char
toUpper Char
s Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
toConstName (Char
s' Char -> String -> String
forall a. a -> [a] -> [a]
: String
ss)
toConstName (Char
s:String
ss)    = Char -> Char
toUpper Char
s Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
toConstName String
ss
toConstName String
""        = String
""