diff options
author | Marvin Borner | 2023-05-29 14:11:42 +0200 |
---|---|---|
committer | Marvin Borner | 2023-05-29 14:11:42 +0200 |
commit | f1dc637384f91bffe2342b8717c68b2f2cd2203e (patch) | |
tree | 6618e968ee54bb1512c1659f53b5743eb374d798 | |
parent | abf68e0ad6c9f6d6cd14693894c609faca925e22 (diff) |
Switched to wider indices
I mean these programs would certainly be quite weird but it doesn't
change the struct size anyway so better be prepared amirite
-rw-r--r-- | inc/term.h | 3 | ||||
-rw-r--r-- | src/term.c | 24 |
2 files changed, 26 insertions, 1 deletions
@@ -22,12 +22,13 @@ struct term { struct term *rhs; } app; struct { - int index; + size_t index; } var; } u; }; struct term *term_new(term_type_t type, hash_t hash, size_t depth); void term_refer(struct term *term, size_t depth); +void term_print(struct term *term); #endif @@ -2,6 +2,7 @@ // SPDX-License-Identifier: MIT #include <stdlib.h> +#include <stdio.h> #include <log.h> #include <term.h> @@ -25,6 +26,29 @@ void term_refer(struct term *term, size_t depth) term->depth = depth; } +void term_print(struct term *term) +{ + switch (term->type) { + case ABS: + fprintf(stderr, "["); + term_print(term->u.abs.term); + fprintf(stderr, "]"); + break; + case APP: + fprintf(stderr, "("); + term_print(term->u.app.lhs); + fprintf(stderr, " "); + term_print(term->u.app.rhs); + fprintf(stderr, ")"); + break; + case VAR: + fprintf(stderr, "%ld", term->u.var.index); + break; + default: + fatal("invalid type %d\n", term->type); + } +} + /* void deref_term(struct term *term) */ /* { */ /* if (term->type == ABS) { */ |