Skip to content

Commit 6f9b8b0

Browse files
committed
Added lispkitc shell script to shortcut compiling.
Added install targets to makefile. Update the docs to include lispkitc info.
1 parent 0d6ae39 commit 6f9b8b0

File tree

7 files changed

+120
-26
lines changed

7 files changed

+120
-26
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.o
2+
*.gcda
3+
*.gcno

Makefile

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
SOURCE_ID := $(shell date +%Y%m%d)
44

5+
PREFIX = /usr/local
6+
MANDIR = $(PREFIX)/share/man
7+
58
CC = gcc
69
CFLAGS += -Wall
710
CFLAGS += -pedantic
@@ -24,6 +27,9 @@ OBJ = $(SRC:.c=.o)
2427

2528
BIN = lispkit
2629

30+
COMPILER_SRC = lispkit-compiler.lks
31+
COMPILER_BIN = lispkit-compiler.bin
32+
2733
all: $(BIN)
2834

2935
.c.o:
@@ -33,8 +39,31 @@ $(BIN): $(OBJ)
3339
$(CC) -o $@ $^ $(LDFLAGS)
3440
@size $(BIN)
3541

42+
install: $(BIN) $(BIN)c
43+
install -v $(BIN) $(PREFIX)/bin
44+
install -v $(BIN)c $(PREFIX)/bin
45+
install -v -d $(MANDIR)/man1
46+
install -v -m 0644 lispkit.1 $(MANDIR)/man1
47+
install -v -d $(PREFIX)/share/lispkit
48+
install -v $(COMPILER_SRC) $(PREFIX)/share/lispkit
49+
install -v $(COMPILER_BIN) $(PREFIX)/share/lispkit
50+
51+
$(BIN)c: $(BIN)c.in
52+
sed "s|COMPILER=|COMPILER=$(PREFIX)/share/lispkit/lispkit-compiler.bin|" lispkitc.in > $@
53+
54+
uninstall:
55+
rm -vf $(PREFIX)/bin/$(BIN)
56+
rm -vf $(PREFIX)/bin/$(BIN)c
57+
rm -vr $(MANDIR)/man1/lispkit.1
58+
rm -vf $(PREFIX)/share/lispkit/$(COMPILER_SRC)
59+
rm -vf $(PREFIX)/share/lispkit/$(COMPILER_BIN)
60+
rm -vr $(PREFIX)/share/lispkit
61+
62+
help:
63+
groff -man -Tascii lispkit.1 | less -R
64+
3665
%.o: %.lisp
37-
./$(BIN) compiler.ascii $< | tee $@
66+
./$(BIN) $(COMPILER_BIN) $< | tee $@
3867

3968
clean:
4069
rm -f $(OBJ) $(BIN) *.gcda *.gcno *.gcov *.o examples/*.o
@@ -43,18 +72,18 @@ test: $(BIN)
4372
./test.sh
4473

4574
examples:
46-
for d in `ls examples/*.lisp`; do \
47-
./$(BIN) compiler.ascii $$d > $$d.o; \
75+
for d in $(shell ls examples/*.lisp); do \
76+
./$(BIN) $(COMPILER_BIN) $$d > $$d.o; \
4877
done;
4978

5079
bootstrap:
51-
./$(BIN) compiler.ascii compiler.txt.ascii > .compiler.out.tmp
52-
cat compiler.ascii | tr '\n' ' ' > .compiler.orig.tmp
80+
./$(BIN) $(COMPILER_BIN) $(COMPILER_SRC) > .compiler.out.tmp
81+
cat $(COMPILER_BIN) | tr '\n' ' ' > .compiler.orig.tmp
5382
diff -w .compiler.orig.tmp .compiler.out.tmp
5483
rm .compiler.out.tmp .compiler.orig.tmp
5584

5685
archive:
5786
git archive --prefix=lispkit-$(SOURCE_ID)/ HEAD | gzip > lispkit-$(SOURCE_ID).tar.gz
5887

59-
.PHONY: clean all test archive examples
88+
.PHONY: clean all test archive examples bootstrap
6089

README

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,43 @@ attempt some of the examples from table 12.1 and 12.2 in the book.
1313

1414
make test
1515

16-
To compile a lispkit program, where [filename] is the name of
17-
a file containing lispkit source code:
1816

19-
./lispkit compiler.ascii [filename]
17+
INSTALLATION
18+
------------
2019

21-
To compile one of the examples, examples/square.lisp:
20+
To install lispkit to your system:
2221

23-
make examples/square.o
22+
[sudo] make install
2423

25-
You should see some output like:
24+
To remove lispkit:
2625

27-
( 3 ( 1 ( 0 . 0 ) 1 ( 0 . 0 ) 17 5 ) 4 21 )
26+
[sudo] make uninstall
27+
28+
29+
USING
30+
-----
31+
32+
To compile a lispkit program, use the lispkitc script:
33+
34+
lispkitc infile [outfile]
35+
36+
37+
For example:
38+
39+
lispkitc examples/square.lisp square.bin
40+
41+
42+
To run a lispkit program:
43+
44+
lispkit program [argument]
45+
46+
47+
If no argument file is given, lispkit will read from stdin.
48+
49+
50+
For example:
51+
52+
echo 16 | lispkit square.bin
2853

29-
Then run it, with no second argument lispkit will read the input
30-
from stdin.
3154

32-
echo 5 | ./lispkit examples/square.o
33-
25
3455

File renamed without changes.
File renamed without changes.

lispkit.1

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,49 @@
11
.\" groff -man -Tascii lispkit.1 | less
22
.TH lispkit 1
33
.SH "NAME"
4-
Lispkit \- a functional programming language similar to Lisp
4+
lispkit \- functional programming language interpreter
5+
.br
6+
lispkitc \- lispkit compiler script
57
.SH "SYNOPSIS"
68
.B lispkit
7-
.I function-file
9+
.I program
810
[
9-
.I arguments-file
11+
.I argument
12+
]
13+
.br
14+
.B lispkitc
15+
.I infile
16+
[
17+
.I outfile
1018
]
1119
.SH "OPTIONS"
12-
.IP function-file
20+
.IP program
1321
A file containing lispkit machine code.
14-
.IP argument-file
22+
.IP argument
1523
A file containing lispkit arguments.
16-
If not present, arguments can be entered through stdin.
24+
If absent will read arguments from stdin.
25+
.IP infile
26+
A lispkit source file.
27+
.IP outfile
28+
A compiled lispkit program.
29+
If absent will write program to stdout.
30+
.SH "DESCRIPTION"
31+
Lispkit is a SECD based machine for interpreting
32+
programs made up of symbolic expressions
33+
and simple functions such as cons, car, cdr,
34+
similar to Lisp.
1735
.SH "FILES"
18-
.IP compiler
36+
.IP lispkit-compiler.bin
1937
Lispkit compiler in machine code form
20-
.IP compiler
38+
.IP lispkit-compiler.lks
2139
Lispkit compiler in source code form
2240
.SH "ENVIRONMENT"
2341
.B LISPKIT_MEMORY
42+
Maximum number of object cells that Lispkit will allocate.
2443
.SH "AUTHOR"
2544
This program is based on the Lispkit described in
2645
"Functional Programming Application and Implementation",
2746
by Peter Henderson (ISBN 0-13-331579-7).
28-
This Lispkit and man page by A. Carl Douglas (carl.douglas@gmail.com).
47+
This Lispkit and man page by
48+
A. Carl Douglas (carl.douglas@gmail.com).
2949

lispkitc.in

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
COMPILER=
4+
5+
LISPKIT=$(which lispkit)
6+
7+
if [[ $# == 0 ]]; then
8+
echo lispkitc infile [outfile];
9+
exit 0
10+
fi
11+
12+
if [[ $LISPKIT == '' ]]; then
13+
LISPKIT=./lispkit
14+
fi
15+
16+
if [[ $2 != '' ]]; then
17+
$LISPKIT $COMPILER $1 > $2
18+
else
19+
$LISPKIT $COMPILER $1
20+
fi
21+

0 commit comments

Comments
 (0)