Added a new variable type, DirectedVariable, for using channel-end specifiers
This commit is contained in:
parent
bfc7be2108
commit
9edea5d958
2
AST.hs
2
AST.hs
|
@ -231,6 +231,8 @@ data Variable =
|
|||
Variable Meta Name
|
||||
-- | A subscripted variable (e.g. @c[0]@ or @person[name]@).
|
||||
| SubscriptedVariable Meta Subscript Variable
|
||||
-- | A channel-end variable (e.g. @c?@)
|
||||
| DirectedVariable Meta Direction Variable
|
||||
deriving (Show, Eq, Typeable, Data)
|
||||
|
||||
-- | An expression.
|
||||
|
|
|
@ -96,6 +96,7 @@ evalVariable (A.Variable _ n)
|
|||
Just e -> evalExpression e
|
||||
Nothing -> throwError $ "non-constant variable " ++ show n ++ " used"
|
||||
evalVariable (A.SubscriptedVariable _ sub v) = evalVariable v >>= evalSubscript sub
|
||||
evalVariable (A.DirectedVariable _ _ v) = evalVariable v
|
||||
|
||||
evalIndex :: A.Expression -> EvalM Int
|
||||
evalIndex e
|
||||
|
|
|
@ -695,6 +695,7 @@ cgenVariable' ops checkValid v
|
|||
let isSub = case v of
|
||||
A.Variable _ _ -> False
|
||||
A.SubscriptedVariable _ _ _ -> True
|
||||
A.DirectedVariable _ _ _ -> False
|
||||
|
||||
let prefix = case (am, t) of
|
||||
(_, A.Array _ _) -> ""
|
||||
|
@ -724,6 +725,7 @@ cgenVariable' ops checkValid v
|
|||
|
||||
inner :: A.Variable -> CGen ()
|
||||
inner (A.Variable _ n) = genName n
|
||||
inner (A.DirectedVariable _ _ v) = inner v
|
||||
inner sv@(A.SubscriptedVariable _ (A.Subscript _ _) _)
|
||||
= do let (es, v) = collectSubs sv
|
||||
call genVariable ops v
|
||||
|
@ -1049,6 +1051,8 @@ cgenArrayAbbrev ops v
|
|||
genAASize (A.Variable _ on) arg
|
||||
= call genArraySize ops True
|
||||
(tell ["&"] >> genName on >> tell ["_sizes[", show arg, "]"])
|
||||
genAASize (A.DirectedVariable _ _ v) arg
|
||||
= genAASize v arg
|
||||
|
||||
cgenArraySize :: GenOps -> Bool -> CGen () -> A.Name -> CGen ()
|
||||
cgenArraySize ops isPtr size n
|
||||
|
|
|
@ -1238,6 +1238,7 @@ cppgenVariable' ops checkValid v
|
|||
let isSub = case v of
|
||||
A.Variable _ _ -> False
|
||||
A.SubscriptedVariable _ _ _ -> True
|
||||
A.DirectedVariable _ _ _ -> False
|
||||
|
||||
let prefix = case (am, t) of
|
||||
(_, A.Array _ _) -> ""
|
||||
|
@ -1267,6 +1268,8 @@ cppgenVariable' ops checkValid v
|
|||
|
||||
inner :: A.Variable -> CGen ()
|
||||
inner (A.Variable _ n) = genName n
|
||||
inner (A.DirectedVariable _ A.DirInput v) = tell ["(("] >> inner v >> tell [")->reader())"]
|
||||
inner (A.DirectedVariable _ A.DirOutput v) = tell ["(("] >> inner v >> tell [")->writer())"]
|
||||
inner sv@(A.SubscriptedVariable _ (A.Subscript _ _) _)
|
||||
= do let (es, v) = collectSubs sv
|
||||
call genVariable ops v
|
||||
|
|
|
@ -196,6 +196,7 @@ pullUp = doGeneric
|
|||
A.Array _ _ ->
|
||||
case e' of
|
||||
A.ExprVariable _ (A.Variable _ _) -> return e'
|
||||
A.ExprVariable _ (A.DirectedVariable _ _ _) -> return e'
|
||||
_ -> pull t e'
|
||||
_ -> return e'
|
||||
where
|
||||
|
|
6
Types.hs
6
Types.hs
|
@ -156,11 +156,17 @@ typeOfVariable :: (CSM m, Die m) => A.Variable -> m A.Type
|
|||
typeOfVariable (A.Variable m n) = typeOfName n
|
||||
typeOfVariable (A.SubscriptedVariable m s v)
|
||||
= typeOfVariable v >>= subscriptType s
|
||||
typeOfVariable (A.DirectedVariable m dir v)
|
||||
= do t <- typeOfVariable v
|
||||
case t of
|
||||
(A.Chan A.DirUnknown attr innerT) -> return (A.Chan dir attr innerT)
|
||||
_ -> die $ "Used specifier on something that was not a directionless channel: " ++ show v
|
||||
|
||||
-- | Get the abbreviation mode of a variable.
|
||||
abbrevModeOfVariable :: (CSM m, Die m) => A.Variable -> m A.AbbrevMode
|
||||
abbrevModeOfVariable (A.Variable _ n) = abbrevModeOfName n
|
||||
abbrevModeOfVariable (A.SubscriptedVariable _ sub v) = abbrevModeOfVariable v
|
||||
abbrevModeOfVariable (A.DirectedVariable _ _ v) = abbrevModeOfVariable v
|
||||
|
||||
dyadicIsBoolean :: A.DyadicOp -> Bool
|
||||
dyadicIsBoolean A.Eq = True
|
||||
|
|
Loading…
Reference in New Issue
Block a user