]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
more fixes
authorDale Weiler <killfieldengine@gmail.com>
Wed, 31 Jul 2013 16:31:45 +0000 (16:31 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Wed, 31 Jul 2013 16:31:45 +0000 (16:31 +0000)
fold.c
parser.c
parser.h

diff --git a/fold.c b/fold.c
index 5f5c12774c9a30bc68262a23dda1315e75f54f72..6a8cec232e1e31d5b5d43129cc83e01473bba494 100644 (file)
--- a/fold.c
+++ b/fold.c
@@ -75,17 +75,17 @@ static GMQCC_INLINE vec3_t vec3_neg(vec3_t a) {
 
 static GMQCC_INLINE vec3_t vec3_xor(vec3_t a, vec3_t b) {
     vec3_t out;
 
 static GMQCC_INLINE vec3_t vec3_xor(vec3_t a, vec3_t b) {
     vec3_t out;
-    out.x = (qcfloat_t)((qcint_t)a.x ^ (qcint_t)b.x);
-    out.y = (qcfloat_t)((qcint_t)a.y ^ (qcint_t)b.y);
-    out.z = (qcfloat_t)((qcint_t)a.z ^ (qcint_t)b.z);
+    out.x = (qcfloat_t)(((qcint_t)a.x) ^ ((qcint_t)b.x));
+    out.y = (qcfloat_t)(((qcint_t)a.y) ^ ((qcint_t)b.y));
+    out.z = (qcfloat_t)(((qcint_t)a.z) ^ ((qcint_t)b.z));
     return out;
 }
 
 static GMQCC_INLINE vec3_t vec3_xorvf(vec3_t a, qcfloat_t b) {
     vec3_t out;
     return out;
 }
 
 static GMQCC_INLINE vec3_t vec3_xorvf(vec3_t a, qcfloat_t b) {
     vec3_t out;
-    out.x = (qcfloat_t)((qcint_t)a.x ^ (qcint_t)b);
-    out.y = (qcfloat_t)((qcint_t)a.y ^ (qcint_t)b);
-    out.z = (qcfloat_t)((qcint_t)a.z ^ (qcint_t)b);
+    out.x = (qcfloat_t)(((qcint_t)a.x) ^ ((qcint_t)b));
+    out.y = (qcfloat_t)(((qcint_t)a.y) ^ ((qcint_t)b));
+    out.z = (qcfloat_t)(((qcint_t)a.z) ^ ((qcint_t)b));
     return out;
 }
 
     return out;
 }
 
@@ -124,7 +124,8 @@ static GMQCC_INLINE bool vec3_pbool(vec3_t a) {
 }
 
 static GMQCC_INLINE bool fold_can_1(const ast_value *val) {
 }
 
 static GMQCC_INLINE bool fold_can_1(const ast_value *val) {
-    return  (ast_istype((ast_expression*)val, ast_value) && val->hasvalue && val->cvq == CV_CONST && ((ast_expression*)val)->vtype != TYPE_FUNCTION);
+    return (ast_istype(((ast_expression*)(val)), ast_value) && val->hasvalue && (val->cvq == CV_CONST) &&
+              ((ast_expression*)(val))->vtype != TYPE_FUNCTION);
 }
 
 static GMQCC_INLINE bool fold_can_2(const ast_value *v1, const ast_value *v2) {
 }
 
 static GMQCC_INLINE bool fold_can_2(const ast_value *v1, const ast_value *v2) {
@@ -149,7 +150,7 @@ static GMQCC_INLINE bool fold_immediate_true(fold_t *fold, ast_value *v) {
         case TYPE_VECTOR: 
             if (OPTS_FLAG(CORRECT_LOGIC))
                 return vec3_pbool(v->constval.vvec);
         case TYPE_VECTOR: 
             if (OPTS_FLAG(CORRECT_LOGIC))
                 return vec3_pbool(v->constval.vvec);
-            return !!v->constval.vvec.x;
+            return !!(v->constval.vvec.x);
         case TYPE_STRING:
             if (!v->constval.vstring)
                 return false;
         case TYPE_STRING:
             if (!v->constval.vstring)
                 return false;
index bfa7105151428ab0167296976150e6b9f8cf351c..fc2ef35de879a5cb58d49793984650ff6332f3c5 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -504,7 +504,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
 
         case opid1('+'):
             if (exprs[0]->vtype != exprs[1]->vtype ||
 
         case opid1('+'):
             if (exprs[0]->vtype != exprs[1]->vtype ||
-                (exprs[0]->vtype != TYPE_VECTOR && exprs[0]->vtype != TYPE_FLOAT) )
+               (exprs[0]->vtype != TYPE_VECTOR && exprs[0]->vtype != TYPE_FLOAT) )
             {
                 compile_error(ctx, "invalid types used in expression: cannot add type %s and %s",
                               type_name[exprs[0]->vtype],
             {
                 compile_error(ctx, "invalid types used in expression: cannot add type %s and %s",
                               type_name[exprs[0]->vtype],
@@ -597,10 +597,19 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             if (!(out = fold_op(parser->fold, op, exprs))) {
                 if (exprs[0]->vtype == TYPE_FLOAT) 
                     out = (ast_expression*)ast_binary_new(ctx, INSTR_DIV_F, exprs[0], exprs[1]);
             if (!(out = fold_op(parser->fold, op, exprs))) {
                 if (exprs[0]->vtype == TYPE_FLOAT) 
                     out = (ast_expression*)ast_binary_new(ctx, INSTR_DIV_F, exprs[0], exprs[1]);
-                else if (exprs[0]->vtype == TYPE_VECTOR)
-                    out = (ast_expression*)ast_binary_new(ctx, INSTR_MUL_VF, exprs[0], out);
-                else /* TODO stot */
-                {
+                else if (exprs[0]->vtype == TYPE_VECTOR) {
+                    out = (ast_expression*)ast_binary_new (
+                                ctx,
+                                INSTR_MUL_VF,
+                                exprs[0],
+                                (ast_expression*)ast_binary_new(
+                                    ctx,
+                                    INSTR_DIV_F,
+                                    (ast_expression*)parser->fold->imm_float[1],
+                                    exprs[1]
+                                )
+                    );
+                } else {
                     ast_type_to_string(exprs[0], ty1, sizeof(ty1));
                     ast_type_to_string(exprs[1], ty2, sizeof(ty2));
                     compile_error(ctx, "invalid types used in expression: cannot divide types %s and %s", ty1, ty2);
                     ast_type_to_string(exprs[0], ty1, sizeof(ty1));
                     ast_type_to_string(exprs[1], ty2, sizeof(ty2));
                     compile_error(ctx, "invalid types used in expression: cannot divide types %s and %s", ty1, ty2);
@@ -758,13 +767,13 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             generated_op += 1; /* INSTR_OR */
         case opid2('&','&'):
             generated_op += INSTR_AND;
             generated_op += 1; /* INSTR_OR */
         case opid2('&','&'):
             generated_op += INSTR_AND;
-            if (OPTS_FLAG(PERL_LOGIC) && !ast_compare_type(exprs[0], exprs[1])) {
-                ast_type_to_string(exprs[0], ty1, sizeof(ty1));
-                ast_type_to_string(exprs[1], ty2, sizeof(ty2));
-                compile_error(ctx, "invalid types for logical operation with -fperl-logic: %s and %s", ty1, ty2);
-                return false;
-            }
             if (!(out = fold_op(parser->fold, op, exprs))) {
             if (!(out = fold_op(parser->fold, op, exprs))) {
+                if (OPTS_FLAG(PERL_LOGIC) && !ast_compare_type(exprs[0], exprs[1])) {
+                    ast_type_to_string(exprs[0], ty1, sizeof(ty1));
+                    ast_type_to_string(exprs[1], ty2, sizeof(ty2));
+                    compile_error(ctx, "invalid types for logical operation with -fperl-logic: %s and %s", ty1, ty2);
+                    return false;
+                }
                 for (i = 0; i < 2; ++i) {
                     if (OPTS_FLAG(CORRECT_LOGIC) && exprs[i]->vtype == TYPE_VECTOR) {
                         out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_V, exprs[i]);
                 for (i = 0; i < 2; ++i) {
                     if (OPTS_FLAG(CORRECT_LOGIC) && exprs[i]->vtype == TYPE_VECTOR) {
                         out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_V, exprs[i]);
@@ -816,7 +825,9 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                 compile_error(ctx, "invalid types used in exponentiation: %s and %s",
                     ty1, ty2);
                 return false;
                 compile_error(ctx, "invalid types used in exponentiation: %s and %s",
                     ty1, ty2);
                 return false;
-            } else if (!(out = fold_op(parser->fold, op, exprs))) {
+            }
+            
+            if (!(out = fold_op(parser->fold, op, exprs))) {
                 ast_call *gencall = ast_call_new(parser_ctx(parser), intrin_func(parser, "pow"));
                 vec_push(gencall->params, exprs[0]);
                 vec_push(gencall->params, exprs[1]);
                 ast_call *gencall = ast_call_new(parser_ctx(parser), intrin_func(parser, "pow"));
                 vec_push(gencall->params, exprs[0]);
                 vec_push(gencall->params, exprs[1]);
@@ -832,7 +843,9 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                     ty1, ty2);
 
                 return false;
                     ty1, ty2);
 
                 return false;
-            } else if (!(out = fold_op(parser->fold, op, exprs))) {
+            } 
+
+            if (!(out = fold_op(parser->fold, op, exprs))) {
                 ast_binary *eq = ast_binary_new(ctx, INSTR_EQ_F, exprs[0], exprs[1]);
 
                 eq->refs = AST_REF_NONE;
                 ast_binary *eq = ast_binary_new(ctx, INSTR_EQ_F, exprs[0], exprs[1]);
 
                 eq->refs = AST_REF_NONE;
index 08692107b93dcf061cccff5032c095e77ee14cf9..147d292b3314cd20f98e5a42701750b10ee61023 100644 (file)
--- a/parser.h
+++ b/parser.h
@@ -36,7 +36,8 @@ typedef struct {
     hash_table_t    *imm_string_dotranslate; /* map<string, ast_value*> */
 } fold_t;
 
     hash_table_t    *imm_string_dotranslate; /* map<string, ast_value*> */
 } fold_t;
 
-#define parser_ctx(p)    ((p)->lex->tok.ctx)
+#define parser_ctx(p) ((p)->lex->tok.ctx)
+
 typedef struct parser_s {
     lex_file *lex;
     int      tok;
 typedef struct parser_s {
     lex_file *lex;
     int      tok;