-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtype.h
26 lines (18 loc) · 833 Bytes
/
type.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
#ifndef __TYPE_H__
#define __TYPE_H__
char *strdup(const char *);
typedef enum typeid {E_type_int, E_type_float, E_type_array, E_type_struct, E_type_func, E_type_ref, E_type_error} typeid_t;
typedef enum relop {GT, LE, GE, LT, EQ, NEQ} relop_t;
typedef enum op2 {OP2_ASSIGNOP, OP2_AND, OP2_OR, OP2_RELOP, OP2_PLUS, OP2_MINUS, OP2_STAR, OP2_DIV} op2_t;
typedef enum op1 {OP1_MINUS, OP1_NOT} op1_t;
#define DEF_ENUM(name, ...) E_##name,
#define NEW(name, ...) ({ \
name##_t *__new_obj = malloc(sizeof(name##_t)); \
*__new_obj = (name##_t) { __VA_ARGS__ }; \
__new_obj; })
#define TYPENEW(name, ...) NEW(name, E_##name, ##__VA_ARGS__)
#define MIN(a, b) (((a) > (b)) ? (b) : (a))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
typedef struct range { int start, end; } range_t;
#define RANGE(st, ed) ((range_t){st, ed})
#endif