Printing of bignums basically done, not tested.
This commit is contained in:
parent
342f0308d3
commit
489f008044
14 changed files with 244 additions and 164 deletions
|
|
@ -80,14 +80,15 @@ 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 =
|
||||
(cell_a->payload.integer.value ==
|
||||
cell_b->payload.integer.value) &&
|
||||
equal(cell_a->payload.integer.more, cell_b->payload.integer.more);
|
||||
( cell_a->payload.integer.value ==
|
||||
cell_b->payload.integer.value ) &&
|
||||
equal( cell_a->payload.integer.more,
|
||||
cell_b->payload.integer.more );
|
||||
break;
|
||||
case REALTV:
|
||||
{
|
||||
|
|
|
|||
|
|
@ -131,8 +131,8 @@ deep_bind( struct cons_pointer key, struct cons_pointer value ) {
|
|||
struct cons_pointer old = oblist;
|
||||
|
||||
oblist = bind( key, value, oblist );
|
||||
inc_ref(oblist);
|
||||
dec_ref(old);
|
||||
inc_ref( oblist );
|
||||
dec_ref( old );
|
||||
|
||||
debug_print( L"Leaving deep_bind\n", DEBUG_BIND );
|
||||
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ eval_lambda( struct cons_space_object cell, struct stack_frame *frame,
|
|||
struct cons_pointer frame_pointer, struct cons_pointer env ) {
|
||||
struct cons_pointer result = NIL;
|
||||
debug_print( L"eval_lambda called\n", DEBUG_LAMBDA );
|
||||
debug_println(DEBUG_LAMBDA);
|
||||
debug_println( DEBUG_LAMBDA );
|
||||
|
||||
struct cons_pointer new_env = env;
|
||||
struct cons_pointer names = cell.payload.lambda.args;
|
||||
|
|
@ -213,7 +213,7 @@ eval_lambda( struct cons_space_object cell, struct stack_frame *frame,
|
|||
|
||||
names = c_cdr( names );
|
||||
}
|
||||
inc_ref(new_env);
|
||||
inc_ref( new_env );
|
||||
|
||||
/* TODO: if there's more than `args_in_frame` arguments, bind those too. */
|
||||
} else if ( symbolp( names ) ) {
|
||||
|
|
@ -233,7 +233,7 @@ eval_lambda( struct cons_space_object cell, struct stack_frame *frame,
|
|||
}
|
||||
|
||||
new_env = bind( names, vals, new_env );
|
||||
inc_ref(new_env);
|
||||
inc_ref( new_env );
|
||||
}
|
||||
|
||||
while ( !nilp( body ) ) {
|
||||
|
|
@ -241,21 +241,22 @@ eval_lambda( struct cons_space_object cell, struct stack_frame *frame,
|
|||
body = c_cdr( body );
|
||||
|
||||
debug_print( L"In lambda: evaluating ", DEBUG_LAMBDA );
|
||||
debug_print_object(sexpr, DEBUG_LAMBDA);
|
||||
debug_println( DEBUG_LAMBDA);
|
||||
debug_print_object( sexpr, DEBUG_LAMBDA );
|
||||
debug_println( DEBUG_LAMBDA );
|
||||
|
||||
/* if a result is not the terminal result in the lambda, it's a
|
||||
* side effect, and needs to be GCed */
|
||||
if (!nilp(result)) dec_ref(result);
|
||||
/* if a result is not the terminal result in the lambda, it's a
|
||||
* side effect, and needs to be GCed */
|
||||
if ( !nilp( result ) )
|
||||
dec_ref( result );
|
||||
|
||||
result = eval_form( frame, frame_pointer, sexpr, new_env );
|
||||
}
|
||||
|
||||
dec_ref(new_env);
|
||||
dec_ref( new_env );
|
||||
|
||||
debug_print( L"eval_lambda returning: \n", DEBUG_LAMBDA );
|
||||
debug_print_object( result, DEBUG_LAMBDA);
|
||||
debug_println(DEBUG_LAMBDA);
|
||||
debug_print_object( result, DEBUG_LAMBDA );
|
||||
debug_println( DEBUG_LAMBDA );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -352,9 +353,10 @@ c_apply( struct stack_frame *frame, struct cons_pointer frame_pointer,
|
|||
result = next_pointer;
|
||||
} else {
|
||||
result =
|
||||
( *fn_cell.payload.special.
|
||||
executable ) ( get_stack_frame( next_pointer ),
|
||||
next_pointer, env );
|
||||
( *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 );
|
||||
|
|
|
|||
|
|
@ -124,38 +124,42 @@ struct cons_pointer print( FILE * output, struct cons_pointer pointer ) {
|
|||
case FUNCTIONTV:
|
||||
fwprintf( output, L"(Function)" );
|
||||
break;
|
||||
case INTEGERTV:
|
||||
if ( print_use_colours ) {
|
||||
fputws( L"\x1B[34m", output );
|
||||
case INTEGERTV:{
|
||||
struct cons_pointer s = integer_to_string( pointer, 10 );
|
||||
inc_ref( s );
|
||||
if ( print_use_colours ) {
|
||||
fputws( L"\x1B[34m", output );
|
||||
}
|
||||
print_string_contents( output, s );
|
||||
dec_ref( s );
|
||||
}
|
||||
fwprintf( output, L"%ld%", cell.payload.integer.value );
|
||||
break;
|
||||
case LAMBDATV: {
|
||||
struct cons_pointer to_print = make_cons( c_string_to_lisp_symbol( L"lambda" ),
|
||||
make_cons( cell.payload.lambda.args,
|
||||
cell.payload.
|
||||
lambda.body ));
|
||||
inc_ref(to_print);
|
||||
case LAMBDATV:{
|
||||
struct cons_pointer to_print =
|
||||
make_cons( c_string_to_lisp_symbol( L"lambda" ),
|
||||
make_cons( cell.payload.lambda.args,
|
||||
cell.payload.lambda.body ) );
|
||||
inc_ref( to_print );
|
||||
|
||||
print( output, to_print );
|
||||
print( output, to_print );
|
||||
|
||||
dec_ref(to_print);
|
||||
}
|
||||
dec_ref( to_print );
|
||||
}
|
||||
break;
|
||||
case NILTV:
|
||||
fwprintf( output, L"nil" );
|
||||
break;
|
||||
case NLAMBDATV: {
|
||||
struct cons_pointer to_print = make_cons( c_string_to_lisp_symbol( L"nlambda" ),
|
||||
make_cons( cell.payload.lambda.args,
|
||||
cell.payload.
|
||||
lambda.body ));
|
||||
inc_ref(to_print);
|
||||
case NLAMBDATV:{
|
||||
struct cons_pointer to_print =
|
||||
make_cons( c_string_to_lisp_symbol( L"nlambda" ),
|
||||
make_cons( cell.payload.lambda.args,
|
||||
cell.payload.lambda.body ) );
|
||||
inc_ref( to_print );
|
||||
|
||||
print( output, to_print );
|
||||
print( output, to_print );
|
||||
|
||||
dec_ref(to_print);
|
||||
}
|
||||
dec_ref( to_print );
|
||||
}
|
||||
break;
|
||||
case RATIOTV:
|
||||
print( output, cell.payload.ratio.dividend );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue