Fixed the sizes of retyping a multi-dimensional array
This commit is contained in:
parent
8030161a90
commit
5ae8aca68e
|
@ -135,15 +135,19 @@ declareSizesArray = doGeneric `ext1M` doStructured
|
||||||
0 -> return $ makeStaticSizeSpec m n_sizes
|
0 -> return $ makeStaticSizeSpec m n_sizes
|
||||||
[if d == A.UnknownDimension then A.Dimension (bytes `div` (knownDimsTotal * biElem)) else d | d <- ds]
|
[if d == A.UnknownDimension then A.Dimension (bytes `div` (knownDimsTotal * biElem)) else d | d <- ds]
|
||||||
_ -> dieP m "RETYPES has sizes that do not fit"
|
_ -> 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
|
BIUnknown -> dieP m $ "Cannot handle RETYPES sizes: " ++ show birhs
|
||||||
-- Some array dimensions are not known at compile-time:
|
-- 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
|
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
|
return $ makeDynamicSizeSpec m n_sizes
|
||||||
[case d of
|
[case d of
|
||||||
-- TODO add a run-time check here for invalid retypes
|
-- 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))
|
A.UnknownDimension -> A.Dyadic m A.Div multipliedDimsV
|
||||||
(makeConstant m $ knownDimsTotal * biElem))
|
(makeConstant m $ knownDimsTotal * biElem)
|
||||||
A.Dimension n -> makeConstant m n
|
A.Dimension n -> makeConstant m n
|
||||||
| d <- ds]
|
| d <- ds]
|
||||||
defineSizesName m n_sizes sizeSpecType
|
defineSizesName m n_sizes sizeSpecType
|
||||||
|
|
|
@ -766,6 +766,10 @@ cgenArraySubscript checkValid v es
|
||||||
gen = sequence_ $ intersperse (tell ["*"]) $ genSub : genChunks
|
gen = sequence_ $ intersperse (tell ["*"]) $ genSub : genChunks
|
||||||
genSub
|
genSub
|
||||||
= if checkValid
|
= 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("]
|
then do tell ["occam_check_index("]
|
||||||
call genExpression e
|
call genExpression e
|
||||||
tell [","]
|
tell [","]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user