1 #ifndef TEST_AST_MACROS_HDR
2 #define TEST_AST_MACROS_HDR
12 #define DEFVAR(name) \
15 #define VAR(type, name) \
16 name = ast_value_new(ctx, #name, type)
18 #define VARnamed(type, name, varname) \
19 name = ast_value_new(ctx, #varname, type)
21 #define MKGLOBAL(name) \
22 assert(globals_add(name) >= 0)
24 #define FIELD(type, name) \
25 name = ast_value_new(ctx, #name, TYPE_FIELD); \
27 ast_value *field_##name = ast_value_new(ctx, #name, type); \
28 name->expression.next = (ast_expression*)field_##name; \
32 #define MKFIELD(name) \
33 assert(fields_add(name) >= 0)
35 #define MKCONSTFLOAT(name, value) \
37 name->isconst = true; \
38 name->constval.vfloat = value; \
42 #define MKCONSTSTRING(name, value) \
44 name->isconst = true; \
45 name->constval.vstring = util_strdup(value); \
51 ast_expression *exp = (ast_expression*)(a); \
52 assert(ast_block_exprs_add(curblock, exp)); \
55 #define ASSIGN(op, a, b) \
56 (ast_expression*)ast_store_new(ctx, INSTR_##op, (ast_expression*)(a), (ast_expression*)(b))
58 #define BIN(op, a, b) \
59 (ast_expression*)ast_binary_new(ctx, INSTR_##op, (ast_expression*)(a), (ast_expression*)(b))
61 #define ENTFIELD(a, b) \
62 (ast_expression*)ast_entfield_new(ctx, (ast_expression*)(a), (ast_expression*)(b))
66 ast_call *call = ast_call_new(ctx, (ast_expression*)what); \
68 #define CALLPARAM(x) \
69 assert(ast_call_params_add(call, (ast_expression*)x));
75 #define ENDCALLWITH(as, where) \
77 ast_expression *as = (ast_expression*)call; \
84 ast_expression *wh_cond = (ast_expression*)(cond); \
85 ast_block *wh_body = ast_block_new(ctx); \
86 ast_block *oldcur = curblock; \
92 loop = ast_loop_new(ctx, NULL, (ast_expression*)wh_cond, \
93 NULL, NULL, (ast_expression*)wh_body); \
98 #define BUILTIN(name, outtype, number) \
100 ast_function *func_##name; \
101 ast_value *thisfuncval; \
102 ast_function *thisfunc; \
103 DEFVAR(return_##name); \
104 VARnamed(TYPE_FUNCTION, name, name); \
105 VARnamed(outtype, return_##name, "#returntype"); \
106 name->expression.next = (ast_expression*)return_##name; \
108 func_##name = ast_function_new(ctx, #name, name); \
109 thisfunc = func_##name; \
111 thisfuncval = name; \
113 assert(functions_add(func_##name) >= 0); \
114 func_##name->builtin = number;
116 #define ENDBUILTIN() } while(0)
118 #define PARAM(ptype, name) \
121 VARnamed(ptype, parm, name); \
122 assert(ast_value_params_add(thisfuncval, parm)); \
125 #define FUNCTION(name, outtype) \
127 ast_function *thisfunc; \
128 ast_function *func_##name; \
129 ast_block *my_funcblock; \
130 DEFVAR(var_##name); \
131 DEFVAR(return_##name); \
132 VARnamed(TYPE_FUNCTION, var_##name, name); \
133 VARnamed(outtype, return_##name, "#returntype"); \
134 var_##name->expression.next = (ast_expression*)return_##name; \
135 MKGLOBAL(var_##name); \
136 func_##name = ast_function_new(ctx, #name, var_##name); \
137 thisfunc = func_##name; \
139 assert(functions_add(func_##name) >= 0); \
140 my_funcblock = ast_block_new(ctx); \
141 assert(my_funcblock); \
142 assert(ast_function_blocks_add(func_##name, my_funcblock)); \
143 curblock = my_funcblock;
145 #define MKLOCAL(var) \
146 assert(ast_block_locals_add(curblock, var))
148 #define ENDFUNCTION(name) \