55 lines
1.1 KiB
C
55 lines
1.1 KiB
C
enum type_form {
|
|
type_var,
|
|
type_name,
|
|
tuple_type,
|
|
func_type,
|
|
};
|
|
|
|
struct type;
|
|
|
|
/* A Linked list of types */
|
|
struct type_list {
|
|
struct type *elem;
|
|
struct type_list *next;
|
|
};
|
|
|
|
struct func_type {
|
|
struct type *dom;
|
|
struct type *cod;
|
|
};
|
|
|
|
struct type_name {
|
|
struct type_list *params;
|
|
char *name;
|
|
};
|
|
|
|
struct type {
|
|
enum type_form form;
|
|
union {
|
|
char *var_name;
|
|
/* We represent a tuple with the linked list of its type components */
|
|
struct type_list *tuple;
|
|
struct func_type func;
|
|
struct type_name type_name;
|
|
};
|
|
};
|
|
|
|
/* type constructors and destructors */
|
|
struct type *make_tuple_type(struct type_list *t);
|
|
struct type *make_func_type(struct type *dom, struct type *cod);
|
|
struct type *make_var_type(char *name);
|
|
struct type *make_type_name(struct type_list *params, char *name);
|
|
|
|
void free_type(struct type *t);
|
|
|
|
/* type_list operations */
|
|
void free_type_list(struct type_list *l);
|
|
|
|
struct type_list_builder {
|
|
struct type_list *head;
|
|
struct type_list *last;
|
|
};
|
|
|
|
void type_list_append(struct type_list_builder *b, struct type *elem);
|
|
|