diff options
| author | Nakidai <plaza521@inbox.ru> | 2024-08-23 20:43:31 +0300 |
|---|---|---|
| committer | Nakidai <plaza521@inbox.ru> | 2024-08-23 20:43:31 +0300 |
| commit | 2b0e05cbc1e4d9beccd3a5867c8730880f6ecc10 (patch) | |
| tree | f0e5e31e6259e0b6ea940c1d4c394b976a4bac74 /src/stack.c | |
| parent | 9e4058194742794f7742f19cb1a0bb3451ce22ea (diff) | |
| download | 3cl-2b0e05cbc1e4d9beccd3a5867c8730880f6ecc10.tar.gz 3cl-2b0e05cbc1e4d9beccd3a5867c8730880f6ecc10.zip | |
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
Diffstat (limited to 'src/stack.c')
| -rw-r--r-- | src/stack.c | 22 |
1 files changed, 22 insertions, 0 deletions
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 <stdlib.h> + + +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--]; +} |