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

Contents of /slime/swank-allegro.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.28 - (hide annotations)
Wed Apr 7 16:28:13 2004 UTC (10 years ago) by pseibel
Branch: MAIN
Changes since 1.27: +4 -0 lines
Allegro specific version of set-default-directory
1 heller 1.8 ;;;; -*- Mode: lisp; indent-tabs-mode: nil; outline-regexp: ";;;;;*"; -*-
2 heller 1.1 ;;;
3     ;;; swank-allegro.lisp --- Allegro CL specific code for SLIME.
4     ;;;
5     ;;; Created 2003, Helmut Eller
6     ;;;
7     ;;; This code has been placed in the Public Domain. All warranties
8 heller 1.14 ;;; are disclaimed. This code was written for "Allegro CL Trial
9     ;;; Edition "5.0 [Linux/X86] (8/29/98 10:57)".
10 heller 1.1 ;;;
11    
12 heller 1.21 (in-package :swank-backend)
13    
14 heller 1.1 (eval-when (:compile-toplevel :load-toplevel :execute)
15     (require :sock)
16     (require :process))
17    
18     (import
19     '(excl:fundamental-character-output-stream
20     excl:stream-write-char
21     excl:stream-force-output
22     excl:fundamental-character-input-stream
23     excl:stream-read-char
24     excl:stream-listen
25     excl:stream-unread-char
26     excl:stream-clear-input
27     excl:stream-line-column
28 heller 1.7 excl:stream-read-char-no-hang
29 heller 1.1 ))
30    
31 heller 1.8 ;;;; TCP Server
32 heller 1.1
33 heller 1.22
34 heller 1.21 (defimplementation preferred-communication-style ()
35     :spawn)
36 heller 1.12
37 heller 1.14 (defimplementation create-socket (host port)
38     (socket:make-socket :connect :passive :local-port port
39     :local-host host :reuse-address t))
40 heller 1.5
41 heller 1.10 (defimplementation local-port (socket)
42 heller 1.6 (socket:local-port socket))
43    
44 heller 1.10 (defimplementation close-socket (socket)
45 heller 1.6 (close socket))
46    
47 heller 1.10 (defimplementation accept-connection (socket)
48 heller 1.6 (socket:accept-connection socket :wait t))
49    
50 heller 1.10 (defimplementation emacs-connected ())
51 heller 1.7
52 heller 1.9 ;;;; Unix signals
53    
54 heller 1.10 (defimplementation call-without-interrupts (fn)
55 heller 1.9 (excl:without-interrupts (funcall fn)))
56    
57 heller 1.10 (defimplementation getpid ()
58 heller 1.8 (excl::getpid))
59 heller 1.6
60 heller 1.15 (defimplementation lisp-implementation-type-name ()
61     "allegro")
62    
63 pseibel 1.28 (defimplementation set-default-directory (directory)
64     (excl:chdir directory)
65     (namestring (setf *default-pathname-defaults* (pathname directory))))
66    
67 heller 1.8 ;;;; Misc
68 heller 1.1
69 heller 1.21 (defimplementation arglist (symbol)
70     (excl:arglist symbol))
71    
72     (defimplementation macroexpand-all (form)
73     (excl::walk form))
74 heller 1.1
75 heller 1.10 (defimplementation describe-symbol-for-emacs (symbol)
76 heller 1.1 (let ((result '()))
77     (flet ((doc (kind &optional (sym symbol))
78     (or (documentation sym kind) :not-documented))
79     (maybe-push (property value)
80     (when value
81     (setf result (list* property value result)))))
82     (maybe-push
83     :variable (when (boundp symbol)
84     (doc 'variable)))
85     (maybe-push
86     :function (if (fboundp symbol)
87     (doc 'function)))
88     (maybe-push
89     :class (if (find-class symbol nil)
90     (doc 'class)))
91     result)))
92    
93 heller 1.22
94 heller 1.21 (defimplementation describe-definition (symbol namespace)
95     (ecase namespace
96     (:variable
97     (describe symbol))
98     ((:function :generic-function)
99     (describe (symbol-function symbol)))
100     (:class
101     (describe (find-class symbol)))))
102 heller 1.4
103 heller 1.20 (defimplementation describe-definition (symbol namespace)
104     (ecase namespace
105     (:variable
106     (describe symbol))
107     ((:function :generic-function)
108     (describe (symbol-function symbol)))
109     (:class
110     (describe (find-class symbol)))))
111 heller 1.10
112 heller 1.8 ;;;; Debugger
113    
114 heller 1.1 (defvar *sldb-topframe*)
115 heller 1.4
116 heller 1.10 (defimplementation call-with-debugging-environment (debugger-loop-fn)
117 heller 1.4 (let ((*sldb-topframe* (excl::int-newest-frame))
118 heller 1.20 (excl::*break-hook* nil))
119 heller 1.4 (funcall debugger-loop-fn)))
120 heller 1.1
121     (defun nth-frame (index)
122     (do ((frame *sldb-topframe* (excl::int-next-older-frame frame))
123     (i index (1- i)))
124     ((zerop i) frame)))
125    
126 heller 1.20 (defimplementation compute-backtrace (start end)
127 heller 1.1 (let ((end (or end most-positive-fixnum)))
128     (loop for f = (nth-frame start) then (excl::int-next-older-frame f)
129     for i from start below end
130     while f
131     collect f)))
132    
133 heller 1.20 (defimplementation print-frame (frame stream)
134     (debugger:output-frame stream frame :moderate))
135 heller 1.4
136 heller 1.10 (defimplementation frame-locals (index)
137 heller 1.1 (let ((frame (nth-frame index)))
138     (loop for i from 0 below (debugger:frame-number-vars frame)
139 mbaringer 1.19 collect (list :name (debugger:frame-var-name frame i)
140 heller 1.1 :id 0
141 mbaringer 1.19 :value (debugger:frame-var-value frame i)))))
142 heller 1.1
143 heller 1.10 (defimplementation frame-catch-tags (index)
144 heller 1.1 (declare (ignore index))
145     nil)
146    
147 heller 1.21 (defimplementation disassemble-frame (index)
148     (disassemble (debugger:frame-function (nth-frame index))))
149    
150 heller 1.10 (defimplementation frame-source-location-for-emacs (index)
151 heller 1.4 (list :error (format nil "Cannot find source for frame: ~A"
152     (nth-frame index))))
153    
154 heller 1.10 (defimplementation eval-in-frame (form frame-number)
155     (debugger:eval-form-in-context
156     form
157     (debugger:environment-of-frame (nth-frame frame-number))))
158    
159 heller 1.11 (defimplementation return-from-frame (frame-number form)
160     (let ((frame (nth-frame frame-number)))
161     (multiple-value-call #'debugger:frame-return
162     frame (debugger:eval-form-in-context
163 heller 1.20 form
164     (debugger:environment-of-frame frame)))))
165 heller 1.11
166 heller 1.21 ;;; XXX doesn't work for frames with arguments
167 heller 1.11 (defimplementation restart-frame (frame-number)
168     (let ((frame (nth-frame frame-number)))
169     (debugger:frame-retry frame (debugger:frame-function frame))))
170    
171 heller 1.8 ;;;; Compiler hooks
172    
173 heller 1.1 (defvar *buffer-name* nil)
174     (defvar *buffer-start-position*)
175     (defvar *buffer-string*)
176     (defvar *compile-filename*)
177    
178     (defun handle-compiler-warning (condition)
179     (let ((loc (getf (slot-value condition 'excl::plist) :loc)))
180     (signal (make-condition
181     'compiler-condition
182     :original-condition condition
183     :severity :warning
184     :message (format nil "~A" condition)
185     :location (cond (*buffer-name*
186     (make-location
187     (list :buffer *buffer-name*)
188     (list :position *buffer-start-position*)))
189     (loc
190     (destructuring-bind (file . pos) loc
191     (make-location
192     (list :file (namestring (truename file)))
193     (list :position (1+ pos)))))
194     (t
195     (make-location
196     (list :file *compile-filename*)
197     (list :position 1))))))))
198    
199 heller 1.20 (defimplementation swank-compile-file (*compile-filename* load-p)
200 heller 1.1 (handler-bind ((warning #'handle-compiler-warning))
201     (let ((*buffer-name* nil))
202 heller 1.4 (compile-file *compile-filename* :load-after-compile load-p))))
203 heller 1.1
204 heller 1.20 (defimplementation swank-compile-string (string &key buffer position)
205 heller 1.1 (handler-bind ((warning #'handle-compiler-warning))
206 heller 1.20 (let ((*buffer-name* buffer)
207 heller 1.1 (*buffer-start-position* position)
208     (*buffer-string* string))
209 heller 1.20 (funcall (compile nil (read-from-string
210 heller 1.24 (format nil "(~S () ~A)" 'lambda string)))))))
211 heller 1.1
212 heller 1.8 ;;;; Definition Finding
213    
214 heller 1.21 (defun find-fspec-location (fspec type)
215     (let ((file (excl::fspec-pathname fspec type)))
216     (etypecase file
217     (pathname
218     (let ((start (scm:find-definition-in-file fspec type file)))
219     (make-location (list :file (namestring (truename file)))
220     (if start
221     (list :position (1+ start))
222     (list :function-name (string fspec))))))
223     ((member :top-level)
224     (list :error (format nil "Defined at toplevel: ~A" fspec)))
225     (null
226     (list :error (format nil "Unkown source location for ~A" fspec))))))
227    
228     (defun fspec-definition-locations (fspec)
229 heller 1.1 (let ((defs (excl::find-multiple-definitions fspec)))
230 heller 1.21 (loop for (fspec type) in defs
231     collect (list fspec (find-fspec-location fspec type)))))
232    
233     (defimplementation find-definitions (symbol)
234     (fspec-definition-locations symbol))
235 heller 1.1
236 heller 1.8 ;;;; XREF
237    
238 heller 1.21 (defmacro defxref (name relation name1 name2)
239     `(defimplementation ,name (x)
240     (xref-result (xref:get-relation ,relation ,name1 ,name2))))
241    
242     (defxref who-calls :calls :wild x)
243     (defxref who-references :uses :wild x)
244     (defxref who-binds :binds :wild x)
245     (defxref who-macroexpands :macro-calls :wild x)
246     (defxref who-sets :sets :wild x)
247     (defxref list-callees :calls x :wild)
248    
249     (defun xref-result (fspecs)
250     (loop for fspec in fspecs
251     append (fspec-definition-locations fspec)))
252 heller 1.4
253 heller 1.18 ;;;; Inspecting
254    
255     (defmethod inspected-parts (o)
256     (let* ((class (class-of o))
257     (slots (clos:class-slots class)))
258     (values (format nil "~A~% is a ~A" o class)
259     (mapcar (lambda (slot)
260     (let ((name (clos:slot-definition-name slot)))
261 heller 1.20 (cons (princ-to-string name)
262 heller 1.18 (slot-value o name))))
263     slots))))
264    
265     ;;;; Multithreading
266 heller 1.8
267 heller 1.10 (defimplementation startup-multiprocessing ()
268 heller 1.8 (mp:start-scheduler))
269    
270 heller 1.10 (defimplementation spawn (fn &key name)
271 heller 1.8 (mp:process-run-function name fn))
272    
273 heller 1.13 (defimplementation thread-name (thread)
274     (mp:process-name thread))
275 heller 1.8
276 heller 1.13 (defimplementation thread-status (thread)
277     (format nil "~A ~D" (mp:process-whostate thread)
278     (mp:process-priority thread)))
279 heller 1.8
280 heller 1.10 (defimplementation make-lock (&key name)
281 heller 1.8 (mp:make-process-lock :name name))
282    
283 heller 1.10 (defimplementation call-with-lock-held (lock function)
284 heller 1.8 (mp:with-process-lock (lock) (funcall function)))
285 heller 1.12
286     (defimplementation current-thread ()
287     mp:*current-process*)
288    
289     (defimplementation all-threads ()
290 heller 1.13 (copy-list mp:*all-processes*))
291 heller 1.12
292     (defimplementation interrupt-thread (thread fn)
293     (mp:process-interrupt thread fn))
294    
295 heller 1.16 (defimplementation kill-thread (thread)
296     (mp:process-kill thread))
297    
298 heller 1.12 (defvar *mailbox-lock* (mp:make-process-lock :name "mailbox lock"))
299    
300     (defstruct (mailbox (:conc-name mailbox.))
301     (mutex (mp:make-process-lock :name "process mailbox"))
302     (queue '() :type list))
303    
304     (defun mailbox (thread)
305     "Return THREAD's mailbox."
306     (mp:with-process-lock (*mailbox-lock*)
307     (or (getf (mp:process-property-list thread) 'mailbox)
308     (setf (getf (mp:process-property-list thread) 'mailbox)
309     (make-mailbox)))))
310    
311     (defimplementation send (thread message)
312     (let* ((mbox (mailbox thread))
313     (mutex (mailbox.mutex mbox)))
314 heller 1.25 (mp:process-wait-with-timeout
315     "yielding before sending" 0.1
316     (lambda ()
317     (mp:with-process-lock (mutex)
318 heller 1.26 (< (length (mailbox.queue mbox)) 10))))
319 heller 1.12 (mp:with-process-lock (mutex)
320     (setf (mailbox.queue mbox)
321     (nconc (mailbox.queue mbox) (list message))))))
322    
323     (defimplementation receive ()
324     (let* ((mbox (mailbox mp:*current-process*))
325     (mutex (mailbox.mutex mbox)))
326     (mp:process-wait "receive" #'mailbox.queue mbox)
327     (mp:with-process-lock (mutex)
328     (pop (mailbox.queue mbox)))))
329 mbaringer 1.27
330     (defimplementation quit-lisp ()
331     (excl:exit 0 :quiet t))

  ViewVC Help
Powered by ViewVC 1.1.5