mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
* feat!: move C library wrapper funtions to IO.Raw * docs: fixed doc string for (String.allocated?) * docs: removed superfluous parameter names for defns * fix: replaces IO.exit by System.exit * fix: ./test/regression.carp for (IO.read->EOF) * fix: ./test/system.carp * feat: implemented IO.fwrite! * feat!: removed IO.exit * feat!: raw character input now returns Int instead of Char * fix: removed irritating space chars * fix: repaired ./example/carp_demo.carp * fix: reverted System.exit to return an Int for SDL examples * fix: removed System.exit! Co-authored-by: guberatsie <gunnar.bernhardt@siemens.com>
63 lines
3.0 KiB
Plaintext
63 lines
3.0 KiB
Plaintext
(system-include "carp_system.h")
|
|
(system-include "errno.h") ; needed for (System.errno)
|
|
(system-include "string.h") ; needed for (System.strerror)
|
|
|
|
(defmodule System
|
|
(doc carp-init-globals "Initializes all global variables (in correct order, based on interdependencies). Called automatically by `main` if the project is compiled as an executable. Client code needs to call this function manually when using a library written in Carp.")
|
|
(register carp-init-globals (Fn [Int (Ptr (Ptr CChar))] ()) "carp_init_globals")
|
|
(doc time "Gets the current system time as an integer.")
|
|
(register time (Fn [] Int))
|
|
(doc nanotime "Gets the current system time in nanoseconds as a long.")
|
|
(register nanotime (Fn [] Long))
|
|
(doc sleep-seconds "Sleeps for a specified number of seconds.")
|
|
(register sleep-seconds (Fn [Int] ()))
|
|
(doc sleep-seconds "Sleeps for a specified number of microseconds.")
|
|
(register sleep-micros (Fn [Int] ()))
|
|
(doc system "Performs a system command.")
|
|
(register system (Fn [&String] Int))
|
|
(doc args "Represents the command line arguments.")
|
|
(register args (StaticArray String))
|
|
(register fork (Fn [] Int) "fork")
|
|
(register wait (Fn [(Ptr Int)] Int) "wait")
|
|
(register get-exit-status (Fn [Int] Int) "WEXITSTATUS")
|
|
(register signal (Fn [Int (Fn [Int] ())] ()) "signal")
|
|
(register signal-abort Int "SIGABRT")
|
|
(register signal-fpe Int "SIGFPE")
|
|
(register signal-ill Int "SIGILL")
|
|
(register signal-int Int "SIGINT")
|
|
(register signal-segv Int "SIGSEGV")
|
|
(register signal-term Int "SIGTERM")
|
|
(register abort (Fn [] ()) "abort")
|
|
|
|
(register strerror- (Fn [Int] (Ptr CChar) ) "strerror")
|
|
(doc strerror "get error description for error code in standard C library (thin wrapper for the C standard library).")
|
|
(defn strerror [error-no]
|
|
(String.from-cstr (strerror- error-no)) )
|
|
(register errno Int "errno")
|
|
(doc error-text "returns a description for the last function from the C standard library to set System.errno. Please note that System.errno may change if strerror() does not know it (and thus sets it to EINVAL), so consider copying it before, if you should need it. Calling error-text after a successful call will return 'SUCCESS' and leave System.errno unchanged.")
|
|
(defn error-text []
|
|
(strerror System.errno) )
|
|
|
|
(register EACCES Int "EACCES")
|
|
(register EEXIST Int "EEXIST")
|
|
(register EINVAL Int "EINVAL")
|
|
(register EIO Int "EIO")
|
|
(register EISDIR Int "EISDIR")
|
|
(register ELOOP Int "ELOOP")
|
|
(register EMFILE Int "EMFILE")
|
|
(register ENAMETOOLONG Int "ENAMETOOLONG")
|
|
(register ENOENT Int "ENOENT")
|
|
(register ENOMEM Int "EINVAL")
|
|
(register ENOSPC Int "ENOSPC")
|
|
(register ENOSR Int "ENOSR")
|
|
(register ENOTDIR Int "ENOTDIR")
|
|
(register ENXIO Int "ENXIO")
|
|
(register EOVERFLOW Int "EOVERFLOW")
|
|
(register EROFS Int "EROFS")
|
|
(register EINTR Int "EINTR")
|
|
|
|
(doc exit "exits the program with the supplied exit code (thin wrapper for the C standard library).")
|
|
(deftemplate exit (Fn [Int] a) "$a $NAME(int code)" "$DECL { exit(code); }")
|
|
|
|
)
|