Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update all tiny interpreters for 64-bit builds #59

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
/llt/*.o
/llt/*.a
/flisp.boot.bak
/tiny/lisp
/tiny/lisp-nontail
/tiny/lisp2
/tiny/lispf
36 changes: 22 additions & 14 deletions tiny/lisp-nontail.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,24 @@
Public Domain
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include <setjmp.h>
#include <stdarg.h>
#include <ctype.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef u_int32_t value_t;
#ifdef __LP64__
lassik marked this conversation as resolved.
Show resolved Hide resolved
#define NUM_FORMAT "%" PRId64
typedef uint64_t value_t;
typedef int64_t number_t;
#else
#define NUM_FORMAT "%" PRId32
typedef uint32_t value_t;
typedef int32_t number_t;
#endif

typedef struct {
value_t car;
Expand Down Expand Up @@ -87,7 +95,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))
Expand Down Expand Up @@ -179,7 +187,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)
{
Expand Down Expand Up @@ -262,7 +270,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);
Expand Down Expand Up @@ -305,7 +313,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];

Expand Down Expand Up @@ -376,7 +384,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;
Expand Down Expand Up @@ -427,7 +435,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
Expand Down Expand Up @@ -498,7 +506,7 @@ void print(FILE *f, value_t v)
value_t cd;

switch (tag(v)) {
case TAG_NUM: fprintf(f, "%d", numval(v)); break;
case TAG_NUM: fprintf(f, NUM_FORMAT, numval(v)); break;
case TAG_SYM: fprintf(f, "%s", ((symbol_t*)ptr(v))->name); break;
case TAG_BUILTIN: fprintf(f, "#<builtin %s>",
builtin_names[intval(v)]); break;
Expand Down Expand Up @@ -538,7 +546,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;

Expand Down
35 changes: 19 additions & 16 deletions tiny/lisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@
Public Domain
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include <setjmp.h>
#include <stdarg.h>
#include <ctype.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef __LP64__
typedef u_int64_t value_t;
#define NUM_FORMAT "%" PRId64
typedef uint64_t value_t;
typedef int64_t number_t;
#else
typedef u_int32_t value_t;
#define NUM_FORMAT "%" PRId32
typedef uint32_t value_t;
typedef int32_t number_t;
#endif

Expand Down Expand Up @@ -92,7 +95,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))
Expand Down Expand Up @@ -184,7 +187,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)
{
Expand Down Expand Up @@ -267,7 +270,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);
Expand Down Expand Up @@ -310,7 +313,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];

Expand Down Expand Up @@ -382,7 +385,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;
Expand Down Expand Up @@ -430,7 +433,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
Expand Down Expand Up @@ -501,7 +504,7 @@ void print(FILE *f, value_t v)
value_t cd;

switch (tag(v)) {
case TAG_NUM: fprintf(f, "%ld", numval(v)); break;
case TAG_NUM: fprintf(f, NUM_FORMAT, numval(v)); break;
case TAG_SYM: fprintf(f, "%s", ((symbol_t*)ptr(v))->name); break;
case TAG_BUILTIN: fprintf(f, "#<builtin %s>",
builtin_names[intval(v)]); break;
Expand Down Expand Up @@ -544,7 +547,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;

Expand Down Expand Up @@ -979,7 +982,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;
Expand Down
54 changes: 31 additions & 23 deletions tiny/lisp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,24 @@
Public Domain
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include <setjmp.h>
#include <stdarg.h>
#include <ctype.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef u_int32_t value_t;
#ifdef __LP64__
#define NUM_FORMAT "%" PRId64
typedef uint64_t value_t;
typedef int64_t number_t;
#else
#define NUM_FORMAT "%" PRId32
typedef uint32_t value_t;
typedef int32_t number_t;
#endif

typedef struct {
value_t car;
Expand Down Expand Up @@ -111,7 +119,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))
Expand All @@ -121,7 +129,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);

Expand Down Expand Up @@ -221,8 +229,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)
Expand Down Expand Up @@ -328,7 +336,7 @@ void gc(int mustgrow)
{
static int grew = 0;
void *temp;
u_int32_t i;
uint32_t i;
readstate_t *rs;

curheap = tospace;
Expand Down Expand Up @@ -366,7 +374,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;
}
Expand All @@ -391,7 +399,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];

Expand Down Expand Up @@ -463,7 +471,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;
Expand Down Expand Up @@ -496,7 +504,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);
}
Expand Down Expand Up @@ -560,7 +568,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
Expand Down Expand Up @@ -601,7 +609,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);
Expand Down Expand Up @@ -759,7 +767,7 @@ static void do_print(FILE *f, value_t v, int princ)
char *name;

switch (tag(v)) {
case TAG_NUM: fprintf(f, "%d", numval(v)); break;
case TAG_NUM: fprintf(f, NUM_FORMAT, numval(v)); break;
case TAG_SYM:
name = ((symbol_t*)ptr(v))->name;
if (princ)
Expand Down Expand Up @@ -856,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
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;

Expand Down Expand Up @@ -1200,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 (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 {
Expand Down Expand Up @@ -1354,7 +1362,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 {
Expand All @@ -1376,7 +1384,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;
Expand Down
Loading