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 MKCONSTFLOAT(name, value) \
26 name->isconst = true; \
27 name->constval.vfloat = value; \
31 #define MKCONSTSTRING(name, value) \
33 name->isconst = true; \
34 name->constval.vstring = util_strdup(value); \
40 ast_expression *exp = (ast_expression*)(a); \
41 assert(ast_block_exprs_add(curblock, exp)); \
44 #define ASSIGN(op, a, b) \
45 (ast_expression*)ast_store_new(ctx, INSTR_##op, (ast_expression*)(a), (ast_expression*)(b))
47 #define BIN(op, a, b) \
48 (ast_expression*)ast_binary_new(ctx, INSTR_##op, (ast_expression*)(a), (ast_expression*)(b))
52 ast_call *call = ast_call_new(ctx, (ast_expression*)what); \
54 #define CALLPARAM(x) \
55 assert(ast_call_params_add(call, (ast_expression*)x));
63 ast_expression *wh_cond = (ast_expression*)(cond); \
64 ast_block *wh_body = ast_block_new(ctx); \
65 ast_block *oldcur = curblock; \
71 loop = ast_loop_new(ctx, NULL, (ast_expression*)wh_cond, \
72 NULL, NULL, (ast_expression*)wh_body); \
77 #define BUILTIN(name, outtype, number) \
79 ast_function *func_##name; \
80 ast_value *thisfuncval; \
81 ast_function *thisfunc; \
82 DEFVAR(return_##name); \
83 VARnamed(TYPE_FUNCTION, name, name); \
84 VARnamed(outtype, return_##name, "#returntype"); \
85 name->expression.next = (ast_expression*)return_##name; \
87 func_##name = ast_function_new(ctx, #name, name); \
88 thisfunc = func_##name; \
92 assert(functions_add(func_##name) >= 0); \
93 func_##name->builtin = number;
95 #define ENDBUILTIN() } while(0)
97 #define PARAM(ptype, name) \
100 VARnamed(ptype, parm, name); \
101 assert(ast_value_params_add(thisfuncval, parm)); \
104 #define FUNCTION(name, outtype) \
106 ast_function *thisfunc; \
107 ast_function *func_##name; \
108 ast_block *my_funcblock; \
109 DEFVAR(var_##name); \
110 DEFVAR(return_##name); \
111 VARnamed(TYPE_FUNCTION, var_##name, name); \
112 VARnamed(outtype, return_##name, "#returntype"); \
113 var_##name->expression.next = (ast_expression*)return_##name; \
114 MKGLOBAL(var_##name); \
115 func_##name = ast_function_new(ctx, #name, var_##name); \
116 thisfunc = func_##name; \
118 assert(functions_add(func_##name) >= 0); \
119 my_funcblock = ast_block_new(ctx); \
120 assert(my_funcblock); \
121 assert(ast_function_blocks_add(func_##name, my_funcblock)); \
122 curblock = my_funcblock;
124 #define MKLOCAL(var) \
125 assert(ast_block_locals_add(curblock, var))
127 #define ENDFUNCTION(name) \