1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 09:47:17 +00:00

Add api for checking build compatibilty.

This commit is contained in:
Andrew Chambers 2019-05-28 13:43:35 +12:00
parent ce9cd4fcef
commit 3c304ddc35
2 changed files with 41 additions and 0 deletions

View File

@ -26,6 +26,16 @@
#include "fiber.h"
#endif
static JanetBuildConfig *api_build_config = &(JanetBuildConfig){
.api_version = JANET_API_VERSION,
.single_threaded = JANET_SINGLE_THREADED_BIT,
.nanbox = JANET_NANBOX_BIT
};
const JanetBuildConfig *janet_build_config() {
return api_build_config;
}
void janet_panicv(Janet message) {
if (janet_vm_return_reg != NULL) {
*janet_vm_return_reg = message;

View File

@ -31,6 +31,8 @@ extern "C" {
#include "janetconf.h"
#define JANET_API_VERSION 1
#ifndef JANET_VERSION
#define JANET_VERSION "latest"
#endif
@ -184,6 +186,26 @@ extern "C" {
#endif
#endif
/* Runtime config constants */
#ifdef JANET_NO_NANBOX
#define JANET_NANBOX_BIT 0
#else
#define JANET_NANBOX_BIT 1
#endif
#ifdef JANET_SINGLE_THREADED
#define JANET_SINGLE_THREADED_BIT 1
#else
#define JANET_SINGLE_THREADED_BIT 0
#endif
typedef struct {
int api_version;
int single_threaded : 1;
int nanbox : 1;
} JanetBuildConfig;
/***** END SECTION CONFIG *****/
/***** START SECTION TYPES *****/
@ -1255,6 +1277,15 @@ JANET_API void janet_register(const char *name, JanetCFunction cfun);
/* New C API */
#define JANET_MODULE_ENTRY JANET_API void _janet_init
JANET_API int janet_api_version();
JANET_API const JanetBuildConfig *janet_build_config();
#define janet_api_compatible() \
((janet_api_build_config()->api_version == JANET_API_VERSION) \
&& (janet_api_build_config()->nanbox == JANET_NANBOX_BIT) \
&& (janet_api_build_config()->single_threaded == JANET_SINGLE_THREADED_BIT))
JANET_API void janet_panicv(Janet message);
JANET_API void janet_panic(const char *message);
JANET_API void janet_panics(const uint8_t *message);