feature-2: allocating cells with count = 1; 7 unit tests (all bignums) fail.

This commit is contained in:
Simon Brooke 2026-02-12 10:17:11 +00:00
parent 351ca5bd17
commit 004ff6737c
10 changed files with 209 additions and 114 deletions

View file

@ -28,11 +28,12 @@
#include <curl/curl.h>
#include "memory/conspage.h"
#include "memory/consspaceobject.h"
#include "arith/integer.h"
#include "debug.h"
#include "io/fopen.h"
#include "arith/integer.h"
#include "io/io.h"
#include "memory/conspage.h"
#include "memory/consspaceobject.h"
#include "ops/intern.h"
#include "ops/lispops.h"
#include "utils.h"
@ -44,6 +45,16 @@
*/
CURLSH *io_share;
/**
* @brief bound to the Lisp string representing C_IO_IN in initialisation.
*/
struct cons_pointer lisp_io_in = NIL;
/**
* @brief bound to the Lisp string representing C_IO_OUT in initialisation.
*/
struct cons_pointer lisp_io_out = NIL;
/**
* Allow a one-character unget facility. This may not be enough - we may need
* to allocate a buffer.
@ -400,7 +411,7 @@ void collect_meta( struct cons_pointer stream, char *url ) {
struct cons_pointer get_default_stream( bool inputp, struct cons_pointer env ) {
struct cons_pointer result = NIL;
struct cons_pointer stream_name =
c_string_to_lisp_symbol( inputp ? L"*in*" : L"*out*" );
inputp ? lisp_io_in : lisp_io_out;
inc_ref( stream_name );

View file

@ -11,12 +11,18 @@
#ifndef __psse_io_h
#define __psse_io_h
#include <curl/curl.h>
#include "consspaceobject.h"
#include "memory/consspaceobject.h"
extern CURLSH *io_share;
int io_init( );
#define C_IO_IN L"*in*"
#define C_IO_OUT L"*out*"
extern struct cons_pointer lisp_io_in;
extern struct cons_pointer lisp_io_out;
URL_FILE *file_to_url_file( FILE * f );
wint_t url_fgetwc( URL_FILE * input );
wint_t url_ungetwc( wint_t wc, URL_FILE * input );

View file

@ -291,10 +291,10 @@ struct cons_pointer read_number( struct stack_frame *frame,
wint_t initial, bool seen_period ) {
debug_print( L"entering read_number\n", DEBUG_IO );
struct cons_pointer result = make_integer( 0, NIL );
struct cons_pointer result = acquire_integer( 0, NIL );
/* \todo we really need to be getting `base` from a privileged Lisp name -
* and it should be the same privileged name we use when writing numbers */
struct cons_pointer base = make_integer( 10, NIL );
struct cons_pointer base = acquire_integer( 10, NIL );
struct cons_pointer dividend = NIL;
int places_of_decimals = 0;
wint_t c;
@ -330,20 +330,20 @@ struct cons_pointer read_number( struct stack_frame *frame,
debug_print( L"read_number: ratio slash seen\n",
DEBUG_IO );
dividend = result;
result = acquire_integer( 0, NIL );
// If I do replace_integer_p here instead of acquire_integer,
// and thus reclaim the garbage, I get a regression. Dom't yet
// know why.
}
break;
case LCOMMA:
// silently ignore comma.
break;
default:
{
struct cons_pointer digit = make_integer( ( int ) c - ( int ) '0',
NIL );
struct cons_pointer new_result = add_integers( multiply_integers( result, base ),
digit );
dec_ref( result);
dec_ref( digit);
result = new_result;
result = add_integers( multiply_integers( result, base ),
acquire_integer( ( int ) c - ( int ) '0',
NIL ) );
debug_printf( DEBUG_IO,
L"read_number: added character %c, result now ",
@ -354,7 +354,6 @@ struct cons_pointer read_number( struct stack_frame *frame,
if ( seen_period ) {
places_of_decimals++;
}
}
}
}
@ -364,14 +363,13 @@ struct cons_pointer read_number( struct stack_frame *frame,
url_ungetwc( c, input );
if ( seen_period ) {
struct cons_pointer divisor = make_integer( powl( to_long_double( base ),
places_of_decimals ),
NIL );
debug_print( L"read_number: converting result to real\n", DEBUG_IO );
struct cons_pointer div = make_ratio( result,
divisor);
dec_ref( divisor);
acquire_integer( powl
( to_long_double
( base ),
places_of_decimals ),
NIL ) );
inc_ref( div );
result = make_real( to_long_double( div ) );
@ -383,19 +381,15 @@ struct cons_pointer read_number( struct stack_frame *frame,
}
if ( neg ) {
struct cons_pointer negt = negative( result );
debug_print( L"read_number: converting result to negative\n",
DEBUG_IO );
dec_ref( result);
result = negt;
result = negative( result );
}
debug_print( L"read_number returning\n", DEBUG_IO );
debug_dump_object( result, DEBUG_IO );
dec_ref( base);
return result;
}