summaryrefslogtreecommitdiff
path: root/src/runtime/c/gfcc-term.h
blob: d1307259d3c95f2f8e80ab787c399d68d8d6cd07 (plain)
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
57
58
59
60
61
62
63
64
65
#ifndef GFCC_TERM_H
#define GFCC_TERM_H

#include <stdio.h>

typedef enum {
	/* size = variable */
	TERM_ARRAY,
	TERM_SEQUENCE,
	TERM_VARIANTS,
	TERM_GLUE,
	/* size = 2 */
	TERM_RECORD_PARAM,
	TERM_SUFFIX_TABLE,
	/* size = 0 */
	TERM_META,
	TERM_STRING,
	TERM_INTEGER
} TermType;

struct Term_ {
	TermType type;
	union {
		const char *string_value;
		int integer_value;
		int size;
	} value;
	struct Term_ *args[0];
};

typedef struct Term_ Term;



static inline Term *term_get_child(Term *t, int n) {
	return t->args[n];
}

static inline void term_set_child(Term *t, int n, Term *c) {
	t->args[n] = c;
}

extern void term_alloc_pool(size_t size);
extern void term_free_pool();
extern void *term_alloc(size_t size);


extern Term *term_array(int n, ...);
extern Term *term_seq(int n, ...);
extern Term *term_variants(int n, ...);
extern Term *term_glue(int n, ...);

extern Term *term_rp(Term *t1, Term *t2);
extern Term *term_suffix(const char *pref, Term *suf);
extern Term *term_str(const char *s);
extern Term *term_int(int i);
extern Term *term_meta();

extern Term *term_sel_int(Term *t, int i);
extern Term *term_sel(Term *t1, Term *t2);


extern void term_print(FILE *stream, Term *t);

#endif