[<<][meta][>>][..]
Sun Dec 4 15:12:29 EST 2011
Array types
Currently I'm assuming that types of variables scalar (constrained by
mVar), but this won't work for arrays.
Ok, this needs some deeper ajustment. The idea is that a type is
really base data type + indirection information (arrays/pointers).
This type should be properly derefereced for a _get in Code, and mVar
should also support this.
Ha. Pointers behave a bit like curried functions, don't they?
I'm running into a problem: array sizes behave as type information,
but they really are not. The same code can work on arrays of
different types.
Maybe just work around that for now. Array types can be fixed in
which case their parameters are host language integers -- not target
language entities! or unknown.
Ok, I'm properly confused now. I would like to encode the pointer
order in the Code type, but I don't see a good way to do that. It
seems that from
_get :: r (a t) -> r Tint -> m (r t)
this could also be
r (a (a (a v))) -> r Tint -> m (r (a (a v)))
but doing that I have trouble mapping this to Code and Term.
Ok, I just use the input Var's Type info to derive the output's type.
This avoids the typeclass stuff.
This is what comes out now:
t19' inArray outArray = do
(inFirst, inLast, inStride) <- _bounds inArray
(outFirst, outLast, outStride) <- _bounds outArray
-- We assume that output and input dims are compatible, ignoring
-- inLast (or equivalently outLast).
i <- _var $ lit 1
v <- _get inArray i
_set outArray i v
_exit
int n = Lit (Type AInt []) (show n)
varArr :: String -> Code (CodeArray Tint)
varArr name = Code $ Ref $ Var (Type AInt [()]) name
t19 = term $ t19' (varArr "in") (varArr "out")
This gives:
(Let (Var (Type i []) "r0") (Lit (Type i []) "1")
(Let (Var (Type i []) "r1") (Get (Var (Type i [()]) "in")
(Ref (Var (Type i []) "r0")))
(Begin
(Set (Var (Type i [()]) "out")
(Ref (Var (Type i []) "r0"))
(Ref (Var (Type i []) "r1")))
(Ret (Lit (Type i []) "0")))))
which looks about right.
[Reply][About]
[<<][meta][>>][..]