| 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 |
;;;; Program Development Environment |
| 12 |
|
| 13 |
(in-package "SYSTEM") |
| 14 |
|
| 15 |
(defun lisp-implementation-type () |
| 16 |
"Args: () |
| 17 |
Returns the string \"ECL\"." |
| 18 |
"ECL") |
| 19 |
|
| 20 |
;;; Compiler functions. |
| 21 |
|
| 22 |
(defun autoload (pathname &rest function-names) |
| 23 |
(dolist (fname function-names) |
| 24 |
(let ((thename fname)) |
| 25 |
(fset fname #'(lambda (&rest args) |
| 26 |
(load pathname) |
| 27 |
(apply thename args)))))) |
| 28 |
|
| 29 |
(unless (fboundp 'compile) |
| 30 |
(defun proclaim (d) |
| 31 |
"Args: (decl-spec) |
| 32 |
Gives a global declaration. See DECLARE for possible DECL-SPECs." |
| 33 |
(when (eq (car d) 'SPECIAL) (mapc #'sys::*make-special (cdr d)))) |
| 34 |
) |
| 35 |
|
| 36 |
(defmacro with-compilation-unit (options &rest body) |
| 37 |
(declare (ignore options)) |
| 38 |
`(progn ,@body)) |
| 39 |
|
| 40 |
;;; Editor. |
| 41 |
|
| 42 |
;;; Default editor hook which calls external program defined by the EDITOR |
| 43 |
;;; environment variable or vi if that is not defined. |
| 44 |
(declaim (ftype (function (t) boolean) ed-external)) |
| 45 |
(defun ed-external (x) |
| 46 |
(when (typep x '(or null pathname string)) |
| 47 |
(run-program (or (getenv "EDITOR") "vi") (and x (list x))) |
| 48 |
t)) |
| 49 |
|
| 50 |
;;; Copied mostly from SBCL |
| 51 |
(declaim (type list *ed-functions*)) |
| 52 |
(defvar *ed-functions* (list #'ed-external) |
| 53 |
"See function documentation for ED.") |
| 54 |
|
| 55 |
(defun ed (&optional x) |
| 56 |
"Starts the editor (on a file or an object if named). Functions from the |
| 57 |
list EXT:*ED-FUNCTIONS* are called in order with X as an argument until one |
| 58 |
of them returns non-NIL; these functions are responsible for signalling a |
| 59 |
FILE-ERROR to indicate failure to perform an operation on the file system. |
| 60 |
If no function returns a non-NIL value or EXT:*ED-FUNCTIONS* is NIL then a |
| 61 |
SIMPLE-ERROR will be signalled. |
| 62 |
|
| 63 |
The Common Lisp specification states that the X argument is either NIL, a |
| 64 |
function name, or an instance of STRING or PATHNAME and that a TYPE-ERROR |
| 65 |
may be signalled if is not one of these types. ECL does not check the type |
| 66 |
of X and thus permits any object to be passed to the hook functions. This |
| 67 |
allows for the possibility of editing other objects that have a |
| 68 |
representation in source code such as class definitions. Therefore, the |
| 69 |
hook functions should not make any assumptions about the type of X and |
| 70 |
should instead return NIL if there is not an approriate edit method for a |
| 71 |
specific value of X. |
| 72 |
|
| 73 |
By default EXT:*ED-FUNCTIONS* contains a single function that attempts to |
| 74 |
run the program named in the environment variable EDITOR. If this |
| 75 |
environment variable is not set then the fallback program is vi." |
| 76 |
(dolist (fun *ed-functions* |
| 77 |
(error "Do not know how to ED ~a." x)) |
| 78 |
(when (funcall fun x) |
| 79 |
(return t)))) |
| 80 |
|
| 81 |
;;; Allocator. |
| 82 |
|
| 83 |
(defun room (&optional x) |
| 84 |
"Args: (&optional (x t)) |
| 85 |
Displays information about storage allocation in the following format. |
| 86 |
* for each type class |
| 87 |
* number of pages so-far allocated for the type class |
| 88 |
* maximum number of pages for the type class |
| 89 |
* percentage of used cells to cells so-far allocated |
| 90 |
* number of times the garbage collector has been called to |
| 91 |
collect cells of the type class |
| 92 |
* implementation types that belongs to the type class |
| 93 |
* number of pages actually allocated for contiguous blocks |
| 94 |
* maximum number of pages for contiguous blocks |
| 95 |
* number of times the garbage collector has been called to collect |
| 96 |
contiguous blocks |
| 97 |
* number of pages in the hole |
| 98 |
* total number of pages allocated for cells |
| 99 |
* total number of pages allocated |
| 100 |
* number of available pages |
| 101 |
* number of pages ECL can use. |
| 102 |
The number of times the garbage collector has been called is not shown, if the |
| 103 |
number is zero. The optional X is simply ignored." |
| 104 |
(declare (ignorable x)) |
| 105 |
#+boehm-gc |
| 106 |
(progn |
| 107 |
(format t " |
| 108 |
Unfortunately, when linked against the Boehm-Weiser garbage collector, |
| 109 |
ECL has no means to find out the amount of memory used. Please use |
| 110 |
some other routine (such as top in Unix or the Ctrl+Alt+Del combination |
| 111 |
in Windows) to learn this.") |
| 112 |
(values)) |
| 113 |
#-boehm-gc |
| 114 |
(let* (npage info-list link-alist) |
| 115 |
(multiple-value-bind |
| 116 |
(maxpage leftpage ncbpage maxcbpage ncb cbgbccount |
| 117 |
holepage l) |
| 118 |
(sys::room-report) |
| 119 |
|
| 120 |
(do ((l l (nthcdr 5 l)) |
| 121 |
(type-list '(cons |
| 122 |
;; fixnum Beppe |
| 123 |
fixnum char |
| 124 |
bignum ratio short-float long-float complex |
| 125 |
symbol package hash-table |
| 126 |
array vector string bit-vector |
| 127 |
stream random-state readtable pathname |
| 128 |
bytecodes cfun cclosure |
| 129 |
#-clos structure #+clos instance #+clos generic-function |
| 130 |
#+threads mp::process #+threads mp::lock |
| 131 |
si::foreign)) |
| 132 |
(tl type-list (cdr tl)) |
| 133 |
(i 0 (+ i (if (nth 2 l) (nth 2 l) 0)))) |
| 134 |
((null l) (setq npage i)) |
| 135 |
(let* ((typename (car tl)) |
| 136 |
(nused (nth 0 l)) |
| 137 |
(nfree (nth 1 l)) |
| 138 |
(npage (nth 2 l)) |
| 139 |
(maxpage (nth 3 l)) |
| 140 |
(gbccount (nth 4 l))) |
| 141 |
(if nused |
| 142 |
(push (list typename npage maxpage |
| 143 |
(if (zerop (+ nused nfree)) |
| 144 |
0 |
| 145 |
(/ nused 0.01 (+ nused nfree))) |
| 146 |
(if (zerop gbccount) nil gbccount)) |
| 147 |
info-list) |
| 148 |
(let ((a (assoc (nth nfree type-list) link-alist))) |
| 149 |
(if a |
| 150 |
(nconc a (list typename)) |
| 151 |
(push (list (nth nfree type-list) typename) |
| 152 |
link-alist)))))) |
| 153 |
(dolist (info (nreverse info-list)) |
| 154 |
(apply #'format t "~4D/~D~10T~5,1F%~@[~3D~]~20T~{~A~^ ~}" |
| 155 |
(append (cdr info) |
| 156 |
(if (assoc (car info) link-alist) |
| 157 |
(list (assoc (car info) link-alist)) |
| 158 |
(list (list (car info)))))) |
| 159 |
(terpri) |
| 160 |
) |
| 161 |
(terpri) |
| 162 |
(format t "~4D/~D~16T~@[~3D~]~20Tcontiguous (~D blocks)~%" |
| 163 |
ncbpage maxcbpage (if (zerop cbgbccount) nil cbgbccount) ncb) |
| 164 |
(format t "~5T~D~20Thole~%" holepage) |
| 165 |
(format t "~5D pages for cells~%" npage) |
| 166 |
(format t "~5D total pages~%" (+ npage ncbpage holepage)) |
| 167 |
(format t "~5D pages available~%" leftpage) |
| 168 |
(format t "~5D pages in heap but not gc'd + pages needed for gc marking~%" |
| 169 |
(- maxpage (+ npage ncbpage holepage leftpage))) |
| 170 |
(format t "~5D maximum pages~%" maxpage) |
| 171 |
(values) |
| 172 |
))) |
| 173 |
|
| 174 |
|
| 175 |
;;; Help. |
| 176 |
|
| 177 |
(autoload "sys:ecl-help" 'dump-help-file 'search-help-file) |
| 178 |
|
| 179 |
(defun help (&optional (symbol 'help)) |
| 180 |
"Args: (&optional symbol) |
| 181 |
ECL specific. |
| 182 |
Prints the documentation associated with SYMBOL. With no args, prints the |
| 183 |
greeting message to ECL beginners. |
| 184 |
|
| 185 |
Welcome to ECL. Here are the few functions you should learn first. |
| 186 |
|
| 187 |
(HELP symbol) prints the online documentation associated with the |
| 188 |
symbol. For example, (HELP 'CONS) will print the useful information |
| 189 |
about the CONS function, the CONS data type, and so on. |
| 190 |
|
| 191 |
(HELP* string) prints the online documentation associated with those |
| 192 |
symbols whose print-names have the string as substring. For example, |
| 193 |
(HELP* \"PROG\") will print the documentation of the symbols such as |
| 194 |
PROG, PROGN, and MULTIPLE-VALUE-PROG1. |
| 195 |
|
| 196 |
(QUIT) ends the current ECL session. |
| 197 |
|
| 198 |
For the precise language specification, refer to Guy Steele's \"Common Lisp, |
| 199 |
the Language\" and our \"ECL Manual\". \"ECL Dictionary\", the hard-copied |
| 200 |
version of ECL online documentation, will be useful as a handbook. |
| 201 |
|
| 202 |
Good luck! |
| 203 |
" |
| 204 |
(print-doc symbol)) |
| 205 |
|
| 206 |
;;; Pretty-print-formats. |
| 207 |
;;; |
| 208 |
;;; The number N as the property of a symbol SYMBOL indicates that, |
| 209 |
;;; in the form (SYMBOL f1 ... fN fN+1 ... fM), the subforms fN+1,...,fM |
| 210 |
;;; are the 'body' of the form and thus are treated in a special way by |
| 211 |
;;; the ECL pretty-printer. |
| 212 |
|
| 213 |
;;; (At boot we don't have setf yet) |
| 214 |
|
| 215 |
#-cmu-format |
| 216 |
(mapc #'(lambda (x) (put-sysprop (first x) 'sys::pretty-print-format (second x))) |
| 217 |
'((block 1) |
| 218 |
(case 1) |
| 219 |
(catch 1) |
| 220 |
(ccase 1) |
| 221 |
(clines 0) |
| 222 |
(compiler-let 1) |
| 223 |
(cond 0) |
| 224 |
(ctypecase 1) |
| 225 |
(defcfun 2) |
| 226 |
(define-setf-method 2) |
| 227 |
(defla 2) |
| 228 |
(defmacro 2) |
| 229 |
(defsetf 3) |
| 230 |
(defstruct 1) |
| 231 |
(deftype 2) |
| 232 |
(defun 2) |
| 233 |
(do 2) |
| 234 |
(do* 2) |
| 235 |
(do-symbols 1) |
| 236 |
(do-all-symbols 1) |
| 237 |
(do-external-symbols 1) |
| 238 |
(dolist 1) |
| 239 |
(dotimes 1) |
| 240 |
(ecase 1) |
| 241 |
(etypecase 1) |
| 242 |
(eval-when 1) |
| 243 |
(flet 1) |
| 244 |
(labels 1) |
| 245 |
(lambda 1) |
| 246 |
(ext::lambda-block 2) |
| 247 |
(let 1) |
| 248 |
(let* 1) |
| 249 |
(locally 0) |
| 250 |
(loop 0) |
| 251 |
(macrolet 1) |
| 252 |
(multiple-value-bind 2) |
| 253 |
(multiple-value-prog1 1) |
| 254 |
(prog 1) |
| 255 |
(prog* 1) |
| 256 |
(prog1 1) |
| 257 |
(prog2 2) |
| 258 |
(progn 0) |
| 259 |
(progv 2) |
| 260 |
(return 0) |
| 261 |
(return-from 1) |
| 262 |
(tagbody 0) |
| 263 |
(the 1) |
| 264 |
(throw 1) |
| 265 |
(typecase 1) |
| 266 |
(unless 1) |
| 267 |
(unwind-protect 0) |
| 268 |
(when 1) |
| 269 |
(with-input-from-string 1) |
| 270 |
(with-open-file 1) |
| 271 |
(with-open-stream 1) |
| 272 |
(with-output-to-string 1) |
| 273 |
#+clos (defclass 2) |
| 274 |
#+clos (defmethod 2) |
| 275 |
#+clos (symbol-macrolet 2) |
| 276 |
#+clos (with-accessors 2) |
| 277 |
#+clos (with-slots 2))) |
| 278 |
|
| 279 |
;;; Import functions which are useful for user interaction |
| 280 |
|
| 281 |
(in-package "CL-USER") |
| 282 |
(import '(sys::help sys::help* #-boehm-gc sys::room sys::gc sys::autoload ext::quit)) |