// Copyright (c) 2023, Marvin Borner // SPDX-License-Identifier: MIT #include #include #include struct term *term_new(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; } void term_refer(struct term *term, size_t depth) { term->refs++; if (depth < term->depth) // lower depths are more important term->depth = depth; } /* void deref_term(struct term *term) */ /* { */ /* if (term->type == ABS) { */ /* deref_term(term->u.abs.term); */ /* } else if (term->type == APP) { */ /* deref_term(term->u.app.lhs); */ /* deref_term(term->u.app.rhs); */ /* } */ /* // TODO: remove from hashmap? */ /* if (--term->refs == 0) */ /* free(term); */ /* } */