Make unsubscriptType produce the right types for slices
This commit is contained in:
parent
ed847a1ea9
commit
4551d97b28
|
@ -7,6 +7,7 @@ import Control.Monad.State (MonadState, StateT, execStateT, liftIO, modify, get,
|
|||
import Data.List
|
||||
import qualified Data.Map as Map
|
||||
import Data.Maybe
|
||||
import Debug.Trace
|
||||
import qualified IO
|
||||
import Numeric (readHex)
|
||||
import Text.ParserCombinators.Parsec
|
||||
|
|
|
@ -25,6 +25,13 @@ Add an option for whether to compile out overflow/bounds checks.
|
|||
|
||||
## Parser
|
||||
|
||||
The way literal typing is done at the moment is a complete mess.
|
||||
We should probably have a smarter "can this literal be of this type?" function
|
||||
that walks both the wanted type and the parsed literal, and is smart about
|
||||
whether elements in an array are pure literals (in which case they can be
|
||||
type-coerced happily) or something else (in which case they must have the right
|
||||
type).
|
||||
|
||||
Record literals aren't implemented.
|
||||
|
||||
Inline C code should be supported; say something like "INLINE "C"" and the
|
||||
|
|
|
@ -8,6 +8,7 @@ import Control.Monad.State
|
|||
import Data.Generics
|
||||
import qualified Data.Map as Map
|
||||
import Data.Maybe
|
||||
import Debug.Trace
|
||||
|
||||
import qualified AST as A
|
||||
import Errors
|
||||
|
@ -108,11 +109,11 @@ subscriptType _ t = die $ "unsubscriptable type: " ++ show t
|
|||
-- a subscript, return what the type being subscripted is.
|
||||
unsubscriptType :: (PSM m, Die m) => A.Subscript -> A.Type -> m A.Type
|
||||
unsubscriptType (A.SubscriptFromFor _ _ _) t
|
||||
= return t
|
||||
= return $ removeFixedDimension t
|
||||
unsubscriptType (A.SubscriptFrom _ _) t
|
||||
= return t
|
||||
= return $ removeFixedDimension t
|
||||
unsubscriptType (A.SubscriptFor _ _) t
|
||||
= return t
|
||||
= return $ removeFixedDimension t
|
||||
unsubscriptType (A.SubscriptField _ _) t
|
||||
= die $ "unsubscript of record type (but we can't tell which one)"
|
||||
unsubscriptType (A.Subscript _ sub) t
|
||||
|
@ -249,6 +250,11 @@ stripArrayType :: A.Type -> A.Type
|
|||
stripArrayType (A.Array _ t) = stripArrayType t
|
||||
stripArrayType t = t
|
||||
|
||||
-- | Remove one fixed dimension from a type.
|
||||
removeFixedDimension :: A.Type -> A.Type
|
||||
removeFixedDimension (A.Array (A.Dimension _:ds) t) = A.Array (A.UnknownDimension:ds) t
|
||||
removeFixedDimension t = t
|
||||
|
||||
-- | Remove any fixed array dimensions from a type.
|
||||
removeFixedDimensions :: A.Type -> A.Type
|
||||
removeFixedDimensions (A.Array ds t) = A.Array [A.UnknownDimension | _ <- ds] t
|
||||
|
|
Loading…
Reference in New Issue
Block a user