home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 June
/
SIMTEL_0692.cdr
/
msdos
/
aijournl
/
ai_feb87.arc
/
COMPIL.FEB
< prev
next >
Wrap
Text File
|
1987-01-29
|
5KB
|
170 lines
Compiling LISP Procedures
by Bruce A. Pumplin
February 1987 LISP issue
Tables and Listings
Table 1.
MOVEI Ri CONST Load register i with a constant
( the load immediate instruction )
PUSH SP Ri Push the contents of Ri onto the stack
POP SP Ri Pop the top of the stack into Ri
PUSHJ SP LOC The subroutine entry instruction:
Push the current contents of
the program counter onto the
stack and branch to memory loc-
ation LOC
CALL LOC The same as PUSHJ SP LOC
POPJ SP The subroutine return instruction:
Pop the top of the stack into
the program counter
MOVE Ri LOC Load Ri with the contents of LOC
MOVE Ri Rj Load Ri with the contents of Rj
MOVEM Ri LOC Store the contents of Ri in memory
location LOC
JUMP LOC Unconditional branch to memory location
LOC
JUMPF Ri LOC Branch to memory location LOC if Ri
contains the constant False
JUMPT Ri LOC Branch to memory location LOC if Ri
does not contain the constant False
(Note: anything other than False is
assumed to be True)
Listing 1.
;;; THE PRIMARY PROCEDURES
(DEFUN COMPEXP (EXP)
(COND ((ISCONST EXP)
(LIST (MKSEND 1 EXP)))
(T (COMPAPPLY (FUNC EXP)
(COMPLIS (ARGLIST EXP))
(LENGTH (ARGLIST EXP))))
) )
(DEFUN COMPLIS (U)
(COND ((NULL U) '())
((NULL (REST U))
(COMPEXP (FIRST U)))
(T (APPEND-3 (COMPEXP (FIRST U))
(LIST (MKALLOC 1))
(COMPLIS (REST U))))
) )
(DEFUN COMPAPPLY (FN VALS N)
(APPEND-3 VALS
(MKLINK N)
(LIST (MKCALL FN))
) )
Listing 2.
;;; THE RECOGNIZER PROCEDURE
(DEFUN ISCONST (X)
(OR (NUMBERP X)
(EQ X T)
(EQ X NIL)
(AND (NOT (ATOM X))
(EQ (FIRST X) 'QUOTE))
) )
;;; THE SELECTOR PROCEDURES
(DEFUN FUNC (X) (FIRST X))
(DEFUN ARGLIST (X) (REST X))
;;; THE CONSTRUCTOR PROCEDURES
(DEFUN MKSEND (DEST VAL) (LIST 'MOVEI DEST VAL))
(DEFUN MKALLOC (DEST) (LIST 'PUSH 'SP DEST))
(DEFUN MKCALL (FN) (LIST 'CALL FN))
(DEFUN MKLINK (N)
(COND ((= N 1) '())
(T (CONCAT (MKMOVE N 1)
(MKLINK1 (SUB1 N))))
) )
(DEFUN MKLINK1 (N)
(COND ((ZEROP N) '())
(T (CONCAT (MKPOP N)
(MKLINK1 (SUB1 N))))
) )
(DEFUN MKPOP (N) (LIST 'POP 'SP N))
(DEFUN MKMOVE (DEST VAL) (LIST 'MOVE DEST VAL))
Listing 3.
;;; THE AUXILIARY PROCEDURES
(DEFUN FIRST (X) (CAR X))
(DEFUN REST (X) (CDR X))
(DEFUN CONCAT (ELEMENT SEQUENCE)
(COND ((LISTP SEQUENCE)
(CONS ELEMENT SEQUENCE))
(T '())
) )
(DEFUN APPEND-3 (L1 L2 L3)
(APPEND L1 (APPEND L2 L3))
)
(DEFUN LISP (X)
(COND ((CONSP X) T)
((NULL X) T)
(T NIL)
) )
Listing 4.
STEP INSTRUCTION R1 R2 STACK (Top...Bottom)
-----------------------------------------------------------------
0 ?? ?? ---
1 (MOVEI 1 (QUOTE A)) A ?? ---
2 (CALL G) A Return-Address
(G A) ?? ---
3 (PUSH SP 1) (G A) ?? (G A)
4 (MOVEI 1 (QUOTE B)) B ?? (G A)
5 (CALL H) B ?? Return-Address (G A)
(H B) ?? (G A)
6 (MOVE 2 1) (H B) (H B) (G A)
7 (POP SP 1) (G A) (H B) ---
8 (CALL F) (G A) (H B) Return-Address
(F ) ?? ---
8 (CALL F) (G A) (H B) Return-Address