Made System.exit return 'a' instead of ().

This commit is contained in:
Erik Svedäng 2018-02-08 22:13:27 +01:00
parent cda502b9d2
commit 36274a29d3
3 changed files with 18 additions and 6 deletions

View File

@ -1,5 +1,4 @@
(defmodule System
(register exit (Fn [Int] ()))
(register free (Fn [t] ()))
(register time (Fn [] Int))
(register srand (Fn [Int] ()))

View File

@ -650,10 +650,6 @@ string Bool_format(string* str, bool b) {
return buffer;
}
void System_exit(int code) {
exit(code);
}
void System_free(void *p) {
CARP_FREE(p);
}

View File

@ -49,7 +49,7 @@ arrayModule = Env { envBindings = bindings, envParent = Nothing, envModuleName =
, templateSort
]
-- | The pointer module contains functions for dealing with pointers.
-- | The Pointer module contains functions for dealing with pointers.
pointerModule :: Env
pointerModule = Env { envBindings = bindings, envParent = Nothing, envModuleName = Just "Pointer", envUseModules = [], envMode = ExternalEnv }
where bindings = Map.fromList [ templatePointerCopy ]
@ -65,6 +65,22 @@ templatePointerCopy = defineTemplate
,"}"])
(const [])
-- | The System module contains functions for various OS related things like timing and process control.
systemModule :: Env
systemModule = Env { envBindings = bindings, envParent = Nothing, envModuleName = Just "System", envUseModules = [], envMode = ExternalEnv }
where bindings = Map.fromList [ templateExit ]
-- | A template function for exiting.
templateExit :: (String, Binder)
templateExit = defineTemplate
(SymPath ["System"] "exit")
(FuncTy [IntTy] (VarTy "a"))
(toTemplate "$a $NAME (int code)")
(toTemplate $ unlines ["$DECL {"
," exit(code);"
,"}"])
(const [])
-- | The dynamic module contains dynamic functions only available in the repl and during compilation.
dynamicModule :: Env
dynamicModule = Env { envBindings = bindings, envParent = Nothing, envModuleName = Just "Dynamic", envUseModules = [], envMode = ExternalEnv }
@ -139,6 +155,7 @@ startingGlobalEnv noArray =
]
++ (if noArray then [] else [("Array", Binder (XObj (Mod arrayModule) Nothing Nothing))])
++ [("Pointer", Binder (XObj (Mod pointerModule) Nothing Nothing))]
++ [("System", Binder (XObj (Mod systemModule) Nothing Nothing))]
++ [("Dynamic", Binder (XObj (Mod dynamicModule) Nothing Nothing))]
-- | The type environment (containing deftypes and interfaces) before any code is run.