Skip to content

Commit

Permalink
#2628 : Remove Deriv from CodeExpr
Browse files Browse the repository at this point in the history
  • Loading branch information
balacij committed Jul 7, 2021
1 parent 3e522b7 commit 83bb992
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 25 deletions.
4 changes: 0 additions & 4 deletions code/drasil-code-base/Language/Drasil/Code/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ data CodeExpr where
AssocA :: AssocArithOper -> [CodeExpr] -> CodeExpr
-- | Takes an associative boolean operator with a list of expressions.
AssocB :: AssocBoolOper -> [CodeExpr] -> CodeExpr
-- | Derivative syntax is:
-- Type ('Part'ial or 'Total') -> principal part of change -> with respect to
-- For example: Deriv Part y x1 would be (dy/dx1).
Deriv :: DerivType -> CodeExpr -> UID -> CodeExpr
-- | C stands for "Chunk", for referring to a chunk in an expression.
-- Implicitly assumes that the chunk has a symbol.
C :: UID -> CodeExpr
Expand Down
16 changes: 8 additions & 8 deletions code/drasil-code-base/Language/Drasil/Code/Expr/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import Language.Drasil.Code.Expr
expr :: L.Expr -> CodeExpr
expr (L.Dbl d) = Dbl d
expr (L.Int i) = Int i
expr (L.ExactDbl i) = ExactDbl i
expr (L.ExactDbl i) = ExactDbl i
expr (L.Str s) = Str s
expr (L.Perc n d) = Perc n d
expr (L.AssocA ao es) = AssocA (assocArithOp ao) $ map expr es
expr (L.AssocB bo es) = AssocB (assocBoolOp bo) $ map expr es
expr (L.Deriv dt e u) = Deriv dt (expr e) u
expr (L.C u) = C u
expr (L.FCall u es ns) = FCall u (map expr es) (map (second expr) ns)
expr (L.Case c es) = Case c $ map (bimap expr expr) es
Expand All @@ -36,6 +35,7 @@ expr (L.VVVBinaryOp bo l r) = VVVBinaryOp (vvvBinOp bo) (expr l) (expr r)
expr (L.VVNBinaryOp bo l r) = VVNBinaryOp (vvnBinOp bo) (expr l) (expr r)
expr (L.Operator aao dd e) = Operator (assocArithOp aao) (renderDomainDesc dd) (expr e)
expr (L.RealI u ri) = RealI u (realInterval ri)
expr L.Deriv {} = error "Expr's Deriv is not convertible to the language of CodeExpr"

-- | Convert 'RealInterval Expr Expr's into 'RealInterval CodeExpr CodeExpr's.
realInterval :: L.RealInterval L.Expr L.Expr -> L.RealInterval CodeExpr CodeExpr
Expand Down Expand Up @@ -93,19 +93,19 @@ assocBoolOp L.Or = Or
uFunc :: L.UFunc -> UFunc
uFunc L.Abs = Abs -- TODO: These L.'s should be exported through L.D.Development
uFunc L.Log = Log
uFunc L.Ln = Ln
uFunc L.Sin = Sin
uFunc L.Ln = Ln
uFunc L.Sin = Sin
uFunc L.Cos = Cos
uFunc L.Tan = Tan
uFunc L.Sec = Sec
uFunc L.Csc = Csc
uFunc L.Cot = Cot
uFunc L.Arcsin = Arcsin
uFunc L.Arccos = Arccos
uFunc L.Arctan = Arctan
uFunc L.Exp = Exp
uFunc L.Sqrt = Sqrt
uFunc L.Neg = Neg
uFunc L.Arctan = Arctan
uFunc L.Exp = Exp
uFunc L.Sqrt = Sqrt
uFunc L.Neg = Neg

uFuncB :: L.UFuncB -> UFuncB
uFuncB LD.Not = Not
Expand Down
2 changes: 0 additions & 2 deletions code/drasil-code-base/Language/Drasil/Code/Expr/Extract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Data.List (nub)
eNames :: CodeExpr -> [String]
eNames (AssocA _ l) = concatMap eNames l
eNames (AssocB _ l) = concatMap eNames l
eNames (Deriv _ a b) = b : eNames a
eNames (C c) = [c]
eNames Int{} = []
eNames Dbl{} = []
Expand Down Expand Up @@ -55,7 +54,6 @@ eNamesRI (UpFrom (_, il)) = eNames il
eNames' :: CodeExpr -> [String]
eNames' (AssocA _ l) = concatMap eNames' l
eNames' (AssocB _ l) = concatMap eNames' l
eNames' (Deriv _ a b) = b : eNames' a
eNames' (C c) = [c]
eNames' Int{} = []
eNames' Dbl{} = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ eprec Perc{} = 500
eprec (AssocA op _) = precA op
eprec (AssocB op _) = precB op
eprec C{} = 500
eprec Deriv{} = prec2Arith Frac
eprec FCall{} = 210
eprec New{} = 210
eprec Message{} = 210
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,6 @@ modifiedODESyst sufx info = map replaceDepVar (odeSyst info)
| otherwise = cc
replaceDepVar (AssocA a es) = AssocA a (map replaceDepVar es)
replaceDepVar (AssocB b es) = AssocB b (map replaceDepVar es)
replaceDepVar (Deriv dt e u) = Deriv dt (replaceDepVar e) u
replaceDepVar (FCall u es nes) = FCall u (map replaceDepVar es)
(map (over _2 replaceDepVar) nes)
replaceDepVar (New u es nes) = New u (map replaceDepVar es)
Expand Down
1 change: 0 additions & 1 deletion code/drasil-code/Language/Drasil/Code/Imperative/Import.hs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ convExpr (AssocA MulI l) = foldl1 (#*) <$> mapM convExpr l
convExpr (AssocA MulRe l) = foldl1 (#*) <$> mapM convExpr l
convExpr (AssocB And l) = foldl1 (?&&) <$> mapM convExpr l
convExpr (AssocB Or l) = foldl1 (?||) <$> mapM convExpr l
convExpr Deriv{} = return $ litString "**convExpr :: Deriv unimplemented**"
convExpr (C c) = do
g <- get
let v = quantvar (lookupC g c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ codeExpr (AssocA AddI l) sm = assocExpr P.Add (precA AddI) l sm
codeExpr (AssocA AddRe l) sm = assocExpr P.Add (precA AddRe) l sm
codeExpr (AssocA MulI l) sm = P.Row $ mulExpr l MulI sm
codeExpr (AssocA MulRe l) sm = P.Row $ mulExpr l MulRe sm
codeExpr (Deriv Part a b) sm =
P.Div (P.Row [P.Spc P.Thin, P.Spec Partial, codeExpr a sm])
(P.Row [P.Spc P.Thin, P.Spec Partial,
symbol $ lookupC (sm ^. stg) (sm ^. ckdb) b])
codeExpr (Deriv Total a b) sm =
P.Div (P.Row [P.Spc P.Thin, P.Ident "d", codeExpr a sm])
(P.Row [P.Spc P.Thin, P.Ident "d",
symbol $ lookupC (sm ^. stg) (sm ^. ckdb) b])
codeExpr (C c) sm = symbol $ lookupC (sm ^. stg) (sm ^. ckdb) c
codeExpr (FCall f [x] []) sm =
P.Row [symbol $ lookupC (sm ^. stg) (sm ^. ckdb) f, parens $ codeExpr x sm]
Expand Down

0 comments on commit 83bb992

Please sign in to comment.