This commit is contained in:
Laria 2023-11-24 21:54:31 +01:00
parent 8d8fcdd64b
commit e5c4f32126
3 changed files with 28 additions and 26 deletions

View file

@ -2530,3 +2530,26 @@ apfl_cfunc_run_deferred(apfl_ctx ctx, struct call_stack_entry *cse)
deferred->cb(ctx, deferred->opaque);
}
}
bool
apfl_call_stack_try_push(apfl_ctx ctx, struct call_stack_entry cse)
{
return apfl_resizable_append(
ctx->gc.allocator,
sizeof(struct call_stack_entry),
(void**)&ctx->call_stack.items,
&ctx->call_stack.len,
&ctx->call_stack.cap,
&cse,
1
);
}
void
apfl_call_stack_push(apfl_ctx ctx, struct call_stack_entry cse)
{
if (!apfl_call_stack_try_push(ctx, cse)) {
apfl_call_stack_entry_deinit(ctx->gc.allocator, &cse);
apfl_raise_alloc_error(ctx);
}
}

View file

@ -209,6 +209,8 @@ struct apfl_string *apfl_to_dynamic_string(apfl_ctx ctx, apfl_stackidx index);
noreturn void apfl_raise_errorfmt(apfl_ctx ctx, const char *fmt, ...);
struct call_stack_entry *apfl_call_stack_cur_entry(apfl_ctx);
bool apfl_call_stack_try_push(apfl_ctx ctx, struct call_stack_entry cse);
void apfl_call_stack_push(apfl_ctx ctx, struct call_stack_entry cse);
struct scope *apfl_closure_scope_for_func(apfl_ctx, struct scopes);

View file

@ -334,29 +334,6 @@ func_set_name(apfl_ctx ctx, struct apfl_string *name)
apfl_func_set_name(value.func, name);
}
static bool
try_call_stack_push(apfl_ctx ctx, struct call_stack_entry cse)
{
return apfl_resizable_append(
ctx->gc.allocator,
sizeof(struct call_stack_entry),
(void**)&ctx->call_stack.items,
&ctx->call_stack.len,
&ctx->call_stack.cap,
&cse,
1
);
}
static void
call_stack_push(apfl_ctx ctx, struct call_stack_entry cse)
{
if (!try_call_stack_push(ctx, cse)) {
apfl_call_stack_entry_deinit(ctx->gc.allocator, &cse);
apfl_raise_alloc_error(ctx);
}
}
static void
call_stack_drop(apfl_ctx ctx)
{
@ -400,7 +377,7 @@ return_from_function(apfl_ctx ctx)
static void
prepare_call(apfl_ctx ctx, size_t tmproots, struct apfl_value args, struct call_stack_entry cse)
{
call_stack_push(ctx, cse);
apfl_call_stack_push(ctx, cse);
// Note: This pushes args on the stack of the newly created call stack
apfl_stack_must_push(ctx, args);
@ -822,7 +799,7 @@ matcher_init_matching_inner(apfl_ctx ctx, struct matcher *matcher, struct scopes
matcher_cse.matcher_state_stack_len = 1;
matcher_cse.matcher_state_stack_cap = 1;
if (!try_call_stack_push(ctx, (struct call_stack_entry) {
if (!apfl_call_stack_try_push(ctx, (struct call_stack_entry) {
.type = APFL_CSE_MATCHER,
.stack = apfl_stack_new(),
.matcher = matcher_cse,
@ -1455,7 +1432,7 @@ iterative_runner_eval_expr_inner(apfl_iterative_runner runner, struct apfl_expr
apfl_raise_error_object(ctx, error);
}
call_stack_push(ctx, (struct call_stack_entry) {
apfl_call_stack_push(ctx, (struct call_stack_entry) {
.type = APFL_CSE_FUNCTION,
.stack = apfl_stack_new(),
.func = (struct func_call_stack_entry) {