This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
[PATCH] scsh block comment fix + small speedup
- To: guile at sourceware dot cygnus dot com
- Subject: [PATCH] scsh block comment fix + small speedup
- From: Chris Cramer <crayc at kiwi dot pyro dot net>
- Date: Sun, 30 Apr 2000 20:26:02 -0500
OK, I looked up the scsh manual, it says block comments start with
#! and end with !# on a line by itself. This patch fixes the block
comment parsing. While I was at it, I also rewrote scm_flush_ws() to
make regular comments parse faster. On my P90, it shaves .02 seconds
off guile startup time.
This patch is for 1.3.4, as I can't get the CVS version to compile
(autoconf problems). I believe it will apply to the CVS version without
any problem though.
--
C. Ray C. aka Christopher Cramer
crayc@pyro.net
http://www.pyro.net/~crayc/
diff -ru old/guile-1.3.4/libguile/ports.c guile-1.3.4/libguile/ports.c
--- old/guile-1.3.4/libguile/ports.c Mon Sep 20 16:34:57 1999
+++ guile-1.3.4/libguile/ports.c Sat Apr 29 19:43:25 2000
@@ -703,14 +703,9 @@
int c;
scm_port *pt = SCM_PTAB_ENTRY (port);
- if (pt->rw_active == SCM_PORT_WRITE)
- {
- /* may be marginally faster than calling scm_flush. */
- scm_ptobs[SCM_PTOBNUM (port)].flush (port);
- }
+ if (pt->rw_active == SCM_PORT_WRITE) scm_flush(port);
- if (pt->rw_random)
- pt->rw_active = SCM_PORT_READ;
+ if (pt->rw_random) pt->rw_active = SCM_PORT_READ;
if (pt->read_pos >= pt->read_end)
{
diff -ru old/guile-1.3.4/libguile/read.c guile-1.3.4/libguile/read.c
--- old/guile-1.3.4/libguile/read.c Mon Sep 20 16:34:57 1999
+++ guile-1.3.4/libguile/read.c Sun Apr 30 18:12:08 2000
@@ -55,6 +55,7 @@
#include "read.h"
+static void skip_scsh_block_comment (SCM port);
SCM_SYMBOL (scm_keyword_prefix, "prefix");
@@ -122,41 +123,102 @@
return SCM_CHARS (*tok_buf);
}
+/* yes, I know this is ugly -crc */
+#define fill_if_needed(x,bp,be,eoferr) \
+ if (bp >= be) \
+ { \
+ if (scm_fill_input (port) == EOF) \
+ { \
+ if (eoferr) \
+ scm_wta (SCM_UNDEFINED, "end of file in ", eoferr); \
+ return EOF; \
+ } \
+ bp = SCM_PTAB_ENTRY(x)->read_pos; \
+ be = SCM_PTAB_ENTRY(x)->read_end; \
+ }
+#define update_port(x,bp) \
+ SCM_PTAB_ENTRY(x)->read_pos = bp;
+#define fill_regardless(x,bp,be,eoferr) \
+ if (scm_fill_input (port) == EOF) \
+ { \
+ if (eoferr) \
+ scm_wta (SCM_UNDEFINED, "end of file in ", eoferr); \
+ return EOF; \
+ } \
+ bp = SCM_PTAB_ENTRY(x)->read_pos; \
+ be = SCM_PTAB_ENTRY(x)->read_end;
+
int
-scm_flush_ws (port, eoferr)
- SCM port;
- const char *eoferr;
+scm_flush_ws (SCM port, const char *eoferr)
{
- register int c;
+ int c;
+ scm_port *pt = SCM_PTAB_ENTRY (port);
+ const unsigned char *bp;
+ unsigned char *be;
+ int line;
+ int col;
+
+ bp = pt->read_pos;
+ be = pt->read_end;
+ line = SCM_LINUM (port);
+ col = SCM_COL (port);
+
while (1)
- switch (c = scm_getc (port))
- {
- case EOF:
- goteof:
- if (eoferr)
- scm_wta (SCM_UNDEFINED, "end of file in ", eoferr);
- return c;
- case ';':
- lp:
- switch (c = scm_getc (port))
- {
- case EOF:
- goto goteof;
- default:
- goto lp;
- case SCM_LINE_INCREMENTORS:
- break;
- }
- break;
- case SCM_LINE_INCREMENTORS:
- case SCM_SINGLE_SPACES:
- case '\t':
- break;
- default:
- return c;
- }
+ {
+ fill_if_needed(port,bp,be,eoferr)
+ switch (c = *bp++)
+ {
+ case ';':
+ /* only works if SCM_LINE_INCREMENTORS is '\n' */
+ fill_if_needed(port,bp,be,eoferr)
+ while ((bp = memchr(bp, '\n', be - bp)) == NULL)
+ {
+ fill_regardless(port,bp,be,eoferr)
+ }
+ bp++;
+ line++;
+ col = 0;
+ break;
+ case SCM_LINE_INCREMENTORS:
+ line++;
+ col = 0;
+ break;
+ case SCM_SINGLE_SPACES:
+ col++;
+ break;
+ case '\t':
+ col += 8 - col % 8;
+ break;
+ case '#':
+ fill_if_needed(port,bp,be,eoferr)
+ if (*bp++ == '!')
+ {
+ update_port(port,bp)
+ SCM_COL(port) = col + 2;
+ SCM_LINUM(port) = line;
+
+ skip_scsh_block_comment(port);
+
+ bp = pt->read_pos;
+ be = pt->read_end;
+ line = SCM_LINUM (port);
+ col = SCM_COL (port);
+ } else {
+ update_port(port,--bp)
+ SCM_COL(port) = col;
+ SCM_LINUM(port) = line;
+ return c;
+ }
+ break;
+ default:
+ update_port(port,bp)
+ SCM_COL(port) = col;
+ SCM_LINUM(port) = line;
+ return c;
+ }
+ }
}
@@ -242,8 +304,7 @@
newline/exclamation-point/sharp-sign/newline sequence. */
static void
-skip_scsh_block_comment (port)
- SCM port;
+skip_scsh_block_comment (SCM port)
{
/* Is this portable? Dear God, spare me from the non-eight-bit
characters. But is it tasteful? */
@@ -357,14 +418,6 @@
scm_ungetc (c, port);
c = '#';
goto num;
-
- case '!':
- /* start of a shell script. Parse as a block comment,
- terminated by !#, just like SCSH. */
- skip_scsh_block_comment (port);
- /* EOF is not an error here */
- c = scm_flush_ws (port, (char *)NULL);
- goto tryagain_no_flush_ws;
case '*':
j = scm_read_token (c, tok_buf, port, 0);
diff -ru old/guile-1.3.4/libguile/read.h guile-1.3.4/libguile/read.h
--- old/guile-1.3.4/libguile/read.h Sat Feb 6 04:30:48 1999
+++ guile-1.3.4/libguile/read.h Sun Apr 30 15:30:00 2000
@@ -53,6 +53,9 @@
* be incremented for the purposes of error reporting. This feature
* is only used for scheme code loaded from files.
*
+ * WARNING: if you change SCM_LINE_INCREMENTORS you will break
+ * scm_flush_ws() in read.c -crc
+ *
* SCM_WHITE_SPACES are other characters which should be treated like spaces
* in programs.
*/