Add apfl_stackidx typedef

This makes it clear that a value of that type is meant as an index into the
stack.
This commit is contained in:
Laria 2022-02-10 22:39:39 +01:00
parent 09c6459565
commit 5f8462fe34
2 changed files with 11 additions and 9 deletions

View file

@ -565,6 +565,8 @@ struct apfl_expr apfl_parser_get_expr(apfl_parser_ptr);
struct apfl_ctx_data;
typedef struct apfl_ctx_data *apfl_ctx;
typedef int apfl_stackidx;
enum apfl_result {
APFL_RESULT_OK, // Evaluation succeeded, value is on the stack
@ -581,7 +583,7 @@ void apfl_ctx_destroy(apfl_ctx);
enum apfl_result apfl_eval(apfl_ctx, struct apfl_expr);
void apfl_debug_print_val(apfl_ctx, int, FILE *);
void apfl_debug_print_val(apfl_ctx, apfl_stackidx, FILE *);
#ifdef __cplusplus
}

View file

@ -230,7 +230,7 @@ stack_push(apfl_ctx ctx, struct apfl_value value)
}
static bool
stack_check_index(apfl_ctx ctx, int *index)
stack_check_index(apfl_ctx ctx, apfl_stackidx *index)
{
if (*index < 0) {
if ((size_t)-*index > ctx->stack_len) {
@ -247,7 +247,7 @@ stack_check_index(apfl_ctx ctx, int *index)
}
static bool
stack_pop(apfl_ctx ctx, struct apfl_value *value, int index)
stack_pop(apfl_ctx ctx, struct apfl_value *value, apfl_stackidx index)
{
if (!stack_check_index(ctx, &index)) {
return false;
@ -271,7 +271,7 @@ stack_pop(apfl_ctx ctx, struct apfl_value *value, int index)
}
static struct apfl_value
stack_must_pop(apfl_ctx ctx, int index)
stack_must_pop(apfl_ctx ctx, apfl_stackidx index)
{
struct apfl_value value;
assert(stack_pop(ctx, &value, index));
@ -279,7 +279,7 @@ stack_must_pop(apfl_ctx ctx, int index)
}
static bool
stack_get(apfl_ctx ctx, struct apfl_value *value, int index)
stack_get(apfl_ctx ctx, struct apfl_value *value, apfl_stackidx index)
{
if (!stack_check_index(ctx, &index)) {
return false;
@ -291,7 +291,7 @@ stack_get(apfl_ctx ctx, struct apfl_value *value, int index)
}
static struct apfl_value
stack_must_get(apfl_ctx ctx, int index)
stack_must_get(apfl_ctx ctx, apfl_stackidx index)
{
struct apfl_value value;
assert(stack_get(ctx, &value, index));
@ -299,7 +299,7 @@ stack_must_get(apfl_ctx ctx, int index)
}
static bool
stack_drop(apfl_ctx ctx, int index)
stack_drop(apfl_ctx ctx, apfl_stackidx index)
{
struct apfl_value value;
if (!stack_pop(ctx, &value, index)) {
@ -310,7 +310,7 @@ stack_drop(apfl_ctx ctx, int index)
}
static void
stack_must_drop(apfl_ctx ctx, int index)
stack_must_drop(apfl_ctx ctx, apfl_stackidx index)
{
assert(stack_drop(ctx, index));
}
@ -1420,7 +1420,7 @@ apfl_eval(apfl_ctx ctx, struct apfl_expr expr)
}
void
apfl_debug_print_val(apfl_ctx ctx, int index, FILE *f)
apfl_debug_print_val(apfl_ctx ctx, apfl_stackidx index, FILE *f)
{
struct apfl_value value;
if (!stack_pop(ctx, &value, index)) {