diff --git a/src/c/environment/environment.c b/src/c/environment/environment.c index 8dbbc1f..8dec0f3 100644 --- a/src/c/environment/environment.c +++ b/src/c/environment/environment.c @@ -52,6 +52,7 @@ struct pso_pointer initialise_environment( uint32_t node ) { object->payload.cons.cdr = nil; nil = n; + lock_object( nil); debug_print( L"success\n", DEBUG_BOOTSTRAP, 0); } else { result = @@ -72,6 +73,7 @@ struct pso_pointer initialise_environment( uint32_t node ) { object->payload.cons.cdr = t; t = n; + lock_object(t); debug_print( L"success\n", DEBUG_BOOTSTRAP, 0); } else { result = @@ -86,6 +88,7 @@ struct pso_pointer initialise_environment( uint32_t node ) { result = c_bind( c_string_to_lisp_symbol( L"t" ), t, result ); environment_initialised = true; + debug_print( L"\nEnvironment initialised successfully.\n", DEBUG_BOOTSTRAP, 0); } return result; diff --git a/src/c/memory/node.c b/src/c/memory/node.c index 5c70ec5..4cc9db0 100644 --- a/src/c/memory/node.c +++ b/src/c/memory/node.c @@ -41,9 +41,10 @@ struct pso_pointer nil = ( struct pso_pointer ) { 0, 0, 0 }; /** * @brief the canonical `t` (true) pointer. - * + * Offset 4, because `t` should be the second pso2 allocated, the offset is + * given in words, and the size of a pso2 should be four words. */ -struct pso_pointer t = ( struct pso_pointer ) { 0, 0, 1 }; +struct pso_pointer t = ( struct pso_pointer ) { 0, 0, 4 }; /** diff --git a/src/c/memory/page.c b/src/c/memory/page.c index 9a90e8e..4b27abc 100644 --- a/src/c/memory/page.c +++ b/src/c/memory/page.c @@ -287,7 +287,7 @@ struct pso_pointer allocate_page( uint8_t size_class ) { memset( pg, 0, sizeof( union page ) ); pages[npages_allocated] = pg; debug_printf( DEBUG_ALLOC, 0, - L"Allocated page %d for objects of size class %x.\n", + L"\nAllocated page %d for objects of size class %x.\n", npages_allocated, size_class ); freelists[size_class] = diff --git a/src/c/memory/pso.c b/src/c/memory/pso.c index 0b336ed..3daa4a9 100644 --- a/src/c/memory/pso.c +++ b/src/c/memory/pso.c @@ -15,6 +15,7 @@ */ #include +#include #include #include "debug.h" @@ -38,7 +39,8 @@ * @return struct pso_pointer a pointer to the newly allocated object */ struct pso_pointer allocate( char *tag, uint8_t size_class ) { - struct pso_pointer result = nil; + // `t`, because if `allocate_page` fails it will be set to `nil`. + struct pso_pointer result = t; #ifdef DEBUG debug_printf( DEBUG_ALLOC, 0, L"Allocating object of size class %d with tag `%s`... ", size_class, tag); @@ -49,7 +51,14 @@ struct pso_pointer allocate( char *tag, uint8_t size_class ) { result = allocate_page( size_class ); } - if ( !exceptionp( result ) ) { + if (nilp(result)) { + fputws( L"FATAL: Page space exhausted\n", stderr ); + exit(1); // TODO: we don't want to do this! Somehow, we need to + // recover a workable environment, ideally by throwing a pre-made + // exception. + } + + if ( !exceptionp( result ) && !nilp(result)) { result = freelists[size_class]; struct pso2 *object = pointer_to_object( result ); freelists[size_class] = object->payload.free.next; @@ -69,7 +78,6 @@ struct pso_pointer allocate( char *tag, uint8_t size_class ) { if ( object->header.count != 0 ) { // TODO: return an exception instead? Or warn, set it, and continue? } - } } // TODO: else throw exception diff --git a/src/c/ops/string_ops.c b/src/c/ops/string_ops.c index 0070be9..cb82abe 100644 --- a/src/c/ops/string_ops.c +++ b/src/c/ops/string_ops.c @@ -127,7 +127,7 @@ struct pso_pointer make_keyword( wint_t c, struct pso_pointer tail ) { * @param tail the symbol which is being built. */ struct pso_pointer make_symbol( wint_t c, struct pso_pointer tail ) { - return make_string_like_thing( c, tail, STRINGTAG ); + return make_string_like_thing( c, tail, SYMBOLTAG ); } diff --git a/src/c/ops/truth.c b/src/c/ops/truth.c index 8ffb2f5..7b0eb76 100644 --- a/src/c/ops/truth.c +++ b/src/c/ops/truth.c @@ -49,12 +49,15 @@ bool not( struct pso_pointer p ) { * each is considered equivalent. So we don't check the node when considering * whether `nil` really is `nil`, or `t` really is `t`. * + * Note that the offset is 4 because `t` should be the second pso2 allocated, + * the offset is given in words, and the size of a pso2 should be four words + * * @param p a pointer * @return true if `p` points to `t`. * @return false otherwise. */ bool truep( struct pso_pointer p ) { - return ( p.page == 0 && p.offset == 1 ); + return ( p.page == 0 && p.offset == 4 ); } /**