mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-03-19 03:00:58 -07:00
[maybe] stacks: add more operations
This commit is contained in:
parent
357ef042ed
commit
0f616e9e2c
2 changed files with 59 additions and 0 deletions
|
|
@ -873,6 +873,43 @@ ecl_stack_push(cl_object self, cl_object elt)
|
|||
return self;
|
||||
}
|
||||
|
||||
cl_object
|
||||
ecl_stack_pop(cl_object self)
|
||||
{
|
||||
cl_index fillp = self->vector.fillp;
|
||||
cl_object elt = ECL_NIL;
|
||||
if (ecl_unlikely(fillp == 0)) {
|
||||
ecl_internal_error("ecl_stack_pop: stack underflow");
|
||||
}
|
||||
elt = self->vector.self.t[fillp-1];
|
||||
self->vector.self.t[fillp-1] = ECL_NIL;
|
||||
self->vector.fillp--;
|
||||
return elt;
|
||||
}
|
||||
|
||||
cl_object
|
||||
ecl_stack_psh(cl_object self, cl_object elt)
|
||||
{
|
||||
cl_index fillp = self->vector.fillp;
|
||||
cl_index dim = self->vector.dim;
|
||||
if (ecl_unlikely(fillp == dim)) {
|
||||
ecl_internal_error("ecl_stack_psh: stack overflow");
|
||||
}
|
||||
self->vector.self.t[self->vector.fillp++] = elt;
|
||||
return self;
|
||||
}
|
||||
|
||||
cl_object
|
||||
ecl_stack_dup(cl_object self)
|
||||
{
|
||||
cl_index fillp = self->vector.fillp;
|
||||
if (ecl_unlikely(fillp == 0)) {
|
||||
ecl_internal_error("ecl_stack_dup: empty stack");
|
||||
}
|
||||
ecl_stack_push(self, self->vector.self.t[fillp-1]);
|
||||
return self;
|
||||
}
|
||||
|
||||
cl_object
|
||||
ecl_stack_del(cl_object self, cl_object elt)
|
||||
{
|
||||
|
|
@ -898,3 +935,22 @@ ecl_stack_popu(cl_object self)
|
|||
self->vector.self.t[self->vector.fillp] = ECL_NIL;
|
||||
return result;
|
||||
}
|
||||
|
||||
cl_object
|
||||
ecl_stack_pshu(cl_object self, cl_object elt)
|
||||
{
|
||||
self->vector.self.t[self->vector.fillp++] = elt;
|
||||
return elt;
|
||||
}
|
||||
|
||||
void
|
||||
ecl_stack_grow(cl_object self, cl_index n)
|
||||
{
|
||||
self->vector.fillp += n;
|
||||
}
|
||||
|
||||
void
|
||||
ecl_stack_drop(cl_object self, cl_index n)
|
||||
{
|
||||
self->vector.fillp -= n;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -311,7 +311,10 @@ extern ECL_API void ecl_free_stack(cl_object o);
|
|||
extern ECL_API void ecl_wipe_stack(cl_object o);
|
||||
extern ECL_API cl_object ecl_stack_push(cl_object stack, cl_object elt);
|
||||
extern ECL_API cl_object ecl_stack_del(cl_object stack, cl_object elt);
|
||||
extern ECL_API cl_object ecl_stack_pop(cl_object stack);
|
||||
extern ECL_API cl_object ecl_stack_psh(cl_object stack, cl_object elt);
|
||||
extern ECL_API cl_object ecl_stack_popu(cl_object stack);
|
||||
extern ECL_API cl_object ecl_stack_pshu(cl_object stack, cl_object elt);
|
||||
|
||||
/* array.c */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue