Much better debugging, but it still doesn't work
This commit is contained in:
parent
3d5c27cb10
commit
75abfb4050
23 changed files with 395 additions and 233 deletions
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "consspaceobject.h"
|
||||
#include "conspage.h"
|
||||
#include "dump.h"
|
||||
|
||||
/**
|
||||
* Flag indicating whether conspage initialisation has been done.
|
||||
|
|
@ -168,7 +169,7 @@ void free_cell( struct cons_pointer pointer ) {
|
|||
fwprintf( stderr, L"About to free vector-space object at %ld\n",
|
||||
cell->payload.vectorp.address );
|
||||
#endif
|
||||
free( ( void * ) cell->payload.vectorp.address );
|
||||
//free( ( void * ) cell->payload.vectorp.address );
|
||||
break;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
* 4294967296.
|
||||
*
|
||||
* Note that this means the total number of addressable cons cells is
|
||||
* 1.8e19, each of 20 bytes; or 3e20 bytes in total; and there are
|
||||
* 1.8e19, each of 20 bytes; or 3e20 bytes in total; and there are
|
||||
* up to a maximum of 4e9 of heap space objects, each of potentially
|
||||
* 4e9 bytes. So we're talking about a potential total of 8e100 bytes
|
||||
* of addressable memory, which is only slightly more than the
|
||||
|
|
@ -38,7 +38,7 @@ struct cons_page {
|
|||
};
|
||||
|
||||
/**
|
||||
* The (global) pointer to the (global) freelist. Not sure whether this ultimately
|
||||
* The (global) pointer to the (global) freelist. Not sure whether this ultimately
|
||||
* belongs in this file.
|
||||
*/
|
||||
extern struct cons_pointer freelist;
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@
|
|||
* A pointer to an object in vector space.
|
||||
*/
|
||||
#define VECTORPOINTTAG "VECP"
|
||||
#define VECTORPOINTTV 0
|
||||
#define VECTORPOINTTV 1346585942
|
||||
/**
|
||||
* An open write stream.
|
||||
*/
|
||||
|
|
@ -263,9 +263,10 @@
|
|||
* An indirect pointer to a cons cell
|
||||
*/
|
||||
struct cons_pointer {
|
||||
uint32_t page; /* the index of the page on which this cell
|
||||
* resides */
|
||||
uint32_t offset; /* the index of the cell within the page */
|
||||
/** the index of the page on which this cell resides */
|
||||
uint32_t page;
|
||||
/** the index of the cell within the page */
|
||||
uint32_t offset;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -421,7 +422,7 @@ struct vectorp_payload {
|
|||
* tag. */
|
||||
uint32_t value; /* the tag considered as a number */
|
||||
} tag;
|
||||
struct vector_space_object *address;
|
||||
void *address;
|
||||
/* the address of the actual vector space
|
||||
* object (TODO: will change when I actually
|
||||
* implement vector space) */
|
||||
|
|
|
|||
9
src/memory/cursor.c
Normal file
9
src/memory/cursor.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* a cursor is a cons-space object which holds:
|
||||
* 1. a pointer to a vector (i.e. a vector-space object which holds an
|
||||
* array of `cons_pointer`);
|
||||
* 2. an integer offset into that array.
|
||||
*
|
||||
* this provides a mechanism for iterating through vectors (actually, in
|
||||
* either direction)
|
||||
*/
|
||||
BIN
src/memory/cursor.h
Normal file
BIN
src/memory/cursor.h
Normal file
Binary file not shown.
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "conspage.h"
|
||||
#include "consspaceobject.h"
|
||||
#include "debug.h"
|
||||
#include "print.h"
|
||||
#include "stack.h"
|
||||
#include "vectorspace.h"
|
||||
|
|
@ -111,11 +112,25 @@ void dump_object( FILE * output, struct cons_pointer pointer ) {
|
|||
dump_string_cell( output, L"Symbol", pointer );
|
||||
break;
|
||||
case VECTORPOINTTV:{
|
||||
fwprintf( output,
|
||||
L"\t\tPointer to vector-space object at %p\n",
|
||||
cell.payload.vectorp.address );
|
||||
struct vector_space_object *vso = cell.payload.vectorp.address;
|
||||
fwprintf( output,
|
||||
L"\t\tVector space object of type %4.4s, payload size %d bytes\n",
|
||||
vso->header.tag, vso->header.size );
|
||||
&vso->header.tag.bytes, vso->header.size );
|
||||
switch ( vso->header.tag.value ) {
|
||||
case STACKFRAMETV:
|
||||
dump_frame( output, pointer );
|
||||
break;
|
||||
default:
|
||||
fputws( L"(Unknown vector type)\n", output );
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fputws( L"(Unknown cons space type)\n", output );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include "consspaceobject.h"
|
||||
#include "conspage.h"
|
||||
#include "debug.h"
|
||||
#include "dump.h"
|
||||
#include "lispops.h"
|
||||
#include "print.h"
|
||||
#include "stack.h"
|
||||
|
|
@ -30,21 +32,24 @@
|
|||
*/
|
||||
struct stack_frame *get_stack_frame( struct cons_pointer pointer ) {
|
||||
struct stack_frame *result = NULL;
|
||||
fputws
|
||||
debug_print
|
||||
( L"get_stack_frame: about to get a pointer to the vector space object\n",
|
||||
stderr );
|
||||
DEBUG_ALLOC );
|
||||
struct vector_space_object *vso =
|
||||
pointer2cell( pointer ).payload.vectorp.address;
|
||||
fputws( L"get_stack_frame: got a pointer, about to test it\n", stderr );
|
||||
debug_print( L"get_stack_frame: got a pointer, about to test it\n",
|
||||
DEBUG_ALLOC );
|
||||
|
||||
if ( vectorpointp( pointer ) ) { // && stackframep(vso)){
|
||||
fputws( L"get_stack_frame: pointer is good, about to set the result\n",
|
||||
stderr );
|
||||
if ( vectorpointp( pointer ) && stackframep( vso ) ) {
|
||||
debug_print
|
||||
( L"get_stack_frame: pointer is good, about to set the result\n",
|
||||
DEBUG_ALLOC );
|
||||
|
||||
result = ( struct stack_frame * ) &( vso->payload );
|
||||
fputws( L"get_stack_frame: all good, returning\n", stderr );
|
||||
fwprintf( stderr, L"get_stack_frame: all good, returning %p\n",
|
||||
result );
|
||||
} else {
|
||||
fputws( L"get_stack_frame: fail, returning NULL\n", stderr );
|
||||
debug_print( L"get_stack_frame: fail, returning NULL\n", DEBUG_ALLOC );
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
@ -57,11 +62,20 @@ struct stack_frame *get_stack_frame( struct cons_pointer pointer ) {
|
|||
* @return the new frame, or NULL if memory is exhausted.
|
||||
*/
|
||||
struct cons_pointer make_empty_frame( struct cons_pointer previous ) {
|
||||
fputws( L"Entering make_empty_frame\n", stderr );
|
||||
debug_print( L"Entering make_empty_frame\n", DEBUG_ALLOC );
|
||||
struct cons_pointer result =
|
||||
make_vso( STACKFRAMETAG, sizeof( struct stack_frame ) );
|
||||
|
||||
debug_dump_object( result, DEBUG_ALLOC );
|
||||
|
||||
fwprintf( stderr,
|
||||
L"make_empty_frame: got vector_space_object with size %lu, tag %4.4s\n",
|
||||
pointer_to_vso( result )->header.size,
|
||||
&pointer_to_vso( result )->header.tag.bytes );
|
||||
|
||||
if ( !nilp( result ) ) {
|
||||
fputws( L"make_empty_frame: about to call get_stack_frame\n", stderr );
|
||||
debug_print( L"make_empty_frame: about to call get_stack_frame\n",
|
||||
DEBUG_ALLOC );
|
||||
struct stack_frame *frame = get_stack_frame( result );
|
||||
/*
|
||||
* TODO: later, pop a frame off a free-list of stack frames
|
||||
|
|
@ -69,9 +83,10 @@ struct cons_pointer make_empty_frame( struct cons_pointer previous ) {
|
|||
|
||||
fwprintf( stderr,
|
||||
L"make_empty_frame: about to set previous to %4.4s\n",
|
||||
pointer2cell( previous ).tag );
|
||||
&pointer2cell( previous ).tag.bytes );
|
||||
frame->previous = previous;
|
||||
fputws( L"make_empty_frame: about to call inc_ref\n", stderr );
|
||||
debug_print( L"make_empty_frame: about to call inc_ref\n",
|
||||
DEBUG_ALLOC );
|
||||
inc_ref( previous );
|
||||
|
||||
/*
|
||||
|
|
@ -82,13 +97,13 @@ struct cons_pointer make_empty_frame( struct cons_pointer previous ) {
|
|||
frame->function = NIL;
|
||||
frame->args = 0;
|
||||
|
||||
fputws( L"make_empty_frame: about to initialise arg registers\n",
|
||||
stderr );
|
||||
debug_print( L"make_empty_frame: about to initialise arg registers\n",
|
||||
DEBUG_ALLOC );
|
||||
for ( int i = 0; i < args_in_frame; i++ ) {
|
||||
set_reg( frame, i, NIL );
|
||||
}
|
||||
}
|
||||
fputws( L"Leaving make_empty_frame\n", stderr );
|
||||
debug_print( L"Leaving make_empty_frame\n", DEBUG_ALLOC );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -104,7 +119,7 @@ struct cons_pointer make_empty_frame( struct cons_pointer previous ) {
|
|||
struct cons_pointer make_stack_frame( struct cons_pointer previous,
|
||||
struct cons_pointer args,
|
||||
struct cons_pointer env ) {
|
||||
fputws( L"Entering make_stack_frame\n", stderr );
|
||||
debug_print( L"Entering make_stack_frame\n", DEBUG_ALLOC );
|
||||
struct cons_pointer result = make_empty_frame( previous );
|
||||
|
||||
if ( nilp( result ) ) {
|
||||
|
|
@ -164,12 +179,11 @@ struct cons_pointer make_stack_frame( struct cons_pointer previous,
|
|||
frame->more = more;
|
||||
inc_ref( more );
|
||||
}
|
||||
#ifdef DEBUG
|
||||
dump_frame( stderr, result );
|
||||
#endif
|
||||
|
||||
debug_dump_object( result, DEBUG_ALLOC );
|
||||
}
|
||||
}
|
||||
fputws( L"Leaving make_stack_frame\n", stderr );
|
||||
debug_print( L"Leaving make_stack_frame\n", DEBUG_ALLOC );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -185,7 +199,7 @@ struct cons_pointer make_stack_frame( struct cons_pointer previous,
|
|||
struct cons_pointer make_special_frame( struct cons_pointer previous,
|
||||
struct cons_pointer args,
|
||||
struct cons_pointer env ) {
|
||||
fputws( L"Entering make_special_frame\n", stderr );
|
||||
debug_print( L"Entering make_special_frame\n", DEBUG_ALLOC );
|
||||
|
||||
struct cons_pointer result = make_empty_frame( previous );
|
||||
|
||||
|
|
@ -213,12 +227,11 @@ struct cons_pointer make_special_frame( struct cons_pointer previous,
|
|||
frame->more = args;
|
||||
inc_ref( args );
|
||||
}
|
||||
#ifdef DEBUG
|
||||
dump_frame( stderr, result );
|
||||
#endif
|
||||
|
||||
debug_dump_object( result, DEBUG_ALLOC );
|
||||
}
|
||||
}
|
||||
fputws( L"Leaving make_special_frame\n", stderr );
|
||||
debug_print( L"Leaving make_special_frame\n", DEBUG_ALLOC );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,13 +33,13 @@
|
|||
/**
|
||||
* is this vector-space object a stack frame?
|
||||
*/
|
||||
#define stackframep(vso)(vso->header.tag.value == STACKFRAMETV)
|
||||
#define stackframep(vso)(((struct vector_space_object *)vso)->header.tag.value == STACKFRAMETV)
|
||||
|
||||
/**
|
||||
* set a register in a stack frame. Alwaye use this macro to do so,
|
||||
• because that way we can be sure the inc_ref happens!
|
||||
*/
|
||||
#define set_reg(frame,register,value)frame->arg[register]=value; inc_ref(value)
|
||||
#define set_reg(frame,register,value){frame->arg[register]=value; inc_ref(value);}
|
||||
|
||||
struct stack_frame *get_stack_frame( struct cons_pointer pointer );
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "conspage.h"
|
||||
#include "consspaceobject.h"
|
||||
#include "dump.h"
|
||||
#include "vectorspace.h"
|
||||
|
||||
|
||||
|
|
@ -30,19 +31,18 @@
|
|||
* NOTE that `tag` should be the vector-space tag of the particular type of
|
||||
* vector-space object, NOT `VECTORPOINTTAG`.
|
||||
*/
|
||||
struct cons_pointer make_vec_pointer( char *tag,
|
||||
struct vector_space_object *address ) {
|
||||
struct cons_pointer make_vec_pointer( struct vector_space_object *address ) {
|
||||
fputws( L"Entered make_vec_pointer\n", stderr );
|
||||
struct cons_pointer pointer = allocate_cell( VECTORPOINTTAG );
|
||||
struct cons_space_object cell = pointer2cell( pointer );
|
||||
struct cons_space_object *cell = &pointer2cell( pointer );
|
||||
fwprintf( stderr,
|
||||
L"make_vec_pointer: allocated cell, about to write tag '%s'\n",
|
||||
tag );
|
||||
strncpy( &cell.payload.vectorp.tag.bytes[0], tag, 4 );
|
||||
fputws( L"make_vec_pointer: tag written, about to set pointer address\n",
|
||||
stderr );
|
||||
cell.payload.vectorp.address = address;
|
||||
fputws( L"make_vec_pointer: all good, returning\n", stderr );
|
||||
L"make_vec_pointer: tag written, about to set pointer address to %p\n",
|
||||
address );
|
||||
cell->payload.vectorp.address = address;
|
||||
fwprintf( stderr, L"make_vec_pointer: all good, returning pointer to %p\n",
|
||||
cell->payload.vectorp.address );
|
||||
|
||||
dump_object( stderr, pointer );
|
||||
|
||||
return pointer;
|
||||
}
|
||||
|
|
@ -66,24 +66,32 @@ struct cons_pointer make_vso( char *tag, uint64_t payload_size ) {
|
|||
struct vector_space_object *vso = malloc( padded );
|
||||
|
||||
if ( vso != NULL ) {
|
||||
fwprintf( stderr, L"make_vso: about to write tag '%s'\n", tag );
|
||||
fwprintf( stderr,
|
||||
L"make_vso: about to write tag '%s' into vso at %p\n", tag,
|
||||
vso );
|
||||
strncpy( &vso->header.tag.bytes[0], tag, TAGLENGTH );
|
||||
vso->header.vecp = make_vec_pointer( tag, vso );
|
||||
result = make_vec_pointer( vso );
|
||||
dump_object( stderr, result );
|
||||
vso->header.vecp = result;
|
||||
// memcpy(vso->header.vecp, result, sizeof(struct cons_pointer));
|
||||
|
||||
vso->header.size = payload_size;
|
||||
|
||||
#ifdef DEBUG
|
||||
fwprintf( stderr,
|
||||
L"Allocated vector-space object of type %4.4s, total size %ld, payload size %ld\n",
|
||||
tag, total_size, payload_size );
|
||||
L"Allocated vector-space object of type %4.4s, total size %ld, payload size %ld, at address %p, payload address %p\n",
|
||||
&vso->header.tag.bytes, total_size, vso->header.size, vso,
|
||||
&vso->payload );
|
||||
if ( padded != total_size ) {
|
||||
fwprintf( stderr, L"\t\tPadded from %d to %d\n",
|
||||
total_size, padded );
|
||||
}
|
||||
#endif
|
||||
|
||||
result = vso->header.vecp;
|
||||
}
|
||||
fputws( L"make_vso: all good, returning\n", stderr );
|
||||
#ifdef DEBUG
|
||||
fwprintf( stderr, L"make_vso: all good, returning pointer to %p\n",
|
||||
pointer2cell( result ).payload.vectorp.address );
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
#define VECTORTAG "VECT"
|
||||
#define VECTORTV 0
|
||||
|
||||
#define pointer_to_vso(pointer)((vectorpointp(pointer)? pointer2cell(pointer).payload.vectorp.address : NULL))
|
||||
#define pointer_to_vso(pointer)((vectorpointp(pointer)? (struct vector_space_object *) pointer2cell(pointer).payload.vectorp.address : (struct vector_space_object *) NULL))
|
||||
#define vso_get_vecp(vso)((vso->header.vecp))
|
||||
|
||||
struct cons_pointer make_vso( char *tag, uint64_t payload_size );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue