blob: 2d920ea78b963a071c8a7ac8e337c0902446c5e0 [file] [log] [blame]
swissChili7a6f5eb2021-04-13 16:46:02 -07001#include "lisp.h"
swissChili8cfb7c42021-04-18 21:17:58 -07002#include "plat/plat.h"
3
swissChili7a6f5eb2021-04-13 16:46:02 -07004#include <ctype.h>
5#include <stdbool.h>
6#include <stdio.h>
swissChilibed80922021-04-13 21:58:05 -07007#include <stdlib.h>
8#include <string.h>
swissChili7a6f5eb2021-04-13 16:46:02 -07009
swissChili9e57da42021-06-15 22:22:46 -070010struct alloc *first_a = NULL, *last_a = NULL;
swissChili7a6f5eb2021-04-13 16:46:02 -070011
swissChili8cfb7c42021-04-18 21:17:58 -070012value_t nil = 0b00101111; // magic ;)
swissChili923b5362021-05-09 20:31:43 -070013value_t t = 1 << 3;
swissChilibed80922021-04-13 21:58:05 -070014
swissChilib8fd4712021-06-23 15:32:04 -070015unsigned char max_pool = 0, current_pool = 0;
16
swissChili53472e82021-05-08 16:06:32 -070017void err(const char *msg)
swissChilibed80922021-04-13 21:58:05 -070018{
swissChili53472e82021-05-08 16:06:32 -070019 fprintf(stderr, "ERROR: %s\n", msg);
20 exit(1);
swissChilibed80922021-04-13 21:58:05 -070021}
22
swissChili53472e82021-05-08 16:06:32 -070023value_t intval(int i)
swissChili7a6f5eb2021-04-13 16:46:02 -070024{
swissChili8cfb7c42021-04-18 21:17:58 -070025 i <<= 2;
26 i |= INT_TAG;
27 return i;
28}
29
swissChili53472e82021-05-08 16:06:32 -070030value_t cons(value_t car, value_t cdr)
swissChili8cfb7c42021-04-18 21:17:58 -070031{
swissChili9e57da42021-06-15 22:22:46 -070032 struct cons_alloc *item = malloc_aligned(sizeof(struct cons_alloc));
33 struct cons *c = &item->cons;
swissChili7a6f5eb2021-04-13 16:46:02 -070034
swissChilibed80922021-04-13 21:58:05 -070035 c->car = car;
36 c->cdr = cdr;
37
swissChilie9fec8b2021-06-22 13:59:33 -070038 item->alloc.type_tag = CONS_TAG;
swissChilib8fd4712021-06-23 15:32:04 -070039 item->alloc.pool = current_pool;
swissChili7a6f5eb2021-04-13 16:46:02 -070040
swissChili53472e82021-05-08 16:06:32 -070041 if (last_a)
swissChili7a6f5eb2021-04-13 16:46:02 -070042 {
swissChili9e57da42021-06-15 22:22:46 -070043 item->alloc.prev = last_a;
swissChili7a6f5eb2021-04-13 16:46:02 -070044 last_a->next = item;
swissChili9e57da42021-06-15 22:22:46 -070045 item->alloc.next = NULL;
swissChilie9fec8b2021-06-22 13:59:33 -070046 last_a = item;
swissChili7a6f5eb2021-04-13 16:46:02 -070047 }
48 else
49 {
swissChili9e57da42021-06-15 22:22:46 -070050 item->alloc.prev = item->alloc.next = NULL;
swissChili7a6f5eb2021-04-13 16:46:02 -070051 first_a = last_a = item;
52 }
53
swissChilib3ca4fb2021-04-20 10:33:00 -070054 value_t v = (value_t)c;
swissChili8cfb7c42021-04-18 21:17:58 -070055 v |= CONS_TAG;
swissChili7a6f5eb2021-04-13 16:46:02 -070056
57 return v;
58}
59
swissChili53472e82021-05-08 16:06:32 -070060void skipws(struct istream *is)
swissChili7a6f5eb2021-04-13 16:46:02 -070061{
swissChilib8fd4712021-06-23 15:32:04 -070062start:
swissChili53472e82021-05-08 16:06:32 -070063 while (isspace(is->peek(is)))
64 is->get(is);
swissChilib8fd4712021-06-23 15:32:04 -070065
66 if (is->peek(is) == ';')
67 {
68 while (is->get(is) != '\n')
69 {}
70
71 // Only time I ever use labels is for stuff like this. Compiler would
72 // probably optimize this if I used recursion but I don't want to
73 // bother.
74 goto start;
75 }
swissChili7a6f5eb2021-04-13 16:46:02 -070076}
77
swissChili53472e82021-05-08 16:06:32 -070078bool isallowedchar(char c)
swissChili7a6f5eb2021-04-13 16:46:02 -070079{
swissChilibed80922021-04-13 21:58:05 -070080 return (c >= '#' && c <= '\'') || (c >= '*' && c <= '/') ||
81 (c >= '>' && c <= '@');
swissChili7a6f5eb2021-04-13 16:46:02 -070082}
83
swissChili53472e82021-05-08 16:06:32 -070084bool issymstart(char c)
swissChili7a6f5eb2021-04-13 16:46:02 -070085{
swissChili53472e82021-05-08 16:06:32 -070086 return isalpha(c) || isallowedchar(c);
swissChili7a6f5eb2021-04-13 16:46:02 -070087}
88
swissChili53472e82021-05-08 16:06:32 -070089bool issym(char c)
swissChili7a6f5eb2021-04-13 16:46:02 -070090{
swissChili53472e82021-05-08 16:06:32 -070091 return isalpha(c) || isallowedchar(c) || isdigit(c);
swissChili7a6f5eb2021-04-13 16:46:02 -070092}
93
swissChili53472e82021-05-08 16:06:32 -070094bool readsym(struct istream *is, value_t *val)
swissChili7a6f5eb2021-04-13 16:46:02 -070095{
swissChili53472e82021-05-08 16:06:32 -070096 skipws(is);
swissChili7a6f5eb2021-04-13 16:46:02 -070097
swissChili53472e82021-05-08 16:06:32 -070098 if (!issymstart(is->peek(is)))
swissChili7a6f5eb2021-04-13 16:46:02 -070099 return false;
100
101 int size = 8;
swissChili53472e82021-05-08 16:06:32 -0700102 char *s = malloc_aligned(size);
swissChili7a6f5eb2021-04-13 16:46:02 -0700103
swissChili53472e82021-05-08 16:06:32 -0700104 s[0] = is->get(is);
swissChili7a6f5eb2021-04-13 16:46:02 -0700105
swissChili53472e82021-05-08 16:06:32 -0700106 for (int i = 1;; i++)
swissChili7a6f5eb2021-04-13 16:46:02 -0700107 {
swissChili53472e82021-05-08 16:06:32 -0700108 if (issym(is->peek(is)))
swissChili7a6f5eb2021-04-13 16:46:02 -0700109 {
swissChili53472e82021-05-08 16:06:32 -0700110 if (i >= size)
swissChili7a6f5eb2021-04-13 16:46:02 -0700111 {
112 size *= 2;
swissChili53472e82021-05-08 16:06:32 -0700113 s = realloc_aligned(s, size);
swissChili7a6f5eb2021-04-13 16:46:02 -0700114 }
115
swissChili53472e82021-05-08 16:06:32 -0700116 s[i] = is->get(is);
swissChili7a6f5eb2021-04-13 16:46:02 -0700117 }
118 else
119 {
swissChili53472e82021-05-08 16:06:32 -0700120 s[i] = 0;
swissChilib3ca4fb2021-04-20 10:33:00 -0700121 *val = (value_t)s;
swissChili8cfb7c42021-04-18 21:17:58 -0700122 *val |= SYMBOL_TAG;
swissChili7a6f5eb2021-04-13 16:46:02 -0700123
124 return true;
125 }
126 }
127}
128
swissChili53472e82021-05-08 16:06:32 -0700129bool readstr(struct istream *is, value_t *val)
swissChili7a6f5eb2021-04-13 16:46:02 -0700130{
swissChili53472e82021-05-08 16:06:32 -0700131 skipws(is);
swissChili7a6f5eb2021-04-13 16:46:02 -0700132
swissChili53472e82021-05-08 16:06:32 -0700133 if (is->peek(is) != '"')
swissChili7a6f5eb2021-04-13 16:46:02 -0700134 return false;
135
136 bool escape = false;
137 int size = 8;
swissChili53472e82021-05-08 16:06:32 -0700138 char *s = malloc_aligned(size);
swissChili7a6f5eb2021-04-13 16:46:02 -0700139
swissChili53472e82021-05-08 16:06:32 -0700140 (void)is->get(is);
swissChili7a6f5eb2021-04-13 16:46:02 -0700141
swissChili53472e82021-05-08 16:06:32 -0700142 for (int i = 0;; i++)
swissChili7a6f5eb2021-04-13 16:46:02 -0700143 {
swissChili53472e82021-05-08 16:06:32 -0700144 if (is->peek(is) != '"')
swissChili7a6f5eb2021-04-13 16:46:02 -0700145 {
swissChili53472e82021-05-08 16:06:32 -0700146 if (i >= size)
swissChili7a6f5eb2021-04-13 16:46:02 -0700147 {
swissChilibed80922021-04-13 21:58:05 -0700148 size *= 2;
swissChili53472e82021-05-08 16:06:32 -0700149 s = realloc_aligned(s, size);
swissChili7a6f5eb2021-04-13 16:46:02 -0700150 }
swissChilibed80922021-04-13 21:58:05 -0700151
swissChili53472e82021-05-08 16:06:32 -0700152 char c = is->get(is);
swissChili7a6f5eb2021-04-13 16:46:02 -0700153
swissChili53472e82021-05-08 16:06:32 -0700154 if (escape && c == 'n')
swissChili7a6f5eb2021-04-13 16:46:02 -0700155 c = '\n';
swissChili53472e82021-05-08 16:06:32 -0700156 else if (escape && c == '\\')
swissChili7a6f5eb2021-04-13 16:46:02 -0700157 c = '\\';
158
swissChili53472e82021-05-08 16:06:32 -0700159 if (c == '\\' && !escape)
swissChili7a6f5eb2021-04-13 16:46:02 -0700160 {
161 escape = true;
162 i--; // will be incremented again, UGLY.
163 }
164 else
165 {
166 escape = false;
swissChili53472e82021-05-08 16:06:32 -0700167 s[i] = c;
swissChili7a6f5eb2021-04-13 16:46:02 -0700168 }
169 }
170 else
171 {
swissChili53472e82021-05-08 16:06:32 -0700172 is->get(is);
swissChili7a6f5eb2021-04-13 16:46:02 -0700173
swissChilib3ca4fb2021-04-20 10:33:00 -0700174 *val = (value_t)s;
swissChili8cfb7c42021-04-18 21:17:58 -0700175 *val |= STRING_TAG;
swissChili7a6f5eb2021-04-13 16:46:02 -0700176
177 return true;
178 }
179 }
180}
181
swissChili53472e82021-05-08 16:06:32 -0700182void printval(value_t v, int depth)
swissChili7a6f5eb2021-04-13 16:46:02 -0700183{
swissChili53472e82021-05-08 16:06:32 -0700184 for (int i = 0; i < depth; i++)
185 printf(" ");
swissChili7a6f5eb2021-04-13 16:46:02 -0700186
swissChili53472e82021-05-08 16:06:32 -0700187 if (symbolp(v))
swissChili7a6f5eb2021-04-13 16:46:02 -0700188 {
swissChili53472e82021-05-08 16:06:32 -0700189 printf("'%s\n", (char *)(v ^ SYMBOL_TAG));
swissChili8cfb7c42021-04-18 21:17:58 -0700190 }
swissChili53472e82021-05-08 16:06:32 -0700191 else if (stringp(v))
swissChili8cfb7c42021-04-18 21:17:58 -0700192 {
swissChili53472e82021-05-08 16:06:32 -0700193 printf("\"%s\"\n", (char *)(v ^ STRING_TAG));
swissChili8cfb7c42021-04-18 21:17:58 -0700194 }
swissChili53472e82021-05-08 16:06:32 -0700195 else if (integerp(v))
swissChili6eee4f92021-04-20 09:34:30 -0700196 {
swissChili53472e82021-05-08 16:06:32 -0700197 printf("%d\n", v >> 2);
swissChili6eee4f92021-04-20 09:34:30 -0700198 }
swissChili53472e82021-05-08 16:06:32 -0700199 else if (consp(v))
swissChili8cfb7c42021-04-18 21:17:58 -0700200 {
swissChili53472e82021-05-08 16:06:32 -0700201 if (listp(v))
swissChilibed80922021-04-13 21:58:05 -0700202 {
swissChili53472e82021-05-08 16:06:32 -0700203 printf("list:\n");
swissChilibed80922021-04-13 21:58:05 -0700204
swissChili53472e82021-05-08 16:06:32 -0700205 for (value_t n = v; !nilp(n); n = cdr(n))
swissChilibed80922021-04-13 21:58:05 -0700206 {
swissChili53472e82021-05-08 16:06:32 -0700207 printval(car(n), depth + 1);
swissChilibed80922021-04-13 21:58:05 -0700208 }
209 }
210 else
211 {
swissChili53472e82021-05-08 16:06:32 -0700212 printf("cons:\n");
213 printval(car(v), depth + 1);
214 printval(cdr(v), depth + 1);
swissChilibed80922021-04-13 21:58:05 -0700215 }
swissChili8cfb7c42021-04-18 21:17:58 -0700216 }
swissChili53472e82021-05-08 16:06:32 -0700217 else if (nilp(v))
swissChili8cfb7c42021-04-18 21:17:58 -0700218 {
swissChili53472e82021-05-08 16:06:32 -0700219 printf("nil\n");
swissChili8cfb7c42021-04-18 21:17:58 -0700220 }
221 else
222 {
swissChili53472e82021-05-08 16:06:32 -0700223 printf("<unknown %d>\n", v);
swissChili7a6f5eb2021-04-13 16:46:02 -0700224 }
225}
226
swissChili53472e82021-05-08 16:06:32 -0700227bool readlist(struct istream *is, value_t *val)
swissChilibed80922021-04-13 21:58:05 -0700228{
swissChili53472e82021-05-08 16:06:32 -0700229 skipws(is);
swissChilibed80922021-04-13 21:58:05 -0700230
swissChili53472e82021-05-08 16:06:32 -0700231 if (is->peek(is) != '(')
swissChilibed80922021-04-13 21:58:05 -0700232 return false;
233
swissChili53472e82021-05-08 16:06:32 -0700234 is->get(is);
swissChilibed80922021-04-13 21:58:05 -0700235
swissChili53472e82021-05-08 16:06:32 -0700236 *val = readn(is);
swissChilibed80922021-04-13 21:58:05 -0700237
swissChili53472e82021-05-08 16:06:32 -0700238 if (is->peek(is) != ')')
swissChilibed80922021-04-13 21:58:05 -0700239 {
swissChili53472e82021-05-08 16:06:32 -0700240 is->showpos(is, stderr);
241 err("Unterminated list");
swissChilibed80922021-04-13 21:58:05 -0700242 return false;
243 }
swissChili53472e82021-05-08 16:06:32 -0700244 is->get(is);
swissChilibed80922021-04-13 21:58:05 -0700245
246 return true;
247}
248
swissChili53472e82021-05-08 16:06:32 -0700249bool readint(struct istream *is, value_t *val)
swissChili6eee4f92021-04-20 09:34:30 -0700250{
251 int number = 0;
252
swissChili53472e82021-05-08 16:06:32 -0700253 if (!isdigit(is->peek(is)))
swissChili6eee4f92021-04-20 09:34:30 -0700254 return false;
255
swissChili53472e82021-05-08 16:06:32 -0700256 while (isdigit(is->peek(is)))
swissChili6eee4f92021-04-20 09:34:30 -0700257 {
258 number *= 10;
swissChili53472e82021-05-08 16:06:32 -0700259 number += is->get(is) - '0';
swissChili6eee4f92021-04-20 09:34:30 -0700260 }
261
swissChili53472e82021-05-08 16:06:32 -0700262 *val = intval(number);
swissChili6eee4f92021-04-20 09:34:30 -0700263 return true;
264}
265
swissChili53472e82021-05-08 16:06:32 -0700266bool read1(struct istream *is, value_t *val)
swissChili7a6f5eb2021-04-13 16:46:02 -0700267{
swissChili53472e82021-05-08 16:06:32 -0700268 if (readsym(is, val))
swissChili7a6f5eb2021-04-13 16:46:02 -0700269 return true;
270
swissChili53472e82021-05-08 16:06:32 -0700271 if (readstr(is, val))
swissChili7a6f5eb2021-04-13 16:46:02 -0700272 return true;
273
swissChili53472e82021-05-08 16:06:32 -0700274 if (readint(is, val))
swissChili6eee4f92021-04-20 09:34:30 -0700275 return true;
276
swissChili53472e82021-05-08 16:06:32 -0700277 if (readlist(is, val))
swissChilibed80922021-04-13 21:58:05 -0700278 return true;
279
swissChili7a6f5eb2021-04-13 16:46:02 -0700280 return false;
281}
282
swissChili53472e82021-05-08 16:06:32 -0700283value_t readn(struct istream *is)
swissChilibed80922021-04-13 21:58:05 -0700284{
swissChili8cfb7c42021-04-18 21:17:58 -0700285 value_t first = nil;
286 value_t *last = &first;
swissChilibed80922021-04-13 21:58:05 -0700287
swissChili8cfb7c42021-04-18 21:17:58 -0700288 value_t read_val;
swissChilibed80922021-04-13 21:58:05 -0700289
swissChili53472e82021-05-08 16:06:32 -0700290 while (read1(is, &read_val))
swissChilibed80922021-04-13 21:58:05 -0700291 {
swissChili53472e82021-05-08 16:06:32 -0700292 *last = cons(read_val, nil);
293 last = cdrref(*last);
swissChilibed80922021-04-13 21:58:05 -0700294 }
295
296 return first;
297}
298
swissChili53472e82021-05-08 16:06:32 -0700299bool startswith(struct istream *s, char *pattern)
swissChili7a6f5eb2021-04-13 16:46:02 -0700300{
swissChili53472e82021-05-08 16:06:32 -0700301 char *check = strdup(pattern);
302 s->read(s, check, strlen(pattern));
swissChili7a6f5eb2021-04-13 16:46:02 -0700303
swissChili53472e82021-05-08 16:06:32 -0700304 bool res = strcmp(check, pattern) == 0;
305 free(check);
swissChili7a6f5eb2021-04-13 16:46:02 -0700306
307 return res;
308}
swissChilibed80922021-04-13 21:58:05 -0700309
swissChili53472e82021-05-08 16:06:32 -0700310value_t strval(char *str)
swissChilibed80922021-04-13 21:58:05 -0700311{
swissChili8cfb7c42021-04-18 21:17:58 -0700312 value_t v;
313
swissChili53472e82021-05-08 16:06:32 -0700314 char *a = malloc_aligned(strlen(str) + 1);
swissChilib3ca4fb2021-04-20 10:33:00 -0700315 v = (value_t)a;
swissChili8cfb7c42021-04-18 21:17:58 -0700316 v |= STRING_TAG;
swissChilibed80922021-04-13 21:58:05 -0700317
318 return v;
319}
320
swissChili53472e82021-05-08 16:06:32 -0700321bool integerp(value_t v)
swissChilibed80922021-04-13 21:58:05 -0700322{
swissChili8cfb7c42021-04-18 21:17:58 -0700323 return (v & INT_MASK) == INT_TAG;
324}
swissChilibed80922021-04-13 21:58:05 -0700325
swissChili53472e82021-05-08 16:06:32 -0700326bool symbolp(value_t v)
swissChili8cfb7c42021-04-18 21:17:58 -0700327{
328 return (v & HEAP_MASK) == SYMBOL_TAG;
329}
330
swissChili53472e82021-05-08 16:06:32 -0700331bool stringp(value_t v)
swissChili8cfb7c42021-04-18 21:17:58 -0700332{
333 return (v & HEAP_MASK) == STRING_TAG;
334}
335
swissChili53472e82021-05-08 16:06:32 -0700336bool consp(value_t v)
swissChili8cfb7c42021-04-18 21:17:58 -0700337{
338 return (v & HEAP_MASK) == CONS_TAG;
339}
340
swissChili9e57da42021-06-15 22:22:46 -0700341bool heapp(value_t v)
342{
343 return consp(v) || stringp(v) || symbolp(v);
344}
345
swissChili53472e82021-05-08 16:06:32 -0700346bool listp(value_t v)
swissChili8cfb7c42021-04-18 21:17:58 -0700347{
348 value_t next = v;
349
swissChili53472e82021-05-08 16:06:32 -0700350 while (consp(next))
swissChilibed80922021-04-13 21:58:05 -0700351 {
swissChili53472e82021-05-08 16:06:32 -0700352 next = cdr(next);
swissChilibed80922021-04-13 21:58:05 -0700353 }
354
swissChili53472e82021-05-08 16:06:32 -0700355 return nilp(next);
swissChilibed80922021-04-13 21:58:05 -0700356}
357
swissChili53472e82021-05-08 16:06:32 -0700358value_t car(value_t v)
swissChilibed80922021-04-13 21:58:05 -0700359{
swissChili53472e82021-05-08 16:06:32 -0700360 if (!consp(v))
swissChilibed80922021-04-13 21:58:05 -0700361 return nil;
362
swissChili53472e82021-05-08 16:06:32 -0700363 return *carref(v);
swissChilibed80922021-04-13 21:58:05 -0700364}
365
swissChili53472e82021-05-08 16:06:32 -0700366value_t cdr(value_t v)
swissChilibed80922021-04-13 21:58:05 -0700367{
swissChili53472e82021-05-08 16:06:32 -0700368 if (!consp(v))
swissChilibed80922021-04-13 21:58:05 -0700369 return nil;
370
swissChili53472e82021-05-08 16:06:32 -0700371 return *cdrref(v);
swissChilibed80922021-04-13 21:58:05 -0700372}
373
swissChili53472e82021-05-08 16:06:32 -0700374value_t *carref(value_t v)
swissChilibed80922021-04-13 21:58:05 -0700375{
swissChili53472e82021-05-08 16:06:32 -0700376 if (!consp(v))
swissChili8cfb7c42021-04-18 21:17:58 -0700377 return NULL;
378
swissChilib3ca4fb2021-04-20 10:33:00 -0700379 struct cons *c = (void *)(v ^ CONS_TAG);
swissChili8cfb7c42021-04-18 21:17:58 -0700380 return &c->car;
swissChilibed80922021-04-13 21:58:05 -0700381}
swissChilica107a02021-04-14 12:07:30 -0700382
swissChili53472e82021-05-08 16:06:32 -0700383value_t *cdrref(value_t v)
swissChili8cfb7c42021-04-18 21:17:58 -0700384{
swissChili53472e82021-05-08 16:06:32 -0700385 if (!consp(v))
swissChili8cfb7c42021-04-18 21:17:58 -0700386 return NULL;
387
swissChilib3ca4fb2021-04-20 10:33:00 -0700388 struct cons *c = (void *)(v ^ CONS_TAG);
swissChili8cfb7c42021-04-18 21:17:58 -0700389 return &c->cdr;
390}
391
swissChili53472e82021-05-08 16:06:32 -0700392bool nilp(value_t v)
swissChili8cfb7c42021-04-18 21:17:58 -0700393{
394 return v == nil;
395}
396
swissChili53472e82021-05-08 16:06:32 -0700397int length(value_t v)
swissChilica107a02021-04-14 12:07:30 -0700398{
399 int i = 0;
400
swissChili53472e82021-05-08 16:06:32 -0700401 for (; !nilp(v); v = cdr(v))
swissChilica107a02021-04-14 12:07:30 -0700402 i++;
403
404 return i;
405}
swissChilib3ca4fb2021-04-20 10:33:00 -0700406
swissChili53472e82021-05-08 16:06:32 -0700407value_t elt(value_t v, int index)
swissChilib3ca4fb2021-04-20 10:33:00 -0700408{
swissChili53472e82021-05-08 16:06:32 -0700409 for (int i = 0; i < index; i++)
swissChilib3ca4fb2021-04-20 10:33:00 -0700410 {
swissChili53472e82021-05-08 16:06:32 -0700411 v = cdr(v);
swissChilib3ca4fb2021-04-20 10:33:00 -0700412 }
413
swissChili53472e82021-05-08 16:06:32 -0700414 return car(v);
swissChilib3ca4fb2021-04-20 10:33:00 -0700415}
swissChili8fc5e2f2021-04-22 13:45:10 -0700416
swissChili53472e82021-05-08 16:06:32 -0700417bool symstreq(value_t sym, char *str)
swissChili8fc5e2f2021-04-22 13:45:10 -0700418{
swissChili53472e82021-05-08 16:06:32 -0700419 if ((sym & HEAP_MASK) != SYMBOL_TAG)
swissChili8fc5e2f2021-04-22 13:45:10 -0700420 return false;
421
swissChili53472e82021-05-08 16:06:32 -0700422 return strcmp((char *)(sym ^ SYMBOL_TAG), str) == 0;
swissChili8fc5e2f2021-04-22 13:45:10 -0700423}
swissChilib8fd4712021-06-23 15:32:04 -0700424
425unsigned char make_pool()
426{
427 return ++max_pool;
428}
429
430unsigned char push_pool(unsigned char pool)
431{
432 unsigned char old = current_pool;
433 current_pool = pool;
434 return old;
435}
436
437void pop_pool(unsigned char pool)
438{
439 current_pool = pool;
440}
441
442bool pool_alive(unsigned char pool)
443{
444 return pool != 0;
445}