diff options
author | Andy Wingo <wingo@pobox.com> | 2016-05-22 18:16:19 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2016-05-22 18:16:19 +0200 |
commit | fd17cf9f72bcfc1832775c848e678e695d05dbd8 (patch) | |
tree | e5e5decb36b46cfa5e436bfb8882b2de9fd5bf91 /libguile/ports-internal.h | |
parent | a4b06357f644c41188d4e3c555ff60c71631493f (diff) | |
download | guile-fd17cf9f72bcfc1832775c848e678e695d05dbd8.tar.gz |
Speed up port position access from Scheme
* libguile/ports-internal.h (scm_port_buffer_position):
(scm_port_position_line, scm_port_position_set_line):
(scm_port_position_column, scm_port_position_set_column): New
helpers.
(scm_t_port): Ports now hold position as a pair, so that Scheme can
access it easily.
(SCM_LINUM, SCM_COL, SCM_INCLINE, SCM_ZEROCOL, SCM_INCCOL)
(SCM_DECCOL, SCM_TABCOL): Remove.
* libguile/ports.c (make_port_buffer): Rename from
scm_c_make_port_buffer, make static, and take port as an argument so
we can initialize the position field.
(initialize_port_buffers): Adapt make_port_buffer change.
(scm_c_make_port_with_encoding): Initialize position.
(update_port_position): Rename from update_port_lf, and operate on
port position objects.
(scm_ungetc): Operate on port position objects.
(scm_setvbuf, scm_expand_port_read_buffer_x): Adapt to
make_port_buffer change.
(scm_lfwrite): Adapt to call update_port_position.
(scm_port_line, scm_set_port_line_x, scm_port_column)
(scm_set_port_column_x): Adapt to use port positions.
* libguile/ports.h (scm_c_make_port_buffer): Remove internal decl.
* libguile/read.c: Adapt to use scm_port_line / scm_port_column instead
of SCM_LINUM et al.
* module/ice-9/ports.scm (port-buffer-position, port-position-line)
(port-position-column, set-port-position-line!)
(set-port-position-column!): New accessors for the internals module.
* module/ice-9/sports.scm (advance-port-position!): Rename from
port-advance-position! and use the new accessors.
(read-char, port-fold-chars/iso-8859-1): Adapt to use
advance-port-position!.
Diffstat (limited to 'libguile/ports-internal.h')
-rw-r--r-- | libguile/ports-internal.h | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/libguile/ports-internal.h b/libguile/ports-internal.h index 38da49eb7..0bfda4f35 100644 --- a/libguile/ports-internal.h +++ b/libguile/ports-internal.h @@ -94,6 +94,7 @@ enum scm_port_buffer_field { SCM_PORT_BUFFER_FIELD_CUR, SCM_PORT_BUFFER_FIELD_END, SCM_PORT_BUFFER_FIELD_HAS_EOF_P, + SCM_PORT_BUFFER_FIELD_POSITION, SCM_PORT_BUFFER_FIELD_COUNT }; @@ -152,6 +153,39 @@ scm_port_buffer_set_has_eof_p (SCM buf, SCM has_eof_p) has_eof_p); } +/* The port position object is a pair that is referenced by the port. + To make things easier for Scheme port code, it is also referenced by + port buffers. */ +static inline SCM +scm_port_buffer_position (SCM buf) +{ + return SCM_SIMPLE_VECTOR_REF (buf, SCM_PORT_BUFFER_FIELD_POSITION); +} + +static inline SCM +scm_port_position_line (SCM position) +{ + return scm_car (position); +} + +static inline void +scm_port_position_set_line (SCM position, SCM line) +{ + scm_set_car_x (position, line); +} + +static inline SCM +scm_port_position_column (SCM position) +{ + return scm_cdr (position); +} + +static inline void +scm_port_position_set_column (SCM position, SCM column) +{ + scm_set_cdr_x (position, column); +} + static inline size_t scm_port_buffer_size (SCM buf) { @@ -290,8 +324,7 @@ struct scm_t_port { /* Source location information. */ SCM file_name; - long line_number; - int column_number; + SCM position; /* Port buffers. */ SCM read_buf; @@ -325,14 +358,6 @@ struct scm_t_port #define SCM_FILENAME(x) (SCM_PORT (x)->file_name) #define SCM_SET_FILENAME(x, n) (SCM_PORT (x)->file_name = (n)) -#define SCM_LINUM(x) (SCM_PORT (x)->line_number) -#define SCM_COL(x) (SCM_PORT (x)->column_number) - -#define SCM_INCLINE(port) do {SCM_LINUM (port) += 1; SCM_COL (port) = 0;} while (0) -#define SCM_ZEROCOL(port) do {SCM_COL (port) = 0;} while (0) -#define SCM_INCCOL(port) do {SCM_COL (port) += 1;} while (0) -#define SCM_DECCOL(port) do {if (SCM_COL (port) > 0) SCM_COL (port) -= 1;} while (0) -#define SCM_TABCOL(port) do {SCM_COL (port) += 8 - SCM_COL (port) % 8;} while (0) SCM_INTERNAL scm_t_iconv_descriptors * scm_i_port_iconv_descriptors (SCM port); |