]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - test/ast-macros.h
better labelling in ast_function_labeling, this time the number is even printed forwa...
[xonotic/gmqcc.git] / test / ast-macros.h
index 6f52bdfceae491d968ae4ed7ae284de37da6730b..580cd7a69a38d69835ed1fa2d2b383f0a7eccd90 100644 (file)
@@ -21,6 +21,17 @@ name = ast_value_new(ctx, #varname, type)
 #define MKGLOBAL(name) \
 assert(globals_add(name) >= 0)
 
+#define FIELD(type, name) \
+name = ast_value_new(ctx, #name, TYPE_FIELD);                  \
+do {                                                           \
+    ast_value *field_##name = ast_value_new(ctx, #name, type); \
+    name->expression.next = (ast_expression*)field_##name;     \
+    MKFIELD(name);                                             \
+} while (0)
+
+#define MKFIELD(name) \
+assert(fields_add(name) >= 0)
+
 #define MKCONSTFLOAT(name, value)  \
 do {                               \
     name->isconst = true;          \
@@ -28,6 +39,22 @@ do {                               \
     MKGLOBAL(name);                \
 } while(0)
 
+#define MKCONSTSTRING(name, value)               \
+do {                                             \
+    name->isconst = true;                        \
+    name->constval.vstring = util_strdup(value); \
+    MKGLOBAL(name);                              \
+} while(0)
+
+#define MKCONSTVECTOR(name, valx, valy, valz) \
+do {                                          \
+    name->isconst = true;                     \
+    name->constval.vvec.x = (valx);           \
+    name->constval.vvec.y = (valy);           \
+    name->constval.vvec.z = (valz);           \
+    MKGLOBAL(name);                           \
+} while(0)
+
 #define STATE(a)                                 \
 do {                                             \
     ast_expression *exp = (ast_expression*)(a);  \
@@ -35,11 +62,35 @@ do {                                             \
 } while(0)
 
 #define ASSIGN(op, a, b) \
-(ast_expression*)ast_store_new(ctx, INSTR_##op, (a), (ast_expression*)(b))
+(ast_expression*)ast_store_new(ctx, INSTR_##op, (ast_expression*)(a), (ast_expression*)(b))
 
 #define BIN(op, a, b) \
 (ast_expression*)ast_binary_new(ctx, INSTR_##op, (ast_expression*)(a), (ast_expression*)(b))
 
+#define ENTFIELD(a, b) \
+(ast_expression*)ast_entfield_new(ctx, (ast_expression*)(a), (ast_expression*)(b))
+
+#define VECMEM(vec, mem) \
+(ast_expression*)ast_member_new(ctx, (ast_expression*)(vec), (mem))
+
+#define CALL(what)                                             \
+do {                                                           \
+    ast_call *call = ast_call_new(ctx, (ast_expression*)what); \
+
+#define CALLPARAM(x)                                       \
+    assert(ast_call_params_add(call, (ast_expression*)x));
+
+#define ENDCALL()                                \
+    STATE(call);                                 \
+} while(0)
+
+#define ENDCALLWITH(as, where)                      \
+    {                                               \
+        ast_expression *as = (ast_expression*)call; \
+        where;                                      \
+    }                                               \
+} while(0)
+
 #define WHILE(cond)                                    \
 do {                                                   \
     ast_expression *wh_cond = (ast_expression*)(cond); \
@@ -59,6 +110,7 @@ do {                                                   \
 #define BUILTIN(name, outtype, number)                              \
 do {                                                                \
     ast_function *func_##name;                                      \
+    ast_value    *thisfuncval;                                      \
     ast_function *thisfunc;                                         \
     DEFVAR(return_##name);                                          \
     VARnamed(TYPE_FUNCTION, name, name);                            \
@@ -68,6 +120,8 @@ do {                                                                \
     func_##name = ast_function_new(ctx, #name, name);               \
     thisfunc = func_##name;                                         \
     (void)thisfunc;                                                 \
+    thisfuncval = name;                                             \
+    (void)thisfuncval;                                              \
     assert(functions_add(func_##name) >= 0);                        \
     func_##name->builtin = number;
 
@@ -77,7 +131,7 @@ do {                                                                \
 do {                                                 \
     DEFVAR(parm);                                    \
     VARnamed(ptype, parm, name);                     \
-    assert(ast_function_params_add(thisfunc, parm)); \
+    assert(ast_value_params_add(thisfuncval, parm)); \
 } while(0)
 
 #define FUNCTION(name, outtype)                                   \