LispBM
Data Structures | Functions
stack.h File Reference
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include "lbm_types.h"
Include dependency graph for stack.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  lbm_stack_t
 

Functions

int lbm_stack_allocate (lbm_stack_t *s, lbm_uint stack_size)
 
int lbm_stack_create (lbm_stack_t *s, lbm_uint *data, lbm_uint size)
 
void lbm_stack_free (lbm_stack_t *s)
 
void lbm_stack_clear (lbm_stack_t *s)
 
lbm_uint * lbm_get_stack_ptr (lbm_stack_t *s, lbm_uint n)
 
int lbm_stack_drop (lbm_stack_t *s, lbm_uint n)
 
lbm_uint * lbm_stack_reserve (lbm_stack_t *s, lbm_uint n)
 
int lbm_push (lbm_stack_t *s, lbm_uint val)
 
int lbm_pop (lbm_stack_t *s, lbm_uint *val)
 
static int lbm_stack_is_empty (lbm_stack_t *s)
 
int lbm_push_2 (lbm_stack_t *s, lbm_uint val0, lbm_uint val1)
 
int lbm_pop_2 (lbm_stack_t *s, lbm_uint *r0, lbm_uint *r1)
 
int lbm_pop_3 (lbm_stack_t *s, lbm_uint *r0, lbm_uint *r1, lbm_uint *r2)
 

Function Documentation

◆ lbm_get_stack_ptr()

lbm_uint* lbm_get_stack_ptr ( lbm_stack_t s,
lbm_uint  n 
)

Get a pointer to the nth element (from the top) of a stack.

Parameters
sStack.
nIndex.
Returns
Pointer into the stack or NULL.

◆ lbm_pop()

int lbm_pop ( lbm_stack_t s,
lbm_uint *  val 
)

Pop a value from a stack.

Parameters
sStack to pop a value from.
valPointer to an lbm_value to store the pop:ed value int.
Returns
1 on success and 0 on failure (stack is empty).

◆ lbm_pop_2()

int lbm_pop_2 ( lbm_stack_t s,
lbm_uint *  r0,
lbm_uint *  r1 
)

Pop 2 values from a stack.

Parameters
sStack to pop values from.
r0Pointer to lbm_value where the first pop:ed value will be stored.
r1Pointer to lbm_value where the seconds pop:ed value will be stored.
Returns
1 on success and 0 on failure (stack is empty).

◆ lbm_pop_3()

int lbm_pop_3 ( lbm_stack_t s,
lbm_uint *  r0,
lbm_uint *  r1,
lbm_uint *  r2 
)

Pop 3 values from a stack.

Parameters
sStack to pop values from.
r0
r1
r2
Returns
1 on success and 0 on failure (stack is empty).

◆ lbm_push()

int lbm_push ( lbm_stack_t s,
lbm_uint  val 
)

Push an element onto a stack.

Parameters
sStack to push a value onto.
valValue to push to the stack.
Returns
1 on success and 0 on failure (stack is full).

◆ lbm_push_2()

int lbm_push_2 ( lbm_stack_t s,
lbm_uint  val0,
lbm_uint  val1 
)

Push 2 values to a stack.

Parameters
sStack to push values onto.
val0Is pushed first.
val1Is pushed last.
Returns
1 on success and 0 on failure (stack is full).

◆ lbm_stack_allocate()

int lbm_stack_allocate ( lbm_stack_t s,
lbm_uint  stack_size 
)

Allocate a stack on the symbols and arrays memory. lbm_memory_init must have been run before this function or it will fail.

Parameters
sPointer to an lbm_stack_t to initialize.
stack_sizeSize in 32 bit words of stack to allocate.
Returns
1 on success and 0 on failure.

◆ lbm_stack_clear()

void lbm_stack_clear ( lbm_stack_t s)

Sets the stack SP to 0.

Parameters
sStack to clear.

◆ lbm_stack_create()

int lbm_stack_create ( lbm_stack_t s,
lbm_uint *  data,
lbm_uint  size 
)

Create a stack in a statically allocated array.

Parameters
sPointer to an lbm_stack_t to initialize.
dataPointer to array of 32 bit words to use as the stack storage.
sizeSize in number of 32 bit words.
Returns
1

◆ lbm_stack_drop()

int lbm_stack_drop ( lbm_stack_t s,
lbm_uint  n 
)

Drop n elements (from the top) of a stack.

Parameters
sStack to drop elements from.
nNumber of elements to drop.
Returns
1 on Success and 0 on failure.

◆ lbm_stack_free()

void lbm_stack_free ( lbm_stack_t s)

Free a stack allocated on the lispbm_memory.

Parameters
sPointer to lbm_stack_t to free.

◆ lbm_stack_is_empty()

static int lbm_stack_is_empty ( lbm_stack_t s)
inlinestatic

Check if a stack is empty.

Parameters
sStack to check.
Returns
1 if stack is empty otherwise 0.

◆ lbm_stack_reserve()

lbm_uint* lbm_stack_reserve ( lbm_stack_t s,
lbm_uint  n 
)

Reserve place for n elements on the stack and move the stack pointer to the new top.

Parameters
sStack to reserve values on
nNumber of values to reserve
Returns
Pointer into stack position of reserver value 0 or NULL on failure