Closes #18. Change to char32_t everywhere; builds fine, behaviour as before.

This commit is contained in:
Simon Brooke 2026-04-20 12:10:38 +01:00
parent 812a1be7d9
commit c59825d7fe
33 changed files with 116 additions and 76 deletions

View file

@ -57,7 +57,7 @@ void debug_print_exception( struct cons_pointer ex_ptr ) {
* `verbosity` is a set of flags, see debug_print.h; so you can
* turn debugging on for only one part of the system.
*/
void debug_print( wchar_t *message, int level ) {
void debug_print( char32_t *message, int level ) {
#ifdef DEBUG
if ( level & verbosity ) {
fwide( stderr, 1 );
@ -117,7 +117,7 @@ void debug_println( int level ) {
* Print to stderr only if `verbosity` matches `level`. All other arguments
* as for `wprintf`.
*/
void debug_printf( int level, wchar_t *format, ... ) {
void debug_printf( int level, char32_t *format, ... ) {
#ifdef DEBUG
if ( level & verbosity ) {
fwide( stderr, 1 );
@ -169,7 +169,7 @@ void debug_dump_object( struct cons_pointer pointer, int level ) {
void debug_print_binding( struct cons_pointer key, struct cons_pointer val,
bool deep, int level ) {
#ifdef DEBUG
// wchar_t * depth = (deep ? L"Deep" : L"Shallow");
// char32_t * depth = (deep ? L"Deep" : L"Shallow");
debug_print( ( deep ? L"Deep" : L"Shallow" ), level );
debug_print( L" binding `", level );

View file

@ -89,10 +89,10 @@
extern int verbosity;
void debug_print_exception( struct cons_pointer ex_ptr );
void debug_print( wchar_t *message, int level );
void debug_print( char32_t *message, int level );
void debug_print_128bit( __int128_t n, int level );
void debug_println( int level );
void debug_printf( int level, wchar_t *format, ... );
void debug_printf( int level, char32_t *format, ... );
void debug_print_object( struct cons_pointer pointer, int level );
void debug_dump_object( struct cons_pointer pointer, int level );
void debug_print_binding( struct cons_pointer key, struct cons_pointer val,

View file

@ -110,8 +110,8 @@ void free_init_symbols( ) {
* the name on the source pointer. Would make stack frames potentially
* more readable and aid debugging generally.
*/
struct cons_pointer bind_function( wchar_t *name,
wchar_t *doc,
struct cons_pointer bind_function( char32_t *name,
char32_t *doc,
struct cons_pointer ( *executable )
( struct stack_frame *,
struct cons_pointer,
@ -141,8 +141,8 @@ struct cons_pointer bind_function( wchar_t *name,
* Bind this compiled `executable` function, as a Lisp special form, to
* this `name` in the `oblist`.
*/
struct cons_pointer bind_special( wchar_t *name,
wchar_t *doc,
struct cons_pointer bind_special( char32_t *name,
char32_t *doc,
struct cons_pointer ( *executable )
( struct stack_frame *, struct cons_pointer,
struct cons_pointer ) ) {
@ -188,7 +188,7 @@ bind_symbol_value( struct cons_pointer symbol, struct cons_pointer value,
/**
* Bind this `value` to this `name` in the `oblist`.
*/
struct cons_pointer bind_value( wchar_t *name, struct cons_pointer value,
struct cons_pointer bind_value( char32_t *name, struct cons_pointer value,
bool lock ) {
struct cons_pointer p = c_string_to_lisp_symbol( name );

View file

@ -103,7 +103,7 @@ char *lisp_string_to_c_string( struct cons_pointer s ) {
len++;
}
wchar_t *buffer = calloc( len + 1, sizeof( wchar_t ) );
char32_t *buffer = calloc( len + 1, sizeof( char32_t ) );
/* worst case, one wide char = four utf bytes */
result = calloc( ( len * 4 ) + 1, sizeof( char ) );
@ -164,8 +164,8 @@ wint_t url_fgetwc( URL_FILE *input ) {
case CFTYPE_CURL:{
char *cbuff =
calloc( sizeof( wchar_t ) + 2, sizeof( char ) );
wchar_t *wbuff = calloc( 2, sizeof( wchar_t ) );
calloc( sizeof( char32_t ) + 2, sizeof( char ) );
char32_t *wbuff = calloc( 2, sizeof( char32_t ) );
size_t count = 0;
@ -265,7 +265,7 @@ lisp_close( struct stack_frame *frame, struct cons_pointer frame_pointer,
return result;
}
struct cons_pointer add_meta_integer( struct cons_pointer meta, wchar_t *key,
struct cons_pointer add_meta_integer( struct cons_pointer meta, char32_t *key,
long int value ) {
return
make_cons( make_cons
@ -273,17 +273,17 @@ struct cons_pointer add_meta_integer( struct cons_pointer meta, wchar_t *key,
make_integer( value, NIL ) ), meta );
}
struct cons_pointer add_meta_string( struct cons_pointer meta, wchar_t *key,
struct cons_pointer add_meta_string( struct cons_pointer meta, char32_t *key,
char *value ) {
value = trim( value );
wchar_t buffer[strlen( value ) + 1];
char32_t buffer[strlen( value ) + 1];
mbstowcs( buffer, value, strlen( value ) + 1 );
return make_cons( make_cons( c_string_to_lisp_keyword( key ),
c_string_to_lisp_string( buffer ) ), meta );
}
struct cons_pointer add_meta_time( struct cons_pointer meta, wchar_t *key,
struct cons_pointer add_meta_time( struct cons_pointer meta, char32_t *key,
time_t *value ) {
/* I don't yet have a concept of a date-time object, which is a
* bit of an oversight! */
@ -317,7 +317,7 @@ static size_t write_meta_callback( char *string, size_t size, size_t nmemb,
s[offset] = ( char ) 0;
char *name = trim( s );
char *value = trim( &s[++offset] );
wchar_t wname[strlen( name )];
char32_t wname[strlen( name )];
mbstowcs( wname, name, strlen( name ) + 1 );
@ -548,7 +548,7 @@ lisp_slurp( struct stack_frame *frame, struct cons_pointer frame_pointer,
debug_println( DEBUG_IO );
struct cons_space_object *cell = &pointer2cell( cursor );
cursor = make_string( ( wchar_t ) c, NIL );
cursor = make_string( ( char32_t ) c, NIL );
cell->payload.string.cdr = cursor;
}
}

View file

@ -37,7 +37,7 @@
void print_string_contents( URL_FILE *output, struct cons_pointer pointer ) {
while ( stringp( pointer ) || symbolp( pointer ) || keywordp( pointer ) ) {
struct cons_space_object *cell = &pointer2cell( pointer );
wchar_t c = cell->payload.string.character;
char32_t c = cell->payload.string.character;
if ( c != '\0' ) {
url_fputwc( c, output );

View file

@ -181,7 +181,7 @@ struct cons_pointer c_type( struct cons_pointer pointer ) {
* strings made with NIL termination. The question is which should be
* fixed, and actually that's probably strings read by `read`. However,
* for now, it was easier to add a null character here. */
struct cons_pointer result = make_string( ( wchar_t ) 0, NIL );
struct cons_pointer result = make_string( ( char32_t ) 0, NIL );
struct cons_space_object *cell = &pointer2cell( pointer );
if ( cell->tag.value == VECTORPOINTTV ) {
@ -189,11 +189,11 @@ struct cons_pointer c_type( struct cons_pointer pointer ) {
for ( int i = TAGLENGTH - 1; i >= 0; i-- ) {
result =
make_string( ( wchar_t ) vec->header.tag.bytes[i], result );
make_string( ( char32_t ) vec->header.tag.bytes[i], result );
}
} else {
for ( int i = TAGLENGTH - 1; i >= 0; i-- ) {
result = make_string( ( wchar_t ) cell->tag.bytes[i], result );
result = make_string( ( char32_t ) cell->tag.bytes[i], result );
}
}
@ -518,11 +518,11 @@ struct cons_pointer make_write_stream( URL_FILE *output,
* Return a lisp keyword representation of this wide character string. In
* keywords, I am accepting only lower case characters and numbers.
*/
struct cons_pointer c_string_to_lisp_keyword( wchar_t *symbol ) {
struct cons_pointer c_string_to_lisp_keyword( char32_t *symbol ) {
struct cons_pointer result = NIL;
for ( int i = wcslen( symbol ) - 1; i >= 0; i-- ) {
wchar_t c = towlower( symbol[i] );
char32_t c = towlower( symbol[i] );
if ( iswalnum( c ) || c == L'-' ) {
result = make_keyword( c, result );
@ -535,7 +535,7 @@ struct cons_pointer c_string_to_lisp_keyword( wchar_t *symbol ) {
/**
* Return a lisp string representation of this wide character string.
*/
struct cons_pointer c_string_to_lisp_string( wchar_t *string ) {
struct cons_pointer c_string_to_lisp_string( char32_t *string ) {
struct cons_pointer result = NIL;
for ( int i = wcslen( string ) - 1; i >= 0; i-- ) {
@ -550,7 +550,7 @@ struct cons_pointer c_string_to_lisp_string( wchar_t *string ) {
/**
* Return a lisp symbol representation of this wide character string.
*/
struct cons_pointer c_string_to_lisp_symbol( wchar_t *symbol ) {
struct cons_pointer c_string_to_lisp_symbol( char32_t *symbol ) {
struct cons_pointer result = NIL;
for ( int i = wcslen( symbol ); i > 0; i-- ) {

View file

@ -773,7 +773,7 @@ struct cons_pointer make_function( struct cons_pointer src,
struct cons_pointer,
struct cons_pointer ) );
struct cons_pointer c_string_to_lisp_keyword( wchar_t *symbol );
struct cons_pointer c_string_to_lisp_keyword( char32_t *symbol );
struct cons_pointer make_lambda( struct cons_pointer args,
struct cons_pointer body );
@ -805,8 +805,8 @@ struct cons_pointer make_read_stream( URL_FILE * input,
struct cons_pointer make_write_stream( URL_FILE * output,
struct cons_pointer metadata );
struct cons_pointer c_string_to_lisp_string( wchar_t *string );
struct cons_pointer c_string_to_lisp_string( char32_t *string );
struct cons_pointer c_string_to_lisp_symbol( wchar_t *symbol );
struct cons_pointer c_string_to_lisp_symbol( char32_t *symbol );
#endif

View file

@ -29,7 +29,7 @@
#include "memory/vectorspace.h"
void dump_string_cell( URL_FILE *output, wchar_t *prefix,
void dump_string_cell( URL_FILE *output, char32_t *prefix,
struct cons_pointer pointer ) {
struct cons_space_object cell = pointer2cell( pointer );
if ( cell.payload.string.character == 0 ) {

View file

@ -19,7 +19,7 @@
#ifndef __dump_h
#define __dump_h
void dump_string_cell( URL_FILE * output, wchar_t *prefix,
void dump_string_cell( URL_FILE * output, char32_t *prefix,
struct cons_pointer pointer );
void dump_object( URL_FILE * output, struct cons_pointer pointer );

View file

@ -369,7 +369,7 @@ bool c_equal( struct cons_pointer a, struct cons_pointer b ) {
* iteration (and even that is problematic) */
if ( cell_a->payload.string.hash ==
cell_b->payload.string.hash ) {
wchar_t a_buff[STRING_SHIPYARD_SIZE],
char32_t a_buff[STRING_SHIPYARD_SIZE],
b_buff[STRING_SHIPYARD_SIZE];
uint32_t tag = cell_a->tag.value;
int i = 0;

View file

@ -502,8 +502,8 @@ c_apply( struct stack_frame *frame, struct cons_pointer frame_pointer,
default:
{
int bs = sizeof( wchar_t ) * 1024;
wchar_t *buffer = malloc( bs );
int bs = sizeof( char32_t ) * 1024;
char32_t *buffer = malloc( bs );
memset( buffer, '\0', bs );
swprintf( buffer, bs,
L"Unexpected cell with tag %d (%4.4s) in function position",

View file

@ -99,7 +99,7 @@ struct cons_pointer time_to_string( struct cons_pointer pointer ) {
if ( t != 0 ) {
char *bytes = ctime( &t );
int l = strlen( bytes ) + 1;
wchar_t buffer[l];
char32_t buffer[l];
mbstowcs( buffer, bytes, l );
result = c_string_to_lisp_string( buffer );