]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Merge branch 'cooking' of github.com:graphitemaster/gmqcc into cooking
authorDale Weiler <killfieldengine@gmail.com>
Tue, 5 Feb 2013 17:16:09 +0000 (17:16 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Tue, 5 Feb 2013 17:16:09 +0000 (17:16 +0000)
ast.c
ast.h
parser.c
tests/perl-ops.qc [deleted file]
tests/perl-ops.tmpl [deleted file]
tests/pops.qc [new file with mode: 0644]
tests/pops.tmpl [new file with mode: 0644]

diff --git a/ast.c b/ast.c
index 2a3997b952cab38d3c9017949dd612c7067c7cc8..c0c92fbe3ab122f7c15fa0b0a588b54f7f549c0a 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -406,13 +406,17 @@ ast_binary* ast_binary_new(lex_ctx ctx, int op,
     else
         self->expression.vtype = left->expression.vtype;
 
+    /* references all */
+    self->refs = AST_REF_ALL;
+
     return self;
 }
 
 void ast_binary_delete(ast_binary *self)
 {
-    ast_unref(self->left);
-    ast_unref(self->right);
+    if (self->refs & AST_REF_LEFT)  ast_unref(self->left);
+    if (self->refs & AST_REF_RIGHT) ast_unref(self->right);
+
     ast_expression_delete((ast_expression*)self);
     mem_d(self);
 }
diff --git a/ast.h b/ast.h
index 18f02a8e259f34da73ca4ecebbf94bdd4b1dcb00..83c700a97938d696b1515ea83bb601a4f439e697 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -218,6 +218,13 @@ ast_expression* ast_type_copy(lex_ctx ctx, const ast_expression *ex);
 void ast_type_adopt_impl(ast_expression *self, const ast_expression *other);
 void ast_type_to_string(ast_expression *e, char *buf, size_t bufsize);
 
+typedef enum ast_binary_ref_s {
+    AST_REF_LEFT  = 1 << 1,
+    AST_REF_RIGHT = 1 << 2,
+    AST_REF_ALL   = (AST_REF_LEFT | AST_REF_RIGHT)
+} ast_binary_ref;
+
+
 /* Binary
  *
  * A value-returning binary expression.
@@ -229,6 +236,8 @@ struct ast_binary_s
     int             op;
     ast_expression *left;
     ast_expression *right;
+    ast_binary_ref  refs;
+    
 };
 ast_binary* ast_binary_new(lex_ctx    ctx,
                            int        op,
index e9cbe0a031c81dc723cf5ff4cecbb7ab7dc96380..d5f800cb7a6a94d095427e232ac0e76616df615c 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1085,23 +1085,21 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 else if (ConstF(0) > ConstF(1))
                     out = (ast_expression*)parser_const_float_1(parser);
             } else {
+                ast_binary *eq = ast_binary_new(ctx, INSTR_EQ_F, exprs[0], exprs[1]);
+
+                eq->refs = false; /* references nothing */
+
                     /* if (lt) { */
                 out = (ast_expression*)ast_ternary_new(ctx,
                         (ast_expression*)ast_binary_new(ctx, INSTR_LT, exprs[0], exprs[1]),
-
                         /* out = -1 */
                         (ast_expression*)parser_const_float_neg1(parser),
-
                     /* } else { */
                         /* if (eq) { */
-                        (ast_expression*)ast_ternary_new(ctx,
-                            (ast_expression*)ast_binary_new(ctx, INSTR_EQ_F, exprs[0], exprs[1]),
-
+                        (ast_expression*)ast_ternary_new(ctx, (ast_expression*)eq,
                             /* out = 0 */
                             (ast_expression*)parser_const_float_0(parser),
-
                         /* } else { */
-
                             /* out = 1 */
                             (ast_expression*)parser_const_float_1(parser)
                         /* } */
diff --git a/tests/perl-ops.qc b/tests/perl-ops.qc
deleted file mode 100644 (file)
index ee6631b..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-void main() {
-    /* so far only one perl operator is implemented */
-    float x = 100;
-    float y = 200;
-    float z = 300;
-
-    /* to ensure runtime */
-    x += 1;
-    y += 1;
-    z += 1;
-
-    float test_x = (x <=> x + 1); // -1 less than
-    float test_y = (x <=> x);     //  0 equal
-    float test_z = (x <=> x - 1); //  1 greater than
-
-    print(ftos(test_x), "\n");
-    print(ftos(test_y), "\n");
-    print(ftos(test_z), "\n");
-}
diff --git a/tests/perl-ops.tmpl b/tests/perl-ops.tmpl
deleted file mode 100644 (file)
index f3f1eb5..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-I: perl-opts.qc
-D: test perl operators
-T: -execute
-C: -std=gmqcc
-M: -1
-M: 0
-M: 1
diff --git a/tests/pops.qc b/tests/pops.qc
new file mode 100644 (file)
index 0000000..ee6631b
--- /dev/null
@@ -0,0 +1,19 @@
+void main() {
+    /* so far only one perl operator is implemented */
+    float x = 100;
+    float y = 200;
+    float z = 300;
+
+    /* to ensure runtime */
+    x += 1;
+    y += 1;
+    z += 1;
+
+    float test_x = (x <=> x + 1); // -1 less than
+    float test_y = (x <=> x);     //  0 equal
+    float test_z = (x <=> x - 1); //  1 greater than
+
+    print(ftos(test_x), "\n");
+    print(ftos(test_y), "\n");
+    print(ftos(test_z), "\n");
+}
diff --git a/tests/pops.tmpl b/tests/pops.tmpl
new file mode 100644 (file)
index 0000000..35b7d41
--- /dev/null
@@ -0,0 +1,7 @@
+I: pops.qc
+D: test perl operators
+T: -execute
+C: -std=gmqcc
+M: -1
+M: 0
+M: 1