Reorganised source files to make navigation easier
All tests still pass (slightly to my surprise)
This commit is contained in:
parent
f6ff403249
commit
a5e1d3ccd8
|
@ -132,10 +132,10 @@ struct cons_pointer simplify_ratio( struct stack_frame *frame,
|
|||
struct cons_pointer arg ) {
|
||||
struct cons_pointer result = arg;
|
||||
long int ddrv =
|
||||
pointer2cell( pointer2cell( arg ).payload.ratio.dividend ).payload.
|
||||
integer.value, drrv =
|
||||
pointer2cell( pointer2cell( arg ).payload.ratio.divisor ).payload.
|
||||
integer.value, gcd = greatest_common_divisor( ddrv, drrv );
|
||||
pointer2cell( pointer2cell( arg ).payload.ratio.dividend ).
|
||||
payload.integer.value, drrv =
|
||||
pointer2cell( pointer2cell( arg ).payload.ratio.divisor ).
|
||||
payload.integer.value, gcd = greatest_common_divisor( ddrv, drrv );
|
||||
|
||||
if ( gcd > 1 ) {
|
||||
if ( drrv / gcd == 1 ) {
|
||||
|
@ -561,8 +561,8 @@ struct cons_pointer inverse( struct stack_frame *frame,
|
|||
case RATIOTV:
|
||||
result = make_ratio( frame,
|
||||
make_integer( 0 -
|
||||
to_long_int( cell.payload.ratio.
|
||||
dividend ) ),
|
||||
to_long_int( cell.payload.
|
||||
ratio.dividend ) ),
|
||||
cell.payload.ratio.divisor );
|
||||
break;
|
||||
case REALTV:
|
||||
|
@ -692,10 +692,10 @@ struct cons_pointer divide_ratio_ratio( struct stack_frame *frame,
|
|||
struct cons_pointer arg1,
|
||||
struct cons_pointer arg2 ) {
|
||||
struct cons_pointer i = make_ratio( frame,
|
||||
pointer2cell( arg2 ).payload.ratio.
|
||||
divisor,
|
||||
pointer2cell( arg2 ).payload.ratio.
|
||||
dividend ), result =
|
||||
pointer2cell( arg2 ).payload.
|
||||
ratio.divisor,
|
||||
pointer2cell( arg2 ).payload.
|
||||
ratio.dividend ), result =
|
||||
multiply_ratio_ratio( frame, arg1, i );
|
||||
|
||||
dec_ref( i );
|
||||
|
@ -727,7 +727,8 @@ struct cons_pointer lisp_divide( struct
|
|||
result = frame->arg[1];
|
||||
break;
|
||||
case INTEGERTV:{
|
||||
struct cons_pointer unsimplified = make_ratio( frame, frame->arg[0], frame->arg[1] );
|
||||
struct cons_pointer unsimplified =
|
||||
make_ratio( frame, frame->arg[0], frame->arg[1] );
|
||||
result = simplify_ratio( frame, unsimplified );
|
||||
if ( !eq( unsimplified, result ) ) {
|
||||
dec_ref( unsimplified );
|
||||
|
@ -764,7 +765,8 @@ struct cons_pointer lisp_divide( struct
|
|||
struct cons_pointer one = make_integer( 1 );
|
||||
struct cons_pointer ratio =
|
||||
make_ratio( frame, frame->arg[1], one );
|
||||
result = divide_ratio_ratio( frame, frame->arg[0], ratio );
|
||||
result =
|
||||
divide_ratio_ratio( frame, frame->arg[0], ratio );
|
||||
dec_ref( ratio );
|
||||
}
|
||||
break;
|
|
@ -163,7 +163,8 @@ void free_cell( struct cons_pointer pointer ) {
|
|||
/* 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", cell->payload.vectorp.address);
|
||||
fwprintf( stderr, L"About to free vector-space object at %ld\n",
|
||||
cell->payload.vectorp.address );
|
||||
#endif
|
||||
free( ( void * ) cell->payload.vectorp.address );
|
||||
break;
|
|
@ -136,10 +136,10 @@ void dump_object( FILE * output, struct cons_pointer pointer ) {
|
|||
case RATIOTV:
|
||||
fwprintf( output,
|
||||
L"\t\tRational cell: value %ld/%ld, count %u\n",
|
||||
pointer2cell( cell.payload.ratio.dividend ).payload.
|
||||
integer.value,
|
||||
pointer2cell( cell.payload.ratio.divisor ).payload.
|
||||
integer.value, cell.count );
|
||||
pointer2cell( cell.payload.ratio.dividend ).
|
||||
payload.integer.value,
|
||||
pointer2cell( cell.payload.ratio.divisor ).
|
||||
payload.integer.value, cell.count );
|
||||
break;
|
||||
case READTV:
|
||||
fwprintf( output, L"\t\tInput stream\n" );
|
|
@ -52,12 +52,13 @@ struct cons_pointer make_vso( char *tag, long int payload_size) {
|
|||
struct vector_space_header *vso = malloc( total_size );
|
||||
|
||||
if ( vso != NULL ) {
|
||||
strncpy( vso->tag.bytes[0], tag, TAGLENGTH );
|
||||
strncpy( &vso->tag.bytes[0], tag, TAGLENGTH );
|
||||
vso->vecp = make_vec_pointer( tag, ( uint64_t ) vso );
|
||||
vso->size = payload_size;
|
||||
|
||||
#ifdef DEBUG
|
||||
fwprintf(stderr, L"Allocated vector-space object of type %s, total size %ld, payload size %ld\n",
|
||||
fwprintf( stderr,
|
||||
L"Allocated vector-space object of type %s, total size %ld, payload size %ld\n",
|
||||
tag, total_size, payload_size );
|
||||
#endif
|
||||
|
||||
|
@ -66,4 +67,3 @@ struct cons_pointer make_vso( char *tag, long int payload_size) {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -66,5 +66,3 @@ struct vector_space_header {
|
|||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -80,8 +80,8 @@ bool equal( struct cons_pointer a, struct cons_pointer b ) {
|
|||
&& ( equal( cell_a->payload.string.cdr,
|
||||
cell_b->payload.string.cdr )
|
||||
|| ( end_of_string( cell_a->payload.string.cdr )
|
||||
&& end_of_string( cell_b->payload.string.
|
||||
cdr ) ) );
|
||||
&& end_of_string( cell_b->payload.
|
||||
string.cdr ) ) );
|
||||
break;
|
||||
case INTEGERTV:
|
||||
result =
|
|
@ -132,8 +132,8 @@ struct cons_pointer print( FILE * output, struct cons_pointer pointer ) {
|
|||
case LAMBDATV:
|
||||
print( output, make_cons( c_string_to_lisp_symbol( "lambda" ),
|
||||
make_cons( cell.payload.lambda.args,
|
||||
cell.payload.
|
||||
lambda.body ) ) );
|
||||
cell.payload.lambda.
|
||||
body ) ) );
|
||||
break;
|
||||
case NILTV:
|
||||
fwprintf( output, L"nil" );
|
||||
|
@ -141,8 +141,8 @@ struct cons_pointer print( FILE * output, struct cons_pointer pointer ) {
|
|||
case NLAMBDATV:
|
||||
print( output, make_cons( c_string_to_lisp_symbol( "nlambda" ),
|
||||
make_cons( cell.payload.lambda.args,
|
||||
cell.payload.
|
||||
lambda.body ) ) );
|
||||
cell.payload.lambda.
|
||||
body ) ) );
|
||||
break;
|
||||
case RATIOTV:
|
||||
print( output, cell.payload.ratio.dividend );
|
Loading…
Reference in a new issue