]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Merge branch 'master' into cooking
authorWolfgang Bumiller <wry.git@bumiller.com>
Sat, 27 Apr 2013 17:05:06 +0000 (19:05 +0200)
committerWolfgang Bumiller <wry.git@bumiller.com>
Sat, 27 Apr 2013 17:05:06 +0000 (19:05 +0200)
ast.c
ast.h
distro/deb/Makefile
ir.c
parser.c

diff --git a/ast.c b/ast.c
index 3e5d304d1e53c6ba9666f56ddfd6aafdc4bc94c8..1e2836f8e2c39181b949d733e85503606b7e5703 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -317,8 +317,9 @@ ast_value* ast_value_new(lex_ctx ctx, const char *name, int t)
     self->cvq      = CV_NONE;
     self->hasvalue = false;
     self->isimm    = false;
-    self->uses    = 0;
+    self->uses     = 0;
     memset(&self->constval, 0, sizeof(self->constval));
+    self->initlist = NULL;
 
     self->ir_v           = NULL;
     self->ir_values      = NULL;
@@ -362,6 +363,20 @@ void ast_value_delete(ast_value* self)
     if (self->desc)
         mem_d(self->desc);
 
+    if (self->initlist) {
+        if (self->expression.next->expression.vtype == TYPE_STRING) {
+            /* strings are allocated, free them */
+            size_t i, len = vec_size(self->initlist);
+            /* in theory, len should be expression.count
+             * but let's not take any chances */
+            for (i = 0; i < len; ++i) {
+                if (self->initlist[i].vstring)
+                    mem_d(self->initlist[i].vstring);
+            }
+        }
+        vec_free(self->initlist);
+    }
+
     ast_expression_delete((ast_expression*)self);
     mem_d(self);
 }
diff --git a/ast.h b/ast.h
index bae07db39ec85c13481a10ecec947ece7f0c7ce8..98ad79228fee073da2a66cf4dbc581f4f4728b53 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -161,6 +161,15 @@ typedef struct
  * typedef float foo;
  * is like creating a 'float foo', foo serving as the type's name.
  */
+typedef union {
+    double        vfloat;
+    int           vint;
+    vector        vvec;
+    const char   *vstring;
+    int           ventity;
+    ast_function *vfunc;
+    ast_value    *vfield;
+} basic_value_t;
 struct ast_value_s
 {
     ast_expression_common expression;
@@ -179,15 +188,12 @@ struct ast_value_s
     bool isfield; /* this declares a field */
     bool isimm;   /* an immediate, not just const */
     bool hasvalue;
-    union {
-        double        vfloat;
-        int           vint;
-        vector        vvec;
-        const char   *vstring;
-        int           ventity;
-        ast_function *vfunc;
-        ast_value    *vfield;
-    } constval;
+    basic_value_t constval;
+    /* for TYPE_ARRAY we have an optional vector
+     * of constants when an initializer list
+     * was provided.
+     */
+    basic_value_t *initlist;
 
     /* usecount for the parser */
     size_t uses;
index df23602b592b94a07c7ef47d0792b030dad86e0b..7594400300c9482bab11df2ae93b5509683a4114 100644 (file)
@@ -10,12 +10,14 @@ DEB     := $(DEBDIR)-$(CARCH).deb
 CONTROL := $(DEBDIR)/DEBIAN/control
 
 ifneq (, $(findstring i686, $(CARCH)))
-       CFLAGS := -m32
+       CFLAGS += -m32
+       LDFLAGS += -m32
 endif
 
 base:
        $(MAKE) -C $(BASEDIR) clean
-       $(MAKE) -C $(BASEDIR) DESTDIR=distro/deb/$(DEBDIR) PREFIX=$(PREFIX) install
+       CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
+         $(MAKE) -C $(BASEDIR) DESTDIR=distro/deb/$(DEBDIR) PREFIX=$(PREFIX) install
        @install -d -m755 $(DEBDIR)/DEBIAN
        @echo "Package: gmqcc" > $(CONTROL)
        @echo "Version: $(MAJOR).$(MINOR).$(PATCH)" >> $(CONTROL)
diff --git a/ir.c b/ir.c
index 82dcb9befaf578f2c6d671a41ef88ac7fe6c3644..a124bd1fa60e1c608a276780812f321cfdc8a594 100644 (file)
--- a/ir.c
+++ b/ir.c
@@ -3418,7 +3418,8 @@ static bool ir_builder_gen_global(code_t *code, ir_builder *self, ir_value *glob
     {
         ir_value_code_setaddr(global, vec_size(code->globals));
         if (global->hasvalue) {
-            vec_push(code->globals, code_genstring(code, global->constval.vstring));
+            uint32_t load = code_genstring(code, global->constval.vstring);
+            vec_push(code->globals, load);
         } else {
             vec_push(code->globals, 0);
         }
index 7fba786c9cead285969038375c0e801cbc4f24b3..a09a54af75eb5b6b1ec645c4ec9e76e0bba40973 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -5623,7 +5623,7 @@ skipvar:
             }
         }
 
-        if (parser->tok != '{') {
+        if (parser->tok != '{' || var->expression.vtype != TYPE_FUNCTION) {
             if (parser->tok != '=') {
                 parseerror(parser, "missing semicolon or initializer, got: `%s`", parser_tokval(parser));
                 break;
@@ -5725,7 +5725,22 @@ skipvar:
                 break;
             }
         }
-        else if (parser->tok == '{' || parser->tok == '[')
+        else if (var->expression.vtype == TYPE_ARRAY && parser->tok == '{')
+        {
+            if (localblock) {
+                /* Note that fteqcc and most others don't even *have*
+                 * local arrays, so this is not a high priority.
+                 */
+                parseerror(parser, "TODO: initializers for local arrays");
+                break;
+            }
+            /*
+static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma, bool truthvalue, bool with_labels);
+*/
+            parseerror(parser, "TODO: initializing global arrays is not supported yet!");
+            break;
+        }
+        else if (var->expression.vtype == TYPE_FUNCTION && (parser->tok == '{' || parser->tok == '['))
         {
             if (localblock) {
                 parseerror(parser, "cannot declare functions within functions");