diff options
author | Marvin Borner | 2023-10-23 00:50:21 +0200 |
---|---|---|
committer | Marvin Borner | 2023-10-23 00:50:21 +0200 |
commit | 9bc17a207a9d5c65509a51f57412c8e28b843330 (patch) | |
tree | 644abe62677705cc8bf8fa51bad482d279a1ec83 | |
parent | 58963c058c0a55916fa89400cfe5572aac73b685 (diff) |
Testing bound state (won't work; backup)
won't give improvements, since inc/dec idcs need inspection anyway
-rw-r--r-- | inc/term.h | 11 | ||||
-rw-r--r-- | src/term.c | 39 |
2 files changed, 29 insertions, 21 deletions
@@ -24,6 +24,7 @@ struct term { union { struct { struct term *term; + char bound; } abs; struct { struct term *lhs; @@ -39,11 +40,13 @@ struct term *term_new(term_type_t type, hash_t hash, size_t depth); void term_destroy_head(struct term *term, char including_parents); char term_is_beta_redex(struct term *term); void term_rehash_parents(struct term *term); -struct term *term_rehash(struct term *term); -struct term *term_rehash_abs(struct term *head, struct term *term); +struct term *term_rehash(struct term *term, int including_parents); +struct term *term_rehash_abs(struct term *head, struct term *term, + int including_parents); struct term *term_rehash_app(struct term *head, struct term *lhs, - struct term *rhs); -struct term *term_rehash_var(struct term *head, size_t index); + struct term *rhs, int including_parents); +struct term *term_rehash_var(struct term *head, size_t index, + int including_parents); void term_refer_head(struct term *term, size_t depth); void term_refer(struct term *term, size_t depth); char term_deref_head(struct term *term, char destroy_parents); @@ -82,7 +82,8 @@ size_t term_print(struct term *term) } } -struct term *term_rehash_abs(struct term *head, struct term *term) +struct term *term_rehash_abs(struct term *head, struct term *term, + int including_parents) { debug("rehashing abs %lx (%lx)\n", head->hash & HASH_MASK, term->hash & HASH_MASK); @@ -95,8 +96,8 @@ struct term *term_rehash_abs(struct term *head, struct term *term) struct term *match = map_get(map_all_terms(), res); if (match) { // already exists // TODO: something different if match->u.abs.term == term)? - term_refer_head(match, head->depth); - term_deref_head(head, 1); + /* term_refer_head(match, head->depth); */ + /* term_deref_head(head, including_parents); */ return match; } else { // create new struct term *new = term_new(ABS, res, head->depth); @@ -104,14 +105,14 @@ struct term *term_rehash_abs(struct term *head, struct term *term) new->u.abs.term = term; map_set(map_all_terms(), new); map_set(term->parents, new); - term_deref_head(head, 1); + /* term_deref_head(head, including_parents); */ return new; } } -// ok main problem is reparenting substitution tickle-up +// TODO: main problem is reparenting substitution tickle-up struct term *term_rehash_app(struct term *head, struct term *lhs, - struct term *rhs) + struct term *rhs, int including_parents) { debug("rehashing app %lx (%lx, %lx)\n", head->hash & HASH_MASK, lhs->hash & HASH_MASK, rhs->hash & HASH_MASK); @@ -124,8 +125,8 @@ struct term *term_rehash_app(struct term *head, struct term *lhs, struct term *match = map_get(map_all_terms(), res); if (match) { // already exists - term_refer_head(match, head->depth); - term_deref(head, 1); + /* term_refer_head(match, head->depth); */ + /* term_deref(head, including_parents); */ return match; } else { // create new struct term *new = term_new(APP, res, head->depth); @@ -135,12 +136,13 @@ struct term *term_rehash_app(struct term *head, struct term *lhs, map_set(map_all_terms(), new); map_set(lhs->parents, new); map_set(rhs->parents, new); - term_deref_head(head, 1); + /* term_deref_head(head, including_parents); */ return new; } } -struct term *term_rehash_var(struct term *head, size_t index) +struct term *term_rehash_var(struct term *head, size_t index, + int including_parents) { debug("rehashing var %lx (%lu)\n", head->hash & HASH_MASK, index); hash_t res = hash((uint8_t *)&head->type, sizeof(head->type), index); @@ -151,28 +153,31 @@ struct term *term_rehash_var(struct term *head, size_t index) struct term *match = map_get(map_all_terms(), res); if (match) { // already exists term_refer_head(match, head->depth); - term_deref(head, 1); + /* term_deref(head, including_parents); */ return match; } else { // create new struct term *new = term_new(VAR, res, head->depth); // TODO: Clone parents new->u.var.index = index; map_set(map_all_terms(), new); - term_deref_head(head, 1); + /* term_deref_head(head, including_parents); */ return new; } } -struct term *term_rehash(struct term *term) +struct term *term_rehash(struct term *term, int including_parents) { if (term->type == ABS) - return term_rehash_abs(term, term->u.abs.term); + return term_rehash_abs(term, term->u.abs.term, + including_parents); if (term->type == APP) - return term_rehash_app(term, term->u.app.lhs, term->u.app.rhs); + return term_rehash_app(term, term->u.app.lhs, term->u.app.rhs, + including_parents); if (term->type == VAR) - return term_rehash_var(term, term->u.var.index); + return term_rehash_var(term, term->u.var.index, + including_parents); fatal("invalid type %d\n", term->type); } @@ -205,7 +210,7 @@ void term_rehash_parents(struct term *term) while (iterator && iterator->term) { struct term *parent = iterator->term; hash_t previous = parent->hash; - struct term *new = term_rehash(parent); + struct term *new = term_rehash(parent, 1); if (previous == new->hash) { struct parent_list *next = iterator->next; free(iterator); |