Fix build, but not compiler(s) yet.
Chris Pressey
10 years ago
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
164 | /* TODO: rewrite to not use term_add_subterm */ | |
165 | void tamsin_mkterm_r(struct term *t, const struct term *list) { | |
164 | void tamsin_mkterm_r(struct termlist **tl, const struct term *list) { | |
166 | 165 | if (term_atom_cstring_equal(list, "list") && list->subterms != NULL) { |
167 | tamsin_mkterm_r(t, list->subterms->next->term); | |
168 | term_add_subterm(t, list->subterms->term); | |
166 | tamsin_mkterm_r(tl, list->subterms->next->term); | |
167 | termlist_add_term(tl, list->subterms->term); | |
169 | 168 | } |
170 | 169 | } |
171 | 170 | |
172 | 171 | const struct term *tamsin_mkterm(const struct term *atom, |
173 | 172 | const struct term *list) { |
174 | struct term *t = term_new_atom(atom->atom, atom->size); | |
175 | tamsin_mkterm_r(t, list); | |
176 | return t; | |
173 | struct termlist *tl = NULL; | |
174 | ||
175 | tamsin_mkterm_r(&tl, list); | |
176 | ||
177 | return term_new_constructor(atom->atom, atom->size, tl); | |
177 | 178 | } |
178 | 179 | |
179 | 180 | const struct term *tamsin_reverse(const struct term *list, const struct term *sentinel) { |
181 | 182 | const struct term *head = list; /* save */ |
182 | 183 | |
183 | 184 | while (list->subterms != NULL && term_atoms_equal(list, head)) { |
184 | const struct term *new = term_new_atom(head->atom, head->size); | |
185 | ||
185 | const struct term *new; | |
186 | struct termlist *tl = NULL; | |
187 | ||
186 | 188 | /*term_fput(list, stderr); |
187 | 189 | fprintf(stderr, "\n");*/ |
188 | 190 | |
189 | term_add_subterm(new, res); | |
190 | term_add_subterm(new, list->subterms->term); | |
191 | termlist_add_term(&tl, res); | |
192 | termlist_add_term(&tl, list->subterms->term); | |
193 | new = term_new_constructor(head->atom, head->size, tl); | |
191 | 194 | res = new; |
195 | ||
192 | 196 | if (list->subterms->next == NULL) { |
193 | 197 | break; |
194 | 198 | } |
24 | 24 | const char *atom; |
25 | 25 | size_t size; |
26 | 26 | int index; |
27 | struct term_list *subterms; | |
27 | struct termlist *subterms; | |
28 | 28 | }; |
29 | 29 | |
30 | struct term_list { | |
30 | struct termlist { | |
31 | 31 | const struct term *term; |
32 | struct term_list *next; | |
32 | struct termlist *next; | |
33 | 33 | }; |
34 | 34 | |
35 | 35 | /* |
44 | 44 | const struct term *term_new_atom_from_char(char c); |
45 | 45 | |
46 | 46 | const struct term *term_new_constructor(const char *, size_t, |
47 | struct term_list *); | |
47 | struct termlist *); | |
48 | void termlist_add_term(struct termlist **, const struct term *); | |
48 | 49 | |
49 | 50 | const struct term *term_new_variable(const char *, size_t, int); |
50 | 51 |
45 | 45 | return t; |
46 | 46 | } |
47 | 47 | |
48 | void termlist_add_term(struct term_list **tl, const struct term *term) { | |
49 | struct term_list *new_tl; | |
50 | ||
51 | new_tl = malloc(sizeof(struct term_list)); | |
52 | new_tl->term = term; | |
53 | new_tl->next = *tl; | |
54 | *tl = new_tl; | |
55 | } | |
56 | ||
57 | 48 | const struct term *term_new_atom_from_char(char c) { |
58 | 49 | char s[2]; |
59 | 50 | |
68 | 59 | } |
69 | 60 | |
70 | 61 | const struct term *term_new_constructor(const char *tag, size_t size, |
71 | struct term_list *subterms) | |
62 | struct termlist *subterms) | |
72 | 63 | { |
73 | 64 | struct term *t = malloc(sizeof(struct term)); |
74 | 65 | char *text = malloc(size); |
80 | 71 | t->subterms = subterms; |
81 | 72 | |
82 | 73 | return t; |
74 | } | |
75 | ||
76 | void termlist_add_term(struct termlist **tl, const struct term *term) { | |
77 | struct termlist *new_tl; | |
78 | ||
79 | new_tl = malloc(sizeof(struct termlist)); | |
80 | new_tl->term = term; | |
81 | new_tl->next = *tl; | |
82 | *tl = new_tl; | |
83 | 83 | } |
84 | 84 | |
85 | 85 | const struct term *term_new_variable(const char *name, size_t size, int index) { |
134 | 134 | const struct term COMMA = { ", ", 2, -1, NULL }; |
135 | 135 | |
136 | 136 | const struct term *term_flatten(const struct term *t) { |
137 | struct term_list *tl; | |
137 | struct termlist *tl; | |
138 | 138 | |
139 | 139 | if (t->subterms == NULL) { /* it's an atom */ |
140 | 140 | return t; |
246 | 246 | } |
247 | 247 | |
248 | 248 | const struct term *term_repr(const struct term *t) { |
249 | struct term_list *tl; | |
249 | struct termlist *tl; | |
250 | 250 | |
251 | 251 | if (t->subterms == NULL) { /* it's an atom */ |
252 | 252 | return term_escape_atom(t); |
267 | 267 | |
268 | 268 | int term_equal(const struct term *pattern, const struct term *ground) |
269 | 269 | { |
270 | struct term_list *tl1, *tl2; | |
270 | struct termlist *tl1, *tl2; | |
271 | 271 | |
272 | 272 | assert(pattern->index == -1); |
273 | 273 | assert(ground->index == -1); |
297 | 297 | int term_match_unifier(const struct term *pattern, const struct term *ground, |
298 | 298 | const struct term **variables) |
299 | 299 | { |
300 | struct term_list *tl1, *tl2; | |
300 | struct termlist *tl1, *tl2; | |
301 | 301 | |
302 | 302 | if (pattern->index >= 0) { |
303 | 303 | variables[pattern->index] = ground; |