Fix preludeFuns and remove ptr %cxt from main

This commit is contained in:
Martin Fredin 2023-05-15 00:32:34 +02:00
parent 5e15983f4c
commit 36df452db5

View file

@ -111,7 +111,8 @@ compileScs (DBind bind : xs) = do
. Map.lookup name . Map.lookup name
. globals . globals
let args' = zip (mkCxtName : map fst args) t_args let args' | isMain = []
| otherwise = zip (mkCxtName : map fst args) t_args
emit $ Define FastCC (if isMain then I64 else t_return) name args' emit $ Define FastCC (if isMain then I64 else t_return) name args'
modify $ \s -> s { locals = foldr insertArg s.locals args' } modify $ \s -> s { locals = foldr insertArg s.locals args' }
@ -365,16 +366,13 @@ emitECased t e cases = do
emit $ Label lbl_failPos emit $ Label lbl_failPos
preludeFuns :: LLVMIr -> Ident -> LLVMValue -> LLVMValue -> CompilerState LLVMIr preludeFuns :: LLVMIr -> Ident -> LLVMValue -> LLVMValue -> CompilerState LLVMIr
preludeFuns def (Ident xs) arg1 arg2 preludeFuns def xs arg1 arg2 = case xs of
| "$langle$$langle$" `isPrefixOf` xs = pure $ Icmp LLSlt I8 arg1 arg2 "$langle$$langle$" -> pure $ Icmp LLSlt I8 arg1 arg2 -- FIXME
| "$langle$" `isPrefixOf` xs = pure $ Icmp LLSlt I64 arg1 arg2 "$langle$$Int_Int_Bool" -> pure $ Icmp LLSlt I64 arg1 arg2
| "$minus$" `isPrefixOf` xs = pure $ Sub I64 arg1 arg2 "$minus$$Int_Int_Int" -> pure $ Sub I64 arg1 arg2
| "$plus$" `isPrefixOf` xs = pure $ Add I64 arg1 arg2 "$plus$$Int_Int_Int" -> pure $ Add I64 arg1 arg2
| "printChar$" `isPrefixOf` xs = do "printChar$Char_Unit" -> pure . UnsafeRaw $ "add i16 0,0\n call void (ptr, ...) @printf(ptr noundef @.char_print_no_nl, i8 noundef " <> toIr arg1 <> ")\n"
pure . UnsafeRaw $ _ -> pure def
"add i16 0,0\n call void (ptr, ...) @printf(ptr noundef @.char_print_no_nl, i8 noundef " <> toIr arg1 <> ")\n"
--char_print_no_nl
| otherwise = pure def
emitApp :: Type -> T Exp -> T Exp -> CompilerState () emitApp :: Type -> T Exp -> T Exp -> CompilerState ()
emitApp rt e1 e2 = do emitApp rt e1 e2 = do