{-# LANGUAGE TemplateHaskell #-}
-- | Defines chunk types for use in code generation.
module Language.Drasil.Chunk.CodeBase where

import Control.Lens ((^.), view, makeLenses, Lens')

import Language.Drasil
import Database.Drasil (ChunkDB, symbResolve)

import Language.Drasil.Code.Expr (CodeExpr)
import Language.Drasil.Code.Expr.Extract (eDep, eDep')

import Utils.Drasil (toPlainName)

import Data.List (nub)

-- not using lenses for now
-- | A 'CodeIdea' must include some code and its name. 
class CodeIdea c where
  -- | Name of the idea.
  codeName  :: c -> String
  -- | Code chunk associated with the idea.
  codeChunk :: c -> CodeChunk

-- | A 'DefiningCodeExpr' must have it's underlying chunk 
--   defined in the CodeExpr language.
class CodeIdea c => DefiningCodeExpr c where
  codeExpr  :: Lens' c CodeExpr

-- | Convert the program name to an abbreviated 'String' without any special characters.
programName :: CommonIdea c => c -> String
programName :: c -> String
programName = String -> String
toPlainName (String -> String) -> (c -> String) -> c -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> String
forall c. CommonIdea c => c -> String
abrv

-- | Used when a function name needs to be distinguishable from a variable name.
funcPrefix :: String
funcPrefix :: String
funcPrefix = "func_"
 
-- | Details if a piece of code is meant to be a variable or a function.
data VarOrFunc = Var | Func

-- | Basic chunk representation in the code generation context.
-- Contains a QuantityDict and the kind of code (variable or function).
data CodeChunk = CodeC { CodeChunk -> QuantityDict
_qc  :: QuantityDict
                       , CodeChunk -> VarOrFunc
kind :: VarOrFunc  -- TODO: Jason: Once we have function spaces, I believe we won't need to store this
                       }
makeLenses ''CodeChunk

-- | Finds the 'UID' of the 'QuantityDict' used to make the 'CodeChunk'.
instance HasUID      CodeChunk where uid :: (UID -> f UID) -> CodeChunk -> f CodeChunk
uid = (QuantityDict -> f QuantityDict) -> CodeChunk -> f CodeChunk
Lens' CodeChunk QuantityDict
qc ((QuantityDict -> f QuantityDict) -> CodeChunk -> f CodeChunk)
-> ((UID -> f UID) -> QuantityDict -> f QuantityDict)
-> (UID -> f UID)
-> CodeChunk
-> f CodeChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UID -> f UID) -> QuantityDict -> f QuantityDict
forall c. HasUID c => Lens' c UID
uid
-- | Finds the term ('NP') of the 'QuantityDict' used to make the 'CodeChunk'.
instance NamedIdea   CodeChunk where term :: (NP -> f NP) -> CodeChunk -> f CodeChunk
term = (QuantityDict -> f QuantityDict) -> CodeChunk -> f CodeChunk
Lens' CodeChunk QuantityDict
qc ((QuantityDict -> f QuantityDict) -> CodeChunk -> f CodeChunk)
-> ((NP -> f NP) -> QuantityDict -> f QuantityDict)
-> (NP -> f NP)
-> CodeChunk
-> f CodeChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NP -> f NP) -> QuantityDict -> f QuantityDict
forall c. NamedIdea c => Lens' c NP
term
-- | Finds the idea contained in the 'QuantityDict' used to make the 'CodeChunk'.
instance Idea        CodeChunk where getA :: CodeChunk -> Maybe String
getA = QuantityDict -> Maybe String
forall c. Idea c => c -> Maybe String
getA (QuantityDict -> Maybe String)
-> (CodeChunk -> QuantityDict) -> CodeChunk -> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting QuantityDict CodeChunk QuantityDict
-> CodeChunk -> QuantityDict
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting QuantityDict CodeChunk QuantityDict
Lens' CodeChunk QuantityDict
qc
-- | Finds the 'Space' of the 'QuantityDict' used to make the 'CodeChunk'.
instance HasSpace    CodeChunk where typ :: (Space -> f Space) -> CodeChunk -> f CodeChunk
typ = (QuantityDict -> f QuantityDict) -> CodeChunk -> f CodeChunk
Lens' CodeChunk QuantityDict
qc ((QuantityDict -> f QuantityDict) -> CodeChunk -> f CodeChunk)
-> ((Space -> f Space) -> QuantityDict -> f QuantityDict)
-> (Space -> f Space)
-> CodeChunk
-> f CodeChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Space -> f Space) -> QuantityDict -> f QuantityDict
forall c. HasSpace c => Lens' c Space
typ
-- | Finds the 'Stage' dependent 'Symbol' of the 'QuantityDict' used to make the 'CodeChunk'.
instance HasSymbol   CodeChunk where symbol :: CodeChunk -> Stage -> Symbol
symbol = QuantityDict -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol (QuantityDict -> Stage -> Symbol)
-> (CodeChunk -> QuantityDict) -> CodeChunk -> Stage -> Symbol
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting QuantityDict CodeChunk QuantityDict
-> CodeChunk -> QuantityDict
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting QuantityDict CodeChunk QuantityDict
Lens' CodeChunk QuantityDict
qc
-- | 'CodeChunk's have a 'Quantity'.
instance Quantity    CodeChunk
-- | Equal if 'UID's are equal.
instance Eq          CodeChunk where c1 :: CodeChunk
c1 == :: CodeChunk -> CodeChunk -> Bool
== c2 :: CodeChunk
c2 = (CodeChunk
c1 CodeChunk -> Getting UID CodeChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID CodeChunk UID
forall c. HasUID c => Lens' c UID
uid) UID -> UID -> Bool
forall a. Eq a => a -> a -> Bool
== (CodeChunk
c2 CodeChunk -> Getting UID CodeChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID CodeChunk UID
forall c. HasUID c => Lens' c UID
uid)
-- | Finds the units of the 'QuantityDict' used to make the 'CodeChunk'.
instance MayHaveUnit CodeChunk where getUnit :: CodeChunk -> Maybe UnitDefn
getUnit = QuantityDict -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit (QuantityDict -> Maybe UnitDefn)
-> (CodeChunk -> QuantityDict) -> CodeChunk -> Maybe UnitDefn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting QuantityDict CodeChunk QuantityDict
-> CodeChunk -> QuantityDict
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting QuantityDict CodeChunk QuantityDict
Lens' CodeChunk QuantityDict
qc

-- | Chunk representing a variable. The @obv@ field represents the object containing 
-- this variable, if it is an object field.
data CodeVarChunk = CodeVC {CodeVarChunk -> CodeChunk
_ccv :: CodeChunk,
                            CodeVarChunk -> Maybe CodeChunk
_obv :: Maybe CodeChunk}
makeLenses ''CodeVarChunk

-- | Finds the 'UID' of the 'CodeChunk' used to make the 'CodeVarChunk'.
instance HasUID      CodeVarChunk where uid :: (UID -> f UID) -> CodeVarChunk -> f CodeVarChunk
uid = (CodeChunk -> f CodeChunk) -> CodeVarChunk -> f CodeVarChunk
Lens' CodeVarChunk CodeChunk
ccv ((CodeChunk -> f CodeChunk) -> CodeVarChunk -> f CodeVarChunk)
-> ((UID -> f UID) -> CodeChunk -> f CodeChunk)
-> (UID -> f UID)
-> CodeVarChunk
-> f CodeVarChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UID -> f UID) -> CodeChunk -> f CodeChunk
forall c. HasUID c => Lens' c UID
uid
-- | Finds the term ('NP') of the 'CodeChunk' used to make the 'CodeVarChunk'.
instance NamedIdea   CodeVarChunk where term :: (NP -> f NP) -> CodeVarChunk -> f CodeVarChunk
term = (CodeChunk -> f CodeChunk) -> CodeVarChunk -> f CodeVarChunk
Lens' CodeVarChunk CodeChunk
ccv ((CodeChunk -> f CodeChunk) -> CodeVarChunk -> f CodeVarChunk)
-> ((NP -> f NP) -> CodeChunk -> f CodeChunk)
-> (NP -> f NP)
-> CodeVarChunk
-> f CodeVarChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NP -> f NP) -> CodeChunk -> f CodeChunk
forall c. NamedIdea c => Lens' c NP
term
-- | Finds the idea contained in the 'CodeChunk' used to make the 'CodeVarChunk'.
instance Idea        CodeVarChunk where getA :: CodeVarChunk -> Maybe String
getA = CodeChunk -> Maybe String
forall c. Idea c => c -> Maybe String
getA (CodeChunk -> Maybe String)
-> (CodeVarChunk -> CodeChunk) -> CodeVarChunk -> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting CodeChunk CodeVarChunk CodeChunk
-> CodeVarChunk -> CodeChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting CodeChunk CodeVarChunk CodeChunk
Lens' CodeVarChunk CodeChunk
ccv
-- | Finds the 'Space' of the 'CodeChunk' used to make the 'CodeVarChunk'.
instance HasSpace    CodeVarChunk where typ :: (Space -> f Space) -> CodeVarChunk -> f CodeVarChunk
typ = (CodeChunk -> f CodeChunk) -> CodeVarChunk -> f CodeVarChunk
Lens' CodeVarChunk CodeChunk
ccv ((CodeChunk -> f CodeChunk) -> CodeVarChunk -> f CodeVarChunk)
-> ((Space -> f Space) -> CodeChunk -> f CodeChunk)
-> (Space -> f Space)
-> CodeVarChunk
-> f CodeVarChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Space -> f Space) -> CodeChunk -> f CodeChunk
forall c. HasSpace c => Lens' c Space
typ
-- | Finds the 'Stage' dependent 'Symbol' of the 'CodeChunk' used to make the 'CodeVarChunk'.
instance HasSymbol   CodeVarChunk where symbol :: CodeVarChunk -> Stage -> Symbol
symbol = CodeChunk -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol (CodeChunk -> Stage -> Symbol)
-> (CodeVarChunk -> CodeChunk) -> CodeVarChunk -> Stage -> Symbol
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting CodeChunk CodeVarChunk CodeChunk
-> CodeVarChunk -> CodeChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting CodeChunk CodeVarChunk CodeChunk
Lens' CodeVarChunk CodeChunk
ccv
-- | 'CodeVarChunk's have a 'Quantity'.
instance Quantity    CodeVarChunk
-- | Equal if 'UID's are equal.
instance Eq          CodeVarChunk where c1 :: CodeVarChunk
c1 == :: CodeVarChunk -> CodeVarChunk -> Bool
== c2 :: CodeVarChunk
c2 = (CodeVarChunk
c1 CodeVarChunk -> Getting UID CodeVarChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID CodeVarChunk UID
forall c. HasUID c => Lens' c UID
uid) UID -> UID -> Bool
forall a. Eq a => a -> a -> Bool
== (CodeVarChunk
c2 CodeVarChunk -> Getting UID CodeVarChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID CodeVarChunk UID
forall c. HasUID c => Lens' c UID
uid)
-- | Finds the units of the 'CodeChunk' used to make the 'CodeVarChunk'.
instance MayHaveUnit CodeVarChunk where getUnit :: CodeVarChunk -> Maybe UnitDefn
getUnit = CodeChunk -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit (CodeChunk -> Maybe UnitDefn)
-> (CodeVarChunk -> CodeChunk) -> CodeVarChunk -> Maybe UnitDefn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting CodeChunk CodeVarChunk CodeChunk
-> CodeVarChunk -> CodeChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting CodeChunk CodeVarChunk CodeChunk
Lens' CodeVarChunk CodeChunk
ccv

-- | Chunk representing a function.
newtype CodeFuncChunk = CodeFC {CodeFuncChunk -> CodeChunk
_ccf :: CodeChunk}
makeLenses ''CodeFuncChunk

-- | Finds the 'UID' of the 'CodeChunk' used to make the 'CodeFuncChunk'.
instance HasUID      CodeFuncChunk where uid :: (UID -> f UID) -> CodeFuncChunk -> f CodeFuncChunk
uid = (CodeChunk -> f CodeChunk) -> CodeFuncChunk -> f CodeFuncChunk
Iso' CodeFuncChunk CodeChunk
ccf ((CodeChunk -> f CodeChunk) -> CodeFuncChunk -> f CodeFuncChunk)
-> ((UID -> f UID) -> CodeChunk -> f CodeChunk)
-> (UID -> f UID)
-> CodeFuncChunk
-> f CodeFuncChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UID -> f UID) -> CodeChunk -> f CodeChunk
forall c. HasUID c => Lens' c UID
uid
-- | Finds the term ('NP') of the 'CodeChunk' used to make the 'CodeFuncChunk'.
instance NamedIdea   CodeFuncChunk where term :: (NP -> f NP) -> CodeFuncChunk -> f CodeFuncChunk
term = (CodeChunk -> f CodeChunk) -> CodeFuncChunk -> f CodeFuncChunk
Iso' CodeFuncChunk CodeChunk
ccf ((CodeChunk -> f CodeChunk) -> CodeFuncChunk -> f CodeFuncChunk)
-> ((NP -> f NP) -> CodeChunk -> f CodeChunk)
-> (NP -> f NP)
-> CodeFuncChunk
-> f CodeFuncChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NP -> f NP) -> CodeChunk -> f CodeChunk
forall c. NamedIdea c => Lens' c NP
term
-- | Finds the idea contained in the 'CodeChunk' used to make the 'CodeFuncChunk'.
instance Idea        CodeFuncChunk where getA :: CodeFuncChunk -> Maybe String
getA = CodeChunk -> Maybe String
forall c. Idea c => c -> Maybe String
getA (CodeChunk -> Maybe String)
-> (CodeFuncChunk -> CodeChunk) -> CodeFuncChunk -> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting CodeChunk CodeFuncChunk CodeChunk
-> CodeFuncChunk -> CodeChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting CodeChunk CodeFuncChunk CodeChunk
Iso' CodeFuncChunk CodeChunk
ccf
-- | Finds the 'Space' of the 'CodeChunk' used to make the 'CodeFuncChunk'.
instance HasSpace    CodeFuncChunk where typ :: (Space -> f Space) -> CodeFuncChunk -> f CodeFuncChunk
typ = (CodeChunk -> f CodeChunk) -> CodeFuncChunk -> f CodeFuncChunk
Iso' CodeFuncChunk CodeChunk
ccf ((CodeChunk -> f CodeChunk) -> CodeFuncChunk -> f CodeFuncChunk)
-> ((Space -> f Space) -> CodeChunk -> f CodeChunk)
-> (Space -> f Space)
-> CodeFuncChunk
-> f CodeFuncChunk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Space -> f Space) -> CodeChunk -> f CodeChunk
forall c. HasSpace c => Lens' c Space
typ
-- | Finds the 'Stage' dependent 'Symbol' of the 'CodeChunk' used to make the 'CodeFuncChunk'.
instance HasSymbol   CodeFuncChunk where symbol :: CodeFuncChunk -> Stage -> Symbol
symbol = CodeChunk -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol (CodeChunk -> Stage -> Symbol)
-> (CodeFuncChunk -> CodeChunk) -> CodeFuncChunk -> Stage -> Symbol
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting CodeChunk CodeFuncChunk CodeChunk
-> CodeFuncChunk -> CodeChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting CodeChunk CodeFuncChunk CodeChunk
Iso' CodeFuncChunk CodeChunk
ccf
-- | 'CodeFuncChunk's have a 'Quantity'.
instance Quantity    CodeFuncChunk
-- | Functions are Callable.
instance Callable    CodeFuncChunk
-- | Equal if 'UID's are equal.
instance Eq          CodeFuncChunk where c1 :: CodeFuncChunk
c1 == :: CodeFuncChunk -> CodeFuncChunk -> Bool
== c2 :: CodeFuncChunk
c2 = (CodeFuncChunk
c1 CodeFuncChunk -> Getting UID CodeFuncChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID CodeFuncChunk UID
forall c. HasUID c => Lens' c UID
uid) UID -> UID -> Bool
forall a. Eq a => a -> a -> Bool
== (CodeFuncChunk
c2 CodeFuncChunk -> Getting UID CodeFuncChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID CodeFuncChunk UID
forall c. HasUID c => Lens' c UID
uid)
-- | Finds the units of the 'CodeChunk' used to make the 'CodeFuncChunk'.
instance MayHaveUnit CodeFuncChunk where getUnit :: CodeFuncChunk -> Maybe UnitDefn
getUnit = CodeChunk -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit (CodeChunk -> Maybe UnitDefn)
-> (CodeFuncChunk -> CodeChunk) -> CodeFuncChunk -> Maybe UnitDefn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting CodeChunk CodeFuncChunk CodeChunk
-> CodeFuncChunk -> CodeChunk
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting CodeChunk CodeFuncChunk CodeChunk
Iso' CodeFuncChunk CodeChunk
ccf

-- | Construct a 'CodeVarChunk' from a 'Quantity'.
quantvar :: (Quantity c, MayHaveUnit c) => c -> CodeVarChunk
quantvar :: c -> CodeVarChunk
quantvar c :: c
c = CodeChunk -> Maybe CodeChunk -> CodeVarChunk
CodeVC (QuantityDict -> VarOrFunc -> CodeChunk
CodeC (c -> QuantityDict
forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw c
c) VarOrFunc
Var) Maybe CodeChunk
forall a. Maybe a
Nothing

-- | Construct a 'CodeFuncChunk' from a 'Quantity'.
quantfunc :: (Quantity c, MayHaveUnit c) => c -> CodeFuncChunk
quantfunc :: c -> CodeFuncChunk
quantfunc c :: c
c = CodeChunk -> CodeFuncChunk
CodeFC (CodeChunk -> CodeFuncChunk) -> CodeChunk -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ QuantityDict -> VarOrFunc -> CodeChunk
CodeC (c -> QuantityDict
forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw c
c) VarOrFunc
Func

-- | Get a list of 'CodeChunk's from an equation.
codevars :: CodeExpr -> ChunkDB -> [CodeVarChunk]
codevars :: CodeExpr -> ChunkDB -> [CodeVarChunk]
codevars e :: CodeExpr
e m :: ChunkDB
m = (UID -> CodeVarChunk) -> [UID] -> [CodeVarChunk]
forall a b. (a -> b) -> [a] -> [b]
map (ChunkDB -> UID -> CodeVarChunk
varResolve ChunkDB
m) ([UID] -> [CodeVarChunk]) -> [UID] -> [CodeVarChunk]
forall a b. (a -> b) -> a -> b
$ CodeExpr -> [UID]
eDep CodeExpr
e

-- | Get a list of 'CodeChunk's from an equation (no functions).
codevars' :: CodeExpr -> ChunkDB -> [CodeVarChunk]
codevars' :: CodeExpr -> ChunkDB -> [CodeVarChunk]
codevars' e :: CodeExpr
e m :: ChunkDB
m = (UID -> CodeVarChunk) -> [UID] -> [CodeVarChunk]
forall a b. (a -> b) -> [a] -> [b]
map (ChunkDB -> UID -> CodeVarChunk
varResolve ChunkDB
m) ([UID] -> [CodeVarChunk]) -> [UID] -> [CodeVarChunk]
forall a b. (a -> b) -> a -> b
$ [UID] -> [UID]
forall a. Eq a => [a] -> [a]
nub ([UID] -> [UID]) -> [UID] -> [UID]
forall a b. (a -> b) -> a -> b
$ CodeExpr -> [UID]
eDep' CodeExpr
e

-- | Make a 'CodeVarChunk' from a 'UID' in the 'ChunkDB'.
varResolve :: ChunkDB -> UID -> CodeVarChunk
varResolve :: ChunkDB -> UID -> CodeVarChunk
varResolve  m :: ChunkDB
m x :: UID
x = QuantityDict -> CodeVarChunk
forall c. (Quantity c, MayHaveUnit c) => c -> CodeVarChunk
quantvar (QuantityDict -> CodeVarChunk) -> QuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ ChunkDB -> UID -> QuantityDict
symbResolve ChunkDB
m UID
x

-- | Make a 'CodeFuncChunk' from a 'UID' in the 'ChunkDB'.
funcResolve :: ChunkDB -> UID -> CodeFuncChunk
funcResolve :: ChunkDB -> UID -> CodeFuncChunk
funcResolve m :: ChunkDB
m x :: UID
x = QuantityDict -> CodeFuncChunk
forall c. (Quantity c, MayHaveUnit c) => c -> CodeFuncChunk
quantfunc (QuantityDict -> CodeFuncChunk) -> QuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ ChunkDB -> UID -> QuantityDict
symbResolve ChunkDB
m UID
x

-- FIXME: use show for the UID here? Perhaps need a different implVar function for UIDs
-- Changes a 'CodeVarChunk'\'s space from 'Vect' to 'Array'.
listToArray :: CodeVarChunk -> CodeVarChunk
listToArray :: CodeVarChunk -> CodeVarChunk
listToArray c :: CodeVarChunk
c = Space -> CodeVarChunk
newSpc (CodeVarChunk
c CodeVarChunk -> Getting Space CodeVarChunk Space -> Space
forall s a. s -> Getting a s a -> a
^. Getting Space CodeVarChunk Space
forall c. HasSpace c => Lens' c Space
typ) 
  where newSpc :: Space -> CodeVarChunk
newSpc (Vect t :: Space
t) = CodeChunk -> Maybe CodeChunk -> CodeVarChunk
CodeVC (QuantityDict -> VarOrFunc -> CodeChunk
CodeC (String
-> NP
-> Maybe String
-> Space
-> Symbol
-> Maybe UnitDefn
-> QuantityDict
implVar' (UID -> String
forall a. Show a => a -> String
show (UID -> String) -> UID -> String
forall a b. (a -> b) -> a -> b
$ CodeVarChunk
c CodeVarChunk -> String -> UID
forall a. HasUID a => a -> String -> UID
+++ "_array")
          (CodeVarChunk
c CodeVarChunk -> Getting NP CodeVarChunk NP -> NP
forall s a. s -> Getting a s a -> a
^. Getting NP CodeVarChunk NP
forall c. NamedIdea c => Lens' c NP
term) (CodeVarChunk -> Maybe String
forall c. Idea c => c -> Maybe String
getA CodeVarChunk
c) (Space -> Space
Array Space
t) (CodeVarChunk -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol CodeVarChunk
c Stage
Implementation) (CodeVarChunk -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit CodeVarChunk
c)) 
          VarOrFunc
Var) (CodeVarChunk
c CodeVarChunk
-> Getting (Maybe CodeChunk) CodeVarChunk (Maybe CodeChunk)
-> Maybe CodeChunk
forall s a. s -> Getting a s a -> a
^. Getting (Maybe CodeChunk) CodeVarChunk (Maybe CodeChunk)
Lens' CodeVarChunk (Maybe CodeChunk)
obv)
        newSpc _ = CodeVarChunk
c