1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-26 16:30:26 +00:00

Add os/compiler to the core.

Allows querying what compiler was used to compile Janet.
This commit is contained in:
Calvin Rose 2023-01-28 14:00:02 -06:00
parent 0dbef65a73
commit 05e7f974e3
2 changed files with 26 additions and 1 deletions

View File

@ -3933,7 +3933,7 @@
compile-only (flycheck stdin :source :stdin :exit exit-on-error) compile-only (flycheck stdin :source :stdin :exit exit-on-error)
(do (do
(if-not quiet (if-not quiet
(print "Janet " janet/version "-" janet/build " " (os/which) "/" (os/arch) " - '(doc)' for help")) (print "Janet " janet/version "-" janet/build " " (os/which) "/" (os/arch) "/" (os/compiler) " - '(doc)' for help"))
(flush) (flush)
(defn getprompt [p] (defn getprompt [p]
(def [line] (parser/where p)) (def [line] (parser/where p))

View File

@ -119,6 +119,7 @@ JANET_CORE_FN(os_which,
"Check the current operating system. Returns one of:\n\n" "Check the current operating system. Returns one of:\n\n"
"* :windows\n\n" "* :windows\n\n"
"* :mingw\n\n" "* :mingw\n\n"
"* :cygwin\n\n"
"* :macos\n\n" "* :macos\n\n"
"* :web - Web assembly (emscripten)\n\n" "* :web - Web assembly (emscripten)\n\n"
"* :linux\n\n" "* :linux\n\n"
@ -133,6 +134,8 @@ JANET_CORE_FN(os_which,
return janet_ckeywordv(janet_stringify(JANET_OS_NAME)); return janet_ckeywordv(janet_stringify(JANET_OS_NAME));
#elif defined(JANET_MINGW) #elif defined(JANET_MINGW)
return janet_ckeywordv("mingw"); return janet_ckeywordv("mingw");
#elif defined(JANET_CYGWIN)
return janet_ckeywordv("cygwin");
#elif defined(JANET_WINDOWS) #elif defined(JANET_WINDOWS)
return janet_ckeywordv("windows"); return janet_ckeywordv("windows");
#elif defined(JANET_APPLE) #elif defined(JANET_APPLE)
@ -197,6 +200,27 @@ JANET_CORE_FN(os_arch,
#endif #endif
} }
/* Detect the compiler used to build the interpreter */
JANET_CORE_FN(os_compiler,
"(os/compiler)",
"Get the compiler used to compile the interpreter. Returns one of:\n\n"
"* :gcc\n\n"
"* :clang\n\n"
"* :msvc\n\n"
"* :unknown\n\n") {
janet_fixarity(argc, 0);
(void) argv;
#if defined(_MSC_VER)
return janet_ckeywordv("msvc");
#elif defined(__clang__)
return janet_ckeywordv("clang");
#elif defined(__GNUC__)
return janet_ckeywordv("gcc");
#else
return janet_ckeywordv("unknown");
#endif
}
#undef janet_stringify1 #undef janet_stringify1
#undef janet_stringify #undef janet_stringify
@ -2244,6 +2268,7 @@ void janet_lib_os(JanetTable *env) {
JANET_CORE_REG("os/exit", os_exit), JANET_CORE_REG("os/exit", os_exit),
JANET_CORE_REG("os/which", os_which), JANET_CORE_REG("os/which", os_which),
JANET_CORE_REG("os/arch", os_arch), JANET_CORE_REG("os/arch", os_arch),
JANET_CORE_REG("os/compiler", os_compiler),
#ifndef JANET_REDUCED_OS #ifndef JANET_REDUCED_OS
JANET_CORE_REG("os/environ", os_environ), JANET_CORE_REG("os/environ", os_environ),
JANET_CORE_REG("os/getenv", os_getenv), JANET_CORE_REG("os/getenv", os_getenv),