Module: common-dylan-internals Author: Gail Zacharias Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND define open class (, ) constant slot stream-error-stream :: , required-init-keyword: stream:; end; // TODO: yuck. Would be nicer to just have a condition-to-string method.. // andrewa: note that then you need to update the runtime manager to // know about the new class too, it is simpler to rely on subclassing // . define method make (class :: subclass(), #rest args, #key stream :: , format-string, format-arguments = format-string & #[], #all-keys) => (error :: ) apply(next-method, class, stream: stream, format-string: format-string | "Condition %s for stream %s", format-arguments: format-arguments | vector(class, stream), args) end method make; define class () end class ; define method make (class == , #key stream :: ) => (error :: ) next-method(class, stream: stream, format-string: "End of stream %s", format-arguments: vector(stream)) end method make; define class () constant slot stream-error-sequence, required-init-keyword: sequence:; constant slot stream-error-count, required-init-keyword: count:; end class ; define class () constant slot stream-error-count, required-init-keyword: count:; end class ; define open generic stream-element-type (stream :: ) => (type :: ); define open generic open-file-stream (filename :: , #key, #all-keys) => (stream :: ); define open generic stream-open? (stream :: ) => (open? :: ); define method stream-open? (stream :: ) => (open? :: ); #t end method stream-open?; define open generic stream-at-end? (stream :: ) => (at-end? :: ); define open generic stream-size (stream :: ) => (size :: false-or()); define method stream-size (stream :: ) => (size :: singleton(#f)) #f end method stream-size; define open abstract class () end; define open generic stream-position (stream :: ) => (position); define open generic stream-position-setter (position, stream :: ) => (position :: ); define open generic adjust-stream-position (stream :: , delta, #key from) => (position); define open generic read-element (stream :: , #key on-end-of-stream) => (element); define open generic unread-element (stream :: , element) => (element); define open generic peek (stream :: , #key on-end-of-stream) => (element); define open generic read (stream :: , n :: , #key on-end-of-stream) => (sequence-or-eof); define method read (stream :: , n :: , #key on-end-of-stream = unsupplied()) => (elements) let elements = make(, size: n); if (supplied?(on-end-of-stream)) read-into!(stream, n, elements, on-end-of-stream: on-end-of-stream); else read-into!(stream, n, elements); end; elements end method read; define open generic read-into! (stream :: , n :: , sequence :: , #key start, on-end-of-stream) => (count); define method read-into! (stream :: , n :: , sequence :: , #key start = 0, on-end-of-stream = unsupplied()) => (count) let limit = min(n + start, sequence.size); iterate loop (i = start) if (i < limit) let elt = read-element(stream, on-end-of-stream: unfound()); if (found?(elt)) sequence[i] := elt; loop(i + 1); elseif (supplied?(on-end-of-stream)) i - start else signal(make(, stream: stream, count: i - start, // seems kinda redundant... sequence: copy-sequence(sequence, start: start, end: i))) end else i - start end if; end; end method read-into!; define open generic discard-input (stream :: ) => (); define method discard-input (stream :: ) => () #f end method discard-input; define open generic stream-input-available? (stream :: ) => (available? :: ); define open generic stream-contents (stream :: , #key clear-contents?) => (sequence :: ); define open generic stream-contents-as (type :: , stream :: , #key clear-contents?) => (sequence :: ); define open generic write-element (stream :: , element) => (); define open generic write (stream :: , elements :: , #key start, \end) => (); define method write (stream :: , elements :: , #key start: start-index = 0, end: end-index) => () for (i from start-index below end-index | elements.size) write-element(stream, elements[i]) end; #f end method write; define open generic force-output (stream :: , #key /* synchronize? :: */) => (); define method force-output (stream :: , #key synchronize? :: ) => () ignore(stream, synchronize?); end method force-output; define open generic wait-for-io-completion (stream :: ) => (); define method wait-for-io-completion (stream :: ) => () ignore(stream); end method wait-for-io-completion; define open generic synchronize-output (stream :: ) => (); define method synchronize-output (stream :: ) => () #f end method synchronize-output; define open generic discard-output (stream :: ) => (); define method discard-output (stream :: ) => () #f end method discard-output;