Skip to content

Commit 2f69678

Browse files
author
Noam Preil
committed
9front port
1 parent efe66f2 commit 2f69678

File tree

12 files changed

+128
-26
lines changed

12 files changed

+128
-26
lines changed

mkfile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
</$objtype/mkfile
2+
3+
TARG=janet
4+
HFILES=src/include/janet.h src/conf/janetconf.h
5+
JANET_PATH=/sys/lib/janet
6+
BIN=/$objtype/bin/
7+
JANET_CONFIG=JANET_SINGLE_THREADED JANET_NO_DYNAMIC_MODULES JANET_NO_THREADS JANET_OS_NAME=9front JANET_ARCH_NAME=$objtype JANET_BUILD="9front" JANET_API='' JANET_NO_RETURN='' JANET_NO_EV JANET_NO_REALPATH JANET_NO_UTC_MKTIME JANET_SIMPLE_GETLINE JANET_NO_FFI JANET_REDUCED_OS JANET_64 JANET_NO_ASSEMBLER
8+
CFLAGS=-FTVBNcwp -D _POSIX_SOURCE -DJANET_PLAN9 -D_BSD_EXTENSION -D_LIMITS_EXTENSION -Isrc/include -Isrc/conf -I/sys/include/npe -Dtypestr=janettypestr -DJANET_API `{echo '-D'^$JANET_CONFIG}
9+
BOOT_CFLAGS=$CFLAGS -DJANET_BOOTSTRAP
10+
CLEANFILES=`{ls build/c/* build/boot/* build/core/*}y
11+
12+
list:
13+
echo $CFLAGS
14+
15+
JANET_CORE_HEADERS=`{ls src/core/*.h}
16+
JANET_CORE_SOURCES=`{ls src/core/*.c}
17+
18+
JANET_BOOT_SOURCES=src/boot/array_test.c \
19+
src/boot/boot.c \
20+
src/boot/buffer_test.c \
21+
src/boot/number_test.c \
22+
src/boot/system_test.c \
23+
src/boot/table_test.c
24+
JANET_BOOT_HEADERS=src/boot/tests.h
25+
JANET_BOOT_OBJECTS=`{echo $JANET_CORE_SOURCES $JANET_BOOT_SOURCES | sed -e 's/\.c/.boot.o/g' -e 's$src/$build/$g'}
26+
27+
OFILES=build/janet.$O build/shell.$O
28+
29+
build/%.boot.o: src/%.c $JANET_HEADERS $JANET_CORE_HEADERS $JANET_BOOT_HEADERS
30+
$CC $BOOT_CFLAGS -o $target $prereq(1)
31+
32+
build/core/%.$O: build/core
33+
34+
build/core:
35+
mkdir -p build/core
36+
37+
build/boot/%.$O: build/boot
38+
39+
build/boot:
40+
mkdir -p build/boot
41+
42+
build/boot/$O.janet: $JANET_BOOT_OBJECTS
43+
$LD $LDFLAGS -o $target $prereq
44+
45+
build/c/janet.c: build/boot/$O.janet src/boot/boot.janet
46+
build/boot/$O.janet . JANET_PATH $JANET_PATH >$target
47+
48+
build/c/shell.c: src/mainclient/shell.c
49+
cp $prereq $target
50+
51+
52+
build/janet.$O: build/c/janet.c src/conf/janetconf.h src/include/janet.h
53+
$CC $CFLAGS -D^$JANET_CONFIG -o $target $prereq(1)
54+
55+
build/shell.$O: src/mainclient/shell.c src/conf/janetconf.h src/include/janet.h
56+
$CC $CFLAGS -D^$JANET_CONFIG -o $target $prereq(1)
57+
58+
</sys/src/cmd/mkone

src/boot/number_test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static void test_valid_str(const char *str) {
4545

4646
int number_test() {
4747

48+
#ifndef JANET_PLAN9
4849
test_valid_str("1.0");
4950
test_valid_str("1");
5051
test_valid_str("2.1");
@@ -62,6 +63,7 @@ int number_test() {
6263
test_valid_str("123123123123123123132123");
6364
test_valid_str("0000000011111111111111111111111111");
6465
test_valid_str(".112312333333323123123123123123123");
66+
#endif
6567

6668
return 0;
6769
}

src/boot/system_test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ int system_test() {
5151
assert(janet_equals(janet_wrap_number(1.4), janet_wrap_number(1.4)));
5252
assert(janet_equals(janet_wrap_number(3.14159265), janet_wrap_number(3.14159265)));
5353
#ifdef NAN
54+
#ifndef JANET_PLAN9
5455
assert(janet_checktype(janet_wrap_number(NAN), JANET_NUMBER));
56+
#endif
5557
#else
5658
assert(janet_checktype(janet_wrap_number(0.0 / 0.0), JANET_NUMBER));
5759
#endif

src/core/capi.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ JanetAtomicInt janet_atomic_inc(JanetAtomicInt volatile *x) {
564564
return _InterlockedIncrement(x);
565565
#elif defined(JANET_USE_STDATOMIC)
566566
return atomic_fetch_add_explicit(x, 1, memory_order_relaxed) + 1;
567+
#elif defined(JANET_PLAN9)
568+
return aincl((void*)x, 1);
567569
#else
568570
return __atomic_add_fetch(x, 1, __ATOMIC_RELAXED);
569571
#endif
@@ -574,6 +576,8 @@ JanetAtomicInt janet_atomic_dec(JanetAtomicInt volatile *x) {
574576
return _InterlockedDecrement(x);
575577
#elif defined(JANET_USE_STDATOMIC)
576578
return atomic_fetch_add_explicit(x, -1, memory_order_acq_rel) - 1;
579+
#elif defined(JANET_PLAN9)
580+
return aincl((void*)x, -1);
577581
#else
578582
return __atomic_add_fetch(x, -1, __ATOMIC_ACQ_REL);
579583
#endif
@@ -582,6 +586,8 @@ JanetAtomicInt janet_atomic_dec(JanetAtomicInt volatile *x) {
582586
JanetAtomicInt janet_atomic_load(JanetAtomicInt volatile *x) {
583587
#ifdef _MSC_VER
584588
return _InterlockedOr(x, 0);
589+
#elif defined(JANET_PLAN9)
590+
return agetl((void*)x);
585591
#elif defined(JANET_USE_STDATOMIC)
586592
return atomic_load_explicit(x, memory_order_acquire);
587593
#else
@@ -592,6 +598,8 @@ JanetAtomicInt janet_atomic_load(JanetAtomicInt volatile *x) {
592598
JanetAtomicInt janet_atomic_load_relaxed(JanetAtomicInt volatile *x) {
593599
#ifdef _MSC_VER
594600
return _InterlockedOr(x, 0);
601+
#elif defined(JANET_PLAN9)
602+
return agetl((void*)x);
595603
#elif defined(JANET_USE_STDATOMIC)
596604
return atomic_load_explicit(x, memory_order_relaxed);
597605
#else

src/core/io.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
#ifndef JANET_WINDOWS
3333
#include <fcntl.h>
3434
#include <sys/stat.h>
35+
#ifndef JANET_PLAN9
3536
#include <sys/wait.h>
37+
#endif
3638
#include <unistd.h>
3739
#endif
3840

@@ -113,7 +115,7 @@ static void *makef(FILE *f, int32_t flags) {
113115
JanetFile *iof = (JanetFile *) janet_abstract(&janet_file_type, sizeof(JanetFile));
114116
iof->file = f;
115117
iof->flags = flags;
116-
#ifndef JANET_WINDOWS
118+
#if !(defined(JANET_WINDOWS) || defined(JANET_PLAN9))
117119
/* While we would like fopen to set cloexec by default (like O_CLOEXEC) with the e flag, that is
118120
* not standard. */
119121
if (!(flags & JANET_FILE_NOT_CLOSEABLE))

src/core/math.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -271,28 +271,30 @@ JANET_DEFINE_MATHOP(cosh, "Returns the hyperbolic cosine of x.")
271271
JANET_DEFINE_MATHOP(acosh, "Returns the hyperbolic arccosine of x.")
272272
JANET_DEFINE_MATHOP(sin, "Returns the sine of x.")
273273
JANET_DEFINE_MATHOP(sinh, "Returns the hyperbolic sine of x.")
274-
JANET_DEFINE_MATHOP(asinh, "Returns the hyperbolic arcsine of x.")
275274
JANET_DEFINE_MATHOP(tan, "Returns the tangent of x.")
276275
JANET_DEFINE_MATHOP(tanh, "Returns the hyperbolic tangent of x.")
277-
JANET_DEFINE_MATHOP(atanh, "Returns the hyperbolic arctangent of x.")
278276
JANET_DEFINE_MATHOP(exp, "Returns e to the power of x.")
279277
JANET_DEFINE_MATHOP(exp2, "Returns 2 to the power of x.")
278+
JANET_DEFINE_MATHOP(log1p, "Returns (log base e of x) + 1 more accurately than (+ (math/log x) 1)")
279+
#ifndef JANET_PLAN9
280280
JANET_DEFINE_MATHOP(expm1, "Returns e to the power of x minus 1.")
281+
JANET_DEFINE_MATHOP(cbrt, "Returns the cube root of x.")
282+
JANET_DEFINE_MATHOP(erf, "Returns the error function of x.")
283+
JANET_DEFINE_MATHOP(erfc, "Returns the complementary error function of x.")
284+
JANET_DEFINE_NAMED_MATHOP("log-gamma", lgamma, "Returns log-gamma(x).")
285+
JANET_DEFINE_NAMED_MATHOP("gamma", tgamma, "Returns gamma(x).")
286+
JANET_DEFINE_MATHOP(atanh, "Returns the hyperbolic arctangent of x.")
287+
JANET_DEFINE_MATHOP(asinh, "Returns the hyperbolic arcsine of x.")
288+
#endif
281289
JANET_DEFINE_MATHOP(log, "Returns the natural logarithm of x.")
282290
JANET_DEFINE_MATHOP(log10, "Returns the log base 10 of x.")
283291
JANET_DEFINE_MATHOP(log2, "Returns the log base 2 of x.")
284292
JANET_DEFINE_MATHOP(sqrt, "Returns the square root of x.")
285-
JANET_DEFINE_MATHOP(cbrt, "Returns the cube root of x.")
286293
JANET_DEFINE_MATHOP(ceil, "Returns the smallest integer value number that is not less than x.")
287294
JANET_DEFINE_MATHOP(floor, "Returns the largest integer value number that is not greater than x.")
288295
JANET_DEFINE_MATHOP(trunc, "Returns the integer between x and 0 nearest to x.")
289296
JANET_DEFINE_MATHOP(round, "Returns the integer nearest to x.")
290-
JANET_DEFINE_MATHOP(log1p, "Returns (log base e of x) + 1 more accurately than (+ (math/log x) 1)")
291-
JANET_DEFINE_MATHOP(erf, "Returns the error function of x.")
292-
JANET_DEFINE_MATHOP(erfc, "Returns the complementary error function of x.")
293-
JANET_DEFINE_NAMED_MATHOP("log-gamma", lgamma, "Returns log-gamma(x).")
294297
JANET_DEFINE_NAMED_MATHOP("abs", fabs, "Return the absolute value of x.")
295-
JANET_DEFINE_NAMED_MATHOP("gamma", tgamma, "Returns gamma(x).")
296298

297299
#define JANET_DEFINE_MATH2OP(name, fop, signature, doc)\
298300
JANET_CORE_FN(janet_##name, signature, doc) {\
@@ -305,7 +307,9 @@ JANET_CORE_FN(janet_##name, signature, doc) {\
305307
JANET_DEFINE_MATH2OP(atan2, atan2, "(math/atan2 y x)", "Returns the arctangent of y/x. Works even when x is 0.")
306308
JANET_DEFINE_MATH2OP(pow, pow, "(math/pow a x)", "Returns a to the power of x.")
307309
JANET_DEFINE_MATH2OP(hypot, hypot, "(math/hypot a b)", "Returns c from the equation c^2 = a^2 + b^2.")
310+
#ifndef JANET_PLAN9
308311
JANET_DEFINE_MATH2OP(nextafter, nextafter, "(math/next x y)", "Returns the next representable floating point value after x in the direction of y.")
312+
#endif
309313

310314
JANET_CORE_FN(janet_not, "(not x)", "Returns the boolean inverse of x.") {
311315
janet_fixarity(argc, 1);
@@ -386,16 +390,24 @@ void janet_lib_math(JanetTable *env) {
386390
JANET_CORE_REG("math/log10", janet_log10),
387391
JANET_CORE_REG("math/log2", janet_log2),
388392
JANET_CORE_REG("math/sqrt", janet_sqrt),
393+
#ifndef JANET_PLAN9
389394
JANET_CORE_REG("math/cbrt", janet_cbrt),
395+
JANET_CORE_REG("math/gamma", janet_tgamma),
396+
JANET_CORE_REG("math/log-gamma", janet_lgamma),
397+
JANET_CORE_REG("math/erfc", janet_erfc),
398+
JANET_CORE_REG("math/erf", janet_erf),
399+
JANET_CORE_REG("math/expm1", janet_expm1),
400+
JANET_CORE_REG("math/atanh", janet_atanh),
401+
JANET_CORE_REG("math/asinh", janet_asinh),
402+
JANET_CORE_REG("math/next", janet_nextafter),
403+
#endif
390404
JANET_CORE_REG("math/floor", janet_floor),
391405
JANET_CORE_REG("math/ceil", janet_ceil),
392406
JANET_CORE_REG("math/pow", janet_pow),
393407
JANET_CORE_REG("math/abs", janet_fabs),
394408
JANET_CORE_REG("math/sinh", janet_sinh),
395409
JANET_CORE_REG("math/cosh", janet_cosh),
396410
JANET_CORE_REG("math/tanh", janet_tanh),
397-
JANET_CORE_REG("math/atanh", janet_atanh),
398-
JANET_CORE_REG("math/asinh", janet_asinh),
399411
JANET_CORE_REG("math/acosh", janet_acosh),
400412
JANET_CORE_REG("math/atan2", janet_atan2),
401413
JANET_CORE_REG("math/rng", cfun_rng_make),
@@ -405,14 +417,8 @@ void janet_lib_math(JanetTable *env) {
405417
JANET_CORE_REG("math/hypot", janet_hypot),
406418
JANET_CORE_REG("math/exp2", janet_exp2),
407419
JANET_CORE_REG("math/log1p", janet_log1p),
408-
JANET_CORE_REG("math/gamma", janet_tgamma),
409-
JANET_CORE_REG("math/log-gamma", janet_lgamma),
410-
JANET_CORE_REG("math/erfc", janet_erfc),
411-
JANET_CORE_REG("math/erf", janet_erf),
412-
JANET_CORE_REG("math/expm1", janet_expm1),
413420
JANET_CORE_REG("math/trunc", janet_trunc),
414421
JANET_CORE_REG("math/round", janet_round),
415-
JANET_CORE_REG("math/next", janet_nextafter),
416422
JANET_CORE_REG("math/gcd", janet_cfun_gcd),
417423
JANET_CORE_REG("math/lcm", janet_cfun_lcm),
418424
JANET_CORE_REG("math/frexp", janet_cfun_frexp),

src/core/os.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ JANET_CORE_FN(os_exit,
277277
}
278278
janet_deinit();
279279
if (argc >= 2 && janet_truthy(argv[1])) {
280+
#ifdef JANET_PLAN9
281+
exit(status);
282+
#else
280283
_Exit(status);
284+
#endif
281285
} else {
282286
exit(status);
283287
}

src/core/parse.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,6 @@ static int to_hex(uint8_t c) {
105105
}
106106
}
107107

108-
typedef int (*Consumer)(JanetParser *p, JanetParseState *state, uint8_t c);
109-
struct JanetParseState {
110-
int32_t counter;
111-
int32_t argn;
112-
int flags;
113-
size_t line;
114-
size_t column;
115-
Consumer consumer;
116-
};
117108

118109
/* Define a stack on the main parser struct */
119110
#define DEF_PARSER_STACK(NAME, T, STACK, STACKCOUNT, STACKCAP) \

src/core/pp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,9 @@ static const char *get_fmt_mapping(char c) {
794794
if (format_mappings[i].c == c)
795795
return format_mappings[i].mapping;
796796
}
797+
#ifndef JANET_PLAN9
797798
janet_assert(0, "bad format mapping");
799+
#endif
798800
}
799801

800802
static const char *scanformat(

src/core/util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,11 @@ typedef void *Clib;
167167
#endif
168168
char *get_processed_name(const char *name);
169169

170+
#ifdef JANET_PLAN9
171+
#define RETRY_EINTR(RC, CALL) (RC) = CALL;
172+
#else
170173
#define RETRY_EINTR(RC, CALL) do { (RC) = CALL; } while((RC) < 0 && errno == EINTR)
174+
#endif
171175

172176
/* Initialize builtin libraries */
173177
void janet_lib_io(JanetTable *env);

0 commit comments

Comments
 (0)