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; \
33 ast_expression *exp = (ast_expression*)(a); \
34 assert(ast_block_exprs_add(curblock, exp)); \
37 #define ASSIGN(op, a, b) \
38 (ast_expression*)ast_store_new(ctx, INSTR_##op, (a), (ast_expression*)(b))
40 #define BIN(op, a, b) \
41 (ast_expression*)ast_binary_new(ctx, INSTR_##op, (ast_expression*)(a), (ast_expression*)(b))
45 ast_expression *wh_cond = (ast_expression*)(cond); \
46 ast_block *wh_body = ast_block_new(ctx); \
47 ast_block *oldcur = curblock; \
53 loop = ast_loop_new(ctx, NULL, (ast_expression*)wh_cond, \
54 NULL, NULL, (ast_expression*)wh_body); \
59 #define BUILTIN(name, outtype, number) \
61 ast_function *func_##name; \
62 ast_function *thisfunc; \
63 DEFVAR(return_##name); \
64 VARnamed(TYPE_FUNCTION, name, name); \
65 VARnamed(outtype, return_##name, "#returntype"); \
66 name->expression.next = (ast_expression*)return_##name; \
68 func_##name = ast_function_new(ctx, #name, name); \
69 thisfunc = func_##name; \
71 assert(functions_add(func_##name) >= 0); \
72 func_##name->builtin = number;
74 #define ENDBUILTIN() } while(0)
76 #define PARAM(ptype, name) \
79 VARnamed(ptype, parm, name); \
80 assert(ast_function_params_add(thisfunc, parm)); \
83 #define FUNCTION(name, outtype) \
85 ast_function *thisfunc; \
86 ast_function *func_##name; \
87 ast_block *my_funcblock; \
89 DEFVAR(return_##name); \
90 VARnamed(TYPE_FUNCTION, var_##name, name); \
91 VARnamed(outtype, return_##name, "#returntype"); \
92 var_##name->expression.next = (ast_expression*)return_##name; \
93 MKGLOBAL(var_##name); \
94 func_##name = ast_function_new(ctx, #name, var_##name); \
95 thisfunc = func_##name; \
97 assert(functions_add(func_##name) >= 0); \
98 my_funcblock = ast_block_new(ctx); \
99 assert(my_funcblock); \
100 assert(ast_function_blocks_add(func_##name, my_funcblock)); \
101 curblock = my_funcblock;
103 #define MKLOCAL(var) \
104 assert(ast_block_locals_add(curblock, var))
106 #define ENDFUNCTION(name) \