diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-01-29 22:29:24 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-01-29 22:29:24 +0100 |
commit | 8f444b0c2a6d468a596949926eccf1edf932d4df (patch) | |
tree | a55eb16637d0c7f0ebb3fa4f4ab7dbb80cf8af40 /check.hs | |
parent | ce13c3ff2b64e1bfde13f735d871ea0a0e58a145 (diff) |
Calling external functions!
- Call extern-declared functions
- Parse 'c'har literals
- Correctly make function arguments into local variables
- Fix error message in check.hs (new line 153)
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 |