Much better GC, still a few things being missed.

This commit is contained in:
Simon Brooke 2018-12-29 20:03:06 +00:00
parent 2ec5d37305
commit c21a762413
6 changed files with 55 additions and 15 deletions

View file

@ -198,7 +198,6 @@ eval_lambda( struct cons_space_object cell, struct stack_frame *frame,
debug_println(DEBUG_LAMBDA);
struct cons_pointer new_env = env;
inc_ref(new_env);
struct cons_pointer names = cell.payload.lambda.args;
struct cons_pointer body = cell.payload.lambda.body;
@ -214,6 +213,8 @@ eval_lambda( struct cons_space_object cell, struct stack_frame *frame,
names = c_cdr( names );
}
inc_ref(new_env);
/* 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,
@ -232,6 +233,7 @@ eval_lambda( struct cons_space_object cell, struct stack_frame *frame,
}
new_env = bind( names, vals, new_env );
inc_ref(new_env);
}
while ( !nilp( body ) ) {
@ -242,6 +244,10 @@ eval_lambda( struct cons_space_object cell, struct stack_frame *frame,
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);
result = eval_form( frame, frame_pointer, sexpr, new_env );
}

View file

@ -130,20 +130,32 @@ struct cons_pointer print( FILE * output, struct cons_pointer pointer ) {
}
fwprintf( output, L"%ld%", cell.payload.integer.value );
break;
case LAMBDATV:
print( output, make_cons( c_string_to_lisp_symbol( L"lambda" ),
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 ) ) );
lambda.body ));
inc_ref(to_print);
print( output, to_print );
dec_ref(to_print);
}
break;
case NILTV:
fwprintf( output, L"nil" );
break;
case NLAMBDATV:
print( output, make_cons( c_string_to_lisp_symbol( L"nlambda" ),
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 ) ) );
lambda.body ));
inc_ref(to_print);
print( output, to_print );
dec_ref(to_print);
}
break;
case RATIOTV:
print( output, cell.payload.ratio.dividend );