shithub: femtolisp

Download patch

ref: d606029959d901ba4db77fd8754f45f97cdec499
parent: ebc07a3b8f4ab9bc0e0eb44f1797461bc616f455
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Mar 9 15:35:16 EST 2023

more fixes

--- a/builtins.c
+++ b/builtins.c
@@ -2,7 +2,7 @@
   Extra femtoLisp builtin functions
 */
 
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #define exit(x) exits(x ? "error" : nil)
@@ -29,6 +29,7 @@
 #include <errno.h>
 #include <math.h>
 #endif
+
 #include "llt.h"
 #include "flisp.h"
 #include "random.h"
@@ -380,7 +381,7 @@
 {
     argcount("path.exists?", nargs, 1);
     char *str = tostring(args[0], "path.exists?");
-#ifdef __plan9__
+#ifdef PLAN9
     if (access(str, 0) != 0)
         return FL_F;
 #else
@@ -410,7 +411,7 @@
     if (args[1] == FL_F) {
 #ifdef LINUX
         result = unsetenv(name);
-#elif defined(__plan9__)
+#elif defined(PLAN9)
         result = putenv(name, "");
 #else
         (void)unsetenv(name);
@@ -419,7 +420,7 @@
     }
     else {
         char *val = tostring(args[1], "os.setenv");
-#ifdef __plan9__
+#ifdef PLAN9
         result = putenv(name, val);
 #else
         result = setenv(name, val, 1);
--- a/cvalues.c
+++ b/cvalues.c
@@ -307,7 +307,7 @@
 num_ctor(uint64, uint64, T_UINT64)
 num_ctor(byte,  uint8, T_UINT8)
 num_ctor(wchar, int32, T_INT32)
-#if defined(BITS64) && !defined(__plan9__)
+#if defined(ULONG64)
 num_ctor(long, int64, T_INT64)
 num_ctor(ulong, uint64, T_UINT64)
 #else
@@ -553,7 +553,7 @@
         return 8;
     }
     if (type == longsym || type == ulongsym) {
-#if defined(BITS64) && !defined(__plan9__)
+#if defined(ULONG64)
         *palign = ALIGN8;
         return 8;
 #else
@@ -740,25 +740,25 @@
         return T_INT16;
     else if (type == uint16sym)
         return T_UINT16;
-#if defined(BITS64) && !defined(__plan9__)
+#if defined(ULONG64)
     else if (type == int32sym || type == wcharsym)
 #else
     else if (type == int32sym || type == wcharsym || type == longsym)
 #endif
         return T_INT32;
-#if defined(BITS64) && !defined(__plan9__)
+#if defined(ULONG64)
     else if (type == uint32sym)
 #else
     else if (type == uint32sym || type == ulongsym)
 #endif
         return T_UINT32;
-#if defined(BITS64) && !defined(__plan9__)
+#if defined(ULONG64)
     else if (type == int64sym || type == longsym)
 #else
     else if (type == int64sym)
 #endif
         return T_INT64;
-#if defined(BITS64) && !defined(__plan9__)
+#if defined(ULONG64)
     else if (type == uint64sym || type == ulongsym)
 #else
     else if (type == uint64sym)
@@ -991,7 +991,7 @@
     mk_primtype(uint32);
     mk_primtype(int64);
     mk_primtype(uint64);
-#if defined(BITS64) && !defined(__plan9__)
+#if defined(ULONG64)
     mk_primtype_(long,int64);
     mk_primtype_(ulong,uint64);
 #else
@@ -1118,7 +1118,7 @@
     if (isfixnum(n)) {
         fixnum_t s = fixnum(-numval(n));
         if (__unlikely(s == n))
-            return mk_long(-numval(n)); // negate overflows
+            return mk_xlong(-numval(n));
         else
             return s;
     }
--- a/equalhash.c
+++ b/equalhash.c
@@ -1,4 +1,4 @@
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else
--- a/flisp.c
+++ b/flisp.c
@@ -29,7 +29,7 @@
   Distributed under the BSD License
 */
 
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #define vsnprintf vsnprint
@@ -149,11 +149,17 @@
   if (!setjmp(_ctx.buf)) \
     for (l__tr=1; l__tr; l__tr=0, (void)(fl_ctx=fl_ctx->prev))
 
+#define FL_CATCH_INC \
+  l__ca=0,fl_lasterror=FL_NIL,fl_throwing_frame=0,SP=_ctx.sp,curr_frame=_ctx.frame
+
 #define FL_CATCH \
   else \
-    for(l__ca=1; l__ca; l__ca=0, \
-      fl_lasterror=FL_NIL,fl_throwing_frame=0,SP=_ctx.sp,curr_frame=_ctx.frame)
+    for(l__ca=1; l__ca;FL_CATCH_INC)
 
+#define FL_CATCH_NO_INC \
+  else \
+    for(l__ca=1; l__ca;)
+
 void fl_savestate(fl_exception_context_t *_ctx)
 {
     _ctx->sp = SP;
@@ -1383,7 +1389,7 @@
                 if (fits_fixnum(s))
                     v = fixnum(s);
                 else
-                    v = mk_long(s);
+                    v = mk_xlong(s);
             }
             else {
                 v = fl_add_any(&Stack[SP-2], 2, 0);
@@ -1409,15 +1415,7 @@
             NEXT_OP;
         OP(OP_NEG)
         do_neg:
-            if (isfixnum(Stack[SP-1])) {
-                s = fixnum(-numval(Stack[SP-1]));
-                if (__unlikely(s == Stack[SP-1]))
-                  Stack[SP-1] = mk_long(-numval(Stack[SP-1])); // negate overflows
-                else
-                  Stack[SP-1] = s;
-            }
-            else
-                Stack[SP-1] = fl_neg(Stack[SP-1]);
+            Stack[SP-1] = fl_neg(Stack[SP-1]);
             NEXT_OP;
         OP(OP_SUB2)
         do_sub2:
@@ -1426,7 +1424,7 @@
                 if (fits_fixnum(s))
                     v = fixnum(s);
                 else
-                    v = mk_long(s);
+                    v = mk_xlong(s);
             }
             else {
                 Stack[SP-1] = fl_neg(Stack[SP-1]);
@@ -1815,8 +1813,6 @@
     }
 #ifdef USE_COMPUTED_GOTO
     return UNBOUND;  // not reached
-#else
-    goto dispatch;
 #endif
 }
 
@@ -2266,7 +2262,7 @@
     int i;
 
     llt_init();
-#ifndef __plan9__
+#ifndef PLAN9
     setlocale(LC_NUMERIC, "C");
 #endif
 
@@ -2339,7 +2335,7 @@
     set(symbol("*os-name*"), symbol("freebsd"));
 #elif defined(NETBSD)
     set(symbol("*os-name*"), symbol("netbsd"));
-#elif defined(__plan9__)
+#elif defined(PLAN9)
     set(symbol("*os-name*"), symbol("plan9"));
 #else
     set(symbol("*os-name*"), symbol("unknown"));
@@ -2411,7 +2407,7 @@
             }
         }
     }
-    FL_CATCH {
+    FL_CATCH_NO_INC {
         ios_puts("fatal error during bootstrap:\n", ios_stderr);
         fl_print(ios_stderr, fl_lasterror);
         ios_putc('\n', ios_stderr);
--- a/flisp.h
+++ b/flisp.h
@@ -1,7 +1,7 @@
 #ifndef FLISP_H
 #define FLISP_H
 
-#ifdef __plan9__
+#ifdef PLAN9
 #define __attribute__(...)
 #else
 #include <setjmp.h>
@@ -58,7 +58,7 @@
 #define tagptr(p,t) (((value_t)(p)) | (t))
 #define fixnum(x) ((value_t)(((fixnum_t)(x))<<2))
 #define numval(x)  (((fixnum_t)(x))>>2)
-#if defined(BITS64) && !defined(__plan9__)
+#if defined(BITS64)
 #define fits_fixnum(x) (((x)>>61) == 0 || (~((x)>>61)) == 0)
 #else
 #define fits_fixnum(x) (((x)>>29) == 0 || (~((x)>>29)) == 0)
@@ -188,6 +188,10 @@
   if (!setjmp(_ctx.buf))                                                \
     for (l__tr=1; l__tr; l__tr=0, (void)(fl_ctx=fl_ctx->prev))
 
+#define FL_CATCH_EXTERN_NO_RESTORE \
+  else \
+    for(l__ca=1; l__ca;)
+
 #define FL_CATCH_EXTERN \
   else \
     for(l__ca=1; l__ca; l__ca=0, fl_restorestate(&_ctx))
@@ -220,7 +224,7 @@
 
 #define N_NUMTYPES ((int)T_DOUBLE+1)
 
-#if defined(BITS64) && !defined(__plan9__)
+#if defined(ULONG64)
 # define T_LONG T_INT64
 # define T_ULONG T_UINT64
 #else
@@ -371,6 +375,12 @@
 value_t return_from_uint64(uint64_t Uaccum);
 value_t return_from_int64(int64_t Saccum);
 
+#ifdef BITS64
+#define mk_xlong mk_int64
+#else
+#define mk_xlong mk_long
+#endif
+
 numerictype_t effective_numerictype(double r);
 double conv_to_double(void *data, numerictype_t tag);
 void conv_from_double(void *data, double d, numerictype_t tag);
@@ -378,7 +388,7 @@
 uint64_t conv_to_uint64(void *data, numerictype_t tag);
 int32_t conv_to_int32(void *data, numerictype_t tag);
 uint32_t conv_to_uint32(void *data, numerictype_t tag);
-#if defined(BITS64) && !defined(__plan9__)
+#if defined(ULONG64)
 #define conv_to_long conv_to_int64
 #define conv_to_ulong conv_to_uint64
 #else
--- a/flmain.c
+++ b/flmain.c
@@ -1,4 +1,4 @@
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else
@@ -25,11 +25,12 @@
 
 extern value_t fl_file(value_t *args, uint32_t nargs);
 
-int main(int argc, char *argv[])
+int main(int argc, char **argv)
 {
     char fname_buf[1024];
 
-#ifdef __plan9__
+#ifdef PLAN9
+	argv0 = argv[0];
     setfcr(FPPDBL|FPRNR|FPOVFL);
     tmfmtinstall();
 #endif
@@ -64,7 +65,7 @@
         fl_applyn(1, symbol_value(symbol("__start")),
                   argv_list(argc, argv));
     }
-    FL_CATCH_EXTERN {
+    FL_CATCH_EXTERN_NO_RESTORE {
         ios_puts("fatal error:\n", ios_stderr);
         fl_print(ios_stderr, fl_lasterror);
         ios_putc('\n', ios_stderr);
--- a/iostream.c
+++ b/iostream.c
@@ -1,4 +1,4 @@
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else
--- a/llt/bitvector-ops.c
+++ b/llt/bitvector-ops.c
@@ -1,4 +1,4 @@
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else
--- a/llt/bitvector.c
+++ b/llt/bitvector.c
@@ -29,7 +29,7 @@
   and_to, or_to, and xor_to allow overlap.
 */
 
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else
--- a/llt/dirpath.c
+++ b/llt/dirpath.c
@@ -1,4 +1,4 @@
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else
@@ -32,7 +32,7 @@
 
 void get_cwd(char *buf, size_t size)
 {
-#ifdef __plan9__
+#ifdef PLAN9
     getwd(buf, size);
 #elif !defined(WIN32)
     getcwd(buf, size);
@@ -65,10 +65,10 @@
     }
 }
 
-#ifdef __plan9__
+#ifdef PLAN9
 char *get_exename(char *buf, size_t size)
 {
-    snprint(buf, size, "/sys/lib/flisp/flisp");
+    snprint(buf, size, argv0);
     return buf;
 }
 #elif defined(LINUX)
--- a/llt/dtypes.h
+++ b/llt/dtypes.h
@@ -29,11 +29,11 @@
 #  define NETBSD
 #elif defined(_WIN32)
 #  define WIN32
-#elif !defined(__plan9__)
+#elif !defined(PLAN9)
 #  error "unknown platform"
 #endif
 
-#if defined(OPENBSD) || defined(FREEBSD) || defined(NETBSD) || defined(__plan9__)
+#if defined(OPENBSD) || defined(FREEBSD) || defined(NETBSD) || defined(PLAN9)
 #if defined(__x86_64__) || defined(__amd64__) || defined(__arm64__)
 #  define __SIZEOF_POINTER__ 8
 #else
@@ -62,7 +62,7 @@
 #  else
 #    define DLLEXPORT __declspec(dllexport)
 #  endif
-#elif defined(__plan9__)
+#elif defined(PLAN9)
 #define STDCALL
 #define DLLEXPORT
 #else
@@ -83,7 +83,7 @@
 #  define __BIG_ENDIAN     BIG_ENDIAN
 #  define __PDP_ENDIAN     PDP_ENDIAN
 #  define __BYTE_ORDER     BYTE_ORDER
-#elif defined(WIN32) || defined(__plan9__)
+#elif defined(WIN32) || defined(PLAN9)
 #  define __LITTLE_ENDIAN	1234
 #  define __BIG_ENDIAN	4321
 #  define __PDP_ENDIAN	3412
@@ -113,9 +113,17 @@
 
 typedef int bool_t;
 
-#if defined(__plan9__)
-typedef ulong size_t;
+#if defined(BITS64)
+#define ULONG64
+#endif
+
+#ifdef PLAN9
+typedef usize size_t;
+#ifdef BITS64
+typedef long long ssize_t;
+#else
 typedef long ssize_t;
+#endif
 #define STATIC_INLINE static
 #define INLINE
 #ifndef NULL
@@ -134,8 +142,7 @@
 # define INLINE inline
 #endif
 
-typedef unsigned char  byte_t;   /* 1 byte */
-#if defined(__plan9__)
+#if defined(PLAN9)
 typedef s8int int8_t;
 typedef s16int int16_t;
 typedef s32int int32_t;
@@ -146,6 +153,8 @@
 typedef u32int u_int32_t;
 typedef u64int u_int64_t;
 typedef vlong off_t;
+typedef intptr intptr_t;
+typedef uintptr uintptr_t;
 #elif defined(WIN32)
 typedef short int16_t;
 typedef int int32_t;
@@ -162,18 +171,19 @@
 #else
 #include <sys/types.h>
 #endif
+typedef u_int8_t  byte_t;   /* 1 byte */
 
 #ifdef BITS64
-#define TOP_BIT 0x8000000000000000
+#define TOP_BIT 0x8000000000000000ULL
 #define NBITS 64
 typedef uint64_t uint_t;  // preferred int type on platform
 typedef int64_t int_t;
 typedef int64_t offset_t;
 typedef u_int64_t index_t;
-typedef int64_t ptrint_t; // pointer-size int
-typedef u_int64_t u_ptrint_t;
+typedef intptr_t ptrint_t; // pointer-size int
+typedef uintptr_t u_ptrint_t;
 #else
-#define TOP_BIT 0x80000000
+#define TOP_BIT 0x80000000UL
 #define NBITS 32
 typedef unsigned long uint_t;
 typedef long int_t;
@@ -205,11 +215,11 @@
 #define U64_MAX    18446744073709551615ULL
 #define S64_MAX    9223372036854775807LL
 #define S64_MIN    (-S64_MAX - 1LL)
-#define BIT63      0x8000000000000000LL
-#define U32_MAX    4294967295L
+#define BIT63      0x8000000000000000ULL
+#define U32_MAX    4294967295UL
 #define S32_MAX    2147483647L
 #define S32_MIN    (-S32_MAX - 1L)
-#define BIT31      0x80000000
+#define BIT31      0x80000000UL
 
 #ifndef DBL_EPSILON
 #define DBL_EPSILON      2.2204460492503131e-16
@@ -224,11 +234,10 @@
 
 #define LOG2_10          3.3219280948873626
 #define rel_zero(a, b) (fabs((a)/(b)) < DBL_EPSILON)
-#define sign_bit(r) ((*(int64_t*)&(r)) & BIT63)
+#define sign_bit(r) ((*(uint64_t*)&(r)) & BIT63)
 #define LABS(n) (((n)^((n)>>(NBITS-1))) - ((n)>>(NBITS-1)))
 #define NBABS(n,nb) (((n)^((n)>>((nb)-1))) - ((n)>>((nb)-1)))
-#define DFINITE(d) (((*(int64_t*)&(d))&0x7ff0000000000000LL)!=0x7ff0000000000000LL)
-#define DNAN(d) ((d)!=(d))
+#define DFINITE(d) (((*(uint64_t*)&(d))&0x7ff0000000000000ULL)!=0x7ff0000000000000ULL)
 
 extern double D_PNAN;
 extern double D_NNAN;
--- a/llt/dump.c
+++ b/llt/dump.c
@@ -1,4 +1,4 @@
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else
--- a/llt/hashing.c
+++ b/llt/hashing.c
@@ -1,7 +1,7 @@
 /*
   Hashing
 */
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else
--- a/llt/htable.c
+++ b/llt/htable.c
@@ -2,7 +2,7 @@
   functions common to all hash table instantiations
 */
 
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else
--- a/llt/int2str.c
+++ b/llt/int2str.c
@@ -1,4 +1,4 @@
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else
--- a/llt/ios.c
+++ b/llt/ios.c
@@ -1,4 +1,4 @@
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 static int errno;
@@ -49,7 +49,7 @@
 
 /* OS-level primitive wrappers */
 
-#if defined(MACOSX) || defined(__plan9__)
+#if defined(MACOSX) || defined(PLAN9)
 void *memrchr(const void *s, int c, size_t n)
 {
     const unsigned char *src = (const unsigned char*)s + n;
@@ -83,7 +83,7 @@
 
 static int _enonfatal(int err)
 {
-#ifdef __plan9__
+#ifdef PLAN9
     USED(err);
     return 0;
 #else
@@ -773,7 +773,7 @@
         goto open_file_err;
     int flags = wr ? (rd ? O_RDWR : O_WRONLY) : O_RDONLY;
     if (trunc)  flags |= O_TRUNC;
-#ifdef __plan9__
+#ifdef PLAN9
     if (creat)
         fd = create(fname, flags, 0644);
     else
@@ -991,7 +991,7 @@
 {
     char *str;
     int c;
-#ifndef __plan9__
+#ifndef PLAN9
     va_list al;
     va_copy(al, args);
 
@@ -1024,7 +1024,7 @@
 
         LLT_FREE(str);
     }
-#ifndef __plan9__
+#ifndef PLAN9
     va_end(al);
 #else
     va_end(args);
--- a/llt/ios.h
+++ b/llt/ios.h
@@ -1,7 +1,7 @@
 #ifndef __IOS_H_
 #define __IOS_H_
 
-#ifndef __plan9__
+#ifndef PLAN9
 #include <stdarg.h>
 #endif
 
--- a/llt/llt.h
+++ b/llt/llt.h
@@ -1,7 +1,7 @@
 #ifndef __LLT_H_
 #define __LLT_H_
 
-#ifndef __plan9__
+#ifndef PLAN9
 #include <stdarg.h>
 #endif
 #include "dtypes.h"
--- a/llt/lltinit.c
+++ b/llt/lltinit.c
@@ -1,4 +1,4 @@
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else
@@ -29,11 +29,11 @@
 
     ios_init_stdstreams();
 
-#ifdef __plan9__
-    D_PNAN = NaN();
-    D_NNAN = NaN(); *(u64int*)&D_NNAN |= 1<<31;
-    D_PINF = Inf(1);
-    D_NINF = Inf(-1);
+    D_PNAN = strtod("+NaN",NULL);
+    D_NNAN = strtod("-NaN",NULL);
+    D_PINF = strtod("+Inf",NULL);
+    D_NINF = strtod("-Inf",NULL);
+#ifdef PLAN9
     u32int x;
     x = 0x7fc00000; memcpy(&F_PNAN, &x, 4);
     x = 0xffc00000; memcpy(&F_NNAN, &x, 4);
@@ -40,10 +40,6 @@
     x = 0x7f800000; memcpy(&F_PINF, &x, 4);
     x = 0xff800000; memcpy(&F_NINF, &x, 4);
 #else
-    D_PNAN = strtod("+NaN",NULL);
-    D_NNAN = -strtod("+NaN",NULL);
-    D_PINF = strtod("+Inf",NULL);
-    D_NINF = strtod("-Inf",NULL);
     F_PNAN = strtof("+NaN",NULL);
     F_NNAN = -strtof("+NaN",NULL);
     F_PINF = strtof("+Inf",NULL);
--- a/llt/lookup3.c
+++ b/llt/lookup3.c
@@ -35,7 +35,7 @@
 */
 //#define SELF_TEST 1
 
-#ifndef __plan9__
+#ifndef PLAN9
 #include <stdio.h>      /* defines printf for tests */
 #include <time.h>       /* defines time_t for timings in the test */
 #ifndef WIN32
--- a/llt/mkfile
+++ b/llt/mkfile
@@ -1,7 +1,7 @@
 </$objtype/mkfile
 LIB=libllt.a
 
-CFLAGS=$CFLAGS -p -D__plan9__ -DNDEBUG -D__${objtype}__
+CFLAGS=$CFLAGS -p -DPLAN9 -DNDEBUG -D__${objtype}__
 
 OFILES=\
 	bitvector-ops.$O\
--- a/llt/mt19937ar.c
+++ b/llt/mt19937ar.c
@@ -41,7 +41,7 @@
    email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
 */
 
-#ifndef __plan9__
+#ifndef PLAN9
 #include <stdio.h>
 #endif
 
--- a/llt/ptrhash.c
+++ b/llt/ptrhash.c
@@ -3,7 +3,7 @@
   optimized for storing info about particular values
 */
 
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else
--- a/llt/random.c
+++ b/llt/random.c
@@ -1,7 +1,7 @@
 /*
   random numbers
 */
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else
--- a/llt/socket.h
+++ b/llt/socket.h
@@ -1,7 +1,7 @@
 #ifndef __LLTSOCKET_H_
 #define __LLTSOCKET_H_
 
-#ifndef __plan9__
+#ifndef PLAN9
 #ifdef WIN32
 #include <winsock2.h>
 #else
--- a/llt/timefuncs.c
+++ b/llt/timefuncs.c
@@ -1,4 +1,4 @@
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else
@@ -40,7 +40,7 @@
     ftime(&tstruct);
     return (double)tstruct.time + (double)tstruct.millitm/1.0e3;
 }
-#elif defined(__plan9__)
+#elif defined(PLAN9)
 double floattime(void)
 {
     return (double)nsec() / 1.0e9;
@@ -65,7 +65,7 @@
     struct timeb tstruct;
     ftime(&tstruct);
     a = (((u_int64_t)tstruct.time)<<32) + (u_int64_t)tstruct.millitm;
-#elif defined(__plan9__)
+#elif defined(PLAN9)
     a = nsec();
 #else
     struct timeval now;
@@ -78,7 +78,7 @@
 
 double clock_now(void)
 {
-#if defined(WIN32) || defined(__plan9__)
+#if defined(WIN32) || defined(PLAN9)
     return floattime();
 #else
     struct timeval now;
@@ -90,7 +90,7 @@
 
 void timestring(double seconds, char *buffer, size_t len)
 {
-#ifdef __plan9__
+#ifdef PLAN9
     Tm tm;
     snprint(buffer, len, "%τ", tmfmt(tmtime(&tm, seconds, tzload("local")), nil));
 #elif defined(LINUX) || defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD) || defined(NETBSD)
@@ -141,7 +141,7 @@
     }
     return -1;
 }
-#elif defined(__plan9__)
+#elif defined(PLAN9)
 double parsetime(const char *str)
 {
     Tm tm;
@@ -162,7 +162,7 @@
 
 #ifdef WIN32
     Sleep(ms);
-#elif defined(__plan9__)
+#elif defined(PLAN9)
     sleep(ms);
 #else
     struct timeval timeout;
--- a/llt/utf8.c
+++ b/llt/utf8.c
@@ -12,12 +12,21 @@
   valid.
   A UTF-8 validation routine is included.
 */
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #define snprintf snprint
 #define vsnprintf vsnprint
-#define iswprint(x) 1
+// iswprint straight from musl
+static int
+iswprint(u32int c)
+{
+	if(c < 0xff)
+		return (c+1 & 0x7f) >= 0x21;
+	if(c < 0x2028 || c-0x202a < 0xd800-0x202a || c-0xe000 < 0xfff9-0xe000)
+		return 1;
+	return !(c-0xfffc > 0x10ffff-0xfffc || (c&0xfffe) == 0xfffe);
+}
 #else
 #define _XOPEN_SOURCE 700
 #include <stdlib.h>
@@ -251,7 +260,7 @@
     return count;
 }
 
-#if defined(__WIN32__) || defined(__plan9__)
+#if defined(__WIN32__) || defined(PLAN9)
 #include "wcwidth.c"
 #endif
 
@@ -596,7 +605,7 @@
     wcs = (u_int32_t*)malloc((cnt+1) * sizeof(u_int32_t));
     nc = u8_toucs(wcs, cnt+1, buf, cnt);
     wcs[nc] = 0;
-#ifdef __plan9__
+#ifdef PLAN9
     print("%S", (Rune*)wcs);
 #else
     printf("%ls", (wchar_t*)wcs);
--- a/llt/utils.h
+++ b/llt/utils.h
@@ -41,7 +41,7 @@
 #  define LEGACY_REGS "=q"
 #endif
 
-#if !defined(__plan9__) && !defined(__INTEL_COMPILER) && (defined(ARCH_X86) || defined(ARCH_X86_64))
+#if !defined(PLAN9) && !defined(__INTEL_COMPILER) && (defined(ARCH_X86) || defined(ARCH_X86_64))
 STATIC_INLINE u_int16_t ByteSwap16(u_int16_t x)
 {
   __asm("xchgb %b0,%h0" :
--- a/llt/wcwidth.c
+++ b/llt/wcwidth.c
@@ -61,7 +61,7 @@
  * MODIFIED TO USE uint32_t
  */
 
-#ifndef __plan9__
+#ifndef PLAN9
 #include <stdint.h>
 #include <stddef.h>
 #include "dtypes.h" //for DLLEXPORT
--- a/mkfile
+++ b/mkfile
@@ -2,7 +2,7 @@
 
 BIN=/$objtype/bin
 TARG=flisp
-CFLAGS=$CFLAGS -p -D__plan9__ -DNDEBUG -D__${objtype}__ -Illt
+CFLAGS=$CFLAGS -p -DPLAN9 -DNDEBUG -D__${objtype}__ -Illt
 
 HFILES=\
 	cvalues.c\
@@ -40,3 +40,9 @@
 
 llt/libllt.a:
 	cd llt && mk
+
+bootstrap:V: $O.out
+	cp flisp.boot flisp.boot.bak && \
+	./$O.out mkboot0.lsp system.lsp compiler.lsp > flisp.boot.new && \
+	mv flisp.boot.new flisp.boot && \
+	./$O.out mkboot1.lsp
--- a/opaque_type_template.c
+++ b/opaque_type_template.c
@@ -1,4 +1,4 @@
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else
--- a/operators.c
+++ b/operators.c
@@ -2,7 +2,7 @@
 #include "utils.h"
 #include "ieee754.h"
 
-#ifdef __plan9__
+#ifdef PLAN9
 double trunc(double x)
 {
     modf(x, &x);
@@ -180,7 +180,7 @@
     case T_UINT64: return *(uint64_t*)a < *(uint64_t*)b;
     case T_FLOAT:  return *(float*)a < *(float*)b;
     case T_DOUBLE: return *(double*)a < *(double*)b
-#ifdef __plan9__
+#ifdef PLAN9
     && !isNaN(*(double*)a) && !isNaN(*(double*)b)
 #endif
     ;
@@ -201,7 +201,7 @@
     case T_UINT64: return *(uint64_t*)a == *(uint64_t*)b;
     case T_FLOAT:  return *(float*)a == *(float*)b;
     case T_DOUBLE: return *(double*)a == *(double*)b
-#ifdef __plan9__
+#ifdef PLAN9
     && !isNaN(*(double*)a)
 #endif
     ;
@@ -217,7 +217,7 @@
     double da = conv_to_double(a, atag);
     double db = conv_to_double(b, btag);
 
-#ifdef __plan9__
+#ifdef PLAN9
     if (isNaN(da) || isNaN(db))
         return 0;
 #endif
--- a/print.c
+++ b/print.c
@@ -1,4 +1,4 @@
-#ifdef __plan9__
+#ifdef PLAN9
 #define isnan isNaN
 #define snprintf snprint
 #define iswprint(x) 1
@@ -389,7 +389,7 @@
 
     switch (tag(v)) {
     case TAG_NUM :
-    case TAG_NUM1: HPOS+=ios_printf(f, "%ld", numval(v)); break;
+    case TAG_NUM1: HPOS+=ios_printf(f, "%lld", (int64_t)numval(v)); break;
     case TAG_SYM:
         name = symbol_name(v);
         if (print_princ)
@@ -699,7 +699,7 @@
         }
     }
     else if (type == uint64sym
-#if defined(BITS64) && !defined(__plan9__)
+#if defined(ULONG64)
              || type == ulongsym
 #endif
              ) {
--- a/read.c
+++ b/read.c
@@ -1,4 +1,4 @@
-#ifdef __plan9__
+#ifdef PLAN9
 #define strcasecmp cistrcmp
 #define ERANGE (-999)
 static int errno;
--- a/string.c
+++ b/string.c
@@ -1,7 +1,7 @@
 /*
   string functions
 */
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #define towupper toupperrune
@@ -62,7 +62,7 @@
         cprim_t *cp = (cprim_t*)ptr(args[0]);
         if (cp_class(cp) == wchartype) {
             // FIXME plan9
-#ifdef __plan9__
+#ifdef PLAN9
             int w = -1;
 #else
             int w = wcwidth(*(uint32_t*)cp_data(cp));
--- a/table.c
+++ b/table.c
@@ -1,4 +1,4 @@
-#ifdef __plan9__
+#ifdef PLAN9
 #include <u.h>
 #include <libc.h>
 #else