Fixed the sizes of retyping a multi-dimensional array

This commit is contained in:
Neil Brown 2008-03-07 22:46:39 +00:00
parent 8030161a90
commit 5ae8aca68e
2 changed files with 11 additions and 3 deletions

View File

@ -135,15 +135,19 @@ declareSizesArray = doGeneric `ext1M` doStructured
0 -> return $ makeStaticSizeSpec m n_sizes
[if d == A.UnknownDimension then A.Dimension (bytes `div` (knownDimsTotal * biElem)) else d | d <- ds]
_ -> dieP m "RETYPES has sizes that do not fit"
-- TODO apply a dynamic check for this part:
BIUnknown -> dieP m $ "Cannot handle RETYPES sizes: " ++ show birhs
-- Some array dimensions are not known at compile-time:
_ -> do let A.Array _ elemSrcT = t
_ -> do let A.Array srcDs elemSrcT = t
BIJust biSrcElem <- bytesInType elemSrcT
let A.Variable _ srcN = v
multipliedDimsV = foldl (A.Dyadic m A.Mul) (makeConstant m biSrcElem)
[A.ExprVariable m $ A.SubscriptedVariable m (A.Subscript m $ makeConstant m i) (A.Variable m $ append_sizes srcN) | i <- [0 .. length srcDs - 1]]
return $ makeDynamicSizeSpec m n_sizes
[case d of
-- TODO add a run-time check here for invalid retypes
A.UnknownDimension -> (A.Dyadic m A.Div (A.Dyadic m A.Mul (makeConstant m biSrcElem) (A.SizeVariable m v))
(makeConstant m $ knownDimsTotal * biElem))
A.UnknownDimension -> A.Dyadic m A.Div multipliedDimsV
(makeConstant m $ knownDimsTotal * biElem)
A.Dimension n -> makeConstant m n
| d <- ds]
defineSizesName m n_sizes sizeSpecType

View File

@ -766,6 +766,10 @@ cgenArraySubscript checkValid v es
gen = sequence_ $ intersperse (tell ["*"]) $ genSub : genChunks
genSub
= if checkValid
-- Total, complete and utter horrible hack until we have
-- some way of expressing unchecked subscripting in the AST:
-- TODO fix this
&& (not $ "_sizes" `isSuffixOf` (let A.Variable _ (A.Name _ _ n) = v in n))
then do tell ["occam_check_index("]
call genExpression e
tell [","]