115 lines
2.6 KiB
C
115 lines
2.6 KiB
C
struct type;
|
|
struct expr;
|
|
struct pattern_list;
|
|
|
|
struct value_decl {
|
|
char *name;
|
|
struct expr *body;
|
|
};
|
|
|
|
/* List of function definition clauses */
|
|
struct func_decl_list {
|
|
char *name;
|
|
struct pattern_list *args;
|
|
struct expr *body;
|
|
|
|
struct func_decl_list *next;
|
|
};
|
|
|
|
struct func_decl_list_builder {
|
|
struct func_decl_list *head;
|
|
struct func_decl_list *last;
|
|
};
|
|
|
|
void func_decl_list_append(struct func_decl_list_builder *b, char *name, struct pattern_list *args, struct expr *body);
|
|
void free_func_decl_list(struct func_decl_list *l);
|
|
|
|
/* A list of type variables */
|
|
struct var_list {
|
|
char *name;
|
|
struct var_list *next;
|
|
};
|
|
|
|
struct var_list_builder {
|
|
struct var_list *head;
|
|
struct var_list *last;
|
|
};
|
|
|
|
void var_list_append(struct var_list_builder *b, char *elem);
|
|
void free_var_list(struct var_list *l);
|
|
|
|
/* List of datatype constructors */
|
|
struct constructor_list {
|
|
char *name;
|
|
struct type *t;
|
|
struct constructor_list *next;
|
|
};
|
|
|
|
struct constructor_list_builder {
|
|
struct constructor_list *head;
|
|
struct constructor_list *last;
|
|
};
|
|
|
|
void constructor_list_append(struct constructor_list_builder *b, char *name, struct type *t);
|
|
void free_constructor_list(struct constructor_list *l);
|
|
|
|
struct datatype_decl {
|
|
/* Definition parameters */
|
|
struct var_list *type_params;
|
|
/* datatype name */
|
|
char *name;
|
|
/* Datatype constructors list */
|
|
struct constructor_list *ctors;
|
|
};
|
|
|
|
struct alias_decl {
|
|
struct var_list *type_params;
|
|
char *definiendum;
|
|
struct type *definiens;
|
|
};
|
|
|
|
struct typecheck_decl {
|
|
char *name;
|
|
struct type *t;
|
|
};
|
|
|
|
enum decl_form {
|
|
value_decl,
|
|
func_decl,
|
|
datatype_decl,
|
|
alias_decl,
|
|
typecheck_decl,
|
|
};
|
|
|
|
struct decl {
|
|
enum decl_form form;
|
|
union {
|
|
struct value_decl value;
|
|
struct func_decl_list *func;
|
|
struct datatype_decl datatype;
|
|
struct alias_decl alias;
|
|
struct typecheck_decl typecheck;
|
|
};
|
|
};
|
|
|
|
struct decl_list {
|
|
struct decl *elem;
|
|
struct decl_list *next;
|
|
};
|
|
|
|
struct decl_list_builder {
|
|
struct decl_list *head;
|
|
struct decl_list *last;
|
|
};
|
|
|
|
void decl_list_append(struct decl_list_builder *b, struct decl *elem);
|
|
void free_decl_list(struct decl_list *l);
|
|
|
|
struct decl *make_value_decl(char *name, struct expr *body);
|
|
struct decl *make_func_decl(struct func_decl_list *f);
|
|
struct decl *make_datatype_decl(struct var_list *ps, char *name, struct constructor_list *cs);
|
|
struct decl *make_alias_decl(struct var_list *ps, char *def, struct type *body);
|
|
struct decl *make_typecheck_decl(char *n, struct type *t);
|
|
|
|
void free_decl(struct decl *d);
|