diff --git a/mkfile b/mkfile new file mode 100644 index 00000000..0996aaf6 --- /dev/null +++ b/mkfile @@ -0,0 +1,58 @@ +$target + +build/c/shell.c: src/mainclient/shell.c + cp $prereq $target + + +build/janet.$O: build/c/janet.c src/conf/janetconf.h src/include/janet.h + $CC $CFLAGS -D^$JANET_CONFIG -o $target $prereq(1) + +build/shell.$O: src/mainclient/shell.c src/conf/janetconf.h src/include/janet.h + $CC $CFLAGS -D^$JANET_CONFIG -o $target $prereq(1) + + #include +#ifndef JANET_PLAN9 #include +#endif #include #endif @@ -113,7 +115,7 @@ static void *makef(FILE *f, int32_t flags) { JanetFile *iof = (JanetFile *) janet_abstract(&janet_file_type, sizeof(JanetFile)); iof->file = f; iof->flags = flags; -#ifndef JANET_WINDOWS +#if !(defined(JANET_WINDOWS) || defined(JANET_PLAN9)) /* While we would like fopen to set cloexec by default (like O_CLOEXEC) with the e flag, that is * not standard. */ if (!(flags & JANET_FILE_NOT_CLOSEABLE)) diff --git a/src/core/math.c b/src/core/math.c index 400ed7e4..4aa22a9f 100644 --- a/src/core/math.c +++ b/src/core/math.c @@ -271,28 +271,30 @@ JANET_DEFINE_MATHOP(cosh, "Returns the hyperbolic cosine of x.") JANET_DEFINE_MATHOP(acosh, "Returns the hyperbolic arccosine of x.") JANET_DEFINE_MATHOP(sin, "Returns the sine of x.") JANET_DEFINE_MATHOP(sinh, "Returns the hyperbolic sine of x.") -JANET_DEFINE_MATHOP(asinh, "Returns the hyperbolic arcsine of x.") JANET_DEFINE_MATHOP(tan, "Returns the tangent of x.") JANET_DEFINE_MATHOP(tanh, "Returns the hyperbolic tangent of x.") -JANET_DEFINE_MATHOP(atanh, "Returns the hyperbolic arctangent of x.") JANET_DEFINE_MATHOP(exp, "Returns e to the power of x.") JANET_DEFINE_MATHOP(exp2, "Returns 2 to the power of x.") +JANET_DEFINE_MATHOP(log1p, "Returns (log base e of x) + 1 more accurately than (+ (math/log x) 1)") +#ifndef JANET_PLAN9 JANET_DEFINE_MATHOP(expm1, "Returns e to the power of x minus 1.") +JANET_DEFINE_MATHOP(cbrt, "Returns the cube root of x.") +JANET_DEFINE_MATHOP(erf, "Returns the error function of x.") +JANET_DEFINE_MATHOP(erfc, "Returns the complementary error function of x.") +JANET_DEFINE_NAMED_MATHOP("log-gamma", lgamma, "Returns log-gamma(x).") +JANET_DEFINE_NAMED_MATHOP("gamma", tgamma, "Returns gamma(x).") +JANET_DEFINE_MATHOP(atanh, "Returns the hyperbolic arctangent of x.") +JANET_DEFINE_MATHOP(asinh, "Returns the hyperbolic arcsine of x.") +#endif JANET_DEFINE_MATHOP(log, "Returns the natural logarithm of x.") JANET_DEFINE_MATHOP(log10, "Returns the log base 10 of x.") JANET_DEFINE_MATHOP(log2, "Returns the log base 2 of x.") JANET_DEFINE_MATHOP(sqrt, "Returns the square root of x.") -JANET_DEFINE_MATHOP(cbrt, "Returns the cube root of x.") JANET_DEFINE_MATHOP(ceil, "Returns the smallest integer value number that is not less than x.") JANET_DEFINE_MATHOP(floor, "Returns the largest integer value number that is not greater than x.") JANET_DEFINE_MATHOP(trunc, "Returns the integer between x and 0 nearest to x.") JANET_DEFINE_MATHOP(round, "Returns the integer nearest to x.") -JANET_DEFINE_MATHOP(log1p, "Returns (log base e of x) + 1 more accurately than (+ (math/log x) 1)") -JANET_DEFINE_MATHOP(erf, "Returns the error function of x.") -JANET_DEFINE_MATHOP(erfc, "Returns the complementary error function of x.") -JANET_DEFINE_NAMED_MATHOP("log-gamma", lgamma, "Returns log-gamma(x).") JANET_DEFINE_NAMED_MATHOP("abs", fabs, "Return the absolute value of x.") -JANET_DEFINE_NAMED_MATHOP("gamma", tgamma, "Returns gamma(x).") #define JANET_DEFINE_MATH2OP(name, fop, signature, doc)\ JANET_CORE_FN(janet_##name, signature, doc) {\ @@ -305,7 +307,9 @@ JANET_CORE_FN(janet_##name, signature, doc) {\ JANET_DEFINE_MATH2OP(atan2, atan2, "(math/atan2 y x)", "Returns the arctangent of y/x. Works even when x is 0.") JANET_DEFINE_MATH2OP(pow, pow, "(math/pow a x)", "Returns a to the power of x.") JANET_DEFINE_MATH2OP(hypot, hypot, "(math/hypot a b)", "Returns c from the equation c^2 = a^2 + b^2.") +#ifndef JANET_PLAN9 JANET_DEFINE_MATH2OP(nextafter, nextafter, "(math/next x y)", "Returns the next representable floating point value after x in the direction of y.") +#endif JANET_CORE_FN(janet_not, "(not x)", "Returns the boolean inverse of x.") { janet_fixarity(argc, 1); @@ -386,7 +390,17 @@ void janet_lib_math(JanetTable *env) { JANET_CORE_REG("math/log10", janet_log10), JANET_CORE_REG("math/log2", janet_log2), JANET_CORE_REG("math/sqrt", janet_sqrt), +#ifndef JANET_PLAN9 JANET_CORE_REG("math/cbrt", janet_cbrt), + JANET_CORE_REG("math/gamma", janet_tgamma), + JANET_CORE_REG("math/log-gamma", janet_lgamma), + JANET_CORE_REG("math/erfc", janet_erfc), + JANET_CORE_REG("math/erf", janet_erf), + JANET_CORE_REG("math/expm1", janet_expm1), + JANET_CORE_REG("math/atanh", janet_atanh), + JANET_CORE_REG("math/asinh", janet_asinh), + JANET_CORE_REG("math/next", janet_nextafter), +#endif JANET_CORE_REG("math/floor", janet_floor), JANET_CORE_REG("math/ceil", janet_ceil), JANET_CORE_REG("math/pow", janet_pow), @@ -394,8 +408,6 @@ void janet_lib_math(JanetTable *env) { JANET_CORE_REG("math/sinh", janet_sinh), JANET_CORE_REG("math/cosh", janet_cosh), JANET_CORE_REG("math/tanh", janet_tanh), - JANET_CORE_REG("math/atanh", janet_atanh), - JANET_CORE_REG("math/asinh", janet_asinh), JANET_CORE_REG("math/acosh", janet_acosh), JANET_CORE_REG("math/atan2", janet_atan2), JANET_CORE_REG("math/rng", cfun_rng_make), @@ -405,14 +417,8 @@ void janet_lib_math(JanetTable *env) { JANET_CORE_REG("math/hypot", janet_hypot), JANET_CORE_REG("math/exp2", janet_exp2), JANET_CORE_REG("math/log1p", janet_log1p), - JANET_CORE_REG("math/gamma", janet_tgamma), - JANET_CORE_REG("math/log-gamma", janet_lgamma), - JANET_CORE_REG("math/erfc", janet_erfc), - JANET_CORE_REG("math/erf", janet_erf), - JANET_CORE_REG("math/expm1", janet_expm1), JANET_CORE_REG("math/trunc", janet_trunc), JANET_CORE_REG("math/round", janet_round), - JANET_CORE_REG("math/next", janet_nextafter), JANET_CORE_REG("math/gcd", janet_cfun_gcd), JANET_CORE_REG("math/lcm", janet_cfun_lcm), JANET_CORE_REG("math/frexp", janet_cfun_frexp), diff --git a/src/core/os.c b/src/core/os.c index 5d86c291..66140c41 100644 --- a/src/core/os.c +++ b/src/core/os.c @@ -277,7 +277,11 @@ JANET_CORE_FN(os_exit, } janet_deinit(); if (argc >= 2 && janet_truthy(argv[1])) { +#ifdef JANET_PLAN9 + exit(status); +#else _Exit(status); +#endif } else { exit(status); } diff --git a/src/core/parse.c b/src/core/parse.c index 5b5ffff8..a9695220 100644 --- a/src/core/parse.c +++ b/src/core/parse.c @@ -105,15 +105,6 @@ static int to_hex(uint8_t c) { } } -typedef int (*Consumer)(JanetParser *p, JanetParseState *state, uint8_t c); -struct JanetParseState { - int32_t counter; - int32_t argn; - int flags; - size_t line; - size_t column; - Consumer consumer; -}; /* Define a stack on the main parser struct */ #define DEF_PARSER_STACK(NAME, T, STACK, STACKCOUNT, STACKCAP) \ diff --git a/src/core/pp.c b/src/core/pp.c index 3b000f41..888d3e61 100644 --- a/src/core/pp.c +++ b/src/core/pp.c @@ -794,7 +794,9 @@ static const char *get_fmt_mapping(char c) { if (format_mappings[i].c == c) return format_mappings[i].mapping; } +#ifndef JANET_PLAN9 janet_assert(0, "bad format mapping"); +#endif } static const char *scanformat( diff --git a/src/core/util.h b/src/core/util.h index 4e16f5e0..be1e2a05 100644 --- a/src/core/util.h +++ b/src/core/util.h @@ -167,7 +167,11 @@ typedef void *Clib; #endif char *get_processed_name(const char *name); +#ifdef JANET_PLAN9 +#define RETRY_EINTR(RC, CALL) (RC) = CALL; +#else #define RETRY_EINTR(RC, CALL) do { (RC) = CALL; } while((RC) < 0 && errno == EINTR) +#endif /* Initialize builtin libraries */ void janet_lib_io(JanetTable *env); diff --git a/src/include/janet.h b/src/include/janet.h index b99d547a..4b47a7ae 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -113,6 +113,8 @@ extern "C" { #endif /* Check 64-bit vs 32-bit */ +#ifndef JANET_64 +#ifndef JANET_32 #if ((defined(__x86_64__) || defined(_M_X64)) \ && (defined(JANET_POSIX) || defined(JANET_WINDOWS))) \ || (defined(_WIN64)) /* Windows 64 bit */ \ @@ -128,6 +130,8 @@ extern "C" { #else #define JANET_32 1 #endif +#endif +#endif /* Check big endian */ #if defined(__LITTLE_ENDIAN__) || \ @@ -301,6 +305,10 @@ extern "C" { #define JANET_STACK_MAX 0x7fffffff #endif +#ifdef JANET_PLAN9 +#undef NAN +#endif + /* Use nanboxed values - uses 8 bytes per value instead of 12 or 16. * To turn of nanboxing, for debugging purposes or for certain * architectures (Nanboxing only tested on x86 and x64), comment out @@ -667,6 +675,8 @@ JANET_API void janet_stream_level_triggered(JanetStream *stream); * signals. Define them here */ #ifdef JANET_WINDOWS typedef long JanetAtomicInt; +#elif defined(JANET_PLAN9) +typedef long JanetAtomicInt; #else typedef int32_t JanetAtomicInt; #endif @@ -1138,6 +1148,17 @@ struct JanetFunction { typedef struct JanetParseState JanetParseState; typedef struct JanetParser JanetParser; +typedef int (*Consumer)(JanetParser *p, JanetParseState *state, uint8_t c); + +struct JanetParseState { + int32_t counter; + int32_t argn; + int flags; + size_t line; + size_t column; + Consumer consumer; +}; + enum JanetParserStatus { JANET_PARSE_ROOT, JANET_PARSE_ERROR, diff --git a/src/mainclient/shell.c b/src/mainclient/shell.c index 2b36375b..93546db2 100644 --- a/src/mainclient/shell.c +++ b/src/mainclient/shell.c @@ -79,9 +79,11 @@ static void simpleline(JanetBuffer *buffer) { int c; for (;;) { c = fgetc(in); +#ifndef JANET_PLAN9 if (c < 0 && !feof(in) && errno == EINTR) { continue; } +#endif if (feof(in) || c < 0) { break; }