Sha256: b27ae9a9694b2927645099398af07afc5cf671922db184eb6cbe4c6dbf017f8b

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

/*
 * compiler/stack.h: Data structure to emulate YARV stack.
 * This header is used only by compiler.c.
 */

#ifndef LLRB_COMPILER_STACK_H
#define LLRB_COMPILER_STACK_H

// Emulates rb_control_frame's sp (stack pointer), which is function local
struct llrb_stack {
  unsigned int size;
  unsigned int max;
  LLVMValueRef *body;
};

static void
llrb_stack_push(struct llrb_stack *stack, LLVMValueRef value)
{
  if (stack->size >= stack->max) {
    rb_raise(rb_eCompileError, "LLRB's internal stack overflow: max=%d, next size=%d", stack->max, stack->size+1);
  }
  stack->body[stack->size] = value;
  stack->size++;
}

static LLVMValueRef
llrb_stack_pop(struct llrb_stack *stack)
{
  if (stack->size <= 0) {
    rb_raise(rb_eCompileError, "LLRB's internal stack underflow: next size=%d", stack->size-1);
  }
  stack->size--;
  return stack->body[stack->size];
}

static inline LLVMValueRef
llrb_stack_topn(struct llrb_stack *stack, unsigned int n)
{
  unsigned int last = stack->size - 1;
  return stack->body[last - n];
}

#endif // LLRB_COMPILER_STACK_H

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
llrb-0.0.1 ext/llrb/compiler/stack.h