Skip to content
Browse files

swank-backend.lisp (definterface): Drop that incredibly unportable

CLOS stuff. Use plists and plain functions instead.  Update backends
accordingly.
  • Loading branch information...
1 parent 12dc840 commit e51892e9e99ad5e8fdfa81d8adf54add930298a3 Helmut Eller committed Aug 10, 2006
Showing with 125 additions and 112 deletions.
  1. +7 −8 swank-abcl.lisp
  2. +38 −15 swank-backend.lisp
  3. +6 −8 swank-clisp.lisp
  4. +23 −23 swank-cmucl.lisp
  5. +2 −3 swank-corman.lisp
  6. +2 −7 swank-ecl.lisp
  7. +2 −3 swank-lispworks.lisp
  8. +25 −23 swank-sbcl.lisp
  9. +16 −17 swank-scl.lisp
  10. +4 −5 swank.lisp
View
15 swank-abcl.lisp
@@ -134,9 +134,9 @@
(ext:server-socket-close socket))
(defimplementation accept-connection (socket
- &key (external-format :iso-latin-1-unix) buffering timeout)
+ &key external-format buffering timeout)
(declare (ignore buffering timeout))
- (assert (eq external-format :iso-latin-1-unix))
+ (assert (member external-format '(nil :iso-latin-1-unix)))
(ext:get-socket-stream (ext:socket-accept socket)))
;;;; Unix signals
@@ -159,12 +159,11 @@
;;;; Misc
-
-(defimplementation arglist ((symbol t))
- (multiple-value-bind (arglist present)
- (sys::arglist symbol)
- (if present arglist :not-available)))
-
+(defimplementation arglist (fun)
+ (cond ((symbolp fun)
+ (multiple-value-bind (arglist present) (sys::arglist fun)
+ (if present arglist :not-available)))
+ (t :not-available)))
(defimplementation function-name (function)
(nth-value 2 (function-lambda-expression function)))
View
53 swank-backend.lisp
@@ -112,24 +112,47 @@ implementation.
Backends implement these functions using DEFIMPLEMENTATION."
(check-type documentation string "a documentation string")
- (flet ((gen-default-impl ()
- `(defmethod no-applicable-method ((_gf (eql #',name)) &rest _rargs)
- (declare (ignore _gf))
- (destructuring-bind ,args _rargs
- ,@default-body))))
- `(progn (defgeneric ,name ,args (:documentation ,documentation))
- (pushnew ',name *interface-functions*)
- ,(if (null default-body)
- `(pushnew ',name *unimplemented-interfaces*)
- (gen-default-impl))
- ;; see <http://www.franz.com/support/documentation/6.2/doc/pages/variables/compiler/s_cltl1-compile-file-toplevel-compatibility-p_s.htm>
- (eval-when (:compile-toplevel :load-toplevel :execute)
- (export ',name :swank-backend))
- ',name)))
+ (assert (every #'symbolp args) ()
+ "Complex lambda-list not supported: ~S ~S" name args)
+ (labels ((gen-default-impl ()
+ `(setf (get ',name 'default) (lambda ,args ,@default-body)))
+ (args-as-list (args)
+ (destructuring-bind (req opt key rest) (parse-lambda-list args)
+ `(,@req ,@opt
+ ,@(loop for k in key append `(,(kw k) ,k))
+ ,@(or rest '(())))))
+ (parse-lambda-list (args)
+ (parse args '(&optional &key &rest)
+ (make-array 4 :initial-element nil)))
+ (parse (args keywords vars)
+ (cond ((null args)
+ (reverse (map 'list #'reverse vars)))
+ ((member (car args) keywords)
+ (parse (cdr args) (cdr (member (car args) keywords)) vars))
+ (t (push (car args) (aref vars (length keywords)))
+ (parse (cdr args) keywords vars))))
+ (kw (s) (intern (string s) :keyword)))
+ `(progn
+ (defun ,name ,args
+ ,documentation
+ (let ((f (or (get ',name 'implementation)
+ (get ',name 'default))))
+ (cond (f (apply f ,@(args-as-list args)))
+ (t (error "~S not implementated" ',name)))))
+ (pushnew ',name *interface-functions*)
+ ,(if (null default-body)
+ `(pushnew ',name *unimplemented-interfaces*)
+ (gen-default-impl))
+ ;; see <http://www.franz.com/support/documentation/6.2/doc/pages/variables/compiler/s_cltl1-compile-file-toplevel-compatibility-p_s.htm>
+ (eval-when (:compile-toplevel :load-toplevel :execute)
+ (export ',name :swank-backend))
+ ',name)))
(defmacro defimplementation (name args &body body)
+ (assert (every #'symbolp args) ()
+ "Complex lambda-list not supported: ~S ~S" name args)
`(progn
- (defmethod ,name ,args ,@body)
+ (setf (get ',name 'implementation) (lambda ,args ,@body))
(if (member ',name *interface-functions*)
(setq *unimplemented-interfaces*
(remove ',name *unimplemented-interfaces*))
View
14 swank-clisp.lisp
@@ -125,9 +125,9 @@
(ext:make-encoding :charset charset :line-terminator :unix)))
(defimplementation accept-connection (socket
- &key (external-format :iso-latin-1-unix)
- buffering timeout)
+ &key external-format buffering timeout)
(declare (ignore buffering timeout))
+ (setq external-format (or external-format :iso-latin-1-unix))
(socket:socket-accept socket
:buffered nil ;; XXX should be t
:element-type 'character
@@ -239,7 +239,7 @@ Return NIL if the symbol is unbound."
(let* (;;(sys::*break-count* (1+ sys::*break-count*))
;;(sys::*driver* debugger-loop-fn)
;;(sys::*fasoutput-stream* nil)
- (*sldb-backtrace* (nthcdr 6 (sldb-backtrace))))
+ (*sldb-backtrace* (nthcdr 5 (sldb-backtrace))))
(funcall debugger-loop-fn)))
(defun nth-frame (index)
@@ -363,11 +363,9 @@ Return NIL if the symbol is unbound."
(sys::redo-eval-frame (car (nth-frame index))))
(defimplementation frame-source-location-for-emacs (index)
- (let ((f (car (nth-frame index))))
- (list :error (format nil "Cannot find source for frame: ~A ~A ~A"
- f
- (sys::eval-frame-p f)
- (sys::the-frame)))))
+ `(:error
+ ,(format nil "frame-source-location not implemented. (frame: ~A)"
+ (car (nth-frame index)))))
;;; Profiling
View
46 swank-cmucl.lisp
@@ -98,16 +98,16 @@
(sys:invalidate-descriptor fd)
(ext:close-socket fd)))
-(defimplementation accept-connection (socket &key
- (external-format :iso-latin-1-unix)
- (buffering :full)
- timeout)
+(defimplementation accept-connection (socket &key
+ external-format buffering timeout)
(declare (ignore timeout))
- (unless (eq external-format ':iso-latin-1-unix)
- (remove-fd-handlers socket)
- (remove-sigio-handlers socket)
- (assert (eq external-format ':iso-latin-1-unix)))
- (make-socket-io-stream (ext:accept-tcp-connection socket) buffering))
+ (let ((ef (or external-format :iso-latin-1-unix))
+ (buffering (or buffering :full)))
+ (unless (eq ef ':iso-latin-1-unix)
+ (remove-fd-handlers socket)
+ (remove-sigio-handlers socket)
+ (error "External format ~S not supported" ef))
+ (make-socket-io-stream (ext:accept-tcp-connection socket) buffering)))
;;;;; Sockets
@@ -1276,18 +1276,15 @@ Signal an error if no constructor can be found."
(list symbol))))
((:defined)
(ext:info :alien-type :definition symbol))
- (:unknown
- (return-from describe-definition
- (format nil "Unknown alien type: ~S" symbol))))))))
+ (:unknown :unkown))))))
;;;;; Argument lists
-(defimplementation arglist ((name symbol))
- (arglist (or (macro-function name)
- (symbol-function name))))
-
-(defimplementation arglist ((fun function))
- (function-arglist fun))
+(defimplementation arglist (fun)
+ (etypecase fun
+ (function (function-arglist fun))
+ (symbol (function-arglist (or (macro-function fun)
+ (symbol-function fun))))))
(defun function-arglist (fun)
(let ((arglist
@@ -1708,9 +1705,12 @@ A utility for debugging DEBUG-FUNCTION-ARGLIST."
(values :initarg :values :reader breakpoint.values))
(:report (lambda (c stream) (princ (breakpoint.message c) stream))))
-(defimplementation condition-extras ((c breakpoint))
- ;; simply pop up the source buffer
- `((:short-frame-source 0)))
+(defimplementation condition-extras (condition)
+ (typecase condition
+ (breakpoint
+ ;; pop up the source buffer
+ `((:short-frame-source 0)))
+ (t '())))
(defun signal-breakpoint (breakpoint frame)
"Signal a breakpoint condition for BREAKPOINT in FRAME.
@@ -2050,8 +2050,8 @@ The `symbol-value' of each element is a type tag.")
;; available again.
(mp::startup-idle-and-top-level-loops))
- (defimplementation spawn (fn &key (name "Anonymous"))
- (mp:make-process fn :name name))
+ (defimplementation spawn (fn &key name)
+ (mp:make-process fn :name (or name "Anonymous")))
(defvar *thread-id-counter* 0)
View
5 swank-corman.lisp
@@ -238,10 +238,9 @@
(close socket))
(defimplementation accept-connection (socket
- &key (external-format :iso-latin-1-unix)
- buffering timeout)
+ &key external-format buffering timeout)
(declare (ignore buffering timeout))
- (ecase external-format
+ (ecase (or external-format :iso-latin-1-unix)
(:iso-latin-1-unix
(sockets:make-socket-stream (sockets:accept-socket socket)))))
View
9 swank-ecl.lisp
@@ -15,11 +15,6 @@
:specializer-direct-methods
:compute-applicable-methods-using-classes))
-#+nil
-(ffi:clines "
-#include <unistd.h>
-#include <sys/types.h>")
-
;;;; TCP Server
@@ -45,7 +40,7 @@
(sb-bsd-sockets:socket-close socket))
(defimplementation accept-connection (socket
- &key (external-format :iso-latin-1-unix)
+ &key external-format
buffering timeout)
(declare (ignore buffering timeout))
(assert (eq external-format :iso-latin-1-unix))
@@ -166,7 +161,7 @@
(t :not-available)))))
:not-available))
-(defimplementation function-name ((f function))
+(defimplementation function-name (f)
(si:compiled-function-name f))
(defimplementation macroexpand-all (form)
View
5 swank-lispworks.lisp
@@ -66,10 +66,9 @@
(comm::close-socket (socket-fd socket)))
(defimplementation accept-connection (socket
- &key (external-format :iso-latin-1-unix)
- buffering timeout)
+ &key external-format buffering timeout)
(declare (ignore buffering timeout))
- (assert (eq external-format :iso-latin-1-unix))
+ (assert (member external-format '(nil :iso-latin-1-unix)))
(let* ((fd (comm::get-fd-from-socket socket)))
(assert (/= fd -1))
(make-instance 'comm:socket-stream :socket fd :direction :io
View
48 swank-sbcl.lisp
@@ -60,10 +60,12 @@
(sb-bsd-sockets:socket-close socket))
(defimplementation accept-connection (socket &key
- (external-format :iso-latin-1-unix)
- (buffering :full) timeout)
+ external-format
+ buffering timeout)
(declare (ignore timeout))
- (make-socket-io-stream (accept socket) external-format buffering))
+ (make-socket-io-stream (accept socket)
+ (or external-format :iso-latin-1-unix)
+ (or buffering :full)))
(defvar *sigio-handlers* '()
"List of (key . fn) pairs to be called on SIGIO.")
@@ -135,7 +137,7 @@
(return (sb-bsd-sockets:socket-accept socket))
(sb-bsd-sockets:interrupted-error ()))))
-(defmethod call-without-interrupts (fn)
+(defimplementation call-without-interrupts (fn)
(declare (type function fn))
(sb-sys:without-interrupts (funcall fn)))
@@ -234,10 +236,11 @@
;;; Utilities
-(defimplementation arglist ((fname t))
+(defimplementation arglist (fname)
(sb-introspect:function-arglist fname))
-(defimplementation function-name ((f function))
+(defimplementation function-name (f)
+ (check-type f function)
(sb-impl::%fun-name f))
(defvar *buffer-name* nil)
@@ -934,23 +937,22 @@ stack."
(defimplementation spawn (fn &key name)
(sb-thread:make-thread fn :name name))
- (defimplementation startup-multiprocessing ())
-
(defimplementation thread-id (thread)
- (sb-thread:with-mutex (*thread-id-map-lock*)
- (loop for id being the hash-key in *thread-id-map*
- using (hash-value thread-pointer)
- do
- (let ((maybe-thread (sb-ext:weak-pointer-value thread-pointer)))
- (cond ((null maybe-thread)
- ;; the value is gc'd, remove it manually
- (remhash id *thread-id-map*))
- ((eq thread maybe-thread)
- (return-from thread-id id)))))
- ;; lazy numbering
- (let ((id (next-thread-id)))
- (setf (gethash id *thread-id-map*) (sb-ext:make-weak-pointer thread))
- id)))
+ (block thread-id
+ (sb-thread:with-mutex (*thread-id-map-lock*)
+ (loop for id being the hash-key in *thread-id-map*
+ using (hash-value thread-pointer)
+ do
+ (let ((maybe-thread (sb-ext:weak-pointer-value thread-pointer)))
+ (cond ((null maybe-thread)
+ ;; the value is gc'd, remove it manually
+ (remhash id *thread-id-map*))
+ ((eq thread maybe-thread)
+ (return-from thread-id id)))))
+ ;; lazy numbering
+ (let ((id (next-thread-id)))
+ (setf (gethash id *thread-id-map*) (sb-ext:make-weak-pointer thread))
+ id))))
(defimplementation find-thread (id)
(sb-thread:with-mutex (*thread-id-map-lock*)
@@ -1040,7 +1042,7 @@ stack."
mutex))))))))
- ;;; Auto-flush streams
+;;; Auto-flush streams
;; XXX race conditions
(defvar *auto-flush-streams* '())
View
33 swank-scl.lisp
@@ -36,11 +36,10 @@
(defimplementation close-socket (socket)
(ext:close-socket (socket-fd socket)))
-(defimplementation accept-connection (socket &key
- (external-format :iso-latin-1-unix)
- (buffering :full)
- (timeout nil))
+(defimplementation accept-connection (socket
+ &key external-format buffering timeout)
(let ((external-format (or external-format :iso-latin-1-unix))
+ (buffering (or buffering :full))
(fd (socket-fd socket)))
(loop
(let ((ready (sys:wait-until-fd-usable fd :input timeout)))
@@ -1168,21 +1167,19 @@ Signal an error if no constructor can be found."
(list symbol))))
((:defined)
(ext:info :alien-type :definition symbol))
- (:unknown
- (return-from describe-definition
- (format nil "Unknown alien type: ~S" symbol))))))))
+ (:unknown :unknown))))))
;;;;; Argument lists
-(defimplementation arglist ((name symbol))
- (cond ((and (symbolp name) (macro-function name))
- (arglist (macro-function name)))
- ((fboundp name)
- (arglist (fdefinition name)))
+(defimplementation arglist (fun)
+ (cond ((and (symbolp fun) (macro-function fun))
+ (arglist (macro-function fun)))
+ ((fboundp fun)
+ (function-arglist (fdefinition fun)))
(t
:not-available)))
-(defimplementation arglist ((fun function))
+(defun function-arglist (fun function)
(flet ((compiled-function-arglist (x)
(let ((args (kernel:%function-arglist x)))
(if args
@@ -1588,6 +1585,7 @@ Signal an error if no constructor can be found."
(values :initarg :values :reader breakpoint.values))
(:report (lambda (c stream) (princ (breakpoint.message c) stream))))
+#+nil
(defimplementation condition-extras ((c breakpoint))
;; simply pop up the source buffer
`((:short-frame-source 0)))
@@ -1933,10 +1931,11 @@ The `symbol-value' of each element is a type tag.")
(incf *thread-id-counter*)))))
(defimplementation find-thread (id)
- (thread:map-over-threads
- #'(lambda (thread)
- (when (eql (getf (thread:thread-plist thread) 'id) id)
- (return-from find-thread thread)))))
+ (block find-thread
+ (thread:map-over-threads
+ #'(lambda (thread)
+ (when (eql (getf (thread:thread-plist thread) 'id) id)
+ (return-from find-thread thread))))))
(defimplementation thread-name (thread)
(princ-to-string (thread:thread-name thread)))
View
9 swank.lisp
@@ -1457,7 +1457,7 @@ Return the package or nil."
(let ((index 0)
(need-space nil))
(labels ((print-arg (arg)
- (etypecase arg
+ (typecase arg
(arglist ; destructuring pattern
(print-arglist arg))
(optional-arg
@@ -2236,9 +2236,8 @@ forward keywords to OPERATOR."
(let* ((p (find-package :swank))
(actual (arglist-to-string list p)))
(unless (string= actual string)
- (format *debug-io*
- "Test failed: ~S => ~S~% Expected: ~S"
- list actual string)))))
+ (warn "Test failed: ~S => ~S~% Expected: ~S"
+ list actual string)))))
(test '(function cons) "(function cons)")
(test '(quote cons) "(quote cons)")
(test '(&key (function #'+)) "(&key (function #'+))")
@@ -3422,7 +3421,7 @@ this call will also recurse.
Once a word has been completely matched, the chunks are pushed
onto the special variable *ALL-CHUNKS* and the function returns."
- (declare (optimize speed)
+ (declare ;;(optimize speed)
(fixnum short-index initial-full-index)
(simple-string short full)
(special *all-chunks*))

0 comments on commit e51892e

Please sign in to comment.
Something went wrong with that request. Please try again.