From 79f749239006042622b5936ba5e263fa008099d8 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 14 Sep 2017 19:02:03 +0100 Subject: [PATCH] Whitespace changes only - trying to keep the format regular --- src/conspage.c | 4 +- src/consspaceobject.c | 14 ++--- src/init.c | 28 +++++----- src/intern.c | 2 +- src/lispops.c | 4 +- src/peano.c | 118 +++++++++++++++++++++--------------------- src/peano.h | 16 +++--- src/print.c | 4 +- src/read.c | 14 ++--- src/real.h | 2 +- src/repl.c | 4 +- src/stack.c | 50 +++++++++--------- src/stack.h | 4 +- 13 files changed, 131 insertions(+), 133 deletions(-) diff --git a/src/conspage.c b/src/conspage.c index 7221ffc..0b03d53 100644 --- a/src/conspage.c +++ b/src/conspage.c @@ -169,7 +169,7 @@ struct cons_pointer allocate_cell( char *tag ) { "Allocated cell of type '%s' at %d, %d \n", tag, result.page, result.offset ); #endif - } else { + } else { fprintf( stderr, "WARNING: Allocating non-free cell!" ); } } @@ -190,6 +190,6 @@ void initialise_cons_pages( ) { conspageinitihasbeencalled = true; } else { 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" ); } } diff --git a/src/consspaceobject.c b/src/consspaceobject.c index c7889ed..2c12621 100644 --- a/src/consspaceobject.c +++ b/src/consspaceobject.c @@ -74,7 +74,7 @@ void dump_object( FILE * output, struct cons_pointer pointer ) { cell.tag.bytes[3], cell.tag.value, pointer.page, pointer.offset, cell.count ); - switch ( cell.tag.value) { + switch ( cell.tag.value ) { case CONSTV: fwprintf( output, 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.cdr.page, cell.payload.string.cdr.offset ); - fwprintf( output, L"\t\t value:"); - print(output, pointer); - fwprintf( output, L"\n"); + fwprintf( output, L"\t\t value:" ); + print( output, pointer ); + fwprintf( output, L"\n" ); break; case SYMBOLTV: fwprintf( output, @@ -111,9 +111,9 @@ void dump_object( FILE * output, struct cons_pointer pointer ) { cell.payload.string.character, cell.payload.string.cdr.page, cell.payload.string.cdr.offset ); - fwprintf( output, L"\t\t value:"); - print(output, pointer); - fwprintf( output, L"\n"); + fwprintf( output, L"\t\t value:" ); + print( output, pointer ); + fwprintf( output, L"\n" ); break; } } diff --git a/src/init.c b/src/init.c index a51e827..33e0a29 100644 --- a/src/init.c +++ b/src/init.c @@ -25,15 +25,15 @@ void bind_function( char *name, struct cons_pointer ( *executable ) ( struct stack_frame *, struct cons_pointer ) ) { - deep_bind( c_string_to_lisp_symbol( name ), - make_function( NIL, executable )); + deep_bind( c_string_to_lisp_symbol( name ), + make_function( NIL, executable ) ); } void bind_special( char *name, struct cons_pointer ( *executable ) ( struct cons_pointer s_expr, struct cons_pointer env, struct stack_frame * frame ) ) { deep_bind( c_string_to_lisp_symbol( name ), - make_special( NIL, executable )); + make_special( NIL, executable ) ); } int main( int argc, char *argv[] ) { @@ -63,8 +63,8 @@ int main( int argc, char *argv[] ) { if ( show_prompt ) { fwprintf( stdout, - L"Post scarcity software environment version %s\n\n", - VERSION ); + L"Post scarcity software environment version %s\n\n", + VERSION ); } initialise_cons_pages( ); @@ -72,7 +72,7 @@ int main( int argc, char *argv[] ) { /* * privileged variables (keywords) */ - + deep_bind( c_string_to_lisp_symbol( "nil" ), NIL ); 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( "read", &lisp_read ); bind_function( "print", &lisp_print ); - - bind_function( "add", &lisp_add); - bind_function( "multiply", &lisp_multiply); - bind_function( "subtract", &lisp_subtract); + + bind_function( "add", &lisp_add ); + bind_function( "multiply", &lisp_multiply ); + bind_function( "subtract", &lisp_subtract ); /* * primitive special forms @@ -98,12 +98,12 @@ int main( int argc, char *argv[] ) { bind_special( "apply", &lisp_apply ); bind_special( "eval", &lisp_eval ); bind_special( "quote", &lisp_quote ); - - + + /* bind the oblist last, at this stage. Something clever needs to be done * 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 ); if ( dump_at_end ) { diff --git a/src/intern.c b/src/intern.c index fae0b7a..31b7e2e 100644 --- a/src/intern.c +++ b/src/intern.c @@ -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 * with this key/value pair added to the front. */ -struct cons_pointer +struct cons_pointer bind( struct cons_pointer key, struct cons_pointer value, struct cons_pointer store ) { return make_cons( make_cons( key, value ), store ); diff --git a/src/lispops.c b/src/lispops.c index 073455f..c73914c 100644 --- a/src/lispops.c +++ b/src/lispops.c @@ -166,7 +166,7 @@ lisp_eval( struct cons_pointer s_expr, struct cons_pointer env, switch ( cell.tag.value ) { case CONSTV: - result = eval_cons( s_expr, env, previous); + result = eval_cons( s_expr, env, previous ); break; case SYMBOLTV: @@ -355,7 +355,7 @@ lisp_throw( struct cons_pointer message, struct stack_frame *frame ) { fwprintf( stderr, L"\nERROR: " ); print( stderr, message ); 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 ); } diff --git a/src/peano.c b/src/peano.c index 5f50280..9e5b1e2 100644 --- a/src/peano.c +++ b/src/peano.c @@ -32,43 +32,41 @@ * @return a pointer to an integer or real. */ 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; long int i_accumulator = 0; long double d_accumulator = 0; bool is_int = true; - - for (int i = 0; i < args_in_frame && !nilp(frame->arg[i]); i++) { - struct cons_space_object arg = pointer2cell(frame->arg[i]); - - switch (arg.tag.value) { + + for ( int i = 0; i < args_in_frame && !nilp( frame->arg[i] ); i++ ) { + struct cons_space_object arg = pointer2cell( frame->arg[i] ); + + switch ( arg.tag.value ) { case INTEGERTV: i_accumulator += arg.payload.integer.value; - d_accumulator += numeric_value( frame->arg[i]); + d_accumulator += numeric_value( frame->arg[i] ); break; case REALTV: d_accumulator += arg.payload.real.value; is_int = false; default: - lisp_throw( - c_string_to_lisp_string("Cannot add: not a number"), - frame); - } - - if (! nilp(frame->more)) { - lisp_throw( - c_string_to_lisp_string("Cannot yet add more than 8 numbers"), - frame); + lisp_throw( c_string_to_lisp_string( "Cannot add: not a number" ), + frame ); } - if ( is_int) { - result = make_integer( i_accumulator); + if ( !nilp( frame->more ) ) { + lisp_throw( c_string_to_lisp_string + ( "Cannot yet add more than 8 numbers" ), frame ); + } + + if ( is_int ) { + result = make_integer( i_accumulator ); } 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. */ 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; long int i_accumulator = 1; long double d_accumulator = 1; bool is_int = true; - - for (int i = 0; i < args_in_frame && !nilp(frame->arg[i]); i++) { - struct cons_space_object arg = pointer2cell(frame->arg[i]); - - switch (arg.tag.value) { + + for ( int i = 0; i < args_in_frame && !nilp( frame->arg[i] ); i++ ) { + struct cons_space_object arg = pointer2cell( frame->arg[i] ); + + switch ( arg.tag.value ) { case INTEGERTV: i_accumulator *= arg.payload.integer.value; - d_accumulator *= numeric_value( frame->arg[i]); + d_accumulator *= numeric_value( frame->arg[i] ); break; case REALTV: d_accumulator *= arg.payload.real.value; is_int = false; default: - lisp_throw( - c_string_to_lisp_string("Cannot multiply: not a number"), - frame); - } - - if (! nilp(frame->more)) { - lisp_throw( - c_string_to_lisp_string("Cannot yet multiply more than 8 numbers"), - frame); + lisp_throw( c_string_to_lisp_string + ( "Cannot multiply: not a number" ), frame ); } - if ( is_int) { - result = make_integer( i_accumulator); + if ( !nilp( frame->more ) ) { + lisp_throw( c_string_to_lisp_string + ( "Cannot yet multiply more than 8 numbers" ), frame ); + } + + if ( is_int ) { + result = make_integer( i_accumulator ); } 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. */ 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_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])) { - result = make_integer(arg0.payload.integer.value - arg1.payload.integer.value); - } else if ( realp(frame->arg[0]) && realp(frame->arg[1])) { - 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! + 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] ) ) { + result = + make_integer( arg0.payload.integer.value - + arg1.payload.integer.value ); + } else if ( realp( frame->arg[0] ) && realp( frame->arg[1] ) ) { + 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. - + return result; } - - - diff --git a/src/peano.h b/src/peano.h index 36b64ea..4650fe0 100644 --- a/src/peano.h +++ b/src/peano.h @@ -22,8 +22,8 @@ extern "C" { * @param frame the stack frame. * @return a pointer to an integer or real. */ -struct cons_pointer -lisp_add(struct stack_frame *frame, struct cons_pointer env); + struct cons_pointer + lisp_add( struct stack_frame *frame, struct cons_pointer env ); /** * 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. * @return a pointer to an integer or real. */ -struct cons_pointer -lisp_multiply(struct stack_frame *frame, struct cons_pointer env); + struct cons_pointer + lisp_multiply( struct stack_frame *frame, struct cons_pointer env ); /** * Subtract one number from another. @@ -40,12 +40,10 @@ lisp_multiply(struct stack_frame *frame, struct cons_pointer env); * @param frame the stack frame. * @return a pointer to an integer or real. */ -struct cons_pointer -lisp_subtract(struct stack_frame *frame, struct cons_pointer env); + struct cons_pointer + lisp_subtract( struct stack_frame *frame, struct cons_pointer env ); #ifdef __cplusplus } #endif - -#endif /* PEANO_H */ - +#endif /* PEANO_H */ diff --git a/src/print.c b/src/print.c index ca866cf..f66cf1b 100644 --- a/src/print.c +++ b/src/print.c @@ -101,10 +101,10 @@ void print( FILE * output, struct cons_pointer pointer ) { fwprintf( output, L"t" ); break; case FUNCTIONTV: - fwprintf( output, L"(Function)"); + fwprintf( output, L"(Function)" ); break; case SPECIALTV: - fwprintf( output, L"(Special form)"); + fwprintf( output, L"(Special form)" ); break; default: fwprintf( stderr, diff --git a/src/read.c b/src/read.c index abd76bb..fb3e6d3 100644 --- a/src/read.c +++ b/src/read.c @@ -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. */ struct cons_pointer read_number( FILE * input, wint_t initial ) { - struct cons_pointer result = NIL; + struct cons_pointer result = NIL; long int accumulator = 0; int places_of_decimals = 0; 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' ); fwprintf( stderr, L"Added character %c, accumulator now %ld\n", c, - accumulator ); + accumulator ); if ( seen_period ) { places_of_decimals++; @@ -112,11 +112,11 @@ struct cons_pointer read_number( FILE * input, wint_t initial ) { ungetwc( c, input ); if ( seen_period ) { - long double rv = (long double) - ( accumulator / pow(10, places_of_decimals) ); + long double rv = ( long double ) + ( accumulator / pow( 10, places_of_decimals ) ); - fwprintf( stderr, L"read_numer returning %Lf\n", rv); - result = make_real( rv); + fwprintf( stderr, L"read_numer returning %Lf\n", rv ); + result = make_real( rv ); } else { result = make_integer( accumulator ); } @@ -203,7 +203,7 @@ struct cons_pointer read_symbol( FILE * input, wint_t initial ) { * push back the character read */ ungetwc( initial, input ); - } + } break; } diff --git a/src/real.h b/src/real.h index 759a2bb..7e3601f 100644 --- a/src/real.h +++ b/src/real.h @@ -24,7 +24,7 @@ extern "C" { * @param value the value to wrap; * @return a real number cell wrapping this value. */ -struct cons_pointer make_real( double value ); + struct cons_pointer make_real( double value ); #ifdef __cplusplus } diff --git a/src/repl.c b/src/repl.c index 2e9fb41..6cedc8e 100644 --- a/src/repl.c +++ b/src/repl.c @@ -31,13 +31,13 @@ repl( FILE * in_stream, FILE * out_stream, FILE * error_stream, struct cons_pointer input = read( in_stream ); fwprintf( error_stream, L"\nread {%d,%d}=> ", input.page, input.offset ); - print( error_stream, input); + print( error_stream, input ); struct cons_pointer value = lisp_eval( input, oblist, NULL ); // print( out_stream, input ); fwprintf( out_stream, L"\n" ); fwprintf( error_stream, L"\neval {%d,%d}=> ", input.page, input.offset ); - print( out_stream, value); + print( out_stream, value ); } } diff --git a/src/stack.c b/src/stack.c index 83ecf3a..c47adbd 100644 --- a/src/stack.c +++ b/src/stack.c @@ -51,27 +51,27 @@ struct stack_frame *make_stack_frame( struct stack_frame *previous, result->arg[i] = NIL; } - for (int i = 0; i < args_in_frame && !nilp( args ); i++ ) { - /* iterate down the arg list filling in the arg slots in the - * frame. When there are no more slots, if there are still args, - * stash them on more */ + for ( int i = 0; i < args_in_frame && !nilp( args ); i++ ) { + /* iterate down the arg list filling in the arg slots in the + * frame. When there are no more slots, if there are still args, + * stash them on more */ struct cons_space_object cell = pointer2cell( args ); - /* - * TODO: if we were running on real massively parallel hardware, - * each arg except the first should be handed off to another - * processor to be evaled in parallel - */ - result->arg[i] = lisp_eval( cell.payload.cons.car, env, result ); - inc_ref( result->arg[i] ); + /* + * TODO: if we were running on real massively parallel hardware, + * each arg except the first should be handed off to another + * processor to be evaled in parallel + */ + result->arg[i] = lisp_eval( cell.payload.cons.car, env, result ); + inc_ref( result->arg[i] ); - args = cell.payload.cons.cdr; - } - /* - * TODO: this isn't right. These args should also each be evaled. - */ - result->more = args; - inc_ref( result->more ); + args = cell.payload.cons.cdr; + } + /* + * TODO: this isn't right. These args should also each be evaled. + */ + result->more = args; + inc_ref( result->more ); return result; } @@ -85,8 +85,8 @@ struct stack_frame *make_stack_frame( struct stack_frame *previous, * @return a new special frame. */ struct stack_frame *make_special_frame( struct stack_frame *previous, - struct cons_pointer args, - struct cons_pointer env ) { + struct cons_pointer args, + struct cons_pointer env ) { /* * 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; } - for (int i = 0; i < args_in_frame && !nilp( args ); i++ ) { - /* iterate down the arg list filling in the arg slots in the - * frame. When there are no more slots, if there are still args, - * stash them on more */ + for ( int i = 0; i < args_in_frame && !nilp( args ); i++ ) { + /* iterate down the arg list filling in the arg slots in the + * frame. When there are no more slots, if there are still args, + * stash them on more */ struct cons_space_object cell = pointer2cell( args ); 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; } result->more = args; - inc_ref(args); + inc_ref( args ); return result; } diff --git a/src/stack.h b/src/stack.h index 4eaa9e1..a7fc82b 100644 --- a/src/stack.h +++ b/src/stack.h @@ -39,8 +39,8 @@ struct cons_pointer fetch_arg( struct stack_frame *frame, unsigned int n ); * @return a new special frame. */ struct stack_frame *make_special_frame( struct stack_frame *previous, - struct cons_pointer args, - struct cons_pointer env ); + struct cons_pointer args, + struct cons_pointer env ); /* * struct stack_frame is defined in consspaceobject.h to break circularity