LispBM
stack.h
Go to the documentation of this file.
1 
2 /*
3  Copyright 2019 Joel 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 {
34  lbm_uint* data;
35  lbm_uint sp;
36  lbm_uint size;
37  lbm_uint max_sp;
38 } lbm_stack_t;
39 
46 int lbm_stack_allocate(lbm_stack_t *s, lbm_uint stack_size);
54 int lbm_stack_create(lbm_stack_t *s, lbm_uint* data, lbm_uint size);
71 lbm_uint *lbm_get_stack_ptr(lbm_stack_t *s, lbm_uint n);
78 int lbm_stack_drop(lbm_stack_t *s, lbm_uint n);
79 
87 lbm_uint *lbm_stack_reserve(lbm_stack_t *s, lbm_uint n);
94 int lbm_push(lbm_stack_t *s, lbm_uint val);
101 int lbm_pop(lbm_stack_t *s, lbm_uint *val);
102 
108 static inline int lbm_stack_is_empty(lbm_stack_t *s) {
109  if (s->sp == 0) return 1;
110  return 0;
111 }
112 
120 int lbm_push_2(lbm_stack_t *s, lbm_uint val0, lbm_uint val1);
121 
129 int lbm_pop_2(lbm_stack_t *s, lbm_uint *r0, lbm_uint *r1);
130 
139 int lbm_pop_3(lbm_stack_t *s, lbm_uint *r0, lbm_uint *r1, lbm_uint *r2);
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 #endif
int lbm_push_2(lbm_stack_t *s, lbm_uint val0, lbm_uint val1)
void lbm_stack_free(lbm_stack_t *s)
lbm_uint * lbm_get_stack_ptr(lbm_stack_t *s, lbm_uint n)
int lbm_stack_create(lbm_stack_t *s, lbm_uint *data, lbm_uint size)
int lbm_stack_allocate(lbm_stack_t *s, lbm_uint stack_size)
int lbm_push(lbm_stack_t *s, lbm_uint val)
lbm_uint * lbm_stack_reserve(lbm_stack_t *s, lbm_uint n)
int lbm_stack_drop(lbm_stack_t *s, lbm_uint n)
void lbm_stack_clear(lbm_stack_t *s)
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)
static int lbm_stack_is_empty(lbm_stack_t *s)
Definition: stack.h:108
int lbm_pop(lbm_stack_t *s, lbm_uint *val)
Definition: stack.h:33