-
Notifications
You must be signed in to change notification settings - Fork 0
/
stlc.h
44 lines (29 loc) · 904 Bytes
/
stlc.h
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
#ifndef STLC_H
#define STLC_H
#include <stdbool.h>
typedef long term_t;
typedef long type_t;
#define NIL 0
#define ROOT 1
/* Terms */
#define ISABS(T) (term[(T)] == (T))
#define ISAPP(T) (term[(T)] > (T))
#define ISVAR(T) (term[(T)] < 0)
#define LEFT(T) (term[(T)])
#define RIGHT(T) ((T) + 1)
#define BODY(T) ((T) + 1)
#define BINDER(T) (-term[(T)])
/* Types */
#define ISATOM(X) ((X) < 0)
#define TYPEOF(T) (ISAPP(T) ? ATOM(T) : term[(T)]) /* T or ATOM(BINDER(T)) */
#define ATOM(T) (-(T))
#define SUB(T) (TYPEOF((T) + 1)) /* RIGHT(T) or BODY(T) */
#define VALUE(A) (type[-(A)])
#define DOM(T) (ISABS(T) ? ATOM(T) : SUB(T))
#define COD(T) (ISABS(T) ? SUB(T) : ATOM(T))
/* Functions */
type_t *infer(const term_t *);
bool valid(long, const term_t *);
void showterm(const term_t *, const type_t *, term_t);
void showtype(const term_t *, const type_t *, type_t);
#endif