Whitespace changes only - trying to keep the format regular

This commit is contained in:
simon 2017-09-14 19:02:03 +01:00
parent e43c9a7b33
commit 79f7492390
13 changed files with 131 additions and 133 deletions

View file

@ -169,7 +169,7 @@ struct cons_pointer allocate_cell( char *tag ) {
"Allocated cell of type '%s' at %d, %d \n", tag, "Allocated cell of type '%s' at %d, %d \n", tag,
result.page, result.offset ); result.page, result.offset );
#endif #endif
} else { } else {
fprintf( stderr, "WARNING: Allocating non-free cell!" ); fprintf( stderr, "WARNING: Allocating non-free cell!" );
} }
} }
@ -190,6 +190,6 @@ void initialise_cons_pages( ) {
conspageinitihasbeencalled = true; conspageinitihasbeencalled = true;
} else { } else {
fwprintf( stderr, fwprintf( stderr,
L"WARNING: initialise_cons_pages() called a second or subsequent time\n" ); L"WARNING: initialise_cons_pages() called a second or subsequent time\n" );
} }
} }

View file

@ -74,7 +74,7 @@ void dump_object( FILE * output, struct cons_pointer pointer ) {
cell.tag.bytes[3], cell.tag.bytes[3],
cell.tag.value, pointer.page, pointer.offset, cell.count ); cell.tag.value, pointer.page, pointer.offset, cell.count );
switch ( cell.tag.value) { switch ( cell.tag.value ) {
case CONSTV: case CONSTV:
fwprintf( output, fwprintf( output,
L"\t\tCons cell: car at page %d offset %d, cdr at page %d offset %d\n", L"\t\tCons cell: car at page %d offset %d, cdr at page %d offset %d\n",
@ -101,9 +101,9 @@ void dump_object( FILE * output, struct cons_pointer pointer ) {
cell.payload.string.character, cell.payload.string.character,
cell.payload.string.cdr.page, cell.payload.string.cdr.page,
cell.payload.string.cdr.offset ); cell.payload.string.cdr.offset );
fwprintf( output, L"\t\t value:"); fwprintf( output, L"\t\t value:" );
print(output, pointer); print( output, pointer );
fwprintf( output, L"\n"); fwprintf( output, L"\n" );
break; break;
case SYMBOLTV: case SYMBOLTV:
fwprintf( output, fwprintf( output,
@ -111,9 +111,9 @@ void dump_object( FILE * output, struct cons_pointer pointer ) {
cell.payload.string.character, cell.payload.string.character,
cell.payload.string.cdr.page, cell.payload.string.cdr.page,
cell.payload.string.cdr.offset ); cell.payload.string.cdr.offset );
fwprintf( output, L"\t\t value:"); fwprintf( output, L"\t\t value:" );
print(output, pointer); print( output, pointer );
fwprintf( output, L"\n"); fwprintf( output, L"\n" );
break; break;
} }
} }

View file

@ -25,15 +25,15 @@
void bind_function( char *name, struct cons_pointer ( *executable ) void bind_function( char *name, struct cons_pointer ( *executable )
( struct stack_frame *, struct cons_pointer ) ) { ( struct stack_frame *, struct cons_pointer ) ) {
deep_bind( c_string_to_lisp_symbol( name ), deep_bind( c_string_to_lisp_symbol( name ),
make_function( NIL, executable )); make_function( NIL, executable ) );
} }
void bind_special( char *name, struct cons_pointer ( *executable ) void bind_special( char *name, struct cons_pointer ( *executable )
( struct cons_pointer s_expr, struct cons_pointer env, ( struct cons_pointer s_expr, struct cons_pointer env,
struct stack_frame * frame ) ) { struct stack_frame * frame ) ) {
deep_bind( c_string_to_lisp_symbol( name ), deep_bind( c_string_to_lisp_symbol( name ),
make_special( NIL, executable )); make_special( NIL, executable ) );
} }
int main( int argc, char *argv[] ) { int main( int argc, char *argv[] ) {
@ -63,8 +63,8 @@ int main( int argc, char *argv[] ) {
if ( show_prompt ) { if ( show_prompt ) {
fwprintf( stdout, fwprintf( stdout,
L"Post scarcity software environment version %s\n\n", L"Post scarcity software environment version %s\n\n",
VERSION ); VERSION );
} }
initialise_cons_pages( ); initialise_cons_pages( );
@ -72,7 +72,7 @@ int main( int argc, char *argv[] ) {
/* /*
* privileged variables (keywords) * privileged variables (keywords)
*/ */
deep_bind( c_string_to_lisp_symbol( "nil" ), NIL ); deep_bind( c_string_to_lisp_symbol( "nil" ), NIL );
deep_bind( c_string_to_lisp_symbol( "t" ), TRUE ); deep_bind( c_string_to_lisp_symbol( "t" ), TRUE );
@ -87,10 +87,10 @@ int main( int argc, char *argv[] ) {
bind_function( "equal", &lisp_equal ); bind_function( "equal", &lisp_equal );
bind_function( "read", &lisp_read ); bind_function( "read", &lisp_read );
bind_function( "print", &lisp_print ); bind_function( "print", &lisp_print );
bind_function( "add", &lisp_add); bind_function( "add", &lisp_add );
bind_function( "multiply", &lisp_multiply); bind_function( "multiply", &lisp_multiply );
bind_function( "subtract", &lisp_subtract); bind_function( "subtract", &lisp_subtract );
/* /*
* primitive special forms * primitive special forms
@ -98,12 +98,12 @@ int main( int argc, char *argv[] ) {
bind_special( "apply", &lisp_apply ); bind_special( "apply", &lisp_apply );
bind_special( "eval", &lisp_eval ); bind_special( "eval", &lisp_eval );
bind_special( "quote", &lisp_quote ); bind_special( "quote", &lisp_quote );
/* bind the oblist last, at this stage. Something clever needs to be done /* bind the oblist last, at this stage. Something clever needs to be done
* here and I'm not sure what it is. */ * here and I'm not sure what it is. */
deep_bind( c_string_to_lisp_symbol( "oblist"), oblist); deep_bind( c_string_to_lisp_symbol( "oblist" ), oblist );
repl( stdin, stdout, stderr, show_prompt ); repl( stdin, stdout, stderr, show_prompt );
if ( dump_at_end ) { if ( dump_at_end ) {

View file

@ -91,7 +91,7 @@ struct cons_pointer c_assoc( struct cons_pointer key,
* Return a new key/value store containing all the key/value pairs in this store * Return a new key/value store containing all the key/value pairs in this store
* with this key/value pair added to the front. * with this key/value pair added to the front.
*/ */
struct cons_pointer struct cons_pointer
bind( struct cons_pointer key, struct cons_pointer value, bind( struct cons_pointer key, struct cons_pointer value,
struct cons_pointer store ) { struct cons_pointer store ) {
return make_cons( make_cons( key, value ), store ); return make_cons( make_cons( key, value ), store );

View file

@ -166,7 +166,7 @@ lisp_eval( struct cons_pointer s_expr, struct cons_pointer env,
switch ( cell.tag.value ) { switch ( cell.tag.value ) {
case CONSTV: case CONSTV:
result = eval_cons( s_expr, env, previous); result = eval_cons( s_expr, env, previous );
break; break;
case SYMBOLTV: case SYMBOLTV:
@ -355,7 +355,7 @@ lisp_throw( struct cons_pointer message, struct stack_frame *frame ) {
fwprintf( stderr, L"\nERROR: " ); fwprintf( stderr, L"\nERROR: " );
print( stderr, message ); print( stderr, message );
fwprintf( stderr, fwprintf( stderr,
L"\n\nAn exception was thrown and I've no idea what to do now\n" ); L"\n\nAn exception was thrown and I've no idea what to do now\n" );
exit( 1 ); exit( 1 );
} }

View file

@ -32,43 +32,41 @@
* @return a pointer to an integer or real. * @return a pointer to an integer or real.
*/ */
struct cons_pointer struct cons_pointer
lisp_add(struct stack_frame *frame, struct cons_pointer env) { lisp_add( struct stack_frame *frame, struct cons_pointer env ) {
struct cons_pointer result = NIL; struct cons_pointer result = NIL;
long int i_accumulator = 0; long int i_accumulator = 0;
long double d_accumulator = 0; long double d_accumulator = 0;
bool is_int = true; bool is_int = true;
for (int i = 0; i < args_in_frame && !nilp(frame->arg[i]); i++) { for ( int i = 0; i < args_in_frame && !nilp( frame->arg[i] ); i++ ) {
struct cons_space_object arg = pointer2cell(frame->arg[i]); struct cons_space_object arg = pointer2cell( frame->arg[i] );
switch (arg.tag.value) { switch ( arg.tag.value ) {
case INTEGERTV: case INTEGERTV:
i_accumulator += arg.payload.integer.value; i_accumulator += arg.payload.integer.value;
d_accumulator += numeric_value( frame->arg[i]); d_accumulator += numeric_value( frame->arg[i] );
break; break;
case REALTV: case REALTV:
d_accumulator += arg.payload.real.value; d_accumulator += arg.payload.real.value;
is_int = false; is_int = false;
default: default:
lisp_throw( lisp_throw( c_string_to_lisp_string( "Cannot add: not a number" ),
c_string_to_lisp_string("Cannot add: not a number"), frame );
frame);
}
if (! nilp(frame->more)) {
lisp_throw(
c_string_to_lisp_string("Cannot yet add more than 8 numbers"),
frame);
} }
if ( is_int) { if ( !nilp( frame->more ) ) {
result = make_integer( i_accumulator); lisp_throw( c_string_to_lisp_string
( "Cannot yet add more than 8 numbers" ), frame );
}
if ( is_int ) {
result = make_integer( i_accumulator );
} else { } else {
result = make_real( d_accumulator); result = make_real( d_accumulator );
} }
} }
return result; return result;
} }
/** /**
@ -78,43 +76,41 @@ lisp_add(struct stack_frame *frame, struct cons_pointer env) {
* @return a pointer to an integer or real. * @return a pointer to an integer or real.
*/ */
struct cons_pointer struct cons_pointer
lisp_multiply(struct stack_frame *frame, struct cons_pointer env) { lisp_multiply( struct stack_frame *frame, struct cons_pointer env ) {
struct cons_pointer result = NIL; struct cons_pointer result = NIL;
long int i_accumulator = 1; long int i_accumulator = 1;
long double d_accumulator = 1; long double d_accumulator = 1;
bool is_int = true; bool is_int = true;
for (int i = 0; i < args_in_frame && !nilp(frame->arg[i]); i++) { for ( int i = 0; i < args_in_frame && !nilp( frame->arg[i] ); i++ ) {
struct cons_space_object arg = pointer2cell(frame->arg[i]); struct cons_space_object arg = pointer2cell( frame->arg[i] );
switch (arg.tag.value) { switch ( arg.tag.value ) {
case INTEGERTV: case INTEGERTV:
i_accumulator *= arg.payload.integer.value; i_accumulator *= arg.payload.integer.value;
d_accumulator *= numeric_value( frame->arg[i]); d_accumulator *= numeric_value( frame->arg[i] );
break; break;
case REALTV: case REALTV:
d_accumulator *= arg.payload.real.value; d_accumulator *= arg.payload.real.value;
is_int = false; is_int = false;
default: default:
lisp_throw( lisp_throw( c_string_to_lisp_string
c_string_to_lisp_string("Cannot multiply: not a number"), ( "Cannot multiply: not a number" ), frame );
frame);
}
if (! nilp(frame->more)) {
lisp_throw(
c_string_to_lisp_string("Cannot yet multiply more than 8 numbers"),
frame);
} }
if ( is_int) { if ( !nilp( frame->more ) ) {
result = make_integer( i_accumulator); lisp_throw( c_string_to_lisp_string
( "Cannot yet multiply more than 8 numbers" ), frame );
}
if ( is_int ) {
result = make_integer( i_accumulator );
} else { } else {
result = make_real( d_accumulator); result = make_real( d_accumulator );
} }
} }
return result; return result;
} }
/** /**
@ -124,26 +120,30 @@ lisp_multiply(struct stack_frame *frame, struct cons_pointer env) {
* @return a pointer to an integer or real. * @return a pointer to an integer or real.
*/ */
struct cons_pointer struct cons_pointer
lisp_subtract(struct stack_frame *frame, struct cons_pointer env) { lisp_subtract( struct stack_frame *frame, struct cons_pointer env ) {
struct cons_pointer result = NIL; struct cons_pointer result = NIL;
struct cons_space_object arg0 = pointer2cell(frame->arg[0]);
struct cons_space_object arg1 = pointer2cell(frame->arg[1]);
if ( integerp(frame->arg[0]) && integerp(frame->arg[1])) { struct cons_space_object arg0 = pointer2cell( frame->arg[0] );
result = make_integer(arg0.payload.integer.value - arg1.payload.integer.value); struct cons_space_object arg1 = pointer2cell( frame->arg[1] );
} else if ( realp(frame->arg[0]) && realp(frame->arg[1])) {
result = make_real(arg0.payload.real.value - arg1.payload.real.value); if ( integerp( frame->arg[0] ) && integerp( frame->arg[1] ) ) {
} else if (integerp(frame->arg[0]) && realp(frame->arg[1])) { result =
result = make_real( numeric_value(frame->arg[0]) - arg1.payload.real.value); make_integer( arg0.payload.integer.value -
} else if (realp(frame->arg[0]) && integerp(frame->arg[1])) { arg1.payload.integer.value );
result = make_real( arg0.payload.real.value - numeric_value(frame->arg[0])); } else if ( realp( frame->arg[0] ) && realp( frame->arg[1] ) ) {
} // else we have an error! result =
make_real( arg0.payload.real.value - arg1.payload.real.value );
} else if ( integerp( frame->arg[0] ) && realp( frame->arg[1] ) ) {
result =
make_real( numeric_value( frame->arg[0] ) -
arg1.payload.real.value );
} else if ( realp( frame->arg[0] ) && integerp( frame->arg[1] ) ) {
result =
make_real( arg0.payload.real.value -
numeric_value( frame->arg[0] ) );
} // else we have an error!
// and if not nilp[frame->arg[2]) we also have an error. // and if not nilp[frame->arg[2]) we also have an error.
return result; return result;
} }

View file

@ -22,8 +22,8 @@ extern "C" {
* @param frame the stack frame. * @param frame the stack frame.
* @return a pointer to an integer or real. * @return a pointer to an integer or real.
*/ */
struct cons_pointer struct cons_pointer
lisp_add(struct stack_frame *frame, struct cons_pointer env); lisp_add( struct stack_frame *frame, struct cons_pointer env );
/** /**
* Multiply an indefinite number of numbers together * Multiply an indefinite number of numbers together
@ -31,8 +31,8 @@ lisp_add(struct stack_frame *frame, struct cons_pointer env);
* @param frame the stack frame. * @param frame the stack frame.
* @return a pointer to an integer or real. * @return a pointer to an integer or real.
*/ */
struct cons_pointer struct cons_pointer
lisp_multiply(struct stack_frame *frame, struct cons_pointer env); lisp_multiply( struct stack_frame *frame, struct cons_pointer env );
/** /**
* Subtract one number from another. * Subtract one number from another.
@ -40,12 +40,10 @@ lisp_multiply(struct stack_frame *frame, struct cons_pointer env);
* @param frame the stack frame. * @param frame the stack frame.
* @return a pointer to an integer or real. * @return a pointer to an integer or real.
*/ */
struct cons_pointer struct cons_pointer
lisp_subtract(struct stack_frame *frame, struct cons_pointer env); lisp_subtract( struct stack_frame *frame, struct cons_pointer env );
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* PEANO_H */
#endif /* PEANO_H */

View file

@ -101,10 +101,10 @@ void print( FILE * output, struct cons_pointer pointer ) {
fwprintf( output, L"t" ); fwprintf( output, L"t" );
break; break;
case FUNCTIONTV: case FUNCTIONTV:
fwprintf( output, L"(Function)"); fwprintf( output, L"(Function)" );
break; break;
case SPECIALTV: case SPECIALTV:
fwprintf( output, L"(Special form)"); fwprintf( output, L"(Special form)" );
break; break;
default: default:
fwprintf( stderr, fwprintf( stderr,

View file

@ -82,7 +82,7 @@ struct cons_pointer read_continuation( FILE * input, wint_t initial ) {
* read a number from this input stream, given this initial character. * read a number from this input stream, given this initial character.
*/ */
struct cons_pointer read_number( FILE * input, wint_t initial ) { struct cons_pointer read_number( FILE * input, wint_t initial ) {
struct cons_pointer result = NIL; struct cons_pointer result = NIL;
long int accumulator = 0; long int accumulator = 0;
int places_of_decimals = 0; int places_of_decimals = 0;
bool seen_period = false; bool seen_period = false;
@ -98,7 +98,7 @@ struct cons_pointer read_number( FILE * input, wint_t initial ) {
accumulator = accumulator * 10 + ( ( int ) c - ( int ) '0' ); accumulator = accumulator * 10 + ( ( int ) c - ( int ) '0' );
fwprintf( stderr, L"Added character %c, accumulator now %ld\n", c, fwprintf( stderr, L"Added character %c, accumulator now %ld\n", c,
accumulator ); accumulator );
if ( seen_period ) { if ( seen_period ) {
places_of_decimals++; places_of_decimals++;
@ -112,11 +112,11 @@ struct cons_pointer read_number( FILE * input, wint_t initial ) {
ungetwc( c, input ); ungetwc( c, input );
if ( seen_period ) { if ( seen_period ) {
long double rv = (long double) long double rv = ( long double )
( accumulator / pow(10, places_of_decimals) ); ( accumulator / pow( 10, places_of_decimals ) );
fwprintf( stderr, L"read_numer returning %Lf\n", rv); fwprintf( stderr, L"read_numer returning %Lf\n", rv );
result = make_real( rv); result = make_real( rv );
} else { } else {
result = make_integer( accumulator ); result = make_integer( accumulator );
} }
@ -203,7 +203,7 @@ struct cons_pointer read_symbol( FILE * input, wint_t initial ) {
* push back the character read * push back the character read
*/ */
ungetwc( initial, input ); ungetwc( initial, input );
} }
break; break;
} }

View file

@ -24,7 +24,7 @@ extern "C" {
* @param value the value to wrap; * @param value the value to wrap;
* @return a real number cell wrapping this value. * @return a real number cell wrapping this value.
*/ */
struct cons_pointer make_real( double value ); struct cons_pointer make_real( double value );
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -31,13 +31,13 @@ repl( FILE * in_stream, FILE * out_stream, FILE * error_stream,
struct cons_pointer input = read( in_stream ); struct cons_pointer input = read( in_stream );
fwprintf( error_stream, L"\nread {%d,%d}=> ", input.page, fwprintf( error_stream, L"\nread {%d,%d}=> ", input.page,
input.offset ); input.offset );
print( error_stream, input); print( error_stream, input );
struct cons_pointer value = lisp_eval( input, oblist, NULL ); struct cons_pointer value = lisp_eval( input, oblist, NULL );
// print( out_stream, input ); // print( out_stream, input );
fwprintf( out_stream, L"\n" ); fwprintf( out_stream, L"\n" );
fwprintf( error_stream, L"\neval {%d,%d}=> ", input.page, fwprintf( error_stream, L"\neval {%d,%d}=> ", input.page,
input.offset ); input.offset );
print( out_stream, value); print( out_stream, value );
} }
} }

View file

@ -51,27 +51,27 @@ struct stack_frame *make_stack_frame( struct stack_frame *previous,
result->arg[i] = NIL; result->arg[i] = NIL;
} }
for (int i = 0; i < args_in_frame && !nilp( args ); i++ ) { for ( int i = 0; i < args_in_frame && !nilp( args ); i++ ) {
/* iterate down the arg list filling in the arg slots in the /* iterate down the arg list filling in the arg slots in the
* frame. When there are no more slots, if there are still args, * frame. When there are no more slots, if there are still args,
* stash them on more */ * stash them on more */
struct cons_space_object cell = pointer2cell( args ); struct cons_space_object cell = pointer2cell( args );
/* /*
* TODO: if we were running on real massively parallel hardware, * TODO: if we were running on real massively parallel hardware,
* each arg except the first should be handed off to another * each arg except the first should be handed off to another
* processor to be evaled in parallel * processor to be evaled in parallel
*/ */
result->arg[i] = lisp_eval( cell.payload.cons.car, env, result ); result->arg[i] = lisp_eval( cell.payload.cons.car, env, result );
inc_ref( result->arg[i] ); inc_ref( result->arg[i] );
args = cell.payload.cons.cdr; args = cell.payload.cons.cdr;
} }
/* /*
* TODO: this isn't right. These args should also each be evaled. * TODO: this isn't right. These args should also each be evaled.
*/ */
result->more = args; result->more = args;
inc_ref( result->more ); inc_ref( result->more );
return result; return result;
} }
@ -85,8 +85,8 @@ struct stack_frame *make_stack_frame( struct stack_frame *previous,
* @return a new special frame. * @return a new special frame.
*/ */
struct stack_frame *make_special_frame( struct stack_frame *previous, struct stack_frame *make_special_frame( struct stack_frame *previous,
struct cons_pointer args, struct cons_pointer args,
struct cons_pointer env ) { struct cons_pointer env ) {
/* /*
* TODO: later, pop a frame off a free-list of stack frames * TODO: later, pop a frame off a free-list of stack frames
*/ */
@ -105,10 +105,10 @@ struct stack_frame *make_special_frame( struct stack_frame *previous,
result->arg[i] = NIL; result->arg[i] = NIL;
} }
for (int i = 0; i < args_in_frame && !nilp( args ); i++ ) { for ( int i = 0; i < args_in_frame && !nilp( args ); i++ ) {
/* iterate down the arg list filling in the arg slots in the /* iterate down the arg list filling in the arg slots in the
* frame. When there are no more slots, if there are still args, * frame. When there are no more slots, if there are still args,
* stash them on more */ * stash them on more */
struct cons_space_object cell = pointer2cell( args ); struct cons_space_object cell = pointer2cell( args );
result->arg[i] = cell.payload.cons.car; result->arg[i] = cell.payload.cons.car;
@ -117,7 +117,7 @@ struct stack_frame *make_special_frame( struct stack_frame *previous,
args = cell.payload.cons.cdr; args = cell.payload.cons.cdr;
} }
result->more = args; result->more = args;
inc_ref(args); inc_ref( args );
return result; return result;
} }

View file

@ -39,8 +39,8 @@ struct cons_pointer fetch_arg( struct stack_frame *frame, unsigned int n );
* @return a new special frame. * @return a new special frame.
*/ */
struct stack_frame *make_special_frame( struct stack_frame *previous, struct stack_frame *make_special_frame( struct stack_frame *previous,
struct cons_pointer args, struct cons_pointer args,
struct cons_pointer env ); struct cons_pointer env );
/* /*
* struct stack_frame is defined in consspaceobject.h to break circularity * struct stack_frame is defined in consspaceobject.h to break circularity