LispBM
stack.h
Go to the documentation of this file.
1 
2 /*
3  Copyright 2019, 2024Joel Svensson svenssonjoel@yahoo.se
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef STACK_H_
19 #define STACK_H_
20 
21 
22 #include <stdlib.h>
23 #include <stdint.h>
24 #include <stdbool.h>
25 #include <stdio.h>
26 
27 #include "lbm_types.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 typedef struct {
37 } lbm_stack_t;
38 
45 int lbm_stack_allocate(lbm_stack_t *s, lbm_uint stack_size);
53 int lbm_stack_create(lbm_stack_t *s, lbm_uint* data, lbm_uint size);
82 int lbm_push(lbm_stack_t *s, lbm_uint val);
89 int lbm_pop(lbm_stack_t *s, lbm_uint *val);
90 
96 static inline int lbm_stack_is_empty(lbm_stack_t *s) {
97  if (s->sp == 0) return 1;
98  return 0;
99 }
100 
108 int lbm_pop_2(lbm_stack_t *s, lbm_uint *r0, lbm_uint *r1);
109 
118 int lbm_pop_3(lbm_stack_t *s, lbm_uint *r0, lbm_uint *r1, lbm_uint *r2);
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 #endif
lbm_uint
uint32_t lbm_uint
Definition: lbm_types.h:48
lbm_get_max_stack
lbm_uint lbm_get_max_stack(lbm_stack_t *s)
Definition: stack.c:52
lbm_stack_clear
void lbm_stack_clear(lbm_stack_t *s)
Definition: stack.c:70
lbm_push
int lbm_push(lbm_stack_t *s, lbm_uint val)
Definition: stack.c:82
lbm_stack_t
Definition: stack.h:33
lbm_stack_drop
int lbm_stack_drop(lbm_stack_t *s, lbm_uint n)
Definition: stack.c:74
lbm_stack_allocate
int lbm_stack_allocate(lbm_stack_t *s, lbm_uint stack_size)
Definition: stack.c:32
lbm_stack_is_empty
static int lbm_stack_is_empty(lbm_stack_t *s)
Definition: stack.h:96
lbm_pop_2
int lbm_pop_2(lbm_stack_t *s, lbm_uint *r0, lbm_uint *r1)
Definition: stack.c:97
lbm_stack_t::sp
lbm_uint sp
Definition: stack.h:35
lbm_stack_t::data
lbm_uint * data
Definition: stack.h:34
lbm_pop_3
int lbm_pop_3(lbm_stack_t *s, lbm_uint *r0, lbm_uint *r1, lbm_uint *r2)
Definition: stack.c:104
lbm_stack_free
void lbm_stack_free(lbm_stack_t *s)
Definition: stack.c:64
lbm_pop
int lbm_pop(lbm_stack_t *s, lbm_uint *val)
Definition: stack.c:91
lbm_types.h
lbm_stack_t::size
lbm_uint size
Definition: stack.h:36
lbm_stack_create
int lbm_stack_create(lbm_stack_t *s, lbm_uint *data, lbm_uint size)
Definition: stack.c:44