| 1 |
;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil; Package: SYSTEM -*- |
| 2 |
;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab: |
| 3 |
|
| 4 |
;;;; |
| 5 |
;;;; Copyright (c) 1984, Taiichi Yuasa and Masami Hagiya. |
| 6 |
;;;; Copyright (c) 1990, Giuseppe Attardi. |
| 7 |
;;;; Copyright (c) 2001, Juan Jose Garcia Ripoll. |
| 8 |
;;;; |
| 9 |
;;;; See file 'LICENSE' for the copyright details. |
| 10 |
|
| 11 |
;;;; Exporting external symbols of LISP package |
| 12 |
|
| 13 |
(eval-when (eval compile load) |
| 14 |
(si::select-package "SI")) |
| 15 |
|
| 16 |
;;; ---------------------------------------------------------------------- |
| 17 |
;;; |
| 18 |
(*make-special '*dump-defun-definitions*) |
| 19 |
(setq *dump-defun-definitions* nil) |
| 20 |
(*make-special '*dump-defmacro-definitions*) |
| 21 |
(setq *dump-defmacro-definitions* *dump-defun-definitions*) |
| 22 |
|
| 23 |
;; This is needed only when bootstrapping ECL using ECL-MIN |
| 24 |
(eval-when (eval) |
| 25 |
(si::fset 'ext:register-with-pde |
| 26 |
#'(ext::lambda-block ext:register-with-pde (whole env) |
| 27 |
(let* ((definition (second whole)) |
| 28 |
(output-form (third whole))) |
| 29 |
`(if ext:*register-with-pde-hook* |
| 30 |
(funcall ext:*register-with-pde-hook* |
| 31 |
(copy-tree *source-location*) |
| 32 |
,definition |
| 33 |
,output-form) |
| 34 |
,output-form))) |
| 35 |
t) |
| 36 |
(si::fset 'defun |
| 37 |
#'(ext::lambda-block defun (def env) |
| 38 |
(let* ((name (second def)) |
| 39 |
(function `#'(ext::lambda-block ,@(cdr def)))) |
| 40 |
(when *dump-defun-definitions* |
| 41 |
(print function) |
| 42 |
(setq function `(si::bc-disassemble ,function))) |
| 43 |
(ext:register-with-pde def `(si::fset ',name ,function)))) |
| 44 |
t) |
| 45 |
(si::fset 'in-package |
| 46 |
#'(ext::lambda-block in-package (def env) |
| 47 |
`(eval-when (eval compile load) |
| 48 |
(si::select-package ,(string (second def))))) |
| 49 |
t) |
| 50 |
) |
| 51 |
|
| 52 |
;; |
| 53 |
;; This is also needed for booting ECL. In particular it is required in |
| 54 |
;; defmacro.lsp. |
| 55 |
;; |
| 56 |
(defun filter-dolist-declarations (declarations) |
| 57 |
(declare (si::c-local)) |
| 58 |
(let ((a nil)) |
| 59 |
(mapc #'(lambda (clause) |
| 60 |
(when (not (and (consp clause) |
| 61 |
(or (eq (car clause) 'type) |
| 62 |
(eq (car clause) 'ignore)))) |
| 63 |
(setq a (cons clause a)))) |
| 64 |
declarations) |
| 65 |
(nreverse a))) |
| 66 |
|
| 67 |
(let ((f #'(ext::lambda-block dolist (whole env) |
| 68 |
(declare (ignore env)) |
| 69 |
(let (body pop finished control var expr exit) |
| 70 |
(setq body (rest whole)) |
| 71 |
(when (endp body) |
| 72 |
(simple-program-error "Syntax error in ~A:~%~A" 'DOLIST whole)) |
| 73 |
(setq control (first body) body (rest body)) |
| 74 |
(when (endp control) |
| 75 |
(simple-program-error "Syntax error in ~A:~%~A" 'DOLIST whole)) |
| 76 |
(setq var (first control) control (rest control)) |
| 77 |
(if (<= 1 (length control) 2) |
| 78 |
(setq expr (first control) exit (rest control)) |
| 79 |
(simple-program-error "Syntax error in ~A:~%~A" 'DOLIST whole)) |
| 80 |
(multiple-value-bind (declarations body) |
| 81 |
(process-declarations body nil) |
| 82 |
`(block nil |
| 83 |
(let* ((%dolist-var ,expr)) |
| 84 |
(si::while %dolist-var |
| 85 |
(let ((,var (car %dolist-var))) |
| 86 |
(declare ,@declarations) |
| 87 |
(tagbody ,@body) |
| 88 |
(setq %dolist-var (cons-cdr %dolist-var)))) |
| 89 |
,(when exit |
| 90 |
`(let ((,var nil)) |
| 91 |
(declare (ignorable ,var) |
| 92 |
,@(filter-dolist-declarations declarations)) |
| 93 |
,@exit))))))))) |
| 94 |
(si::fset 'dolist f t)) |
| 95 |
|
| 96 |
(let ((f #'(ext::lambda-block dotimes (whole env) |
| 97 |
(declare (ignore env)) |
| 98 |
(let (body pop finished control var expr exit) |
| 99 |
(setq body (rest whole)) |
| 100 |
(when (endp body) |
| 101 |
(simple-program-error "Syntax error in ~A:~%~A" 'DOTIMES whole)) |
| 102 |
(setq control (first body) body (rest body)) |
| 103 |
(when (endp control) |
| 104 |
(simple-program-error "Syntax error in ~A:~%~A" 'DOTIMES whole)) |
| 105 |
(setq var (first control) control (rest control)) |
| 106 |
(if (<= 1 (length control) 2) |
| 107 |
(setq expr (first control) exit (rest control)) |
| 108 |
(simple-program-error "Syntax error in ~A:~%~A" 'DOTIMES whole)) |
| 109 |
(multiple-value-bind (declarations body) |
| 110 |
(process-declarations body nil) |
| 111 |
(when (integerp expr) |
| 112 |
(setq declarations |
| 113 |
(cons `(type (integer 0 ,expr) ,var) declarations))) |
| 114 |
`(block nil |
| 115 |
(let* ((%dotimes-var ,expr) |
| 116 |
(,var 0)) |
| 117 |
(declare ,@declarations) |
| 118 |
(si::while (< ,var %dotimes-var) |
| 119 |
,@body |
| 120 |
(setq ,var (1+ ,var))) |
| 121 |
,@exit))))))) |
| 122 |
(si::fset 'dotimes f t)) |
| 123 |
|
| 124 |
(let ((f #'(ext::lambda-block do/do*-expand (whole env) |
| 125 |
(declare (ignore env)) |
| 126 |
(let (do/do* control test result vl step let psetq body) |
| 127 |
(setq do/do* (first whole) body (rest whole)) |
| 128 |
(if (eq do/do* 'do) |
| 129 |
(setq let 'LET psetq 'PSETQ) |
| 130 |
(setq let 'LET* psetq 'SETQ)) |
| 131 |
(when (endp body) |
| 132 |
(simple-program-error "Syntax error in ~A:~%~A" do/do* whole)) |
| 133 |
(setq control (first body) body (rest body)) |
| 134 |
(when (endp body) |
| 135 |
(simple-program-error "Syntax error in ~A:~%~A" do/do* whole)) |
| 136 |
(setq test (first body) body (rest body)) |
| 137 |
(when (endp test) |
| 138 |
(simple-program-error "Syntax error in ~A:~%~A" do/do* whole)) |
| 139 |
(setq result (rest test) test (first test)) |
| 140 |
(dolist (c control) |
| 141 |
(when (symbolp c) (setq c (list c))) |
| 142 |
(case (length c) |
| 143 |
((1 2) |
| 144 |
(setq vl (cons c vl))) |
| 145 |
(3 |
| 146 |
(setq vl (cons (butlast c) vl) |
| 147 |
step (list* (third c) (first c) step))) |
| 148 |
(t |
| 149 |
(simple-program-error "Syntax error in ~A:~%~A" do/do* whole)))) |
| 150 |
(multiple-value-bind (declarations real-body) |
| 151 |
(process-declarations body nil) |
| 152 |
`(BLOCK NIL |
| 153 |
(,let ,(nreverse vl) |
| 154 |
(declare ,@declarations) |
| 155 |
(sys::until ,test |
| 156 |
,@real-body |
| 157 |
,@(when step (list (cons psetq (nreverse step))))) |
| 158 |
,@(or result '(nil))))))))) |
| 159 |
(si::fset 'do f t) |
| 160 |
(si::fset 'do* f t)) |
| 161 |
|
| 162 |
(defun eval-feature (x &aux operator) |
| 163 |
(declare (si::c-local)) |
| 164 |
(cond ((symbolp x) |
| 165 |
(and (member x *features* :test #'eq) t)) |
| 166 |
((atom x) (error "~ is not allowed as a feature" x)) |
| 167 |
((not (symbolp (setq operator (first x)))) |
| 168 |
(error "~S is not a valid feature expression." x)) |
| 169 |
((eql operator :AND) |
| 170 |
(dolist (x (cdr x) t) (when (not (eval-feature x)) (return nil)))) |
| 171 |
((eql operator :OR) |
| 172 |
(dolist (x (cdr x) nil) (when (eval-feature x) (return t)))) |
| 173 |
((eql operator :NOT) |
| 174 |
(not (eval-feature (second x)))) |
| 175 |
(t (error "~S is not a valid feature expression." x)))) |
| 176 |
|
| 177 |
(defun do-read-feature (stream subchar arg test) |
| 178 |
(declare (si::c-local)) |
| 179 |
(when arg |
| 180 |
(error "Reading from ~S: no number should appear between # and ~A" |
| 181 |
stream subchar)) |
| 182 |
(let ((feature (let ((*package* (find-package "KEYWORD"))) |
| 183 |
(read stream t nil t)))) |
| 184 |
(if (and (not *read-suppress*) (eq (eval-feature feature) test)) |
| 185 |
(read stream t nil t) |
| 186 |
(let ((*read-suppress* t)) (read stream t nil t) (values))))) |
| 187 |
|
| 188 |
(defun sharp-+-reader (stream subchar arg) |
| 189 |
(do-read-feature stream subchar arg T)) |
| 190 |
|
| 191 |
(defun sharp---reader (stream subchar arg) |
| 192 |
(do-read-feature stream subchar arg NIL)) |
| 193 |
|
| 194 |
(si::readtable-lock (si::standard-readtable) nil) |
| 195 |
(set-dispatch-macro-character #\# #\+ 'sharp-+-reader) |
| 196 |
(set-dispatch-macro-character #\# #\+ 'sharp-+-reader (sys::standard-readtable)) |
| 197 |
(set-dispatch-macro-character #\# #\- 'sharp---reader) |
| 198 |
(set-dispatch-macro-character #\# #\- 'sharp---reader (sys::standard-readtable)) |
| 199 |
(si::readtable-lock (si::standard-readtable) t) |