]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.c
Offsetting builtins so we can use 'if builtin!=0' as condition but also allow a ...
[xonotic/gmqcc.git] / ast.c
diff --git a/ast.c b/ast.c
index 390faf7e073117b33cde5fe6d87a0b1fe247fac6..40a53a3f3c7ed19a3a253e0496b79fb1ab2c030d 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -322,6 +322,7 @@ ast_value* ast_value_new(lex_ctx ctx, const char *name, int t)
     self->name = name ? util_strdup(name) : NULL;
     self->expression.vtype = t;
     self->expression.next  = NULL;
+    self->isfield  = false;
     self->cvq      = CV_NONE;
     self->hasvalue = false;
     self->uses    = 0;
@@ -997,7 +998,7 @@ ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype)
         vtype->hasvalue ||
         vtype->expression.vtype != TYPE_FUNCTION)
     {
-        compile_error(ast_ctx(self), "internal error: ast_function_new condition %i %i type=%i",
+        compile_error(ast_ctx(self), "internal error: ast_function_new condition %i %i type=%i (probably 2 bodies?)",
                  (int)!vtype,
                  (int)vtype->hasvalue,
                  vtype->expression.vtype);
@@ -1263,6 +1264,18 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
                 /* Cannot generate an IR value for a function,
                  * need a pointer pointing to a function rather.
                  */
+            case TYPE_FIELD:
+                if (!self->constval.vfield) {
+                    compile_error(ast_ctx(self), "field constant without vfield set");
+                    goto error;
+                }
+                if (!self->constval.vfield->ir_v) {
+                    compile_error(ast_ctx(self), "field constant generated before its field");
+                    goto error;
+                }
+                if (!ir_value_set_field(v, self->constval.vfield->ir_v))
+                    goto error;
+                break;
             default:
                 compile_error(ast_ctx(self), "TODO: global constant type %i", self->expression.vtype);
                 break;
@@ -2407,7 +2420,7 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
     bbreak = bout;
 
     /* The loop body... */
-    if (self->body)
+    /* if (self->body) */
     {
         bbody = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "loop_body"));
         if (!bbody)
@@ -2424,9 +2437,11 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
             func->continueblock = bbody;
 
         /* generate */
-        cgen = self->body->expression.codegen;
-        if (!(*cgen)((ast_expression*)(self->body), func, false, &dummy))
-            return false;
+        if (self->body) {
+            cgen = self->body->expression.codegen;
+            if (!(*cgen)((ast_expression*)(self->body), func, false, &dummy))
+                return false;
+        }
 
         end_bbody = func->curblock;
         func->breakblock    = old_bbreak;