Lisp1.5 on PDP1

Introduction

 

In one of the subjects I had at university Lisp was taught. This language always seemed very interesting to me, because of its elegance and simplicity. In these last few months, I read more and more about Lisp for two main reasons, it is one of the languages that are being built on top of the Parrot virtual machine, and the other reason, is that some colleagues are getting me into Emacs, and the emacs extension language is a variant of Lisp. Well, there is also another fundamental reason, and that is that on all the machines (OSes) that seem interesting to me there are versions of lisp, examples: Multics(maclisp), ITS(maclisp), TOPS-10, TOPS-20(interlisp, maclisp), VAX(franz lisp), Apollo(T), etc..

.. And one of the best ways to see Lisp, is perhaps by trying it on old architectures, so here we are going to try it on a PDP1.  This version of Lisp is from February 23, 1964, it was written by L. Peter Deutsch and is one of the first for general use and the first for interactive use. It is worth noting that it is written entirely in assembler, and leaving out the comments and the separator lines it takes up about fifteen hundred lines of code.

 

Installing SIMH

 

As usual, we are going to use SIMH to emulate the PDP1. I very much doubt that anyone has a real PDP1, as far as is known, only three functional systems remain,  and they are at the CHM.

Installing SIMH is no problem at all, except that a BIN directory is needed and that it needs to be linked with the «librt» library, which by default does not come with SIMH.

That is why, instead of a package, we will download the latest version of SIMH, compile it and install it somewhere that is in our PATH (for example /usr/local/bin,  change it to the consumer’s taste).

 

Note: We install not only the PDP1 emulator, but all of the emulators, since we could make use of them later on.

 

mkdir -p ~/emuladores/simh
cd ~/emuladores/simh
wget http://simh.trailing-edge.com/sources/simhv37-3.zip
unzip simhv37-3.zip
mkdir BIN
mv makefile makefile.orig
cat makefile.orig | sed s/c99/"c99 -lrt"/ > makefile
make
sudo cp BIN/* /usr/local/bin

These commands will download the latest version of SIMH, compile the sources and  install the resulting binaries in /usr/local/bin .

NOTE: Bob Supknik, the author of SIMH, has recently announced that he is going to release a new version of SIMH, possibly in a week (today is June 9, 2008). The new version will already come patched…

 
With this we will already have the emulator of the PDP1 machine ready.

Downloading the Lisp1.5 sources

 

This version of Lisp is available as a software package ready to work on the SIMH emulator, so the only thing we will have to do is download it into our working directory and unpack it:

mkdir -p ~/emuladores/pdp1-lisp
cd ~/emuladores/pdp1-lisp
wget http://simh.trailing-edge.com/kits/lispswre.zip
unzip lispswre.zip 

 

The package comes with the Lisp source code, the .mac file, as well as an image ready to load into the emulator. I find it more interesting to assemble the code and create that image ourselves, since a cross assembler comes in the package. We only have to compile the assembler beforehand:

 

rm lisp.rim
cc macro1.c -o macro1
./macro1 lisp.mac

 

Running Lisp on the PDP1 machine

 

Before being able to use the emulator with the Lisp image, there are some previous steps to follow, we launch the emulator…

 

pdp1

PDP-1 simulator V3.7-2
sim> 

 

And we type the sequences… (we type what is in bold):

 

set cpu mdv
load lisp.rim
deposit extm_init 1
run

       HALT INSTRUCTION, PC: 002353 (CLA LAT CLI)

deposit tw 7777
cont

       HALT INSTRUCTION, PC: 002357 (CLA LAT)

deposit tw 400
cont

        HALT INSTRUCTION, PC: 000005 (STF5)

deposit ss 2
save lisp.sav
cont

 

The moment we type the last cont, we are already in the read-eval loop, so we can already pass it expressions ..

 

(car (quote (a b c d))) --- detras del ultimo parentesis pulsar espacio
a 

(cdr (quote (a b c d))) 
(b c d) 

oblist 
(d c b a atom car cdr cond cons eq gensym greaterp list minus n
umberp stop prin1 quotient rplaca rplacd terpri prog return go s
etq sassoc plus times logand logor xeq loc null quote lambda apv
al subr expr fsubr fexpr t oblist read eval print nil) 

(rplaca (quote (nil x y))
(quote (a b)))
 ((a b) x y) 

 

To get out of the emulator you only have to press ^e and then type exit:

 

oblist
 
(atom car cdr cond cons eq gensym greaterp list minus numberp s
top prin1 quotient rplaca rplacd terpri prog return go setq sass
oc plus times logand logor xeq loc null quote lambda apval subr 
expr fsubr fexpr t oblist read eval print nil) ^e
Simulation stopped, PC: 001133 (SZS5)
sim> exit
Goodbye
paco@linux:~/emuladores/pdp1-lisp$

 

So that the next time we want to play with Lisp we do not have to type the configuration part, we can take advantage of the fact that we made an image in lisp.sav, so we will only have to restore it. In addition, the loading of the parameters can be automated, using the pdp1.ini file:

 

cat > pdp1.ini
restore lisp.sav
cont -- tecleamos ^Z
paco@linux:~/emuladores/pdp1-lisp$ pdp1

PDP-1 simulator V3.7-2
oblist 
(atom car cdr cond cons eq gensym greaterp list minus numberp s
top prin1 quotient rplaca rplacd terpri prog return go setq sass
oc plus times logand logor xeq loc null quote lambda apval subr 
expr fsubr fexpr t oblist read eval print nil) 

 

PDP1 Lisp functions

 

  • atom
  • car
  • cdr
  • cond x y
  • CONS x y
  • eq x y
  • eval x
  • gensym
  • greaterp x y
  • go
  • list
  • loc x
  • logand x y
  • logor x y
  • minus x
  • null x
  • numberp x
  • plus x y
  • prin1 x
  • print
  • prog
  • quote
  • quotient x y
  • read
  • return
  • rplaca
  • rplacd
  • sassoc
  • setq
  • stop x
  • terpri
  • times x y
  • xeq c a i

 

Objects

    

  • oblist
  • nil
  • t
  • expr
  • subr
  • fexpr
  • fsubr
  • apval