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