Initialisation almost succeeds. nil and t are successfully instantiated.

We then go into a mess of exceptions which trigger exceptions until we run out
of allocatable memory, but all those exceptions and stack frames are correctly
allocated and torn down again afterwards, so.... sort of good?
This commit is contained in:
Simon Brooke 2026-04-16 11:39:01 +01:00
commit ba985474f6
31 changed files with 869 additions and 199 deletions

View file

@ -18,6 +18,7 @@
#include <string.h>
#include "debug.h"
#include "memory/destroy.h"
#include "memory/header.h"
#include "memory/memory.h"
@ -39,12 +40,16 @@
struct pso_pointer allocate( char *tag, uint8_t size_class ) {
struct pso_pointer result = nil;
#ifdef DEBUG
debug_printf( DEBUG_ALLOC, 0, L"Allocating object of size class %d with tag `%s`... ", size_class, tag);
#endif
if ( size_class <= MAX_SIZE_CLASS ) {
if ( nilp( freelists[size_class] ) ) {
result = allocate_page( size_class );
}
if ( !exceptionp( result ) && not( freelists[size_class] ) ) {
if ( !exceptionp( result ) ) {
result = freelists[size_class];
struct pso2 *object = pointer_to_object( result );
freelists[size_class] = object->payload.free.next;
@ -52,6 +57,8 @@ struct pso_pointer allocate( char *tag, uint8_t size_class ) {
strncpy( ( char * ) ( object->header.tag.bytes.mnemonic ), tag,
TAGLENGTH );
debug_printf( DEBUG_ALLOC, 0, L"at page %d, offset %d... ", result.page, result.offset);
/* the object ought already to have the right size class in its tag
* because it was popped off the freelist for that size class. */
if ( object->header.tag.bytes.size_class != size_class ) {
@ -66,6 +73,10 @@ struct pso_pointer allocate( char *tag, uint8_t size_class ) {
}
} // TODO: else throw exception
#ifdef DEBUG
debug_print(exceptionp(result)? L"fail\n" : L"success\n", DEBUG_ALLOC, 0);
#endif
return result;
}
@ -118,11 +129,11 @@ struct pso_pointer inc_ref( struct pso_pointer pointer ) {
struct pso_pointer dec_ref( struct pso_pointer pointer ) {
struct pso2 *object = pointer_to_object( pointer );
if ( object->header.count > 0 && object->header.count != MAXREFERENCE ) {
if ( !nilp(pointer) && object->header.count > 0 && object->header.count != MAXREFERENCE ) {
object->header.count--;
#ifdef DEBUG
debug_printf( DEBUG_ALLOC, 0,
L"\nDecremented object of type %4.4s at page %d, offset %d to count %d",
L"\nDecremented object of type %3.3s at page %d, offset %d to count %d",
( ( char * ) ( object->header.tag.bytes.mnemonic ) ),
pointer.page, pointer.offset, object->header.count );
if ( vectorpointp( pointer ) ) {