aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2023-05-29 14:11:42 +0200
committerMarvin Borner2023-05-29 14:11:42 +0200
commitf1dc637384f91bffe2342b8717c68b2f2cd2203e (patch)
tree6618e968ee54bb1512c1659f53b5743eb374d798
parentabf68e0ad6c9f6d6cd14693894c609faca925e22 (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.h3
-rw-r--r--src/term.c24
2 files changed, 26 insertions, 1 deletions
diff --git a/inc/term.h b/inc/term.h
index b64b106..eb74c2c 100644
--- a/inc/term.h
+++ b/inc/term.h
@@ -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
diff --git a/src/term.c b/src/term.c
index b2202cc..903ee8a 100644
--- a/src/term.c
+++ b/src/term.c
@@ -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) { */