From 23a2a19a784d52b9f0a4efe43cc737c8db34fc39 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 17 Oct 2016 15:52:29 +0200 Subject: [PATCH] - added handling for shift and bit operators. - added the '>>>' (unsigned shift) operator. Although, with unsigned numbers available, this is technically not really needed, DECORATE supports this so ZScript should, too, if only for the benefit of making conversion tools easier to handle. --- src/scripting/codegeneration/codegen.cpp | 4 ++-- src/scripting/zscript/zcc-parse.lemon | 7 ++++++- src/scripting/zscript/zcc_compile.cpp | 8 ++++++++ src/scripting/zscript/zcc_exprlist.h | 3 ++- src/scripting/zscript/zcc_parser.cpp | 1 + 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index fceee42c05..c68fc3723a 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -2430,9 +2430,9 @@ FxExpression *FxBinaryInt::Resolve(FCompileContext& ctx) CHECKRESOLVED(); if (!ResolveLR(ctx, false)) return NULL; - if (ValueType->GetRegType() == REGT_FLOAT /* lax */) + if (ValueType->GetRegType() == REGT_FLOAT && ctx.FromDecorate) { - // For DECORATE which allows floats here. + // For DECORATE which allows floats here. ZScript does not. if (left->ValueType->GetRegType() != REGT_INT) { left = new FxIntCast(left, ctx.FromDecorate); diff --git a/src/scripting/zscript/zcc-parse.lemon b/src/scripting/zscript/zcc-parse.lemon index 215670c825..1e10103a06 100644 --- a/src/scripting/zscript/zcc-parse.lemon +++ b/src/scripting/zscript/zcc-parse.lemon @@ -114,7 +114,7 @@ static void SetNodeLine(ZCC_TreeNode *name, int line) %left OR. /* Note that this is like the Ruby precedence for these */ %left XOR. /* three operators and not the C precedence, since */ %left AND. /* they are higher priority than the comparisons. */ -%left LSH RSH. +%left LSH RSH URSH. %left SUB ADD. %left MUL DIV MOD CROSSPROD DOTPROD. %left POW. @@ -1148,6 +1148,11 @@ expr(X) ::= expr(A) RSH expr(B). /* a >> b */ BINARY_EXPR(A,B,PEX_RightShift); X = expr2; } +expr(X) ::= expr(A) URSH expr(B). /* a >>> b */ +{ + BINARY_EXPR(A,B,PEX_URightShift); + X = expr2; +} expr(X) ::= expr(A) DOTDOT expr(B). /* a .. b */ { BINARY_EXPR(A,B,PEX_Concat); diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 6ec463490f..9d0ff5428d 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -2425,6 +2425,14 @@ FxExpression *ZCCCompiler::ConvertNode(ZCC_TreeNode *ast) case PEX_Pow: return new FxPow(left, right); + case PEX_LeftShift: + case PEX_RightShift: + case PEX_URightShift: + case PEX_BitAnd: + case PEX_BitOr: + case PEX_BitXor: + return new FxBinaryInt(op == PEX_LeftShift ? TK_LShift : op == PEX_RightShift ? TK_RShift : op == PEX_URightShift? TK_URShift : op == PEX_BitAnd ? '&' : op == PEX_BitOr ? '|' : '^', left, right); + default: I_Error("Binary operator %d not implemented yet", op); } diff --git a/src/scripting/zscript/zcc_exprlist.h b/src/scripting/zscript/zcc_exprlist.h index 2df687798a..46a1b9c690 100644 --- a/src/scripting/zscript/zcc_exprlist.h +++ b/src/scripting/zscript/zcc_exprlist.h @@ -32,6 +32,7 @@ xx(CrossProduct, ) xx(DotProduct, ) xx(LeftShift, ) xx(RightShift, ) +xx(URightShift, ) xx(Concat, ) xx(LT, ) @@ -42,7 +43,7 @@ xx(LTGTEQ, ) xx(Is, ) xx(EQEQ, ) -xx(NEQ, ) +xx(NEQ, ) xx(APREQ, ) xx(BitAnd, ) diff --git a/src/scripting/zscript/zcc_parser.cpp b/src/scripting/zscript/zcc_parser.cpp index c3f75b2b0a..cc8d187d31 100644 --- a/src/scripting/zscript/zcc_parser.cpp +++ b/src/scripting/zscript/zcc_parser.cpp @@ -95,6 +95,7 @@ static void InitTokenMap() TOKENDEF ('&', ZCC_AND); TOKENDEF (TK_LShift, ZCC_LSH); TOKENDEF (TK_RShift, ZCC_RSH); + TOKENDEF (TK_URShift, ZCC_URSH); TOKENDEF ('-', ZCC_SUB); TOKENDEF ('+', ZCC_ADD); TOKENDEF ('*', ZCC_MUL);