source: branches/0.22.x/abcl/doc/design/streams/design.rst

Last change on this file was 12410, checked in by vvoutilainen, 15 years ago

Add documentation for the streams.

File size: 2.4 KB
Line 
1==============================
2Design of lisp streams in ABCL
3==============================
4
5The previous design
6-------------------
7
8Previously, ABCL streams were built-in classes. This presented some problems for Gray streams,
9because ABCL CLOS can't use a built-in class as a base class, and Gray streams derive from
10a system-stream class. This was corrected by converting ABCL streams to be structure-objects
11instead of built-in classes, allowing CLOS to derive from the streams. There was, however, another
12problem that revealed a need to change the design in more drastic ways.
13
14The problem with the previous design
15~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16
17While converting the streams from built-in classes to structure-objects allowed derivation,
18the pretty printer still didn't work with Gray streams. Gray streams replace the system stream
19functions, saving the old function symbols so that they can be later invoked. The pretty printer,
20however, just replaces the stream functions, and calls the low-level primitives directly, thus
21bypassing Gray streams completely. The attached image portrays the problem, where pprint will,
22for example, invoke %stream-write-char, thus bypassing any methods that there may be for
23stream-write-char using Gray streams.
24
25.. image:: pprint-problem.png
26
27The planned future design and solution to the problem
28-----------------------------------------------------
29
30The solution to the problem is quite similar to how SBCL does its streams. First of all, the pretty printer will
31no longer replace stream functions. The stream functionality will be based on closures in the slots of
32the structure-object representing the stream, and those closures will invoke low-level i/o functions that
33are stream-specific.
34
35The pretty printer will just setup closures that will extract the underlying stream
36object from a pprint-wrapped stream, and invoke its low-level functions. If pprint wrapping isn't present,
37the slots will contain closures that directly invoke low-level functions of streams. Gray streams will
38still replace the stream functions, because it's capable of invoking the replaced functions.
39
40In addition to these changes, it is planned that the stream function primitives will be moved from the Stream
41java class to a streamfunctions library, allowing the stream functions to be written in lisp rather than java.
42There's an ongoing aspiration to increase the lisp/java code ratio of ABCL, and this new design allows for that.
43
44.. image:: pprint-solution.png
Note: See TracBrowser for help on using the repository browser.