
// stack operations

int pop() {
  int pop_value;
  if (stack_idx <= 0) {
    log_error(STACK_UNDERFLOW, 0);
    return 0;
  }
  else {
    pop_value = stack[stack_idx - 1];
    stack_idx = stack_idx - 1;
    return pop_value;
  }
}

void push(int x) {
  stack[stack_idx] = x;
  stack_idx = stack_idx + 1;
  // TODO check for stack overflow
  return;
}

int tos() {
  if (stack_idx <= 0) {
    log_error(STACK_UNDERFLOW, 0);
    return 0;
  }
  else
    return stack[stack_idx - 1];
}

int empty_stack() {
  return stack_idx <= 0;
}
