From: Wolfgang Bumiller Date: Thu, 10 Jan 2013 14:12:19 +0000 (+0100) Subject: for compile-time constants << and >> are now available X-Git-Tag: before-library~331 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=428453a132f4099d1ff8f61598166bff9d1d3bb4;p=xonotic%2Fgmqcc.git for compile-time constants << and >> are now available --- diff --git a/lexer.h b/lexer.h index 5d7b7f6..71ff198 100644 --- 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 }, diff --git a/parser.c b/parser.c index 3496437..b15280b 100644 --- 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('|','|'):