/[slime]/slime/swank-backend.lisp
ViewVC logotype

Diff of /slime/swank-backend.lisp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.94 by heller, Sun Nov 20 23:25:38 2005 UTC revision 1.202 by crhodes, Fri Oct 8 09:03:24 2010 UTC
# Line 12  Line 12 
12    
13  (defpackage :swank-backend  (defpackage :swank-backend
14    (:use :common-lisp)    (:use :common-lisp)
15    (:export #:sldb-condition    (:export #:*debug-swank-backend*
16             #:original-condition             #:sldb-condition
17             #:compiler-condition             #:compiler-condition
18               #:original-condition
19             #:message             #:message
20             #:short-message             #:source-context
21             #:condition             #:condition
22             #:severity             #:severity
23               #:with-compilation-hooks
24             #:location             #:location
25             #:location-p             #:location-p
26             #:location-buffer             #:location-buffer
# Line 29  Line 31 
31             #:quit-lisp             #:quit-lisp
32             #:references             #:references
33             #:unbound-slot-filler             #:unbound-slot-filler
34               #:declaration-arglist
35               #:type-specifier-arglist
36               #:with-struct
37               #:when-let
38               ;; interrupt macro for the backend
39               #:*pending-slime-interrupts*
40               #:check-slime-interrupts
41               #:*interrupt-queued-handler*
42             ;; inspector related symbols             ;; inspector related symbols
43             #:inspector             #:emacs-inspect
            #:inspect-for-emacs  
            #:raw-inspection  
            #:fancy-inspection  
44             #:label-value-line             #:label-value-line
45             #:label-value-line*             #:label-value-line*
46             ))             #:with-symbol))
47    
48  (defpackage :swank-mop  (defpackage :swank-mop
49    (:use)    (:use)
# Line 84  Line 91 
91     #:slot-definition-type     #:slot-definition-type
92     #:slot-definition-readers     #:slot-definition-readers
93     #:slot-definition-writers     #:slot-definition-writers
94       #:slot-boundp-using-class
95       #:slot-value-using-class
96       #:slot-makunbound-using-class
97     ;; generic function protocol     ;; generic function protocol
98     #:compute-applicable-methods-using-classes     #:compute-applicable-methods-using-classes
99     #:finalize-inheritance))     #:finalize-inheritance))
# Line 93  Line 103 
103    
104  ;;;; Metacode  ;;;; Metacode
105    
106    (defparameter *debug-swank-backend* nil
107      "If this is true, backends should not catch errors but enter the
108    debugger where appropriate. Also, they should not perform backtrace
109    magic but really show every frame including SWANK related ones.")
110    
111  (defparameter *interface-functions* '()  (defparameter *interface-functions* '()
112    "The names of all interface functions.")    "The names of all interface functions.")
113    
# Line 102  DEFINTERFACE adds to this list and DEFIM Line 117  DEFINTERFACE adds to this list and DEFIM
117    
118  (defmacro definterface (name args documentation &rest default-body)  (defmacro definterface (name args documentation &rest default-body)
119    "Define an interface function for the backend to implement.    "Define an interface function for the backend to implement.
120  A generic function is defined with NAME, ARGS, and DOCUMENTATION.  A function is defined with NAME, ARGS, and DOCUMENTATION.  This
121    function first looks for a function to call in NAME's property list
122  If a DEFAULT-BODY is supplied then NO-APPLICABLE-METHOD is specialized  that is indicated by 'IMPLEMENTATION; failing that, it looks for a
123  to execute the body if the backend doesn't provide a specific  function indicated by 'DEFAULT. If neither is present, an error is
124  implementation.  signaled.
125    
126    If a DEFAULT-BODY is supplied, then a function with the same body and
127    ARGS will be added to NAME's property list as the property indicated
128    by 'DEFAULT.
129    
130  Backends implement these functions using DEFIMPLEMENTATION."  Backends implement these functions using DEFIMPLEMENTATION."
131    (check-type documentation string "a documentation string")    (check-type documentation string "a documentation string")
132    (flet ((gen-default-impl ()    (assert (every #'symbolp args) ()
133             `(defmethod ,name ,args ,@default-body)))            "Complex lambda-list not supported: ~S ~S" name args)
134      `(progn (defgeneric ,name ,args (:documentation ,documentation))    (labels ((gen-default-impl ()
135              (pushnew ',name *interface-functions*)               `(setf (get ',name 'default) (lambda ,args ,@default-body)))
136              ,(if (null default-body)             (args-as-list (args)
137                   `(pushnew ',name *unimplemented-interfaces*)               (destructuring-bind (req opt key rest) (parse-lambda-list args)
138                   (gen-default-impl))                 `(,@req ,@opt
139              ;; see <http://www.franz.com/support/documentation/6.2/doc/pages/variables/compiler/s_cltl1-compile-file-toplevel-compatibility-p_s.htm>                         ,@(loop for k in key append `(,(kw k) ,k))
140              (eval-when (:compile-toplevel :load-toplevel :execute)                         ,@(or rest '(())))))
141                (export ',name :swank-backend))             (parse-lambda-list (args)
142              ',name)))               (parse args '(&optional &key &rest)
143                        (make-array 4 :initial-element nil)))
144               (parse (args keywords vars)
145                 (cond ((null args)
146                        (reverse (map 'list #'reverse vars)))
147                       ((member (car args) keywords)
148                        (parse (cdr args) (cdr (member (car args) keywords)) vars))
149                       (t (push (car args) (aref vars (length keywords)))
150                          (parse (cdr args) keywords vars))))
151               (kw (s) (intern (string s) :keyword)))
152        `(progn
153           (defun ,name ,args
154             ,documentation
155             (let ((f (or (get ',name 'implementation)
156                          (get ',name 'default))))
157               (cond (f (apply f ,@(args-as-list args)))
158                     (t (error "~S not implemented" ',name)))))
159           (pushnew ',name *interface-functions*)
160           ,(if (null default-body)
161                `(pushnew ',name *unimplemented-interfaces*)
162                (gen-default-impl))
163           ;; see <http://www.franz.com/support/documentation/6.2/doc/pages/variables/compiler/s_cltl1-compile-file-toplevel-compatibility-p_s.htm>
164           (eval-when (:compile-toplevel :load-toplevel :execute)
165             (export ',name :swank-backend))
166           ',name)))
167    
168  (defmacro defimplementation (name args &body body)  (defmacro defimplementation (name args &body body)
169    `(progn (defmethod ,name ,args ,@body)    (assert (every #'symbolp args) ()
170            (if (member ',name *interface-functions*)            "Complex lambda-list not supported: ~S ~S" name args)
171                (setq *unimplemented-interfaces*    `(progn
172                      (remove ',name *unimplemented-interfaces*))       (setf (get ',name 'implementation)
173                (warn "DEFIMPLEMENTATION of undefined interface (~S)" ',name))             ;; For implicit BLOCK. FLET because of interplay w/ decls.
174            ',name))             (flet ((,name ,args ,@body)) #',name))
175         (if (member ',name *interface-functions*)
176             (setq *unimplemented-interfaces*
177                   (remove ',name *unimplemented-interfaces*))
178             (warn "DEFIMPLEMENTATION of undefined interface (~S)" ',name))
179         ',name))
180    
181  (defun warn-unimplemented-interfaces ()  (defun warn-unimplemented-interfaces ()
182    "Warn the user about unimplemented backend features.    "Warn the user about unimplemented backend features.
183  The portable code calls this function at startup."  The portable code calls this function at startup."
184    (warn "These Swank interfaces are unimplemented:~% ~A"    (let ((*print-pretty* t))
185          (sort (copy-list *unimplemented-interfaces*) #'string<)))      (warn "These Swank interfaces are unimplemented:~% ~:<~{~A~^ ~:_~}~:>"
186              (list (sort (copy-list *unimplemented-interfaces*) #'string<)))))
187    
188  (defun import-to-swank-mop (symbol-list)  (defun import-to-swank-mop (symbol-list)
189    (dolist (sym symbol-list)    (dolist (sym symbol-list)
# Line 158  EXCEPT is a list of symbol names which s Line 207  EXCEPT is a list of symbol names which s
207  (defvar *gray-stream-symbols*  (defvar *gray-stream-symbols*
208    '(:fundamental-character-output-stream    '(:fundamental-character-output-stream
209      :stream-write-char      :stream-write-char
210        :stream-write-string
211      :stream-fresh-line      :stream-fresh-line
212      :stream-force-output      :stream-force-output
213      :stream-finish-output      :stream-finish-output
214      :fundamental-character-input-stream      :fundamental-character-input-stream
215      :stream-read-char      :stream-read-char
216        :stream-peek-char
217        :stream-read-line
218        ;; STREAM-FILE-POSITION is not available on all implementations, or
219        ;; partially under a different name.
220        ; :stream-file-posiion
221      :stream-listen      :stream-listen
222      :stream-unread-char      :stream-unread-char
223      :stream-clear-input      :stream-clear-input
# Line 199  EXCEPT is a list of symbol names which s Line 254  EXCEPT is a list of symbol names which s
254                       (t (error "Malformed syntax in WITH-STRUCT: ~A" name))))                       (t (error "Malformed syntax in WITH-STRUCT: ~A" name))))
255            ,@body)))))            ,@body)))))
256    
257    (defmacro when-let ((var value) &body body)
258      `(let ((,var ,value))
259         (when ,var ,@body)))
260    
261    (defun with-symbol (name package)
262      "Generate a form suitable for testing with #+."
263      (if (and (find-package package)
264               (find-symbol (string name) package))
265          '(:and)
266          '(:or)))
267    
268    
269  ;;;; TCP server  ;;;; TCP server
270    
# Line 212  EXCEPT is a list of symbol names which s Line 278  EXCEPT is a list of symbol names which s
278    "Close the socket SOCKET.")    "Close the socket SOCKET.")
279    
280  (definterface accept-connection (socket &key external-format  (definterface accept-connection (socket &key external-format
281                                          buffering)                                          buffering timeout)
282     "Accept a client connection on the listening socket SOCKET.     "Accept a client connection on the listening socket SOCKET.
283  Return a stream for the new connection.")  Return a stream for the new connection.")
284    
# Line 232  Return a stream for the new connection." Line 298  Return a stream for the new connection."
298    "Return one of the symbols :spawn, :sigio, :fd-handler, or NIL."    "Return one of the symbols :spawn, :sigio, :fd-handler, or NIL."
299    nil)    nil)
300    
301    (definterface set-stream-timeout (stream timeout)
302      "Set the 'stream 'timeout.  The timeout is either the real number
303      specifying the timeout in seconds or 'nil for no timeout."
304      (declare (ignore stream timeout))
305      nil)
306    
307  ;;; Base condition for networking errors.  ;;; Base condition for networking errors.
308  (define-condition network-error (simple-error) ())  (define-condition network-error (simple-error) ())
309    
# Line 249  that the calling thread is the one that Line 321  that the calling thread is the one that
321    
322  (defconstant +sigint+ 2)  (defconstant +sigint+ 2)
323    
 (definterface call-without-interrupts (fn)  
   "Call FN in a context where interrupts are disabled."  
   (funcall fn))  
   
324  (definterface getpid ()  (definterface getpid ()
325    "Return the (Unix) process ID of this superior Lisp.")    "Return the (Unix) process ID of this superior Lisp.")
326    
327    (definterface install-sigint-handler (function)
328      "Call FUNCTION on SIGINT (instead of invoking the debugger).
329    Return old signal handler."
330      (declare (ignore function))
331      nil)
332    
333    (definterface call-with-user-break-handler (handler function)
334      "Install the break handler HANDLER while executing FUNCTION."
335      (let ((old-handler (install-sigint-handler handler)))
336        (unwind-protect (funcall function)
337          (install-sigint-handler old-handler))))
338    
339    (definterface quit-lisp ()
340      "Exit the current lisp image.")
341    
342  (definterface lisp-implementation-type-name ()  (definterface lisp-implementation-type-name ()
343    "Return a short name for the Lisp implementation."    "Return a short name for the Lisp implementation."
344    (lisp-implementation-type))    (lisp-implementation-type))
345    
346    (definterface lisp-implementation-program ()
347      "Return the argv[0] of the running Lisp process, or NIL."
348      (let ((file (car (command-line-args))))
349        (when (and file (probe-file file))
350          (namestring (truename file)))))
351    
352    (definterface socket-fd (socket-stream)
353      "Return the file descriptor for SOCKET-STREAM.")
354    
355    (definterface make-fd-stream (fd external-format)
356      "Create a character stream for the file descriptor FD.")
357    
358    (definterface dup (fd)
359      "Duplicate a file descriptor.
360    If the syscall fails, signal a condition.
361    See dup(2).")
362    
363    (definterface exec-image (image-file args)
364      "Replace the current process with a new process image.
365    The new image is created by loading the previously dumped
366    core file IMAGE-FILE.
367    ARGS is a list of strings passed as arguments to
368    the new image.
369    This is thin wrapper around exec(3).")
370    
371    (definterface command-line-args ()
372      "Return a list of strings as passed by the OS."
373      nil)
374    
375    
376    ;; pathnames are sooo useless
377    
378    (definterface filename-to-pathname (filename)
379      "Return a pathname for FILENAME.
380    A filename in Emacs may for example contain asterisks which should not
381    be translated to wildcards."
382      (parse-namestring filename))
383    
384    (definterface pathname-to-filename (pathname)
385      "Return the filename for PATHNAME."
386      (namestring pathname))
387    
388  (definterface default-directory ()  (definterface default-directory ()
389    "Return the default directory."    "Return the default directory."
390    (directory-namestring (truename *default-pathname-defaults*)))    (directory-namestring (truename *default-pathname-defaults*)))
# Line 270  This is used to resolve filenames withou Line 395  This is used to resolve filenames withou
395    (setf *default-pathname-defaults* (truename (merge-pathnames directory)))    (setf *default-pathname-defaults* (truename (merge-pathnames directory)))
396    (default-directory))    (default-directory))
397    
398    
399  (definterface call-with-syntax-hooks (fn)  (definterface call-with-syntax-hooks (fn)
400    "Call FN with hooks to handle special syntax."    "Call FN with hooks to handle special syntax."
401    (funcall fn))    (funcall fn))
# Line 278  This is used to resolve filenames withou Line 404  This is used to resolve filenames withou
404    "Return a suitable initial value for SWANK:*READTABLE-ALIST*."    "Return a suitable initial value for SWANK:*READTABLE-ALIST*."
405    '())    '())
406    
 (definterface quit-lisp ()  
   "Exit the current lisp image.")  
   
407    
408  ;;;; Compilation  ;;;; Compilation
409    
# Line 292  This is used to resolve filenames withou Line 415  This is used to resolve filenames withou
415    (declare (ignore ignore))    (declare (ignore ignore))
416    `(call-with-compilation-hooks (lambda () (progn ,@body))))    `(call-with-compilation-hooks (lambda () (progn ,@body))))
417    
418  (definterface swank-compile-string (string &key buffer position directory)  (definterface swank-compile-string (string &key buffer position filename
419    "Compile source from STRING.  During compilation, compiler                                             policy)
420  conditions must be trapped and resignalled as COMPILER-CONDITIONs.    "Compile source from STRING.
421    During compilation, compiler conditions must be trapped and
422    resignalled as COMPILER-CONDITIONs.
423    
424  If supplied, BUFFER and POSITION specify the source location in Emacs.  If supplied, BUFFER and POSITION specify the source location in Emacs.
425    
426  Additionally, if POSITION is supplied, it must be added to source  Additionally, if POSITION is supplied, it must be added to source
427  positions reported in compiler conditions.  positions reported in compiler conditions.
428    
429  If DIRECTORY is specified it may be used by certain implementations to  If FILENAME is specified it may be used by certain implementations to
430  rebind *DEFAULT-PATHNAME-DEFAULTS* which may improve the recording of  rebind *DEFAULT-PATHNAME-DEFAULTS* which may improve the recording of
431  source information.")  source information.
432    
433  (definterface operate-on-system (system-name operation-name &rest keyword-args)  If POLICY is supplied, and non-NIL, it may be used by certain
434    "Perform OPERATION-NAME on SYSTEM-NAME using ASDF.  implementations to compile with optimization qualities of its
435  The KEYWORD-ARGS are passed on to the operation.  value.
436  Example:  
437  \(operate-on-system \"SWANK\" \"COMPILE-OP\" :force t)"  Should return T on successful compilation, NIL otherwise.
438    (unless (member :asdf *features*)  ")
439      (error "ASDF is not loaded."))  
440    (with-compilation-hooks ()  (definterface swank-compile-file (input-file output-file load-p
441      (let ((operate (find-symbol "OPERATE" :asdf))                                               external-format
442            (operation (find-symbol operation-name :asdf)))                                               &key policy)
443        (when (null operation)     "Compile INPUT-FILE signalling COMPILE-CONDITIONs.
444          (error "Couldn't find ASDF operation ~S" operation-name))  If LOAD-P is true, load the file after compilation.
445        (apply operate operation system-name keyword-args))))  EXTERNAL-FORMAT is a value returned by find-external-format or
446    :default.
447  (definterface swank-compile-file (filename load-p &optional external-format)  
448     "Compile FILENAME signalling COMPILE-CONDITIONs.  If POLICY is supplied, and non-NIL, it may be used by certain
449  If LOAD-P is true, load the file after compilation.")  implementations to compile with optimization qualities of its
450    value.
451    
452    Should return OUTPUT-TRUENAME, WARNINGS-P and FAILURE-p
453    like `compile-file'")
454    
455  (deftype severity ()  (deftype severity ()
456    '(member :error :read-error :warning :style-warning :note))    '(member :error :read-error :warning :style-warning :note :redefinition))
457    
458  ;; Base condition type for compiler errors, warnings and notes.  ;; Base condition type for compiler errors, warnings and notes.
459  (define-condition compiler-condition (condition)  (define-condition compiler-condition (condition)
# Line 342  If LOAD-P is true, load the file after c Line 471  If LOAD-P is true, load the file after c
471     (message :initarg :message     (message :initarg :message
472              :accessor message)              :accessor message)
473    
474     (short-message :initarg :short-message     ;; Macro expansion history etc. which may be helpful in some cases
475                    :initform nil     ;; but is often very verbose.
476                    :accessor short-message)     (source-context :initarg :source-context
477                       :type (or null string)
478                       :initform nil
479                       :accessor source-context)
480    
481     (references :initarg :references     (references :initarg :references
482                 :initform nil                 :initform nil
# Line 353  If LOAD-P is true, load the file after c Line 485  If LOAD-P is true, load the file after c
485     (location :initarg :location     (location :initarg :location
486               :accessor location)))               :accessor location)))
487    
488    (definterface find-external-format (coding-system)
489      "Return a \"external file format designator\" for CODING-SYSTEM.
490    CODING-SYSTEM is Emacs-style coding system name (a string),
491    e.g. \"latin-1-unix\"."
492      (if (equal coding-system "iso-latin-1-unix")
493          :default
494          nil))
495    
496    (definterface guess-external-format (pathname)
497      "Detect the external format for the file with name pathname.
498    Return nil if the file contains no special markers."
499      ;; Look for a Emacs-style -*- coding: ... -*- or Local Variable: section.
500      (with-open-file (s pathname :if-does-not-exist nil
501                         :external-format (or (find-external-format "latin-1-unix")
502                                              :default))
503        (if s
504            (or (let* ((line (read-line s nil))
505                       (p (search "-*-" line)))
506                  (when p
507                    (let* ((start (+ p (length "-*-")))
508                           (end (search "-*-" line :start2 start)))
509                      (when end
510                        (%search-coding line start end)))))
511                (let* ((len (file-length s))
512                       (buf (make-string (min len 3000))))
513                  (file-position s (- len (length buf)))
514                  (read-sequence buf s)
515                  (let ((start (search "Local Variables:" buf :from-end t))
516                        (end (search "End:" buf :from-end t)))
517                    (and start end (< start end)
518                         (%search-coding buf start end))))))))
519    
520    (defun %search-coding (str start end)
521      (let ((p (search "coding:" str :start2 start :end2 end)))
522        (when p
523          (incf p (length "coding:"))
524          (loop while (and (< p end)
525                           (member (aref str p) '(#\space #\tab)))
526                do (incf p))
527          (let ((end (position-if (lambda (c) (find c '(#\space #\tab #\newline)))
528                                  str :start p)))
529            (find-external-format (subseq str p end))))))
530    
531    
532  ;;;; Streams  ;;;; Streams
533    
534  (definterface make-fn-streams (input-fn output-fn)  (definterface make-output-stream (write-string)
535     "Return character input and output streams backended by functions.    "Return a new character output stream.
536  When input is needed, INPUT-FN is called with no arguments to  The stream calls WRITE-STRING when output is ready.")
537  return a string.  
538  When output is ready, OUTPUT-FN is called with the output as its  (definterface make-input-stream (read-string)
539  argument.    "Return a new character input stream.
540    The stream calls READ-STRING when input is needed.")
 Output should be forced to OUTPUT-FN before calling INPUT-FN.  
   
 The streams are returned as two values.")  
   
 (definterface make-stream-interactive (stream)  
   "Do any necessary setup to make STREAM work interactively.  
 This is called for each stream used for interaction with the user  
 \(e.g. *standard-output*). An implementation could setup some  
 implementation-specific functions to control output flushing at the  
 like."  
   (declare (ignore stream))  
   nil)  
541    
542    
543  ;;;; Documentation  ;;;; Documentation
# Line 383  like." Line 546  like."
546     "Return the lambda list for the symbol NAME. NAME can also be     "Return the lambda list for the symbol NAME. NAME can also be
547  a lisp function object, on lisps which support this.  a lisp function object, on lisps which support this.
548    
549  The result can be a list or the :not-available if the arglist  The result can be a list or the :not-available keyword if the
550  cannot be determined."  arglist cannot be determined."
551     (declare (ignore name))     (declare (ignore name))
552     :not-available)     :not-available)
553    
554    (defgeneric declaration-arglist (decl-identifier)
555      (:documentation
556       "Return the argument list of the declaration specifier belonging to the
557    declaration identifier DECL-IDENTIFIER. If the arglist cannot be determined,
558    the keyword :NOT-AVAILABLE is returned.
559    
560    The different SWANK backends can specialize this generic function to
561    include implementation-dependend declaration specifiers, or to provide
562    additional information on the specifiers defined in ANSI Common Lisp.")
563      (:method (decl-identifier)
564        (case decl-identifier
565          (dynamic-extent '(&rest variables))
566          (ignore         '(&rest variables))
567          (ignorable      '(&rest variables))
568          (special        '(&rest variables))
569          (inline         '(&rest function-names))
570          (notinline      '(&rest function-names))
571          (declaration    '(&rest names))
572          (optimize       '(&any compilation-speed debug safety space speed))
573          (type           '(type-specifier &rest args))
574          (ftype          '(type-specifier &rest function-names))
575          (otherwise
576           (flet ((typespec-p (symbol) (member :type (describe-symbol-for-emacs symbol))))
577             (cond ((and (symbolp decl-identifier) (typespec-p decl-identifier))
578                    '(&rest variables))
579                   ((and (listp decl-identifier) (typespec-p (first decl-identifier)))
580                    '(&rest variables))
581                   (t :not-available)))))))
582    
583    (defgeneric type-specifier-arglist (typespec-operator)
584      (:documentation
585       "Return the argument list of the type specifier belonging to
586    TYPESPEC-OPERATOR.. If the arglist cannot be determined, the keyword
587    :NOT-AVAILABLE is returned.
588    
589    The different SWANK backends can specialize this generic function to
590    include implementation-dependend declaration specifiers, or to provide
591    additional information on the specifiers defined in ANSI Common Lisp.")
592      (:method (typespec-operator)
593        (declare (special *type-specifier-arglists*)) ; defined at end of file.
594        (typecase typespec-operator
595          (symbol (or (cdr (assoc typespec-operator *type-specifier-arglists*))
596                      :not-available))
597          (t :not-available))))
598    
599  (definterface function-name (function)  (definterface function-name (function)
600    "Return the name of the function object FUNCTION.    "Return the name of the function object FUNCTION.
601    
# Line 395  The result is either a symbol, a list, o Line 603  The result is either a symbol, a list, o
603    (declare (ignore function))    (declare (ignore function))
604    nil)    nil)
605    
606    (definterface valid-function-name-p (form)
607      "Is FORM syntactically valid to name a function?
608       If true, FBOUNDP should not signal a type-error for FORM."
609      (flet ((length=2 (list)
610               (and (not (null (cdr list))) (null (cddr list)))))
611        (or (symbolp form)
612            (and (consp form) (length=2 form)
613                 (eq (first form) 'setf) (symbolp (second form))))))
614    
615  (definterface macroexpand-all (form)  (definterface macroexpand-all (form)
616     "Recursively expand all macros in FORM.     "Recursively expand all macros in FORM.
617  Return the resulting form.")  Return the resulting form.")
# Line 405  If FORM is a function call for which a c Line 622  If FORM is a function call for which a c
622  defined, invoke the expander function using *macroexpand-hook* and  defined, invoke the expander function using *macroexpand-hook* and
623  return the results and T.  Otherwise, return the original form and  return the results and T.  Otherwise, return the original form and
624  NIL."  NIL."
625    (let ((fun (and (consp form) (compiler-macro-function (car form)))))    (let ((fun (and (consp form)
626                      (valid-function-name-p (car form))
627                      (compiler-macro-function (car form)))))
628      (if fun      (if fun
629          (let ((result (funcall *macroexpand-hook* fun form env)))          (let ((result (funcall *macroexpand-hook* fun form env)))
630            (values result (not (eq result form))))            (values result (not (eq result form))))
# Line 421  NIL." Line 640  NIL."
640                     (values new-form expanded)))))                     (values new-form expanded)))))
641      (frob form env)))      (frob form env)))
642    
643    (definterface format-string-expand (control-string)
644      "Expand the format string CONTROL-STRING."
645      (macroexpand `(formatter ,control-string)))
646    
647  (definterface describe-symbol-for-emacs (symbol)  (definterface describe-symbol-for-emacs (symbol)
648     "Return a property list describing SYMBOL.     "Return a property list describing SYMBOL.
649    
# Line 470  For example, this is a reasonable place Line 693  For example, this is a reasonable place
693  to safe reader/printer settings, and so on.")  to safe reader/printer settings, and so on.")
694    
695  (definterface call-with-debugger-hook (hook fun)  (definterface call-with-debugger-hook (hook fun)
696    "Call FUN and use HOOK as debugger hook.    "Call FUN and use HOOK as debugger hook. HOOK can be NIL.
697    
698  HOOK should be called for both BREAK and INVOKE-DEBUGGER."  HOOK should be called for both BREAK and INVOKE-DEBUGGER."
699    (let ((*debugger-hook* hook))    (let ((*debugger-hook* hook))
# Line 492  debug the debugger! Instead, such condit Line 715  debug the debugger! Instead, such condit
715  user without (re)entering the debugger by wrapping them as  user without (re)entering the debugger by wrapping them as
716  `sldb-condition's."))  `sldb-condition's."))
717    
718    ;;; The following functions in this section are supposed to be called
719    ;;; within the dynamic contour of CALL-WITH-DEBUGGING-ENVIRONMENT only.
720    
721  (definterface compute-backtrace (start end)  (definterface compute-backtrace (start end)
722     "Return a list containing a backtrace of the condition current     "Returns a backtrace of the condition currently being debugged,
723  being debugged.  The results are unspecified if this function is  that is an ordered list consisting of frames. ``Ordered list''
724  called outside the dynamic contour CALL-WITH-DEBUGGING-ENVIRONMENT.  means that an integer I can be mapped back to the i-th frame of this
725    backtrace.
726    
727  START and END are zero-based indices constraining the number of frames  START and END are zero-based indices constraining the number of frames
728  returned.  Frame zero is defined as the frame which invoked the  returned. Frame zero is defined as the frame which invoked the
729  debugger.  If END is nil, return the frames from START to the end of  debugger. If END is nil, return the frames from START to the end of
730  the stack.")  the stack.")
731    
732  (definterface print-frame (frame stream)  (definterface print-frame (frame stream)
733    "Print frame to stream.")    "Print frame to stream.")
734    
735  (definterface frame-source-location-for-emacs (frame-number)  (definterface frame-restartable-p (frame)
736    "Return the source location for FRAME-NUMBER.")    "Is the frame FRAME restartable?.
737    Return T if `restart-frame' can safely be called on the frame."
738      (declare (ignore frame))
739      nil)
740    
741    (definterface frame-source-location (frame-number)
742      "Return the source location for the frame associated to FRAME-NUMBER.")
743    
744  (definterface frame-catch-tags (frame-number)  (definterface frame-catch-tags (frame-number)
745    "Return a list of XXX list of what? catch tags for a debugger    "Return a list of catch tags for being printed in a debugger stack
746  stack frame.  The results are undefined unless this is called  frame."
747  within the dynamic contour of a function defined by    (declare (ignore frame-number))
748  DEFINE-DEBUGGER-HOOK.")    '())
749    
750  (definterface frame-locals (frame-number)  (definterface frame-locals (frame-number)
751    "Return a list of XXX local variable designators define me    "Return a list of ((&key NAME ID VALUE) ...) where each element of
752  for a debugger stack frame.  The results are undefined unless  the list represents a local variable in the stack frame associated to
753  this is called within the dynamic contour of a function defined  FRAME-NUMBER.
754  by DEFINE-DEBUGGER-HOOK.")  
755    NAME, a symbol; the name of the local variable.
756  (definterface frame-var-value (frame var)  
757    "Return the value of VAR in FRAME.  ID, an integer; used as primary key for the local variable, unique
758  FRAME is the number of the frame in the backtrace.  relatively to the frame under operation.
759  VAR is the number of the variable in the frame.")  
760    value, an object; the value of the local variable.")
761    
762    (definterface frame-var-value (frame-number var-id)
763      "Return the value of the local variable associated to VAR-ID
764    relatively to the frame associated to FRAME-NUMBER.")
765    
766  (definterface disassemble-frame (frame-number)  (definterface disassemble-frame (frame-number)
767    "Disassemble the code for the FRAME-NUMBER.    "Disassemble the code for the FRAME-NUMBER.
# Line 532  FRAME-NUMBER is a non-negative integer." Line 770  FRAME-NUMBER is a non-negative integer."
770    
771  (definterface eval-in-frame (form frame-number)  (definterface eval-in-frame (form frame-number)
772     "Evaluate a Lisp form in the lexical context of a stack frame     "Evaluate a Lisp form in the lexical context of a stack frame
773  in the debugger.  The results are undefined unless called in the  in the debugger.
 dynamic contour of a function defined by DEFINE-DEBUGGER-HOOK.  
774    
775  FRAME-NUMBER must be a positive integer with 0 indicating the  FRAME-NUMBER must be a positive integer with 0 indicating the
776  frame which invoked the debugger.  frame which invoked the debugger.
# Line 541  frame which invoked the debugger. Line 778  frame which invoked the debugger.
778  The return value is the result of evaulating FORM in the  The return value is the result of evaulating FORM in the
779  appropriate context.")  appropriate context.")
780    
781    (definterface frame-call (frame-number)
782      "Return a string representing a call to the entry point of a frame.")
783    
784  (definterface return-from-frame (frame-number form)  (definterface return-from-frame (frame-number form)
785    "Unwind the stack to the frame FRAME-NUMBER and return the value(s)    "Unwind the stack to the frame FRAME-NUMBER and return the value(s)
786  produced by evaluating FORM in the frame context to its caller.  produced by evaluating FORM in the frame context to its caller.
# Line 559  as it was called originally.") Line 799  as it was called originally.")
799    "Format a condition for display in SLDB."    "Format a condition for display in SLDB."
800    (princ-to-string condition))    (princ-to-string condition))
801    
 (definterface condition-references (condition)  
   "Return a list of documentation references for a condition.  
 Each reference is one of:  
   (:ANSI-CL  
    {:FUNCTION | :SPECIAL-OPERATOR | :MACRO | :SECTION | :GLOSSARY }  
    symbol-or-name)  
   (:SBCL :NODE node-name)"  
   (declare (ignore condition))  
   '())  
   
802  (definterface condition-extras (condition)  (definterface condition-extras (condition)
803    "Return a list of extra for the debugger.    "Return a list of extra for the debugger.
804  The allowed elements are of the form:  The allowed elements are of the form:
805    (:SHOW-FRAME-SOURCE frame-number)"    (:SHOW-FRAME-SOURCE frame-number)
806      (:REFERENCES &rest refs)
807    "
808    (declare (ignore condition))    (declare (ignore condition))
809    '())    '())
810    
811    (definterface gdb-initial-commands ()
812      "List of gdb commands supposed to be executed first for the
813       ATTACH-GDB restart."
814      nil)
815    
816  (definterface activate-stepping (frame-number)  (definterface activate-stepping (frame-number)
817    "Prepare the frame FRAME-NUMBER for stepping.")    "Prepare the frame FRAME-NUMBER for stepping.")
818    
# Line 585  The allowed elements are of the form: Line 822  The allowed elements are of the form:
822  (definterface sldb-break-at-start (symbol)  (definterface sldb-break-at-start (symbol)
823    "Set a breakpoint on the beginning of the function for SYMBOL.")    "Set a breakpoint on the beginning of the function for SYMBOL.")
824    
825    (definterface sldb-stepper-condition-p (condition)
826      "Return true if SLDB was invoked due to a single-stepping condition,
827    false otherwise. "
828      (declare (ignore condition))
829      nil)
830    
831    (definterface sldb-step-into ()
832      "Step into the current single-stepper form.")
833    
834    (definterface sldb-step-next ()
835      "Step to the next form in the current function.")
836    
837    (definterface sldb-step-out ()
838      "Stop single-stepping temporarily, but resume it once the current function
839    returns.")
840    
841    
842  ;;;; Definition finding  ;;;; Definition finding
# Line 600  The allowed elements are of the form: Line 852  The allowed elements are of the form:
852    hints)    hints)
853    
854  (defstruct (:error (:type list) :named (:constructor)) message)  (defstruct (:error (:type list) :named (:constructor)) message)
855  (defstruct (:file (:type list) :named (:constructor)) name)  
856  (defstruct (:buffer (:type list) :named (:constructor)) name)  ;;; Valid content for BUFFER slot
857    (defstruct (:file       (:type list) :named (:constructor)) name)
858    (defstruct (:buffer     (:type list) :named (:constructor)) name)
859    (defstruct (:etags-file (:type list) :named (:constructor)) filename)
860    
861    ;;; Valid content for POSITION slot
862  (defstruct (:position (:type list) :named (:constructor)) pos)  (defstruct (:position (:type list) :named (:constructor)) pos)
863    (defstruct (:tag      (:type list) :named (:constructor)) tag1 tag2)
864    
865    (defmacro converting-errors-to-error-location (&body body)
866      "Catches errors during BODY and converts them to an error location."
867      (let ((gblock (gensym "CONVERTING-ERRORS+")))
868        `(block ,gblock
869           (handler-bind ((error
870                           #'(lambda (e)
871                                (if *debug-swank-backend*
872                                    nil     ;decline
873                                    (return-from ,gblock
874                                      (make-error-location e))))))
875             ,@body))))
876    
877    (defun make-error-location (datum &rest args)
878      (cond ((typep datum 'condition)
879             `(:error ,(format nil "Error: ~A" datum)))
880            ((symbolp datum)
881             `(:error ,(format nil "Error: ~A" (apply #'make-condition datum args))))
882            (t
883             (assert (stringp datum))
884             `(:error ,(apply #'format nil datum args)))))
885    
886  (definterface find-definitions (name)  (definterface find-definitions (name)
887     "Return a list ((DSPEC LOCATION) ...) for NAME's definitions.     "Return a list ((DSPEC LOCATION) ...) for NAME's definitions.
# Line 615  definition, e.g., FOO or (METHOD FOO (ST Line 894  definition, e.g., FOO or (METHOD FOO (ST
894    
895  LOCATION is the source location for the definition.")  LOCATION is the source location for the definition.")
896    
897    (definterface find-source-location (object)
898      "Returns the source location of OBJECT, or NIL.
899    
900    That is the source location of the underlying datastructure of
901    OBJECT. E.g. on a STANDARD-OBJECT, the source location of the
902    respective DEFCLASS definition is returned, on a STRUCTURE-CLASS the
903    respective DEFSTRUCT definition, and so on."
904      ;; This returns one source location and not a list of locations. It's
905      ;; supposed to return the location of the DEFGENERIC definition on
906      ;; #'SOME-GENERIC-FUNCTION.
907      (declare (ignore object))
908      (make-error-location "FIND-DEFINITIONS is not yet implemented on ~
909                            this implementation."))
910    
911    
912  (definterface buffer-first-change (filename)  (definterface buffer-first-change (filename)
913    "Called for effect the first time FILENAME's buffer is modified."    "Called for effect the first time FILENAME's buffer is modified."
914    (declare (ignore filename))    (declare (ignore filename))
915    nil)    nil)
916    
917    
918    
919  ;;;; XREF  ;;;; XREF
920    
921  (definterface who-calls (function-name)  (definterface who-calls (function-name)
922    "Return the call sites of FUNCTION-NAME (a symbol).    "Return the call sites of FUNCTION-NAME (a symbol).
923  The results is a list ((DSPEC LOCATION) ...).")  The results is a list ((DSPEC LOCATION) ...)."
924      (declare (ignore function-name))
925      :not-implemented)
926    
927  (definterface calls-who (function-name)  (definterface calls-who (function-name)
928    "Return the call sites of FUNCTION-NAME (a symbol).    "Return the call sites of FUNCTION-NAME (a symbol).
929  The results is a list ((DSPEC LOCATION) ...).")  The results is a list ((DSPEC LOCATION) ...)."
930      (declare (ignore function-name))
931      :not-implemented)
932    
933  (definterface who-references (variable-name)  (definterface who-references (variable-name)
934    "Return the locations where VARIABLE-NAME (a symbol) is referenced.    "Return the locations where VARIABLE-NAME (a symbol) is referenced.
935  See WHO-CALLS for a description of the return value.")  See WHO-CALLS for a description of the return value."
936      (declare (ignore variable-name))
937      :not-implemented)
938    
939  (definterface who-binds (variable-name)  (definterface who-binds (variable-name)
940    "Return the locations where VARIABLE-NAME (a symbol) is bound.    "Return the locations where VARIABLE-NAME (a symbol) is bound.
941  See WHO-CALLS for a description of the return value.")  See WHO-CALLS for a description of the return value."
942      (declare (ignore variable-name))
943      :not-implemented)
944    
945  (definterface who-sets (variable-name)  (definterface who-sets (variable-name)
946    "Return the locations where VARIABLE-NAME (a symbol) is set.    "Return the locations where VARIABLE-NAME (a symbol) is set.
947  See WHO-CALLS for a description of the return value.")  See WHO-CALLS for a description of the return value."
948      (declare (ignore variable-name))
949      :not-implemented)
950    
951  (definterface who-macroexpands (macro-name)  (definterface who-macroexpands (macro-name)
952    "Return the locations where MACRO-NAME (a symbol) is expanded.    "Return the locations where MACRO-NAME (a symbol) is expanded.
953  See WHO-CALLS for a description of the return value.")  See WHO-CALLS for a description of the return value."
954      (declare (ignore macro-name))
955      :not-implemented)
956    
957  (definterface who-specializes (class-name)  (definterface who-specializes (class-name)
958    "Return the locations where CLASS-NAME (a symbol) is specialized.    "Return the locations where CLASS-NAME (a symbol) is specialized.
959  See WHO-CALLS for a description of the return value.")  See WHO-CALLS for a description of the return value."
960      (declare (ignore class-name))
961      :not-implemented)
962    
963  ;;; Simpler variants.  ;;; Simpler variants.
964    
# Line 706  themselves, that is, their dispatch func Line 1015  themselves, that is, their dispatch func
1015    
1016  ;;;; Inspector  ;;;; Inspector
1017    
1018  (defclass inspector ()  (defgeneric emacs-inspect (object)
1019    ()    (:documentation
   (:documentation "Super class of inspector objects.  
   
 Implementations should sub class in order to dispatch off of the  
 inspect-for-emacs method."))  
   
 (definterface make-default-inspector ()  
   "Return an inspector object suitable for passing to inspect-for-emacs.")  
   
 (definterface inspect-for-emacs (object inspector)  
1020     "Explain to Emacs how to inspect OBJECT.     "Explain to Emacs how to inspect OBJECT.
1021    
1022  The argument INSPECTOR is an object representing how to get at  Returns a list specifying how to render the object for inspection.
 the internals of OBJECT, it is usually an implementation specific  
 class used simply for dispatching to the proper method.  
   
 The orgument INSPECTION-MODE is an object specifying how, and  
 what, to show to the user.  
   
 Returns two values: a string which will be used as the title of  
 the inspector buffer and a list specifying how to render the  
 object for inspection.  
1023    
1024  Every element of the list must be either a string, which will be  Every element of the list must be either a string, which will be
1025  inserted into the buffer as is, or a list of the form:  inserted into the buffer as is, or a list of the form:
# Line 739  inserted into the buffer as is, or a lis Line 1030  inserted into the buffer as is, or a lis
1030    
1031   (:newline) - Render a \\n   (:newline) - Render a \\n
1032    
1033   (:action label lambda) - Render LABEL (a text string) which when   (:action label lambda &key (refresh t)) - Render LABEL (a text
1034   clicked will call LAMBDA.   string) which when clicked will call LAMBDA. If REFRESH is
1035     non-NIL the currently inspected object will be re-inspected
1036     after calling the lambda.
1037    "))
1038    
1039   NIL - do nothing.")  (defmethod emacs-inspect ((object t))
   
 (defmethod inspect-for-emacs ((object t) (inspector t))  
1040    "Generic method for inspecting any kind of object.    "Generic method for inspecting any kind of object.
1041    
1042  Since we don't know how to deal with OBJECT we simply dump the  Since we don't know how to deal with OBJECT we simply dump the
1043  output of CL:DESCRIBE."  output of CL:DESCRIBE."
   (declare (ignore inspector))  
   (values  
    "A value."  
1044     `("Type: " (:value ,(type-of object)) (:newline)     `("Type: " (:value ,(type-of object)) (:newline)
1045       "Don't know how to inspect the object, dumping output of CL:DESCRIBE:"       "Don't know how to inspect the object, dumping output of CL:DESCRIBE:"
1046       (:newline) (:newline)       (:newline) (:newline)
1047       ,(with-output-to-string (desc) (describe object desc)))))       ,(with-output-to-string (desc) (describe object desc))))
1048    
1049    (definterface eval-context (object)
1050      "Return a list of bindings corresponding to OBJECT's slots."
1051      (declare (ignore object))
1052      '())
1053    
1054  ;;; Utilities for inspector methods.  ;;; Utilities for inspector methods.
1055  ;;;  ;;;
1056  (defun label-value-line (label value)  
1057    "Create a control list which prints \"LABEL: VALUE\" in the inspector."  (defun label-value-line (label value &key (newline t))
1058    (list (princ-to-string label) ": " `(:value ,value) '(:newline)))    "Create a control list which prints \"LABEL: VALUE\" in the inspector.
1059    If NEWLINE is non-NIL a `(:newline)' is added to the result."
1060    
1061      (list* (princ-to-string label) ": " `(:value ,value)
1062             (if newline '((:newline)) nil)))
1063    
1064  (defmacro label-value-line* (&rest label-values)  (defmacro label-value-line* (&rest label-values)
1065    ` (append ,@(loop for (label value) in label-values    ` (append ,@(loop for (label value) in label-values
# Line 778  output of CL:DESCRIBE." Line 1076  output of CL:DESCRIBE."
1076  ;;; The default implementations are sufficient for non-multiprocessing  ;;; The default implementations are sufficient for non-multiprocessing
1077  ;;; implementations.  ;;; implementations.
1078    
1079  (definterface initialize-multiprocessing ()  (definterface initialize-multiprocessing (continuation)
1080     "Initialize multiprocessing, if necessary."     "Initialize multiprocessing, if necessary and then invoke CONTINUATION.
    nil)  
1081    
1082  (definterface startup-idle-and-top-level-loops ()  Depending on the impleimentaion, this function may never return."
1083    "This function is called directly through the listener, not in an RPC     (funcall continuation))
 from Emacs. This is to support interfaces such as CMUCL's  
 MP::STARTUP-IDLE-AND-TOP-LEVEL-LOOPS which does not return like a  
 normal function."  
    nil)  
1084    
1085  (definterface spawn (fn &key name)  (definterface spawn (fn &key name)
1086    "Create a new thread to call FN.")    "Create a new thread to call FN.")
# Line 796  normal function." Line 1089  normal function."
1089    "Return an Emacs-parsable object to identify THREAD.    "Return an Emacs-parsable object to identify THREAD.
1090    
1091  Ids should be comparable with equal, i.e.:  Ids should be comparable with equal, i.e.:
1092   (equal (thread-id <t1>) (thread-id <t2>)) <==> (eq <t1> <t2>)")   (equal (thread-id <t1>) (thread-id <t2>)) <==> (eq <t1> <t2>)"
1093      thread)
1094    
1095  (definterface find-thread (id)  (definterface find-thread (id)
1096    "Return the thread for ID.    "Return the thread for ID.
1097  ID should be an id previously obtained with THREAD-ID.  ID should be an id previously obtained with THREAD-ID.
1098  Can return nil if the thread no longer exists.")  Can return nil if the thread no longer exists."
1099      (declare (ignore id))
1100      (current-thread))
1101    
1102  (definterface thread-name (thread)  (definterface thread-name (thread)
1103     "Return the name of THREAD.     "Return the name of THREAD.
1104    Thread names are short strings meaningful to the user. They do not
1105  Thread names are be single-line strings and are meaningful to the  have to be unique."
 user. They do not have to be unique."  
1106     (declare (ignore thread))     (declare (ignore thread))
1107     "The One True Thread")     "The One True Thread")
1108    
# Line 816  user. They do not have to be unique." Line 1111  user. They do not have to be unique."
1111     (declare (ignore thread))     (declare (ignore thread))
1112     "")     "")
1113    
1114    (definterface thread-attributes (thread)
1115      "Return a plist of implementation-dependent attributes for THREAD"
1116      (declare (ignore thread))
1117      '())
1118    
1119  (definterface make-lock (&key name)  (definterface make-lock (&key name)
1120     "Make a lock for thread synchronization.     "Make a lock for thread synchronization.
1121  Only one thread may hold the lock (via CALL-WITH-LOCK-HELD) at a time."  Only one thread may hold the lock (via CALL-WITH-LOCK-HELD) at a time
1122    but that thread may hold it more than once."
1123     (declare (ignore name))     (declare (ignore name))
1124     :null-lock)     :null-lock)
1125    
# Line 833  Only one thread may hold the lock (via C Line 1134  Only one thread may hold the lock (via C
1134    0)    0)
1135    
1136  (definterface all-threads ()  (definterface all-threads ()
1137    "Return a list of all threads.")    "Return a fresh list of all threads."
1138      '())
1139    
1140  (definterface thread-alive-p (thread)  (definterface thread-alive-p (thread)
1141    "Test if THREAD is termintated."    "Test if THREAD is termintated."
# Line 843  Only one thread may hold the lock (via C Line 1145  Only one thread may hold the lock (via C
1145    "Cause THREAD to execute FN.")    "Cause THREAD to execute FN.")
1146    
1147  (definterface kill-thread (thread)  (definterface kill-thread (thread)
1148    "Kill THREAD."    "Terminate THREAD immediately.
1149    Don't execute unwind-protected sections, don't raise conditions.
1150    (Do not pass go, do not collect $200.)"
1151    (declare (ignore thread))    (declare (ignore thread))
1152    nil)    nil)
1153    
1154  (definterface send (thread object)  (definterface send (thread object)
1155    "Send OBJECT to thread THREAD.")    "Send OBJECT to thread THREAD.")
1156    
1157  (definterface receive ()  (definterface receive (&optional timeout)
1158    "Return the next message from current thread's mailbox.")    "Return the next message from current thread's mailbox."
1159      (receive-if (constantly t) timeout))
1160    
1161    (definterface receive-if (predicate &optional timeout)
1162      "Return the first message satisfiying PREDICATE.")
1163    
1164    (definterface set-default-initial-binding (var form)
1165      "Initialize special variable VAR by default with FORM.
1166    
1167    Some implementations initialize certain variables in each newly
1168    created thread.  This function sets the form which is used to produce
1169    the initial value."
1170      (set var (eval form)))
1171    
1172    ;; List of delayed interrupts.
1173    ;; This should only have thread-local bindings, so no init form.
1174    (defvar *pending-slime-interrupts*)
1175    
1176    (defun check-slime-interrupts ()
1177      "Execute pending interrupts if any.
1178    This should be called periodically in operations which
1179    can take a long time to complete.
1180    Return a boolean indicating whether any interrupts was processed."
1181      (when (and (boundp '*pending-slime-interrupts*)
1182                 *pending-slime-interrupts*)
1183        (funcall (pop *pending-slime-interrupts*))
1184        t))
1185    
1186    (defvar *interrupt-queued-handler* nil
1187      "Function to call on queued interrupts.
1188    Interrupts get queued when an interrupt occurs while interrupt
1189    handling is disabled.
1190    
1191    Backends can use this function to abort slow operations.")
1192    
1193    (definterface wait-for-input (streams &optional timeout)
1194      "Wait for input on a list of streams.  Return those that are ready.
1195    STREAMS is a list of streams
1196    TIMEOUT nil, t, or real number. If TIMEOUT is t, return
1197    those streams which are ready immediately, without waiting.
1198    If TIMEOUT is a number and no streams is ready after TIMEOUT seconds,
1199    return nil.
1200    
1201    Return :interrupt if an interrupt occurs while waiting."
1202      (assert (member timeout '(nil t)))
1203      (cond #+(or)
1204            ((null (cdr streams))
1205             (wait-for-one-stream (car streams) timeout))
1206            (t
1207             (wait-for-streams streams timeout))))
1208    
1209    (defun wait-for-streams (streams timeout)
1210      (loop
1211       (when (check-slime-interrupts) (return :interrupt))
1212       (let ((ready (remove-if-not #'stream-readable-p streams)))
1213         (when ready (return ready)))
1214       (when timeout (return nil))
1215       (sleep 0.1)))
1216    
1217    ;; Note: Usually we can't interrupt PEEK-CHAR cleanly.
1218    (defun wait-for-one-stream (stream timeout)
1219      (ecase timeout
1220        ((nil)
1221         (cond ((check-slime-interrupts) :interrupt)
1222               (t (peek-char nil stream nil nil)
1223                  (list stream))))
1224        ((t)
1225         (let ((c (read-char-no-hang stream nil nil)))
1226           (cond (c
1227                  (unread-char c stream)
1228                  (list stream))
1229                 (t '()))))))
1230    
1231    (defun stream-readable-p (stream)
1232      (let ((c (read-char-no-hang stream nil :eof)))
1233        (cond ((not c) nil)
1234              ((eq c :eof) t)
1235              (t (unread-char c stream) t))))
1236    
1237  (definterface toggle-trace (spec)  (definterface toggle-trace (spec)
1238    "Toggle tracing of the function(s) given with SPEC.    "Toggle tracing of the function(s) given with SPEC.
# Line 873  SPEC can be: Line 1254  SPEC can be:
1254  (definterface make-weak-value-hash-table (&rest args)  (definterface make-weak-value-hash-table (&rest args)
1255    "Like MAKE-HASH-TABLE, but weak w.r.t. the values."    "Like MAKE-HASH-TABLE, but weak w.r.t. the values."
1256    (apply #'make-hash-table args))    (apply #'make-hash-table args))
1257    
1258    (definterface hash-table-weakness (hashtable)
1259      "Return nil or one of :key :value :key-or-value :key-and-value"
1260      (declare (ignore hashtable))
1261      nil)
1262    
1263    
1264    ;;;; Character names
1265    
1266    (definterface character-completion-set (prefix matchp)
1267      "Return a list of names of characters that match PREFIX."
1268      ;; Handle the standard and semi-standard characters.
1269      (loop for name in '("Newline" "Space" "Tab" "Page" "Rubout"
1270                          "Linefeed" "Return" "Backspace")
1271         when (funcall matchp prefix name)
1272         collect name))
1273    
1274    
1275    (defparameter *type-specifier-arglists*
1276      '((and                . (&rest type-specifiers))
1277        (array              . (&optional element-type dimension-spec))
1278        (base-string        . (&optional size))
1279        (bit-vector         . (&optional size))
1280        (complex            . (&optional type-specifier))
1281        (cons               . (&optional car-typespec cdr-typespec))
1282        (double-float       . (&optional lower-limit upper-limit))
1283        (eql                . (object))
1284        (float              . (&optional lower-limit upper-limit))
1285        (function           . (&optional arg-typespec value-typespec))
1286        (integer            . (&optional lower-limit upper-limit))
1287        (long-float         . (&optional lower-limit upper-limit))
1288        (member             . (&rest eql-objects))
1289        (mod                . (n))
1290        (not                . (type-specifier))
1291        (or                 . (&rest type-specifiers))
1292        (rational           . (&optional lower-limit upper-limit))
1293        (real               . (&optional lower-limit upper-limit))
1294        (satisfies          . (predicate-symbol))
1295        (short-float        . (&optional lower-limit upper-limit))
1296        (signed-byte        . (&optional size))
1297        (simple-array       . (&optional element-type dimension-spec))
1298        (simple-base-string . (&optional size))
1299        (simple-bit-vector  . (&optional size))
1300        (simple-string      . (&optional size))
1301        (single-float       . (&optional lower-limit upper-limit))
1302        (simple-vector      . (&optional size))
1303        (string             . (&optional size))
1304        (unsigned-byte      . (&optional size))
1305        (values             . (&rest typespecs))
1306        (vector             . (&optional element-type size))
1307        ))
1308    
1309    ;;; Heap dumps
1310    
1311    (definterface save-image (filename &optional restart-function)
1312      "Save a heap image to the file FILENAME.
1313    RESTART-FUNCTION, if non-nil, should be called when the image is loaded.")
1314    
1315    (definterface background-save-image (filename &key restart-function
1316                                                  completion-function)
1317      "Request saving a heap image to the file FILENAME.
1318    RESTART-FUNCTION, if non-nil, should be called when the image is loaded.
1319    COMPLETION-FUNCTION, if non-nil, should be called after saving the image.")

Legend:
Removed from v.1.94  
changed lines
  Added in v.1.202

  ViewVC Help
Powered by ViewVC 1.1.5