Skip to content
Newer
Older
100644 662 lines (546 sloc) 22 KB
d502794 (find-external-format): Translate :utf-8-unix to :utf8, which Allegro
Helmut Eller authored
1 ;;;; -*- indent-tabs-mode: nil; outline-regexp: ";;;;;* "; -*-
f912c9c New file.
Helmut Eller authored
2 ;;;
3 ;;; swank-allegro.lisp --- Allegro CL specific code for SLIME.
4 ;;;
2ab1edd (find-fspec-location): excl:source-file can return stuff like
Helmut Eller authored
5 ;;; Created 2003
f912c9c New file.
Helmut Eller authored
6 ;;;
7 ;;; This code has been placed in the Public Domain. All warranties
521e923 (swank-compile-file): New optional argument `external-format'.
Helmut Eller authored
8 ;;; are disclaimed.
f912c9c New file.
Helmut Eller authored
9 ;;;
10
8052a9e Minor modifications.
Helmut Eller authored
11 (in-package :swank-backend)
12
f912c9c New file.
Helmut Eller authored
13 (eval-when (:compile-toplevel :load-toplevel :execute)
14 (require :sock)
d502794 (find-external-format): Translate :utf-8-unix to :utf8, which Allegro
Helmut Eller authored
15 (require :process))
aa65d6e Implemented.
Luke Gorrie authored
16
d502794 (find-external-format): Translate :utf-8-unix to :utf8, which Allegro
Helmut Eller authored
17 (import-from :excl *gray-stream-symbols* :swank-backend)
f912c9c New file.
Helmut Eller authored
18
f759e67 2004-09-13 Marco Baringer <mb@bese.it>
Marco Baringer authored
19 ;;; swank-mop
20
2ab1edd (find-fspec-location): excl:source-file can return stuff like
Helmut Eller authored
21 ;; maybe better change MOP to ACLMOP ?
22 ;; CLOS also works in ACL5. --he
23 (import-swank-mop-symbols :clos '(:slot-definition-documentation))
ff1fa86 2004-09-13 Marco Baringer <mb@bese.it>
Marco Baringer authored
24
25 (defun swank-mop:slot-definition-documentation (slot)
5bb5d51 (swank-mop:slot-definition-documentation): ACL 7 says documentation
Helmut Eller authored
26 (documentation slot t))
f759e67 2004-09-13 Marco Baringer <mb@bese.it>
Marco Baringer authored
27
d502794 (find-external-format): Translate :utf-8-unix to :utf8, which Allegro
Helmut Eller authored
28
fab0b31 Add multiprocessing support.
Helmut Eller authored
29 ;;;; TCP Server
f912c9c New file.
Helmut Eller authored
30
8052a9e Minor modifications.
Helmut Eller authored
31 (defimplementation preferred-communication-style ()
32 :spawn)
92d6085 Use signal driven IO for CMUCL and SBCL. Use one thread per request
Helmut Eller authored
33
39861f4 (create-socket): Take interface as argument.
Helmut Eller authored
34 (defimplementation create-socket (host port)
35 (socket:make-socket :connect :passive :local-port port
36 :local-host host :reuse-address t))
bba6c65 (format-condition-for-emacs): Replaced with debugger-condition-for-em…
Helmut Eller authored
37
72f16c0 Replace defmethod with defimplementation.
Helmut Eller authored
38 (defimplementation local-port (socket)
7b493c0 (create-socket, local-port, close-socket, accept-connection)
Helmut Eller authored
39 (socket:local-port socket))
c9ef56e (create-swank-server): Add support for BACKGROUND and CLOSE argument.
Helmut Eller authored
40
72f16c0 Replace defmethod with defimplementation.
Helmut Eller authored
41 (defimplementation close-socket (socket)
7b493c0 (create-socket, local-port, close-socket, accept-connection)
Helmut Eller authored
42 (close socket))
c9ef56e (create-swank-server): Add support for BACKGROUND and CLOSE argument.
Helmut Eller authored
43
a60a913 (accept-connection): New argument: buffering.
Helmut Eller authored
44 (defimplementation accept-connection (socket &key external-format buffering)
45 (declare (ignore buffering))
358236a (handle-compiler-warning): Handle undefined-functions warnings by
Helmut Eller authored
46 (let ((ef (or external-format :iso-latin-1-unix))
47 (s (socket:accept-connection socket :wait t)))
48 (set-external-format s ef)
984c411 (accept-connection): Accept :external-format as argument.
Helmut Eller authored
49 s))
c9ef56e (create-swank-server): Add support for BACKGROUND and CLOSE argument.
Helmut Eller authored
50
521e923 (swank-compile-file): New optional argument `external-format'.
Helmut Eller authored
51 (defun find-external-format (coding-system)
52 #+(version>= 6)
2bbbb17 (find-external-format): Fix typo.
Helmut Eller authored
53 (let* ((name (ecase coding-system
ca9bb1b (set-external-format): New function. Use LF as eol mark.
Helmut Eller authored
54 (:iso-latin-1-unix :latin1)
d502794 (find-external-format): Translate :utf-8-unix to :utf8, which Allegro
Helmut Eller authored
55 (:utf-8-unix :utf8)
521e923 (swank-compile-file): New optional argument `external-format'.
Helmut Eller authored
56 (:emacs-mule-unix :emacs-mule))))
d502794 (find-external-format): Translate :utf-8-unix to :utf8, which Allegro
Helmut Eller authored
57 (excl:crlf-base-ef (excl:find-external-format name :try-variant t)))
58 #-(version>= 6)
59 (ecase coding-system
60 (:iso-latin-1-unix :default)))
521e923 (swank-compile-file): New optional argument `external-format'.
Helmut Eller authored
61
62 (defun set-external-format (stream external-format)
2bbbb17 (find-external-format): Fix typo.
Helmut Eller authored
63 (setf (stream-external-format stream)
64 (find-external-format external-format)))
ca9bb1b (set-external-format): New function. Use LF as eol mark.
Helmut Eller authored
65
58bc7fb (format-sldb-condition, condition-references): Add workarounds for
Helmut Eller authored
66 (defimplementation format-sldb-condition (c)
67 (princ-to-string c))
68
69 (defimplementation condition-references (c)
2b0dd28 (frame-var-value): New backend function.
Helmut Eller authored
70 (declare (ignore c))
58bc7fb (format-sldb-condition, condition-references): Add workarounds for
Helmut Eller authored
71 '())
72
2b0dd28 (frame-var-value): New backend function.
Helmut Eller authored
73 (defimplementation call-with-syntax-hooks (fn)
74 (funcall fn))
75
6fa3b33 (arglist-string): Refactor common code to swank.lisp.
Helmut Eller authored
76 ;;;; Unix signals
77
72f16c0 Replace defmethod with defimplementation.
Helmut Eller authored
78 (defimplementation call-without-interrupts (fn)
6fa3b33 (arglist-string): Refactor common code to swank.lisp.
Helmut Eller authored
79 (excl:without-interrupts (funcall fn)))
80
72f16c0 Replace defmethod with defimplementation.
Helmut Eller authored
81 (defimplementation getpid ()
fab0b31 Add multiprocessing support.
Helmut Eller authored
82 (excl::getpid))
83
6827452 (lisp-implementation-type-name): Implement it.
Helmut Eller authored
84 (defimplementation lisp-implementation-type-name ()
85 "allegro")
86
38b61c2 Allegro specific version of set-default-directory
Peter Seibel authored
87 (defimplementation set-default-directory (directory)
358236a (handle-compiler-warning): Handle undefined-functions warnings by
Helmut Eller authored
88 (let ((dir (namestring (setf *default-pathname-defaults*
89 (truename (merge-pathnames directory))))))
90 (excl:chdir dir)
91 dir))
38b61c2 Allegro specific version of set-default-directory
Peter Seibel authored
92
167a03c (default-directory, call-with-syntax-hooks): Add implementations as
Helmut Eller authored
93 (defimplementation default-directory ()
358236a (handle-compiler-warning): Handle undefined-functions warnings by
Helmut Eller authored
94 (namestring (excl:current-directory)))
167a03c (default-directory, call-with-syntax-hooks): Add implementations as
Helmut Eller authored
95
fab0b31 Add multiprocessing support.
Helmut Eller authored
96 ;;;; Misc
f912c9c New file.
Helmut Eller authored
97
8052a9e Minor modifications.
Helmut Eller authored
98 (defimplementation arglist (symbol)
d589600 (arglist): Return :not-available if arglist lookup fails with an
Luke Gorrie authored
99 (handler-case (excl:arglist symbol)
100 (simple-error () :not-available)))
8052a9e Minor modifications.
Helmut Eller authored
101
102 (defimplementation macroexpand-all (form)
103 (excl::walk form))
f912c9c New file.
Helmut Eller authored
104
72f16c0 Replace defmethod with defimplementation.
Helmut Eller authored
105 (defimplementation describe-symbol-for-emacs (symbol)
f912c9c New file.
Helmut Eller authored
106 (let ((result '()))
107 (flet ((doc (kind &optional (sym symbol))
108 (or (documentation sym kind) :not-documented))
109 (maybe-push (property value)
110 (when value
111 (setf result (list* property value result)))))
112 (maybe-push
113 :variable (when (boundp symbol)
114 (doc 'variable)))
115 (maybe-push
116 :function (if (fboundp symbol)
117 (doc 'function)))
118 (maybe-push
119 :class (if (find-class symbol nil)
120 (doc 'class)))
121 result)))
122
c2d3f88 Implement changed backend interface and remove references to front en…
Helmut Eller authored
123 (defimplementation describe-definition (symbol namespace)
124 (ecase namespace
125 (:variable
126 (describe symbol))
127 ((:function :generic-function)
128 (describe (symbol-function symbol)))
129 (:class
130 (describe (find-class symbol)))))
72f16c0 Replace defmethod with defimplementation.
Helmut Eller authored
131
c153745 (make-stream-interactive): Set interactive-stream-p slot on the stream
Luke Gorrie authored
132 (defimplementation make-stream-interactive (stream)
133 (setf (interactive-stream-p stream) t))
134
fab0b31 Add multiprocessing support.
Helmut Eller authored
135 ;;;; Debugger
136
f912c9c New file.
Helmut Eller authored
137 (defvar *sldb-topframe*)
c9ef56e (create-swank-server): Add support for BACKGROUND and CLOSE argument.
Helmut Eller authored
138
72f16c0 Replace defmethod with defimplementation.
Helmut Eller authored
139 (defimplementation call-with-debugging-environment (debugger-loop-fn)
73e84b5 (process-fspec-for-allegro, toggle-trace): Handle setf functions.
Helmut Eller authored
140 (let ((*sldb-topframe* (find-topframe))
c2d3f88 Implement changed backend interface and remove references to front en…
Helmut Eller authored
141 (excl::*break-hook* nil))
c9ef56e (create-swank-server): Add support for BACKGROUND and CLOSE argument.
Helmut Eller authored
142 (funcall debugger-loop-fn)))
f912c9c New file.
Helmut Eller authored
143
73e84b5 (process-fspec-for-allegro, toggle-trace): Handle setf functions.
Helmut Eller authored
144 (defun find-topframe ()
971c7b4 (eval-in-frame): Allegro's eval-form-in-context does nothing special
Helmut Eller authored
145 (let ((skip-frames 3))
146 (do ((f (excl::int-newest-frame) (next-frame f))
147 (i 0 (1+ i)))
148 ((= i skip-frames) f))))
73e84b5 (process-fspec-for-allegro, toggle-trace): Handle setf functions.
Helmut Eller authored
149
3dc039d (nth-frame): Skip frames where frame-visible-p is false.
Helmut Eller authored
150 (defun next-frame (frame)
151 (let ((next (excl::int-next-older-frame frame)))
152 (cond ((not next) nil)
153 ((debugger:frame-visible-p next) next)
154 (t (next-frame next)))))
155
f912c9c New file.
Helmut Eller authored
156 (defun nth-frame (index)
3dc039d (nth-frame): Skip frames where frame-visible-p is false.
Helmut Eller authored
157 (do ((frame *sldb-topframe* (next-frame frame))
f912c9c New file.
Helmut Eller authored
158 (i index (1- i)))
159 ((zerop i) frame)))
160
c2d3f88 Implement changed backend interface and remove references to front en…
Helmut Eller authored
161 (defimplementation compute-backtrace (start end)
f912c9c New file.
Helmut Eller authored
162 (let ((end (or end most-positive-fixnum)))
3dc039d (nth-frame): Skip frames where frame-visible-p is false.
Helmut Eller authored
163 (loop for f = (nth-frame start) then (next-frame f)
f912c9c New file.
Helmut Eller authored
164 for i from start below end
165 while f
3dc039d (nth-frame): Skip frames where frame-visible-p is false.
Helmut Eller authored
166 collect f)))
f912c9c New file.
Helmut Eller authored
167
c2d3f88 Implement changed backend interface and remove references to front en…
Helmut Eller authored
168 (defimplementation print-frame (frame stream)
169 (debugger:output-frame stream frame :moderate))
c9ef56e (create-swank-server): Add support for BACKGROUND and CLOSE argument.
Helmut Eller authored
170
72f16c0 Replace defmethod with defimplementation.
Helmut Eller authored
171 (defimplementation frame-locals (index)
f912c9c New file.
Helmut Eller authored
172 (let ((frame (nth-frame index)))
173 (loop for i from 0 below (debugger:frame-number-vars frame)
de3dd96 See ChangeLog entry 2004-03-05 Marco Baringer
Marco Baringer authored
174 collect (list :name (debugger:frame-var-name frame i)
f912c9c New file.
Helmut Eller authored
175 :id 0
de3dd96 See ChangeLog entry 2004-03-05 Marco Baringer
Marco Baringer authored
176 :value (debugger:frame-var-value frame i)))))
f912c9c New file.
Helmut Eller authored
177
2b0dd28 (frame-var-value): New backend function.
Helmut Eller authored
178 (defimplementation frame-var-value (frame var)
179 (let ((frame (nth-frame frame)))
180 (debugger:frame-var-value frame var)))
181
72f16c0 Replace defmethod with defimplementation.
Helmut Eller authored
182 (defimplementation frame-catch-tags (index)
f912c9c New file.
Helmut Eller authored
183 (declare (ignore index))
184 nil)
185
8052a9e Minor modifications.
Helmut Eller authored
186 (defimplementation disassemble-frame (index)
187 (disassemble (debugger:frame-function (nth-frame index))))
188
72f16c0 Replace defmethod with defimplementation.
Helmut Eller authored
189 (defimplementation frame-source-location-for-emacs (index)
33236b4 From Matthew Danish:
Luke Gorrie authored
190 (let* ((frame (nth-frame index))
191 (expr (debugger:frame-expression frame))
192 (fspec (first expr)))
193 (second (first (fspec-definition-locations fspec)))))
c9ef56e (create-swank-server): Add support for BACKGROUND and CLOSE argument.
Helmut Eller authored
194
72f16c0 Replace defmethod with defimplementation.
Helmut Eller authored
195 (defimplementation eval-in-frame (form frame-number)
971c7b4 (eval-in-frame): Allegro's eval-form-in-context does nothing special
Helmut Eller authored
196 (let ((frame (nth-frame frame-number)))
197 ;; let-bind lexical variables
198 (let ((vars (loop for i below (debugger:frame-number-vars frame)
199 for name = (debugger:frame-var-name frame i)
200 if (symbolp name)
201 collect `(,name ',(debugger:frame-var-value frame i)))))
202 (debugger:eval-form-in-context
203 `(let* ,vars ,form)
204 (debugger:environment-of-frame frame)))))
72f16c0 Replace defmethod with defimplementation.
Helmut Eller authored
205
4303a24 (return-from-frame, restart-name): Implement interface (partly).
Helmut Eller authored
206 (defimplementation return-from-frame (frame-number form)
207 (let ((frame (nth-frame frame-number)))
208 (multiple-value-call #'debugger:frame-return
209 frame (debugger:eval-form-in-context
c2d3f88 Implement changed backend interface and remove references to front en…
Helmut Eller authored
210 form
211 (debugger:environment-of-frame frame)))))
9f80540 (handle-undefined-functions-warning): Prevent breakage if the
Helmut Eller authored
212
4303a24 (return-from-frame, restart-name): Implement interface (partly).
Helmut Eller authored
213 (defimplementation restart-frame (frame-number)
214 (let ((frame (nth-frame frame-number)))
18204be (restart-frame): Simplify it a little.
Helmut Eller authored
215 (cond ((debugger:frame-retryable-p frame)
216 (apply #'debugger:frame-retry frame (debugger:frame-function frame)
217 (cdr (debugger:frame-expression frame))))
218 (t "Frame is not retryable"))))
9f80540 (handle-undefined-functions-warning): Prevent breakage if the
Helmut Eller authored
219
fab0b31 Add multiprocessing support.
Helmut Eller authored
220 ;;;; Compiler hooks
221
f912c9c New file.
Helmut Eller authored
222 (defvar *buffer-name* nil)
223 (defvar *buffer-start-position*)
224 (defvar *buffer-string*)
aa65d6e Implemented.
Luke Gorrie authored
225 (defvar *compile-filename* nil)
f912c9c New file.
Helmut Eller authored
226
358236a (handle-compiler-warning): Handle undefined-functions warnings by
Helmut Eller authored
227 (defun compiler-note-p (object)
228 (member (type-of object) '(excl::compiler-note compiler::compiler-note)))
229
230 (defun compiler-undefined-functions-called-warning-p (object)
2bbbb17 (find-external-format): Fix typo.
Helmut Eller authored
231 #+(version>= 6)
358236a (handle-compiler-warning): Handle undefined-functions warnings by
Helmut Eller authored
232 (typep object 'excl:compiler-undefined-functions-called-warning))
ca9bb1b (set-external-format): New function. Use LF as eol mark.
Helmut Eller authored
233
234 (deftype compiler-note ()
235 `(satisfies compiler-note-p))
236
358236a (handle-compiler-warning): Handle undefined-functions warnings by
Helmut Eller authored
237 (defun signal-compiler-condition (&rest args)
238 (signal (apply #'make-condition 'compiler-condition args)))
239
f912c9c New file.
Helmut Eller authored
240 (defun handle-compiler-warning (condition)
358236a (handle-compiler-warning): Handle undefined-functions warnings by
Helmut Eller authored
241 (declare (optimize (debug 3) (speed 0) (space 0)))
242 (cond ((and (not *buffer-name*)
243 (compiler-undefined-functions-called-warning-p condition))
244 (handle-undefined-functions-warning condition))
245 (t
246 (signal-compiler-condition
247 :original-condition condition
248 :severity (etypecase condition
249 (warning :warning)
250 (compiler-note :note))
251 :message (format nil "~A" condition)
252 :location (location-for-warning condition)))))
253
254 (defun location-for-warning (condition)
f912c9c New file.
Helmut Eller authored
255 (let ((loc (getf (slot-value condition 'excl::plist) :loc)))
358236a (handle-compiler-warning): Handle undefined-functions warnings by
Helmut Eller authored
256 (cond (*buffer-name*
257 (make-location
258 (list :buffer *buffer-name*)
259 (list :position *buffer-start-position*)))
260 (loc
261 (destructuring-bind (file . pos) loc
262 (make-location
263 (list :file (namestring (truename file)))
264 (list :position (1+ pos)))))
265 (t
266 (list :error "No error location available.")))))
267
268 (defun handle-undefined-functions-warning (condition)
269 (let ((fargs (slot-value condition 'excl::format-arguments)))
9f80540 (handle-undefined-functions-warning): Prevent breakage if the
Helmut Eller authored
270 (loop for (fname . pos-file) in (car fargs) do
271 (loop for (pos file) in pos-file do
272 (signal-compiler-condition
273 :original-condition condition
274 :severity :warning
275 :message (format nil "Undefined function referenced: ~S"
276 fname)
277 :location (make-location (list :file file)
278 (list :position (1+ pos))))))))
f912c9c New file.
Helmut Eller authored
279
aa65d6e Implemented.
Luke Gorrie authored
280 (defimplementation call-with-compilation-hooks (function)
ca9bb1b (set-external-format): New function. Use LF as eol mark.
Helmut Eller authored
281 (handler-bind ((warning #'handle-compiler-warning)
c9f86e2 (toggle-trace): Update tracing code for new interface.
Helmut Eller authored
282 ;;(compiler-note #'handle-compiler-warning)
283 )
aa65d6e Implemented.
Luke Gorrie authored
284 (funcall function)))
285
521e923 (swank-compile-file): New optional argument `external-format'.
Helmut Eller authored
286 (defimplementation swank-compile-file (filename load-p
287 &optional external-format)
aa65d6e Implemented.
Luke Gorrie authored
288 (with-compilation-hooks ()
521e923 (swank-compile-file): New optional argument `external-format'.
Helmut Eller authored
289 (let ((*buffer-name* nil)
290 (*compile-filename* filename)
291 (ef (if external-format
292 (find-external-format external-format)
293 :default)))
294 (compile-file *compile-filename* :load-after-compile load-p
295 :external-format ef))))
f912c9c New file.
Helmut Eller authored
296
1a07e24 (swank-compile-string): Use a temporary file and set
Helmut Eller authored
297 (defun call-with-temp-file (fn)
298 (let ((tmpname (system:make-temp-file-name)))
299 (unwind-protect
300 (with-open-file (file tmpname :direction :output :if-exists :error)
301 (funcall fn file tmpname))
302 (delete-file tmpname))))
303
304 (defun compile-from-temp-file (string)
305 (call-with-temp-file
306 (lambda (stream filename)
307 (write-string string stream)
308 (finish-output stream)
309 (let ((binary-filename (compile-file filename :load-after-compile t)))
310 (when binary-filename
311 (delete-file binary-filename))))))
312
79c38c6 Adding directory argument to swank-compile-string.
Peter Seibel authored
313 (defimplementation swank-compile-string (string &key buffer position directory)
1a07e24 (swank-compile-string): Use a temporary file and set
Helmut Eller authored
314 ;; We store the source buffer in excl::*source-pathname* as a string
36f4daf (swank-compile-string): Use #\; instead of #\: to separate the
Helmut Eller authored
315 ;; of the form <buffername>;<start-offset>. Quite ugly encoding, but
1a07e24 (swank-compile-string): Use a temporary file and set
Helmut Eller authored
316 ;; the fasl file is corrupted if we use some other datatype.
aa65d6e Implemented.
Luke Gorrie authored
317 (with-compilation-hooks ()
c2d3f88 Implement changed backend interface and remove references to front en…
Helmut Eller authored
318 (let ((*buffer-name* buffer)
f912c9c New file.
Helmut Eller authored
319 (*buffer-start-position* position)
79c38c6 Adding directory argument to swank-compile-string.
Peter Seibel authored
320 (*buffer-string* string)
321 (*default-pathname-defaults*
322 (if directory (merge-pathnames (pathname directory))
323 *default-pathname-defaults*)))
1a07e24 (swank-compile-string): Use a temporary file and set
Helmut Eller authored
324 (compile-from-temp-file
325 (format nil "~S ~S~%~A"
326 `(in-package ,(package-name *package*))
327 `(eval-when (:compile-toplevel :load-toplevel)
328 (setq excl::*source-pathname*
6d27ed7 (find-fspec-location): Catch errors in excl:source-file.
Helmut Eller authored
329 ',(format nil "~A;~D" buffer position)))
1a07e24 (swank-compile-string): Use a temporary file and set
Helmut Eller authored
330 string)))))
f912c9c New file.
Helmut Eller authored
331
fab0b31 Add multiprocessing support.
Helmut Eller authored
332 ;;;; Definition Finding
333
56d2e6d (fspec-primary-name): New function.
Helmut Eller authored
334 (defun fspec-primary-name (fspec)
335 (etypecase fspec
5bb5d51 (swank-mop:slot-definition-documentation): ACL 7 says documentation
Helmut Eller authored
336 (symbol fspec)
337 (list (fspec-primary-name (second fspec)))))
338
339 ;; If Emacs uses DOS-style eol conventions, \n\r are considered as a
340 ;; single character, but file-position counts them as two. Here we do
341 ;; our own conversion.
342 (defun count-cr (file pos)
343 (let* ((bufsize 256)
984c411 (accept-connection): Accept :external-format as argument.
Helmut Eller authored
344 (type '(unsigned-byte 8))
345 (buf (make-array bufsize :element-type type))
5bb5d51 (swank-mop:slot-definition-documentation): ACL 7 says documentation
Helmut Eller authored
346 (cr-count 0))
984c411 (accept-connection): Accept :external-format as argument.
Helmut Eller authored
347 (with-open-file (stream file :direction :input :element-type type)
348 (loop for bytes-read = (read-sequence buf stream) do
349 (incf cr-count (count (char-code #\return) buf
350 :end (min pos bytes-read)))
351 (decf pos bytes-read)
352 (when (<= pos 0)
353 (return cr-count))))))
5bb5d51 (swank-mop:slot-definition-documentation): ACL 7 says documentation
Helmut Eller authored
354
7544734 (find-definition-in-file)
Matthias Koeppe authored
355 (defun find-definition-in-file (fspec type file top-level)
356 (let* ((part
357 (or (scm::find-definition-in-definition-group
358 fspec type (scm:section-file :file file)
359 :top-level top-level)
360 (scm::find-definition-in-definition-group
361 (fspec-primary-name fspec)
362 type (scm:section-file :file file)
363 :top-level top-level)))
364 (start (and part
365 (scm::source-part-start part)))
2ab1edd (find-fspec-location): excl:source-file can return stuff like
Helmut Eller authored
366 (pos (if start
5bb5d51 (swank-mop:slot-definition-documentation): ACL 7 says documentation
Helmut Eller authored
367 (list :position (1+ (- start (count-cr file start))))
368 (list :function-name (string (fspec-primary-name fspec))))))
369 (make-location (list :file (namestring (truename file)))
370 pos)))
2ab1edd (find-fspec-location): excl:source-file can return stuff like
Helmut Eller authored
371
372 (defun find-definition-in-buffer (filename)
373 (let ((pos (position #\; filename :from-end t)))
374 (make-location
375 (list :buffer (subseq filename 0 pos))
376 (list :position (parse-integer (subseq filename (1+ pos)))))))
377
7544734 (find-definition-in-file)
Matthias Koeppe authored
378 (defun find-fspec-location (fspec type file top-level)
379 (etypecase file
380 (pathname
381 (find-definition-in-file fspec type file top-level))
382 ((member :top-level)
383 (list :error (format nil "Defined at toplevel: ~A"
384 (fspec->string fspec))))
385 (string
386 (find-definition-in-buffer file))))
4902bdb (find-fspec-location): Include the type of the definition in the
Luke Gorrie authored
387
36f4daf (swank-compile-string): Use #\; instead of #\: to separate the
Helmut Eller authored
388 (defun fspec->string (fspec)
4902bdb (find-fspec-location): Include the type of the definition in the
Luke Gorrie authored
389 (etypecase fspec
36f4daf (swank-compile-string): Use #\; instead of #\: to separate the
Helmut Eller authored
390 (symbol (let ((*package* (find-package :keyword)))
391 (prin1-to-string fspec)))
392 (list (format nil "(~A ~A)"
393 (prin1-to-string (first fspec))
394 (let ((*package* (find-package :keyword)))
395 (prin1-to-string (second fspec)))))))
c2d3f88 Implement changed backend interface and remove references to front en…
Helmut Eller authored
396
437f909 Remove stupid conflicts.
Helmut Eller authored
397 (defun fspec-definition-locations (fspec)
7544734 (find-definition-in-file)
Matthias Koeppe authored
398 (let ((defs (excl::find-source-file fspec)))
399 (if (null defs)
400 (list
401 (list (list nil fspec)
402 (list :error
403 (format nil "Unknown source location for ~A"
404 (fspec->string fspec)))))
405 (loop for (fspec type file top-level) in defs
406 collect (list (list type fspec)
407 (find-fspec-location fspec type file top-level))))))
8052a9e Minor modifications.
Helmut Eller authored
408
409 (defimplementation find-definitions (symbol)
410 (fspec-definition-locations symbol))
fab0b31 Add multiprocessing support.
Helmut Eller authored
411
c2d3f88 Implement changed backend interface and remove references to front en…
Helmut Eller authored
412 ;;;; XREF
f912c9c New file.
Helmut Eller authored
413
8052a9e Minor modifications.
Helmut Eller authored
414 (defmacro defxref (name relation name1 name2)
415 `(defimplementation ,name (x)
416 (xref-result (xref:get-relation ,relation ,name1 ,name2))))
417
418 (defxref who-calls :calls :wild x)
c9f86e2 (toggle-trace): Update tracing code for new interface.
Helmut Eller authored
419 (defxref calls-who :calls x :wild)
8052a9e Minor modifications.
Helmut Eller authored
420 (defxref who-references :uses :wild x)
421 (defxref who-binds :binds :wild x)
422 (defxref who-macroexpands :macro-calls :wild x)
423 (defxref who-sets :sets :wild x)
424
425 (defun xref-result (fspecs)
426 (loop for fspec in fspecs
427 append (fspec-definition-locations fspec)))
c9ef56e (create-swank-server): Add support for BACKGROUND and CLOSE argument.
Helmut Eller authored
428
1a07e24 (swank-compile-string): Use a temporary file and set
Helmut Eller authored
429 ;; list-callers implemented by groveling through all fbound symbols.
430 ;; Only symbols are considered. Functions in the constant pool are
73e84b5 (process-fspec-for-allegro, toggle-trace): Handle setf functions.
Helmut Eller authored
431 ;; searched recursively. Closure environments are ignored at the
1a07e24 (swank-compile-string): Use a temporary file and set
Helmut Eller authored
432 ;; moment (constants in methods are therefore not found).
433
434 (defun map-function-constants (function fn depth)
435 "Call FN with the elements of FUNCTION's constant pool."
436 (do ((i 0 (1+ i))
437 (max (excl::function-constant-count function)))
438 ((= i max))
439 (let ((c (excl::function-constant function i)))
440 (cond ((and (functionp c)
441 (not (eq c function))
442 (plusp depth))
443 (map-function-constants c fn (1- depth)))
444 (t
445 (funcall fn c))))))
446
ca9bb1b (set-external-format): New function. Use LF as eol mark.
Helmut Eller authored
447 (defun in-constants-p (fun symbol)
448 (map-function-constants fun
449 (lambda (c)
450 (when (eq c symbol)
451 (return-from in-constants-p t)))
452 3))
c9f86e2 (toggle-trace): Update tracing code for new interface.
Helmut Eller authored
453
1a07e24 (swank-compile-string): Use a temporary file and set
Helmut Eller authored
454 (defun function-callers (name)
455 (let ((callers '()))
456 (do-all-symbols (sym)
457 (when (fboundp sym)
458 (let ((fn (fdefinition sym)))
459 (when (in-constants-p fn name)
460 (push sym callers)))))
461 callers))
462
463 (defimplementation list-callers (name)
464 (xref-result (function-callers name)))
465
c9f86e2 (toggle-trace): Update tracing code for new interface.
Helmut Eller authored
466 (defimplementation list-callees (name)
467 (let ((result '()))
468 (map-function-constants (fdefinition name)
469 (lambda (c)
470 (when (fboundp c)
471 (push c result)))
472 2)
473 (xref-result result)))
474
aeada84 (thread-alive-p): Add default implementation.
Helmut Eller authored
475 ;;;; Inspecting
476
0ce7bc2 2004-09-14 Marco Baringer <mb@bese.it>
Marco Baringer authored
477 (defclass acl-inspector (inspector)
478 ())
479
480 (defimplementation make-default-inspector ()
481 (make-instance 'acl-inspector))
482
5bb5d51 (swank-mop:slot-definition-documentation): ACL 7 says documentation
Helmut Eller authored
483 (defmethod inspect-for-emacs ((f function) inspector)
484 inspector
0ce7bc2 2004-09-14 Marco Baringer <mb@bese.it>
Marco Baringer authored
485 (values "A function."
5bb5d51 (swank-mop:slot-definition-documentation): ACL 7 says documentation
Helmut Eller authored
486 (append
487 (label-value-line "Name" (function-name f))
488 `("Formals" ,(princ-to-string (arglist f)) (:newline))
489 (let ((doc (documentation (excl::external-fn_symdef f) 'function)))
490 (when doc
491 `("Documentation:" (:newline) ,doc))))))
492
493 (defmethod inspect-for-emacs ((o t) (inspector acl-inspector))
494 inspector
495 (values "A value." (allegro-inspect o)))
496
497 (defmethod inspect-for-emacs ((o function) (inspector acl-inspector))
498 inspector
499 (values "A function." (allegro-inspect o)))
500
dc71b6e (inspect-for-emacs): Use the backend specific method to inspect
Helmut Eller authored
501 (defmethod inspect-for-emacs ((o standard-object) (inspector acl-inspector))
502 inspector
503 (values (format "~A is a standard-object." o) (allegro-inspect o)))
504
5bb5d51 (swank-mop:slot-definition-documentation): ACL 7 says documentation
Helmut Eller authored
505 (defun allegro-inspect (o)
506 (loop for (d dd) on (inspect::inspect-ctl o)
971c7b4 (eval-in-frame): Allegro's eval-form-in-context does nothing special
Helmut Eller authored
507 append (frob-allegro-field-def o d)
508 until (eq d dd)))
5bb5d51 (swank-mop:slot-definition-documentation): ACL 7 says documentation
Helmut Eller authored
509
971c7b4 (eval-in-frame): Allegro's eval-form-in-context does nothing special
Helmut Eller authored
510 (defun frob-allegro-field-def (object def)
5bb5d51 (swank-mop:slot-definition-documentation): ACL 7 says documentation
Helmut Eller authored
511 (with-struct (inspect::field-def- name type access) def
971c7b4 (eval-in-frame): Allegro's eval-form-in-context does nothing special
Helmut Eller authored
512 (ecase type
d502794 (find-external-format): Translate :utf-8-unix to :utf8, which Allegro
Helmut Eller authored
513 ((:unsigned-word :unsigned-byte :unsigned-natural
514 :unsigned-long :unsigned-half-long
515 :unsigned-3byte)
971c7b4 (eval-in-frame): Allegro's eval-form-in-context does nothing special
Helmut Eller authored
516 (label-value-line name (inspect::component-ref-v object access type)))
517 ((:lisp :value)
518 (label-value-line name (inspect::component-ref object access)))
519 (:indirect
520 (destructuring-bind (prefix count ref set) access
521 (declare (ignore set prefix))
522 (loop for i below (funcall count object)
523 append (label-value-line (format nil "~A-~D" name i)
524 (funcall ref object i))))))))
5bb5d51 (swank-mop:slot-definition-documentation): ACL 7 says documentation
Helmut Eller authored
525
aeada84 (thread-alive-p): Add default implementation.
Helmut Eller authored
526 ;;;; Multithreading
fab0b31 Add multiprocessing support.
Helmut Eller authored
527
d4e5a85 (startup-multiprocessing): Deleted.
Helmut Eller authored
528 (defimplementation initialize-multiprocessing ()
fab0b31 Add multiprocessing support.
Helmut Eller authored
529 (mp:start-scheduler))
530
72f16c0 Replace defmethod with defimplementation.
Helmut Eller authored
531 (defimplementation spawn (fn &key name)
68dd370 Removed fwrapper-based code for inheriting "swankiness" to newly
Luke Gorrie authored
532 (mp:process-run-function name fn))
fab0b31 Add multiprocessing support.
Helmut Eller authored
533
12da821 (thread-id, find-thread): New backend function.
Helmut Eller authored
534 (defvar *id-lock* (mp:make-process-lock :name "id lock"))
535 (defvar *thread-id-counter* 0)
536
537 (defimplementation thread-id (thread)
538 (mp:with-process-lock (*id-lock*)
539 (or (getf (mp:process-property-list thread) 'id)
540 (setf (getf (mp:process-property-list thread) 'id)
541 (incf *thread-id-counter*)))))
542
543 (defimplementation find-thread (id)
544 (find id mp:*all-processes*
545 :key (lambda (p) (getf (mp:process-property-list p) 'id))))
546
64ff730 Update for modified thread interface.
Helmut Eller authored
547 (defimplementation thread-name (thread)
548 (mp:process-name thread))
fab0b31 Add multiprocessing support.
Helmut Eller authored
549
64ff730 Update for modified thread interface.
Helmut Eller authored
550 (defimplementation thread-status (thread)
551 (format nil "~A ~D" (mp:process-whostate thread)
552 (mp:process-priority thread)))
fab0b31 Add multiprocessing support.
Helmut Eller authored
553
72f16c0 Replace defmethod with defimplementation.
Helmut Eller authored
554 (defimplementation make-lock (&key name)
fab0b31 Add multiprocessing support.
Helmut Eller authored
555 (mp:make-process-lock :name name))
556
72f16c0 Replace defmethod with defimplementation.
Helmut Eller authored
557 (defimplementation call-with-lock-held (lock function)
fab0b31 Add multiprocessing support.
Helmut Eller authored
558 (mp:with-process-lock (lock) (funcall function)))
92d6085 Use signal driven IO for CMUCL and SBCL. Use one thread per request
Helmut Eller authored
559
560 (defimplementation current-thread ()
561 mp:*current-process*)
562
563 (defimplementation all-threads ()
64ff730 Update for modified thread interface.
Helmut Eller authored
564 (copy-list mp:*all-processes*))
92d6085 Use signal driven IO for CMUCL and SBCL. Use one thread per request
Helmut Eller authored
565
566 (defimplementation interrupt-thread (thread fn)
567 (mp:process-interrupt thread fn))
568
52dc1fc (kill-thread): Implemented.
Helmut Eller authored
569 (defimplementation kill-thread (thread)
570 (mp:process-kill thread))
571
92d6085 Use signal driven IO for CMUCL and SBCL. Use one thread per request
Helmut Eller authored
572 (defvar *mailbox-lock* (mp:make-process-lock :name "mailbox lock"))
573
574 (defstruct (mailbox (:conc-name mailbox.))
575 (mutex (mp:make-process-lock :name "process mailbox"))
576 (queue '() :type list))
577
578 (defun mailbox (thread)
579 "Return THREAD's mailbox."
580 (mp:with-process-lock (*mailbox-lock*)
581 (or (getf (mp:process-property-list thread) 'mailbox)
582 (setf (getf (mp:process-property-list thread) 'mailbox)
583 (make-mailbox)))))
584
585 (defimplementation send (thread message)
586 (let* ((mbox (mailbox thread))
587 (mutex (mailbox.mutex mbox)))
cbaae0c (send): Wait a bit if there are already many message in the mailbox.
Helmut Eller authored
588 (mp:process-wait-with-timeout
589 "yielding before sending" 0.1
590 (lambda ()
591 (mp:with-process-lock (mutex)
95e3c25 (send): Fix misplaced parens. (From Bill Clementson)
Helmut Eller authored
592 (< (length (mailbox.queue mbox)) 10))))
92d6085 Use signal driven IO for CMUCL and SBCL. Use one thread per request
Helmut Eller authored
593 (mp:with-process-lock (mutex)
594 (setf (mailbox.queue mbox)
595 (nconc (mailbox.queue mbox) (list message))))))
596
597 (defimplementation receive ()
598 (let* ((mbox (mailbox mp:*current-process*))
599 (mutex (mailbox.mutex mbox)))
600 (mp:process-wait "receive" #'mailbox.queue mbox)
601 (mp:with-process-lock (mutex)
602 (pop (mailbox.queue mbox)))))
9decabc See ChangeLog entry 2004-04-06 Marco Baringer
Marco Baringer authored
603
604 (defimplementation quit-lisp ()
605 (excl:exit 0 :quiet t))
80d90a0 (toggle-trace-generic-function-methods,
Marco Baringer authored
606
18204be (restart-frame): Simplify it a little.
Helmut Eller authored
607
80d90a0 (toggle-trace-generic-function-methods,
Marco Baringer authored
608 ;;Trace implementations
609 ;;In Allegro 7.0, we have:
610 ;; (trace <name>)
611 ;; (trace ((method <name> <qualifier>? (<specializer>+))))
612 ;; (trace ((labels <name> <label-name>)))
613 ;; (trace ((labels (method <name> (<specializer>+)) <label-name>)))
614 ;; <name> can be a normal name or a (setf name)
615
c9f86e2 (toggle-trace): Update tracing code for new interface.
Helmut Eller authored
616 (defimplementation toggle-trace (spec)
b846225 (toggle-trace): Fix from Antonio Menezes Leitao.
Luke Gorrie authored
617 (ecase (car spec)
618 ((setf)
619 (toggle-trace-aux spec))
c9f86e2 (toggle-trace): Update tracing code for new interface.
Helmut Eller authored
620 (:defgeneric (toggle-trace-generic-function-methods (second spec)))
73e84b5 (process-fspec-for-allegro, toggle-trace): Handle setf functions.
Helmut Eller authored
621 ((setf :defmethod :labels :flet)
c9f86e2 (toggle-trace): Update tracing code for new interface.
Helmut Eller authored
622 (toggle-trace-aux (process-fspec-for-allegro spec)))
b846225 (toggle-trace): Fix from Antonio Menezes Leitao.
Luke Gorrie authored
623 (:call
c9f86e2 (toggle-trace): Update tracing code for new interface.
Helmut Eller authored
624 (destructuring-bind (caller callee) (cdr spec)
625 (toggle-trace-aux callee
626 :inside (list (process-fspec-for-allegro caller)))))))
627
628 (defun tracedp (fspec)
73e84b5 (process-fspec-for-allegro, toggle-trace): Handle setf functions.
Helmut Eller authored
629 (member fspec (eval '(trace)) :test #'equal))
c9f86e2 (toggle-trace): Update tracing code for new interface.
Helmut Eller authored
630
631 (defun toggle-trace-aux (fspec &rest args)
632 (cond ((tracedp fspec)
633 (eval `(untrace ,fspec))
634 (format nil "~S is now untraced." fspec))
635 (t
636 (eval `(trace (,fspec ,@args)))
637 (format nil "~S is now traced." fspec))))
638
639 (defun toggle-trace-generic-function-methods (name)
80d90a0 (toggle-trace-generic-function-methods,
Marco Baringer authored
640 (let ((methods (mop:generic-function-methods (fdefinition name))))
c9f86e2 (toggle-trace): Update tracing code for new interface.
Helmut Eller authored
641 (cond ((tracedp name)
80d90a0 (toggle-trace-generic-function-methods,
Marco Baringer authored
642 (eval `(untrace ,name))
643 (dolist (method methods (format nil "~S is now untraced." name))
644 (excl:funtrace (mop:method-function method))))
645 (t
b846225 (toggle-trace): Fix from Antonio Menezes Leitao.
Luke Gorrie authored
646 (eval `(trace (,name)))
c9f86e2 (toggle-trace): Update tracing code for new interface.
Helmut Eller authored
647 (dolist (method methods (format nil "~S is now traced." name))
80d90a0 (toggle-trace-generic-function-methods,
Marco Baringer authored
648 (excl:ftrace (mop:method-function method)))))))
649
650 (defun process-fspec-for-allegro (fspec)
651 (cond ((consp fspec)
652 (ecase (first fspec)
73e84b5 (process-fspec-for-allegro, toggle-trace): Handle setf functions.
Helmut Eller authored
653 ((setf) fspec)
80d90a0 (toggle-trace-generic-function-methods,
Marco Baringer authored
654 ((:defun :defgeneric) (second fspec))
655 ((:defmethod) `(method ,@(rest fspec)))
18204be (restart-frame): Simplify it a little.
Helmut Eller authored
656 ((:labels) `(labels ,(process-fspec-for-allegro (second fspec))
657 ,(third fspec)))
658 ((:flet) `(flet ,(process-fspec-for-allegro (second fspec))
659 ,(third fspec)))))
80d90a0 (toggle-trace-generic-function-methods,
Marco Baringer authored
660 (t
661 fspec)))
Something went wrong with that request. Please try again.