- 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.
This commit is contained in:
Christoph Oelckers 2016-10-17 15:52:29 +02:00
parent 938ab4ca70
commit 23a2a19a78
5 changed files with 19 additions and 4 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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, )

View File

@ -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);