mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-03-08 22:30:23 -07:00
streams: rename common sequence stream accessors
SEQ_{INPUT,OUTPUT}* -> SEQ_STREAM*
Don't use IO_STREAM_ELT_TYPE in sequences and define SEQ_STREAM_ELT_TYPE
instread to avoid ambiguity.
This is a cleanup that signifies similarities between both objects.
This commit is contained in:
parent
37c3955180
commit
ea11e2c433
2 changed files with 49 additions and 44 deletions
|
|
@ -25,14 +25,14 @@
|
|||
static cl_index
|
||||
seq_in_read_byte8(cl_object strm, unsigned char *c, cl_index n)
|
||||
{
|
||||
cl_fixnum curr_pos = SEQ_INPUT_POSITION(strm);
|
||||
cl_fixnum curr_pos = SEQ_STREAM_POSITION(strm);
|
||||
cl_fixnum last = SEQ_INPUT_LIMIT(strm);
|
||||
cl_fixnum delta = last - curr_pos;
|
||||
if (delta > 0) {
|
||||
cl_object vector = SEQ_INPUT_VECTOR(strm);
|
||||
cl_object vector = SEQ_STREAM_VECTOR(strm);
|
||||
if (delta > n) delta = n;
|
||||
ecl_copy(c, vector->vector.self.bc + curr_pos, delta);
|
||||
SEQ_INPUT_POSITION(strm) += delta;
|
||||
SEQ_STREAM_POSITION(strm) += delta;
|
||||
return delta;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -42,29 +42,29 @@ static void
|
|||
seq_in_unread_char(cl_object strm, ecl_character c)
|
||||
{
|
||||
ecl_eformat_unread_char(strm, c);
|
||||
SEQ_INPUT_POSITION(strm) -= ecl_length(strm->stream.byte_stack);
|
||||
SEQ_STREAM_POSITION(strm) -= ecl_length(strm->stream.byte_stack);
|
||||
strm->stream.byte_stack = ECL_NIL;
|
||||
}
|
||||
|
||||
static void
|
||||
seq_in_unread_byte(cl_object strm, cl_object byte)
|
||||
{
|
||||
unlikely_if(SEQ_INPUT_POSITION(strm) <= 0) {
|
||||
unlikely_if(SEQ_STREAM_POSITION(strm) <= 0) {
|
||||
ecl_unread_error(strm);
|
||||
}
|
||||
SEQ_INPUT_POSITION(strm) -= 1;
|
||||
SEQ_STREAM_POSITION(strm) -= 1;
|
||||
}
|
||||
|
||||
#ifdef ecl_uint16_t
|
||||
static ecl_character
|
||||
seq_in_ucs2_read_char(cl_object strm)
|
||||
{
|
||||
cl_fixnum curr_pos = SEQ_INPUT_POSITION(strm);
|
||||
cl_fixnum curr_pos = SEQ_STREAM_POSITION(strm);
|
||||
cl_fixnum last = SEQ_INPUT_LIMIT(strm);
|
||||
if (curr_pos >= last) {
|
||||
return EOF;
|
||||
}
|
||||
cl_object vector = SEQ_INPUT_VECTOR(strm);
|
||||
cl_object vector = SEQ_STREAM_VECTOR(strm);
|
||||
ecl_character c = vector->vector.self.b16[curr_pos++];
|
||||
cl_object err;
|
||||
if (c >= 0xD800 && c <= 0xDBFF) {
|
||||
|
|
@ -79,7 +79,7 @@ seq_in_ucs2_read_char(cl_object strm)
|
|||
}
|
||||
c = ((c & 0x3FF) << 10) + (aux & 0x3FF) + 0x10000;
|
||||
}
|
||||
SEQ_INPUT_POSITION(strm) = curr_pos;
|
||||
SEQ_STREAM_POSITION(strm) = curr_pos;
|
||||
return c;
|
||||
cl_object code;
|
||||
DECODING_ERROR:
|
||||
|
|
@ -99,9 +99,9 @@ static void
|
|||
seq_in_ucs2_unread_char(cl_object strm, ecl_character c)
|
||||
{
|
||||
if (c >= 0x10000) {
|
||||
SEQ_INPUT_POSITION(strm) -= 2;
|
||||
SEQ_STREAM_POSITION(strm) -= 2;
|
||||
} else {
|
||||
SEQ_INPUT_POSITION(strm) -= 1;
|
||||
SEQ_STREAM_POSITION(strm) -= 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -110,26 +110,26 @@ seq_in_ucs2_unread_char(cl_object strm, ecl_character c)
|
|||
static ecl_character
|
||||
seq_in_ucs4_read_char(cl_object strm)
|
||||
{
|
||||
cl_fixnum curr_pos = SEQ_INPUT_POSITION(strm);
|
||||
cl_fixnum curr_pos = SEQ_STREAM_POSITION(strm);
|
||||
if (curr_pos >= SEQ_INPUT_LIMIT(strm)) {
|
||||
return EOF;
|
||||
}
|
||||
cl_object vector = SEQ_INPUT_VECTOR(strm);
|
||||
SEQ_INPUT_POSITION(strm) += 1;
|
||||
cl_object vector = SEQ_STREAM_VECTOR(strm);
|
||||
SEQ_STREAM_POSITION(strm) += 1;
|
||||
return vector->vector.self.b32[curr_pos];
|
||||
}
|
||||
|
||||
static void
|
||||
seq_in_ucs4_unread_char(cl_object strm, ecl_character c)
|
||||
{
|
||||
SEQ_INPUT_POSITION(strm) -= 1;
|
||||
SEQ_STREAM_POSITION(strm) -= 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
seq_in_listen(cl_object strm)
|
||||
{
|
||||
if (SEQ_INPUT_POSITION(strm) < SEQ_INPUT_LIMIT(strm))
|
||||
if (SEQ_STREAM_POSITION(strm) < SEQ_INPUT_LIMIT(strm))
|
||||
return ECL_LISTEN_AVAILABLE;
|
||||
else
|
||||
return ECL_LISTEN_EOF;
|
||||
|
|
@ -138,7 +138,7 @@ seq_in_listen(cl_object strm)
|
|||
static cl_object
|
||||
seq_in_get_position(cl_object strm)
|
||||
{
|
||||
return ecl_make_unsigned_integer(SEQ_INPUT_POSITION(strm));
|
||||
return ecl_make_unsigned_integer(SEQ_STREAM_POSITION(strm));
|
||||
}
|
||||
|
||||
static cl_object
|
||||
|
|
@ -153,7 +153,7 @@ seq_in_set_position(cl_object strm, cl_object pos)
|
|||
disp = SEQ_INPUT_LIMIT(strm);
|
||||
}
|
||||
}
|
||||
SEQ_INPUT_POSITION(strm) = disp;
|
||||
SEQ_STREAM_POSITION(strm) = disp;
|
||||
return ECL_T;
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +233,7 @@ make_sequence_input_stream(cl_object vector, cl_index istart, cl_index iend,
|
|||
}
|
||||
#ifdef ecl_uint16_t
|
||||
else if (ecl_aet_size[type] == 2 && external_format == @':ucs-2') {
|
||||
IO_STREAM_ELT_TYPE(strm) = @'character';
|
||||
SEQ_STREAM_ELT_TYPE(strm) = @'character';
|
||||
strm->stream.format = @':ucs-2';
|
||||
strm->stream.byte_size = 2*8;
|
||||
strm->stream.ops->read_char = seq_in_ucs2_read_char;
|
||||
|
|
@ -242,7 +242,7 @@ make_sequence_input_stream(cl_object vector, cl_index istart, cl_index iend,
|
|||
#endif
|
||||
#ifdef ecl_uint32_t
|
||||
else if (ecl_aet_size[type] == 4 && external_format == @':ucs-4') {
|
||||
IO_STREAM_ELT_TYPE(strm) = @'character';
|
||||
SEQ_STREAM_ELT_TYPE(strm) = @'character';
|
||||
strm->stream.format = @':ucs-4';
|
||||
strm->stream.byte_size = 4*8;
|
||||
strm->stream.ops->read_char = seq_in_ucs4_read_char;
|
||||
|
|
@ -252,8 +252,8 @@ make_sequence_input_stream(cl_object vector, cl_index istart, cl_index iend,
|
|||
else {
|
||||
FEerror("Illegal combination of external-format ~A and input vector ~A for MAKE-SEQUENCE-INPUT-STREAM.~%", 2, external_format, vector);
|
||||
}
|
||||
SEQ_INPUT_VECTOR(strm) = vector;
|
||||
SEQ_INPUT_POSITION(strm) = istart;
|
||||
SEQ_STREAM_VECTOR(strm) = vector;
|
||||
SEQ_STREAM_POSITION(strm) = istart;
|
||||
SEQ_INPUT_LIMIT(strm) = iend;
|
||||
return strm;
|
||||
}
|
||||
|
|
@ -277,9 +277,9 @@ make_sequence_input_stream(cl_object vector, cl_index istart, cl_index iend,
|
|||
static void
|
||||
seq_out_enlarge_vector(cl_object strm)
|
||||
{
|
||||
cl_object vector = SEQ_OUTPUT_VECTOR(strm);
|
||||
cl_object vector = SEQ_STREAM_VECTOR(strm);
|
||||
si_adjust_vector(vector, ecl_ash(ecl_make_fixnum(vector->vector.dim), 1));
|
||||
SEQ_OUTPUT_VECTOR(strm) = vector;
|
||||
SEQ_STREAM_VECTOR(strm) = vector;
|
||||
}
|
||||
|
||||
static cl_index
|
||||
|
|
@ -287,8 +287,8 @@ seq_out_write_byte8(cl_object strm, unsigned char *c, cl_index n)
|
|||
{
|
||||
AGAIN:
|
||||
{
|
||||
cl_object vector = SEQ_OUTPUT_VECTOR(strm);
|
||||
cl_fixnum curr_pos = SEQ_OUTPUT_POSITION(strm);
|
||||
cl_object vector = SEQ_STREAM_VECTOR(strm);
|
||||
cl_fixnum curr_pos = SEQ_STREAM_POSITION(strm);
|
||||
cl_fixnum last = vector->vector.dim;
|
||||
cl_fixnum delta = last - curr_pos;
|
||||
if (delta < n) {
|
||||
|
|
@ -296,7 +296,7 @@ seq_out_write_byte8(cl_object strm, unsigned char *c, cl_index n)
|
|||
goto AGAIN;
|
||||
}
|
||||
ecl_copy(vector->vector.self.bc + curr_pos, c, n);
|
||||
SEQ_OUTPUT_POSITION(strm) = curr_pos += n;
|
||||
SEQ_STREAM_POSITION(strm) = curr_pos += n;
|
||||
if (vector->vector.fillp < curr_pos)
|
||||
vector->vector.fillp = curr_pos;
|
||||
}
|
||||
|
|
@ -309,8 +309,8 @@ seq_out_ucs2_write_char(cl_object strm, ecl_character c)
|
|||
{
|
||||
AGAIN:
|
||||
{
|
||||
cl_object vector = SEQ_OUTPUT_VECTOR(strm);
|
||||
cl_fixnum curr_pos = SEQ_OUTPUT_POSITION(strm);
|
||||
cl_object vector = SEQ_STREAM_VECTOR(strm);
|
||||
cl_fixnum curr_pos = SEQ_STREAM_POSITION(strm);
|
||||
cl_fixnum n = (c >= 0x10000) ? 2 : 1;
|
||||
if (vector->vector.dim - curr_pos < n) {
|
||||
seq_out_enlarge_vector(strm);
|
||||
|
|
@ -323,7 +323,7 @@ seq_out_ucs2_write_char(cl_object strm, ecl_character c)
|
|||
} else {
|
||||
vector->vector.self.b16[curr_pos++] = c;
|
||||
}
|
||||
SEQ_OUTPUT_POSITION(strm) = curr_pos;
|
||||
SEQ_STREAM_POSITION(strm) = curr_pos;
|
||||
if (vector->vector.fillp < curr_pos)
|
||||
vector->vector.fillp = curr_pos;
|
||||
}
|
||||
|
|
@ -337,14 +337,14 @@ seq_out_ucs4_write_char(cl_object strm, ecl_character c)
|
|||
{
|
||||
AGAIN:
|
||||
{
|
||||
cl_object vector = SEQ_OUTPUT_VECTOR(strm);
|
||||
cl_fixnum curr_pos = SEQ_OUTPUT_POSITION(strm);
|
||||
cl_object vector = SEQ_STREAM_VECTOR(strm);
|
||||
cl_fixnum curr_pos = SEQ_STREAM_POSITION(strm);
|
||||
if (vector->vector.dim - curr_pos < 1) {
|
||||
seq_out_enlarge_vector(strm);
|
||||
goto AGAIN;
|
||||
}
|
||||
vector->vector.self.b32[curr_pos++] = c;
|
||||
SEQ_OUTPUT_POSITION(strm) = curr_pos;
|
||||
SEQ_STREAM_POSITION(strm) = curr_pos;
|
||||
if (vector->vector.fillp < curr_pos)
|
||||
vector->vector.fillp = curr_pos;
|
||||
}
|
||||
|
|
@ -355,13 +355,13 @@ seq_out_ucs4_write_char(cl_object strm, ecl_character c)
|
|||
static cl_object
|
||||
seq_out_get_position(cl_object strm)
|
||||
{
|
||||
return ecl_make_unsigned_integer(SEQ_OUTPUT_POSITION(strm));
|
||||
return ecl_make_unsigned_integer(SEQ_STREAM_POSITION(strm));
|
||||
}
|
||||
|
||||
static cl_object
|
||||
seq_out_set_position(cl_object strm, cl_object pos)
|
||||
{
|
||||
cl_object vector = SEQ_OUTPUT_VECTOR(strm);
|
||||
cl_object vector = SEQ_STREAM_VECTOR(strm);
|
||||
cl_fixnum disp;
|
||||
if (Null(pos)) {
|
||||
disp = vector->vector.fillp;
|
||||
|
|
@ -371,7 +371,7 @@ seq_out_set_position(cl_object strm, cl_object pos)
|
|||
disp = vector->vector.fillp;
|
||||
}
|
||||
}
|
||||
SEQ_OUTPUT_POSITION(strm) = disp;
|
||||
SEQ_STREAM_POSITION(strm) = disp;
|
||||
return ECL_T;
|
||||
}
|
||||
|
||||
|
|
@ -444,7 +444,7 @@ make_sequence_output_stream(cl_object vector, cl_object external_format)
|
|||
}
|
||||
#ifdef ecl_uint16_t
|
||||
else if (ecl_aet_size[type] == 2 && external_format == @':ucs-2') {
|
||||
IO_STREAM_ELT_TYPE(strm) = @'character';
|
||||
SEQ_STREAM_ELT_TYPE(strm) = @'character';
|
||||
strm->stream.format = @':ucs-2';
|
||||
strm->stream.byte_size = 2*8;
|
||||
strm->stream.ops->write_char = seq_out_ucs2_write_char;
|
||||
|
|
@ -452,7 +452,7 @@ make_sequence_output_stream(cl_object vector, cl_object external_format)
|
|||
#endif
|
||||
#ifdef ecl_uint32_t
|
||||
else if (ecl_aet_size[type] == 4 && external_format == @':ucs-4') {
|
||||
IO_STREAM_ELT_TYPE(strm) = @'character';
|
||||
SEQ_STREAM_ELT_TYPE(strm) = @'character';
|
||||
strm->stream.format = @':ucs-4';
|
||||
strm->stream.byte_size = 4*8;
|
||||
strm->stream.ops->write_char = seq_out_ucs4_write_char;
|
||||
|
|
@ -461,8 +461,8 @@ make_sequence_output_stream(cl_object vector, cl_object external_format)
|
|||
else {
|
||||
FEerror("Illegal combination of external-format ~A and output vector ~A for MAKE-SEQUENCE-OUTPUT-STREAM.~%", 2, external_format, vector);
|
||||
}
|
||||
SEQ_OUTPUT_VECTOR(strm) = vector;
|
||||
SEQ_OUTPUT_POSITION(strm) = vector->vector.fillp;
|
||||
SEQ_STREAM_VECTOR(strm) = vector;
|
||||
SEQ_STREAM_POSITION(strm) = vector->vector.fillp;
|
||||
return strm;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -506,28 +506,33 @@ write_char_increment_column(cl_object strm, ecl_character c)
|
|||
|
||||
#define ECL_FILE_STREAM_P(strm) \
|
||||
(ECL_ANSI_STREAM_P(strm) && (strm)->stream.mode < ecl_smm_synonym)
|
||||
|
||||
#define STRING_OUTPUT_STRING(strm) (strm)->stream.object0
|
||||
#define STRING_INPUT_STRING(strm) (strm)->stream.object0
|
||||
#define STRING_INPUT_POSITION(strm) (strm)->stream.int0
|
||||
#define STRING_INPUT_LIMIT(strm) (strm)->stream.int1
|
||||
|
||||
#define TWO_WAY_STREAM_INPUT(strm) (strm)->stream.object0
|
||||
#define TWO_WAY_STREAM_OUTPUT(strm) (strm)->stream.object1
|
||||
|
||||
#define SYNONYM_STREAM_SYMBOL(strm) (strm)->stream.object0
|
||||
#define SYNONYM_STREAM_STREAM(strm) ecl_symbol_value((strm)->stream.object0)
|
||||
#define BROADCAST_STREAM_LIST(strm) (strm)->stream.object0
|
||||
#define ECHO_STREAM_INPUT(strm) (strm)->stream.object0
|
||||
#define ECHO_STREAM_OUTPUT(strm) (strm)->stream.object1
|
||||
#define CONCATENATED_STREAM_LIST(strm) (strm)->stream.object0
|
||||
|
||||
#define IO_STREAM_FILE(strm) ((strm)->stream.file.stream)
|
||||
#define IO_STREAM_ELT_TYPE(strm) (strm)->stream.object0
|
||||
#define IO_STREAM_FILENAME(strm) (strm)->stream.object1
|
||||
|
||||
#define IO_FILE_DESCRIPTOR(strm) (strm)->stream.file.descriptor
|
||||
#define IO_FILE_ELT_TYPE(strm) (strm)->stream.object0
|
||||
#define IO_FILE_FILENAME(strm) (strm)->stream.object1
|
||||
#define SEQ_OUTPUT_VECTOR(strm) (strm)->stream.object1
|
||||
#define SEQ_OUTPUT_POSITION(strm) (strm)->stream.int0
|
||||
#define SEQ_INPUT_VECTOR(strm) (strm)->stream.object1
|
||||
#define SEQ_INPUT_POSITION(strm) (strm)->stream.int0
|
||||
|
||||
#define SEQ_STREAM_ELT_TYPE(strm) (strm)->stream.object0
|
||||
#define SEQ_STREAM_VECTOR(strm) (strm)->stream.object1
|
||||
#define SEQ_STREAM_POSITION(strm) (strm)->stream.int0
|
||||
#define SEQ_INPUT_LIMIT(strm) (strm)->stream.int1
|
||||
|
||||
#ifndef HAVE_FSEEKO
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue