diff options
author | Marvin Borner | 2023-05-27 10:07:24 +0200 |
---|---|---|
committer | Marvin Borner | 2023-05-27 10:07:24 +0200 |
commit | abf68e0ad6c9f6d6cd14693894c609faca925e22 (patch) | |
tree | 0ac1a7f74f1543d8343ed346c577dbf1cda93bfe /src/parse.c | |
parent | 337ec809393b709b36ca7b64d77489ae4bc1af1c (diff) |
Moved term logic
Diffstat (limited to 'src/parse.c')
-rw-r--r-- | src/parse.c | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/src/parse.c b/src/parse.c index 5445aea..b10a698 100644 --- a/src/parse.c +++ b/src/parse.c @@ -10,25 +10,6 @@ static size_t max_depth = 0; -static struct term *new_term(term_type_t type, hash_t hash, size_t depth) -{ - struct term *term = malloc(sizeof(*term)); - if (!term) - fatal("out of memory!\n"); - term->type = type; - term->refs = 1; - term->hash = hash; - term->depth = depth; - return term; -} - -static void update_term(struct term *term, size_t depth) -{ - term->refs++; - if (depth < term->depth) // lower depths are more important - term->depth = depth; -} - static struct term_handle abs_blc(char **term, size_t depth) { term_type_t res_type = ABS; @@ -37,9 +18,9 @@ static struct term_handle abs_blc(char **term, size_t depth) struct term *res_term; if ((res_term = map_get(res))) { - update_term(res_term, depth); + term_refer(res_term, depth); } else { - res_term = new_term(res_type, res, depth); + res_term = term_new(res_type, res, depth); res_term->u.abs.term = inner.term; map_set(res_term, res); } @@ -58,9 +39,9 @@ static struct term_handle app_blc(char **term, size_t depth) struct term *res_term; if ((res_term = map_get(res))) { - update_term(res_term, depth); + term_refer(res_term, depth); } else { - res_term = new_term(res_type, res, depth); + res_term = term_new(res_type, res, depth); res_term->u.app.lhs = lhs.term; res_term->u.app.rhs = rhs.term; map_set(res_term, res); @@ -76,9 +57,9 @@ static struct term_handle var_blc(int index, size_t depth) struct term *res_term; if ((res_term = map_get(res))) { - update_term(res_term, depth); + term_refer(res_term, depth); } else { - res_term = new_term(res_type, res, depth); + res_term = term_new(res_type, res, depth); res_term->u.var.index = index; map_set(res_term, res); } |