Refactored cgenArraySubscript ready to add support for static dimensions

This commit is contained in:
Neil Brown 2008-03-01 20:39:45 +00:00
parent 60daa07b93
commit 20f7666044

View File

@ -740,17 +740,20 @@ cgenArraySubscript checkValid v es
= do t <- typeOfVariable v = do t <- typeOfVariable v
let numDims = case t of A.Array ds _ -> length ds let numDims = case t of A.Array ds _ -> length ds
tell ["["] tell ["["]
sequence_ $ intersperse (tell ["+"]) $ genPlainSub v es [0..(numDims - 1)] sequence_ $ intersperse (tell ["+"]) $ genPlainSub (genDynamicDim v) es [0..(numDims - 1)]
tell ["]"] tell ["]"]
where where
genDynamicDim :: A.Variable -> Int -> CGen ()
genDynamicDim v i = call genVariable v >> call genSizeSuffix (show i)
-- | Generate the individual offsets that need adding together to find the -- | Generate the individual offsets that need adding together to find the
-- right place in the array. -- right place in the array.
-- FIXME This is obviously not the best way to factor this, but I figure a -- FIXME This is obviously not the best way to factor this, but I figure a
-- smart C compiler should be able to work it out... -- smart C compiler should be able to work it out...
genPlainSub :: A.Variable -> [A.Expression] -> [Int] -> [CGen ()] genPlainSub :: (Int -> CGen ()) -> [A.Expression] -> [Int] -> [CGen ()]
genPlainSub _ [] _ = [] genPlainSub _ [] _ = []
genPlainSub v (e:es) (sub:subs) genPlainSub genDim (e:es) (sub:subs)
= gen : genPlainSub v es subs = gen : genPlainSub genDim es subs
where where
gen = sequence_ $ intersperse (tell ["*"]) $ genSub : genChunks gen = sequence_ $ intersperse (tell ["*"]) $ genSub : genChunks
genSub genSub
@ -758,13 +761,12 @@ cgenArraySubscript checkValid v es
then do tell ["occam_check_index("] then do tell ["occam_check_index("]
call genExpression e call genExpression e
tell [","] tell [","]
call genVariable v genDim sub
call genSizeSuffix (show sub)
tell [","] tell [","]
genMeta (findMeta e) genMeta (findMeta e)
tell [")"] tell [")"]
else call genExpression e else call genExpression e
genChunks = [call genVariable v >> call genSizeSuffix (show i) | i <- subs] genChunks = map genDim subs
--}}} --}}}
--{{{ expressions --{{{ expressions