From 2b0e05cbc1e4d9beccd3a5867c8730880f6ecc10 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Fri, 23 Aug 2024 20:43:31 +0300 Subject: Start to rewriting code Since there's some UB in the master I decided to rewrite code from scratch again. I hope that attempt will be better :D --- src/stack.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/stack.c (limited to 'src/stack.c') diff --git a/src/stack.c b/src/stack.c new file mode 100644 index 0000000..3a1f697 --- /dev/null +++ b/src/stack.c @@ -0,0 +1,22 @@ +#include "3cl.h" + +#include + + +static inline void resize(struct CCLStack *stack) +{ + stack->length *= 2; + stack->stack = realloc(stack->stack, stack->length * sizeof(*stack->stack)); +} + +void ccl_stack_push(struct CCLStack *stack, CCLNum num) +{ + if (stack->cur + 1 == stack->length) + resize(stack); + stack->stack[++stack->cur] = num; +} + +CCLNum ccl_stack_pop(struct CCLStack *stack, CCLNum num) +{ + return stack->stack[stack->cur--]; +} -- cgit 1.4.1