From 45d7aff47545f52136487fbb5b06cdcf716cbe9f Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 13 Jan 2021 01:48:36 -0800 Subject: Major overhaul of some of the memory tracking code, as well as some cleanup of the compilation code. --- grammar.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'grammar.c') diff --git a/grammar.c b/grammar.c index cdc8f51..08e7083 100644 --- a/grammar.c +++ b/grammar.c @@ -72,9 +72,7 @@ vm_op_t *lookup(def_t *defs, const char *name) // static def_t *with_backref(def_t *defs, file_t *f, const char *name, match_t *m) { - vm_op_t *op = new(vm_op_t); - op->type = VM_BACKREF; - op->start = m->start; + vm_op_t *op = new_op(f, m->start, VM_BACKREF); op->end = m->end; op->len = -1; // TODO: maybe calculate this? (nontrivial because of replacements) op->args.backref = m; @@ -95,4 +93,17 @@ def_t *with_backrefs(def_t *defs, file_t *f, match_t *m) return defs; } +// +// Free all the given definitions up till (but not including) `stop` +// +void free_defs(def_t **defs, def_t *stop) +{ + while (*defs != stop && *defs != NULL) { + def_t *next = (*defs)->next; + (*defs)->next = NULL; + free(*defs); + (*defs) = next; + } +} + // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1 -- cgit v1.2.3