/[cmucl]/src/code/lispinit.lisp
ViewVC logotype

Contents of /src/code/lispinit.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15.1.1 - (show annotations) (vendor branch)
Sat Nov 24 19:53:44 1990 UTC (23 years, 5 months ago) by wlott
Branch: sparc
Changes since 1.15: +8 -12 lines
Took out lots of the init stuff so we can load less into the kernel core.
1 ;;; -*- Mode: Lisp; Package: Lisp; Log: code.log -*-
2 ;;;
3 ;;; **********************************************************************
4 ;;; This code was written as part of the Spice Lisp project at
5 ;;; Carnegie-Mellon University, and has been placed in the public domain.
6 ;;; If you want to use this code or any part of Spice Lisp, please contact
7 ;;; Scott Fahlman (FAHLMAN@CMUC).
8 ;;; **********************************************************************
9 ;;;
10 ;;; $Header: /tiger/var/lib/cvsroots/cmucl/src/code/lispinit.lisp,v 1.15.1.1 1990/11/24 19:53:44 wlott Exp $
11 ;;;
12 ;;; Initialization stuff for CMU Common Lisp, plus some other random functions
13 ;;; that we don't have any better place for.
14 ;;;
15 ;;; Written by Skef Wholey and Rob MacLachlan.
16 ;;;
17 (in-package "LISP" :use '("SYSTEM" "DEBUG"))
18
19 (export '(most-positive-fixnum most-negative-fixnum sleep
20 ++ +++ ** *** // ///))
21
22
23 (in-package "SYSTEM" :nicknames '("SYS"))
24 (export '(add-port-death-handler remove-port-death-handler sap-int
25 int-sap sap-ref-8 sap-ref-16 sap-ref-32 without-gcing
26 *in-the-compiler* compiler-version *pornography-of-death*
27 *port-receive-rights-handlers* *port-ownership-rights-handlers*
28 without-interrupts with-reply-port map-port add-port-object
29 remove-port-object make-object-set object-set-operation
30 server-message *xwindow-table* map-xwindow add-xwindow-object
31 remove-xwindow-object server-event coerce-to-key-event
32 coerce-to-motion-event coerce-to-expose-event
33 coerece-to-exposecopy-event coerce-to-focuschange-event server
34 *nameserverport* *usertypescript* *userwindow* *typescriptport*
35 *task-self* *task-data* *task-notify* with-interrupts
36 with-enabled-interrupts enable-interrupt ignore-interrupt
37 default-interrupt))
38
39 (in-package "EXTENSIONS")
40 (export '(quit *prompt* save-lisp gc-on gc-off *clx-server-displays*))
41
42 (in-package "LISP")
43
44 ;;; Make the error system enable interrupts.
45
46 (defconstant most-positive-fixnum #.vm:target-most-positive-fixnum
47 "The fixnum closest in value to positive infinity.")
48
49 (defconstant most-negative-fixnum #.vm:target-most-negative-fixnum
50 "The fixnum closest in value to negative infinity.")
51
52
53 ;;; Random information:
54
55 (defvar *lisp-implementation-version* "4.0(?)")
56
57 (defvar *in-the-compiler* nil
58 "Bound to T while running code inside the compiler. Macros may test this to
59 see where they are being expanded.")
60
61
62 ;;; Must be initialized in %INITIAL-FUNCTION before the DEFVAR runs...
63 (proclaim '(special *gc-inhibit* *already-maybe-gcing*
64 *need-to-collect-garbage* *gc-verbose*
65 *before-gc-hooks* *after-gc-hooks*
66 mach::*interrupts-enabled*
67 mach::*interrupt-pending*
68 c::*type-system-initialized*))
69
70
71 ;;;; Random magic specials.
72
73
74 ;;; These are filled in by Genesis.
75
76 (defvar *current-catch-block*)
77 (defvar *current-unwind-block*)
78 (defvar *free-interrupt-context-index*)
79
80
81
82 ;;;; Global ports:
83
84 (defvar *task-self* 1
85 "Port that refers to the current task.")
86
87 (defvar *task-data* 2
88 "Port used to receive data for the current task.")
89
90 (defvar *nameserverport* ()
91 "Port to the name server.")
92
93
94
95 ;;;; Reply port allocation.
96 ;;;
97 ;;; We maintain a global stack of reply ports which is shared among
98 ;;; all matchmaker interfaces, and could be used by other people as well.
99 ;;;
100
101 #| More stuff that will probably be drastically different.
102
103 ;;; The stack is represented by a vector, and a pointer to the first
104 ;;; free port. The stack grows upward. There is always at least one
105 ;;; NIL entry in the stack after the last allocated port.
106 ;;;
107 (defvar *reply-port-stack* (make-array 16)) ; Vector of reply ports.
108 (defvar *reply-port-pointer* 0) ; Index of first free port.
109 (defvar *reply-port-depth* 0) ; Dynamic depth in With-Reply-Port forms.
110
111 ;;; We use this as the reply port when allocating or deallocating reply
112 ;;; ports to get around potentially nasty interactions. Interrupts
113 ;;; are always off when we are doing this, so we don't have to have
114 ;;; more than one of these, or worry about unwinding.
115 (defvar *allocate-reply-port* (mach:mach-task_data))
116
117 ;;; Reset-Reply-Port-Stack -- Internal
118 ;;;
119 ;;; This is a before-save initialization which Nil's out the reply
120 ;;; port stack and sets *allocate-reply-port* back to DataPort so that
121 ;;; things initialize right at OS-Init time.
122 ;;;
123 (defun reset-reply-port-stack ()
124 (setf *reply-port-pointer* 0 *reply-port-depth* 0)
125 (fill (the simple-vector *reply-port-stack*) nil)
126 (setf *allocate-reply-port* (mach:mach-task_data)))
127 (pushnew 'reset-reply-port-stack *before-save-initializations*)
128
129 ;;; Allocate-New-Reply-Ports -- Internal
130 ;;;
131 ;;; If we run out of reply ports, we allocate another one, possibly
132 ;;; growing the stack.
133 ;;;
134 (defun allocate-new-reply-ports ()
135 (let* ((stack *reply-port-stack*)
136 (pointer *reply-port-pointer*)
137 (len (length stack)))
138 (declare (simple-vector stack) (fixnum len))
139 (when (eql pointer (1- len))
140 (let ((new (make-array (* len 2))))
141 (replace new stack :end1 len :end2 len)
142 (setf stack new *reply-port-stack* new)))
143 (setf (svref stack pointer) *allocate-reply-port*)
144 (let ((port (gr-call* mach:port_allocate (mach:mach-task_self))))
145 (gr-call mach:port_disable (mach:mach-task_self) port)
146 ;;
147 ;; Nil out the allocate reply port so it isn't used for mundane purposes.
148 (setf (svref stack pointer) nil)
149 (setf (svref stack (1- pointer)) port)
150 port)))
151
152 ;;; Reallocate-Reply-Ports -- Internal
153 ;;;
154 ;;; This function is called when With-Reply-Port finds the stack pointer
155 ;;; to be other than what it expected when it finishes. Reallocates all
156 ;;; of the ports on the stack from Start to *reply-port-pointer*. We
157 ;;; stick the *allocate-reply-port* out at *reply-port-pointer*, and
158 ;;; bind *reply-port-depth*, so that the allocation functions are happy.
159 ;;;
160 (defun reallocate-reply-ports (start)
161 (let* ((pointer *reply-port-pointer*)
162 (*reply-port-depth* pointer)
163 (stack *reply-port-stack*)
164 (save-port (svref stack pointer)))
165 (when (> start pointer)
166 (error "More ports in use than allocated???"))
167 (setf (svref stack pointer) *allocate-reply-port*)
168 (do ((i start (1+ i)))
169 ((= i pointer)
170 (setf (svref stack pointer) save-port))
171 (let ((port (svref stack i)))
172 (gr-call mach:port_deallocate *task-self* port)
173 (setf (svref stack i)
174 (gr-call* mach:port_allocate *task-self*))))))
175 |#
176
177
178 ;;;; Server stuff:
179 ;;;
180 ;;; There is a fair amount of stuff to support Matchmaker RPC servers
181 ;;; and asynchonous message service. RPC message service needs to be
182 ;;; centralized since a server must receive on all ports, and there is
183 ;;; no way for a particular server to know about all other servers
184 ;;; in the same lisp.
185 ;;;
186 ;;; The idea is that you receive the message, and then dispatch off
187 ;;; of the port received on and the message ID received. Ports correspond
188 ;;; to objects that the server manages. Message ID's correspond to the
189 ;;; operations on the objects. Objects are grouped into object sets, which
190 ;;; are sets of objects having the same operations defined.
191 ;;;
192 ;;; The same mechanism is used for handling asynchronous messages.
193 ;;;
194
195 ;;; The current implementation uses standard eq[l] hashtables for both
196 ;;; levels of dispatching. Special purpose data structures would be more
197 ;;; efficient, but the ~1ms overhead will probably be lost in the noise.
198
199 ;;;
200 ;;; Hashtable from ports to objects. Each entry is a cons (object . set).
201 ;;;
202 (defvar *port-table* (make-hash-table :test #'eql))
203
204 ;;; Hashtable from windows to objects. Each entry is a cons (object . set).
205 ;;;
206 (defvar *xwindow-table* (make-hash-table :test #'eql))
207
208
209 (defstruct (object-set
210 (:constructor make-object-set
211 (name &optional
212 (default-handler #'default-default-handler)))
213 (:print-function
214 (lambda (s stream d)
215 (declare (ignore d))
216 (format stream "#<Object Set ~S>" (object-set-name s)))))
217 name ; Name, for descriptive purposes.
218 (table (make-hash-table :test #'eq)) ; Message-ID or xevent-type --> handler fun.
219 default-handler)
220
221 (setf (documentation 'make-object-set 'function)
222 "Make an object set for use by a RPC/xevent server. Name is for
223 descriptive purposes only.")
224
225 ;;; Default-Default-Handler -- Internal
226 ;;;
227 ;;; If no such operation defined, signal an error.
228 ;;;
229 (defun default-default-handler (object)
230 #+nil
231 (alien-bind ((msg (server-message-msg server-message)))
232 (error "No operation for ID ~D on ~S in ~S."
233 (alien-access (mach:msg-id (alien-value msg))) object
234 (car (gethash (alien-access (mach:msg-localport (alien-value msg)))
235 *port-table*))))
236 (error "You lose, object: ~S" object))
237
238
239 ;;; MAP-XWINDOW and MAP-PORT return as multiple values the object and
240 ;;; object set mapped to by a xwindow or port in *xwindow-table* or
241 ;;; *port-table*.
242 ;;;
243 (macrolet ((defmapper (name table)
244 `(defun ,(intern (concatenate 'simple-string
245 "MAP-" (symbol-name name)))
246 (,name)
247 ,(format nil "Return as multiple values the object and ~
248 object-set mapped to by ~A."
249 (string-downcase (symbol-name name)))
250 (let ((temp (gethash ,name ,table)))
251 (if temp
252 (values (car temp) (cdr temp))
253 (values nil nil))))))
254 (defmapper port *port-table*)
255 (defmapper xwindow *xwindow-table*))
256
257
258 ;;; ADD-PORT-OBJECT and ADD-XWINDOW-OBJECT store an object/object-set pair
259 ;;; mapped to by a port or xwindow in either *port-table* or *xwindow-table*.
260 ;;;
261 (macrolet ((def-add-object (name table)
262 `(defun ,(intern (concatenate 'simple-string
263 "ADD-" (symbol-name name)
264 "-OBJECT"))
265 (,name object object-set)
266 ,(format nil "Add a new ~A/object/object-set association."
267 (string-downcase (symbol-name name)))
268 (check-type object-set object-set)
269 (setf (gethash ,name ,table) (cons object object-set))
270 object)))
271 (def-add-object port *port-table*)
272 (def-add-object xwindow *xwindow-table*))
273
274
275 ;;; REMOVE-PORT-OBJECT and REMOVE-XWINDOW-OBJECT remove a port or xwindow and
276 ;;; its associated object/object-set pair from *port-table* or *xwindow-table*.
277 ;;;
278 (macrolet ((def-remove-object (name table)
279 `(defun ,(intern (concatenate 'simple-string
280 "REMOVE-" (symbol-name name)
281 "-OBJECT"))
282 (,name)
283 ,(format nil
284 "Remove ~A and its associated object/object-set pair."
285 (string-downcase (symbol-name name)))
286 (remhash ,name ,table))))
287 (def-remove-object port *port-table*)
288 (def-remove-object xwindow *xwindow-table*))
289
290
291 ;;; Object-Set-Operation -- Public
292 ;;;
293 ;;; Look up the handler function for a given message ID.
294 ;;;
295 (defun object-set-operation (object-set message-id)
296 "Return the handler function in Object-Set for the operation specified by
297 Message-ID, if none, NIL is returned. The handler function is passed
298 the object. The received message is in server-Message."
299 (check-type object-set object-set)
300 (check-type message-id fixnum)
301 (values (gethash message-id (object-set-table object-set))))
302
303 ;;; %Set-Object-Set-Operation -- Internal
304 ;;;
305 ;;; The setf inverse for Object-Set-Operation.
306 ;;;
307 (defun %set-object-set-operation (object-set message-id new-value)
308 (check-type object-set object-set)
309 (check-type message-id fixnum)
310 (setf (gethash message-id (object-set-table object-set)) new-value))
311 ;;;
312 (defsetf object-set-operation %set-object-set-operation
313 "Sets the handler function for an object set operation.")
314
315
316
317 ;;;; Emergency Message Handling:
318 ;;;
319 ;;; We use the same mechanism for asynchronous messages as is used for
320 ;;; normal server messages. The only tricky part is that we don't want
321 ;;; some random server function being called when we really want to
322 ;;; receive an emergency message, so we can't receive on all ports.
323 ;;; Instead, we use MessagesWaiting to find the ports with emergency
324 ;;; messages.
325
326 #| still more noise that will be different.
327
328 (defalien waiting-ports nil (long-words 128))
329
330 ;;; Service-Emergency-Message-Interrupt -- Internal
331 ;;;
332 ;;; This is a lot like the server function, but we only receive on
333 ;;; ports with one emergency message. We only receive one message because
334 ;;; the handler function might have caused any other messages to be received.
335 ;;; When we re-enable interrupts, if any emergency messages are left, we
336 ;;; should be interrupted again.
337 ;;;
338 (defun service-emergency-message-interrupt ()
339 (grab-message-loop))
340
341 ;;;
342 ;;; This object set is used for DataPort, which is the port various magical
343 ;;; message from the kernel are received on...
344 (defvar *kernel-messages* (make-object-set "Kernel Messages"))
345
346 (compiler-let ((*alien-eval-when* '(compile eval)))
347 (defrecord port-death-msg
348 (msg mach:msg #.(record-size 'mach:msg))
349 (ex-port-tt pad (long-words 1))
350 (ex-port (signed-byte 32) (long-words 1)))
351
352 (defoperator (server-message-port-death-msg port-death-msg)
353 ((msg server-message))
354 `(alien-index (alien-value ,msg) 0 (record-size 'port-death-msg)))
355 ); Compiler-Let
356
357
358 ;;; *Port-Death-Handlers* is an EQ hash table of lists of functions that are
359 ;;; called upon port death. If a port dies that is not in the table, we print
360 ;;; out a message on *Trace-Output* describing its death. If
361 ;;; *Pornography-Of-Death* is true, we don't even print that message.
362
363 (defvar *port-death-handlers* (make-hash-table :test #'eql)
364 "Don't use this --- use Add-Port-Death-Handler instead.")
365
366 ;;; Add-Port-Death-Handler, Remove-Port-Death-Handler -- Public
367 ;;;
368 (defun add-port-death-handler (port function)
369 "Make Function a handler for port death on Port. When the port dies,
370 Function is called with the port and an argument. See also
371 Remove-Port-Death-Handler."
372 (pushnew function (gethash port *port-death-handlers*))
373 nil)
374 ;;;
375 (defun remove-port-death-handler (port function)
376 "Undoes the effect of Add-Port-Death-Handler."
377 (setf (gethash port *port-death-handlers*)
378 (delete function (gethash port *port-death-handlers*)))
379 nil)
380
381 (setf (object-set-operation *kernel-messages* mach:notify-port-deleted)
382 #'(lambda (obj)
383 (declare (ignore obj))
384 (let* ((ex-port (alien-access
385 (port-death-msg-ex-port
386 (server-message-port-death-msg server-message))))
387 (handlers (gethash ex-port *port-death-handlers*)))
388 (remhash ex-port *port-table*)
389 (remhash ex-port *port-death-handlers*)
390 (if (null handlers)
391 (handle-unclaimed-port-death ex-port)
392 (dolist (fun handlers) (funcall fun ex-port))))
393 mach:kern-success))
394
395 (defvar *pornography-of-death* t
396 "If true, nothing is said about port deaths.")
397
398 (defun handle-unclaimed-port-death (port)
399 (unless *pornography-of-death*
400 (format *trace-output* "~&[Port ~S just bit the dust.]~%" port)))
401
402 ;;; Port receive and ownership rights messages are handled simlarly, but
403 ;;; by default we deallocate the port to make sure it's really dead. This
404 ;;; gets around problems with ports being exhausted because some servers
405 ;;; don't really nuke the port when the deallocate the object.
406 ;;;
407
408 (defvar *port-receive-rights-handlers* (make-hash-table :test #'eql)
409 "This is a hashtable from ports to functions. The function is called with
410 the port as its argument when a port receive rights message for that port
411 is received from the kernel.")
412
413 (defvar *port-ownership-rights-handlers* (make-hash-table :test #'eql)
414 "This is a hashtable from ports to functions. The function is called with
415 the port as its argument when a port ownership rights message for that port
416 is received from the kernel.")
417
418 (setf (object-set-operation *kernel-messages* mach:notify-receive-rights)
419 #'(lambda (obj)
420 (declare (ignore obj))
421 (let ((ex-port (alien-access
422 (port-death-msg-ex-port
423 (server-message-port-death-msg server-message)))))
424 (funcall (gethash ex-port *port-receive-rights-handlers*
425 #'handle-unclaimed-port-rights)
426 ex-port))
427 mach:kern-success))
428
429 (setf (object-set-operation *kernel-messages* mach:notify-ownership-rights)
430 #'(lambda (obj)
431 (declare (ignore obj))
432 (let ((ex-port (alien-access
433 (port-death-msg-ex-port
434 (server-message-port-death-msg server-message)))))
435 (funcall (gethash ex-port *port-ownership-rights-handlers*
436 #'handle-unclaimed-port-rights)
437 ex-port))
438 mach:kern-success))
439
440 (defun handle-unclaimed-port-rights (port)
441 (unless *pornography-of-death*
442 (format *trace-output* "~&[Rights received for port ~D, deallocating it.]~%"
443 port))
444 (mach:port_deallocate *task-self* port)
445 (remhash port *port-receive-rights-handlers*)
446 (remhash port *port-ownership-rights-handlers*)
447 (remhash port *port-table*))
448
449 (add-port-object *task-data* nil *kernel-messages*)
450
451 ;;; Clear-Port-Tables -- Internal
452 ;;;
453 ;;; A before-save initialization which clears all of the port hashtables.
454 ;;;
455 (defun clear-port-tables ()
456 (clrhash *port-table*)
457 (clrhash *port-death-handlers*)
458 (clrhash *port-receive-rights-handlers*)
459 (clrhash *port-ownership-rights-handlers*))
460
461 (pushnew 'clear-port-tables *before-save-initializations*)
462
463 |#
464
465
466
467 ;;; %Initial-Function is called when a cold system starts up. First we zoom
468 ;;; down the *Lisp-Initialization-Functions* doing things that wanted to happen
469 ;;; at "load time." Then we initialize the various subsystems and call the
470 ;;; read-eval-print loop. The top-level Read-Eval-Print loop is executed until
471 ;;; someone (most likely the Quit function) throws to the tag
472 ;;; %End-Of-The-World. We quit this way so that all outstanding cleanup forms
473 ;;; in Unwind-Protects will get executed.
474
475 (proclaim '(special *lisp-initialization-functions*))
476
477 (eval-when (compile)
478 (defmacro print-and-call (name)
479 `(progn
480 (%primitive print ,(symbol-name name))
481 (,name))))
482
483 (defun %initial-function ()
484 "Gives the world a shove and hopes it spins."
485 (%primitive print "In initial-function, and running.")
486 (setf *already-maybe-gcing* t)
487 (setf *gc-inhibit* t)
488 (setf *need-to-collect-garbage* nil)
489 (setf *gc-verbose* t)
490 (setf *before-gc-hooks* nil)
491 (setf *after-gc-hooks* nil)
492 (setf mach::*interrupts-enabled* t)
493 (setf mach::*interrupt-pending* nil)
494 (setf c::*type-system-initialized* nil)
495
496 ;; Many top-level forms call INFO, (SETF INFO).
497 (print-and-call c::globaldb-init)
498
499 ;; Some of the random top-level forms call Make-Array, which calls Subtypep...
500 (print-and-call type-init)
501
502 (setf *lisp-initialization-functions*
503 (nreverse *lisp-initialization-functions*))
504 (%primitive print "Calling top-level forms.")
505 (dolist (fun *lisp-initialization-functions*)
506 (funcall fun))
507 (makunbound '*lisp-initialization-functions*) ; So it gets GC'ed.
508
509 ;; Only do this after top level forms have run, 'cause thats where
510 ;; deftypes are.
511 (setf c::*type-system-initialized* t)
512
513 (print-and-call os-init)
514 (print-and-call filesys-init)
515 ;(print-and-call conditions::error-init)
516 ;(print-and-call kernel::signal-init)
517
518 (print-and-call reader-init)
519 ;(print-and-call backq-init)
520 ;(print-and-call sharp-init)
521 ;; After the various reader subsystems have done their thing to the standard
522 ;; readtable, copy it to *readtable*.
523 (setf *readtable* (copy-readtable std-lisp-readtable))
524
525 (print-and-call stream-init)
526 (print-and-call loader-init)
527 ;(print-and-call format-init)
528 (print-and-call package-init)
529
530 (%primitive print "Done initializing.")
531
532 (setf *already-maybe-gcing* nil)
533 (terpri)
534 (princ "CMU Common Lisp kernel core image ")
535 (princ *lisp-implementation-version*)
536 (princ ".")
537 (terpri)
538 (princ "[You are in the LISP package.]")
539 (terpri)
540 (catch '%end-of-the-world
541 (loop
542 (%top-level)
543 (write-line "You're certainly a clever child.")))
544 (mach:unix-exit 0))
545
546
547 ;;;; Initialization functions:
548
549 ;;; Reinit is called to reinitialize the world when a saved core image
550 ;;; is resumed.
551 (defvar *task-notify* NIL)
552
553 (defun reinit ()
554 (without-interrupts
555 (setf *already-maybe-gcing* t)
556 (os-init)
557 (kernel::signal-init)
558 (stream-reinit)
559 (setf *already-maybe-gcing* nil))
560 #+nil
561 (mach:port_enable (mach:mach-task_self) *task-notify*)
562 #+nil
563 (add-port-object *task-notify* nil *kernel-messages*))
564
565 ;;; OS-Init initializes our operating-system interface. It sets the values
566 ;;; of the global port variables to what they should be and calls the functions
567 ;;; that set up the argument blocks for the server interfaces.
568
569 (defun os-init ()
570 (setf *task-self* (mach:mach-task_self))
571 (setf *task-data* (mach:mach-task_data))
572 (setf *task-notify* (mach:mach-task_notify)))
573
574
575 ;;; Setup-path-search-list returns a list of the directories that are
576 ;;; in the unix path environment variable. This is so that run-program
577 ;;; can be smarter about where to find a program to run.
578 (defun setup-path-search-list ()
579 (let ((path (cdr (assoc :path ext::*environment-list*))))
580 (when path
581 (do* ((i 0 (1+ p))
582 (p (position #\: path :start i)
583 (position #\: path :start i))
584 (pl ()))
585 ((null p)
586 (let ((s (subseq path i)))
587 (if (string= s "")
588 (push "default:" pl)
589 (push (concatenate 'simple-string s "/") pl)))
590 (nreverse pl))
591 (let ((s (subseq path i p)))
592 (if (string= s "")
593 (push "default:" pl)
594 (push (concatenate 'simple-string s "/") pl)))))))
595
596
597 ;;;; Miscellaneous external functions:
598
599 ;;; Quit gets us out, one way or another.
600
601 (defun quit (&optional recklessly-p)
602 "Terminates the current Lisp. Things are cleaned up unless Recklessly-P is
603 non-Nil."
604 (if recklessly-p
605 (mach:unix-exit 0)
606 (throw '%end-of-the-world nil)))
607
608
609 (defun sleep (n)
610 "This function causes execution to be suspended for N seconds. N may
611 be any non-negative, non-complex number."
612 (when (or (not (realp n))
613 (minusp n))
614 (error "Invalid argument to SLEEP: ~S.~%~
615 Must be a non-negative, non-complex number."
616 n))
617 (multiple-value-bind (sec usec)
618 (if (integerp n)
619 (values n 0)
620 (values (truncate n)
621 (truncate (* n 1000000))))
622 (mach:unix-select 0 0 0 0 sec usec))
623 nil)
624
625
626 ;;;; TOP-LEVEL loop.
627
628 (defvar / nil
629 "Holds a list of all the values returned by the most recent top-level EVAL.")
630 (defvar // nil "Gets the previous value of / when a new value is computed.")
631 (defvar /// nil "Gets the previous value of // when a new value is computed.")
632 (defvar * nil "Holds the value of the most recent top-level EVAL.")
633 (defvar ** nil "Gets the previous value of * when a new value is computed.")
634 (defvar *** nil "Gets the previous value of ** when a new value is computed.")
635 (defvar + nil "Holds the value of the most recent top-level READ.")
636 (defvar ++ nil "Gets the previous value of + when a new value is read.")
637 (defvar +++ nil "Gets the previous value of ++ when a new value is read.")
638 (defvar - nil "Holds the form curently being evaluated.")
639 (defvar *prompt* "* "
640 "The top-level prompt string. This also may be a function of no arguments
641 that returns a simple-string.")
642 (defvar *in-top-level-catcher* nil
643 "True if we are within the Top-Level-Catcher. This is used by interrupt
644 handlers to see whether it is o.k. to throw.")
645
646 (defun interactive-eval (form)
647 "Evaluate FORM, returning whatever it returns but adjust ***, **, *, +++, ++,
648 +, ///, //, /, and -."
649 (setf +++ ++
650 ++ +
651 + -
652 - form)
653 (let ((results (multiple-value-list (eval form))))
654 (setf /// //
655 // /
656 / results
657 *** **
658 ** *
659 * (car results)))
660 (unless (boundp '*)
661 ;; The bogon returned an unbound marker.
662 (setf * nil)
663 (cerror "Go on with * set to NIL."
664 "EVAL returned an unbound marker."))
665 (values-list /))
666
667 (defconstant eofs-before-quit 10)
668
669 (defun %top-level ()
670 "Top-level READ-EVAL-PRINT loop. Do not call this."
671 (let ((* nil) (** nil) (*** nil)
672 (- nil) (+ nil) (++ nil) (+++ nil)
673 (/// nil) (// nil) (/ nil)
674 (magic-eof-cookie (cons :eof nil))
675 (number-of-eofs 0))
676 (loop
677 (with-simple-restart (abort "Return to Top-Level.")
678 (catch 'top-level-catcher
679 (let ((*in-top-level-catcher* t))
680 (loop
681 (fresh-line)
682 (princ (if (functionp *prompt*)
683 (funcall *prompt*)
684 *prompt*))
685 (force-output)
686 (let ((form (read *standard-input* nil magic-eof-cookie)))
687 (cond ((not (eq form magic-eof-cookie))
688 (let ((results
689 (multiple-value-list (interactive-eval form))))
690 (dolist (result results)
691 (fresh-line)
692 (prin1 result)))
693 (setf number-of-eofs 0))
694 ((eql (incf number-of-eofs) 1)
695 (let ((stream (make-synonym-stream '*terminal-io*)))
696 (setf *standard-input* stream)
697 (setf *standard-output* stream)
698 (format t "~&Received EOF on *standard-input*, ~
699 switching to *terminal-io*.~%")))
700 ((> number-of-eofs eofs-before-quit)
701 (format t "~&Received more than ~D EOFs; Aborting.~%"
702 eofs-before-quit)
703 (quit))
704 (t
705 (format t "~&Received EOF.~%")))))))))))
706
707
708
709 ;;; %Halt -- Interface
710 ;;;
711 ;;; A convenient way to get into the assembly level debugger.
712 ;;;
713 (defun %halt ()
714 (%primitive halt))

  ViewVC Help
Powered by ViewVC 1.1.5