implement basic RAII-ish array management

This commit is contained in:
r4
2021-12-29 21:42:43 +01:00
parent 7773cc6c14
commit 4d5cd93354
8 changed files with 137 additions and 47 deletions

5
lex.c
View File

@@ -58,7 +58,7 @@ static char get_esc_char(char c) {
}
}
TokList lex(const char *s, Pool *static_vars) {
TokList lex(const char *s) {
TokList toks;
toklist_init(&toks);
Pos pos = { .ln = 1, .col = 1 };
@@ -329,7 +329,7 @@ TokList lex(const char *s, Pool *static_vars) {
/* go through the actual string */
s = start;
pos = start_pos;
char *str = pool_alloc(static_vars, type_size[TypeChar] * size);
char *str = xmalloc(size);
for (size_t i = 0; i < size; i++) {
char c = s[0];
if (c == '\\') {
@@ -347,6 +347,7 @@ TokList lex(const char *s, Pool *static_vars) {
.type = TypeArr,
.Arr = {
.is_string = true,
.dynamically_allocated = false,
.type = TypeChar,
.vals = str,
.len = size,