-- | Language-polymorphic functions that are defined by GOOL code
module Drasil.Shared.LanguageRenderer.Macros (
  ifExists, decrement1, increment, increment1, runStrategy,
  listSlice, makeSetterVal, stringListVals, stringListLists, forRange,
  notifyObservers, notifyObservers', arrayDecAsList
) where

import Drasil.Shared.CodeType (CodeType(..))
import Drasil.Shared.InterfaceCommon (Label, SVariable, SValue, bodyStatements,
  oneLiner, VariableElim(..), getCodeType, listOf, ValueSym(valueType),
  NumericExpression((#+), (#-), (#*), (#/)), Comparison(..),
  BooleanExpression((?&&), (?||)), List, at, EmptyStatement(emptyStmt),
  MultiStatement(multi), ValueStatement(valStmt),
  AssignStatement((&+=), (&-=), (&++)), (&=), convScope, VariableValue, BodySym,
  ControlStatement, DeclStatement, Literal)
import qualified Drasil.Shared.InterfaceCommon as IC
import Drasil.GOOL.InterfaceGOOL (($.), observerListName, OOFunctionSym)
import Drasil.Shared.RendererClassesCommon (RenderValue(cast),
  ValueElim(valueInt))
import qualified Drasil.Shared.RendererClassesCommon as S (
  RenderStatement(stmt), RenderValue)
import qualified Drasil.Shared.RendererClassesCommon as RC (BodyElim(..),
  StatementElim(statement))
import Drasil.Shared.Helpers (toCode, onStateValue, on2StateValues)
import Drasil.Shared.State (MS, VS, MS, lensMStoVS, genVarName, genLoopIndex,
  genVarNameIf, getVarScope)
import Drasil.Shared.AST (ScopeData, TypeData, FuncData)

import Data.Maybe (fromMaybe, isNothing)
import Data.Functor ((<&>))
import Control.Lens.Zoom (zoom)
import Text.PrettyPrint.HughesPJ (Doc, vcat)

ifExists
  :: (IC.ControlStatement r stmt bod, IC.ValueExpression r)
  => SValue r -> MS (r bod) -> MS (r bod) -> MS (r stmt)
ifExists :: forall (r :: * -> *) stmt bod.
(ControlStatement r stmt bod, ValueExpression r) =>
SValue r -> MS (r bod) -> MS (r bod) -> MS (r stmt)
ifExists SValue r
v MS (r bod)
ifBody = [(SValue r, MS (r bod))] -> MS (r bod) -> MS (r stmt)
forall (r :: * -> *) stmt bod.
ControlStatement r stmt bod =>
[(SValue r, MS (r bod))] -> MS (r bod) -> MS (r stmt)
IC.ifCond [(SValue r -> SValue r
forall (r :: * -> *). ValueExpression r => SValue r -> SValue r
IC.notNull SValue r
v, MS (r bod)
ifBody)]

decrement1
  :: (IC.AssignStatement r stmt, IC.Literal r)
  => SVariable r -> MS (r stmt)
decrement1 :: forall (r :: * -> *) stmt.
(AssignStatement r stmt, Literal r) =>
SVariable r -> MS (r stmt)
decrement1 SVariable r
v = SVariable r
v SVariable r -> SValue r -> MS (r stmt)
forall (r :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
&-= Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
1

increment
  :: (IC.AssignStatement r stmt, IC.NumericExpression r, IC.VariableValue r)
  => SVariable r -> SValue r -> MS (r stmt)
increment :: forall (r :: * -> *) stmt.
(AssignStatement r stmt, NumericExpression r, VariableValue r) =>
SVariable r -> SValue r -> MS (r stmt)
increment SVariable r
vr SValue r
vl = SVariable r
vr SVariable r -> SValue r -> MS (r stmt)
forall (r :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
&= SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
IC.valueOf SVariable r
vr SValue r -> SValue r -> SValue r
forall (r :: * -> *).
NumericExpression r =>
SValue r -> SValue r -> SValue r
#+ SValue r
vl

increment1
  :: (IC.AssignStatement r stmt, IC.Literal r)
  => SVariable r -> MS (r stmt)
increment1 :: forall (r :: * -> *) stmt.
(AssignStatement r stmt, Literal r) =>
SVariable r -> MS (r stmt)
increment1 SVariable r
vr = SVariable r
vr SVariable r -> SValue r -> MS (r stmt)
forall (r :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
&+= Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
1

strat
  :: (RC.BodyElim r bod, Monad r, RC.StatementElim r stmt)
  => MS (r stmt) -> MS (r bod) -> MS (r Doc)
strat :: forall (r :: * -> *) bod stmt.
(BodyElim r bod, Monad r, StatementElim r stmt) =>
MS (r stmt) -> MS (r bod) -> MS (r Doc)
strat = (r stmt -> r bod -> r Doc)
-> State MethodState (r stmt)
-> State MethodState (r bod)
-> State MethodState (r Doc)
forall a b c s.
(a -> b -> c) -> State s a -> State s b -> State s c
on2StateValues (\r stmt
result r bod
b -> Doc -> r Doc
forall (r :: * -> *) a. Monad r => a -> r a
toCode (Doc -> r Doc) -> Doc -> r Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vcat [r bod -> Doc
forall {k} (r :: k -> *) (bod :: k). BodyElim r bod => r bod -> Doc
RC.body r bod
b,
  r stmt -> Doc
forall {k} (r :: k -> *) (stmt :: k).
StatementElim r stmt =>
r stmt -> Doc
RC.statement r stmt
result])

runStrategy
  :: ( EmptyStatement r stmt
     , IC.AssignStatement r stmt
     , RC.BodyElim r bod
     , Monad r
     , S.RenderStatement r stmt
     , RC.StatementElim r stmt
     )
  => Label
  -> [(Label, MS (r bod))]
  -> Maybe (SValue r)
  -> Maybe (SVariable r)
  -> MS (r Doc)
runStrategy :: forall (r :: * -> *) stmt bod.
(EmptyStatement r stmt, AssignStatement r stmt, BodyElim r bod,
 Monad r, RenderStatement r stmt, StatementElim r stmt) =>
Label
-> [(Label, MS (r bod))]
-> Maybe (SValue r)
-> Maybe (SVariable r)
-> MS (r Doc)
runStrategy Label
l [(Label, MS (r bod))]
strats Maybe (SValue r)
rv Maybe (SVariable r)
av = MS (r Doc)
-> (MS (r bod) -> MS (r Doc)) -> Maybe (MS (r bod)) -> MS (r Doc)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
  (Label -> Label -> MS (r Doc)
forall {a}. Label -> Label -> a
strError Label
l Label
"RunStrategy called on non-existent strategy")
  (MS (r stmt) -> MS (r bod) -> MS (r Doc)
forall (r :: * -> *) bod stmt.
(BodyElim r bod, Monad r, StatementElim r stmt) =>
MS (r stmt) -> MS (r bod) -> MS (r Doc)
strat (MS (r stmt) -> MS (r stmt)
forall {k} (r :: k -> *) (stmt :: k).
RenderStatement r stmt =>
MS (r stmt) -> MS (r stmt)
S.stmt MS (r stmt)
resultState)) (Label -> [(Label, MS (r bod))] -> Maybe (MS (r bod))
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Label
l [(Label, MS (r bod))]
strats)
  where resultState :: MS (r stmt)
resultState = MS (r stmt)
-> (SVariable r -> MS (r stmt))
-> Maybe (SVariable r)
-> MS (r stmt)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe MS (r stmt)
forall {k} (r :: k -> *) (stmt :: k).
EmptyStatement r stmt =>
MS (r stmt)
emptyStmt SVariable r -> MS (r stmt)
asgState Maybe (SVariable r)
av
        asgState :: SVariable r -> MS (r stmt)
asgState SVariable r
v = MS (r stmt)
-> (SValue r -> MS (r stmt)) -> Maybe (SValue r) -> MS (r stmt)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Label -> Label -> MS (r stmt)
forall {a}. Label -> Label -> a
strError Label
l
          Label
"Attempt to assign null return to a Value") (SVariable r
v SVariable r -> SValue r -> MS (r stmt)
forall (r :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
&=) Maybe (SValue r)
rv
        strError :: Label -> Label -> a
strError Label
n Label
s = Label -> a
forall a. HasCallStack => Label -> a
error (Label -> a) -> Label -> a
forall a b. (a -> b) -> a -> b
$ Label
"Strategy '" Label -> Label -> Label
forall a. [a] -> [a] -> [a]
++ Label
n Label -> Label -> Label
forall a. [a] -> [a] -> [a]
++ Label
"': " Label -> Label -> Label
forall a. [a] -> [a] -> [a]
++ Label
s Label -> Label -> Label
forall a. [a] -> [a] -> [a]
++ Label
"."

listSlice
  ::
    ( BodySym r bod block
    , IC.BlockSym r block stmt
    , EmptyStatement r stmt
    , IC.DeclStatement r stmt bod
    , AssignStatement r stmt
    , IC.ControlStatement r stmt bod
    , IC.Literal r
    , BooleanExpression r
    , Comparison r
    , NumericExpression r
    , IC.ValueExpression r
    , IC.VariableValue r
    , IC.List r
    , IC.ListStatement r stmt
    , ValueElim r
    , VariableElim r
    )
  => Maybe (SValue r)
  -> Maybe (SValue r)
  -> Maybe (SValue r)
  -> SVariable r
  -> SValue r
  -> MS (r block)
listSlice :: forall (r :: * -> *) bod block stmt.
(BodySym r bod block, BlockSym r block stmt, EmptyStatement r stmt,
 DeclStatement r stmt bod, AssignStatement r stmt,
 ControlStatement r stmt bod, Literal r, BooleanExpression r,
 Comparison r, NumericExpression r, ValueExpression r,
 VariableValue r, List r, ListStatement r stmt, ValueElim r,
 VariableElim r) =>
Maybe (SValue r)
-> Maybe (SValue r)
-> Maybe (SValue r)
-> SVariable r
-> SValue r
-> MS (r block)
listSlice Maybe (SValue r)
beg Maybe (SValue r)
end Maybe (SValue r)
step SVariable r
vnew SValue r
vold = do

  l_temp <- [Label] -> Label -> MS Label
genVarName [] Label
"temp"
  l_i <- genLoopIndex
  vn <- zoom lensMStoVS vnew
  scpData <- getVarScope $ variableName vn
  let scp = ScopeData -> r ScopeData
forall (r :: * -> *). ScopeSym r => ScopeData -> r ScopeData
convScope ScopeData
scpData
      var_temp = Label -> VS (r TypeData) -> SVariable r
forall (r :: * -> *).
VariableSym r =>
Label -> VS (r TypeData) -> SVariable r
IC.var Label
l_temp ((r Variable -> r TypeData) -> SVariable r -> VS (r TypeData)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue r Variable -> r TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType SVariable r
vnew)
      v_temp = SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
IC.valueOf SVariable r
var_temp
      var_i = Label -> VS (r TypeData) -> SVariable r
forall (r :: * -> *).
VariableSym r =>
Label -> VS (r TypeData) -> SVariable r
IC.var Label
l_i VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
IC.int
      v_i = SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
IC.valueOf SVariable r
var_i

  let step' = SValue r -> Maybe (SValue r) -> SValue r
forall a. a -> Maybe a -> a
fromMaybe (Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
1) Maybe (SValue r)
step
  stepV <- zoom lensMStoVS step'
  let mbStepV = r Value -> Maybe Integer
forall (r :: * -> *). ValueElim r => r Value -> Maybe Integer
valueInt r Value
stepV

  -- Generate fresh variable names if required
  begName <- genVarNameIf (isNothing beg && isNothing mbStepV) "begIdx"
  endName <- genVarNameIf (isNothing end && isNothing mbStepV) "endIdx"

  let (setBeg, begVal) = makeSetterVal begName step' mbStepV beg (IC.litInt 0)    (IC.listSize vold #- IC.litInt 1) scp
      (setEnd, endVal) = makeSetterVal endName step' mbStepV end (IC.listSize vold) (IC.litInt (-1)) scp

  mbBegV <- case beg of
        Maybe (SValue r)
Nothing -> Maybe Integer -> StateT MethodState Identity (Maybe Integer)
forall a. a -> StateT MethodState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Integer
forall a. Maybe a
Nothing
        (Just SValue r
b) -> 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
b StateT MethodState Identity (r Value)
-> (r Value -> Maybe Integer)
-> StateT MethodState Identity (Maybe Integer)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> r Value -> Maybe Integer
forall (r :: * -> *). ValueElim r => r Value -> Maybe Integer
valueInt
  mbEndV <- case end of
        Maybe (SValue r)
Nothing -> Maybe Integer -> StateT MethodState Identity (Maybe Integer)
forall a. a -> StateT MethodState Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Integer
forall a. Maybe a
Nothing
        (Just SValue r
e) -> 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
e StateT MethodState Identity (r Value)
-> (r Value -> Maybe Integer)
-> StateT MethodState Identity (Maybe Integer)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> r Value -> Maybe Integer
forall (r :: * -> *). ValueElim r => r Value -> Maybe Integer
valueInt
  -- Get the condition for the for-loop
  let cond = case Maybe Integer
mbStepV of
              -- If step is a litInt, do a one-sided check
              (Just Integer
s) -> if Integer
s Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
>= Integer
0 then SValue r
v_i SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?< SValue r
endVal else SValue r
v_i SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?> SValue r
endVal
              Maybe Integer
Nothing -> case (Maybe Integer
mbBegV, Maybe Integer
mbEndV) of
                -- If both bounds are litInt's, do a two-sided check.
                -- Also, make sure step is in same direction as check.
                (Just Integer
b, Just Integer
e) -> if Integer
e Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
>= Integer
b
                    then SValue r
begVal SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?<= SValue r
v_i SValue r -> SValue r -> SValue r
forall (r :: * -> *).
BooleanExpression r =>
SValue r -> SValue r -> SValue r
?&& SValue r
v_i SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?< SValue r
endVal SValue r -> SValue r -> SValue r
forall (r :: * -> *).
BooleanExpression r =>
SValue r -> SValue r -> SValue r
?&& SValue r
step' SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?> Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
0
                    else SValue r
endVal SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?< SValue r
v_i SValue r -> SValue r -> SValue r
forall (r :: * -> *).
BooleanExpression r =>
SValue r -> SValue r -> SValue r
?&& SValue r
v_i SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?<= SValue r
begVal SValue r -> SValue r -> SValue r
forall (r :: * -> *).
BooleanExpression r =>
SValue r -> SValue r -> SValue r
?&& SValue r
step' SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?< Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
0
                -- If bounds are not litInt's, do both two-sided checks
                (Maybe Integer, Maybe Integer)
_ ->  SValue r
begVal SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?<= SValue r
v_i SValue r -> SValue r -> SValue r
forall (r :: * -> *).
BooleanExpression r =>
SValue r -> SValue r -> SValue r
?&& SValue r
v_i SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?< SValue r
endVal SValue r -> SValue r -> SValue r
forall (r :: * -> *).
BooleanExpression r =>
SValue r -> SValue r -> SValue r
?&& SValue r
step' SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?> Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
0 SValue r -> SValue r -> SValue r
forall (r :: * -> *).
BooleanExpression r =>
SValue r -> SValue r -> SValue r
?||
                      SValue r
endVal SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?< SValue r
v_i SValue r -> SValue r -> SValue r
forall (r :: * -> *).
BooleanExpression r =>
SValue r -> SValue r -> SValue r
?&& SValue r
v_i SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?<= SValue r
begVal SValue r -> SValue r -> SValue r
forall (r :: * -> *).
BooleanExpression r =>
SValue r -> SValue r -> SValue r
?&& SValue r
step' SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?< Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
0

  IC.block [
    IC.listDec 0 var_temp scp,
    setBeg, setEnd,
    IC.for (IC.varDecDef var_i IC.local begVal) cond
      (maybe (var_i &++) (var_i &+=) step)
      (oneLiner $ IC.listAppend v_temp (IC.listAccess vold v_i)),
    vnew &= v_temp]

-- Java, C#, C++, and Swift --
-- | Gets the expression and code for setting bounds in a list slice
--   Input:
--   - String: Variable name for bound (to be created if necessary),
--   - SValue: step value
--   - Maybe Integer: literal value of step, if exists
--   - Maybe SValue: given value of bound
--   - SValue: value of bound if bound not given and step is positive
--   - SValue: value of bound if bound not given and step is negative
--   Output: (SValue): (setter, value) of bound
makeSetterVal
  ::
    ( EmptyStatement r stmt
    , IC.DeclStatement r stmt bod
    , Comparison r
    , IC.IndexTranslator r
    , IC.Literal r
    , IC.ValueExpression r
    , IC.VariableValue r
    )
  => Label
  -> SValue r
  -> Maybe Integer
  -> Maybe (SValue r)
  -> SValue r
  -> SValue r
  -> r ScopeData
  -> (MS (r stmt), SValue r)
makeSetterVal :: forall (r :: * -> *) stmt bod.
(EmptyStatement r stmt, DeclStatement r stmt bod, Comparison r,
 IndexTranslator r, Literal r, ValueExpression r,
 VariableValue r) =>
Label
-> SValue r
-> Maybe Integer
-> Maybe (SValue r)
-> SValue r
-> SValue r
-> r ScopeData
-> (MS (r stmt), SValue r)
makeSetterVal Label
_     SValue r
_    Maybe Integer
_      (Just SValue r
v) SValue r
_  SValue r
_  r ScopeData
_   = (MS (r stmt)
forall {k} (r :: k -> *) (stmt :: k).
EmptyStatement r stmt =>
MS (r stmt)
emptyStmt, SValue r
v)
makeSetterVal Label
_     SValue r
_   (Just Integer
s) Maybe (SValue r)
_       SValue r
lb SValue r
rb r ScopeData
_   = (MS (r stmt)
forall {k} (r :: k -> *) (stmt :: k).
EmptyStatement r stmt =>
MS (r stmt)
emptyStmt, if Integer
s Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> Integer
0 then SValue r
lb else SValue r
rb)
makeSetterVal Label
vName SValue r
step Maybe Integer
_       Maybe (SValue r)
_       SValue r
lb SValue r
rb  r ScopeData
scp =
  let theVar :: SVariable r
theVar = Label -> VS (r TypeData) -> SVariable r
forall (r :: * -> *).
VariableSym r =>
Label -> VS (r TypeData) -> SVariable r
IC.var Label
vName VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
IC.int
      theSetter :: MS (r stmt)
theSetter = SVariable r -> r ScopeData -> SValue r -> MS (r stmt)
forall (r :: * -> *) stmt bod.
DeclStatement r stmt bod =>
SVariable r -> r ScopeData -> SValue r -> MS (r stmt)
IC.varDecDef SVariable r
theVar r ScopeData
scp (SValue r -> MS (r stmt)) -> SValue r -> MS (r stmt)
forall a b. (a -> b) -> a -> b
$ SValue r -> SValue r -> SValue r -> SValue r
forall (r :: * -> *).
ValueExpression r =>
SValue r -> SValue r -> SValue r -> SValue r
IC.inlineIf (SValue r
step SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?> Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
0) SValue r
lb SValue r
rb
  in (MS (r stmt)
theSetter, SValue r -> SValue r
forall (r :: * -> *). IndexTranslator r => SValue r -> SValue r
IC.intToIndex (SValue r -> SValue r) -> SValue r -> SValue r
forall a b. (a -> b) -> a -> b
$ SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
IC.valueOf SVariable r
theVar)

stringListVals
  :: ( MultiStatement r stmt
     , IC.AssignStatement r stmt
     , IC.List r
     , IC.Literal r
     , RenderValue r
     , IC.TypeElim r
     , VariableElim r
     )
  => [SVariable r] -> SValue r -> MS (r stmt)
stringListVals :: 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)
stringListVals [SVariable r]
vars SValue r
sl = 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
sl 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
>>= (\r Value
slst -> [StateT MethodState Identity (r stmt)]
-> StateT MethodState Identity (r stmt)
forall {k} (r :: k -> *) (stmt :: k).
MultiStatement r stmt =>
[MS (r stmt)] -> MS (r stmt)
multi ([StateT MethodState Identity (r stmt)]
 -> StateT MethodState Identity (r stmt))
-> [StateT MethodState Identity (r stmt)]
-> StateT MethodState Identity (r stmt)
forall a b. (a -> b) -> a -> b
$ CodeType -> [StateT MethodState Identity (r stmt)]
checkList
  (r TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (r TypeData -> CodeType) -> r TypeData -> CodeType
forall a b. (a -> b) -> a -> b
$ r Value -> r TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType r Value
slst))
  where checkList :: CodeType -> [StateT MethodState Identity (r stmt)]
checkList (List CodeType
String) = [SVariable r] -> Integer -> [StateT MethodState Identity (r stmt)]
assignVals [SVariable r]
vars Integer
0
        checkList CodeType
_ = Label -> [StateT MethodState Identity (r stmt)]
forall a. HasCallStack => Label -> a
error
          Label
"Value passed to stringListVals must be a list of strings"
        assignVals :: [SVariable r] -> Integer -> [StateT MethodState Identity (r stmt)]
assignVals [] Integer
_ = []
        assignVals (SVariable r
v:[SVariable r]
vs) Integer
n = SVariable r -> SValue r -> StateT MethodState Identity (r stmt)
forall (r :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
IC.assign SVariable r
v (VS (r TypeData) -> SValue r -> SValue r
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> SValue r -> SValue r
cast ((r Variable -> r TypeData) -> SVariable r -> VS (r TypeData)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue r Variable -> r TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType SVariable r
v)
          (SValue r -> SValue r -> SValue r
forall (r :: * -> *). List r => SValue r -> SValue r -> SValue r
IC.listAccess SValue r
sl (Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
n))) StateT MethodState Identity (r stmt)
-> [StateT MethodState Identity (r stmt)]
-> [StateT MethodState Identity (r stmt)]
forall a. a -> [a] -> [a]
: [SVariable r] -> Integer -> [StateT MethodState Identity (r stmt)]
assignVals [SVariable r]
vs (Integer
nInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
+Integer
1)

stringListLists
  ::
    ( BodySym r bod block
    , IC.BlockSym r block stmt
    , IC.ControlStatement r stmt bod
    , IC.Literal r
    , NumericExpression r
    , IC.VariableValue r
    , IC.List r
    , IC.ListStatement r stmt
    , IC.TypeElim r
    , VariableElim r
    , S.RenderValue r
    )
  => [SVariable r] -> SValue r -> MS (r stmt)
stringListLists :: 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)
stringListLists [SVariable r]
lsts SValue r
sl = do
  slst <- 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
sl
  l_i <- genLoopIndex
  let
    checkList (List CodeType
String) = (SVariable r -> StateT MethodState Identity (r Variable))
-> [SVariable r] -> StateT MethodState Identity [r Variable]
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 ValueState Identity) (r Variable))
  MethodState
  ValueState
-> SVariable r -> StateT MethodState Identity (r 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) (r Variable))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r Variable) ValueState)
-> MethodState -> Focusing Identity (r Variable) MethodState
Lens' MethodState ValueState
lensMStoVS) [SVariable r]
lsts StateT MethodState Identity [r Variable]
-> ([r Variable] -> 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)
listVals ([CodeType] -> StateT MethodState Identity (r stmt))
-> ([r Variable] -> [CodeType])
-> [r Variable]
-> StateT MethodState Identity (r stmt)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      (r Variable -> CodeType) -> [r Variable] -> [CodeType]
forall a b. (a -> b) -> [a] -> [b]
map (r TypeData -> CodeType
forall (r :: * -> *). TypeElim r => r TypeData -> CodeType
getCodeType (r TypeData -> CodeType)
-> (r Variable -> r TypeData) -> r Variable -> CodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. r Variable -> r TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType)
    checkList CodeType
_ = Label -> StateT MethodState Identity (r stmt)
forall a. HasCallStack => Label -> a
error
      Label
"Value passed to stringListLists must be a list of strings"
    listVals [] = StateT MethodState Identity (r stmt)
loop
    listVals (List CodeType
_:[CodeType]
vs) = [CodeType] -> StateT MethodState Identity (r stmt)
listVals [CodeType]
vs
    listVals [CodeType]
_ = Label -> StateT MethodState Identity (r stmt)
forall a. HasCallStack => Label -> a
error
      Label
"All values passed to stringListLists must have list types"
    loop = SVariable r
-> SValue r
-> SValue r
-> SValue r
-> MS (r bod)
-> StateT MethodState Identity (r stmt)
forall (r :: * -> *) stmt bod.
ControlStatement r stmt bod =>
SVariable r
-> SValue r -> SValue r -> SValue r -> MS (r bod) -> MS (r stmt)
IC.forRange SVariable r
var_i (Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
0) (SValue r -> SValue r
forall (r :: * -> *). List r => SValue r -> SValue r
IC.listSize SValue r
sl SValue r -> SValue r -> SValue r
forall (r :: * -> *).
NumericExpression r =>
SValue r -> SValue r -> SValue r
#/ SValue r
numLists)
      (Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
1) ([StateT MethodState Identity (r stmt)] -> MS (r bod)
forall {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k).
(BlockSym r block stmt, BodySym r bod block) =>
[MS (r stmt)] -> MS (r bod)
bodyStatements ([StateT MethodState Identity (r stmt)] -> MS (r bod))
-> [StateT MethodState Identity (r stmt)] -> MS (r bod)
forall a b. (a -> b) -> a -> b
$ [SValue r] -> Integer -> [StateT MethodState Identity (r stmt)]
appendLists ((SVariable r -> SValue r) -> [SVariable r] -> [SValue r]
forall a b. (a -> b) -> [a] -> [b]
map SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
IC.valueOf [SVariable r]
lsts) Integer
0)
    appendLists [] Integer
_ = []
    appendLists (SValue r
v:[SValue r]
vs) Integer
n = SValue r -> SValue r -> StateT MethodState Identity (r stmt)
forall (r :: * -> *) stmt.
ListStatement r stmt =>
SValue r -> SValue r -> MS (r stmt)
IC.listAppend SValue r
v (VS (r TypeData) -> SValue r -> SValue r
forall (r :: * -> *).
RenderValue r =>
VS (r TypeData) -> SValue r -> SValue r
cast
      (VS (r TypeData) -> VS (r TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
IC.innerType (VS (r TypeData) -> VS (r TypeData))
-> VS (r TypeData) -> VS (r TypeData)
forall a b. (a -> b) -> a -> b
$ (r Value -> r TypeData) -> SValue r -> VS (r TypeData)
forall a b s. (a -> b) -> State s a -> State s b
onStateValue r Value -> r TypeData
forall (r :: * -> *). ValueSym r => r Value -> r TypeData
valueType SValue r
v)
      (SValue r -> SValue r -> SValue r
forall (r :: * -> *). List r => SValue r -> SValue r -> SValue r
IC.listAccess SValue r
sl ((SValue r
v_i SValue r -> SValue r -> SValue r
forall (r :: * -> *).
NumericExpression r =>
SValue r -> SValue r -> SValue r
#* SValue r
numLists) SValue r -> SValue r -> SValue r
forall (r :: * -> *).
NumericExpression r =>
SValue r -> SValue r -> SValue r
#+ Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
n)))
      StateT MethodState Identity (r stmt)
-> [StateT MethodState Identity (r stmt)]
-> [StateT MethodState Identity (r stmt)]
forall a. a -> [a] -> [a]
: [SValue r] -> Integer -> [StateT MethodState Identity (r stmt)]
appendLists [SValue r]
vs (Integer
nInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
+Integer
1)
    numLists = Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt (Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ [SVariable r] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [SVariable r]
lsts)
    var_i = Label -> VS (r TypeData) -> SVariable r
forall (r :: * -> *).
VariableSym r =>
Label -> VS (r TypeData) -> SVariable r
IC.var Label
l_i VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
IC.int
    v_i = SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
IC.valueOf SVariable r
var_i
  checkList (getCodeType $ valueType slst)

forRange
  ::
    ( IC.DeclStatement r stmt bod
    , AssignStatement r stmt
    , IC.ControlStatement r stmt bod
    , Comparison r
    , IC.VariableValue r
    )
  => SVariable r
  -> SValue r
  -> SValue r
  -> SValue r
  -> MS (r bod)
  -> MS (r stmt)
forRange :: forall (r :: * -> *) stmt bod.
(DeclStatement r stmt bod, AssignStatement r stmt,
 ControlStatement r stmt bod, Comparison r, VariableValue r) =>
SVariable r
-> SValue r -> SValue r -> SValue r -> MS (r bod) -> MS (r stmt)
forRange SVariable r
i SValue r
initv SValue r
finalv SValue r
stepv = MS (r stmt) -> SValue r -> MS (r stmt) -> MS (r bod) -> MS (r stmt)
forall (r :: * -> *) stmt bod.
ControlStatement r stmt bod =>
MS (r stmt) -> SValue r -> MS (r stmt) -> MS (r bod) -> MS (r stmt)
IC.for (SVariable r -> r ScopeData -> SValue r -> MS (r stmt)
forall (r :: * -> *) stmt bod.
DeclStatement r stmt bod =>
SVariable r -> r ScopeData -> SValue r -> MS (r stmt)
IC.varDecDef SVariable r
i r ScopeData
forall (r :: * -> *). ScopeSym r => r ScopeData
IC.local SValue r
initv)
  (SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
IC.valueOf SVariable r
i SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?< SValue r
finalv) (SVariable r
i SVariable r -> SValue r -> MS (r stmt)
forall (r :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> SValue r -> MS (r stmt)
&+= SValue r
stepv)

observerIndex :: (IC.VariableSym r) => SVariable r
observerIndex :: forall (r :: * -> *). VariableSym r => SVariable r
observerIndex = Label -> VS (r TypeData) -> SVariable r
forall (r :: * -> *).
VariableSym r =>
Label -> VS (r TypeData) -> SVariable r
IC.var Label
"observerIndex" VS (r TypeData)
forall (r :: * -> *). TypeSym r => VS (r TypeData)
IC.int

observerIdxVal :: (IC.VariableValue r) => SValue r
observerIdxVal :: forall (r :: * -> *). VariableValue r => SValue r
observerIdxVal = SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
IC.valueOf SVariable r
forall (r :: * -> *). VariableSym r => SVariable r
observerIndex

obsList :: (IC.VariableValue r) => VS (r TypeData) -> SValue r
obsList :: forall (r :: * -> *).
VariableValue r =>
VS (r TypeData) -> SValue r
obsList VS (r TypeData)
t = SVariable r -> SValue r
forall (r :: * -> *). VariableValue r => SVariable r -> SValue r
IC.valueOf (SVariable r -> SValue r) -> SVariable r -> SValue r
forall a b. (a -> b) -> a -> b
$ Label -> VS (r TypeData) -> SVariable r
forall (r :: * -> *).
VariableSym r =>
Label -> VS (r TypeData) -> SVariable r
listOf Label
observerListName VS (r TypeData)
t

notify
  ::
    ( ValueStatement r stmt
    , VariableValue r
    , List r
    , OOFunctionSym r
    , BodySym r bod block
    , IC.BlockSym r block stmt
    )
  => VS (r TypeData) -> VS (r FuncData) -> MS (r bod)
notify :: forall (r :: * -> *) stmt bod block.
(ValueStatement r stmt, VariableValue r, List r, OOFunctionSym r,
 BodySym r bod block, BlockSym r block stmt) =>
VS (r TypeData) -> VS (r FuncData) -> MS (r bod)
notify VS (r TypeData)
t VS (r FuncData)
f = MS (r stmt) -> MS (r bod)
forall {k} (r :: k -> *) (block :: k) (stmt :: k) (bod :: k).
(BlockSym r block stmt, BodySym r bod block) =>
MS (r stmt) -> MS (r bod)
oneLiner (MS (r stmt) -> MS (r bod)) -> MS (r stmt) -> MS (r bod)
forall a b. (a -> b) -> a -> b
$ SValue r -> MS (r stmt)
forall (r :: * -> *) stmt.
ValueStatement r stmt =>
SValue r -> MS (r stmt)
valStmt (SValue r -> MS (r stmt)) -> SValue r -> MS (r stmt)
forall a b. (a -> b) -> a -> b
$ SValue r -> SValue r -> SValue r
forall (r :: * -> *). List r => SValue r -> SValue r -> SValue r
at (VS (r TypeData) -> SValue r
forall (r :: * -> *).
VariableValue r =>
VS (r TypeData) -> SValue r
obsList VS (r TypeData)
t) SValue r
forall (r :: * -> *). VariableValue r => SValue r
observerIdxVal SValue r -> VS (r FuncData) -> SValue r
forall (r :: * -> *).
OOFunctionSym r =>
SValue r -> VS (r FuncData) -> SValue r
$. VS (r FuncData)
f

notifyObservers
  ::
    ( BodySym r bod block
    , IC.BlockSym r block stmt
    , Literal r
    , VariableValue r
    , Comparison r
    , List r
    , ValueStatement r stmt
    , DeclStatement r stmt bod
    , AssignStatement r stmt
    , ControlStatement r stmt bod
    , OOFunctionSym r
    )
  => VS (r FuncData) -> VS (r TypeData) -> MS (r stmt)
notifyObservers :: forall (r :: * -> *) bod block stmt.
(BodySym r bod block, BlockSym r block stmt, Literal r,
 VariableValue r, Comparison r, List r, ValueStatement r stmt,
 DeclStatement r stmt bod, AssignStatement r stmt,
 ControlStatement r stmt bod, OOFunctionSym r) =>
VS (r FuncData) -> VS (r TypeData) -> MS (r stmt)
notifyObservers VS (r FuncData)
f VS (r TypeData)
t = MS (r stmt) -> SValue r -> MS (r stmt) -> MS (r bod) -> MS (r stmt)
forall (r :: * -> *) stmt bod.
ControlStatement r stmt bod =>
MS (r stmt) -> SValue r -> MS (r stmt) -> MS (r bod) -> MS (r stmt)
IC.for MS (r stmt)
initv (SValue r
forall (r :: * -> *). VariableValue r => SValue r
observerIdxVal SValue r -> SValue r -> SValue r
forall (r :: * -> *).
Comparison r =>
SValue r -> SValue r -> SValue r
?< SValue r -> SValue r
forall (r :: * -> *). List r => SValue r -> SValue r
IC.listSize (VS (r TypeData) -> SValue r
forall (r :: * -> *).
VariableValue r =>
VS (r TypeData) -> SValue r
obsList VS (r TypeData)
t))
  (SVariable r
forall (r :: * -> *). VariableSym r => SVariable r
observerIndex SVariable r -> MS (r stmt)
forall (r :: * -> *) stmt.
AssignStatement r stmt =>
SVariable r -> MS (r stmt)
&++) (VS (r TypeData) -> VS (r FuncData) -> MS (r bod)
forall (r :: * -> *) stmt bod block.
(ValueStatement r stmt, VariableValue r, List r, OOFunctionSym r,
 BodySym r bod block, BlockSym r block stmt) =>
VS (r TypeData) -> VS (r FuncData) -> MS (r bod)
notify VS (r TypeData)
t VS (r FuncData)
f)
  where initv :: MS (r stmt)
initv = SVariable r -> r ScopeData -> SValue r -> MS (r stmt)
forall (r :: * -> *) stmt bod.
DeclStatement r stmt bod =>
SVariable r -> r ScopeData -> SValue r -> MS (r stmt)
IC.varDecDef SVariable r
forall (r :: * -> *). VariableSym r => SVariable r
observerIndex r ScopeData
forall (r :: * -> *). ScopeSym r => r ScopeData
IC.local (SValue r -> MS (r stmt)) -> SValue r -> MS (r stmt)
forall a b. (a -> b) -> a -> b
$ Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
0

notifyObservers'
  ::
    ( BodySym r bod block
    , IC.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)
notifyObservers' :: 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)
notifyObservers' VS (r FuncData)
f VS (r TypeData)
t = SVariable r
-> SValue r -> SValue r -> SValue r -> MS (r bod) -> MS (r stmt)
forall (r :: * -> *) stmt bod.
ControlStatement r stmt bod =>
SVariable r
-> SValue r -> SValue r -> SValue r -> MS (r bod) -> MS (r stmt)
IC.forRange SVariable r
forall (r :: * -> *). VariableSym r => SVariable r
observerIndex SValue r
initv (SValue r -> SValue r
forall (r :: * -> *). List r => SValue r -> SValue r
IC.listSize (SValue r -> SValue r) -> SValue r -> SValue r
forall a b. (a -> b) -> a -> b
$ VS (r TypeData) -> SValue r
forall (r :: * -> *).
VariableValue r =>
VS (r TypeData) -> SValue r
obsList VS (r TypeData)
t )
    (Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
1) (VS (r TypeData) -> VS (r FuncData) -> MS (r bod)
forall (r :: * -> *) stmt bod block.
(ValueStatement r stmt, VariableValue r, List r, OOFunctionSym r,
 BodySym r bod block, BlockSym r block stmt) =>
VS (r TypeData) -> VS (r FuncData) -> MS (r bod)
notify VS (r TypeData)
t VS (r FuncData)
f)
    where initv :: SValue r
initv = Integer -> SValue r
forall (r :: * -> *). Literal r => Integer -> SValue r
IC.litInt Integer
0

arrayDecAsList
  ::
    ( BodySym r bod block
    , IC.BlockSym r block stmt
    , MultiStatement r stmt
    , IC.DeclStatement r stmt bod
    , IC.ControlStatement r stmt bod
    , IC.Literal r
    , IC.VariableValue r
    , IC.ListStatement r stmt
    , VariableElim r
    )
  => Integer -> SValue r -> SVariable r -> r ScopeData -> MS (r stmt)
arrayDecAsList :: 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)
arrayDecAsList Integer
len SValue r
dflt SVariable r
vr r ScopeData
scp = do
  vr' <- LensLike'
  (Zoomed (StateT ValueState Identity) (r Variable))
  MethodState
  ValueState
-> SVariable r -> StateT MethodState Identity (r 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) (r Variable))
  MethodState
  ValueState
(ValueState -> Focusing Identity (r Variable) ValueState)
-> MethodState -> Focusing Identity (r Variable) MethodState
Lens' MethodState ValueState
lensMStoVS SVariable r
vr
  let innerTp = VS (r TypeData) -> VS (r TypeData)
forall (r :: * -> *).
TypeSym r =>
VS (r TypeData) -> VS (r TypeData)
IC.innerType (VS (r TypeData) -> VS (r TypeData))
-> VS (r TypeData) -> VS (r TypeData)
forall a b. (a -> b) -> a -> b
$ r TypeData -> VS (r TypeData)
forall a. a -> StateT ValueState Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return (r TypeData -> VS (r TypeData)) -> r TypeData -> VS (r TypeData)
forall a b. (a -> b) -> a -> b
$ r Variable -> r TypeData
forall (r :: * -> *). VariableElim r => r Variable -> r TypeData
variableType r Variable
vr'
  i <- genVarName [] "i"
  multi [
    IC.varDecDef vr scp (IC.litList innerTp []),
    IC.forRange (IC.var i IC.int) (IC.litInt 0) (IC.litInt len) (IC.litInt 1)
      (oneLiner $ IC.listAppend (IC.valueOf vr) dflt)]