Begun work on bignums; changed integer size to 64 bits
I'm fairly sure the size of a long int on my machines is 64 bit anyway, but for portability it needs to be explicit.
This commit is contained in:
parent
ad9b1cd7f8
commit
6ee9f9b59a
13 changed files with 109 additions and 25 deletions
|
|
@ -127,8 +127,10 @@ 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
|
||||
|
||||
switch ( cell->tag.value ) {
|
||||
/* for all the types of cons-space object which point to other
|
||||
|
|
@ -173,7 +175,7 @@ void free_cell( struct cons_pointer pointer ) {
|
|||
|
||||
if ( !check_tag( pointer, FREETAG ) ) {
|
||||
if ( cell->count == 0 ) {
|
||||
strncpy( &cell->tag.bytes[0], FREETAG, 4 );
|
||||
strncpy( &cell->tag.bytes[0], FREETAG, TAGLENGTH );
|
||||
cell->payload.free.car = NIL;
|
||||
cell->payload.free.cdr = freelist;
|
||||
freelist = pointer;
|
||||
|
|
@ -209,7 +211,7 @@ struct cons_pointer allocate_cell( char *tag ) {
|
|||
if ( strncmp( &cell->tag.bytes[0], FREETAG, TAGLENGTH ) == 0 ) {
|
||||
freelist = cell->payload.free.cdr;
|
||||
|
||||
strncpy( &cell->tag.bytes[0], tag, 4 );
|
||||
strncpy( &cell->tag.bytes[0], tag, TAGLENGTH );
|
||||
|
||||
cell->count = 0;
|
||||
cell->payload.cons.car = NIL;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,13 @@
|
|||
/**
|
||||
* tag values, all of which must be 4 bytes. Must not collide with vector space tag values
|
||||
*/
|
||||
|
||||
/**
|
||||
* A word within a bignum - arbitrary precision integer.
|
||||
*/
|
||||
#define BIGNUMTAG "BIGN"
|
||||
#define BIGNUMTV 1313294658
|
||||
|
||||
/**
|
||||
* An ordinary cons cell: 1397641027
|
||||
*/
|
||||
|
|
@ -38,7 +45,6 @@
|
|||
* An exception.
|
||||
*/
|
||||
#define EXCEPTIONTAG "EXEP"
|
||||
/* TODO: this is wrong */
|
||||
#define EXCEPTIONTV 1346721861
|
||||
|
||||
/**
|
||||
|
|
@ -162,6 +168,11 @@
|
|||
*/
|
||||
#define nilp(conspoint) (check_tag(conspoint,NILTAG))
|
||||
|
||||
/**
|
||||
* true if conspointer points to a cons cell, else false
|
||||
*/
|
||||
#define bignump(conspoint) (check_tag(conspoint,BIGNUMTAG))
|
||||
|
||||
/**
|
||||
* true if conspointer points to a cons cell, else false
|
||||
*/
|
||||
|
|
@ -221,7 +232,7 @@
|
|||
* true if conspointer points to some sort of a number cell,
|
||||
* else false
|
||||
*/
|
||||
#define numberp(conspoint) (check_tag(conspoint,INTEGERTAG)||check_tag(conspoint,RATIOTAG)||heck_tag(conspoint,REALTAG))
|
||||
#define numberp(conspoint) (check_tag(conspoint,INTEGERTAG)||check_tag(conspoint,RATIOTAG)||check_tag(conspoint,REALTAG)||check_tag(conspoint,BIGNUMTAG))
|
||||
|
||||
/**
|
||||
* true if thr conspointer points to a vector pointer.
|
||||
|
|
@ -274,6 +285,16 @@ struct stack_frame {
|
|||
struct cons_pointer function; /* the function to be called */
|
||||
};
|
||||
|
||||
/**
|
||||
* payload of a bignum cell. Intentionally similar to an integer payload, but
|
||||
* with a next pointer.
|
||||
*/
|
||||
struct bignum_payload {
|
||||
int64_t value;
|
||||
struct cons_pointer next;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* payload of a cons cell.
|
||||
*/
|
||||
|
|
@ -321,7 +342,7 @@ struct free_payload {
|
|||
* optional bignum object.
|
||||
*/
|
||||
struct integer_payload {
|
||||
long int value;
|
||||
int64_t value;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ struct cons_pointer make_vec_pointer( char *tag, uint64_t address ) {
|
|||
* NOTE that `tag` should be the vector-space tag of the particular type of
|
||||
* vector-space object, NOT `VECTORPOINTTAG`.
|
||||
*/
|
||||
struct cons_pointer make_vso( char *tag, long int payload_size ) {
|
||||
struct cons_pointer make_vso( char *tag, int64_t payload_size ) {
|
||||
struct cons_pointer result = NIL;
|
||||
long int total_size = sizeof( struct vector_space_header ) + payload_size;
|
||||
int64_t total_size = sizeof( struct vector_space_header ) + payload_size;
|
||||
|
||||
struct vector_space_header *vso = malloc( total_size );
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,11 @@
|
|||
#define NAMESPACETAG "NMSP"
|
||||
#define NAMESPACETV 0
|
||||
|
||||
/*
|
||||
* a stack frame.
|
||||
*/
|
||||
#define STACKFRAMETAG "STAK"
|
||||
#define STACKFRAMETV
|
||||
/*
|
||||
* a vector of cons pointers.
|
||||
*/
|
||||
|
|
@ -42,7 +47,7 @@
|
|||
|
||||
#define pointer_to_vso(pointer)(vectorpointp(pointer)? pointer2cell(pointer).payload.vectorp.address : 0)
|
||||
|
||||
struct cons_pointer make_vso( char *tag, long int payload_size );
|
||||
struct cons_pointer make_vso( char *tag, int64_t payload_size );
|
||||
|
||||
struct vector_space_header {
|
||||
union {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue