diff --git a/fco2/GenerateC.hs b/fco2/GenerateC.hs index d6871ef..178cb14 100644 --- a/fco2/GenerateC.hs +++ b/fco2/GenerateC.hs @@ -498,7 +498,7 @@ genInputItem c (A.InCounted m cv av) tell [", "] fst $ abbrevVariable A.Abbrev t av tell [", "] - subT <- subscriptType (A.Subscript m $ makeConstant m 0) t + subT <- trivialSubscriptType t genVariable cv tell [" * "] genBytesInType subT @@ -533,7 +533,7 @@ genOutputItem c (A.OutCounted m ce ae) tell [", "] fst $ abbrevVariable A.Abbrev t v tell [", "] - subT <- subscriptType (A.Subscript m $ makeConstant m 0) t + subT <- trivialSubscriptType t genExpression ce tell [" * "] genBytesInType subT diff --git a/fco2/Parse.hs b/fco2/Parse.hs index cda8d29..448a995 100644 --- a/fco2/Parse.hs +++ b/fco2/Parse.hs @@ -472,7 +472,7 @@ pushSubscriptTypeContext = do ps <- get case psTypeContext ps of (Just t):_ -> - do subT <- subscriptType (A.Subscript emptyMeta $ makeConstant emptyMeta 0) t + do subT <- trivialSubscriptType t pushTypeContext $ Just subT _ -> pushTypeContext Nothing --}}} @@ -1200,7 +1200,7 @@ chanArrayAbbrev n <- newChannelName sIS sLeft - ct <- subscriptType (A.Subscript m $ makeConstant m 0) s + ct <- trivialSubscriptType s case ct of A.Chan _ -> return (ct, s, n) _ -> pzero) diff --git a/fco2/Types.hs b/fco2/Types.hs index d4ee818..6c58ccc 100644 --- a/fco2/Types.hs +++ b/fco2/Types.hs @@ -101,6 +101,15 @@ subscriptType (A.SubscriptField m tag) t = typeOfRecordField m t tag subscriptType (A.Subscript m sub) t = plainSubscriptType m sub t subscriptType _ _ = die "unsubscriptable type" +-- | Just remove the first dimension from an array type -- like doing +-- subscriptType with constant 0 as a subscript, but without the checking. +-- This is used for the couple of cases where we know it's safe and don't want +-- the usage check. +trivialSubscriptType :: (Die m) => A.Type -> m A.Type +trivialSubscriptType (A.Array [d] t) = return t +trivialSubscriptType (A.Array (d:ds) t) = return $ A.Array ds t +trivialSubscriptType _ = die "not plain array type" + typeOfVariable :: (PSM m, Die m) => A.Variable -> m A.Type typeOfVariable (A.Variable m n) = typeOfName n typeOfVariable (A.SubscriptedVariable m s v)