#include "types.h" #include void stack_init(Stack* stack, uint32_t len) { stack->index = 0; stack->len = len; stack->data = malloc(stack->len * sizeof(union stored)); } void stack_push(Stack* stack, void* value) { if (stack->index == stack->len) { stack->len *= 2; stack->data = realloc(stack->data, stack->len * sizeof(union stored)); } stack->data[stack->index].p = value; stack->index++; } void* stack_pop(Stack* stack) { if (stack->index == 0) { return NULL; } stack->index--; return stack->data[stack->index].p; } void stack_pushi(Stack* stack, uint32_t value) { if (stack->index == stack->len) { stack->len *= 2; stack->data = realloc(stack->data, stack->len * sizeof(union stored)); } stack->data[stack->index].i = value; stack->index++; } uint32_t stack_popi(Stack* stack) { if (stack->index == 0) { return 0; } stack->index--; return stack->data[stack->index].i; } void stack_free(Stack* stack) { free(stack->data); }