| parrotcode: Stack handling routines for Parrot | |
| Contents | C |

src/stacks.c - Stack handling routines for Parrot

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

void stack_system_initmake_interpreter() to initialize the interpreter's register stacks.
Stack_Chunk_t *cst_new_stack_chunkStack_Chunk_t *new_stackstack->name is used for debugging/error reporting.
void mark_stackvoid stack_destroysize_t stack_heightStack_Entry_t *stack_entrydepth >= 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.
Stack_Entry_t *stack_prepare_pushvoid stack_pushNULL,
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.*/PARROT_EXPORT void stack_push(PARROT_INTERP,
ARGMOD(Stack_Chunk_t **stack_p),
ARGIN(void *thing),
Stack_entry_type type,
NULLOK(Stack_cleanup_method cleanup)) { ASSERT_ARGS(stack_push) Stack_Entry_t * const entry = (Stack_Entry_t *)stack_prepare_push(interp,
stack_p);
/* Remember the type */
entry->entry_type = type;
/* Remember the cleanup function */
entry->cleanup = cleanup;
/* Store our thing */
switch (type) {
case STACK_ENTRY_MARK:
UVal_int(entry->entry) = *(INTVAL *)thing;
break;
case STACK_ENTRY_DESTINATION:
UVal_ptr(entry->entry) = thing;
break;
case STACK_ENTRY_ACTION:
case STACK_ENTRY_PMC:
UVal_pmc(entry->entry) = (PMC *)thing;
break;
default:
Parrot_ex_throw_from_c_args(interp, NULL, ERROR_BAD_STACK_TYPE,
"Invalid Stack_Entry_type!");
}
}
/*
Stack_Entry_t *stack_prepare_popvoid *stack_pop /* Types of 0 mean we don't care */
if (type && entry->entry_type != type)
Parrot_ex_throw_from_c_args(interp, NULL, ERROR_BAD_STACK_TYPE,
"Wrong type on top of stack!\n");
/* Cleanup routine? */
if (entry->cleanup != STACK_CLEANUP_NULL)
(*entry->cleanup) (interp, entry);
/* Sometimes the caller cares what the value was */
if (where) {
/* Snag the value */
switch (type) {
case STACK_ENTRY_MARK:
*(INTVAL *)where = UVal_int(entry->entry);
break;
case STACK_ENTRY_DESTINATION:
*(void **)where = UVal_ptr(entry->entry);
break;
case STACK_ENTRY_ACTION:
case STACK_ENTRY_PMC:
*(PMC **)where = UVal_pmc(entry->entry);
break;
default:
Parrot_ex_throw_from_c_args(interp, NULL, ERROR_BAD_STACK_TYPE,
"Wrong type on top of stack!\n");
}
}
/* recycle this chunk to the free list if it's otherwise unreferenced */
if (cur_chunk->refcount <= 0) {
Small_Object_Pool * const pool = cur_chunk->pool;
pool->dod_object(interp, pool, (PObj *)cur_chunk);
pool->add_free_object(interp, pool, (PObj *)cur_chunk);
}
return where;
}
/*
void *pop_destvoid *stack_peekStack_entry_type get_entry_typeentry.
void Parrot_dump_dynamic_environmentParrot_io_eprintf). This is used only temporarily for debugging.
static void run_cleanup_actionParrot_push_action.
void Parrot_push_actionvoid Parrot_push_markvoid Parrot_pop_mark
include/parrot/stacks.h and include/parrot/enums.h.
|
|
|