From 40e1f3ca64d1fcbfe7371c1708f2c80188789e9f Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Sat, 29 Dec 2018 07:40:01 +0000 Subject: [PATCH] Whitespace only changes --- src/arith/peano.c | 4 +- src/arith/ratio.c | 20 ++-- src/debug.c | 20 ++-- src/debug.h | 2 +- src/init.c | 68 ++++++------- src/memory/conspage.c | 29 +++--- src/memory/consspaceobject.c | 6 +- src/memory/dump.c | 25 ++--- src/memory/stack.c | 65 ++++++------ src/memory/stack.h | 2 +- src/memory/vectorspace.c | 26 ++--- src/ops/equal.c | 4 +- src/ops/intern.c | 34 +++---- src/ops/lispops.c | 189 ++++++++++++++++++----------------- src/ops/print.c | 8 +- src/ops/read.c | 25 ++--- src/repl.c | 25 +++-- 17 files changed, 283 insertions(+), 269 deletions(-) diff --git a/src/arith/peano.c b/src/arith/peano.c index 9f5e0fb..d040e28 100644 --- a/src/arith/peano.c +++ b/src/arith/peano.c @@ -412,8 +412,8 @@ struct cons_pointer inverse( struct cons_pointer 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: diff --git a/src/arith/ratio.c b/src/arith/ratio.c index ca83335..31dd0a2 100644 --- a/src/arith/ratio.c +++ b/src/arith/ratio.c @@ -61,10 +61,10 @@ struct cons_pointer simplify_ratio( struct cons_pointer frame_pointer, if ( ratiop( arg ) ) { int64_t 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 ) { @@ -117,7 +117,8 @@ struct cons_pointer add_ratio_ratio( struct cons_pointer frame_pointer, lcm = least_common_multiple( dr1v, dr2v ), m1 = lcm / dr1v, m2 = lcm / dr2v; - debug_printf( DEBUG_ARITH, L"); lcm = %ld; m1 = %ld; m2 = %ld", lcm, m1, m2 ); + debug_printf( DEBUG_ARITH, L"); lcm = %ld; m1 = %ld; m2 = %ld", lcm, + m1, m2 ); if ( dr1v == dr2v ) { r = make_ratio( frame_pointer, @@ -201,11 +202,10 @@ struct cons_pointer divide_ratio_ratio( struct cons_pointer frame_pointer, struct cons_pointer arg1, struct cons_pointer arg2 ) { struct cons_pointer i = make_ratio( frame_pointer, - 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_pointer, arg1, i ); dec_ref( i ); diff --git a/src/debug.c b/src/debug.c index b21f4af..eba31e8 100644 --- a/src/debug.c +++ b/src/debug.c @@ -61,15 +61,15 @@ void debug_println( int level ) { * `wprintf` adapted for the debug logging system. Print to stderr only * `verbosity` matches `level`. All other arguments as for `wprintf`. */ -void debug_printf( int level, wchar_t * format, ...) { - #ifdef DEBUG - if ( level & verbosity ) { - fwide( stderr, 1 ); - va_list(args); - va_start(args, format); - vfwprintf(stderr, format, args); - } - #endif +void debug_printf( int level, wchar_t *format, ... ) { +#ifdef DEBUG + if ( level & verbosity ) { + fwide( stderr, 1 ); + va_list( args ); + va_start( args, format ); + vfwprintf( stderr, format, args ); + } +#endif } /** @@ -92,7 +92,7 @@ void debug_print_object( struct cons_pointer pointer, int level ) { void debug_dump_object( struct cons_pointer pointer, int level ) { #ifdef DEBUG if ( level & verbosity ) { - fwide( stderr, 1 ); + fwide( stderr, 1 ); dump_object( stderr, pointer ); } #endif diff --git a/src/debug.h b/src/debug.h index acd67fe..72fa020 100644 --- a/src/debug.h +++ b/src/debug.h @@ -27,7 +27,7 @@ extern int verbosity; void debug_print( wchar_t *message, int level ); void debug_println( int level ); -void debug_printf( int level, wchar_t * format, ...); +void debug_printf( int level, wchar_t *format, ... ); void debug_print_object( struct cons_pointer pointer, int level ); void debug_dump_object( struct cons_pointer pointer, int level ); diff --git a/src/init.c b/src/init.c index d81aa00..4a2032d 100644 --- a/src/init.c +++ b/src/init.c @@ -93,45 +93,45 @@ int main( int argc, char *argv[] ) { /* * primitive function operations */ - bind_function( L"add", &lisp_add ); - bind_function( L"apply", &lisp_apply ); - bind_function( L"assoc", &lisp_assoc ); - bind_function( L"car", &lisp_car ); - bind_function( L"cdr", &lisp_cdr ); - bind_function( L"cons", &lisp_cons ); - bind_function( L"divide", &lisp_divide ); - bind_function( L"eq", &lisp_eq ); - bind_function( L"equal", &lisp_equal ); - bind_function( L"eval", &lisp_eval ); - bind_function( L"exception", &lisp_exception ); - bind_function( L"multiply", &lisp_multiply ); - bind_function( L"read", &lisp_read ); - bind_function( L"oblist", &lisp_oblist ); - bind_function( L"print", &lisp_print ); - bind_function( L"progn", &lisp_progn ); - bind_function( L"reverse", &lisp_reverse ); - bind_function( L"set", &lisp_set ); - bind_function( L"subtract", &lisp_subtract ); - bind_function( L"throw", &lisp_exception ); - bind_function( L"type", &lisp_type ); + bind_function( L"add", &lisp_add ); + bind_function( L"apply", &lisp_apply ); + bind_function( L"assoc", &lisp_assoc ); + bind_function( L"car", &lisp_car ); + bind_function( L"cdr", &lisp_cdr ); + bind_function( L"cons", &lisp_cons ); + bind_function( L"divide", &lisp_divide ); + bind_function( L"eq", &lisp_eq ); + bind_function( L"equal", &lisp_equal ); + bind_function( L"eval", &lisp_eval ); + bind_function( L"exception", &lisp_exception ); + bind_function( L"multiply", &lisp_multiply ); + bind_function( L"read", &lisp_read ); + bind_function( L"oblist", &lisp_oblist ); + bind_function( L"print", &lisp_print ); + bind_function( L"progn", &lisp_progn ); + bind_function( L"reverse", &lisp_reverse ); + bind_function( L"set", &lisp_set ); + bind_function( L"subtract", &lisp_subtract ); + bind_function( L"throw", &lisp_exception ); + bind_function( L"type", &lisp_type ); - bind_function( L"+", &lisp_add ); - bind_function( L"*", &lisp_multiply ); - bind_function( L"-", &lisp_subtract ); - bind_function( L"/", &lisp_divide ); - bind_function( L"=", &lisp_equal ); + bind_function( L"+", &lisp_add ); + bind_function( L"*", &lisp_multiply ); + bind_function( L"-", &lisp_subtract ); + bind_function( L"/", &lisp_divide ); + bind_function( L"=", &lisp_equal ); /* * primitive special forms */ - bind_special( L"cond", &lisp_cond ); - bind_special( L"lambda", &lisp_lambda ); - // bind_special( L"λ", &lisp_lambda ); - bind_special( L"nlambda", &lisp_nlambda ); - // bind_special( L"nλ", &lisp_nlambda ); - bind_special( L"progn", &lisp_progn ); - bind_special( L"quote", &lisp_quote ); - bind_special( L"set!", &lisp_set_shriek ); + bind_special( L"cond", &lisp_cond ); + bind_special( L"lambda", &lisp_lambda ); + // bind_special( L"λ", &lisp_lambda ); + bind_special( L"nlambda", &lisp_nlambda ); + // bind_special( L"nλ", &lisp_nlambda ); + bind_special( L"progn", &lisp_progn ); + bind_special( L"quote", &lisp_quote ); + bind_special( L"set!", &lisp_set_shriek ); repl( stdin, stdout, stderr, show_prompt ); diff --git a/src/memory/conspage.c b/src/memory/conspage.c index cf87028..bf3819c 100644 --- a/src/memory/conspage.c +++ b/src/memory/conspage.c @@ -66,7 +66,8 @@ void make_cons_page( ) { cell->count = MAXREFERENCE; cell->payload.free.car = NIL; cell->payload.free.cdr = NIL; - debug_printf( DEBUG_ALLOC, L"Allocated special cell NIL\n" ); + debug_printf( DEBUG_ALLOC, + L"Allocated special cell NIL\n" ); break; case 1: /* @@ -80,7 +81,8 @@ void make_cons_page( ) { cell->payload.free.cdr = ( struct cons_pointer ) { 0, 1 }; - debug_printf( DEBUG_ALLOC, L"Allocated special cell T\n" ); + debug_printf( DEBUG_ALLOC, + L"Allocated special cell T\n" ); break; } } else { @@ -98,8 +100,8 @@ void make_cons_page( ) { initialised_cons_pages++; } else { debug_printf( DEBUG_ALLOC, - L"FATAL: Failed to allocate memory for cons page %d\n", - initialised_cons_pages ); + L"FATAL: Failed to allocate memory for cons page %d\n", + initialised_cons_pages ); exit( 1 ); } @@ -164,8 +166,9 @@ void free_cell( struct cons_pointer pointer ) { case VECTORPOINTTV: /* for vector space pointers, free the actual vector-space * object. Dangerous! */ - debug_printf( DEBUG_ALLOC, L"About to free vector-space object at %ld\n", - cell->payload.vectorp.address ); + debug_printf( DEBUG_ALLOC, + L"About to free vector-space object at %ld\n", + cell->payload.vectorp.address ); //free( ( void * ) cell->payload.vectorp.address ); break; @@ -179,13 +182,13 @@ void free_cell( struct cons_pointer pointer ) { freelist = pointer; } else { debug_printf( DEBUG_ALLOC, - L"ERROR: Attempt to free cell with %d dangling references at page %d, offset %d\n", - cell->count, pointer.page, pointer.offset ); + L"ERROR: Attempt to free cell with %d dangling references at page %d, offset %d\n", + cell->count, pointer.page, pointer.offset ); } } else { debug_printf( DEBUG_ALLOC, - L"ERROR: Attempt to free cell which is already FREE at page %d, offset %d\n", - pointer.page, pointer.offset ); + L"ERROR: Attempt to free cell which is already FREE at page %d, offset %d\n", + pointer.page, pointer.offset ); } } @@ -216,8 +219,8 @@ struct cons_pointer allocate_cell( char *tag ) { cell->payload.cons.cdr = NIL; debug_printf( DEBUG_ALLOC, - L"Allocated cell of type '%s' at %d, %d \n", tag, - result.page, result.offset ); + L"Allocated cell of type '%s' at %d, %d \n", tag, + result.page, result.offset ); } else { debug_printf( DEBUG_ALLOC, L"WARNING: Allocating non-free cell!" ); } @@ -239,6 +242,6 @@ void initialise_cons_pages( ) { conspageinitihasbeencalled = true; } else { debug_printf( DEBUG_ALLOC, - 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/memory/consspaceobject.c b/src/memory/consspaceobject.c index f5cc8b8..31927d8 100644 --- a/src/memory/consspaceobject.c +++ b/src/memory/consspaceobject.c @@ -183,10 +183,10 @@ make_string_like_thing( wint_t c, struct cons_pointer tail, char *tag ) { * cell->payload.string.cdr = tsil */ cell->payload.string.cdr.offset = tail.offset; } else { - // TODO: should throw an exception! + // TODO: should throw an exception! debug_printf( DEBUG_ALLOC, - L"Warning: only NIL and %s can be prepended to %s\n", - tag, tag ); + L"Warning: only NIL and %s can be prepended to %s\n", + tag, tag ); } return pointer; diff --git a/src/memory/dump.c b/src/memory/dump.c index cf26bb5..d3a53d3 100644 --- a/src/memory/dump.c +++ b/src/memory/dump.c @@ -67,8 +67,8 @@ void dump_object( FILE * output, struct cons_pointer pointer ) { cell.payload.cons.car.offset, cell.payload.cons.cdr.page, cell.payload.cons.cdr.offset, cell.count ); - print( output, pointer); - fputws( L"\n", output); + print( output, pointer ); + fputws( L"\n", output ); break; case EXCEPTIONTV: fwprintf( output, L"\t\tException cell: " ); @@ -89,7 +89,7 @@ void dump_object( FILE * output, struct cons_pointer pointer ) { print( output, cell.payload.lambda.args ); fwprintf( output, L";\n\t\t\tbody: " ); print( output, cell.payload.lambda.body ); - fputws( L"\n", output); + fputws( L"\n", output ); break; case NILTV: break; @@ -98,15 +98,15 @@ void dump_object( FILE * output, struct cons_pointer pointer ) { print( output, cell.payload.lambda.args ); fwprintf( output, L";\n\t\t\tbody: " ); print( output, cell.payload.lambda.body ); - fputws( L"\n", output); + fputws( L"\n", output ); break; 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" ); @@ -130,10 +130,11 @@ void dump_object( FILE * output, struct cons_pointer pointer ) { struct vector_space_object *vso = cell.payload.vectorp.address; fwprintf( output, L"\t\tVector space object of type %4.4s (%d), payload size %d bytes\n", - &vso->header.tag.bytes, vso->header.tag.value, vso->header.size ); - if (stackframep(vso)) { - dump_frame(output, pointer); - } + &vso->header.tag.bytes, vso->header.tag.value, + vso->header.size ); + if ( stackframep( vso ) ) { + dump_frame( output, pointer ); + } switch ( vso->header.tag.value ) { case STACKFRAMETV: dump_frame( output, pointer ); diff --git a/src/memory/stack.c b/src/memory/stack.c index f91d896..f036402 100644 --- a/src/memory/stack.c +++ b/src/memory/stack.c @@ -26,15 +26,15 @@ #include "stack.h" #include "vectorspace.h" -void set_reg(struct stack_frame * frame, int reg, struct cons_pointer value) { - debug_printf(DEBUG_STACK, L"Setting register %d to ", reg); - debug_print_object(value, DEBUG_STACK); - debug_println(DEBUG_STACK); - frame->arg[reg++] = value; - inc_ref(value); - if (reg > frame->args) { - frame->args = reg; - } +void set_reg( struct stack_frame *frame, int reg, struct cons_pointer value ) { + debug_printf( DEBUG_STACK, L"Setting register %d to ", reg ); + debug_print_object( value, DEBUG_STACK ); + debug_println( DEBUG_STACK ); + frame->arg[reg++] = value; + inc_ref( value ); + if ( reg > frame->args ) { + frame->args = reg; + } } @@ -49,8 +49,8 @@ struct stack_frame *get_stack_frame( struct cons_pointer pointer ) { if ( vectorpointp( pointer ) && stackframep( vso ) ) { result = ( struct stack_frame * ) &( vso->payload ); - debug_printf( DEBUG_STACK, L"get_stack_frame: all good, returning %p\n", - result ); + debug_printf( DEBUG_STACK, + L"get_stack_frame: all good, returning %p\n", result ); } else { debug_print( L"get_stack_frame: fail, returning NULL\n", DEBUG_STACK ); } @@ -97,7 +97,7 @@ struct cons_pointer make_empty_frame( struct cons_pointer previous ) { } } debug_print( L"Leaving make_empty_frame\n", DEBUG_ALLOC ); - debug_dump_object( result, DEBUG_ALLOC); + debug_dump_object( result, DEBUG_ALLOC ); return result; } @@ -124,7 +124,7 @@ struct cons_pointer make_stack_frame( struct cons_pointer previous, } else { struct stack_frame *frame = get_stack_frame( result ); - while ( frame->args < args_in_frame && consp( args )) { + while ( frame->args < args_in_frame && consp( args ) ) { /* 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 */ @@ -136,19 +136,21 @@ struct cons_pointer make_stack_frame( struct cons_pointer previous, * processor to be evaled in parallel; but see notes here: * https://github.com/simon-brooke/post-scarcity/wiki/parallelism */ - struct cons_pointer val = eval_form(frame, result, cell.payload.cons.car, env); - if ( exceptionp( val ) ) { - result = val; - break; - } else { - debug_printf( DEBUG_STACK, L"Setting argument %d to ", frame->args); - debug_print_object(cell.payload.cons.car, DEBUG_STACK); - set_reg( frame, frame->args, val ); - } - - args = cell.payload.cons.cdr; + struct cons_pointer val = + eval_form( frame, result, cell.payload.cons.car, env ); + if ( exceptionp( val ) ) { + result = val; + break; + } else { + debug_printf( DEBUG_STACK, L"Setting argument %d to ", + frame->args ); + debug_print_object( cell.payload.cons.car, DEBUG_STACK ); + set_reg( frame, frame->args, val ); } + args = cell.payload.cons.cdr; + } + if ( !exceptionp( result ) ) { if ( consp( args ) ) { /* if we still have args, eval them and stick the values on `more` */ @@ -190,7 +192,7 @@ struct cons_pointer make_special_frame( struct cons_pointer previous, } else { struct stack_frame *frame = get_stack_frame( result ); - while ( frame->args < args_in_frame && !nilp( args )) { + while ( frame->args < args_in_frame && !nilp( args ) ) { /* 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 */ @@ -240,7 +242,7 @@ void dump_frame( FILE * output, struct cons_pointer frame_pointer ) { struct stack_frame *frame = get_stack_frame( frame_pointer ); if ( frame != NULL ) { - fwprintf( output, L"Stack frame with %d arguments:\n", frame->args); + fwprintf( output, L"Stack frame with %d arguments:\n", frame->args ); for ( int arg = 0; arg < frame->args; arg++ ) { struct cons_space_object cell = pointer2cell( frame->arg[arg] ); @@ -252,12 +254,11 @@ void dump_frame( FILE * output, struct cons_pointer frame_pointer ) { print( output, frame->arg[arg] ); fputws( L"\n", output ); } - if (!nilp(frame->more)) - { - fputws( L"More: \t", output ); - print( output, frame->more ); - fputws( L"\n", output ); - } + if ( !nilp( frame->more ) ) { + fputws( L"More: \t", output ); + print( output, frame->more ); + fputws( L"\n", output ); + } } } diff --git a/src/memory/stack.h b/src/memory/stack.h index 79cd1e2..189ff6b 100644 --- a/src/memory/stack.h +++ b/src/memory/stack.h @@ -41,7 +41,7 @@ */ //#define set_reg(frame,register,value){frame->arg[register]=value; inc_ref(value);} -void set_reg(struct stack_frame * frame, int reg, struct cons_pointer value); +void set_reg( struct stack_frame *frame, int reg, struct cons_pointer value ); struct stack_frame *get_stack_frame( struct cons_pointer pointer ); diff --git a/src/memory/vectorspace.c b/src/memory/vectorspace.c index c30f120..3aef0f1 100644 --- a/src/memory/vectorspace.c +++ b/src/memory/vectorspace.c @@ -36,11 +36,12 @@ struct cons_pointer make_vec_pointer( struct vector_space_object *address ) { struct cons_pointer pointer = allocate_cell( VECTORPOINTTAG ); struct cons_space_object *cell = &pointer2cell( pointer ); debug_printf( DEBUG_ALLOC, - L"make_vec_pointer: tag written, about to set pointer address to %p\n", - address ); + L"make_vec_pointer: tag written, about to set pointer address to %p\n", + address ); cell->payload.vectorp.address = address; - debug_printf( DEBUG_ALLOC, L"make_vec_pointer: all good, returning pointer to %p\n", - cell->payload.vectorp.address ); + debug_printf( DEBUG_ALLOC, + L"make_vec_pointer: all good, returning pointer to %p\n", + cell->payload.vectorp.address ); debug_dump_object( pointer, DEBUG_ALLOC ); @@ -67,8 +68,8 @@ struct cons_pointer make_vso( char *tag, uint64_t payload_size ) { if ( vso != NULL ) { debug_printf( DEBUG_ALLOC, - L"make_vso: about to write tag '%s' into vso at %p\n", tag, - vso ); + L"make_vso: about to write tag '%s' into vso at %p\n", + tag, vso ); strncpy( &vso->header.tag.bytes[0], tag, TAGLENGTH ); result = make_vec_pointer( vso ); debug_dump_object( result, DEBUG_ALLOC ); @@ -79,18 +80,19 @@ struct cons_pointer make_vso( char *tag, uint64_t payload_size ) { #ifdef DEBUG debug_printf( DEBUG_ALLOC, - 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 ); + 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 ) { debug_printf( DEBUG_ALLOC, L"\t\tPadded from %d to %d\n", - total_size, padded ); + total_size, padded ); } #endif } #ifdef DEBUG - debug_printf( DEBUG_ALLOC, L"make_vso: all good, returning pointer to %p\n", - pointer2cell( result ).payload.vectorp.address ); + debug_printf( DEBUG_ALLOC, + L"make_vso: all good, returning pointer to %p\n", + pointer2cell( result ).payload.vectorp.address ); #endif return result; diff --git a/src/ops/equal.c b/src/ops/equal.c index 0f0597c..ebb085e 100644 --- a/src/ops/equal.c +++ b/src/ops/equal.c @@ -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 = diff --git a/src/ops/intern.c b/src/ops/intern.c index 03da271..e36437d 100644 --- a/src/ops/intern.c +++ b/src/ops/intern.c @@ -57,22 +57,22 @@ internedp( struct cons_pointer key, struct cons_pointer store ) { struct cons_space_object entry = pointer2cell( pointer2cell( next ).payload.cons.car ); - debug_print( L"Internedp: checking whether `", DEBUG_BIND ); - debug_print_object( key, DEBUG_BIND ); - debug_print( L"` equals `", DEBUG_BIND ); - debug_print_object( entry.payload.cons.car, DEBUG_BIND ); - debug_print( L"`\n", DEBUG_BIND ); + debug_print( L"Internedp: checking whether `", DEBUG_BIND ); + debug_print_object( key, DEBUG_BIND ); + debug_print( L"` equals `", DEBUG_BIND ); + debug_print_object( entry.payload.cons.car, DEBUG_BIND ); + debug_print( L"`\n", DEBUG_BIND ); if ( equal( key, entry.payload.cons.car ) ) { result = entry.payload.cons.car; } } } else { - debug_print( L"`", DEBUG_BIND ); - debug_print_object( key, DEBUG_BIND ); - debug_print( L"` is a ", DEBUG_BIND ); - debug_print_object( c_type( key ), DEBUG_BIND ); - debug_print( L", not a SYMB", DEBUG_BIND ); + debug_print( L"`", DEBUG_BIND ); + debug_print_object( key, DEBUG_BIND ); + debug_print( L"` is a ", DEBUG_BIND ); + debug_print_object( c_type( key ), DEBUG_BIND ); + debug_print( L", not a SYMB", DEBUG_BIND ); } return result; @@ -111,11 +111,11 @@ struct cons_pointer c_assoc( struct cons_pointer key, struct cons_pointer bind( struct cons_pointer key, struct cons_pointer value, struct cons_pointer store ) { - debug_print(L"Binding ", DEBUG_BIND); - debug_print_object(key, DEBUG_BIND); - debug_print(L" to ", DEBUG_BIND); - debug_print_object(value, DEBUG_BIND); - debug_println( DEBUG_BIND); + debug_print( L"Binding ", DEBUG_BIND ); + debug_print_object( key, DEBUG_BIND ); + debug_print( L" to ", DEBUG_BIND ); + debug_print_object( value, DEBUG_BIND ); + debug_println( DEBUG_BIND ); return make_cons( make_cons( key, value ), store ); } @@ -127,11 +127,11 @@ bind( struct cons_pointer key, struct cons_pointer value, */ struct cons_pointer deep_bind( struct cons_pointer key, struct cons_pointer value ) { - debug_print( L"Entering deep_bind\n", DEBUG_BIND ); + debug_print( L"Entering deep_bind\n", DEBUG_BIND ); oblist = bind( key, value, oblist ); - debug_print( L"Leaving deep_bind\n", DEBUG_BIND ); + debug_print( L"Leaving deep_bind\n", DEBUG_BIND ); return oblist; } diff --git a/src/ops/lispops.c b/src/ops/lispops.c index 2be19b6..b0a1a7e 100644 --- a/src/ops/lispops.c +++ b/src/ops/lispops.c @@ -212,7 +212,7 @@ eval_lambda( struct cons_space_object cell, struct stack_frame *frame, names = c_cdr( names ); } - /* TODO: if there's more than `args_in_frame` arguments, bind those too. */ + /* TODO: if there's more than `args_in_frame` arguments, bind those too. */ } else if ( symbolp( names ) ) { /* if `names` is a symbol, rather than a list of symbols, * then bind a list of the values of args to that symbol. */ @@ -255,8 +255,8 @@ eval_lambda( struct cons_space_object cell, struct stack_frame *frame, struct cons_pointer c_apply( struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env ) { - debug_print(L"Entering c_apply\n", DEBUG_EVAL); - struct cons_pointer result = NIL; + debug_print( L"Entering c_apply\n", DEBUG_EVAL ); + struct cons_pointer result = NIL; struct cons_pointer fn_pointer = eval_form( frame, frame_pointer, c_car( frame->arg[0] ), env ); @@ -264,103 +264,107 @@ c_apply( struct stack_frame *frame, struct cons_pointer frame_pointer, if ( exceptionp( fn_pointer ) ) { result = fn_pointer; } else { - struct cons_space_object fn_cell = pointer2cell( fn_pointer ); - struct cons_pointer args = c_cdr( frame->arg[0] ); + struct cons_space_object fn_cell = pointer2cell( fn_pointer ); + struct cons_pointer args = c_cdr( frame->arg[0] ); - switch ( fn_cell.tag.value ) { - case EXCEPTIONTV: - /* just pass exceptions straight back */ - result = fn_pointer; - break; - case FUNCTIONTV: - { - struct cons_pointer exep = NIL; - struct cons_pointer next_pointer = - make_stack_frame( frame_pointer, args, env ); - inc_ref( next_pointer ); - if ( exceptionp( next_pointer ) ) { - result = next_pointer; - } else { - struct stack_frame *next = get_stack_frame( next_pointer ); + switch ( fn_cell.tag.value ) { + case EXCEPTIONTV: + /* just pass exceptions straight back */ + result = fn_pointer; + break; + case FUNCTIONTV: + { + struct cons_pointer exep = NIL; + struct cons_pointer next_pointer = + make_stack_frame( frame_pointer, args, env ); + inc_ref( next_pointer ); + if ( exceptionp( next_pointer ) ) { + result = next_pointer; + } else { + struct stack_frame *next = + get_stack_frame( next_pointer ); - result = - ( *fn_cell.payload.function.executable ) ( next, - next_pointer, - env ); - dec_ref( next_pointer ); - } - } - break; - case LAMBDATV: - { - struct cons_pointer exep = NIL; - struct cons_pointer next_pointer = - make_stack_frame( frame_pointer, args, env ); - inc_ref( next_pointer ); - if ( exceptionp( next_pointer ) ) { - result = next_pointer; - } else { - struct stack_frame *next = get_stack_frame( next_pointer ); - result = eval_lambda( fn_cell, next, next_pointer, env ); - if ( !exceptionp( result ) ) { + result = + ( *fn_cell.payload.function.executable ) ( next, + next_pointer, + env ); dec_ref( next_pointer ); } } - } - break; - case NLAMBDATV: - { - struct cons_pointer next_pointer = - make_special_frame( frame_pointer, args, env ); - inc_ref( next_pointer ); - if ( exceptionp( next_pointer ) ) { - result = next_pointer; - } else { - struct stack_frame *next = - get_stack_frame( next_pointer ); - result = eval_lambda( fn_cell, next, next_pointer, env ); + break; + case LAMBDATV: + { + struct cons_pointer exep = NIL; + struct cons_pointer next_pointer = + make_stack_frame( frame_pointer, args, env ); + inc_ref( next_pointer ); + if ( exceptionp( next_pointer ) ) { + result = next_pointer; + } else { + struct stack_frame *next = + get_stack_frame( next_pointer ); + result = + eval_lambda( fn_cell, next, next_pointer, env ); + if ( !exceptionp( result ) ) { + dec_ref( next_pointer ); + } + } + } + break; + case NLAMBDATV: + { + struct cons_pointer next_pointer = + make_special_frame( frame_pointer, args, env ); + inc_ref( next_pointer ); + if ( exceptionp( next_pointer ) ) { + result = next_pointer; + } else { + struct stack_frame *next = + get_stack_frame( next_pointer ); + result = + eval_lambda( fn_cell, next, next_pointer, env ); dec_ref( next_pointer ); + } } - } - break; - case SPECIALTV: - { - struct cons_pointer next_pointer = - make_special_frame( frame_pointer, args, env ); - inc_ref( next_pointer ); - if ( exceptionp( next_pointer ) ) { - result = next_pointer; - } else { - result = - ( *fn_cell.payload.special.executable ) ( get_stack_frame( next_pointer ), - next_pointer, - env ); - debug_print(L"Special form returning: ", DEBUG_EVAL); - debug_print_object(result, DEBUG_EVAL); - debug_println(DEBUG_EVAL); - dec_ref( next_pointer ); + break; + case SPECIALTV: + { + struct cons_pointer next_pointer = + make_special_frame( frame_pointer, args, env ); + inc_ref( next_pointer ); + if ( exceptionp( next_pointer ) ) { + result = next_pointer; + } else { + result = + ( *fn_cell.payload.special. + executable ) ( get_stack_frame( next_pointer ), + next_pointer, env ); + debug_print( L"Special form returning: ", DEBUG_EVAL ); + debug_print_object( result, DEBUG_EVAL ); + debug_println( DEBUG_EVAL ); + dec_ref( next_pointer ); + } } - } - break; - default: - { - int bs = sizeof(wchar_t) * 1024; - wchar_t *buffer = malloc( bs ); - memset( buffer, '\0', bs ); - swprintf( buffer, bs, - L"Unexpected cell with tag %d (%4.4s) in function position", - fn_cell.tag.value, &fn_cell.tag.bytes[0] ); - struct cons_pointer message = - c_string_to_lisp_string( buffer ); - free( buffer ); - result = throw_exception( message, frame_pointer ); - } - } + break; + default: + { + int bs = sizeof( wchar_t ) * 1024; + wchar_t *buffer = malloc( bs ); + memset( buffer, '\0', bs ); + swprintf( buffer, bs, + L"Unexpected cell with tag %d (%4.4s) in function position", + fn_cell.tag.value, &fn_cell.tag.bytes[0] ); + struct cons_pointer message = + c_string_to_lisp_string( buffer ); + free( buffer ); + result = throw_exception( message, frame_pointer ); + } + } } - debug_print(L"c_apply: returning: ", DEBUG_EVAL); - debug_print_object(result, DEBUG_EVAL); - debug_println(DEBUG_EVAL); + debug_print( L"c_apply: returning: ", DEBUG_EVAL ); + debug_print_object( result, DEBUG_EVAL ); + debug_println( DEBUG_EVAL ); return result; } @@ -375,9 +379,8 @@ struct cons_pointer c_type( struct cons_pointer pointer ) { struct cons_pointer result = NIL; struct cons_space_object cell = pointer2cell( pointer ); - for (int i = TAGLENGTH -1; i >= 0; i--) - { - result = make_string((wchar_t)cell.tag.bytes[i], result); + for ( int i = TAGLENGTH - 1; i >= 0; i-- ) { + result = make_string( ( wchar_t ) cell.tag.bytes[i], result ); } return result; diff --git a/src/ops/print.c b/src/ops/print.c index 49adca7..6b971ef 100644 --- a/src/ops/print.c +++ b/src/ops/print.c @@ -133,8 +133,8 @@ struct cons_pointer print( FILE * output, struct cons_pointer pointer ) { case LAMBDATV: print( output, make_cons( c_string_to_lisp_symbol( L"lambda" ), make_cons( cell.payload.lambda.args, - cell.payload.lambda. - body ) ) ); + cell.payload. + lambda.body ) ) ); break; case NILTV: fwprintf( output, L"nil" ); @@ -142,8 +142,8 @@ struct cons_pointer print( FILE * output, struct cons_pointer pointer ) { case NLAMBDATV: print( output, make_cons( c_string_to_lisp_symbol( L"nlambda" ), make_cons( cell.payload.lambda.args, - cell.payload.lambda. - body ) ) ); + cell.payload. + lambda.body ) ) ); break; case RATIOTV: print( output, cell.payload.ratio.dividend ); diff --git a/src/ops/read.c b/src/ops/read.c index a9b1ffe..69de893 100644 --- a/src/ops/read.c +++ b/src/ops/read.c @@ -72,7 +72,7 @@ struct cons_pointer read_continuation( struct stack_frame *frame, if ( feof( input ) ) { result = throw_exception( c_string_to_lisp_string - ( L"End of file while reading" ), frame_pointer ); + ( L"End of file while reading" ), frame_pointer ); } else { switch ( c ) { case ';': @@ -137,9 +137,9 @@ struct cons_pointer read_continuation( struct stack_frame *frame, } else { result = throw_exception( make_cons( c_string_to_lisp_string - ( L"Unrecognised start of input character" ), - make_string( c, NIL ) ), - frame_pointer ); + ( L"Unrecognised start of input character" ), + make_string( c, NIL ) ), + frame_pointer ); } break; } @@ -171,23 +171,24 @@ struct cons_pointer read_number( struct stack_frame *frame, initial = fgetwc( input ); } - debug_printf( DEBUG_IO, L"read_number starting '%c' (%d)\n", initial, initial ); + debug_printf( DEBUG_IO, L"read_number starting '%c' (%d)\n", initial, + initial ); for ( c = initial; iswdigit( c ) || c == btowc( '.' ) || c == btowc( '/' ); c = fgetwc( input ) ) { if ( c == btowc( '.' ) ) { if ( seen_period || dividend != 0 ) { return throw_exception( c_string_to_lisp_string - ( L"Malformed number: too many periods" ), - frame_pointer ); + ( L"Malformed number: too many periods" ), + frame_pointer ); } else { seen_period = true; } } else if ( c == btowc( '/' ) ) { if ( seen_period || dividend > 0 ) { return throw_exception( c_string_to_lisp_string - ( L"Malformed number: dividend of rational must be integer" ), - frame_pointer ); + ( L"Malformed number: dividend of rational must be integer" ), + frame_pointer ); } else { dividend = negative ? 0 - accumulator : accumulator; @@ -197,8 +198,8 @@ struct cons_pointer read_number( struct stack_frame *frame, accumulator = accumulator * 10 + ( ( int ) c - ( int ) '0' ); debug_printf( DEBUG_IO, - L"Added character %c, accumulator now %ld\n", - c, accumulator ); + L"Added character %c, accumulator now %ld\n", + c, accumulator ); if ( seen_period ) { places_of_decimals++; @@ -244,7 +245,7 @@ struct cons_pointer read_list( struct stack_frame *frame, struct cons_pointer result = NIL; if ( initial != ')' ) { debug_printf( DEBUG_IO, - L"read_list starting '%C' (%d)\n", initial, initial ); + L"read_list starting '%C' (%d)\n", initial, initial ); struct cons_pointer car = read_continuation( frame, frame_pointer, input, initial ); diff --git a/src/repl.c b/src/repl.c index e0170b6..7914fd4 100644 --- a/src/repl.c +++ b/src/repl.c @@ -34,15 +34,18 @@ struct cons_pointer repl_read( struct cons_pointer stream_pointer ) { struct cons_pointer result = NIL; debug_print( L"Entered repl_read\n", DEBUG_REPL ); - struct cons_pointer frame_pointer = make_stack_frame( NIL, make_cons(stream_pointer, NIL), oblist ); - debug_print( L"repl_read: got stack_frame pointer\n", DEBUG_REPL ); + struct cons_pointer frame_pointer = + make_stack_frame( NIL, make_cons( stream_pointer, NIL ), oblist ); + debug_print( L"repl_read: got stack_frame pointer\n", DEBUG_REPL ); debug_dump_object( frame_pointer, DEBUG_REPL ); if ( !nilp( frame_pointer ) ) { inc_ref( frame_pointer ); - result = lisp_read( get_stack_frame( frame_pointer ), frame_pointer, oblist ); + result = + lisp_read( get_stack_frame( frame_pointer ), frame_pointer, + oblist ); dec_ref( frame_pointer ); } - debug_print( L"repl_read: returning\n", DEBUG_REPL ); + debug_print( L"repl_read: returning\n", DEBUG_REPL ); debug_dump_object( result, DEBUG_REPL ); return result; @@ -52,12 +55,12 @@ struct cons_pointer repl_read( struct cons_pointer stream_pointer ) { * Dummy up a Lisp eval call with its own stack frame. */ struct cons_pointer repl_eval( struct cons_pointer input ) { - debug_print( L"Entered repl_eval\n", DEBUG_REPL ); + debug_print( L"Entered repl_eval\n", DEBUG_REPL ); struct cons_pointer result = NIL; result = eval_form( NULL, NIL, input, oblist ); - debug_print( L"repl_eval: returning\n", DEBUG_REPL ); + debug_print( L"repl_eval: returning\n", DEBUG_REPL ); debug_dump_object( result, DEBUG_REPL ); return result; @@ -68,11 +71,11 @@ struct cons_pointer repl_eval( struct cons_pointer input ) { */ struct cons_pointer repl_print( struct cons_pointer stream_pointer, struct cons_pointer value ) { - debug_print( L"Entered repl_print\n", DEBUG_REPL ); + debug_print( L"Entered repl_print\n", DEBUG_REPL ); debug_dump_object( value, DEBUG_REPL ); struct cons_pointer result = - print( pointer2cell( stream_pointer ).payload.stream.stream, value ); - debug_print( L"repl_print: returning\n", DEBUG_REPL ); + print( pointer2cell( stream_pointer ).payload.stream.stream, value ); + debug_print( L"repl_print: returning\n", DEBUG_REPL ); debug_dump_object( result, DEBUG_REPL ); return result; @@ -88,7 +91,7 @@ struct cons_pointer repl_print( struct cons_pointer stream_pointer, void repl( FILE * in_stream, FILE * out_stream, FILE * error_stream, bool show_prompt ) { - debug_print( L"Entered repl\n", DEBUG_REPL ); + debug_print( L"Entered repl\n", DEBUG_REPL ); struct cons_pointer input_stream = make_read_stream( in_stream ); inc_ref( input_stream ); @@ -113,5 +116,5 @@ repl( FILE * in_stream, FILE * out_stream, FILE * error_stream, } dec_ref( input ); } - debug_print( L"Leaving repl\n", DEBUG_REPL ); + debug_print( L"Leaving repl\n", DEBUG_REPL ); }