LISTING FOR >udd>sm>ds>w>ml>lisp_defmacro_ COMPILED BY Multics LISP Compiler, Version 2.13c, July 11, 1983 ON 05/05/00 1835.8 mdt Fri IN BEHALF OF Schroth.SysMaint.m ;;; ************************************************************** ;;; * * ;;; * Copyright, (C) Massachusetts Institute of Technology, 1982 * ;;; * * ;;; ************************************************************** ;; -*- Mode: Lisp; Lowercase: True -*- ;; Written: January 1980 by Alan Bawden ;; Modified: March 1981 by Carl Hoffman ;; Observe compiler "macros" flag. Don't output an argument count check when ;; the lambda list is (&optional ... &rest ...) or (&rest ...). ;; Modified: March 1982 by Alan Bawden ;; Now includes a macro macro. That is, (macro foo (x) ...) is like ;; the good old (defun foo macro (x) ...). ;; Modified: October 1982 by Carl Hoffman for installation in bound_lisp_library_ (%include backquote) (%include destructuring_let) (declare (macros t)) (declare (special macros)) (declare (*expr let-macro-flush-declares let-macro-cons-declares)) ;; Note: The "let" package must also be loaded at run time since defmacro ;; expands into "let" forms. defmacro.incl.lisp does this. (declare (special *rest* *normal* *optional* *body*)) (defun grok-&keyword-list (pattern body) (prog (pat x) (setq pat pattern) (setq *body* body) norm (cond ((null pat) (return t)) ((atom pat) (setq *rest* pat) (return t))) (setq x (car pat)) (cond ((eq x '&optional) (go opt)) ((memq x '(&rest &body)) (go rst)) ((eq x '&aux) (go ax))) (setq *normal* (cons x *normal*) pat (cdr pat)) (go norm) opt (cond ((null (setq pat (cdr pat))) (return t)) ((atom pat) (setq *rest* pat) (return t))) (setq x (car pat)) (cond ((eq x '&optional) (go barf)) ((memq x '(&rest &body)) (go rst)) ((eq x '&aux) (go ax))) (cond ((atom x) (setq *optional* (cons (list x nil) *optional*))) (t (setq *optional* (cons x *optional*)))) (go opt) rst (or (and (not (null (setq pat (cdr pat)))) (not (atom pat)) (atom (setq x (car pat)))) (go barf)) (setq *rest* x) (or (setq pat (cdr pat)) (return t)) (and (or (atom pat) (not (eq (car pat) '&aux))) (go barf)) ax (setq *body* `((let* ,(cdr pat) . ,*body*))) (return t) barf (error "Bad &keyword argument list: " pattern 'fail-act))) (defprop defmacro defmacro/ macro macro) (defun defmacro/ macro (x) (displace x (let (((nil name pattern . body) x) (var (gensym)) *normal* *optional* *rest* *body* nname check-args guts tail) ;; make_atom returns an interned result. (setq nname (make_atom (catenate name " macro"))) (grok-&keyword-list pattern (let-macro-flush-declares body)) (setq check-args (length *normal*)) ;; nreconc is broken. This uses esoteric features of nconc: ;; (nconc '(a b c) 'd) --> (a b c . d) ;; (nconc nil 'x) -> x (setq *normal* (nconc (nreverse *normal*) (cond ((null *optional*) *rest*) (t (setq tail (gensym)))))) (setq check-args (let ((cnd (cond ((null *rest*) (cond ((null tail) `(= (length ,var) ,(1+ check-args))) (t `(and (> (length ,var) ,check-args) (< (length ,var) ,(+ 2 check-args (length *optional*))))))) ;; If we have a rest var, then there is no upper bound. ;; If *normal* is atomic, then there is no lower bound. ((and (atom *normal*) *rest*) nil) (t `(> (length ,var) ,check-args))))) (and cnd `((or ,cnd (error "Wrong number of args in macro form: " ,var 'fail-act)))))) (setq guts `((,var) .,(let-macro-cons-declares body `((comment args = ,pattern) ,@check-args (displace ,var (let ((,*normal* (cdr ,var))) . ,(cond (tail (do ((o *optional* (cdr o)) (ps nil (cond ((null (cddar o)) ps) (t (cons (caddar o) ps)))) (b (cond (*rest* `((let ((,*rest* (cdr ,tail))) . ,*body*))) (t *body*)) `((let ((,(caar o) (cond (,(cond ((null (cdr o)) tail) (t `(setq ,tail (cdr ,tail)))) ,@(cond ((null (cddar o)) nil) (t `((setq ,(caddar o) t)))) (car ,tail)) (t ,(cadar o))))) . ,b)))) ((null o) (cond ((null ps) b) (t `((let ,ps . ,b))))))) (t *body*)))))))) `(eval-when ,(cond ((and (boundp 'macros) macros) '(eval load compile)) (t '(eval compile))) (defprop ,name ,nname macro) (defun ,nname . ,guts))))) ;;;Probably defmacro should use this, but lets not toy with success. (defprop macro macro/ macro macro) (defun macro/ macro (x) (displace x (let (;; make_atom returns an interned result. (nname (make_atom (catenate (cadr x) " macro")))) `(eval-when ,(cond ((and (boundp 'macros) macros) `(eval load compile)) (t `(eval compile))) (defprop ,(cadr x) ,nname macro) (defun ,nname . ,(cddr x)))))) (sstatus feature defmacro) INCLUDE FILE >ldd>incl>backquote.incl.lisp ;;; ;;; backquote.incl.lisp - BSG 10/9/79 ;;; Loads lisp_backquote_ into either the compiler or interpreter ;;; environment. ;;; ;;; Modified 10/30/82 by Richard Lamson to use eval-when and ;;; (status feature backquote) ;;; (eval-when (eval compile) (or (status feature backquote) (load (catenate (car (namelist (truename infile))) ">lisp_backquote_")))) INCLUDE FILE >ldd>incl>destructuring_let.incl.lisp ;; -*- Mode: Lisp; Lowercase: True -*- ;; destructuring_let.incl.lisp - Loads lisp_destructuring_let_ into either ;; the compiler or interpreter environment. ;; Written: October 1982 by Carl Hoffman (eval-when (eval compile) (or (status feature destructuring_let) (load (catenate (car (namelist (truename infile))) ">lisp_destructuring_let_")))) Functions Defined Name Offset Offset Name defmacro macro 177 0 grok-&keyword-list grok-&keyword-list 0 177 defmacro macro macro macro 1151 1151 macro macro Functions Referenced append gensym let-macro-flush-declares catenate grok-&keyword-list make_atom displace length nconc error let-macro-cons-declares nreverse ----------------------------------------------------------- Historical Background This edition of the Multics software materials and documentation is provided and donated to Massachusetts Institute of Technology by Group BULL including BULL HN Information Systems Inc. as a contribution to computer science knowledge. This donation is made also to give evidence of the common contributions of Massachusetts Institute of Technology, Bell Laboratories, General Electric, Honeywell Information Systems Inc., Honeywell BULL Inc., Groupe BULL and BULL HN Information Systems Inc. to the development of this operating system. Multics development was initiated by Massachusetts Institute of Technology Project MAC (1963-1970), renamed the MIT Laboratory for Computer Science and Artificial Intelligence in the mid 1970s, under the leadership of Professor Fernando Jose Corbato. Users consider that Multics provided the best software architecture for managing computer hardware properly and for executing programs. Many subsequent operating systems incorporated Multics principles. Multics was distributed in 1975 to 2000 by Group Bull in Europe , and in the U.S. by Bull HN Information Systems Inc., as successor in interest by change in name only to Honeywell Bull Inc. and Honeywell Information Systems Inc. . ----------------------------------------------------------- Permission to use, copy, modify, and distribute these programs and their documentation for any purpose and without fee is hereby granted,provided that the below copyright notice and historical background appear in all copies and that both the copyright notice and historical background and this permission notice appear in supporting documentation, and that the names of MIT, HIS, BULL or BULL HN not be used in advertising or publicity pertaining to distribution of the programs without specific prior written permission. Copyright 1972 by Massachusetts Institute of Technology and Honeywell Information Systems Inc. Copyright 2006 by BULL HN Information Systems Inc. Copyright 2006 by Bull SAS All Rights Reserved