#include #include "rifle/scope.h" #include "rifle/trace.h" int scope_push(struct rifle_state *state, tt_t tok) { if (state == NULL) { errno = -EINVAL; return -1; } if (state->scope_depth >= SCOPE_STACK_MAX) { trace_error(state, "maximum scope reached\n"); return -1; } state->scope_stack[state->scope_depth++] = tok; return 0; } tt_t scope_pop(struct rifle_state *state) { tt_t scope; if (state->scope_depth == 0) { return state->scope_stack[0]; } scope = state->scope_stack[--state->scope_depth]; state->scope_stack[state->scope_depth] = TT_NONE; return scope; } tt_t scope_top(struct rifle_state *state) { if (state->scope_depth == 0) { return state->scope_stack[0]; } return state->scope_stack[state->scope_depth - 1]; }