#ifndef APFL_CONTEXT_H #define APFL_CONTEXT_H #ifdef __cplusplus extern "C" { #endif #include #include #include "bytecode.h" #include "hashmap.h" #include "gc.h" #include "value.h" #include "scope.h" struct stack { struct apfl_value *items; size_t len; size_t cap; }; struct error_handler { jmp_buf jump; bool with_error_on_stack; }; struct apfl_ctx_data { struct gc gc; apfl_panic_callback panic_callback; void *panic_callback_data; struct scope *scope; struct stack *stack; struct error_handler *error_handler; int execution_line; }; APFL_NORETURN void apfl_raise_error_with_type(apfl_ctx, apfl_stackidx, enum apfl_result type); APFL_NORETURN void apfl_raise_const_error(apfl_ctx, enum apfl_result type, const char *message); APFL_NORETURN void apfl_raise_alloc_error(apfl_ctx); APFL_NORETURN void apfl_raise_invalid_stackidx(apfl_ctx); APFL_NORETURN void apfl_raise_error_object(apfl_ctx, struct apfl_error); void apfl_stack_deinit(struct apfl_allocator, struct stack *); void apfl_gc_stack_traverse(struct stack *, gc_visitor, void *); bool apfl_stack_push(apfl_ctx, struct apfl_value); void apfl_stack_must_push(apfl_ctx ctx, struct apfl_value value); bool apfl_stack_check_index(apfl_ctx, apfl_stackidx *); bool apfl_stack_pop(apfl_ctx, struct apfl_value *value, apfl_stackidx); bool apfl_stack_get(apfl_ctx, struct apfl_value *value, apfl_stackidx); bool apfl_stack_drop(apfl_ctx, apfl_stackidx); bool apfl_stack_move_to_top(apfl_ctx, apfl_stackidx); void apfl_stack_clear(apfl_ctx); struct apfl_value *apfl_stack_push_placeholder(apfl_ctx); bool apfl_move_string_onto_stack(apfl_ctx, struct apfl_string); typedef void (*apfl_protected_callback)(apfl_ctx, void *); enum apfl_result apfl_protected(apfl_ctx, apfl_protected_callback, void *, bool *with_error_on_stack); #ifdef __cplusplus } #endif #endif