#include #include #include #include "mem.h" #include "stack.h" void stack_alloc(struct stack *st) { st->len = 0; st->cap = 512; st->items = MALLOC(sizeof(st->items[0]) * st->cap); } void *pop(struct stack *st) { return st->items[--(st->len)]; } void push(struct stack *st, void *item) { if (st->len >= st->cap) { st->cap <<= 1; st->items = REALLOC(st->items, sizeof(st->items[0]) * st->cap); } st->items[st->len++] = item; } void stack_free(struct stack *st) { free(st->items); }