Skip to content

Commit

Permalink
gen glassbr.py example
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahCardoso committed Jul 12, 2024
1 parent 957fd0b commit 0801630
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module Language.Drasil.Code.Imperative.Import (codeType, spaceCodeType,
import Language.Drasil (HasSymbol, HasUID(..), HasSpace(..),
Space (Rational, Real), RealInterval(..), UID, Constraint(..), Inclusive (..))
import Database.Drasil (symbResolve)
import Language.Drasil.CodeExpr (sy, ($<), ($>), ($<=), ($>=), ($&&), ($=), exactDbl, idx)
import Language.Drasil.CodeExpr (sy, ($<), ($>), ($<=), ($>=), ($&&), idxOf)
import qualified Language.Drasil.CodeExpr as CE (int)
import Language.Drasil.CodeExpr.Development (CodeExpr(..), ArithBinOp(..),
AssocArithOper(..), AssocBoolOper(..), AssocConcatOper(..), BoolBinOp(..), EqBinOp(..),
LABinOp(..), OrdBinOp(..), UFunc(..), UFuncB(..), UFuncVV(..), UFuncVN(..),
Expand Down Expand Up @@ -401,7 +402,7 @@ renderRealInt s (UpFrom (Inc, a)) = sy s $>= a
renderRealInt s (UpFrom (Exc, a)) = sy s $> a

renderSet :: (HasUID c, HasSymbol c) => c -> CodeExpr -> CodeExpr
renderSet e s = ((idx s (sy e))$= exactDbl 0)
renderSet e s = ((idxOf s (sy e))$>= CE.int 0)

Check warning on line 406 in code/drasil-code/lib/Language/Drasil/Code/Imperative/Import.hs

View workflow job for this annotation

GitHub Actions / HLint

Suggestion in renderSet in module Language.Drasil.Code.Imperative.Import: Redundant bracket ▫︎ Found: "((idxOf s (sy e)) $>= CE.int 0)" ▫︎ Perhaps: "(idxOf s (sy e)) $>= CE.int 0"

Check warning on line 406 in code/drasil-code/lib/Language/Drasil/Code/Imperative/Import.hs

View workflow job for this annotation

GitHub Actions / HLint

Suggestion in renderSet in module Language.Drasil.Code.Imperative.Import: Redundant bracket ▫︎ Found: "(idxOf s (sy e)) $>= CE.int 0" ▫︎ Perhaps: "idxOf s (sy e) $>= CE.int 0"
-- | Maps a 'UFunc' to the corresponding GOOL unary function.
unop :: (OOProg r) => UFunc -> (SValue r -> SValue r)
Expand Down
4 changes: 2 additions & 2 deletions code/drasil-example/glassbr/lib/Drasil/GlassBR/Unitals.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ standOffDist = uq (constrained' (uc sD (variable "SD") Real metre)

nomThick = cuc "nomThick"
(nounPhraseSent $ S "nominal thickness")
lT millimetre {-Discrete nominalThicknesses, but not implemented-} Integer
[sfwrElem $ mkSet (map exactDbl [2,2,3,4,5,6,8,10,12,16,19,22])] $ exactDbl 8 -- for testing
lT millimetre {-Discrete nominalThicknesses, but not implemented-} Rational
[sfwrElem $ mkSet (map dbl nominalThicknesses)] $ exactDbl 8 -- for testing

glassTypeCon = constrainedNRV' (dqdNoUnit glassTy lG String)
[{- TODO: add back constraint: EnumeratedStr Software $ map (abrv . snd) glassType -}]
Expand Down
2 changes: 1 addition & 1 deletion code/drasil-lang/lib/Language/Drasil/CodeExpr/Lang.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ data BoolBinOp = Impl | Iff
deriving Eq

-- | Index operator.
data LABinOp = Index
data LABinOp = Index | IndexOf
deriving Eq

-- | Ordered binary operators (less than, greater than, less than or equal to, greater than or equal to).
Expand Down
9 changes: 8 additions & 1 deletion code/drasil-lang/lib/Language/Drasil/Expr/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ class ExprC r where

-- | Smart constructor for indexing.
idx :: r -> r -> r


idxOf :: r -> r -> r

-- | Smart constructor for the summation, product, and integral functions over an interval.
defint, defsum, defprod :: Symbol -> r -> r -> r -> r

Expand Down Expand Up @@ -339,6 +341,7 @@ instance ExprC Expr where
-- | Smart constructor for indexing.
idx = LABinaryOp Index

idxOf = LABinaryOp IndexOf
-- | Integrate over some expression with bounds (∫).
defint v low high = Operator Add (BoundedDD v Continuous low high)

Expand Down Expand Up @@ -501,6 +504,9 @@ instance ExprC M.ModelExpr where
-- | Smart constructor for indexing.
idx = M.LABinaryOp M.Index

-- | Smart constructor for indexing.
idxOf = M.LABinaryOp M.IndexOf

-- | Integrate over some expression with bounds (∫).
defint v low high = M.Operator M.Add (BoundedDD v Continuous low high)

Expand Down Expand Up @@ -665,6 +671,7 @@ instance ExprC C.CodeExpr where
-- | Smart constructor for indexing.
idx = C.LABinaryOp C.Index

idxOf = C.LABinaryOp C.IndexOf
-- | Integrate over some expression with bounds (∫).
defint v low high = C.Operator C.Add (BoundedDD v Continuous low high)

Expand Down
10 changes: 8 additions & 2 deletions code/drasil-lang/lib/Language/Drasil/Expr/Lang.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ data BoolBinOp = Impl | Iff
deriving Eq

-- | Index operator.
data LABinOp = Index
data LABinOp = Index | IndexOf
deriving Eq

-- | Ordered binary operators (less than, greater than, less than or equal to, greater than or equal to).
Expand Down Expand Up @@ -399,7 +399,13 @@ instance Typed Expr Space where
(Left lt , Left _) -> Right $ "List accessor expects a list/vector, but received `" ++ show lt ++ "`."
(_ , Right e) -> Right e
(Right e , _ ) -> Right e

infer cxt (LABinaryOp IndexOf l n) = case (infer cxt l, infer cxt n) of
(Left (S.Set lt), Left nt) -> if S.isBasicNumSpace lt && nt == lt-- I guess we should only want it to be natural numbers, but integers or naturals is fine for now
then Left lt
else Right $ "List accessor not of type Integer nor Natural, but of type `" ++ show nt ++ "`"
(Left lt , Left _) -> Right $ "List accessor expects a list/vector, but received `" ++ show lt ++ "`."
(_ , Right e) -> Right e
(Right e , _ ) -> Right e
infer cxt (OrdBinaryOp _ l r) = case (infer cxt l, infer cxt r) of
(Left lt, Left rt) -> if S.isBasicNumSpace lt && lt == rt
then Left S.Boolean
Expand Down
2 changes: 1 addition & 1 deletion code/drasil-lang/lib/Language/Drasil/ModelExpr/Lang.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ data BoolBinOp = Impl | Iff
deriving Eq

-- | Index operator.
data LABinOp = Index
data LABinOp = Index | IndexOf
deriving Eq

-- | Ordered binary operators (less than, greater than, less than or equal to, greater than or equal to).
Expand Down

0 comments on commit 0801630

Please sign in to comment.