Fixed a segfault when the system can initialise no more pages.

Still not fixed the `member?` bug.
This commit is contained in:
Simon Brooke 2026-03-18 13:27:19 +00:00
parent 69b199fecd
commit 7d0ce67373
3 changed files with 25 additions and 19 deletions

View file

@ -1,14 +1,18 @@
(set! nil? (lambda (set! nil? (lambda (o) (= (type o) "NIL ")))
(o)
"`(nil? object)`: Return `t` if object is `nil`, else `t`."
(= o nil)))
(set! member? (lambda (set! CDR (lambda (o)
(print (list "in CDR; o is: " o) *log*)
(let ((r . (cdr o)))
(print (list "; returning: " r) *log*)
(println *log*)
(println *log*)
r)))
(set! member?
(lambda
(item collection) (item collection)
"`(member? item collection)`: Return `t` if this `item` is a member of this `collection`, else `nil`." (print (list "in member?: " 'item item 'collection collection) *log*)(println *log*)
(cond (cond
((nil? collection) nil) ((nil? collection) nil)
((= item (car collection)) t) ((= item (car collection)) t)
(t (member? item (cdr collection)))))) (t (member? item (CDR collection))))))
;; (member? (type member?) '("LMDA" "NLMD"))

View file

@ -65,7 +65,11 @@ struct cons_page *conspages[NCONSPAGES];
* that exception would have to have been pre-built. * that exception would have to have been pre-built.
*/ */
void make_cons_page( ) { void make_cons_page( ) {
struct cons_page *result = malloc( sizeof( struct cons_page ) ); struct cons_page *result = NULL;
if ( initialised_cons_pages < NCONSPAGES) {
result = malloc( sizeof( struct cons_page ) );
}
if ( result != NULL ) { if ( result != NULL ) {
conspages[initialised_cons_pages] = result; conspages[initialised_cons_pages] = result;
@ -116,12 +120,10 @@ void make_cons_page( ) {
initialised_cons_pages++; initialised_cons_pages++;
} else { } else {
debug_printf( DEBUG_ALLOC, fwide( stderr, 1 );
L"FATAL: Failed to allocate memory for cons page %d\n", fwprintf( stderr, L"FATAL: Failed to allocate memory for cons page %d\n", initialised_cons_pages );
initialised_cons_pages );
exit( 1 ); exit( 1 );
} }
} }
/** /**

View file

@ -53,7 +53,7 @@ else
fi fi
expected='nil' expected='nil'(CDR )
output=`target/psse $1 <<EOF output=`target/psse $1 <<EOF
(progn (progn
(set! nil? (lambda (o) (= (type o) "NIL "))) (set! nil? (lambda (o) (= (type o) "NIL ")))
@ -86,7 +86,7 @@ output=`target/psse $1 -s100<<EOF
(set! member? (set! member?
(lambda (lambda
(item collection) (item collection)
;; (print (list "in member?: " 'item item 'collection collection)) ;; (print (list "in member?: " 'item item 'collection collection) *log*)(println *log*)
(cond (cond
((nil? collection) nil) ((nil? collection) nil)
((= item (car collection)) t) ((= item (car collection)) t)