## string-out-stream.pkg
#
# The basis seems to be missing a string (out)stream type.
# This is it.
#
# -- Allen Leung.
# Compiled by:
#
src/lib/compiler/back/low/lib/lib.lib### "Then anyone who leaves behind him a written manual,
### and likewise anyone who receives it, in the belief
### that such writing will be clear and certain,
### must be exceedingly simple-minded."
###
### -- Plato
stipulate
package fil = file__premicrothread; # file__premicrothread is from
src/lib/std/src/posix/file--premicrothread.pkg package iox = io_exceptions; # io_exceptions is from
src/lib/std/src/io/io-exceptions.pkg package lst = list; # list is from
src/lib/std/src/list.pkg package rcs = vector_slice_of_chars; # vector_slice_of_chars is from
src/lib/std/src/vector-slice-of-chars.pkg package str = string; # string is from
src/lib/std/string.pkg package tbi = winix_base_text_file_io_driver_for_posix__premicrothread; # winix_base_text_file_io_driver_for_posix__premicrothread is from
src/lib/std/src/io/winix-base-text-file-io-driver-for-posix--premicrothread.pkg package wcs = rw_vector_slice_of_chars; # rw_vector_slice_of_chars is from
src/lib/std/src/rw-vector-slice-of-chars.pkgherein
# This package is referenced (only) in:
#
#
src/lib/compiler/back/low/display/lowhalf-format-instruction-g.pkg #
src/lib/compiler/back/low/mcg/machcode-controlflow-graph-g.pkg #
src/lib/compiler/back/low/intel32/treecode/floating-point-code-intel32-g.pkg #
package string_outstream
: String_Outstream # String_Outstream is from
src/lib/compiler/back/low/library/string-out-stream.api {
Streambuf = Ref( List( String ) );
fun make_stream_buf ()
=
REF [] : Streambuf;
fun get_string (REF s)
=
str::cat (lst::reverse s);
fun set_string (r, s)
=
r := [s];
fun open_string_out buffer
=
output_stream
where
fun write_vector strings
=
{ buffer := rcs::to_vector strings ! *buffer;
#
rcs::length strings;
};
fun write_rw_vector strings
=
{ buffer := wcs::to_vector strings ! *buffer;
#
wcs::length strings;
};
stream_writer
=
tbi::FILEWRITER
{
filename => "<string stream>",
best_io_quantum => 512,
#
write_vector => THE write_vector,
write_rw_vector => THE write_rw_vector,
#
blockx => NULL,
can_output => NULL,
#
get_file_position => NULL,
set_file_position => NULL,
#
end_file_position => NULL,
verify_file_position => NULL,
#
close => \\ () = (),
io_descriptor => NULL
};
output_stream
=
fil::make_outstream
(fil::pur::make_outstream (stream_writer, iox::NO_BUFFERING));
end;
};
end;