home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / CLX / depdefs.l < prev    next >
Encoding:
Text File  |  1991-07-12  |  21.5 KB  |  651 lines

  1. ;;; -*- Mode: LISP; Syntax: Common-lisp; Package: XLIB; Base: 10; Lowercase: Yes -*-
  2.  
  3. ;; This file contains some of the system dependent code for CLX
  4.  
  5. ;;;
  6. ;;;             TEXAS INSTRUMENTS INCORPORATED
  7. ;;;                  P.O. BOX 2909
  8. ;;;                   AUSTIN, TEXAS 78769
  9. ;;;
  10. ;;; Copyright (C) 1987 Texas Instruments Incorporated.
  11. ;;;
  12. ;;; Permission is granted to any individual or institution to use, copy, modify,
  13. ;;; and distribute this software, provided that this complete copyright and
  14. ;;; permission notice is maintained, intact, in all copies and supporting
  15. ;;; documentation.
  16. ;;;
  17. ;;; Texas Instruments Incorporated provides this software "as is" without
  18. ;;; express or implied warranty.
  19. ;;;
  20.  
  21. (in-package :xlib)
  22.  
  23. ;;;-------------------------------------------------------------------------
  24. ;;; Declarations
  25. ;;;-------------------------------------------------------------------------
  26.  
  27. ;;; fix a bug in kcl's RATIONAL...
  28. ;;;   redefine both the function and the type.
  29.  
  30. #+(or kcl ibcl)
  31. (progn
  32.   (defun rational (x)
  33.     (if (rationalp x)
  34.     x
  35.     (lisp:rational x)))
  36.   (deftype rational (&optional l u) `(lisp:rational ,l ,u)))
  37.  
  38. ;;; DECLAIM
  39.  
  40. #-clx-ansi-common-lisp
  41. (defmacro declaim (&rest decl-specs)
  42.   (if (cdr decl-specs)
  43.       `(progn
  44.      ,@(mapcar #'(lambda (decl-spec) `(proclaim ',decl-spec))
  45.            decl-specs))
  46.     `(proclaim ',(car decl-specs))))
  47.  
  48. ;;; VALUES value1 value2 ... -- Documents the values returned by the function.
  49.  
  50. #-lispm
  51. (declaim (declaration values))
  52.  
  53. ;;; ARGLIST arg1 arg2 ... -- Documents the arglist of the function.  Overrides
  54. ;;; the documentation that might get generated by the real arglist of the
  55. ;;; function.
  56.  
  57. #-(or lispm lcl3.0)
  58. (declaim (declaration arglist))
  59.  
  60. ;;; DYNAMIC-EXTENT var -- Tells the compiler that the rest arg var has
  61. ;;; dynamic extent and therefore can be kept on the stack and not copied to
  62. ;;; the heap, even though the value is passed out of the function.
  63.  
  64. #-(or clx-ansi-common-lisp lcl3.0)
  65. (declaim (declaration dynamic-extent))
  66.  
  67. ;;; IGNORABLE var -- Tells the compiler that the variable might or might not be used.
  68.  
  69. #-clx-ansi-common-lisp
  70. (declaim (declaration ignorable))
  71.  
  72. ;;; ARRAY-REGISTER var1 var2 ... -- The variables mentioned are locals (not
  73. ;;; args) that hold vectors.  
  74.  
  75. #-Genera 
  76. (declaim (declaration array-register))
  77.  
  78. ;;; INDENTATION argpos1 arginden1 argpos2 arginden2 --- Tells the lisp editor how to
  79. ;;; indent calls to the function or macro containing the declaration.  
  80.  
  81. #-genera
  82. (declaim (declaration indentation))
  83.  
  84. ;;;-------------------------------------------------------------------------
  85. ;;; Declaration macros
  86. ;;;-------------------------------------------------------------------------
  87.  
  88. ;;; WITH-VECTOR (variable type) &body body --- ensures the variable is a local
  89. ;;; and then does a type declaration and array register declaration
  90. (defmacro with-vector ((var type) &body body)
  91.   `(let ((,var ,var))
  92.      (declare (type ,type ,var)
  93.           (array-register ,var))
  94.      ,@body))
  95.  
  96. ;;; WITHIN-DEFINITION (name type) &body body --- Includes definitions for
  97. ;;; Meta-.
  98.  
  99. #+lispm
  100. (defmacro within-definition ((name type) &body body)
  101.   `(zl:local-declare
  102.      ((sys:function-parent ,name ,type))
  103.      (sys:record-source-file-name ',name ',type)
  104.      ,@body))
  105.  
  106. #-lispm
  107. (defmacro within-definition ((name type) &body body)
  108.   (declare (ignore name type))
  109.   `(progn ,@body))
  110.  
  111.  
  112. ;;;-------------------------------------------------------------------------
  113. ;;; CLX can maintain a mapping from X server ID's to local data types.  If
  114. ;;; one takes the view that CLX objects will be instance variables of
  115. ;;; objects at the next higher level, then PROCESS-EVENT will typically map
  116. ;;; from resource-id to higher-level object.  In that case, the lower-level
  117. ;;; CLX mapping will almost never be used (except in rare cases like
  118. ;;; query-tree), and only serve to consume space (which is difficult to
  119. ;;; GC), in which case always-consing versions of the make-<mumble>s will
  120. ;;; be better.  Even when maps are maintained, it isn't clear they are
  121. ;;; useful for much beyond xatoms and windows (since almost nothing else
  122. ;;; ever comes back in events).
  123. ;;;--------------------------------------------------------------------------
  124. (defconstant *clx-cached-types*
  125.          '( drawable
  126.         window
  127.         pixmap
  128. ;        gcontext
  129.         cursor
  130.         colormap
  131.         font))
  132.  
  133. (defmacro resource-id-map-test ()
  134.   #+excl '#'equal
  135.   #-excl '#'eql)
  136.                     ; (eq fixnum fixnum) is not guaranteed.
  137. (defmacro atom-cache-map-test ()
  138.   #+excl '#'equal
  139.   #-excl '#'eq)
  140.  
  141. (defmacro keysym->character-map-test ()
  142.   #+excl '#'equal
  143.   #-excl '#'eql)
  144.  
  145. ;;; You must define this to match the real byte order.  It is used by
  146. ;;; overlapping array and image code.
  147.  
  148. #+(or lispm vax little-endian Minima)
  149. (eval-when (eval compile load)
  150.   (pushnew :clx-little-endian *features*))
  151.  
  152. #+lcl3.0
  153. (eval-when (compile eval load)
  154.   (ecase lucid::machine-endian
  155.     (:big nil)
  156.     (:little (pushnew :clx-little-endian *features*))))
  157.  
  158. ;;; Steele's Common-Lisp states:  "It is an error if the array specified
  159. ;;; as the :displaced-to argument  does not have the same :element-type
  160. ;;; as the array being created" If this is the case on your lisp, then
  161. ;;; leave the overlapping-arrays feature turned off.  Lisp machines
  162. ;;; (Symbolics TI and LMI) don't have this restriction, and allow arrays
  163. ;;; with different element types to overlap.  CLX will take advantage of
  164. ;;; this to do fast array packing/unpacking when the overlapping-arrays
  165. ;;; feature is enabled.
  166.  
  167. #+(and clx-little-endian lispm)
  168. (eval-when (eval compile load)
  169.   (pushnew :clx-overlapping-arrays *features*))
  170.  
  171. #+(and clx-overlapping-arrays genera)
  172. (progn
  173. (deftype overlap16 () '(unsigned-byte 16))
  174. (deftype overlap32 () '(signed-byte 32))
  175. )
  176.  
  177. #+(and clx-overlapping-arrays (or explorer lambda cadr))
  178. (progn
  179. (deftype overlap16 () '(unsigned-byte 16))
  180. (deftype overlap32 () '(unsigned-byte 32))
  181. )
  182.  
  183. (deftype buffer-bytes () `(simple-array (unsigned-byte 8) (*)))
  184.  
  185. #+clx-overlapping-arrays
  186. (progn
  187. (deftype buffer-words () `(vector overlap16))
  188. (deftype buffer-longs () `(vector overlap32))
  189. )
  190.  
  191. ;;; This defines a type which is a subtype of the integers.
  192. ;;; This type is used to describe all variables that can be array indices.
  193. ;;; It is here because it is used below.
  194. ;;; This is inclusive because start/end can be 1 past the end.
  195. (deftype array-index () `(integer 0 ,array-dimension-limit))
  196.  
  197.  
  198. ;; this is the best place to define these?
  199.  
  200. #-Genera
  201. (progn
  202.  
  203. (defun make-index-typed (form)
  204.   (if (constantp form) form `(the array-index ,form)))
  205.  
  206. (defun make-index-op (operator args)
  207.   `(the array-index
  208.     (values 
  209.       ,(case (length args)
  210.          (0 `(,operator))
  211.          (1 `(,operator
  212.           ,(make-index-typed (first args))))
  213.          (2 `(,operator
  214.           ,(make-index-typed (first args))
  215.           ,(make-index-typed (second args))))
  216.          (otherwise
  217.            `(,operator
  218.          ,(make-index-op operator (subseq args 0 (1- (length args))))
  219.          ,(make-index-typed (first (last args)))))))))
  220.  
  221. (defmacro index+ (&rest numbers) (make-index-op '+ numbers))
  222. (defmacro index-logand (&rest numbers) (make-index-op 'logand numbers))
  223. (defmacro index-logior (&rest numbers) (make-index-op 'logior numbers))
  224. (defmacro index- (&rest numbers) (make-index-op '- numbers))
  225. (defmacro index* (&rest numbers) (make-index-op '* numbers))
  226.  
  227. (defmacro index1+ (number) (make-index-op '1+ (list number)))
  228. (defmacro index1- (number) (make-index-op '1- (list number)))
  229.  
  230. (defmacro index-incf (place &optional (delta 1))
  231.   (make-index-op 'incf (list place delta)))
  232. (defmacro index-decf (place &optional (delta 1))
  233.   (make-index-op 'decf (list place delta)))
  234.  
  235. (defmacro index-min (&rest numbers) (make-index-op 'min numbers))
  236. (defmacro index-max (&rest numbers) (make-index-op 'max numbers))
  237.  
  238. (defmacro index-floor (number divisor)
  239.   (make-index-op 'floor (list number divisor)))
  240. (defmacro index-ceiling (number divisor)
  241.   (make-index-op 'ceiling (list number divisor)))
  242. (defmacro index-truncate (number divisor)
  243.   (make-index-op 'truncate (list number divisor)))
  244.  
  245. (defmacro index-mod (number divisor)
  246.   (make-index-op 'mod (list number divisor)))
  247.  
  248. (defmacro index-ash (number count)
  249.   (make-index-op 'ash (list number count)))
  250.  
  251. (defmacro index-plusp (number) `(plusp (the array-index ,number)))
  252. (defmacro index-zerop (number) `(zerop (the array-index ,number)))
  253. (defmacro index-evenp (number) `(evenp (the array-index ,number)))
  254. (defmacro index-oddp  (number) `(oddp  (the array-index ,number)))
  255.  
  256. (defmacro index> (&rest numbers)
  257.   `(> ,@(mapcar #'make-index-typed numbers)))
  258. (defmacro index= (&rest numbers)
  259.   `(= ,@(mapcar #'make-index-typed numbers)))
  260. (defmacro index< (&rest numbers)
  261.   `(< ,@(mapcar #'make-index-typed numbers)))
  262. (defmacro index>= (&rest numbers)
  263.   `(>= ,@(mapcar #'make-index-typed numbers)))
  264. (defmacro index<= (&rest numbers)
  265.   `(<= ,@(mapcar #'make-index-typed numbers)))
  266.  
  267. )
  268.  
  269. #+Genera
  270. (progn
  271.  
  272. (defmacro index+ (&rest numbers) `(+ ,@numbers))
  273. (defmacro index-logand (&rest numbers) `(logand ,@numbers))
  274. (defmacro index-logior (&rest numbers) `(logior ,@numbers))
  275. (defmacro index- (&rest numbers) `(- ,@numbers))
  276. (defmacro index* (&rest numbers) `(* ,@numbers))
  277.  
  278. (defmacro index1+ (number) `(1+ ,number))
  279. (defmacro index1- (number) `(1- ,number))
  280.  
  281. (defmacro index-incf (place &optional (delta 1)) `(setf ,place (index+ ,place ,delta)))
  282. (defmacro index-decf (place &optional (delta 1)) `(setf ,place (index- ,place ,delta)))
  283.  
  284. (defmacro index-min (&rest numbers) `(min ,@numbers))
  285. (defmacro index-max (&rest numbers) `(max ,@numbers))
  286.  
  287. (defun positive-power-of-two-p (x)
  288.   (when (symbolp x)
  289.     (multiple-value-bind (constantp value) (lt:named-constant-p x)
  290.       (when constantp (setq x value))))
  291.   (and (typep x 'fixnum) (plusp x) (zerop (logand x (1- x)))))
  292.  
  293. (defmacro index-floor (number divisor)
  294.   (cond ((eql divisor 1) number)
  295.     ((and (positive-power-of-two-p divisor) (fboundp 'si:%fixnum-floor))
  296.      `(si:%fixnum-floor ,number ,divisor))
  297.     (t `(floor ,number ,divisor))))
  298.  
  299. (defmacro index-ceiling (number divisor)
  300.   (cond ((eql divisor 1) number)
  301.     ((and (positive-power-of-two-p divisor) (fboundp 'si:%fixnum-ceiling))
  302.      `(si:%fixnum-ceiling ,number ,divisor))
  303.     (t `(ceiling ,number ,divisor))))
  304.  
  305. (defmacro index-truncate (number divisor)
  306.   (cond ((eql divisor 1) number)
  307.     ((and (positive-power-of-two-p divisor) (fboundp 'si:%fixnum-floor))
  308.      `(si:%fixnum-floor ,number ,divisor))
  309.     (t `(truncate ,number ,divisor))))
  310.  
  311. (defmacro index-mod (number divisor)
  312.   (cond ((and (positive-power-of-two-p divisor) (fboundp 'si:%fixnum-mod))
  313.      `(si:%fixnum-mod ,number ,divisor))
  314.     (t `(mod ,number ,divisor))))
  315.  
  316. (defmacro index-ash (number count)
  317.   (cond ((eql count 0) number)
  318.     ((and (typep count 'fixnum) (minusp count) (fboundp 'si:%fixnum-floor))
  319.      `(si:%fixnum-floor ,number ,(expt 2 (- count))))
  320.     ((and (typep count 'fixnum) (plusp count) (fboundp 'si:%fixnum-multiply))
  321.      `(si:%fixnum-multiply ,number ,(expt 2 count)))
  322.     (t `(ash ,number ,count))))
  323.  
  324. (defmacro index-plusp (number) `(plusp ,number))
  325. (defmacro index-zerop (number) `(zerop ,number))
  326. (defmacro index-evenp (number) `(evenp ,number))
  327. (defmacro index-oddp  (number) `(oddp  ,number))
  328.  
  329. (defmacro index> (&rest numbers) `(> ,@numbers))
  330. (defmacro index= (&rest numbers) `(= ,@numbers))
  331. (defmacro index< (&rest numbers) `(< ,@numbers))
  332. (defmacro index>= (&rest numbers) `(>= ,@numbers))
  333. (defmacro index<= (&rest numbers) `(<= ,@numbers))
  334.  
  335. )
  336.  
  337. ;;;; Stuff for BUFFER definition
  338.  
  339. (defconstant *replysize* 32.)
  340.  
  341. ;; used in defstruct initializations to avoid compiler warnings
  342. (defvar *empty-bytes* (make-sequence 'buffer-bytes 0))
  343. (declaim (type buffer-bytes *empty-bytes*))
  344. #+clx-overlapping-arrays
  345. (progn
  346. (defvar *empty-words* (make-sequence 'buffer-words 0))
  347. (declaim (type buffer-words *empty-words*))
  348. )
  349. #+clx-overlapping-arrays
  350. (progn
  351. (defvar *empty-longs* (make-sequence 'buffer-longs 0))
  352. (declaim (type buffer-longs *empty-longs*))
  353. )
  354.  
  355. (defstruct (reply-buffer (:conc-name reply-) (:constructor make-reply-buffer-internal)
  356.              (:copier nil) (:predicate nil))
  357.   (size 0 :type array-index)            ;Buffer size
  358.   ;; Byte (8 bit) input buffer
  359.   (ibuf8 *empty-bytes* :type buffer-bytes)
  360.   ;; Word (16bit) input buffer
  361.   #+clx-overlapping-arrays
  362.   (ibuf16 *empty-words* :type buffer-words)
  363.   ;; Long (32bit) input buffer
  364.   #+clx-overlapping-arrays
  365.   (ibuf32 *empty-longs* :type buffer-longs)
  366.   (next nil #-explorer :type #-explorer (or null reply-buffer))
  367.   (data-size 0 :type array-index)
  368.   )
  369.  
  370. (defconstant *buffer-text16-size* 256)
  371. (deftype buffer-text16 () `(simple-array (unsigned-byte 16) (,*buffer-text16-size*)))
  372.  
  373. ;; These are here because.
  374.  
  375. (defparameter *xlib-package* (find-package :xlib))
  376.  
  377. (defun xintern (&rest parts)
  378.   (intern (apply #'concatenate 'string (mapcar #'string parts)) *xlib-package*))
  379.  
  380. (defparameter *keyword-package* (find-package :keyword))
  381.  
  382. (defun kintern (name)
  383.   (intern (string name) *keyword-package*))
  384.  
  385. ;;; Pseudo-class mechanism.
  386.  
  387. (eval-when (eval compile load)
  388. (defvar *def-clx-class-use-defclass* #+Genera t #-Genera nil
  389.   "Controls whether DEF-CLX-CLASS uses DEFCLASS.  
  390.    If it is a list, it is interpreted by DEF-CLX-CLASS to be a list of type names
  391.    for which DEFCLASS should be used. 
  392.    If it is not a list, then DEFCLASS is always used.
  393.    If it is NIL, then DEFCLASS is never used, since NIL is the empty list.")
  394. )
  395.  
  396. (defmacro def-clx-class ((name &rest options) &body slots)
  397.   (if (or (not (listp *def-clx-class-use-defclass*))
  398.       (member name *def-clx-class-use-defclass*))
  399.       (let ((clos-package #+clx-ansi-common-lisp
  400.               (find-package :common-lisp)
  401.               #-clx-ansi-common-lisp
  402.               (or (find-package :clos)
  403.                   (find-package :pcl)
  404.                   (let ((lisp-pkg (find-package :lisp)))
  405.                 (and (find-symbol (string 'defclass) lisp-pkg)
  406.                      lisp-pkg))))
  407.         (constructor t)
  408.         (constructor-args t)
  409.         (include nil)
  410.         (print-function nil)
  411.         (copier t)
  412.         (predicate t))
  413.     (dolist (option options)
  414.       (ecase (pop option)
  415.         (:constructor
  416.           (setf constructor (pop option))
  417.           (setf constructor-args (if (null option) t (pop option))))
  418.         (:include
  419.           (setf include (pop option)))
  420.         (:print-function
  421.           (setf print-function (pop option)))
  422.         (:copier
  423.           (setf copier (pop option)))
  424.         (:predicate
  425.           (setf predicate (pop option)))))
  426.     (flet ((cintern (&rest symbols)
  427.          (intern (apply #'concatenate 'simple-string
  428.                 (mapcar #'symbol-name symbols))
  429.              *package*))
  430.            (kintern (symbol)
  431.             (intern (symbol-name symbol) (find-package :keyword)))
  432.            (closintern (symbol)
  433.          (intern (symbol-name symbol) clos-package)))
  434.       (when (eq constructor t)
  435.         (setf constructor (cintern 'make- name)))
  436.       (when (eq copier t)
  437.         (setf copier (cintern 'copy- name)))
  438.       (when (eq predicate t)
  439.         (setf predicate (cintern name '-p)))
  440.       (when include
  441.         (setf slots (append (get include 'def-clx-class) slots)))
  442.       (let* ((n-slots (length slots))
  443.          (slot-names (make-list n-slots))
  444.          (slot-initforms (make-list n-slots))
  445.          (slot-types (make-list n-slots)))
  446.         (dotimes (i n-slots)
  447.           (let ((slot (elt slots i)))
  448.         (setf (elt slot-names i) (pop slot))
  449.         (setf (elt slot-initforms i) (pop slot))
  450.         (setf (elt slot-types i) (getf slot :type t))))
  451.         `(progn
  452.  
  453.            (eval-when (compile load eval)
  454.          (setf (get ',name 'def-clx-class) ',slots))
  455.  
  456.            ;; From here down are the system-specific expansions:
  457.  
  458.            (within-definition (,name def-clx-class)
  459.          (,(closintern 'defclass)
  460.           ,name ,(and include `(,include))
  461.           (,@(map 'list
  462.               #'(lambda (slot-name slot-initform slot-type)
  463.                   `(,slot-name
  464.                 :initform ,slot-initform :type ,slot-type
  465.                 :accessor ,(cintern name '- slot-name)
  466.                 ,@(when (and constructor
  467.                          (or (eq constructor-args t)
  468.                          (member slot-name
  469.                              constructor-args)))
  470.                     `(:initarg ,(kintern slot-name)))
  471.                 ))
  472.               slot-names slot-initforms slot-types)))
  473.          ,(when constructor
  474.             (if (eq constructor-args t)
  475.             `(defun ,constructor (&rest args)
  476.                (apply #',(closintern 'make-instance)
  477.                   ',name args))
  478.             `(defun ,constructor ,constructor-args
  479.                (,(closintern 'make-instance) ',name
  480.                 ,@(mapcan #'(lambda (slot-name)
  481.                       (and (member slot-name slot-names)
  482.                            `(,(kintern slot-name) ,slot-name)))
  483.                       constructor-args)))))
  484.          ,(when predicate
  485.             #+allegro
  486.             `(progn
  487.                (,(closintern 'defmethod) ,predicate (object)
  488.              (declare (ignore object))
  489.              nil)
  490.                (,(closintern 'defmethod) ,predicate ((object ,name))
  491.              t))
  492.             #-allegro
  493.             `(defun ,predicate (object)
  494.                (typep object ',name)))
  495.          ,(when copier
  496.             `(,(closintern 'defmethod) ,copier ((.object. ,name))
  497.               (,(closintern 'with-slots) ,slot-names .object.
  498.                (,(closintern 'make-instance) ',name
  499.             ,@(mapcan #'(lambda (slot-name)
  500.                       `(,(kintern slot-name) ,slot-name))
  501.                   slot-names)))))
  502.          ,(when print-function
  503.             `(,(closintern 'defmethod)
  504.               ,(closintern 'print-object)
  505.               ((object ,name) stream)
  506.               (,print-function object stream 0))))))))
  507.       `(within-definition (,name def-clx-class)
  508.      (defstruct (,name ,@options)
  509.        ,@slots))))
  510.  
  511. #+Genera
  512. (progn
  513.   (scl:defprop def-clx-class "CLX Class" si:definition-type-name)
  514.   (scl:defprop def-clx-class zwei:defselect-function-spec-finder
  515.            zwei:definition-function-spec-finder))
  516.  
  517.  
  518. ;; We need this here so we can define DISPLAY for CLX.
  519. ;;
  520. ;; This structure is :INCLUDEd in the DISPLAY structure.
  521. ;; Overlapping (displaced) arrays are provided for byte
  522. ;; half-word and word access on both input and output.
  523. ;;
  524. (def-clx-class (buffer (:constructor nil) (:copier nil) (:predicate nil))
  525.   ;; Lock for multi-processing systems
  526.   (lock (make-process-lock "CLX Buffer Lock"))
  527.   #-excl (output-stream nil :type (or null stream))
  528.   #+excl (output-stream -1 :type fixnum)
  529.   ;; Buffer size
  530.   (size 0 :type array-index)
  531.   (request-number 0 :type (unsigned-byte 16))
  532.   ;; Byte position of start of last request
  533.   ;; used for appending requests and error recovery
  534.   (last-request nil :type (or null array-index))
  535.   ;; Byte position of start of last flushed request
  536.   (last-flushed-request nil :type (or null array-index))
  537.   ;; Current byte offset
  538.   (boffset 0 :type array-index)
  539.   ;; Byte (8 bit) output buffer
  540.   (obuf8 *empty-bytes* :type buffer-bytes)
  541.   ;; Word (16bit) output buffer
  542.   #+clx-overlapping-arrays
  543.   (obuf16 *empty-words* :type buffer-words)
  544.   ;; Long (32bit) output buffer
  545.   #+clx-overlapping-arrays
  546.   (obuf32 *empty-longs* :type buffer-longs)
  547.   ;; Holding buffer for 16-bit text
  548.   (tbuf16 (make-sequence 'buffer-text16 *buffer-text16-size* :initial-element 0))
  549.   ;; Probably EQ to Output-Stream
  550.   #-excl (input-stream nil :type (or null stream))
  551.   #+excl (input-stream -1 :type fixnum)
  552.   ;; T when the host connection has gotten errors
  553.   (dead nil :type (or null (not null)))
  554.   ;; T makes buffer-flush a noop.  Manipulated with with-buffer-flush-inhibited.
  555.   (flush-inhibit nil :type (or null (not null)))
  556.   
  557.   ;; Change these functions when using shared memory buffers to the server
  558.   ;; Function to call when writing the buffer
  559.   (write-function 'buffer-write-default)
  560.   ;; Function to call when flushing the buffer
  561.   (force-output-function 'buffer-force-output-default)
  562.   ;; Function to call when closing a connection
  563.   (close-function 'buffer-close-default)
  564.   ;; Function to call when reading the buffer
  565.   (input-function 'buffer-read-default)
  566.   ;; Function to call to wait for data to be input
  567.   (input-wait-function 'buffer-input-wait-default)
  568.   ;; Function to call to listen for input data
  569.   (listen-function 'buffer-listen-default)
  570.  
  571.   #+Genera (debug-io nil :type (or null stream))
  572.   ) 
  573.  
  574. ;;-----------------------------------------------------------------------------
  575. ;; Printing routines.
  576. ;;-----------------------------------------------------------------------------
  577.  
  578. #-(or clx-ansi-common-lisp Genera)
  579. (defun print-unreadable-object-function (object stream type identity function)
  580.   (declare #+lispm
  581.        (sys:downward-funarg function))
  582.   (princ "#<" stream)
  583.   (when type
  584.     (let ((type (type-of object))
  585.       (pcl-package (find-package :pcl)))
  586.       ;; Handle pcl type-of lossage
  587.       (when (and pcl-package
  588.          (symbolp type)
  589.          (eq (symbol-package type) pcl-package)
  590.          (string-equal (symbol-name type) "STD-INSTANCE"))
  591.     (setq type
  592.           (funcall (intern (symbol-name 'class-name) pcl-package)
  593.                (funcall (intern (symbol-name 'class-of) pcl-package)
  594.                 object))))
  595.       (prin1 type stream)))
  596.   (when (and type function) (princ " " stream))
  597.   (when function (funcall function))
  598.   (when (and (or type function) identity) (princ " " stream))
  599.   (when identity (princ "???" stream))
  600.   (princ ">" stream)
  601.   nil)
  602.   
  603. #-(or clx-ansi-common-lisp Genera)
  604. (defmacro print-unreadable-object
  605.       ((object stream &key type identity) &body body)
  606.   (if body
  607.       `(flet ((.print-unreadable-object-body. () ,@body))
  608.      (print-unreadable-object-function
  609.        ,object ,stream ,type ,identity #'.print-unreadable-object-body.))
  610.     `(print-unreadable-object-function ,object ,stream ,type ,identity nil)))
  611.  
  612.  
  613. ;;-----------------------------------------------------------------------------
  614. ;; Image stuff
  615. ;;-----------------------------------------------------------------------------
  616.  
  617. (defconstant *image-bit-lsb-first-p*
  618.          #+clx-little-endian t
  619.          #-clx-little-endian nil)
  620.  
  621. (defconstant *image-byte-lsb-first-p*
  622.          #+clx-little-endian t
  623.          #-clx-little-endian nil)
  624.  
  625. (defconstant *image-unit* 32)
  626.  
  627. (defconstant *image-pad* 32)
  628.  
  629.  
  630. ;;-----------------------------------------------------------------------------
  631. ;; Foreign Functions
  632. ;;-----------------------------------------------------------------------------
  633.  
  634. #+(and lucid apollo (not lcl3.0))
  635. (lucid::define-foreign-function '(connect-to-server "connect_to_server")
  636.   '((:val host    :string)
  637.     (:val display :integer32))
  638.   :integer32)
  639.  
  640. #+(and lucid (not apollo) (not lcl3.0))
  641. (lucid::define-c-function connect-to-server (host display)
  642.   :result-type :integer)
  643.  
  644. #+lcl3.0
  645. (lucid::def-foreign-function
  646.     (connect-to-server 
  647.       (:language :c)
  648.       (:return-type :signed-32bit))
  649.   (host :simple-string)
  650.   (display :signed-32bit))
  651.