فهرست منبع

Initial revision

dlichteblau 20 سال پیش
کامیت
7c02055836
5فایلهای تغییر یافته به همراه130 افزوده شده و 0 حذف شده
  1. 3 0
      Makefile
  2. 20 0
      README
  3. 54 0
      mixin.lisp
  4. 44 0
      package.lisp
  5. 9 0
      trivial-gray-streams.asd

+ 3 - 0
Makefile

@@ -0,0 +1,3 @@
+.PHONY: clean
+clean:
+	rm -f *.fasl *.x86f *.fas *.ufsl *.lib *.pfsl

+ 20 - 0
README

@@ -0,0 +1,20 @@
+trivial-gray-streams
+====================
+
+This system provides an extremely thin compatibility layer for gray
+streams.  It is nearly *too* trivial for a complete package, except that
+I have copy&pasted this code into enough projects now that I decided to
+factor it out once again now, and then *never* have to touch it again.
+
+
+How to use it
+=============
+
+1. Use the package TRIVIAL-GRAY-STREAMS instead of whatever
+   implementation-specific package you would have to use otherwise to
+   get at gray stream symbols.
+2. For STREAM-READ-SEQUENCE and STREAM-WRITE-SEQUENCE, notice that we
+   use two &OPTIONAL arguments.
+3. In order for (2) to work on Lispworks, CLISP, and OpenMCL, make sure to
+   subclass all your stream classes from TRIVIAL-GRAY-STREAM-MIXIN if you
+   intend to define methods on those two generic functions.

+ 54 - 0
mixin.lisp

@@ -0,0 +1,54 @@
+(in-package :trivial-gray-streams)
+
+(defclass trivial-gray-stream-mixin () ())
+
+#+lispworks
+(progn
+  (defgeneric stream-read-sequence (stream sequence &optional start end))
+  (defgeneric stream-write-sequence (stream sequence &optional start end))
+
+  (defmethod stream:stream-read-sequence
+      ((s trivial-gray-stream-mixin) seq start end)
+    (stream-read-sequence seq start end))
+
+  (defmethod stream:stream-write-sequence
+      ((s trivial-gray-stream-mixin) seq start end)
+    (stream-read-sequence seq start end)))
+
+#+openmcl
+(progn
+  (defgeneric stream-read-sequence (stream sequence &optional start end))
+  (defgeneric stream-write-sequence (stream sequence &optional start end))
+
+  (defmethod ccl:stream-read-vector
+      ((s trivial-gray-stream-mixin) seq start end)
+    (stream-read-sequence seq start end))
+
+  (defmethod ccl:stream-write-vector
+      ((s trivial-gray-stream-mixin) seq start end)
+    (stream-write-sequence seq start end)))
+
+#+clisp
+(progn
+  (defgeneric stream-read-sequence (stream sequence &optional start end))
+  (defgeneric stream-write-sequence (stream sequence &optional start end))
+
+  (defmethod gray:stream-read-byte-sequence
+      ((s trivial-gray-stream-mixin)
+       seq
+       &optional start end no-hang interactive)
+    (when no-hang
+      (error "this stream does not support the NO-HANG argument"))
+    (when interactive
+      (error "this stream does not support the INTERACTIVE argument"))
+    (stream-read-sequence seq start end))
+
+  (defmethod gray:stream-write-byte-sequence
+      ((s trivial-gray-stream-mixin)
+       seq
+       &optional start end no-hang interactive)
+    (when no-hang
+      (error "this stream does not support the NO-HANG argument"))
+    (when interactive
+      (error "this stream does not support the INTERACTIVE argument"))
+    (stream-write-sequence seq start end)))

+ 44 - 0
package.lisp

@@ -0,0 +1,44 @@
+(in-package :trivial-gray-streams-system)
+
+#+cmu
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (require :gray-streams))
+
+(macrolet
+    ((frob ()
+       (let
+	   ((common-symbols
+	     '(#:fundamental-stream #:fundamental-input-stream
+	       #:fundamental-output-stream #:fundamental-character-stream
+	       #:fundamental-binary-stream #:fundamental-character-input-stream
+	       #:fundamental-character-output-stream
+	       #:fundamental-binary-input-stream
+	       #:fundamental-binary-output-stream #:stream-read-char
+	       #:stream-unread-char #:stream-read-char-no-hang
+	       #:stream-peek-char #:stream-listen #:stream-read-line
+	       #:stream-clear-input #:stream-write-char #:stream-line-column
+	       #:stream-start-line-p #:stream-write-string #:stream-terpri
+	       #:stream-fresh-line #:stream-finish-output #:stream-force-output
+	       #:stream-clear-output #:stream-advance-to-column
+	       #:stream-read-byte #:stream-write-byte)))
+	 `(defpackage :trivial-gray-streams
+	    (:use :cl)
+	    (:import-from #+sbcl :sb-gray
+			  #+allegro :excl
+			  #+cmu :ext
+			  #+clisp :gray
+			  #+openmcl :ccl
+			  #+lispworks :stream
+			  #-(or sbcl allegro cmu clisp openmcl lispworks) ...
+
+			  #-(or lispworks clisp openmcl)
+                          #:stream-read-sequence
+			  #-(or lispworks clisp openmcl)
+                          #:stream-write-sequence
+
+			  ,@common-symbols)
+	    (:export #:trivial-gray-stream-mixin
+		     #:stream-read-sequence
+		     #:stream-write-sequence
+		     ,@common-symbols)))))
+  (frob))

+ 9 - 0
trivial-gray-streams.asd

@@ -0,0 +1,9 @@
+;;; -*- mode: lisp -*-
+
+(defpackage :trivial-gray-streams-system
+(:use :cl :asdf))
+(in-package :trivial-gray-streams-system)
+
+(defsystem :trivial-gray-streams
+  :serial t
+  :components ((:file "package") (:file "mixin")))