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

Contents of /slime/swank-allegro.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.102 - (show annotations)
Thu Apr 17 14:56:43 2008 UTC (5 years, 11 months ago) by heller
Branch: MAIN
Changes since 1.101: +3 -1 lines
C-c C-c with prefix args now uses the maximal debug level.  (By Zach Beane.)
Only implemented for SBCL.

* slime.el (slime-compile-with-maximum-debug): New variable.
(slime-compile-defun, slime-compile-region): Use it.

* swank.lisp (compile-string-for-emacs): Accept new debug
argument. Update backend accordingly.
1 ;;;; -*- indent-tabs-mode: nil; outline-regexp: ";;;;;* "; -*-
2 ;;;
3 ;;; swank-allegro.lisp --- Allegro CL specific code for SLIME.
4 ;;;
5 ;;; Created 2003
6 ;;;
7 ;;; This code has been placed in the Public Domain. All warranties
8 ;;; are disclaimed.
9 ;;;
10
11 (in-package :swank-backend)
12
13 (eval-when (:compile-toplevel :load-toplevel :execute)
14 (require :sock)
15 (require :process))
16
17 (import-from :excl *gray-stream-symbols* :swank-backend)
18
19 ;;; swank-mop
20
21 (import-swank-mop-symbols :clos '(:slot-definition-documentation))
22
23 (defun swank-mop:slot-definition-documentation (slot)
24 (documentation slot t))
25
26
27 ;;;; TCP Server
28
29 (defimplementation preferred-communication-style ()
30 :spawn)
31
32 (defimplementation create-socket (host port)
33 (socket:make-socket :connect :passive :local-port port
34 :local-host host :reuse-address t))
35
36 (defimplementation local-port (socket)
37 (socket:local-port socket))
38
39 (defimplementation close-socket (socket)
40 (close socket))
41
42 (defimplementation accept-connection (socket &key external-format buffering
43 timeout)
44 (declare (ignore buffering timeout))
45 (let ((s (socket:accept-connection socket :wait t)))
46 (when external-format
47 (setf (stream-external-format s) external-format))
48 s))
49
50 (defvar *external-format-to-coding-system*
51 '((:iso-8859-1
52 "latin-1" "latin-1-unix" "iso-latin-1-unix"
53 "iso-8859-1" "iso-8859-1-unix")
54 (:utf-8 "utf-8" "utf-8-unix")
55 (:euc-jp "euc-jp" "euc-jp-unix")
56 (:us-ascii "us-ascii" "us-ascii-unix")
57 (:emacs-mule "emacs-mule" "emacs-mule-unix")))
58
59 (defimplementation find-external-format (coding-system)
60 (let ((e (rassoc-if (lambda (x) (member coding-system x :test #'equal))
61 *external-format-to-coding-system*)))
62 (and e (excl:crlf-base-ef
63 (excl:find-external-format (car e)
64 :try-variant t)))))
65
66 (defimplementation format-sldb-condition (c)
67 (princ-to-string c))
68
69 (defimplementation call-with-syntax-hooks (fn)
70 (funcall fn))
71
72 ;;;; Unix signals
73
74 (defimplementation call-without-interrupts (fn)
75 (excl:without-interrupts (funcall fn)))
76
77 (defimplementation getpid ()
78 (excl::getpid))
79
80 (defimplementation lisp-implementation-type-name ()
81 "allegro")
82
83 (defimplementation set-default-directory (directory)
84 (let* ((dir (namestring (truename (merge-pathnames directory)))))
85 (setf *default-pathname-defaults* (pathname (excl:chdir dir)))
86 dir))
87
88 (defimplementation default-directory ()
89 (namestring (excl:current-directory)))
90
91 ;;;; Misc
92
93 (defimplementation arglist (symbol)
94 (handler-case (excl:arglist symbol)
95 (simple-error () :not-available)))
96
97 (defimplementation macroexpand-all (form)
98 (excl::walk form))
99
100 (defimplementation describe-symbol-for-emacs (symbol)
101 (let ((result '()))
102 (flet ((doc (kind &optional (sym symbol))
103 (or (documentation sym kind) :not-documented))
104 (maybe-push (property value)
105 (when value
106 (setf result (list* property value result)))))
107 (maybe-push
108 :variable (when (boundp symbol)
109 (doc 'variable)))
110 (maybe-push
111 :function (if (fboundp symbol)
112 (doc 'function)))
113 (maybe-push
114 :class (if (find-class symbol nil)
115 (doc 'class)))
116 result)))
117
118 (defimplementation describe-definition (symbol namespace)
119 (ecase namespace
120 (:variable
121 (describe symbol))
122 ((:function :generic-function)
123 (describe (symbol-function symbol)))
124 (:class
125 (describe (find-class symbol)))))
126
127 (defimplementation make-stream-interactive (stream)
128 (setf (interactive-stream-p stream) t))
129
130 ;;;; Debugger
131
132 (defvar *sldb-topframe*)
133
134 (defimplementation call-with-debugging-environment (debugger-loop-fn)
135 (let ((*sldb-topframe* (find-topframe))
136 (excl::*break-hook* nil))
137 (funcall debugger-loop-fn)))
138
139 (defimplementation sldb-break-at-start (fname)
140 ;; :print-before is kind of mis-used but we just want to stuff our break form
141 ;; somewhere. This does not work for setf, :before and :after methods, which
142 ;; need special syntax in the trace call, see ACL's doc/debugging.htm chapter 10.
143 (eval `(trace (,fname
144 :print-before
145 ((break "Function start breakpoint of ~A" ',fname)))))
146 `(:ok ,(format nil "Set breakpoint at start of ~S" fname)))
147
148 (defun find-topframe ()
149 (let ((skip-frames 3))
150 (do ((f (excl::int-newest-frame) (next-frame f))
151 (i 0 (1+ i)))
152 ((= i skip-frames) f))))
153
154 (defun next-frame (frame)
155 (let ((next (excl::int-next-older-frame frame)))
156 (cond ((not next) nil)
157 ((debugger:frame-visible-p next) next)
158 (t (next-frame next)))))
159
160 (defun nth-frame (index)
161 (do ((frame *sldb-topframe* (next-frame frame))
162 (i index (1- i)))
163 ((zerop i) frame)))
164
165 (defimplementation compute-backtrace (start end)
166 (let ((end (or end most-positive-fixnum)))
167 (loop for f = (nth-frame start) then (next-frame f)
168 for i from start below end
169 while f
170 collect f)))
171
172 (defimplementation print-frame (frame stream)
173 (debugger:output-frame stream frame :moderate))
174
175 (defimplementation frame-locals (index)
176 (let ((frame (nth-frame index)))
177 (loop for i from 0 below (debugger:frame-number-vars frame)
178 collect (list :name (debugger:frame-var-name frame i)
179 :id 0
180 :value (debugger:frame-var-value frame i)))))
181
182 (defimplementation frame-var-value (frame var)
183 (let ((frame (nth-frame frame)))
184 (debugger:frame-var-value frame var)))
185
186 (defimplementation frame-catch-tags (index)
187 (declare (ignore index))
188 nil)
189
190 (defimplementation disassemble-frame (index)
191 (disassemble (debugger:frame-function (nth-frame index))))
192
193 (defimplementation frame-source-location-for-emacs (index)
194 (let* ((frame (nth-frame index))
195 (expr (debugger:frame-expression frame))
196 (fspec (first expr)))
197 (second (first (fspec-definition-locations fspec)))))
198
199 (defimplementation eval-in-frame (form frame-number)
200 (let ((frame (nth-frame frame-number)))
201 ;; let-bind lexical variables
202 (let ((vars (loop for i below (debugger:frame-number-vars frame)
203 for name = (debugger:frame-var-name frame i)
204 if (symbolp name)
205 collect `(,name ',(debugger:frame-var-value frame i)))))
206 (debugger:eval-form-in-context
207 `(let* ,vars ,form)
208 (debugger:environment-of-frame frame)))))
209
210 (defimplementation return-from-frame (frame-number form)
211 (let ((frame (nth-frame frame-number)))
212 (multiple-value-call #'debugger:frame-return
213 frame (debugger:eval-form-in-context
214 form
215 (debugger:environment-of-frame frame)))))
216
217 (defimplementation restart-frame (frame-number)
218 (let ((frame (nth-frame frame-number)))
219 (cond ((debugger:frame-retryable-p frame)
220 (apply #'debugger:frame-retry frame (debugger:frame-function frame)
221 (cdr (debugger:frame-expression frame))))
222 (t "Frame is not retryable"))))
223
224 ;;;; Compiler hooks
225
226 (defvar *buffer-name* nil)
227 (defvar *buffer-start-position*)
228 (defvar *buffer-string*)
229 (defvar *compile-filename* nil)
230
231 (defun compiler-note-p (object)
232 (member (type-of object) '(excl::compiler-note compiler::compiler-note)))
233
234 (defun compiler-undefined-functions-called-warning-p (object)
235 (typep object 'excl:compiler-undefined-functions-called-warning))
236
237 (deftype compiler-note ()
238 `(satisfies compiler-note-p))
239
240 (defun signal-compiler-condition (&rest args)
241 (signal (apply #'make-condition 'compiler-condition args)))
242
243 (defun handle-compiler-warning (condition)
244 (declare (optimize (debug 3) (speed 0) (space 0)))
245 (cond ((and (not *buffer-name*)
246 (compiler-undefined-functions-called-warning-p condition))
247 (handle-undefined-functions-warning condition))
248 (t
249 (signal-compiler-condition
250 :original-condition condition
251 :severity (etypecase condition
252 (warning :warning)
253 (compiler-note :note))
254 :message (format nil "~A" condition)
255 :location (location-for-warning condition)))))
256
257 (defun location-for-warning (condition)
258 (let ((loc (getf (slot-value condition 'excl::plist) :loc)))
259 (cond (*buffer-name*
260 (make-location
261 (list :buffer *buffer-name*)
262 (list :position *buffer-start-position*)))
263 (loc
264 (destructuring-bind (file . pos) loc
265 (make-location
266 (list :file (namestring (truename file)))
267 (list :position (1+ pos)))))
268 (t
269 (list :error "No error location available.")))))
270
271 (defun handle-undefined-functions-warning (condition)
272 (let ((fargs (slot-value condition 'excl::format-arguments)))
273 (loop for (fname . pos-file) in (car fargs) do
274 (loop for (pos file) in pos-file do
275 (signal-compiler-condition
276 :original-condition condition
277 :severity :warning
278 :message (format nil "Undefined function referenced: ~S"
279 fname)
280 :location (make-location (list :file file)
281 (list :position (1+ pos))))))))
282
283 (defimplementation call-with-compilation-hooks (function)
284 (handler-bind ((warning #'handle-compiler-warning)
285 ;;(compiler-note #'handle-compiler-warning)
286 )
287 (funcall function)))
288
289 (defimplementation swank-compile-file (filename load-p external-format)
290 (with-compilation-hooks ()
291 (let ((*buffer-name* nil)
292 (*compile-filename* filename))
293 (compile-file *compile-filename* :load-after-compile load-p
294 :external-format external-format))))
295
296 (defun call-with-temp-file (fn)
297 (let ((tmpname (system:make-temp-file-name)))
298 (unwind-protect
299 (with-open-file (file tmpname :direction :output :if-exists :error)
300 (funcall fn file tmpname))
301 (delete-file tmpname))))
302
303 (defun compile-from-temp-file (string)
304 (call-with-temp-file
305 (lambda (stream filename)
306 (write-string string stream)
307 (finish-output stream)
308 (let ((binary-filename
309 (excl:without-redefinition-warnings
310 ;; Suppress Allegro's redefinition warnings; they are
311 ;; pointless when we are compiling via a temporary
312 ;; file.
313 (compile-file filename :load-after-compile t))))
314 (when binary-filename
315 (delete-file binary-filename))))))
316
317 (defimplementation swank-compile-string (string &key buffer position directory
318 debug)
319 (declare (ignore debug))
320 ;; We store the source buffer in excl::*source-pathname* as a string
321 ;; of the form <buffername>;<start-offset>. Quite ugly encoding, but
322 ;; the fasl file is corrupted if we use some other datatype.
323 (with-compilation-hooks ()
324 (let ((*buffer-name* buffer)
325 (*buffer-start-position* position)
326 (*buffer-string* string)
327 (*default-pathname-defaults*
328 (if directory (merge-pathnames (pathname directory))
329 *default-pathname-defaults*)))
330 (compile-from-temp-file
331 (format nil "~S ~S~%~A"
332 `(in-package ,(package-name *package*))
333 `(eval-when (:compile-toplevel :load-toplevel)
334 (setq excl::*source-pathname*
335 ',(format nil "~A;~D" buffer position)))
336 string)))))
337
338 ;;;; Definition Finding
339
340 (defun fspec-primary-name (fspec)
341 (etypecase fspec
342 (symbol fspec)
343 (list (fspec-primary-name (second fspec)))))
344
345 ;; If Emacs uses DOS-style eol conventions, \n\r are considered as a
346 ;; single character, but file-position counts them as two. Here we do
347 ;; our own conversion.
348 (defun count-cr (file pos)
349 (let* ((bufsize 256)
350 (type '(unsigned-byte 8))
351 (buf (make-array bufsize :element-type type))
352 (cr-count 0))
353 (with-open-file (stream file :direction :input :element-type type)
354 (loop for bytes-read = (read-sequence buf stream) do
355 (incf cr-count (count (char-code #\return) buf
356 :end (min pos bytes-read)))
357 (decf pos bytes-read)
358 (when (<= pos 0)
359 (return cr-count))))))
360
361 (defun find-definition-in-file (fspec type file top-level)
362 (let* ((part
363 (or (scm::find-definition-in-definition-group
364 fspec type (scm:section-file :file file)
365 :top-level top-level)
366 (scm::find-definition-in-definition-group
367 (fspec-primary-name fspec)
368 type (scm:section-file :file file)
369 :top-level top-level)))
370 (start (and part
371 (scm::source-part-start part)))
372 (pos (if start
373 (list :position (1+ (- start (count-cr file start))))
374 (list :function-name (string (fspec-primary-name fspec))))))
375 (make-location (list :file (namestring (truename file)))
376 pos)))
377
378 (defun find-definition-in-buffer (filename)
379 (let ((pos (position #\; filename :from-end t)))
380 (make-location
381 (list :buffer (subseq filename 0 pos))
382 (list :position (parse-integer (subseq filename (1+ pos)))))))
383
384 (defun find-fspec-location (fspec type file top-level)
385 (etypecase file
386 (pathname
387 (find-definition-in-file fspec type file top-level))
388 ((member :top-level)
389 (list :error (format nil "Defined at toplevel: ~A"
390 (fspec->string fspec))))
391 (string
392 (find-definition-in-buffer file))))
393
394 (defun fspec->string (fspec)
395 (etypecase fspec
396 (symbol (let ((*package* (find-package :keyword)))
397 (prin1-to-string fspec)))
398 (list (format nil "(~A ~A)"
399 (prin1-to-string (first fspec))
400 (let ((*package* (find-package :keyword)))
401 (prin1-to-string (second fspec)))))))
402
403 (defun fspec-definition-locations (fspec)
404 (cond
405 ((and (listp fspec)
406 (eql (car fspec) :top-level-form))
407 (destructuring-bind (top-level-form file &optional position) fspec
408 (list
409 (list (list nil fspec)
410 (make-location (list :buffer file)
411 (list :position position t))))))
412 ((and (listp fspec) (eq (car fspec) :internal))
413 (destructuring-bind (_internal next _n) fspec
414 (fspec-definition-locations next)))
415 (t
416 (let ((defs (excl::find-source-file fspec)))
417 (if (null defs)
418 (list
419 (list (list nil fspec)
420 (list :error
421 (format nil "Unknown source location for ~A"
422 (fspec->string fspec)))))
423 (loop for (fspec type file top-level) in defs
424 collect (list (list type fspec)
425 (find-fspec-location fspec type file top-level))))))))
426
427 (defimplementation find-definitions (symbol)
428 (fspec-definition-locations symbol))
429
430 ;;;; XREF
431
432 (defmacro defxref (name relation name1 name2)
433 `(defimplementation ,name (x)
434 (xref-result (xref:get-relation ,relation ,name1 ,name2))))
435
436 (defxref who-calls :calls :wild x)
437 (defxref calls-who :calls x :wild)
438 (defxref who-references :uses :wild x)
439 (defxref who-binds :binds :wild x)
440 (defxref who-macroexpands :macro-calls :wild x)
441 (defxref who-sets :sets :wild x)
442
443 (defun xref-result (fspecs)
444 (loop for fspec in fspecs
445 append (fspec-definition-locations fspec)))
446
447 ;; list-callers implemented by groveling through all fbound symbols.
448 ;; Only symbols are considered. Functions in the constant pool are
449 ;; searched recursively. Closure environments are ignored at the
450 ;; moment (constants in methods are therefore not found).
451
452 (defun map-function-constants (function fn depth)
453 "Call FN with the elements of FUNCTION's constant pool."
454 (do ((i 0 (1+ i))
455 (max (excl::function-constant-count function)))
456 ((= i max))
457 (let ((c (excl::function-constant function i)))
458 (cond ((and (functionp c)
459 (not (eq c function))
460 (plusp depth))
461 (map-function-constants c fn (1- depth)))
462 (t
463 (funcall fn c))))))
464
465 (defun in-constants-p (fun symbol)
466 (map-function-constants fun
467 (lambda (c)
468 (when (eq c symbol)
469 (return-from in-constants-p t)))
470 3))
471
472 (defun function-callers (name)
473 (let ((callers '()))
474 (do-all-symbols (sym)
475 (when (fboundp sym)
476 (let ((fn (fdefinition sym)))
477 (when (in-constants-p fn name)
478 (push sym callers)))))
479 callers))
480
481 (defimplementation list-callers (name)
482 (xref-result (function-callers name)))
483
484 (defimplementation list-callees (name)
485 (let ((result '()))
486 (map-function-constants (fdefinition name)
487 (lambda (c)
488 (when (fboundp c)
489 (push c result)))
490 2)
491 (xref-result result)))
492
493 ;;;; Profiling
494
495 ;; Per-function profiling based on description in
496 ;; http://www.franz.com/support/documentation/8.0/doc/runtime-analyzer.htm#data-collection-control-2
497
498 (defvar *profiled-functions* ())
499 (defvar *profile-depth* 0)
500
501 (defmacro with-redirected-y-or-n-p (&body body)
502 ;; If the profiler is restarted when the data from the previous
503 ;; session is not reported yet, the user is warned via Y-OR-N-P.
504 ;; As the CL:Y-OR-N-P question is (for some reason) not directly
505 ;; sent to the Slime user, the function CL:Y-OR-N-P is temporarily
506 ;; overruled.
507 `(let* ((pkg (find-package "common-lisp"))
508 (saved-pdl (excl::package-definition-lock pkg))
509 (saved-ynp (symbol-function 'cl:y-or-n-p)))
510
511 (setf (excl::package-definition-lock pkg) nil
512 (symbol-function 'cl:y-or-n-p) (symbol-function
513 (find-symbol "y-or-n-p-in-emacs"
514 "swank")))
515 (unwind-protect
516 (progn ,@body)
517
518 (setf (symbol-function 'cl:y-or-n-p) saved-ynp
519 (excl::package-definition-lock pkg) saved-pdl))))
520
521 (defun start-acl-profiler ()
522 (with-redirected-y-or-n-p
523 (prof:start-profiler :type :time :count t
524 :start-sampling-p nil :verbose nil)))
525 (defun acl-profiler-active-p ()
526 (not (eq (prof:profiler-status :verbose nil) :inactive)))
527
528 (defun stop-acl-profiler ()
529 (prof:stop-profiler :verbose nil))
530
531 (excl:def-fwrapper profile-fwrapper (&rest args)
532 ;; Ensures sampling is done during the execution of the function,
533 ;; taking into account recursion.
534 (declare (ignore args))
535 (cond ((zerop *profile-depth*)
536 (let ((*profile-depth* (1+ *profile-depth*)))
537 (prof:start-sampling)
538 (unwind-protect (excl:call-next-fwrapper)
539 (prof:stop-sampling))))
540 (t
541 (excl:call-next-fwrapper))))
542
543 (defimplementation profile (fname)
544 (unless (acl-profiler-active-p)
545 (start-acl-profiler))
546 (excl:fwrap fname 'profile-fwrapper 'profile-fwrapper)
547 (push fname *profiled-functions*))
548
549 (defimplementation profiled-functions ()
550 *profiled-functions*)
551
552 (defimplementation unprofile (fname)
553 (excl:funwrap fname 'profile-fwrapper)
554 (setq *profiled-functions* (remove fname *profiled-functions*)))
555
556 (defimplementation profile-report ()
557 (prof:show-flat-profile :verbose nil)
558 (when *profiled-functions*
559 (start-acl-profiler)))
560
561 (defimplementation profile-reset ()
562 (when (acl-profiler-active-p)
563 (stop-acl-profiler)
564 (start-acl-profiler))
565 "Reset profiling counters.")
566
567 ;;;; Inspecting
568
569 (defmethod emacs-inspect ((f function))
570 (append
571 (label-value-line "Name" (function-name f))
572 `("Formals" ,(princ-to-string (arglist f)) (:newline))
573 (let ((doc (documentation (excl::external-fn_symdef f) 'function)))
574 (when doc
575 `("Documentation:" (:newline) ,doc)))))
576
577 (defmethod emacs-inspect ((o t))
578 (allegro-inspect o))
579
580 (defmethod emacs-inspect ((o function))
581 (allegro-inspect o))
582
583 (defmethod emacs-inspect ((o standard-object))
584 (allegro-inspect o))
585
586 (defun allegro-inspect (o)
587 (loop for (d dd) on (inspect::inspect-ctl o)
588 append (frob-allegro-field-def o d)
589 until (eq d dd)))
590
591 (defun frob-allegro-field-def (object def)
592 (with-struct (inspect::field-def- name type access) def
593 (ecase type
594 ((:unsigned-word :unsigned-byte :unsigned-natural
595 :unsigned-long :unsigned-half-long
596 :unsigned-3byte)
597 (label-value-line name (inspect::component-ref-v object access type)))
598 ((:lisp :value)
599 (label-value-line name (inspect::component-ref object access)))
600 (:indirect
601 (destructuring-bind (prefix count ref set) access
602 (declare (ignore set prefix))
603 (loop for i below (funcall count object)
604 append (label-value-line (format nil "~A-~D" name i)
605 (funcall ref object i))))))))
606
607 ;;;; Multithreading
608
609 (defimplementation initialize-multiprocessing (continuation)
610 (mp:start-scheduler)
611 (funcall continuation))
612
613 (defimplementation spawn (fn &key name)
614 (mp:process-run-function name fn))
615
616 (defvar *id-lock* (mp:make-process-lock :name "id lock"))
617 (defvar *thread-id-counter* 0)
618
619 (defimplementation thread-id (thread)
620 (mp:with-process-lock (*id-lock*)
621 (or (getf (mp:process-property-list thread) 'id)
622 (setf (getf (mp:process-property-list thread) 'id)
623 (incf *thread-id-counter*)))))
624
625 (defimplementation find-thread (id)
626 (find id mp:*all-processes*
627 :key (lambda (p) (getf (mp:process-property-list p) 'id))))
628
629 (defimplementation thread-name (thread)
630 (mp:process-name thread))
631
632 (defimplementation thread-status (thread)
633 (format nil "~A ~D" (mp:process-whostate thread)
634 (mp:process-priority thread)))
635
636 (defimplementation make-lock (&key name)
637 (mp:make-process-lock :name name))
638
639 (defimplementation call-with-lock-held (lock function)
640 (mp:with-process-lock (lock) (funcall function)))
641
642 (defimplementation current-thread ()
643 mp:*current-process*)
644
645 (defimplementation all-threads ()
646 (copy-list mp:*all-processes*))
647
648 (defimplementation interrupt-thread (thread fn)
649 (mp:process-interrupt thread fn))
650
651 (defimplementation kill-thread (thread)
652 (mp:process-kill thread))
653
654 (defvar *mailbox-lock* (mp:make-process-lock :name "mailbox lock"))
655
656 (defstruct (mailbox (:conc-name mailbox.))
657 (mutex (mp:make-process-lock :name "process mailbox"))
658 (queue '() :type list))
659
660 (defun mailbox (thread)
661 "Return THREAD's mailbox."
662 (mp:with-process-lock (*mailbox-lock*)
663 (or (getf (mp:process-property-list thread) 'mailbox)
664 (setf (getf (mp:process-property-list thread) 'mailbox)
665 (make-mailbox)))))
666
667 (defimplementation send (thread message)
668 (let* ((mbox (mailbox thread))
669 (mutex (mailbox.mutex mbox)))
670 (mp:process-wait-with-timeout
671 "yielding before sending" 0.1
672 (lambda ()
673 (mp:with-process-lock (mutex)
674 (< (length (mailbox.queue mbox)) 10))))
675 (mp:with-process-lock (mutex)
676 (setf (mailbox.queue mbox)
677 (nconc (mailbox.queue mbox) (list message))))))
678
679 (defimplementation receive ()
680 (let* ((mbox (mailbox mp:*current-process*))
681 (mutex (mailbox.mutex mbox)))
682 (mp:process-wait "receive" #'mailbox.queue mbox)
683 (mp:with-process-lock (mutex)
684 (pop (mailbox.queue mbox)))))
685
686 (defimplementation quit-lisp ()
687 (excl:exit 0 :quiet t))
688
689
690 ;;Trace implementations
691 ;;In Allegro 7.0, we have:
692 ;; (trace <name>)
693 ;; (trace ((method <name> <qualifier>? (<specializer>+))))
694 ;; (trace ((labels <name> <label-name>)))
695 ;; (trace ((labels (method <name> (<specializer>+)) <label-name>)))
696 ;; <name> can be a normal name or a (setf name)
697
698 (defimplementation toggle-trace (spec)
699 (ecase (car spec)
700 ((setf)
701 (toggle-trace-aux spec))
702 (:defgeneric (toggle-trace-generic-function-methods (second spec)))
703 ((setf :defmethod :labels :flet)
704 (toggle-trace-aux (process-fspec-for-allegro spec)))
705 (:call
706 (destructuring-bind (caller callee) (cdr spec)
707 (toggle-trace-aux callee
708 :inside (list (process-fspec-for-allegro caller)))))))
709
710 (defun tracedp (fspec)
711 (member fspec (eval '(trace)) :test #'equal))
712
713 (defun toggle-trace-aux (fspec &rest args)
714 (cond ((tracedp fspec)
715 (eval `(untrace ,fspec))
716 (format nil "~S is now untraced." fspec))
717 (t
718 (eval `(trace (,fspec ,@args)))
719 (format nil "~S is now traced." fspec))))
720
721 (defun toggle-trace-generic-function-methods (name)
722 (let ((methods (mop:generic-function-methods (fdefinition name))))
723 (cond ((tracedp name)
724 (eval `(untrace ,name))
725 (dolist (method methods (format nil "~S is now untraced." name))
726 (excl:funtrace (mop:method-function method))))
727 (t
728 (eval `(trace (,name)))
729 (dolist (method methods (format nil "~S is now traced." name))
730 (excl:ftrace (mop:method-function method)))))))
731
732 (defun process-fspec-for-allegro (fspec)
733 (cond ((consp fspec)
734 (ecase (first fspec)
735 ((setf) fspec)
736 ((:defun :defgeneric) (second fspec))
737 ((:defmethod) `(method ,@(rest fspec)))
738 ((:labels) `(labels ,(process-fspec-for-allegro (second fspec))
739 ,(third fspec)))
740 ((:flet) `(flet ,(process-fspec-for-allegro (second fspec))
741 ,(third fspec)))))
742 (t
743 fspec)))
744
745
746 ;;;; Weak hashtables
747
748 (defimplementation make-weak-key-hash-table (&rest args)
749 (apply #'make-hash-table :weak-keys t args))
750
751 (defimplementation make-weak-value-hash-table (&rest args)
752 (apply #'make-hash-table :values :weak args))
753
754 (defimplementation hash-table-weakness (hashtable)
755 (cond ((excl:hash-table-weak-keys hashtable) :key)
756 ((eq (excl:hash-table-values hashtable) :weak) :value)))
757
758
759
760 ;;;; Character names
761
762 (defimplementation character-completion-set (prefix matchp)
763 (loop for name being the hash-keys of excl::*name-to-char-table*
764 when (funcall matchp prefix name)
765 collect (string-capitalize name)))

  ViewVC Help
Powered by ViewVC 1.1.5