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 FUNCTION(name, outtype) \
61 ast_function *func_##name; \
62 ast_block *my_funcblock; \
64 DEFVAR(return_##name); \
65 VARnamed(TYPE_FUNCTION, var_##name, name); \
66 VARnamed(outtype, return_##name, "#returntype"); \
67 var_##name->expression.next = (ast_expression*)return_##name; \
68 MKGLOBAL(var_##name); \
69 func_##name = ast_function_new(ctx, #name, var_##name); \
70 assert(functions_add(func_##name) >= 0); \
71 my_funcblock = ast_block_new(ctx); \
72 assert(my_funcblock); \
73 assert(ast_function_blocks_add(func_##name, my_funcblock)); \
74 curblock = my_funcblock;
76 #define MKLOCAL(var) \
77 assert(ast_block_locals_add(curblock, var))
79 #define ENDFUNCTION(name) \