mirror of
https://github.com/janet-lang/janet
synced 2025-01-13 17:10:27 +00:00
Add JANET_DEF and co, use in math.c
This commit is contained in:
parent
700770b883
commit
98bdbfd3d5
@ -311,9 +311,6 @@ JANET_CORE_FN(janet_not, "(not x)", "Returns the boolean inverse of x.") {
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define JANET_CORE_CONST(env, name, val, doc) janet_def_sm(env, name, val, doc, __FILE__, __LINE__)
|
||||
|
||||
/* Module entry point */
|
||||
void janet_lib_math(JanetTable *env) {
|
||||
JanetRegExt math_cfuns[] = {
|
||||
@ -362,27 +359,26 @@ void janet_lib_math(JanetTable *env) {
|
||||
janet_core_cfuns_ext(env, NULL, math_cfuns);
|
||||
janet_register_abstract_type(&janet_rng_type);
|
||||
#ifdef JANET_BOOTSTRAP
|
||||
JANET_CORE_CONST(env, "math/pi", janet_wrap_number(3.1415926535897931),
|
||||
JDOC("The value pi."));
|
||||
JANET_CORE_CONST(env, "math/e", janet_wrap_number(2.7182818284590451),
|
||||
JDOC("The base of the natural log."));
|
||||
JANET_CORE_CONST(env, "math/inf", janet_wrap_number(INFINITY),
|
||||
JDOC("The number representing positive infinity"));
|
||||
JANET_CORE_CONST(env, "math/-inf", janet_wrap_number(-INFINITY),
|
||||
JDOC("The number representing negative infinity"));
|
||||
JANET_CORE_CONST(env, "math/int32-min", janet_wrap_number(INT32_MIN),
|
||||
JDOC("The minimum contiguous integer representable by a 32 bit signed integer"));
|
||||
JANET_CORE_CONST(env, "math/int32-max", janet_wrap_number(INT32_MAX),
|
||||
JDOC("The maximum contiguous integer represtenable by a 32 bit signed integer"));
|
||||
JANET_CORE_CONST(env, "math/int-min", janet_wrap_number(JANET_INTMIN_DOUBLE),
|
||||
JDOC("The minimum contiguous integer representable by a double (2^53)"));
|
||||
JANET_CORE_CONST(env, "math/int-max", janet_wrap_number(JANET_INTMAX_DOUBLE),
|
||||
JDOC("The maximum contiguous integer represtenable by a double (-(2^53))"));
|
||||
JANET_CORE_DEF(env, "math/pi", janet_wrap_number(3.1415926535897931),
|
||||
"The value pi.");
|
||||
JANET_CORE_DEF(env, "math/e", janet_wrap_number(2.7182818284590451),
|
||||
"The base of the natural log.");
|
||||
JANET_CORE_DEF(env, "math/inf", janet_wrap_number(INFINITY),
|
||||
"The number representing positive infinity");
|
||||
JANET_CORE_DEF(env, "math/-inf", janet_wrap_number(-INFINITY),
|
||||
"The number representing negative infinity");
|
||||
JANET_CORE_DEF(env, "math/int32-min", janet_wrap_number(INT32_MIN),
|
||||
"The minimum contiguous integer representable by a 32 bit signed integer");
|
||||
JANET_CORE_DEF(env, "math/int32-max", janet_wrap_number(INT32_MAX),
|
||||
"The maximum contiguous integer represtenable by a 32 bit signed integer");
|
||||
JANET_CORE_DEF(env, "math/int-min", janet_wrap_number(JANET_INTMIN_DOUBLE),
|
||||
"The minimum contiguous integer representable by a double (2^53)");
|
||||
JANET_CORE_DEF(env, "math/int-max", janet_wrap_number(JANET_INTMAX_DOUBLE),
|
||||
"The maximum contiguous integer represtenable by a double (-(2^53))");
|
||||
#ifdef NAN
|
||||
janet_def_sm(env, "math/nan", janet_wrap_number(NAN),
|
||||
JANET_CORE_DEF(env, "math/nan", janet_wrap_number(NAN), "Not a number (IEEE-754 NaN");
|
||||
#else
|
||||
janet_def_sm(env, "math/nan", janet_wrap_number(0.0 / 0.0),
|
||||
JANET_CORE_DEF(env, "math/nan", janet_wrap_number(0.0 / 0.0), "Not a number (IEEE-754 NaN)");
|
||||
#endif
|
||||
JDOC("Not a number (IEEE-754 NaN)"), __FILE__, __LINE__);
|
||||
#endif
|
||||
}
|
||||
|
@ -92,6 +92,7 @@ Janet janet_next_impl(Janet ds, Janet key, int is_interpreter);
|
||||
#ifdef JANET_BOOTSTRAP
|
||||
#define JANET_CORE_REG JANET_REG
|
||||
#define JANET_CORE_FN JANET_FN
|
||||
#define JANET_CORE_DEF JANET_DEF
|
||||
#define janet_core_def janet_def
|
||||
#define janet_core_cfuns janet_cfuns
|
||||
#define janet_core_def_sm janet_def_sm
|
||||
@ -99,6 +100,7 @@ Janet janet_next_impl(Janet ds, Janet key, int is_interpreter);
|
||||
#else
|
||||
#define JANET_CORE_REG JANET_REG_
|
||||
#define JANET_CORE_FN JANET_FN_
|
||||
#define JANET_CORE_DEF JANET_DEF_
|
||||
void janet_core_def(JanetTable *env, const char *name, Janet x, const void *p);
|
||||
void janet_core_cfuns(JanetTable *env, const char *regprefix, const JanetReg *cfuns);
|
||||
void janet_core_def_sm(JanetTable *env, const char *name, Janet x, const void *p, const void *sf, int32_t sl);
|
||||
|
@ -1766,18 +1766,24 @@ JANET_API Janet janet_resolve_core(const char *name);
|
||||
#define JANET_REG_(JNAME, CNAME) {JNAME, CNAME, NULL, NULL, 0}
|
||||
#define JANET_FN_(CNAME, USAGE, DOCSTRING) \
|
||||
static Janet CNAME (int32_t argc, Janet *argv)
|
||||
#define JANET_DEF_(ENV, JNAME, VAL, DOC) \
|
||||
janet_def(ENV, JNAME, VAL, NULL)
|
||||
|
||||
/* sourcemaps only */
|
||||
#define JANET_REG_S(JNAME, CNAME) {JNAME, CNAME, NULL, __FILE__, CNAME##_sourceline_}
|
||||
#define JANET_FN_S(CNAME, USAGE, DOCSTRING) \
|
||||
static int32_t CNAME##_sourceline_ = __LINE__; \
|
||||
static Janet CNAME (int32_t argc, Janet *argv)
|
||||
#define JANET_DEF_S(ENV, JNAME, VAL, DOC) \
|
||||
janet_def_sm(ENV, JNAME, VAL, NULL, __FILE__, __LINE__)
|
||||
|
||||
/* docstring only */
|
||||
#define JANET_REG_D(JNAME, CNAME) {JNAME, CNAME, CNAME##_docstring_, NULL, 0}
|
||||
#define JANET_FN_D(CNAME, USAGE, DOCSTRING) \
|
||||
static const char CNAME##_docstring_[] = USAGE "\n\n" DOCSTRING; \
|
||||
static Janet CNAME (int32_t argc, Janet *argv)
|
||||
#define JANET_DEF_D(ENV, JNAME, VAL, DOC) \
|
||||
janet_def(ENV, JNAME, VAL, DOC)
|
||||
|
||||
/* sourcemaps and docstrings */
|
||||
#define JANET_REG_SD(JNAME, CNAME) {JNAME, CNAME, CNAME##_docstring_, __FILE__, CNAME##_sourceline_}
|
||||
@ -1785,20 +1791,26 @@ JANET_API Janet janet_resolve_core(const char *name);
|
||||
static int32_t CNAME##_sourceline_ = __LINE__; \
|
||||
static const char CNAME##_docstring_[] = USAGE "\n\n" DOCSTRING; \
|
||||
static Janet CNAME (int32_t argc, Janet *argv)
|
||||
#define JANET_DEF_SD(ENV, JNAME, VAL, DOC) \
|
||||
janet_def_sm(ENV, JNAME, VAL, DOC, __FILE__, __LINE__)
|
||||
|
||||
/* Choose defaults for source mapping and docstring based on config defs */
|
||||
#if defined(JANET_NO_SOURCEMAPS) && defined(JANET_NO_DOCSTRINGS)
|
||||
#define JANET_REG JANET_REG_
|
||||
#define JANET_FN JANET_FN_
|
||||
#define JANET_DEF JANET_DEF_
|
||||
#elif defined(JANET_NO_SOURCEMAPS) && !defined(JANET_NO_DOCSTRINGS)
|
||||
#define JANET_REG JANET_REG_D
|
||||
#define JANET_FN JANET_FN_D
|
||||
#define JANET_DEF JANET_DEF_D
|
||||
#elif !defined(JANET_NO_SOURCEMAPS) && defined(JANET_NO_DOCSTRINGS)
|
||||
#define JANET_REG JANET_REG_S
|
||||
#define JANET_FN JANET_FN_S
|
||||
#define JANET_DEF JANET_DEF_S
|
||||
#elif !defined(JANET_NO_SOURCEMAPS) && !defined(JANET_NO_DOCSTRINGS)
|
||||
#define JANET_REG JANET_REG_SD
|
||||
#define JANET_FN JANET_FN_SD
|
||||
#define JANET_DEF JANET_DEF_SD
|
||||
#endif
|
||||
|
||||
/* Define things with source mapping information */
|
||||
|
Loading…
Reference in New Issue
Block a user