From 05e7f974e34445340cda226a28b42a66fe5c7941 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 28 Jan 2023 14:00:02 -0600 Subject: [PATCH] Add os/compiler to the core. Allows querying what compiler was used to compile Janet. --- src/boot/boot.janet | 2 +- src/core/os.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 27470270..675a5262 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -3933,7 +3933,7 @@ compile-only (flycheck stdin :source :stdin :exit exit-on-error) (do (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) (defn getprompt [p] (def [line] (parser/where p)) diff --git a/src/core/os.c b/src/core/os.c index 5b355b49..7fdfcd67 100644 --- a/src/core/os.c +++ b/src/core/os.c @@ -119,6 +119,7 @@ JANET_CORE_FN(os_which, "Check the current operating system. Returns one of:\n\n" "* :windows\n\n" "* :mingw\n\n" + "* :cygwin\n\n" "* :macos\n\n" "* :web - Web assembly (emscripten)\n\n" "* :linux\n\n" @@ -133,6 +134,8 @@ JANET_CORE_FN(os_which, return janet_ckeywordv(janet_stringify(JANET_OS_NAME)); #elif defined(JANET_MINGW) return janet_ckeywordv("mingw"); +#elif defined(JANET_CYGWIN) + return janet_ckeywordv("cygwin"); #elif defined(JANET_WINDOWS) return janet_ckeywordv("windows"); #elif defined(JANET_APPLE) @@ -197,6 +200,27 @@ JANET_CORE_FN(os_arch, #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_stringify @@ -2244,6 +2268,7 @@ void janet_lib_os(JanetTable *env) { JANET_CORE_REG("os/exit", os_exit), JANET_CORE_REG("os/which", os_which), JANET_CORE_REG("os/arch", os_arch), + JANET_CORE_REG("os/compiler", os_compiler), #ifndef JANET_REDUCED_OS JANET_CORE_REG("os/environ", os_environ), JANET_CORE_REG("os/getenv", os_getenv),