Much progress! Half the unit tests pass.
This commit is contained in:
parent
75abfb4050
commit
e52ccce0eb
17 changed files with 296 additions and 253 deletions
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "consspaceobject.h"
|
||||
#include "conspage.h"
|
||||
#include "debug.h"
|
||||
#include "dump.h"
|
||||
|
||||
/**
|
||||
|
|
@ -65,7 +66,7 @@ void make_cons_page( ) {
|
|||
cell->count = MAXREFERENCE;
|
||||
cell->payload.free.car = NIL;
|
||||
cell->payload.free.cdr = NIL;
|
||||
fwprintf( stderr, L"Allocated special cell NIL\n" );
|
||||
debug_printf( DEBUG_ALLOC, L"Allocated special cell NIL\n" );
|
||||
break;
|
||||
case 1:
|
||||
/*
|
||||
|
|
@ -79,7 +80,7 @@ void make_cons_page( ) {
|
|||
cell->payload.free.cdr = ( struct cons_pointer ) {
|
||||
0, 1
|
||||
};
|
||||
fwprintf( stderr, L"Allocated special cell T\n" );
|
||||
debug_printf( DEBUG_ALLOC, L"Allocated special cell T\n" );
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -96,7 +97,7 @@ void make_cons_page( ) {
|
|||
|
||||
initialised_cons_pages++;
|
||||
} else {
|
||||
fwprintf( stderr,
|
||||
debug_printf( DEBUG_ALLOC,
|
||||
L"FATAL: Failed to allocate memory for cons page %d\n",
|
||||
initialised_cons_pages );
|
||||
exit( 1 );
|
||||
|
|
@ -128,10 +129,8 @@ void dump_pages( FILE * output ) {
|
|||
void free_cell( struct cons_pointer pointer ) {
|
||||
struct cons_space_object *cell = &pointer2cell( pointer );
|
||||
|
||||
#ifdef DEBUG
|
||||
fwprintf( stderr, L"Freeing cell " );
|
||||
dump_object( stderr, pointer );
|
||||
#endif
|
||||
debug_printf( DEBUG_ALLOC, L"Freeing cell " );
|
||||
debug_dump_object( pointer, DEBUG_ALLOC );
|
||||
|
||||
switch ( cell->tag.value ) {
|
||||
/* for all the types of cons-space object which point to other
|
||||
|
|
@ -165,10 +164,8 @@ void free_cell( struct cons_pointer pointer ) {
|
|||
case VECTORPOINTTV:
|
||||
/* for vector space pointers, free the actual vector-space
|
||||
* object. Dangerous! */
|
||||
#ifdef DEBUG
|
||||
fwprintf( stderr, L"About to free vector-space object at %ld\n",
|
||||
debug_printf( DEBUG_ALLOC, L"About to free vector-space object at %ld\n",
|
||||
cell->payload.vectorp.address );
|
||||
#endif
|
||||
//free( ( void * ) cell->payload.vectorp.address );
|
||||
break;
|
||||
|
||||
|
|
@ -181,12 +178,12 @@ void free_cell( struct cons_pointer pointer ) {
|
|||
cell->payload.free.cdr = freelist;
|
||||
freelist = pointer;
|
||||
} else {
|
||||
fwprintf( stderr,
|
||||
debug_printf( DEBUG_ALLOC,
|
||||
L"ERROR: Attempt to free cell with %d dangling references at page %d, offset %d\n",
|
||||
cell->count, pointer.page, pointer.offset );
|
||||
}
|
||||
} else {
|
||||
fwprintf( stderr,
|
||||
debug_printf( DEBUG_ALLOC,
|
||||
L"ERROR: Attempt to free cell which is already FREE at page %d, offset %d\n",
|
||||
pointer.page, pointer.offset );
|
||||
}
|
||||
|
|
@ -218,13 +215,11 @@ struct cons_pointer allocate_cell( char *tag ) {
|
|||
cell->payload.cons.car = NIL;
|
||||
cell->payload.cons.cdr = NIL;
|
||||
|
||||
#ifdef DEBUG
|
||||
fwprintf( stderr,
|
||||
debug_printf( DEBUG_ALLOC,
|
||||
L"Allocated cell of type '%s' at %d, %d \n", tag,
|
||||
result.page, result.offset );
|
||||
#endif
|
||||
} else {
|
||||
fwprintf( stderr, L"WARNING: Allocating non-free cell!" );
|
||||
debug_printf( DEBUG_ALLOC, L"WARNING: Allocating non-free cell!" );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -243,7 +238,7 @@ void initialise_cons_pages( ) {
|
|||
make_cons_page( );
|
||||
conspageinitihasbeencalled = true;
|
||||
} else {
|
||||
fwprintf( stderr,
|
||||
debug_printf( DEBUG_ALLOC,
|
||||
L"WARNING: initialise_cons_pages() called a second or subsequent time\n" );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue