diff options
Diffstat (limited to 'check.hs')
-rw-r--r-- | check.hs | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -64,13 +64,16 @@ typeCheck (Program decls) = Program <$> mapM (goD topLevelNames) decls functionTypes :: Map.Map Name (Type,[Type]) functionTypes = foldr (uncurry Map.insert) Map.empty pairs where pairs = map ((,) <$> nameOf <*> getTypes) $ filter isFunctionDecl decls + getTypes (DecFunction rt _ args _) = (rt, map fst args) + getTypes (DecExtern (TypeFunc rt ats) _) = (rt, ats) getTypes _ = undefined isVarDecl (DecVariable {}) = True isVarDecl _ = False isFunctionDecl (DecFunction {}) = True + isFunctionDecl (DecExtern (TypeFunc {}) _) = True isFunctionDecl _ = False goD :: Map.Map Name Type -> Declaration -> Error Declaration @@ -150,7 +153,7 @@ typeCheck (Program decls) = Program <$> mapM (goD topLevelNames) decls \(a,i) -> let argtype = fromJust (exTypeOf a) in if canConvert argtype (snd ft !! i) then return a - else Left $ "Cannot convert type '" ++ pshow argtype ++ "' to '" ++ pshow (fst ft) + else Left $ "Cannot convert type '" ++ pshow argtype ++ "' to '" ++ pshow (snd ft !! i) ++ "' in call of function '" ++ pshow n ++ "'" return $ ExLit (LitCall n rargs) (Just (fst ft)) goE names (ExBinOp bo e1 e2 _) = do @@ -324,10 +327,18 @@ mapProgram prog mapper = goP prog rt <- goT t rn <- goN n h_d $ DecTypedef rt rn + goD (DecExtern t n) = do + rt <- goT t + rn <- goN n + h_d $ DecExtern rt rn goT :: MapperHandler Type goT (TypePtr t) = goT t >>= (h_t . TypePtr) goT (TypeName n) = goN n >>= (h_t . TypeName) + goT (TypeFunc t as) = do + rt <- goT t + ras <- mapM goT as + h_t $ TypeFunc rt ras goT t = h_t t goN :: MapperHandler Name |