]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Work in progress ~ operator implemented as -1-x.
authorDale Weiler <killfieldengine@gmail.com>
Fri, 1 Feb 2013 12:56:01 +0000 (12:56 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Fri, 1 Feb 2013 12:56:01 +0000 (12:56 +0000)
lexer.c
parser.c

diff --git a/lexer.c b/lexer.c
index f345e47be5b8dfc7589a84abe03e38ef967a91ce..e1cff47ef24bfd19b2ff7c27a14d1b450f846724 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -1288,10 +1288,11 @@ int lex_do(lex_file *lex)
     }
 
     if (ch == '+' || ch == '-' || /* ++, --, +=, -=  and -> as well! */
-        ch == '>' || ch == '<' || /* <<, >>, <=, >= */
-        ch == '=' || ch == '!' || /* ==, != */
-        ch == '&' || ch == '|')   /* &&, ||, &=, |= */
-    {
+        ch == '>' || ch == '<' || /* <<, >>, <=, >=                  */
+        ch == '=' || ch == '!' || /* ==, !=                          */
+        ch == '&' || ch == '|' || /* &&, ||, &=, |=                  */
+        ch == '~'                 /* ~=, ~                           */
+    )  {
         lex_tokench(lex, ch);
 
         nextch = lex_getch(lex);
@@ -1484,6 +1485,6 @@ int lex_do(lex_file *lex)
         return (lex->tok.ttype = ch);
     }
 
-    lexerror(lex, "unknown token");
+    lexerror(lex, "unknown token: %c", lex->tok);
     return (lex->tok.ttype = TOKEN_ERROR);
 }
index bfd8e845ddfc1c320df6e5df1b472953f12107aa..1de2459dfc54768a8b91e54c3ff3aee369d40cd1 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -951,6 +951,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             return false;
         case opid1('|'):
         case opid1('&'):
+        case opid1('~'):
             if (NotSameType(TYPE_FLOAT)) {
                 compile_error(ctx, "invalid types used in expression: cannot perform bit operations between types %s and %s",
                               type_name[exprs[0]->expression.vtype],
@@ -1346,6 +1347,21 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             asbinstore->keep_dest = true;
             out = (ast_expression*)asbinstore;
             break;
+
+        case opid2('~', 'P'):
+            if (exprs[0]->expression.vtype != TYPE_FLOAT) {
+                ast_type_to_string(exprs[0], ty1, sizeof(ty1));
+                compile_error(ast_ctx(exprs[0]), "invalid type for bit not: %s", ty1);
+                return false;
+            }
+
+            if (ast_istype(exprs[0], ast_value) && asvalue[0]->cvq == CV_CONST) {
+                compile_error(ast_ctx(exprs[0]), "assignment to constant `%s`", asvalue[0]->name);
+            }
+
+            out = (ast_expression*)ast_binary_new(ctx, INSTR_SUB_F, (ast_expression*)parser_const_float(parser, -1), exprs[0]);
+            break;
+            
     }
 #undef NotSameType