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

Contents of /slime/swank-backend.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations)
Thu Dec 11 02:19:33 2003 UTC (10 years, 4 months ago) by dbarlow
Branch: MAIN
Changes since 1.7: +7 -1 lines
        * swank-backend.lisp (call-with-compilation-hooks): new GF
        should set up all appropriate error condition loggers etc
        to do a compilation preserving the notes.  Implement for
        sbcl, cmucl
1 ;;;; -*- Mode: lisp; indent-tabs-mode: nil; outline-regexp: ";;;;;*" -*-
2 ;;;
3 ;;; slime-impl.lisp --- Slime interface reference implementation.
4 ;;;
5 ;;; Copyright (C) 2003, James Bielman <jamesjb@jamesjb.com>
6 ;;; Released into the public domain.
7 ;;;
8 ;;; $Id: swank-backend.lisp,v 1.8 2003/12/11 02:19:33 dbarlow Exp $
9 ;;;
10
11 ;; This is a skeletal implementation of the Slime internals interface.
12 ;;
13 ;; The idea is to create a de-facto standard interface that can be
14 ;; used by editor <-> CL integration software, such as Slime. Vendors
15 ;; are encouraged to comment on this interface.
16
17 (defpackage :swank
18 (:use :common-lisp)
19 (:nicknames #:swank-backend)
20 (:export #:start-server #:create-swank-server
21 #:*sldb-pprint-frames*
22 #:eval-string
23 #:interactive-eval-region
24 #:interactive-eval
25 #:pprint-eval
26 #:re-evaluate-defvar
27 #:listener-eval
28 #:swank-compile-file
29 #:swank-compile-string
30 #:compiler-notes-for-emacs
31 #:load-file
32 #:set-default-directory
33 #:set-package
34 #:list-all-package-names
35 #:getpid
36 #:disassemble-symbol
37 #:describe-symbol
38 #:describe-alien-type
39 #:describe-function
40 #:describe-type
41 #:describe-alien-struct
42 #:describe-class
43 #:describe-inspectee
44 #:describe-alien-union
45 #:describe-alien-enum
46 #:describe-setf-function
47 #:documentation-symbol
48 #:arglist-string
49 #:completions
50 #:apropos-list-for-emacs
51 #:inspect-nth-part
52 #:inspect-in-frame
53 #:init-inspector
54 #:quit-inspector
55 #:inspector-next
56 #:swank-macroexpand-all
57 #:swank-macroexpand
58 #:swank-macroexpand-1
59 #:untrace-all
60 #:toggle-trace-fdefinition
61 #:find-function-locations
62 #:who-binds
63 #:who-references
64 #:who-calls
65 #:who-sets
66 #:who-macroexpands
67 #:list-callers
68 #:list-callees
69 #:backtrace
70 #:frame-catch-tags
71 #:frame-source-position
72 #:frame-locals
73 #:throw-to-toplevel
74 #:inspector-pop
75 #:invoke-nth-restart
76 #:pprint-eval-string-in-frame
77 #:frame-source-location-for-emacs
78 #:eval-in-frame
79 #:eval-string-in-frame
80 #:sldb-abort
81 #:sldb-continue
82 #:take-input
83 #:slime-debugger-function
84 ))
85
86 (in-package :swank)
87
88
89 ;;;; Conditions and Error Handling
90
91 ;; XXX need to specify restart behavior for errors/warnings?
92
93 (define-condition not-implemented-error (error)
94 ())
95
96 (deftype severity () '(member :error :warning :style-warning :note))
97
98 ;; Base condition type for compiler errors, warnings and notes.
99 (define-condition compiler-condition (condition)
100 ((original-condition
101 ;; The original condition thrown by the compiler if appropriate.
102 ;; May be NIL if a compiler does not report using conditions.
103 :initarg :original-condition
104 :accessor original-condition)
105
106 (severity
107 :type severity
108 :initarg :severity
109 :accessor severity)
110
111 (message
112 :initarg :message
113 :accessor message)
114
115 (location
116 :initarg :location
117 :accessor location)))
118
119
120 ;;;; Compilation
121
122 (defgeneric call-with-compilation-hooks (func)
123 (:documentation
124 "Call FUNC with hooks to trigger SLDB on compiler errors."))
125 (defmacro with-compilation-hooks (() &body body)
126 `(call-with-compilation-hooks (lambda () (progn ,@body))))
127
128 (defgeneric compile-string-for-emacs (string &key buffer position)
129 (:documentation
130 "Compile source from STRING. During compilation, compiler
131 conditions must be trapped and resignalled as COMPILER-CONDITIONs.
132
133 If supplied, BUFFER and POSITION specify the source location in Emacs.
134
135 Additionally, if POSITION is supplied, it must be added to source
136 positions reported in compiler conditions."))
137
138 (defgeneric compile-file-for-emacs (filename load-p)
139 (:documentation
140 "Compile FILENAME signalling COMPILE-CONDITIONs.
141 If LOAD-P is true, load the file after compilation."))
142
143
144 ;;;; Documentation
145
146 (defgeneric arglist-string (function-name)
147 (:documentation
148 "Return the argument for FUNCTION-NAME as a string.
149 The result should begin and end with parenthesis."))
150
151 (defgeneric macroexpand-all (form)
152 (:documentation
153 "Recursively expand all macros in FORM.
154 Return the resulting form."))
155
156 (defgeneric describe-symbol-for-emacs (symbol)
157 (:documentation
158 "Return a property list describing SYMBOL.
159
160 The property list has an entry for each interesting aspect of the
161 symbol. The recognised keys are:
162
163 :VARIABLE :FUNCTION :SETF :TYPE :CLASS :MACRO :COMPILER-MACRO
164 :ALIEN-TYPE :ALIEN-STRUCT :ALIEN-UNION :ALIEN-ENUM
165
166 The value of each property is the corresponding documentation string,
167 or :NOT-DOCUMENTED. It is legal to include keys not listed here.
168
169 Properties should be included if and only if they are applicable to
170 the symbol. For example, only (and all) fbound symbols should include
171 the :FUNCTION property.
172
173 Example:
174 \(describe-symbol-for-emacs 'vector)
175 => (:CLASS :NOT-DOCUMENTED
176 :TYPE :NOT-DOCUMENTED
177 :FUNCTION \"Constructs a simple-vector from the given objects.\")"))
178
179
180 ;;;; Debugging
181
182 (defgeneric call-with-debugging-environment (debugger-loop-fn)
183 (:documentation
184 "Call DEBUGGER-LOOP-FN in a suitable debugging environment.
185
186 This function is called recursively at each debug level to invoke the
187 debugger loop. The purpose is to setup any necessary environment for
188 other debugger callbacks that will be called within the debugger loop.
189
190 For example, this is a reasonable place to compute a backtrace, switch
191 to safe reader/printer settings, and so on."))
192
193 (define-condition sldb-condition (condition)
194 ((original-condition
195 :initarg :original-condition
196 :accessor original-condition))
197 (:documentation
198 "Wrapper for conditions that should not be debugged.
199
200 When a condition arises from the internals of the debugger, it is not
201 desirable to debug it -- we'd risk entering an endless loop trying to
202 debug the debugger! Instead, such conditions can be reported to the
203 user without (re)entering the debugger by wrapping them as
204 `sldb-condition's."))
205
206 (defgeneric debugger-info-for-emacs (start end)
207 (:documentation
208 "Return debugger state, with stack frames from START to END.
209 The result is a list:
210 (condition-description ({restart}*) ({stack-frame}*)
211 where
212 restart ::= (name description)
213 stack-frame ::= (number description)
214
215 condition-description---a string describing the condition that
216 triggered the debugger.
217
218 restart---a pair of strings: restart name, and description.
219
220 stack-frame---a number from zero (the top), and a printed
221 representation of the frame's call.
222
223 Below is an example return value. In this case the condition was a
224 division by zero (multi-line description), and only one frame is being
225 fetched (start=0, end=1).
226
227 (\"Arithmetic error DIVISION-BY-ZERO signalled.
228 Operation was KERNEL::DIVISION, operands (1 0).
229 [Condition of type DIVISION-BY-ZERO]\"
230 ((\"ABORT\" \"Return to Slime toplevel.\")
231 (\"ABORT\" \"Return to Top-Level.\"))
232 ((0 \"0: (KERNEL::INTEGER-/-INTEGER 1 0)\")))"))
233
234 (defgeneric backtrace (start end)
235 (:documentation
236 "Return a list containing a backtrace of the condition current
237 being debugged. The results are unspecified if this function is
238 called outside the dynamic contour of a debugger hook defined by
239 DEFINE-DEBUGGER-HOOK.
240
241 START and END are zero-based indices constraining the number of
242 frames returned. Frame zero is defined as the frame which invoked
243 the debugger.
244
245 The backtrace is returned as a list of tuples of the form
246 \(FRAME-NUMBER FRAME-DESCRIPTION), where FRAME-NUMBER is the
247 index of the frame, defined like START/END, and FRAME-DESCRIPTION
248 is a string containing text to display in the debugger for this
249 frame.
250
251 An example return value:
252
253 ((0 \"(HELLO \"world\")\")
254 (1 \"(RUN-EXCITING-LISP-DEMO)\")
255 (2 \"(SYS::%TOPLEVEL #<SYS::ENVIRONMENT #x394834>)\"))"))
256
257 (defgeneric frame-source-location-for-emacs (frame-number)
258 (:documentation
259 "Return the source location for FRAME-NUMBER."))
260
261 (defgeneric frame-catch-tags (frame-number)
262 (:documentation
263 "Return a list of XXX list of what? catch tags for a debugger
264 stack frame. The results are undefined unless this is called
265 within the dynamic contour of a function defined by
266 DEFINE-DEBUGGER-HOOK."))
267
268 (defgeneric frame-locals (frame-number)
269 (:documentation
270 "Return a list of XXX local variable designators define me
271 for a debugger stack frame. The results are undefined unless
272 this is called within the dynamic contour of a function defined
273 by DEFINE-DEBUGGER-HOOK."))
274
275 (defgeneric eval-in-frame (form frame-number)
276 (:documentation
277 "Evaluate a Lisp form in the lexical context of a stack frame
278 in the debugger. The results are undefined unless called in the
279 dynamic contour of a function defined by DEFINE-DEBUGGER-HOOK.
280
281 FRAME-NUMBER must be a positive integer with 0 indicating the
282 frame which invoked the debugger.
283
284 The return value is the result of evaulating FORM in the
285 appropriate context."))
286
287
288 ;;;; Queries
289
290 #+(or)
291 ;;; This is probably a better interface than find-function-locations.
292 (defgeneric find-definitions (name)
293 (:documentation
294 "Return a list of (LABEL . LOCATION) pairs for NAME's definitions.
295
296 NAME is string denoting a symbol or \"definition specifier\".
297
298 LABEL is a string describing the definition, e.g., \"foo\" or
299 \"(method foo (string number))\" or \"(variable bar)\".
300
301 LOCATION is a source location of the form:
302
303 <location> ::= (:location <buffer> <position>)
304 | (:error <message>)
305
306 <buffer> ::= (:file <filename>)
307 | (:buffer <buffername>)
308 | (:source-form <string>)
309
310 <position> ::= (:position <fixnum> [<align>]) ; 1 based
311 | (:function-name <string>)
312 "))
313
314 (defgeneric find-function-locations (name)
315 (:documentation
316 "Return a list (LOCATION LOCATION ...) for NAME's definitions.
317
318 LOCATION is a source location of the form:
319
320 <location> ::= (:location <buffer> <position>)
321 | (:error <message>)
322
323 <buffer> ::= (:file <filename>)
324 | (:buffer <buffername>)
325 | (:source-form <string>)
326
327 <position> ::= (:position <fixnum> [<align>]) ; 1 based
328 | (:function-name <string>)"))
329

  ViewVC Help
Powered by ViewVC 1.1.5