Compare commits
5 Commits
2abf82a0e8
...
0bf4243ae0
Author | SHA1 | Date |
---|---|---|
|
0bf4243ae0 | |
|
1006496256 | |
![]() |
2bc5c43022 | |
![]() |
48ff4764a4 | |
|
956fd32a06 |
|
@ -0,0 +1,2 @@
|
|||
*.lsp linguist-language=Scheme
|
||||
flisp.boot linguist-language=Scheme
|
2
flisp.c
2
flisp.c
|
@ -2320,6 +2320,8 @@ static void lisp_init(size_t initial_heapsize)
|
|||
set(symbol("*os-name*"), symbol("openbsd"));
|
||||
#elif defined(FREEBSD)
|
||||
set(symbol("*os-name*"), symbol("freebsd"));
|
||||
#elif defined(NETBSD)
|
||||
set(symbol("*os-name*"), symbol("netbsd"));
|
||||
#else
|
||||
set(symbol("*os-name*"), symbol("unknown"));
|
||||
#endif
|
||||
|
|
|
@ -191,7 +191,7 @@ char *get_exename(char *buf, size_t size)
|
|||
|
||||
return buf;
|
||||
}
|
||||
#elif defined(FREEBSD)
|
||||
#elif defined(FREEBSD) || defined(NETBSD)
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
|
@ -199,9 +199,15 @@ char *get_exename(char *buf, size_t size)
|
|||
{
|
||||
int mib[4];
|
||||
mib[0] = CTL_KERN;
|
||||
#if defined(FREEBSD)
|
||||
mib[1] = KERN_PROC;
|
||||
mib[2] = KERN_PROC_PATHNAME;
|
||||
mib[3] = -1;
|
||||
#else
|
||||
mib[1] = KERN_PROC_ARGS;
|
||||
mib[2] = -1;
|
||||
mib[3] = KERN_PROC_PATHNAME;
|
||||
#endif
|
||||
sysctl(mib, 4, buf, &size, NULL, 0);
|
||||
|
||||
return buf;
|
||||
|
|
|
@ -25,13 +25,15 @@
|
|||
# define OPENBSD
|
||||
#elif defined(__FreeBSD__)
|
||||
# define FREEBSD
|
||||
#elif defined(__NetBSD__)
|
||||
# define NETBSD
|
||||
#elif defined(_WIN32)
|
||||
# define WIN32
|
||||
#else
|
||||
# error "unknown platform"
|
||||
#endif
|
||||
|
||||
#if defined(OPENBSD) || defined(FREEBSD)
|
||||
#if defined(OPENBSD) || defined(FREEBSD) || defined(NETBSD)
|
||||
#if defined(__x86_64__)
|
||||
# define __SIZEOF_POINTER__ 8
|
||||
#else
|
||||
|
@ -72,7 +74,7 @@
|
|||
# define BIG_ENDIAN __BIG_ENDIAN
|
||||
# define PDP_ENDIAN __PDP_ENDIAN
|
||||
# define BYTE_ORDER __BYTE_ORDER
|
||||
#elif defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD)
|
||||
#elif defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD) || defined(NETBSD)
|
||||
# include <machine/endian.h>
|
||||
# define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
# define __BIG_ENDIAN BIG_ENDIAN
|
||||
|
@ -193,10 +195,12 @@ typedef u_ptrint_t uptrint_t;
|
|||
|
||||
#define DBL_EPSILON 2.2204460492503131e-16
|
||||
#define FLT_EPSILON 1.192092896e-7
|
||||
#if !defined(NETBSD)
|
||||
#define DBL_MAX 1.7976931348623157e+308
|
||||
#define DBL_MIN 2.2250738585072014e-308
|
||||
#define FLT_MAX 3.402823466e+38
|
||||
#define FLT_MIN 1.175494351e-38
|
||||
#endif
|
||||
#define LOG2_10 3.3219280948873626
|
||||
#define rel_zero(a, b) (fabs((a)/(b)) < DBL_EPSILON)
|
||||
#define sign_bit(r) ((*(int64_t*)&(r)) & BIT63)
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "dtypes.h"
|
||||
|
||||
#if defined(MACOSX)
|
||||
#if defined(MACOSX) || defined(NETBSD)
|
||||
#include <sys/time.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/types.h>
|
||||
|
|
|
@ -82,7 +82,7 @@ void timestring(double seconds, char *buffer, size_t len)
|
|||
{
|
||||
time_t tme = (time_t)seconds;
|
||||
|
||||
#if defined(LINUX) || defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD)
|
||||
#if defined(LINUX) || defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD) || defined(NETBSD)
|
||||
char *fmt = "%c"; /* needed to suppress GCC warning */
|
||||
struct tm tm;
|
||||
|
||||
|
@ -106,7 +106,7 @@ void timestring(double seconds, char *buffer, size_t len)
|
|||
#endif
|
||||
}
|
||||
|
||||
#if defined(LINUX) || defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD)
|
||||
#if defined(LINUX) || defined(MACOSX) || defined(OPENBSD) || defined(FREEBSD) || defined(NETBSD)
|
||||
extern char *strptime(const char *s, const char *format, struct tm *tm);
|
||||
double parsetime(const char *str)
|
||||
{
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#define _XOPEN_SOURCE 700
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
|
@ -26,9 +27,9 @@
|
|||
#include <malloc.h>
|
||||
#define snprintf _snprintf
|
||||
#else
|
||||
#if !defined(__FreeBSD__) && !defined(__OpenBSD__)
|
||||
#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
|
||||
#include <alloca.h>
|
||||
#endif /* __FreeBSD__ && __OpenBSD__ */
|
||||
#endif /* __FreeBSD__ && __OpenBSD__ && __NetBSD__ */
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ value_t eval_sexpr(value_t e, value_t *penv)
|
|||
value_t *rest;
|
||||
cons_t *c;
|
||||
symbol_t *sym;
|
||||
u_int32_t saveSP;
|
||||
uint32_t saveSP;
|
||||
int i, nargs, noeval=0;
|
||||
number_t s, n;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ value_t eval_sexpr(value_t e, value_t *penv)
|
|||
value_t *rest;
|
||||
cons_t *c;
|
||||
symbol_t *sym;
|
||||
u_int32_t saveSP;
|
||||
uint32_t saveSP;
|
||||
int i, nargs, noeval=0;
|
||||
number_t s, n;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ value_t eval_sexpr(value_t e, value_t *penv)
|
|||
value_t *rest;
|
||||
cons_t *c;
|
||||
symbol_t *sym;
|
||||
u_int32_t saveSP;
|
||||
uint32_t saveSP;
|
||||
int i, nargs, noeval=0;
|
||||
number_t s, n;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
u_int32_t *bitvector_resize(u_int32_t *b, size_t n)
|
||||
uint32_t *bitvector_resize(uint32_t *b, size_t n)
|
||||
{
|
||||
u_int32_t *p;
|
||||
uint32_t *p;
|
||||
size_t sz = ((n+31)>>5) * 4;
|
||||
p = realloc(b, sz);
|
||||
if (p == NULL) return NULL;
|
||||
|
@ -8,12 +8,12 @@ u_int32_t *bitvector_resize(u_int32_t *b, size_t n)
|
|||
return p;
|
||||
}
|
||||
|
||||
u_int32_t *mk_bitvector(size_t n)
|
||||
uint32_t *mk_bitvector(size_t n)
|
||||
{
|
||||
return bitvector_resize(NULL, n);
|
||||
}
|
||||
|
||||
void bitvector_set(u_int32_t *b, u_int32_t n, u_int32_t c)
|
||||
void bitvector_set(uint32_t *b, uint32_t n, uint32_t c)
|
||||
{
|
||||
if (c)
|
||||
b[n>>5] |= (1<<(n&31));
|
||||
|
@ -21,7 +21,7 @@ void bitvector_set(u_int32_t *b, u_int32_t n, u_int32_t c)
|
|||
b[n>>5] &= ~(1<<(n&31));
|
||||
}
|
||||
|
||||
u_int32_t bitvector_get(u_int32_t *b, u_int32_t n)
|
||||
uint32_t bitvector_get(uint32_t *b, uint32_t n)
|
||||
{
|
||||
return b[n>>5] & (1<<(n&31));
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ void ltable_adjoin(ltable_t *t, unsigned long item)
|
|||
ltable_insert(t, item);
|
||||
}
|
||||
|
||||
static const u_int32_t offsetsFromUTF8[6] = {
|
||||
static const uint32_t offsetsFromUTF8[6] = {
|
||||
0x00000000UL, 0x00003080UL, 0x000E2080UL,
|
||||
0x03C82080UL, 0xFA082080UL, 0x82082080UL
|
||||
};
|
||||
|
@ -94,24 +94,24 @@ int u8_seqlen(const char c)
|
|||
return trailingBytesForUTF8[(unsigned int)(unsigned char)c] + 1;
|
||||
}
|
||||
|
||||
#define UEOF ((u_int32_t)EOF)
|
||||
#define UEOF ((uint32_t)EOF)
|
||||
|
||||
u_int32_t u8_fgetc(FILE *f)
|
||||
uint32_t u8_fgetc(FILE *f)
|
||||
{
|
||||
int amt=0, sz, c;
|
||||
u_int32_t ch=0;
|
||||
uint32_t ch=0;
|
||||
|
||||
c = fgetc(f);
|
||||
if (c == EOF)
|
||||
return UEOF;
|
||||
ch = (u_int32_t)c;
|
||||
ch = (uint32_t)c;
|
||||
amt = sz = u8_seqlen(ch);
|
||||
while (--amt) {
|
||||
ch <<= 6;
|
||||
c = fgetc(f);
|
||||
if (c == EOF)
|
||||
return UEOF;
|
||||
ch += (u_int32_t)c;
|
||||
ch += (uint32_t)c;
|
||||
}
|
||||
ch -= offsetsFromUTF8[sz-1];
|
||||
|
||||
|
|
|
@ -18,25 +18,19 @@
|
|||
Public Domain
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __LP64__
|
||||
#define NUM_FORMAT "%" PRId64
|
||||
typedef u_int64_t value_t;
|
||||
typedef int64_t number_t;
|
||||
#else
|
||||
#define NUM_FORMAT "%" PRId32
|
||||
typedef u_int32_t value_t;
|
||||
typedef int32_t number_t;
|
||||
#endif
|
||||
#define NUM_FORMAT "%" PRIdPTR
|
||||
|
||||
typedef intptr_t number_t;
|
||||
typedef uintptr_t value_t;
|
||||
|
||||
typedef struct {
|
||||
value_t car;
|
||||
|
@ -96,7 +90,7 @@ static char *stack_bottom;
|
|||
#define PROCESS_STACK_SIZE (2*1024*1024)
|
||||
#define N_STACK 49152
|
||||
static value_t Stack[N_STACK];
|
||||
static u_int32_t SP = 0;
|
||||
static uint32_t SP = 0;
|
||||
#define PUSH(v) (Stack[SP++] = (v))
|
||||
#define POP() (Stack[--SP])
|
||||
#define POPN(n) (SP-=(n))
|
||||
|
@ -188,7 +182,7 @@ static unsigned char *fromspace;
|
|||
static unsigned char *tospace;
|
||||
static unsigned char *curheap;
|
||||
static unsigned char *lim;
|
||||
static u_int32_t heapsize = 64*1024;//bytes
|
||||
static uint32_t heapsize = 64*1024;//bytes
|
||||
|
||||
void lisp_init(void)
|
||||
{
|
||||
|
@ -271,7 +265,7 @@ void gc(void)
|
|||
{
|
||||
static int grew = 0;
|
||||
unsigned char *temp;
|
||||
u_int32_t i;
|
||||
uint32_t i;
|
||||
|
||||
curheap = tospace;
|
||||
lim = curheap+heapsize-sizeof(cons_t);
|
||||
|
@ -314,7 +308,7 @@ static int symchar(char c)
|
|||
return (!isspace(c) && !strchr(special, c));
|
||||
}
|
||||
|
||||
static u_int32_t toktype = TOK_NONE;
|
||||
static uint32_t toktype = TOK_NONE;
|
||||
static value_t tokval;
|
||||
static char buf[256];
|
||||
|
||||
|
@ -385,7 +379,7 @@ static int read_token(FILE *f, char c)
|
|||
return i;
|
||||
}
|
||||
|
||||
static u_int32_t peek(FILE *f)
|
||||
static uint32_t peek(FILE *f)
|
||||
{
|
||||
char c, *end;
|
||||
number_t x;
|
||||
|
@ -436,7 +430,7 @@ static u_int32_t peek(FILE *f)
|
|||
static void read_list(FILE *f, value_t *pval)
|
||||
{
|
||||
value_t c, *pc;
|
||||
u_int32_t t;
|
||||
uint32_t t;
|
||||
|
||||
PUSH(NIL);
|
||||
pc = &Stack[SP-1]; // to keep track of current cons cell
|
||||
|
@ -547,7 +541,7 @@ value_t eval_sexpr(value_t e, value_t *penv)
|
|||
value_t *rest;
|
||||
cons_t *c;
|
||||
symbol_t *sym;
|
||||
u_int32_t saveSP;
|
||||
uint32_t saveSP;
|
||||
int i, nargs, noeval=0;
|
||||
number_t s, n;
|
||||
|
||||
|
|
32
tiny/lisp.c
32
tiny/lisp.c
|
@ -18,25 +18,19 @@
|
|||
Public Domain
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __LP64__
|
||||
#define NUM_FORMAT "%" PRId64
|
||||
typedef u_int64_t value_t;
|
||||
typedef int64_t number_t;
|
||||
#else
|
||||
#define NUM_FORMAT "%" PRId32
|
||||
typedef u_int32_t value_t;
|
||||
typedef int32_t number_t;
|
||||
#endif
|
||||
#define NUM_FORMAT "%" PRIdPTR
|
||||
|
||||
typedef intptr_t number_t;
|
||||
typedef uintptr_t value_t;
|
||||
|
||||
typedef struct {
|
||||
value_t car;
|
||||
|
@ -96,7 +90,7 @@ static char *stack_bottom;
|
|||
#define PROCESS_STACK_SIZE (2*1024*1024)
|
||||
#define N_STACK 49152
|
||||
static value_t Stack[N_STACK];
|
||||
static u_int32_t SP = 0;
|
||||
static uint32_t SP = 0;
|
||||
#define PUSH(v) (Stack[SP++] = (v))
|
||||
#define POP() (Stack[--SP])
|
||||
#define POPN(n) (SP-=(n))
|
||||
|
@ -188,7 +182,7 @@ static unsigned char *fromspace;
|
|||
static unsigned char *tospace;
|
||||
static unsigned char *curheap;
|
||||
static unsigned char *lim;
|
||||
static u_int32_t heapsize = 64*1024;//bytes
|
||||
static uint32_t heapsize = 64*1024;//bytes
|
||||
|
||||
void lisp_init(void)
|
||||
{
|
||||
|
@ -271,7 +265,7 @@ void gc(void)
|
|||
{
|
||||
static int grew = 0;
|
||||
unsigned char *temp;
|
||||
u_int32_t i;
|
||||
uint32_t i;
|
||||
|
||||
curheap = tospace;
|
||||
lim = curheap+heapsize-sizeof(cons_t);
|
||||
|
@ -314,7 +308,7 @@ static int symchar(char c)
|
|||
return (!isspace(c) && !strchr(special, c));
|
||||
}
|
||||
|
||||
static u_int32_t toktype = TOK_NONE;
|
||||
static uint32_t toktype = TOK_NONE;
|
||||
static value_t tokval;
|
||||
static char buf[256];
|
||||
|
||||
|
@ -386,7 +380,7 @@ static int read_token(FILE *f, char c)
|
|||
return (dot && (totread==2));
|
||||
}
|
||||
|
||||
static u_int32_t peek(FILE *f)
|
||||
static uint32_t peek(FILE *f)
|
||||
{
|
||||
char c, *end;
|
||||
number_t x;
|
||||
|
@ -434,7 +428,7 @@ static u_int32_t peek(FILE *f)
|
|||
static void read_list(FILE *f, value_t *pval)
|
||||
{
|
||||
value_t c, *pc;
|
||||
u_int32_t t;
|
||||
uint32_t t;
|
||||
|
||||
PUSH(NIL);
|
||||
pc = &Stack[SP-1]; // to keep track of current cons cell
|
||||
|
@ -548,7 +542,7 @@ value_t eval_sexpr(value_t e, value_t *penv)
|
|||
value_t *rest;
|
||||
cons_t *c;
|
||||
symbol_t *sym;
|
||||
u_int32_t saveSP;
|
||||
uint32_t saveSP;
|
||||
int i, nargs, noeval=0;
|
||||
number_t s, n;
|
||||
|
||||
|
@ -983,7 +977,7 @@ static char *infile = NULL;
|
|||
value_t toplevel_eval(value_t expr)
|
||||
{
|
||||
value_t v;
|
||||
u_int32_t saveSP = SP;
|
||||
uint32_t saveSP = SP;
|
||||
PUSH(NIL);
|
||||
v = eval(expr, &Stack[SP-1]);
|
||||
SP = saveSP;
|
||||
|
|
48
tiny/lisp2.c
48
tiny/lisp2.c
|
@ -39,25 +39,19 @@
|
|||
Public Domain
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __LP64__
|
||||
#define NUM_FORMAT "%" PRId64
|
||||
typedef u_int64_t value_t;
|
||||
typedef int64_t number_t;
|
||||
#else
|
||||
#define NUM_FORMAT "%" PRId32
|
||||
typedef u_int32_t value_t;
|
||||
typedef int32_t number_t;
|
||||
#endif
|
||||
#define NUM_FORMAT "%" PRIdPTR
|
||||
|
||||
typedef intptr_t number_t;
|
||||
typedef uintptr_t value_t;
|
||||
|
||||
typedef struct {
|
||||
value_t car;
|
||||
|
@ -120,7 +114,7 @@ static char *stack_bottom;
|
|||
#define PROCESS_STACK_SIZE (2*1024*1024)
|
||||
#define N_STACK 98304
|
||||
static value_t Stack[N_STACK];
|
||||
static u_int32_t SP = 0;
|
||||
static uint32_t SP = 0;
|
||||
#define PUSH(v) (Stack[SP++] = (v))
|
||||
#define POP() (Stack[--SP])
|
||||
#define POPN(n) (SP-=(n))
|
||||
|
@ -130,7 +124,7 @@ value_t BACKQUOTE, COMMA, COMMAAT, COMMADOT;
|
|||
|
||||
value_t read_sexpr(FILE *f);
|
||||
void print(FILE *f, value_t v, int princ);
|
||||
value_t eval_sexpr(value_t e, value_t *penv, int tail, u_int32_t envend);
|
||||
value_t eval_sexpr(value_t e, value_t *penv, int tail, uint32_t envend);
|
||||
value_t load_file(char *fname);
|
||||
value_t toplevel_eval(value_t expr);
|
||||
|
||||
|
@ -230,8 +224,8 @@ static unsigned char *fromspace;
|
|||
static unsigned char *tospace;
|
||||
static unsigned char *curheap;
|
||||
static unsigned char *lim;
|
||||
static u_int32_t heapsize = 128*1024;//bytes
|
||||
static u_int32_t *consflags;
|
||||
static uint32_t heapsize = 128*1024;//bytes
|
||||
static uint32_t *consflags;
|
||||
static ltable_t printconses;
|
||||
|
||||
void lisp_init(void)
|
||||
|
@ -337,7 +331,7 @@ void gc(int mustgrow)
|
|||
{
|
||||
static int grew = 0;
|
||||
void *temp;
|
||||
u_int32_t i;
|
||||
uint32_t i;
|
||||
readstate_t *rs;
|
||||
|
||||
curheap = tospace;
|
||||
|
@ -375,7 +369,7 @@ void gc(int mustgrow)
|
|||
temp = bitvector_resize(consflags, heapsize/sizeof(cons_t));
|
||||
if (temp == NULL)
|
||||
lerror("out of memory\n");
|
||||
consflags = (u_int32_t*)temp;
|
||||
consflags = (uint32_t*)temp;
|
||||
}
|
||||
grew = !grew;
|
||||
}
|
||||
|
@ -400,7 +394,7 @@ static int symchar(char c)
|
|||
return (!isspace(c) && !strchr(special, c));
|
||||
}
|
||||
|
||||
static u_int32_t toktype = TOK_NONE;
|
||||
static uint32_t toktype = TOK_NONE;
|
||||
static value_t tokval;
|
||||
static char buf[256];
|
||||
|
||||
|
@ -472,7 +466,7 @@ static int read_token(FILE *f, char c, int digits)
|
|||
return (dot && (totread==2));
|
||||
}
|
||||
|
||||
static u_int32_t peek(FILE *f)
|
||||
static uint32_t peek(FILE *f)
|
||||
{
|
||||
char c, *end;
|
||||
number_t x;
|
||||
|
@ -505,7 +499,7 @@ static u_int32_t peek(FILE *f)
|
|||
toktype = TOK_SHARPQUOTE;
|
||||
}
|
||||
else if ((char)ch == '\\') {
|
||||
u_int32_t cval = u8_fgetc(f);
|
||||
uint32_t cval = u8_fgetc(f);
|
||||
toktype = TOK_NUM;
|
||||
tokval = number(cval);
|
||||
}
|
||||
|
@ -569,7 +563,7 @@ static value_t do_read_sexpr(FILE *f, int fixup);
|
|||
static void read_list(FILE *f, value_t *pval, int fixup)
|
||||
{
|
||||
value_t c, *pc;
|
||||
u_int32_t t;
|
||||
uint32_t t;
|
||||
|
||||
PUSH(NIL);
|
||||
pc = &Stack[SP-1]; // to keep track of current cons cell
|
||||
|
@ -610,7 +604,7 @@ static void read_list(FILE *f, value_t *pval, int fixup)
|
|||
static value_t do_read_sexpr(FILE *f, int fixup)
|
||||
{
|
||||
value_t v, *head;
|
||||
u_int32_t t, l;
|
||||
uint32_t t, l;
|
||||
int i;
|
||||
|
||||
t = peek(f);
|
||||
|
@ -865,12 +859,12 @@ static value_t assoc(value_t item, value_t v)
|
|||
environment, otherwise you have to put any new environment on the top
|
||||
of the stack.
|
||||
*/
|
||||
value_t eval_sexpr(value_t e, value_t *penv, int tail, u_int32_t envend)
|
||||
value_t eval_sexpr(value_t e, value_t *penv, int tail, uint32_t envend)
|
||||
{
|
||||
value_t f, v, headsym, asym, *pv, *argsyms, *body, *lenv, *argenv;
|
||||
cons_t *c;
|
||||
symbol_t *sym;
|
||||
u_int32_t saveSP;
|
||||
uint32_t saveSP;
|
||||
int i, nargs, noeval=0;
|
||||
number_t s, n;
|
||||
|
||||
|
@ -1209,7 +1203,7 @@ value_t eval_sexpr(value_t e, value_t *penv, int tail, u_int32_t envend)
|
|||
if (tag(v)<0x2) { SP=saveSP; return v; }
|
||||
if (tail) {
|
||||
*penv = NIL;
|
||||
envend = SP = (u_int32_t)(penv-&Stack[0]) + 1;
|
||||
envend = SP = (uint32_t)(penv-&Stack[0]) + 1;
|
||||
e=v; goto eval_top;
|
||||
}
|
||||
else {
|
||||
|
@ -1363,7 +1357,7 @@ value_t eval_sexpr(value_t e, value_t *penv, int tail, u_int32_t envend)
|
|||
nargs = (int)(&Stack[SP] - argenv);
|
||||
for(i=0; i < nargs; i++)
|
||||
penv[i] = argenv[i];
|
||||
envend = SP = (u_int32_t)((penv+nargs) - &Stack[0]);
|
||||
envend = SP = (uint32_t)((penv+nargs) - &Stack[0]);
|
||||
goto eval_top;
|
||||
}
|
||||
else {
|
||||
|
@ -1385,7 +1379,7 @@ static char *infile = NULL;
|
|||
value_t toplevel_eval(value_t expr)
|
||||
{
|
||||
value_t v;
|
||||
u_int32_t saveSP = SP;
|
||||
uint32_t saveSP = SP;
|
||||
PUSH(NIL);
|
||||
v = topeval(expr, &Stack[SP-1]);
|
||||
SP = saveSP;
|
||||
|
|
34
tiny/lispf.c
34
tiny/lispf.c
|
@ -24,35 +24,25 @@
|
|||
Public Domain
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __LP64__
|
||||
typedef u_int64_t value_t;
|
||||
#else
|
||||
typedef u_int32_t value_t;
|
||||
#endif
|
||||
|
||||
#ifdef FLOAT
|
||||
#define NUM_FORMAT "%f"
|
||||
typedef float number_t;
|
||||
#else
|
||||
#ifdef __LP64__
|
||||
#define NUM_FORMAT "%" PRId64
|
||||
typedef int64_t number_t;
|
||||
#else
|
||||
#define NUM_FORMAT "%" PRId32
|
||||
typedef int32_t number_t;
|
||||
#endif
|
||||
#define NUM_FORMAT "%" PRIdPTR
|
||||
typedef intptr_t number_t;
|
||||
#endif
|
||||
|
||||
typedef uintptr_t value_t;
|
||||
|
||||
typedef struct {
|
||||
value_t car;
|
||||
value_t cdr;
|
||||
|
@ -119,7 +109,7 @@ static char *stack_bottom;
|
|||
#define PROCESS_STACK_SIZE (2*1024*1024)
|
||||
#define N_STACK 49152
|
||||
static value_t Stack[N_STACK];
|
||||
static u_int32_t SP = 0;
|
||||
static uint32_t SP = 0;
|
||||
#define PUSH(v) (Stack[SP++] = (v))
|
||||
#define POP() (Stack[--SP])
|
||||
#define POPN(n) (SP-=(n))
|
||||
|
@ -211,7 +201,7 @@ static unsigned char *fromspace;
|
|||
static unsigned char *tospace;
|
||||
static unsigned char *curheap;
|
||||
static unsigned char *lim;
|
||||
static u_int32_t heapsize = 64*1024;//bytes
|
||||
static uint32_t heapsize = 64*1024;//bytes
|
||||
|
||||
void lisp_init(void)
|
||||
{
|
||||
|
@ -294,7 +284,7 @@ void gc(void)
|
|||
{
|
||||
static int grew = 0;
|
||||
unsigned char *temp;
|
||||
u_int32_t i;
|
||||
uint32_t i;
|
||||
|
||||
curheap = tospace;
|
||||
lim = curheap+heapsize-sizeof(cons_t);
|
||||
|
@ -337,7 +327,7 @@ static int symchar(char c)
|
|||
return (!isspace(c) && !strchr(special, c));
|
||||
}
|
||||
|
||||
static u_int32_t toktype = TOK_NONE;
|
||||
static uint32_t toktype = TOK_NONE;
|
||||
static value_t tokval;
|
||||
static char buf[256];
|
||||
|
||||
|
@ -408,7 +398,7 @@ static int read_token(FILE *f, char c)
|
|||
return i;
|
||||
}
|
||||
|
||||
static u_int32_t peek(FILE *f)
|
||||
static uint32_t peek(FILE *f)
|
||||
{
|
||||
char c, *end;
|
||||
number_t x;
|
||||
|
@ -459,7 +449,7 @@ static u_int32_t peek(FILE *f)
|
|||
static void read_list(FILE *f, value_t *pval)
|
||||
{
|
||||
value_t c, *pc;
|
||||
u_int32_t t;
|
||||
uint32_t t;
|
||||
|
||||
PUSH(NIL);
|
||||
pc = &Stack[SP-1]; // to keep track of current cons cell
|
||||
|
@ -573,7 +563,7 @@ value_t eval_sexpr(value_t e, value_t *penv)
|
|||
value_t *rest;
|
||||
cons_t *c;
|
||||
symbol_t *sym;
|
||||
u_int32_t saveSP;
|
||||
uint32_t saveSP;
|
||||
int i, nargs, noeval=0;
|
||||
number_t s, n;
|
||||
|
||||
|
|
Loading…
Reference in New Issue