diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2021-01-13 01:48:36 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2021-01-13 01:48:36 -0800 |
| commit | 45d7aff47545f52136487fbb5b06cdcf716cbe9f (patch) | |
| tree | 38140eaa9d47cea8276e06cec93f0cb2988eae8d /grammar.c | |
| parent | 7e4b287d9bd904aaf9cc2bf77cdd456194130e99 (diff) | |
Major overhaul of some of the memory tracking code, as well as some
cleanup of the compilation code.
Diffstat (limited to 'grammar.c')
| -rw-r--r-- | grammar.c | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -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 |
