NAME ^

src/stacks.c - Stack handling routines for Parrot

DESCRIPTION ^

The stack is stored as a linked list of chunks (Stack_Chunk), where each chunk has room for one entry.

Functions ^

Stack_Chunk_t *new_stack(Interp *interpreter, const char *name)

Create a new stack and name it. stack->name is used for debugging/error reporting.

void mark_stack(Interp *interpreter, Stack_Chunk_t *chunk)

Mark entries in a stack structure during DOD.

void stack_destroy(Stack_Chunk_t *top)

GC does it all.

size_t stack_height(Interp *interpreter, Stack_Chunk_t *top)

Returns the height of the stack. The maximum "depth" is height - 1.

Stack_Entry_t *stack_entry(Interp *interpreter, Stack_Chunk_t *stack, INTVAL depth)

If depth >= 0, return the entry at that depth from the top of the stack, with 0 being the top entry. If depth < 0, then return the entry |depth| entries from the bottom of the stack. Returns NULL if |depth| number> of entries in stack.

void rotate_entries(Interp *interpreter, Stack_Chunk_t **stack_p, INTVAL num_entries)

Rotate the top N entries by one. If N 0>, the rotation is bubble up, so the top most element becomes the Nth element. If N < 0, the rotation is bubble down, so that the Nth element becomes the top most element.

void stack_push(Interp *interpreter, Stack_Chunk_t **stack_p, void *thing, Stack_entry_type type, Stack_cleanup_method cleanup)

Push something on the generic stack.

Note that the cleanup pointer, if non-NULL, points to a routine that'll be called when the entry is removed from the stack. This is handy for those cases where you need some sort of activity to take place when an entry is removed, such as when you push a lexical lock onto the call stack, or localize (or tempify, or whatever we're calling it) variable or something.

void *stack_pop(Interp *interpreter, Stack_Chunk_t **stack_p, void *where, Stack_entry_type type)

Pop off an entry and return a pointer to the contents.

void *pop_dest(Interp *interpreter)

Pop off a destination entry and return a pointer to the contents.

void *stack_peek(Interp *interpreter, Stack_Chunk_t *stack_base, Stack_entry_type *type)

Peek at stack and return pointer to entry and the type of the entry.

Stack_entry_type get_entry_type(Interp *interpreter, Stack_Entry_t *entry)

Returns the stack entry type of entry.

SEE ALSO ^

include/parrot/stacks.h, include/parrot/enums.h, and src/stack_common.c


parrot