BCI-dev/interpreter/stack.c

27 lines
421 B
C
Raw Normal View History

2018-09-26 15:50:12 +00:00
#include <stdlib.h>
#include "stack.h"
char bci_stack_t_push(bci_stack_t * stack, uint16_t value)
{
bci_stack_t node = malloc(sizeof(struct bci_stack_s));
if(!node)
{
return 1;
}
node->next = *stack;
node->value = value;
stack = &node;
return 0;
}
char bci_stack_t_pop(bci_stack_t * stack, uint16_t * result)
{
if(!*stack)
{
return 1;
}
*result = (*stack)->value;
*stack = (*stack)->next;
return 0;
}