1 ;;;============================================================================
3 ;;; File: "_io#.scm", Time-stamp: <2009-11-24 19:11:32 feeley>
5 ;;; Copyright (c) 1994-2009 by Marc Feeley, All Rights Reserved.
7 ;;;============================================================================
9 ;;; Representation of exceptions.
11 (define-library-type-of-exception datum-parsing-exception
12 id: 84660e37-9565-4abf-ac09-f9767f926d40
16 (kind unprintable: read-only:)
17 (readenv unprintable: read-only:)
18 (parameters unprintable: read-only:)
21 (define-library-type-of-exception unterminated-process-exception
22 id: b320dfbf-c714-4dc5-8bfa-cac5ee6c8421
33 (define-library-type-of-exception nonempty-input-port-character-buffer-exception
34 id: 63b50ae7-375b-4b94-81df-3522686f5634
45 ;;;----------------------------------------------------------------------------
47 ;;; Define type checking macros.
49 (define-check-type string-or-ip-address 'string-or-ip-address
50 macro-string-or-ip-address?)
52 (##define-macro (macro-string-or-ip-address? obj)
53 `(##string-or-ip-address? ,obj))
55 ;;;----------------------------------------------------------------------------
57 ;;; Representation of ports.
59 ;; There are 5 kinds of ports, each providing a set of operations. All
60 ;; port objects have the capability of being both an input port and an
61 ;; output port. The "none-port" kind provides no operation and is
62 ;; mainly for internal use to indicate that no input operation is
63 ;; available or that no output operation is available.
65 ;; 1) An "object-port" (or simply a "port") provides operations to read
66 ;; and write Scheme data (i.e. any Scheme object) to/from the port.
67 ;; It also provides operations to get the name of the port, to force
68 ;; output to occur, and to close the port. This kind of port need
69 ;; not be connected to a character based device or file (it could
70 ;; for example be a FIFO queue linking two threads that need to
71 ;; communicate Scheme objects).
73 ;; 2) A "character-port" provides all the operations of an "object-port",
74 ;; and also operations to read and write individual characters
75 ;; to/from the port. When a Scheme object is written to a
76 ;; character-port, it is converted into the sequence of characters that
77 ;; corresponds to its "external-representation". When reading a
78 ;; Scheme object, an inverse conversion occurs.
80 ;; 3) A "byte-port" provides all the operations of a "character-port", and
81 ;; also operations to read and write individual bytes to/from the
82 ;; port. When a **character** is written to a byte-port, some
83 ;; encoding of that character into a sequence of bytes will occur
84 ;; (for example, #\newline might be encoded as the 2 bytes CR-LF
85 ;; when using ISO-8859-1 encoding, or a non-ASCII character will
86 ;; generate more than 1 byte when using UTF-8 encoding). When
87 ;; reading a character, a similar decoding occurs.
89 ;; 4) A "device-port" provides all the operations of a "byte-port", and
90 ;; also operations to control the device (file, tty, etc) that is
91 ;; connected to the port, such as changing the tty settings.
94 id: 2babe060-9af6-456f-a26e-40b592f690ec
95 type-exhibitor: macro-type-port
96 constructor: macro-make-port
97 implementer: implement-type-port
103 extender: define-type-of-port
105 mutex ;; access to the port is controlled with this mutex
107 rkind ;; port kind for reading (none-port if can't read)
108 wkind ;; port kind for writing (none-port if can't write)
110 name ;; procedure which returns the name of the port
111 read-datum ;; procedure to read a datum
112 write-datum ;; procedure to write a datum
113 newline ;; procedure to write a datum separator
114 force-output ;; procedure to force output to occur on target device
115 close ;; procedure to close the port
116 roptions ;; options for reading (buffering type, encoding, etc)
117 rtimeout ;; time at which a read that would block times out
118 rtimeout-thunk ;; thunk called when a read timeout occurs
119 set-rtimeout ;; procedure to set rtimeout and rtimeout-thunk
120 woptions ;; options for writing (buffering type, encoding, etc)
121 wtimeout ;; time at which a write that would block times out
122 wtimeout-thunk ;; thunk called when a write timeout occurs
123 set-wtimeout ;; procedure to set wtimeout and wtimeout-thunk
126 (define-check-type port (macro-type-port)
129 (##define-macro (macro-port-of-rkind? obj kind)
131 (and (macro-port? obj)
132 (##fixnum.= (##fixnum.bitwise-and (macro-port-rkind obj) ,kind)
135 (##define-macro (macro-port-of-wkind? obj kind)
137 (and (macro-port? obj)
138 (##fixnum.= (##fixnum.bitwise-and (macro-port-wkind obj) ,kind)
141 (##define-macro (macro-none-kind) 0) ;; allows nothing
142 (##define-macro (macro-object-kind) 1) ;; can read and write objects
143 (##define-macro (macro-character-kind) 3) ;; can also read and write chars
144 (##define-macro (macro-byte-kind) 7) ;; can also read and write bytes
145 (##define-macro (macro-device-kind) 15) ;; can also do device operations
147 (##define-macro (macro-file-kind) (+ 15 16))
148 (##define-macro (macro-process-kind) (+ 15 32))
149 (##define-macro (macro-tty-kind) (+ 15 64))
150 (##define-macro (macro-serial-kind) (+ 15 128))
151 (##define-macro (macro-tcp-client-kind) (+ 15 256))
152 (##define-macro (macro-tcp-server-kind) (+ 1 512))
153 (##define-macro (macro-directory-kind) (+ 1 1024))
154 (##define-macro (macro-event-queue-kind) (+ 1 2048))
155 (##define-macro (macro-timer-kind) (+ 1 4096))
156 (##define-macro (macro-vector-kind) (+ 1 8192))
157 (##define-macro (macro-string-kind) (+ 3 16384))
158 (##define-macro (macro-u8vector-kind) (+ 7 32768))
160 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
162 ;;; Representation of object ports.
164 (define-check-type input-port 'input-port
166 (define-check-type output-port 'output-port
169 (##define-macro (macro-input-port? obj)
170 `(macro-port-of-rkind? ,obj (macro-object-kind)))
172 (##define-macro (macro-output-port? obj)
173 `(macro-port-of-wkind? ,obj (macro-object-kind)))
175 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
177 ;;; Representation of char ports.
179 (define-check-type character-input-port 'character-input-port
180 macro-character-input-port?)
181 (define-check-type character-output-port 'character-output-port
182 macro-character-output-port?)
184 (define-type-of-port character-port
185 id: 85099702-35ec-4cb8-ae55-13c4b9b05d10
186 type-exhibitor: macro-type-character-port
187 constructor: macro-make-character-port
188 implementer: implement-type-character-port
194 extender: define-type-of-character-port
196 rbuf ;; character read buffer (a string)
197 rlo ;; low pointer (start of unread characters)
198 rhi ;; high pointer (end of unread characters)
199 rchars ;; number of characters read at start of read buffer
200 rlines ;; number of lines read up to low pointer
201 rcurline ;; absolute character position where current line starts
202 rbuf-fill ;; procedure to read characters into the read buffer
203 peek-eof? ;; peeking the next character should return end-of-file?
205 wbuf ;; character write buffer (a string)
206 wlo ;; low pointer (start of unwritten characters)
207 whi ;; high pointer (end of unwritten characters)
208 wchars ;; number of characters written at start of write buffer
209 wlines ;; number of lines written up to high pointer
210 wcurline ;; absolute character position where current line starts
211 wbuf-drain ;; procedure to write characters from the write buffer
213 input-readtable ;; readtable for reading
214 output-readtable ;; readtable for writing
215 output-width ;; procedure to get the output width in characters
218 (##define-macro (macro-character-input-port? obj)
219 `(macro-port-of-rkind? ,obj (macro-character-kind)))
221 (##define-macro (macro-character-output-port? obj)
222 `(macro-port-of-wkind? ,obj (macro-character-kind)))
224 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
226 ;;; Representation of byte ports.
228 (define-check-type byte-port 'byte-port
230 (define-check-type byte-input-port 'byte-input-port
231 macro-byte-input-port?)
232 (define-check-type byte-output-port 'byte-output-port
233 macro-byte-output-port?)
235 (define-type-of-character-port byte-port
236 id: 8a99028e-7b99-4468-b94e-728737ec1b1a
237 type-exhibitor: macro-type-byte-port
238 constructor: macro-make-byte-port
239 implementer: implement-type-byte-port
245 extender: define-type-of-byte-port
247 rbuf ;; byte read buffer (a u8vector)
248 rlo ;; low pointer (start of unread bytes)
249 rhi ;; high pointer (end of unread bytes)
250 rbuf-fill ;; procedure to read bytes into the read buffer
252 wbuf ;; byte write buffer (a u8vector)
253 wlo ;; low pointer (start of unwritten bytes)
254 whi ;; high pointer (end of unwritten bytes)
255 wbuf-drain ;; procedure to write bytes from the write buffer
258 (##define-macro (macro-byte-port? obj)
259 `(or (macro-byte-input-port? ,obj)
260 (macro-byte-output-port? ,obj)))
262 (##define-macro (macro-byte-input-port? obj)
263 `(macro-port-of-rkind? ,obj (macro-byte-kind)))
265 (##define-macro (macro-byte-output-port? obj)
266 `(macro-port-of-wkind? ,obj (macro-byte-kind)))
268 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
270 ;;; Representation of device ports.
272 (define-check-type device-input-port 'device-input-port
273 macro-device-input-port?)
274 (define-check-type device-output-port 'device-output-port
275 macro-device-output-port?)
277 (define-type-of-byte-port device-port
278 id: b4fa842f-5da6-43b6-b447-d0b0348ae962
279 type-exhibitor: macro-type-device-port
280 constructor: macro-make-device-port
281 implementer: implement-type-device-port
287 extender: define-type-of-device-port
289 rdevice-condvar ;; device condvar from which bytes are read
290 wdevice-condvar ;; device condvar to which bytes are written
291 name ;; name of device
294 (##define-macro (macro-device-input-port? obj)
295 `(macro-port-of-rkind? ,obj (macro-device-kind)))
297 (##define-macro (macro-device-output-port? obj)
298 `(macro-port-of-wkind? ,obj (macro-device-kind)))
300 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
302 ;;; Representation of vector, string and u8vector ports.
305 (define-type-of-port vector-port
306 id: 2fb9e1fc-693b-455f-94a2-70c617a304d1
307 type-exhibitor: macro-type-vector-port
308 constructor: macro-make-vector-port
309 implementer: implement-type-vector-port
315 extender: define-type-of-vector-port
332 (define-check-type vector-input-port 'vector-input-port
333 macro-vector-input-port?)
334 (define-check-type vector-output-port 'vector-output-port
335 macro-vector-output-port?)
337 (##define-macro (macro-vector-input-port? obj)
338 `(macro-port-of-rkind? ,obj (macro-vector-kind)))
340 (##define-macro (macro-vector-output-port? obj)
341 `(macro-port-of-wkind? ,obj (macro-vector-kind)))
343 (define-type-of-character-port string-port
344 id: 81e73361-b03c-4889-9d02-e340e3309934
345 type-exhibitor: macro-type-string-port
346 constructor: macro-make-string-port
347 implementer: implement-type-string-port
353 extender: define-type-of-string-port
363 (define-check-type string-input-port 'string-input-port
364 macro-string-input-port?)
365 (define-check-type string-output-port 'string-output-port
366 macro-string-output-port?)
368 (##define-macro (macro-string-input-port? obj)
369 `(macro-port-of-rkind? ,obj (macro-string-kind)))
371 (##define-macro (macro-string-output-port? obj)
372 `(macro-port-of-wkind? ,obj (macro-string-kind)))
374 (define-type-of-byte-port u8vector-port
375 id: 04c1b0ae-b11f-4815-b206-ce01648675bd
376 type-exhibitor: macro-type-u8vector-port
377 constructor: macro-make-u8vector-port
378 implementer: implement-type-u8vector-port
384 extender: define-type-of-u8vector-port
394 (define-check-type u8vector-input-port 'u8vector-input-port
395 macro-u8vector-input-port?)
396 (define-check-type u8vector-output-port 'u8vector-output-port
397 macro-u8vector-output-port?)
399 (##define-macro (macro-u8vector-input-port? obj)
400 `(macro-port-of-rkind? ,obj (macro-u8vector-kind)))
402 (##define-macro (macro-u8vector-output-port? obj)
403 `(macro-port-of-wkind? ,obj (macro-u8vector-kind)))
405 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
407 ;;; Representation of file device ports.
409 (define-check-type file-port 'file-port
412 (##define-macro (macro-file-port? obj)
413 `(##port-of-kind? ,obj (macro-file-kind)))
415 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
417 ;;; Representation of tty device ports.
419 (define-check-type tty-port 'tty-port
422 (##define-macro (macro-tty-port? obj)
423 `(##port-of-kind? ,obj (macro-tty-kind)))
425 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
427 ;;; Representation of process device ports.
429 (define-check-type process-port 'process-port
432 (##define-macro (macro-process-port? obj)
433 `(##port-of-kind? ,obj (macro-process-kind)))
435 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
437 ;;; Representation of host-info objects.
439 (define-library-type host-info
440 id: e3dc833e-a176-42c1-bdc0-76a6c4b302f8
444 (name printable: read-only:)
445 (aliases printable: read-only:)
446 (addresses printable: read-only:)
449 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
451 ;;; Representation of service-info objects.
453 (define-library-type service-info
454 id: 177749b2-beb0-4670-9ab2-4b9c01b54c1d
458 (name printable: read-only:)
459 (aliases printable: read-only:)
460 (port-number printable: read-only:)
461 (protocol printable: read-only:)
464 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
466 ;;; Representation of protocol-info objects.
468 (define-library-type protocol-info
469 id: ffc668b5-2146-42b7-ab11-7d91641f2124
473 (name printable: read-only:)
474 (aliases printable: read-only:)
475 (number printable: read-only:)
478 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
480 ;;; Representation of network-info objects.
482 (define-library-type network-info
483 id: ce2e418b-96c7-4562-9cb6-419ec113704e
487 (name printable: read-only:)
488 (aliases printable: read-only:)
489 (number printable: read-only:)
492 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
494 ;;; Representation of socket-info objects.
496 (define-library-type socket-info
497 id: 837d9768-9d27-455e-ac65-5ae59f43f79e
501 (family printable: read-only:)
502 (port-number printable: read-only:)
503 (address printable: read-only:)
506 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
508 ;;; Representation of address-info objects.
510 (define-library-type address-info
511 id: f165f359-8685-48da-bc99-f38827ad8af9
515 (family printable: read-only:)
516 (socket-type printable: read-only:)
517 (protocol printable: read-only:)
518 (socket-info printable: read-only:)
521 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
523 ;;; Representation of TCP client device ports.
525 (define-check-type tcp-client-port 'tcp-client-port
526 macro-tcp-client-port?)
528 (##define-macro (macro-tcp-client-port? obj)
529 `(##port-of-kind? ,obj (macro-tcp-client-kind)))
531 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
533 ;;; Representation of TCP server ports.
535 (define-type-of-port tcp-server-port
536 id: 42696abb-6729-4637-99de-cef7d3a230ae
537 type-exhibitor: macro-type-tcp-server-port
538 constructor: macro-make-tcp-server-port
539 implementer: implement-type-tcp-server-port
545 extender: define-type-of-tcp-server-port
551 (define-check-type tcp-server-port (macro-type-tcp-server-port)
552 macro-tcp-server-port?)
554 (##define-macro (macro-tcp-server-port? obj)
555 `(##port-of-kind? ,obj (macro-tcp-server-kind)))
557 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
559 ;;; Representation of pipe device ports.
561 (define-check-type pipe-port 'pipe-port
564 (##define-macro (macro-pipe-port? obj)
565 `(##port-of-kind? ,obj (macro-pipe-kind)))
567 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
569 ;;; Representation of serial device ports.
571 (define-check-type serial-port 'serial-port
574 (##define-macro (macro-serial-port? obj)
575 `(##port-of-kind? ,obj (macro-serial-kind)))
577 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
579 ;;; Representation of directory ports.
581 (define-type-of-port directory-port
582 id: deebf606-97e4-4d34-8fed-b9e5468851b9
583 type-exhibitor: macro-type-directory-port
584 constructor: macro-make-directory-port
585 implementer: implement-type-directory-port
591 extender: define-type-of-directory-port
597 (define-check-type directory-port 'directory-port
598 macro-directory-port?)
600 (##define-macro (macro-directory-port? obj)
601 `(##port-of-kind? ,obj (macro-directory-kind)))
603 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
605 ;;; Representation of event queue ports.
607 (define-type-of-port event-queue-port
608 id: 59109ed7-6339-4c6e-8bc2-f52e9c91b9f5
609 type-exhibitor: macro-type-event-queue-port
610 constructor: macro-make-event-queue-port
611 implementer: implement-type-event-queue-port
617 extender: define-type-of-event-queue-port
623 (define-check-type event-queue-port 'event-queue-port
624 macro-event-queue-port?)
626 (##define-macro (macro-event-queue-port? obj)
627 `(##port-of-kind? ,obj (macro-event-queue-kind)))
629 ;;; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
631 ;;; Representation of timer ports.
633 (define-check-type timer-port 'timer-port
636 (##define-macro (macro-timer-port? obj)
637 `(##port-of-kind? ,obj (macro-timer-kind)))
639 ;;;----------------------------------------------------------------------------
641 ;;; Representation of port mutexes.
643 (##define-macro (macro-make-port-mutex)
646 (##define-macro (macro-port-mutex-lock! port)
647 `(macro-mutex-lock! (macro-port-mutex ,port) #f (macro-current-thread)))
649 (##define-macro (macro-port-mutex-unlock! port)
650 `(macro-mutex-unlock! (macro-port-mutex ,port)))
652 (##define-macro (macro-port-mutex-unlocked-not-abandoned-and-not-multiprocessor? port)
653 `(macro-mutex-unlocked-not-abandoned-and-not-multiprocessor? (macro-port-mutex ,port)))
655 ;;;----------------------------------------------------------------------------
657 ;;; Representation of port settings.
659 (define-type psettings
660 id: 0b02934e-7c23-4f9e-a629-0eede16e6987
661 type-exhibitor: macro-type-psettings
662 constructor: macro-make-psettings
663 implementer: implement-type-psettings
698 (define-type psettings-options
699 id: edb28923-9aa0-4c55-9756-f1a37136f727
700 type-exhibitor: macro-type-psettings-options
701 constructor: macro-make-psettings-options
702 implementer: implement-type-psettings-options
716 (##define-macro (macro-default-readtable) #f)
718 (##define-macro (macro-char-encoding-shift) 1)
719 (##define-macro (macro-char-encoding-range) 32)
720 (##define-macro (macro-default-char-encoding) 0)
721 (##define-macro (macro-char-encoding-ASCII) 1)
722 (##define-macro (macro-char-encoding-ISO-8859-1) 2)
723 (##define-macro (macro-char-encoding-UTF-8) 3)
724 (##define-macro (macro-char-encoding-UTF-16) 4)
725 (##define-macro (macro-char-encoding-UTF-16BE) 5)
726 (##define-macro (macro-char-encoding-UTF-16LE) 6)
727 (##define-macro (macro-char-encoding-UTF-fallback-ASCII) 7)
728 (##define-macro (macro-char-encoding-UTF-fallback-ISO-8859-1) 8)
729 (##define-macro (macro-char-encoding-UTF-fallback-UTF-8) 9)
730 (##define-macro (macro-char-encoding-UTF-fallback-UTF-16) 10)
731 (##define-macro (macro-char-encoding-UTF-fallback-UTF-16BE) 11)
732 (##define-macro (macro-char-encoding-UTF-fallback-UTF-16LE) 12)
733 (##define-macro (macro-char-encoding-UCS-2) 13)
734 (##define-macro (macro-char-encoding-UCS-2BE) 14)
735 (##define-macro (macro-char-encoding-UCS-2LE) 15)
736 (##define-macro (macro-char-encoding-UCS-4) 16)
737 (##define-macro (macro-char-encoding-UCS-4BE) 17)
738 (##define-macro (macro-char-encoding-UCS-4LE) 18)
739 (##define-macro (macro-char-encoding-wchar) 19)
740 (##define-macro (macro-char-encoding-native) 20)
742 (##define-macro (macro-char-encoding-UTF)
743 `(macro-char-encoding-UTF-fallback-UTF-8))
745 (##define-macro (macro-char-encoding-errors-shift) 32)
746 (##define-macro (macro-char-encoding-errors-range) 4)
747 (##define-macro (macro-default-char-encoding-errors) 0)
748 (##define-macro (macro-char-encoding-errors-on) 1)
749 (##define-macro (macro-char-encoding-errors-off) 2)
751 (##define-macro (macro-eol-encoding-shift) 128)
752 (##define-macro (macro-eol-encoding-range) 4)
753 (##define-macro (macro-default-eol-encoding) 0)
754 (##define-macro (macro-eol-encoding-lf) 1)
755 (##define-macro (macro-eol-encoding-cr) 2)
756 (##define-macro (macro-eol-encoding-crlf) 3)
758 (##define-macro (macro-buffering-shift) 512)
759 (##define-macro (macro-buffering-range) 4)
760 (##define-macro (macro-default-buffering) 0)
761 (##define-macro (macro-no-buffering) 1)
762 (##define-macro (macro-line-buffering) 2)
763 (##define-macro (macro-full-buffering) 3)
765 (##define-macro (macro-unbuffered? options)
766 `(##fixnum.< (##fixnum.bitwise-and ,options 2047) 1024))
768 (##define-macro (macro-fully-buffered? options)
769 `(##not (##fixnum.< (##fixnum.bitwise-and ,options 2047) 1536)))
771 (##define-macro (macro-decode-state-shift) 2048)
772 (##define-macro (macro-decode-state-range) 4)
773 (##define-macro (macro-decode-state-none) 0)
774 (##define-macro (macro-decode-state-lf) 1)
775 (##define-macro (macro-decode-state-cr) 2)
777 (##define-macro (macro-open-state-shift) 8192)
778 (##define-macro (macro-open-state-range) 2)
779 (##define-macro (macro-open-state-open) 0)
780 (##define-macro (macro-open-state-closed) 1)
782 (##define-macro (macro-closed? options)
783 `(##not (##fixnum.= (##fixnum.bitwise-and ,options 8192) 0)))
785 (##define-macro (macro-close! options)
786 `(##fixnum.bitwise-ior ,options 8192))
788 (##define-macro (macro-unclose! options)
789 `(##fixnum.bitwise-and ,options -8193))
791 (##define-macro (macro-permanent-close-shift) 16384)
792 (##define-macro (macro-permanent-close-range) 2)
793 (##define-macro (macro-permanent-close-no) 0)
794 (##define-macro (macro-permanent-close-yes) 1)
796 (##define-macro (macro-perm-close? options)
797 `(##not (##fixnum.= (##fixnum.bitwise-and ,options 16384) 0)))
799 (##define-macro (macro-direction-shift) 16)
800 (##define-macro (macro-direction-in) 1)
801 (##define-macro (macro-direction-out) 2)
802 (##define-macro (macro-direction-inout) 3)
804 (##define-macro (macro-default-path) #f)
806 (##define-macro (macro-default-init) #f)
808 (##define-macro (macro-default-arguments) ''())
810 (##define-macro (macro-default-environment) #f)
812 (##define-macro (macro-default-directory) #f)
814 (##define-macro (macro-append-shift) 8)
815 (##define-macro (macro-no-append) 0)
816 (##define-macro (macro-append) 1)
817 (##define-macro (macro-default-append) 2)
819 (##define-macro (macro-create-shift) 2)
820 (##define-macro (macro-no-create) 0)
821 (##define-macro (macro-maybe-create) 1)
822 (##define-macro (macro-create) 2)
823 (##define-macro (macro-default-create) 3)
825 (##define-macro (macro-truncate-shift) 1)
826 (##define-macro (macro-no-truncate) 0)
827 (##define-macro (macro-truncate) 1)
828 (##define-macro (macro-default-truncate) 2)
830 (##define-macro (macro-default-permissions) -1)
832 (##define-macro (macro-default-output-width) -1)
834 (##define-macro (macro-permanent-close) 1)
835 (##define-macro (macro-no-permanent-close) 0)
836 (##define-macro (macro-default-permanent-close) `(macro-permanent-close))
838 (##define-macro (macro-stdin-from-port) 1)
839 (##define-macro (macro-stdin-unchanged) 0)
840 (##define-macro (macro-default-stdin-redir) `(macro-stdin-from-port))
842 (##define-macro (macro-stdout-to-port) 1)
843 (##define-macro (macro-stdout-unchanged) 0)
844 (##define-macro (macro-default-stdout-redir) `(macro-stdout-to-port))
846 (##define-macro (macro-stderr-to-port) 1)
847 (##define-macro (macro-stderr-unchanged) 0)
848 (##define-macro (macro-default-stderr-redir) `(macro-stderr-unchanged))
850 (##define-macro (macro-pseudo-term) 1)
851 (##define-macro (macro-no-pseudo-term) 0)
852 (##define-macro (macro-default-pseudo-term) `(macro-no-pseudo-term))
854 (##define-macro (macro-show-console) 1)
855 (##define-macro (macro-no-show-console) 0)
856 (##define-macro (macro-default-show-console) `(macro-show-console))
858 (##define-macro (macro-default-server-address) `'#u8(127 0 0 1))
860 (##define-macro (macro-default-port-number) #f)
862 (##define-macro (macro-socket-type-TCP) 0)
863 (##define-macro (macro-socket-type-UDP) 1)
864 (##define-macro (macro-socket-type-RAW) 2)
865 (##define-macro (macro-default-socket-type) `(macro-socket-type-TCP))
867 (##define-macro (macro-coalesce) 1)
868 (##define-macro (macro-no-coalesce) 0)
869 (##define-macro (macro-default-coalesce) `(macro-coalesce))
871 (##define-macro (macro-keep-alive) 1)
872 (##define-macro (macro-no-keep-alive) 0)
873 (##define-macro (macro-default-keep-alive) `(macro-no-keep-alive))
875 (##define-macro (macro-broadcast) 1)
876 (##define-macro (macro-no-broadcast) 0)
877 (##define-macro (macro-default-broadcast) `(macro-no-broadcast))
879 (##define-macro (macro-default-backlog) 128)
881 (##define-macro (macro-reuse-address) 1)
882 (##define-macro (macro-no-reuse-address) 0)
883 (##define-macro (macro-default-reuse-address) `(macro-reuse-address))
885 (##define-macro (macro-ignore-hidden) 2)
886 (##define-macro (macro-ignore-dot-and-dot-dot) 1)
887 (##define-macro (macro-ignore-nothing) 0)
888 (##define-macro (macro-default-ignore-hidden) `(macro-ignore-hidden))
890 ;;;----------------------------------------------------------------------------
892 ;;; Representation of write environments.
894 ;; A writeenv structure maintains the "write environment" throughout
895 ;; the writing of a Scheme datum. It includes the write style
896 ;; (display, write, pretty-print, mark), the port on which to write,
897 ;; the readtable, the marktable (for detecting cycles), the force flag,
898 ;; the pretty-print width, the number of closing parentheses to follow
899 ;; the datum, the current nesting level, and the character count limit.
901 (define-type writeenv
902 id: f5cfcf78-bba4-4140-9aa0-1a136c50d36b
903 type-exhibitor: macro-type-writeenv
904 constructor: macro-make-writeenv
905 implementer: implement-type-writeenv
923 ;;;----------------------------------------------------------------------------
925 ;;; Representation of read environments.
927 ;; A readenv structure maintains the "read environment" throughout the
928 ;; reading of a Scheme datum. It includes the port from which to read,
929 ;; the readtable, the wrap and unwrap procedures, the table of labels
930 ;; (i.e. "#n#"), and the position where the currently being read datum
934 id: edd21ef2-ee48-407f-a9a9-c1c361078e55
935 type-exhibitor: macro-type-readenv
936 constructor: macro-make-readenv
937 implementer: implement-type-readenv
953 (##define-macro (macro-readenv-wrap re x)
956 ((macro-readenv-wrapper re) re x)))
958 (##define-macro (macro-readenv-unwrap re x)
961 ((macro-readenv-unwrapper re) re x)))
963 ;;;----------------------------------------------------------------------------
965 ;;; Generic char port procedures.
967 (##define-macro (macro-peek-char port)
970 (##declare (not interrupts-enabled))
972 ;; try to get exclusive access to port and if successful perform
975 (if (macro-port-mutex-unlocked-not-abandoned-and-not-multiprocessor? port)
977 (let ((char-rlo (macro-character-port-rlo port))
978 (char-rhi (macro-character-port-rhi port)))
979 (if (##fixnum.< char-rlo char-rhi)
981 ;; the next character is in the character read buffer
983 (##string-ref (macro-character-port-rbuf port) char-rlo)
985 ;; more characters are needed, do this out-of-line
988 (##declare (interrupts-enabled))
989 (##peek-char port))))
991 ;; couldn't easily get exclusive access to port, handle this out-of-line
994 (##declare (interrupts-enabled))
995 (##peek-char port)))))
997 (##define-macro (macro-read-char port)
1000 (##declare (not interrupts-enabled))
1002 ;; try to get exclusive access to port and if successful perform
1005 (if (macro-port-mutex-unlocked-not-abandoned-and-not-multiprocessor? port)
1007 (let ((char-rlo (macro-character-port-rlo port))
1008 (char-rhi (macro-character-port-rhi port)))
1009 (if (##fixnum.< char-rlo char-rhi)
1011 ;; the next character is in the character read buffer
1013 (let ((c (##string-ref (macro-character-port-rbuf port) char-rlo)))
1014 (if (##not (##char=? c #\newline))
1016 ;; frequent simple case, just advance rlo
1019 (macro-character-port-rlo-set! port (##fixnum.+ char-rlo 1))
1022 ;; end-of-line processing is complex, so do it out-of-line
1025 (##declare (interrupts-enabled))
1026 (##read-char port))))
1028 ;; more characters are needed, do this out-of-line
1031 (##declare (interrupts-enabled))
1032 (##read-char port))))
1034 ;; couldn't easily get exclusive access to port, handle this out-of-line
1037 (##declare (interrupts-enabled))
1038 (##read-char port)))))
1040 (##define-macro (macro-write-char c port)
1044 (##declare (not interrupts-enabled))
1046 ;; try to get exclusive access to port and if successful perform
1049 (if (and (##not (##char=? c #\newline))
1050 (macro-port-mutex-unlocked-not-abandoned-and-not-multiprocessor? port))
1052 (let ((char-wbuf (macro-character-port-wbuf port))
1053 (char-whi+1 (##fixnum.+ (macro-character-port-whi port) 1)))
1054 (if (##fixnum.< char-whi+1 (##string-length char-wbuf))
1056 ;; adding this character would not make the character write
1057 ;; buffer full, so add character and increment whi
1060 (##string-set! char-wbuf (##fixnum.- char-whi+1 1) c)
1061 (macro-character-port-whi-set! port char-whi+1)
1064 ;; the character write buffer would become full, so handle
1068 (##declare (interrupts-enabled))
1069 (##write-char c port))))
1071 ;; end-of-line processing is needed or exclusive access to port
1072 ;; cannot be obtained easily, so handle this out-of-line
1075 (##declare (interrupts-enabled))
1076 (##write-char c port)))))
1078 ;;;----------------------------------------------------------------------------
1080 ;;; Representation of readtables.
1082 (define-type readtable
1083 id: bebee95d-0da2-401d-a33a-c1afc75b9e43
1084 type-exhibitor: macro-type-readtable
1085 constructor: macro-make-readtable
1086 implementer: implement-type-readtable
1091 (case-conversion? unprintable: read-write:)
1092 (keywords-allowed? unprintable: read-write:)
1093 (escaped-char-table unprintable: read-write:)
1094 (named-char-table unprintable: read-write:)
1095 (sharp-bang-table unprintable: read-write:)
1096 (char-delimiter?-table unprintable: read-write:)
1097 (char-handler-table unprintable: read-write:)
1098 (char-sharp-handler-table unprintable: read-write:)
1099 (max-unescaped-char unprintable: read-write:)
1100 (escape-ctrl-chars? unprintable: read-write:)
1101 (sharing-allowed? unprintable: read-write:)
1102 (eval-allowed? unprintable: read-write:)
1103 (write-extended-read-macros? unprintable: read-write:)
1104 (write-cdr-read-macros? unprintable: read-write:)
1105 (max-write-level unprintable: read-write:)
1106 (max-write-length unprintable: read-write:)
1107 (pretty-print-formats unprintable: read-write:)
1108 (quote-keyword unprintable: read-write:)
1109 (quasiquote-keyword unprintable: read-write:)
1110 (unquote-keyword unprintable: read-write:)
1111 (unquote-splicing-keyword unprintable: read-write:)
1112 (sharp-quote-keyword unprintable: read-write:)
1113 (sharp-quasiquote-keyword unprintable: read-write:)
1114 (sharp-unquote-keyword unprintable: read-write:)
1115 (sharp-unquote-splicing-keyword unprintable: read-write:)
1116 (sharp-num-keyword unprintable: read-write:)
1117 (sharp-seq-keyword unprintable: read-write:)
1118 (paren-keyword unprintable: read-write:)
1119 (bracket-keyword unprintable: read-write:)
1120 (brace-keyword unprintable: read-write:)
1121 (angle-keyword unprintable: read-write:)
1122 (start-syntax unprintable: read-write:)
1123 (six-type? unprintable: read-write:)
1124 (r6rs-compatible-read? unprintable: read-write:)
1125 (r6rs-compatible-write? unprintable: read-write:)
1126 (here-strings-allowed? unprintable: read-write:)
1129 (define-check-type readtable (macro-type-readtable)
1132 ;;;----------------------------------------------------------------------------
1134 ;;; Representation of language specs.
1136 (##define-macro (macro-language-name x) `(##vector-ref ,x 0))
1137 (##define-macro (macro-language-case-conversion? x) `(##vector-ref ,x 1))
1138 (##define-macro (macro-language-keywords-allowed? x) `(##vector-ref ,x 2))
1139 (##define-macro (macro-language-start-syntax x) `(##vector-ref ,x 3))
1140 (##define-macro (macro-language-srfi-22? x) `(##vector-ref ,x 4))
1142 ;;;============================================================================