diff --git a/sample-programs/basic-1 b/sample-programs/basic-1 index f3f4a26..3738b1b 100644 --- a/sample-programs/basic-1 +++ b/sample-programs/basic-1 @@ -1,13 +1,20 @@ --tripplemagic : Int -> Int -> Int -> Int; --tripplemagic x y z = ((\x:Int. x+x) x) + y + z; - --- main : Int; --- main = tripplemagic ((\x:Int. x+x+3) ((\x:Int. x) 2)) 5 3 +--main : Int; +--main = tripplemagic ((\x:Int. x+x+3) ((\x:Int. x) 2)) 5 3 apply : (Int -> Int) -> Int -> Int; apply f x = f x; main : Int; -main = apply (\x:Int . x + 2) 5; +main = (\x : Int . x + 5) 5 + + +--apply : (Int -> Int -> Int) -> Int -> Int; +--apply f x y = f x y; +--krimp: Int -> Int -> Int; +--krimp x y = x + y; +--main : Int; +--main = apply (krimp) 2 3;--apply (\y: Int . (\x: Int . x + y + 2)) 5 2; diff --git a/src/Compiler.hs b/src/Compiler.hs index a31c3d8..cc90fa9 100644 --- a/src/Compiler.hs +++ b/src/Compiler.hs @@ -264,8 +264,14 @@ compile (Program prg) = do type2LlvmType :: Type -> LLVMType type2LlvmType = \case TInt -> I64 - TFun t xs -> Function (type2LlvmType t) [type2LlvmType xs] + TFun t xs -> do + let (t', xs') = function2LLVMType xs [type2LlvmType t] + Function t' xs' t -> CustomType $ Ident ("\"" ++ show t ++ "\"") + where + function2LLVMType :: Type -> [LLVMType] -> (LLVMType, [LLVMType]) + function2LLVMType (TFun t xs) s = function2LLVMType xs (type2LlvmType t : s) + function2LLVMType x s = (type2LlvmType x, s) getType :: Exp -> LLVMType getType (EInt _) = I64