Use stdint.h instead of sys/types.h

This commit is contained in:
Lassi Kortela 2020-02-26 11:26:50 +02:00
parent 2abf82a0e8
commit 956fd32a06
4 changed files with 50 additions and 54 deletions

View File

@ -18,23 +18,22 @@
Public Domain Public Domain
*/ */
#include <sys/types.h>
#include <ctype.h> #include <ctype.h>
#include <inttypes.h> #include <inttypes.h>
#include <setjmp.h> #include <setjmp.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef __LP64__ #ifdef __LP64__
#define NUM_FORMAT "%" PRId64 #define NUM_FORMAT "%" PRId64
typedef u_int64_t value_t; typedef uint64_t value_t;
typedef int64_t number_t; typedef int64_t number_t;
#else #else
#define NUM_FORMAT "%" PRId32 #define NUM_FORMAT "%" PRId32
typedef u_int32_t value_t; typedef uint32_t value_t;
typedef int32_t number_t; typedef int32_t number_t;
#endif #endif
@ -96,7 +95,7 @@ static char *stack_bottom;
#define PROCESS_STACK_SIZE (2*1024*1024) #define PROCESS_STACK_SIZE (2*1024*1024)
#define N_STACK 49152 #define N_STACK 49152
static value_t Stack[N_STACK]; static value_t Stack[N_STACK];
static u_int32_t SP = 0; static uint32_t SP = 0;
#define PUSH(v) (Stack[SP++] = (v)) #define PUSH(v) (Stack[SP++] = (v))
#define POP() (Stack[--SP]) #define POP() (Stack[--SP])
#define POPN(n) (SP-=(n)) #define POPN(n) (SP-=(n))
@ -188,7 +187,7 @@ static unsigned char *fromspace;
static unsigned char *tospace; static unsigned char *tospace;
static unsigned char *curheap; static unsigned char *curheap;
static unsigned char *lim; static unsigned char *lim;
static u_int32_t heapsize = 64*1024;//bytes static uint32_t heapsize = 64*1024;//bytes
void lisp_init(void) void lisp_init(void)
{ {
@ -271,7 +270,7 @@ void gc(void)
{ {
static int grew = 0; static int grew = 0;
unsigned char *temp; unsigned char *temp;
u_int32_t i; uint32_t i;
curheap = tospace; curheap = tospace;
lim = curheap+heapsize-sizeof(cons_t); lim = curheap+heapsize-sizeof(cons_t);
@ -314,7 +313,7 @@ static int symchar(char c)
return (!isspace(c) && !strchr(special, 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 value_t tokval;
static char buf[256]; static char buf[256];
@ -385,7 +384,7 @@ static int read_token(FILE *f, char c)
return i; return i;
} }
static u_int32_t peek(FILE *f) static uint32_t peek(FILE *f)
{ {
char c, *end; char c, *end;
number_t x; number_t x;
@ -436,7 +435,7 @@ static u_int32_t peek(FILE *f)
static void read_list(FILE *f, value_t *pval) static void read_list(FILE *f, value_t *pval)
{ {
value_t c, *pc; value_t c, *pc;
u_int32_t t; uint32_t t;
PUSH(NIL); PUSH(NIL);
pc = &Stack[SP-1]; // to keep track of current cons cell pc = &Stack[SP-1]; // to keep track of current cons cell
@ -547,7 +546,7 @@ value_t eval_sexpr(value_t e, value_t *penv)
value_t *rest; value_t *rest;
cons_t *c; cons_t *c;
symbol_t *sym; symbol_t *sym;
u_int32_t saveSP; uint32_t saveSP;
int i, nargs, noeval=0; int i, nargs, noeval=0;
number_t s, n; number_t s, n;

View File

@ -18,23 +18,22 @@
Public Domain Public Domain
*/ */
#include <sys/types.h>
#include <ctype.h> #include <ctype.h>
#include <inttypes.h> #include <inttypes.h>
#include <setjmp.h> #include <setjmp.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef __LP64__ #ifdef __LP64__
#define NUM_FORMAT "%" PRId64 #define NUM_FORMAT "%" PRId64
typedef u_int64_t value_t; typedef uint64_t value_t;
typedef int64_t number_t; typedef int64_t number_t;
#else #else
#define NUM_FORMAT "%" PRId32 #define NUM_FORMAT "%" PRId32
typedef u_int32_t value_t; typedef uint32_t value_t;
typedef int32_t number_t; typedef int32_t number_t;
#endif #endif
@ -96,7 +95,7 @@ static char *stack_bottom;
#define PROCESS_STACK_SIZE (2*1024*1024) #define PROCESS_STACK_SIZE (2*1024*1024)
#define N_STACK 49152 #define N_STACK 49152
static value_t Stack[N_STACK]; static value_t Stack[N_STACK];
static u_int32_t SP = 0; static uint32_t SP = 0;
#define PUSH(v) (Stack[SP++] = (v)) #define PUSH(v) (Stack[SP++] = (v))
#define POP() (Stack[--SP]) #define POP() (Stack[--SP])
#define POPN(n) (SP-=(n)) #define POPN(n) (SP-=(n))
@ -188,7 +187,7 @@ static unsigned char *fromspace;
static unsigned char *tospace; static unsigned char *tospace;
static unsigned char *curheap; static unsigned char *curheap;
static unsigned char *lim; static unsigned char *lim;
static u_int32_t heapsize = 64*1024;//bytes static uint32_t heapsize = 64*1024;//bytes
void lisp_init(void) void lisp_init(void)
{ {
@ -271,7 +270,7 @@ void gc(void)
{ {
static int grew = 0; static int grew = 0;
unsigned char *temp; unsigned char *temp;
u_int32_t i; uint32_t i;
curheap = tospace; curheap = tospace;
lim = curheap+heapsize-sizeof(cons_t); lim = curheap+heapsize-sizeof(cons_t);
@ -314,7 +313,7 @@ static int symchar(char c)
return (!isspace(c) && !strchr(special, 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 value_t tokval;
static char buf[256]; static char buf[256];
@ -386,7 +385,7 @@ static int read_token(FILE *f, char c)
return (dot && (totread==2)); return (dot && (totread==2));
} }
static u_int32_t peek(FILE *f) static uint32_t peek(FILE *f)
{ {
char c, *end; char c, *end;
number_t x; number_t x;
@ -434,7 +433,7 @@ static u_int32_t peek(FILE *f)
static void read_list(FILE *f, value_t *pval) static void read_list(FILE *f, value_t *pval)
{ {
value_t c, *pc; value_t c, *pc;
u_int32_t t; uint32_t t;
PUSH(NIL); PUSH(NIL);
pc = &Stack[SP-1]; // to keep track of current cons cell pc = &Stack[SP-1]; // to keep track of current cons cell
@ -548,7 +547,7 @@ value_t eval_sexpr(value_t e, value_t *penv)
value_t *rest; value_t *rest;
cons_t *c; cons_t *c;
symbol_t *sym; symbol_t *sym;
u_int32_t saveSP; uint32_t saveSP;
int i, nargs, noeval=0; int i, nargs, noeval=0;
number_t s, n; number_t s, n;
@ -983,7 +982,7 @@ static char *infile = NULL;
value_t toplevel_eval(value_t expr) value_t toplevel_eval(value_t expr)
{ {
value_t v; value_t v;
u_int32_t saveSP = SP; uint32_t saveSP = SP;
PUSH(NIL); PUSH(NIL);
v = eval(expr, &Stack[SP-1]); v = eval(expr, &Stack[SP-1]);
SP = saveSP; SP = saveSP;

View File

@ -39,23 +39,22 @@
Public Domain Public Domain
*/ */
#include <sys/types.h>
#include <ctype.h> #include <ctype.h>
#include <inttypes.h> #include <inttypes.h>
#include <setjmp.h> #include <setjmp.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef __LP64__ #ifdef __LP64__
#define NUM_FORMAT "%" PRId64 #define NUM_FORMAT "%" PRId64
typedef u_int64_t value_t; typedef uint64_t value_t;
typedef int64_t number_t; typedef int64_t number_t;
#else #else
#define NUM_FORMAT "%" PRId32 #define NUM_FORMAT "%" PRId32
typedef u_int32_t value_t; typedef uint32_t value_t;
typedef int32_t number_t; typedef int32_t number_t;
#endif #endif
@ -120,7 +119,7 @@ static char *stack_bottom;
#define PROCESS_STACK_SIZE (2*1024*1024) #define PROCESS_STACK_SIZE (2*1024*1024)
#define N_STACK 98304 #define N_STACK 98304
static value_t Stack[N_STACK]; static value_t Stack[N_STACK];
static u_int32_t SP = 0; static uint32_t SP = 0;
#define PUSH(v) (Stack[SP++] = (v)) #define PUSH(v) (Stack[SP++] = (v))
#define POP() (Stack[--SP]) #define POP() (Stack[--SP])
#define POPN(n) (SP-=(n)) #define POPN(n) (SP-=(n))
@ -130,7 +129,7 @@ value_t BACKQUOTE, COMMA, COMMAAT, COMMADOT;
value_t read_sexpr(FILE *f); value_t read_sexpr(FILE *f);
void print(FILE *f, value_t v, int princ); 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 load_file(char *fname);
value_t toplevel_eval(value_t expr); value_t toplevel_eval(value_t expr);
@ -230,8 +229,8 @@ static unsigned char *fromspace;
static unsigned char *tospace; static unsigned char *tospace;
static unsigned char *curheap; static unsigned char *curheap;
static unsigned char *lim; static unsigned char *lim;
static u_int32_t heapsize = 128*1024;//bytes static uint32_t heapsize = 128*1024;//bytes
static u_int32_t *consflags; static uint32_t *consflags;
static ltable_t printconses; static ltable_t printconses;
void lisp_init(void) void lisp_init(void)
@ -337,7 +336,7 @@ void gc(int mustgrow)
{ {
static int grew = 0; static int grew = 0;
void *temp; void *temp;
u_int32_t i; uint32_t i;
readstate_t *rs; readstate_t *rs;
curheap = tospace; curheap = tospace;
@ -375,7 +374,7 @@ void gc(int mustgrow)
temp = bitvector_resize(consflags, heapsize/sizeof(cons_t)); temp = bitvector_resize(consflags, heapsize/sizeof(cons_t));
if (temp == NULL) if (temp == NULL)
lerror("out of memory\n"); lerror("out of memory\n");
consflags = (u_int32_t*)temp; consflags = (uint32_t*)temp;
} }
grew = !grew; grew = !grew;
} }
@ -400,7 +399,7 @@ static int symchar(char c)
return (!isspace(c) && !strchr(special, 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 value_t tokval;
static char buf[256]; static char buf[256];
@ -472,7 +471,7 @@ static int read_token(FILE *f, char c, int digits)
return (dot && (totread==2)); return (dot && (totread==2));
} }
static u_int32_t peek(FILE *f) static uint32_t peek(FILE *f)
{ {
char c, *end; char c, *end;
number_t x; number_t x;
@ -505,7 +504,7 @@ static u_int32_t peek(FILE *f)
toktype = TOK_SHARPQUOTE; toktype = TOK_SHARPQUOTE;
} }
else if ((char)ch == '\\') { else if ((char)ch == '\\') {
u_int32_t cval = u8_fgetc(f); uint32_t cval = u8_fgetc(f);
toktype = TOK_NUM; toktype = TOK_NUM;
tokval = number(cval); tokval = number(cval);
} }
@ -569,7 +568,7 @@ static value_t do_read_sexpr(FILE *f, int fixup);
static void read_list(FILE *f, value_t *pval, int fixup) static void read_list(FILE *f, value_t *pval, int fixup)
{ {
value_t c, *pc; value_t c, *pc;
u_int32_t t; uint32_t t;
PUSH(NIL); PUSH(NIL);
pc = &Stack[SP-1]; // to keep track of current cons cell pc = &Stack[SP-1]; // to keep track of current cons cell
@ -610,7 +609,7 @@ static void read_list(FILE *f, value_t *pval, int fixup)
static value_t do_read_sexpr(FILE *f, int fixup) static value_t do_read_sexpr(FILE *f, int fixup)
{ {
value_t v, *head; value_t v, *head;
u_int32_t t, l; uint32_t t, l;
int i; int i;
t = peek(f); t = peek(f);
@ -865,12 +864,12 @@ static value_t assoc(value_t item, value_t v)
environment, otherwise you have to put any new environment on the top environment, otherwise you have to put any new environment on the top
of the stack. 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; value_t f, v, headsym, asym, *pv, *argsyms, *body, *lenv, *argenv;
cons_t *c; cons_t *c;
symbol_t *sym; symbol_t *sym;
u_int32_t saveSP; uint32_t saveSP;
int i, nargs, noeval=0; int i, nargs, noeval=0;
number_t s, n; number_t s, n;
@ -1209,7 +1208,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 (tag(v)<0x2) { SP=saveSP; return v; }
if (tail) { if (tail) {
*penv = NIL; *penv = NIL;
envend = SP = (u_int32_t)(penv-&Stack[0]) + 1; envend = SP = (uint32_t)(penv-&Stack[0]) + 1;
e=v; goto eval_top; e=v; goto eval_top;
} }
else { else {
@ -1363,7 +1362,7 @@ value_t eval_sexpr(value_t e, value_t *penv, int tail, u_int32_t envend)
nargs = (int)(&Stack[SP] - argenv); nargs = (int)(&Stack[SP] - argenv);
for(i=0; i < nargs; i++) for(i=0; i < nargs; i++)
penv[i] = argenv[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; goto eval_top;
} }
else { else {
@ -1385,7 +1384,7 @@ static char *infile = NULL;
value_t toplevel_eval(value_t expr) value_t toplevel_eval(value_t expr)
{ {
value_t v; value_t v;
u_int32_t saveSP = SP; uint32_t saveSP = SP;
PUSH(NIL); PUSH(NIL);
v = topeval(expr, &Stack[SP-1]); v = topeval(expr, &Stack[SP-1]);
SP = saveSP; SP = saveSP;

View File

@ -24,20 +24,19 @@
Public Domain Public Domain
*/ */
#include <sys/types.h>
#include <ctype.h> #include <ctype.h>
#include <inttypes.h> #include <inttypes.h>
#include <setjmp.h> #include <setjmp.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef __LP64__ #ifdef __LP64__
typedef u_int64_t value_t; typedef uint64_t value_t;
#else #else
typedef u_int32_t value_t; typedef uint32_t value_t;
#endif #endif
#ifdef FLOAT #ifdef FLOAT
@ -119,7 +118,7 @@ static char *stack_bottom;
#define PROCESS_STACK_SIZE (2*1024*1024) #define PROCESS_STACK_SIZE (2*1024*1024)
#define N_STACK 49152 #define N_STACK 49152
static value_t Stack[N_STACK]; static value_t Stack[N_STACK];
static u_int32_t SP = 0; static uint32_t SP = 0;
#define PUSH(v) (Stack[SP++] = (v)) #define PUSH(v) (Stack[SP++] = (v))
#define POP() (Stack[--SP]) #define POP() (Stack[--SP])
#define POPN(n) (SP-=(n)) #define POPN(n) (SP-=(n))
@ -211,7 +210,7 @@ static unsigned char *fromspace;
static unsigned char *tospace; static unsigned char *tospace;
static unsigned char *curheap; static unsigned char *curheap;
static unsigned char *lim; static unsigned char *lim;
static u_int32_t heapsize = 64*1024;//bytes static uint32_t heapsize = 64*1024;//bytes
void lisp_init(void) void lisp_init(void)
{ {
@ -294,7 +293,7 @@ void gc(void)
{ {
static int grew = 0; static int grew = 0;
unsigned char *temp; unsigned char *temp;
u_int32_t i; uint32_t i;
curheap = tospace; curheap = tospace;
lim = curheap+heapsize-sizeof(cons_t); lim = curheap+heapsize-sizeof(cons_t);
@ -337,7 +336,7 @@ static int symchar(char c)
return (!isspace(c) && !strchr(special, 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 value_t tokval;
static char buf[256]; static char buf[256];
@ -408,7 +407,7 @@ static int read_token(FILE *f, char c)
return i; return i;
} }
static u_int32_t peek(FILE *f) static uint32_t peek(FILE *f)
{ {
char c, *end; char c, *end;
number_t x; number_t x;
@ -459,7 +458,7 @@ static u_int32_t peek(FILE *f)
static void read_list(FILE *f, value_t *pval) static void read_list(FILE *f, value_t *pval)
{ {
value_t c, *pc; value_t c, *pc;
u_int32_t t; uint32_t t;
PUSH(NIL); PUSH(NIL);
pc = &Stack[SP-1]; // to keep track of current cons cell pc = &Stack[SP-1]; // to keep track of current cons cell
@ -573,7 +572,7 @@ value_t eval_sexpr(value_t e, value_t *penv)
value_t *rest; value_t *rest;
cons_t *c; cons_t *c;
symbol_t *sym; symbol_t *sym;
u_int32_t saveSP; uint32_t saveSP;
int i, nargs, noeval=0; int i, nargs, noeval=0;
number_t s, n; number_t s, n;