Skip to content

Commit d0a501b

Browse files
committed
Too many changes to count, 64-bit now works.
1 parent f8d6fbf commit d0a501b

37 files changed

+8124
-5679
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*~
2+
*.o
3+
*.stamp
4+
/ls9
5+
/ls9.image
6+
/ls9-*.image
7+
/dump-image.sh
8+
/*_protos.h
9+
/ls9.c

Makefile

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
1-
A=lisp9.tgz
2-
R=lisp9-20200220.tgz
3-
CFLAGS= -g -O2
41

5-
all: ls9 ls9.image # prolog # lisp9.ps
2+
NOFAKE = tools/nofake
63

7-
ls9: ls9.c
8-
$(CC) $(CFLAGS) -o ls9 ls9.c
4+
CC = gcc
95

10-
ls9.image: ls9 ls9.ls9
11-
rm -f ls9.image
12-
echo "(dump-image \"ls9.image\")" | ./ls9 -q
6+
WIDTH = -m32
7+
# WIDTH = -m64
8+
9+
OPTFLAGS = -O2
10+
# OPTFLAGS = -O3
11+
# OPTFLAGS = -O0
12+
13+
WERROR = -pedantic -Werror -fmax-errors=5
14+
15+
CFLAGS = $(WIDTH) -ggdb3 $(OPTFLAGS) -std=c99 \
16+
-Wall -Wextra -Wstrict-prototypes -Wmissing-prototypes \
17+
-Wshadow -Wconversion -Wdeclaration-after-statement \
18+
-Wno-unused-parameter \
19+
$(WERROR)
20+
21+
all: ls9 # prolog # lisp9.ps
22+
23+
ls9.c: size_t_aux.nw ls9*.nw
24+
NOFAKE='$(NOFAKE)' $(NOFAKE).sh -L -Rls9.c -ols9.c size_t_aux.nw ls9*.nw
25+
26+
ls9_protos.h: ls9.c
27+
cproto -ev -DINSIDE_CPROTO ls9.c > .tmp.ls9_protos.h
28+
mv -f .tmp.ls9_protos.h ls9_protos.h
29+
chmod a-w ls9_protos.h
30+
31+
ls9.o: ls9.c ls9_protos.h
32+
$(CC) $(CFLAGS) -c ls9.c
33+
34+
ls9: ls9.o
35+
$(CC) $(CFLAGS) -o ls9 ls9.o
36+
CHMOD='chmod 0555' NOFAKE='$(NOFAKE)' $(NOFAKE).sh -Rdump-image.sh \
37+
ls9.nw ls9-scripts.nw -odump-image.sh
38+
./dump-image.sh
1339

1440
lisp9.tr: lisp9.txt
1541
./ls9 src/print.ls9 -T -C -p 60 -l 6 -m -4 -t "LISP9 REFERENCE MANUAL" \
@@ -36,11 +62,10 @@ prolog: ls9 src/prolog.ls9 src/prolog.pl9
3662
| ./ls9 -ql src/prolog.ls9
3763

3864
arc: clean
39-
tar cf - * | gzip -c9 >$A
65+
./archive.sh
4066

4167
dist: clean
42-
cd ..; tar -cvf - `cat lisp9/_nodist` lisp9 | gzip -9c >$R
43-
mv ../$R .
68+
./release.sh
4469

4570
csums:
4671
csum -u <_csums >_csums.new
@@ -50,5 +75,6 @@ mksums: clean
5075
find . -type f | grep -v _csums |grep -v $A | csum >_csums
5176

5277
clean:
53-
rm -f ls9 ls9.image *.oimage prolog lisp9.ps lisp9.tr lisp9.ps \
54-
$A $R a.out *.core
78+
rm -f ls9.c ls9_protos.h ls9 ls9.image ls9-*.image \
79+
dump-image.sh archive.sh release.sh *.oimage prolog \
80+
lisp9.ps lisp9.tr lisp9.ps $A $R a.out *.core

README

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11

2+
This is a fork of LISP9 based on lisp9-20200220.tgz from
3+
https://www.t3x.org/lsi/index.html and
4+
https://www.t3x.org/lisp9/index.html.
5+
6+
The canonical source for this version is at
7+
https://github.com/ctarbide/lisp9.
8+
9+
This version depends on cproto, from
10+
https://invisible-island.net/cproto/cproto.html.
11+
12+
Nils M Holm has many books (and code) on LISP and
13+
other advanced topics on https://www.t3x.org/.
14+
15+
The original README follows:
16+
17+
****************************************************************
18+
19+
220
LISP9 -- an experimental LISP system
321
Nils M Holm, 2018, 2019
422
In the public domain.

ls9-arith.nw

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
2+
<<ls9 macros>>=
3+
#define mkifix(v) mkfix((full)(v))
4+
@
5+
6+
<<ls9 init>>=
7+
P_plus = symref("+");
8+
P_minus = symref("-");
9+
P_times = symref("*");
10+
P_div = symref("div");
11+
P_rem = symref("rem");
12+
P_grtr = symref(">");
13+
P_gteq = symref(">=");
14+
P_less = symref("<");
15+
P_lteq = symref("<=");
16+
P_equal = symref("=");
17+
P_bitop = symref("bitop");
18+
@
19+
20+
<<ls9 impl>>=
21+
void fixover(char *who, full x, full y) {
22+
char b[100];
23+
24+
sprintf(b, "%s: fixnum overflow", who);
25+
error(b, cons(x, cons(y, NIL)));
26+
}
27+
28+
full add(full x, full y) {
29+
if (!fixp(x)) expect("+", "fixnum", x);
30+
if (!fixp(y)) expect("+", "fixnum", y);
31+
if (add_ovfl(fixval(x), fixval(y))) fixover("+", x, y);
32+
return mkifix((ifull)fixval(x) + (ifull)fixval(y));
33+
}
34+
35+
full xsub(full x, full y) {
36+
if (!fixp(x)) expect("-", "fixnum", x);
37+
if (!fixp(y)) expect("-", "fixnum", y);
38+
if (sub_ovfl(fixval(y), fixval(x))) fixover("+", y, x);
39+
return mkifix((ifull)fixval(y) - (ifull)fixval(x));
40+
}
41+
42+
full mul(full x, full y) {
43+
ifull a, b;
44+
45+
if (!fixp(x)) expect("*", "fixnum", x);
46+
if (!fixp(y)) expect("*", "fixnum", y);
47+
a = (ifull)fixval(x);
48+
b = (ifull)fixval(y);
49+
/*
50+
* Overflow of a*b is undefined, sooo
51+
*/
52+
/* Shortcuts, also protect later division */
53+
if (0 == a || 0 == b) return Zero;
54+
if (1 == a) return y;
55+
if (1 == b) return x;
56+
/* abs(IFULL_MIN) is undefined using two's complement, so */
57+
if (IFULL_MIN == a || IFULL_MIN == b) fixover("*", x, y);
58+
/* Catch the rest */
59+
/* Bug: result may not be IFULL_MIN
60+
*/
61+
if (abs_wrap(a) > IFULL_MAX / abs_wrap(b)) fixover("*", x, y);
62+
return mkifix(a * b);
63+
}
64+
65+
full intdiv(full x, full y) {
66+
if (!fixp(x)) expect("div", "fixnum", x);
67+
if (!fixp(y)) expect("div", "fixnum", y);
68+
if (0 == fixval(y)) error("div: divide by zero", UNDEF);
69+
return mkifix((ifull)fixval(x) / (ifull)fixval(y));
70+
}
71+
72+
full intrem(full x, full y) {
73+
if (!fixp(x)) expect("rem", "fixnum", x);
74+
if (!fixp(y)) expect("rem", "fixnum", y);
75+
if (0 == fixval(y)) error("rem: divide by zero", UNDEF);
76+
return mkifix((ifull)fixval(x) % (ifull)fixval(y));
77+
}
78+
79+
void grtr(full x, full y) {
80+
if (!fixp(x)) expect(">", "fixnum", x);
81+
if (!fixp(y)) expect(">", "fixnum", y);
82+
if ((ifull)fixval(y) <= (ifull)fixval(x)) stackset(Sp-1, NIL);
83+
}
84+
85+
void gteq(full x, full y) {
86+
if (!fixp(x)) expect(">=", "fixnum", x);
87+
if (!fixp(y)) expect(">=", "fixnum", y);
88+
if ((ifull)fixval(y) < (ifull)fixval(x)) stackset(Sp-1, NIL);
89+
}
90+
91+
void less(full x, full y) {
92+
if (!fixp(x)) expect("<", "fixnum", x);
93+
if (!fixp(y)) expect("<", "fixnum", y);
94+
if ((ifull)fixval(y) >= (ifull)fixval(x)) stackset(Sp-1, NIL);
95+
}
96+
97+
void lteq(full x, full y) {
98+
if (!fixp(x)) expect("<=", "fixnum", x);
99+
if (!fixp(y)) expect("<=", "fixnum", y);
100+
if ((ifull)fixval(y) > (ifull)fixval(x)) stackset(Sp-1, NIL);
101+
}
102+
103+
void equal(full x, full y) {
104+
/* fprintf(stderr, "**************** equal: %"PRIxFULL" %"PRIxFULL"\n", x, y); */
105+
if (!fixp(x)) expect("=", "fixnum", x);
106+
if (!fixp(y)) expect("=", "fixnum", y);
107+
if (fixval(y) != fixval(x)) stackset(Sp-1, NIL);
108+
}
109+
110+
full bitop(full x, full y, full o) {
111+
full i, op, a, b;
112+
113+
if (!fixp(o)) expect("bitop", "fixnum", o);
114+
if (!fixp(x)) expect("bitop", "fixnum", x);
115+
if (!fixp(y)) expect("bitop", "fixnum", y);
116+
op = fixval(o);
117+
b = fixval(x);
118+
a = i = fixval(y);
119+
switch (op) {
120+
case 0: a = 0; break;
121+
case 1: a = a & b; break;
122+
case 2: a = a & ~b; break;
123+
case 3: /* a = a; */ break;
124+
case 4: a = ~a & b; break;
125+
case 5: a = b; break;
126+
case 6: a = a ^ b; break;
127+
case 7: a = a | b; break;
128+
case 8: a = ~(a | b); break;
129+
case 9: a = ~(a ^ b); break;
130+
case 10: a = ~b; break;
131+
case 11: a = a | ~b; break;
132+
case 12: a = ~a; break;
133+
case 13: a = ~a | b; break;
134+
case 14: a = ~(a & b); break;
135+
case 15: a = (full)~0; break;
136+
case 16: a = a @<< b; break;
137+
case 17: a = i @>> b; break;
138+
case 18: a = a @>> b; break;
139+
default: error("bitop: invalid opcode", o);
140+
break;
141+
}
142+
return mkfix(a);
143+
}
144+
@

0 commit comments

Comments
 (0)