Merge commit '67e31df279eb74c8e35d3570f80e96b1a4073f32'

This commit is contained in:
Benjamin Vedder 2022-11-16 12:31:09 +01:00
commit 2a87b5a954
1 changed files with 21 additions and 13 deletions

View File

@ -1893,14 +1893,18 @@ static void apply_reverse(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
if (nargs == 1 && lbm_is_list(args[1])) {
lbm_value curr = args[1];
char buf[1024];
lbm_print_value(buf,1024, args[1]);
printf("before: %s\n", buf);
lbm_value new_list = ENC_SYM_NIL;
while (lbm_type_of(curr) == LBM_TYPE_CONS) {
WITH_GC_1(new_list, lbm_cons(lbm_car(curr), new_list), new_list);
if (lbm_type_of(new_list) == LBM_TYPE_SYMBOL) {
error_ctx(ENC_SYM_MERROR);
}
lbm_value tmp;
WITH_GC_1(tmp, lbm_cons(lbm_car(curr), new_list), new_list);
new_list = tmp;
curr = lbm_cdr(curr);
}
lbm_print_value(buf,1024, new_list);
printf("after: %s\n", buf);
lbm_stack_drop(&ctx->K, 2);
ctx->r = new_list;
ctx->app_cont = true;
@ -1976,7 +1980,7 @@ static void application(eval_context_t *ctx, lbm_value *fun_args, lbm_uint arg_c
lbm_value res;
WITH_GC(res, fundamental_table[fund_ix](&fun_args[1], arg_count, ctx));
if (lbm_is_error(res)) {
if (lbm_is_error(res)) { //Error other than merror.
error_ctx(res);
return;
}
@ -1993,7 +1997,7 @@ static void application(eval_context_t *ctx, lbm_value *fun_args, lbm_uint arg_c
lbm_value ext_res;
WITH_GC(ext_res, f(&fun_args[1], arg_count));
if (lbm_is_error(ext_res)) {
if (lbm_is_error(ext_res)) { //Error other than merror
error_ctx(ext_res);
return;
}
@ -2044,14 +2048,17 @@ static void cont_closure_application_args(eval_context_t *ctx) {
bool p_nil = lbm_is_symbol_nil(lbm_cdr(params));
if (a_nil && p_nil) {
// Arguments and parameters match up in number
lbm_stack_drop(&ctx->K, 5);
ctx->curr_env = clo_env;
ctx->curr_exp = exp;
ctx->app_cont = false;
} else if (!a_nil && p_nil) {
// Application with extra arguments
lbm_set_error_reason((char*)num_args_error);
error_ctx(ENC_SYM_EERROR);
} else if (a_nil && !p_nil) {
// Ran out of arguments, but there are still parameters.
lbm_value new_env = lbm_list_append(arg_env,clo_env);
lbm_value closure;
if (mk_closure(&closure, new_env, exp, lbm_cdr(params))) {
@ -2062,6 +2069,7 @@ static void cont_closure_application_args(eval_context_t *ctx) {
error_ctx(ENC_SYM_MERROR);
}
} else {
// evaluate the next argument.
sptr[2] = clo_env;
sptr[3] = lbm_cdr(params);
sptr[4] = lbm_cdr(args);