]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
for compile-time constants << and >> are now available
authorWolfgang Bumiller <blub@speed.at>
Thu, 10 Jan 2013 14:12:19 +0000 (15:12 +0100)
committerWolfgang Bumiller <blub@speed.at>
Thu, 10 Jan 2013 14:12:19 +0000 (15:12 +0100)
lexer.h
parser.c

diff --git a/lexer.h b/lexer.h
index 5d7b7f611bd0ef8166ed8e70ad432c7173ea6e3b..71ff198eed024b66c1932830d26148cd45e0d514 100644 (file)
--- a/lexer.h
+++ b/lexer.h
@@ -250,6 +250,9 @@ static const oper_info fte_operators[] = {
     { "+",   2, opid1('+'),         ASSOC_LEFT,  12, 0 },
     { "-",   2, opid1('-'),         ASSOC_LEFT,  12, 0 },
 
+    { "<<",  2, opid2('<','<'),     ASSOC_LEFT,  11, 0 },
+    { ">>",  2, opid2('>','>'),     ASSOC_LEFT,  11, 0 },
+
     { "<",   2, opid1('<'),         ASSOC_LEFT,  10, 0 },
     { ">",   2, opid1('>'),         ASSOC_LEFT,  10, 0 },
     { "<=",  2, opid2('<','='),     ASSOC_LEFT,  10, 0 },
index 3496437ad1e887ae440edf6e9ca701c156624d17..b15280b8d993ee9f33441463a700762f1ed460fb 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -929,14 +929,21 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                     exprs[0], exprs[1]);
             break;
         case opid1('^'):
-            parseerror(parser, "TODO: bitxor");
+            compile_error(ast_ctx(exprs[0]), "Not Yet Implemented: bit-xor via ^");
             return false;
 
         case opid2('<','<'):
         case opid2('>','>'):
+            if (CanConstFold(exprs[0], exprs[1]) && ! NotSameType(TYPE_FLOAT)) {
+                if (op->id == opid2('<','<'))
+                    out = (ast_expression*)parser_const_float(parser, (double)((int)(ConstF(0)) << (int)(ConstF(1))));
+                else
+                    out = (ast_expression*)parser_const_float(parser, (double)((int)(ConstF(0)) >> (int)(ConstF(1))));
+                break;
+            }
         case opid3('<','<','='):
         case opid3('>','>','='):
-            parseerror(parser, "TODO: shifts");
+            compile_error(ast_ctx(exprs[0]), "Not Yet Implemented: bit-shifts");
             return false;
 
         case opid2('|','|'):