1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Copyright (c) 2023, Marvin Borner <dev@marvinborner.de>
// SPDX-License-Identifier: MIT
#ifndef CALM_TERM_H
#define CALM_TERM_H
#include <lib/pqueue.h>
#include <lib/hash.h>
#include <lib/hashmap.h>
typedef enum { INV, ABS, APP, VAR } term_type_t;
struct term {
term_type_t type;
hash_t hash;
struct hashmap *parents;
size_t refs;
size_t depth;
pqueue_pri_t priority;
size_t position;
union {
struct {
struct term *term;
} abs;
struct {
struct term *lhs;
struct term *rhs;
} app;
struct {
size_t index;
} var;
} u;
};
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, 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, 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);
char term_deref(struct term *term, char destroy_parents);
size_t term_print(struct term *term);
#endif
|