From ce1c72973db7b80b381333b9daa60f6f288b8c28 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Thu, 13 Mar 2025 12:47:54 +0000 Subject: [PATCH] Defensive commit before experimenting with code::blocks --- src/arith/peano.h | 4 ++++ src/io/read.c | 19 ++++++++++--------- src/io/read.h | 9 +++++++++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/arith/peano.h b/src/arith/peano.h index 3076391..b1d3087 100644 --- a/src/arith/peano.h +++ b/src/arith/peano.h @@ -14,6 +14,10 @@ /** * The maximum value we will allow in an integer cell. + * + * NOTE: 20250312 this is 2^60. WHY? Given that we're using the sign bit + * inside the int64 record, we only have 63 value bits; but why did I decide + * not to use all 63? */ #define MAX_INTEGER ((__int128_t)0x0fffffffffffffffL) diff --git a/src/io/read.c b/src/io/read.c index df0735b..bf92f35 100644 --- a/src/io/read.c +++ b/src/io/read.c @@ -83,7 +83,7 @@ struct cons_pointer read_path( URL_FILE * input, wint_t initial, prefix = c_string_to_lisp_symbol( L"oblist" ); break; case '$': - case L'§': + case LSESSION: prefix = c_string_to_lisp_symbol( L"session" ); break; } @@ -245,7 +245,7 @@ struct cons_pointer read_continuation( struct stack_frame *frame, } break; case '$': - case L'§': + case LSESSION: result = read_path( input, c, NIL ); break; default: @@ -298,9 +298,9 @@ struct cons_pointer read_number( struct stack_frame *frame, initial ); for ( c = initial; iswdigit( c ) - || c == L'.' || c == L'/' || c == L','; c = url_fgetwc( input ) ) { + || c == LPERIOD || c == LSLASH || c == LCOMMA; c = url_fgetwc( input ) ) { switch ( c ) { - case L'.': + case LPERIOD: if ( seen_period || !nilp( dividend ) ) { return throw_exception( c_string_to_lisp_string ( L"Malformed number: too many periods" ), @@ -311,7 +311,7 @@ struct cons_pointer read_number( struct stack_frame *frame, seen_period = true; } break; - case L'/': + case LSLASH: if ( seen_period || !nilp( dividend ) ) { return throw_exception( c_string_to_lisp_string ( L"Malformed number: dividend of rational must be integer" ), @@ -324,11 +324,12 @@ struct cons_pointer read_number( struct stack_frame *frame, result = make_integer( 0, NIL ); } break; - case L',': + case LCOMMA: // silently ignore it. break; default: result = add_integers( multiply_integers( result, base ), + /* /todo: this won't work for hex digits */ make_integer( ( int ) c - ( int ) '0', NIL ) ); @@ -402,7 +403,7 @@ struct cons_pointer read_list( struct stack_frame *frame, for ( c = url_fgetwc( input ); iswblank( c ) || iswcntrl( c ); c = url_fgetwc( input ) ); - if ( c == L'.' ) { + if ( c == LPERIOD ) { /* might be a dotted pair; indeed, if we rule out numbers with * initial periods, it must be a dotted pair. \todo Ought to check, * howerver, that there's only one form after the period. */ @@ -433,7 +434,7 @@ struct cons_pointer read_map( struct stack_frame *frame, make_hashmap( DFLT_HASHMAP_BUCKETS, NIL, TRUE ); wint_t c = initial; - while ( c != L'}' ) { + while ( c != LCBRACE ) { struct cons_pointer key = read_continuation( frame, frame_pointer, env, input, c ); @@ -446,7 +447,7 @@ struct cons_pointer read_map( struct stack_frame *frame, /* skip commaa and whitespace at this point. */ for ( c = url_fgetwc( input ); - c == L',' || iswblank( c ) || iswcntrl( c ); + c == LCOMMA || iswblank( c ) || iswcntrl( c ); c = url_fgetwc( input ) ); result = diff --git a/src/io/read.h b/src/io/read.h index 031bb4f..7f58d0c 100644 --- a/src/io/read.h +++ b/src/io/read.h @@ -13,6 +13,15 @@ #include "memory/consspaceobject.h" +/* characters (other than arabic numberals) used in number representations */ +#define LCOMMA L',' +#define LPERIOD L'.' +#define LSLASH L'/' +/* ... used in map representations */ +#define LCBRACE L'}' +/* ... used in path representations */ +#define LSESSION L'§' + /** * read the next object on this input stream and return a cons_pointer to it. */