private static void FoldExpression_Binary_BoolBool_Arithmetic( ref ES_AstExpression expr, SimpleBinaryExprType op, ES_AstBooleanConstantExpression lhs, ES_AstBooleanConstantExpression rhs ) { Debug.Assert(!op.IsComparison() && !op.IsBitShift()); bool finalValue; switch (op) { // Bit ops case SimpleBinaryExprType.BitAnd: finalValue = lhs.Value & rhs.Value; break; case SimpleBinaryExprType.BitOr: finalValue = lhs.Value | rhs.Value; break; case SimpleBinaryExprType.BitXor: finalValue = lhs.Value ^ rhs.Value; break; default: return; } expr = new ES_AstBooleanConstantExpression(finalValue, expr); }
private static void FoldExpression_Binary_BoolBool_Comp( ref ES_AstExpression expr, SimpleBinaryExprType op, ES_AstBooleanConstantExpression lhs, ES_AstBooleanConstantExpression rhs ) { Debug.Assert(op.IsComparison()); bool finalValue; switch (op) { case SimpleBinaryExprType.Equals: finalValue = lhs.Value == rhs.Value; break; case SimpleBinaryExprType.NotEquals: finalValue = lhs.Value != rhs.Value; break; default: return; } expr = new ES_AstBooleanConstantExpression(finalValue, expr); }
public static bool BinaryOpCompat( EchelonScriptEnvironment env, ES_TypeInfo *lhsType, ES_TypeInfo *rhsType, SimpleBinaryExprType exprType, out ES_TypeInfo *finalType, out bool isConst ) { finalType = env.TypeUnknownValue; if (lhsType->TypeTag == ES_TypeTag.UNKNOWN || rhsType->TypeTag == ES_TypeTag.UNKNOWN) { isConst = false; return(true); } if (lhsType->TypeTag == ES_TypeTag.Null || rhsType->TypeTag == ES_TypeTag.Null) { return(BinaryOpCompat_Null(env, lhsType, rhsType, exprType, out finalType, out isConst)); } return((lhsType->TypeTag, rhsType->TypeTag) switch { (ES_TypeTag.Int, ES_TypeTag.Int) => BinaryOpCompat_IntInt(env, lhsType, rhsType, exprType, out finalType, out isConst), (ES_TypeTag.Bool, ES_TypeTag.Bool) => BinaryOpCompat_BoolBool(env, lhsType, rhsType, exprType, out finalType, out isConst), (ES_TypeTag.Float, ES_TypeTag.Float) => BinaryOpCompat_FloatFloat(env, lhsType, rhsType, exprType, out finalType, out isConst), (ES_TypeTag.Float, ES_TypeTag.Int) => BinaryOpCompat_FloatInt(env, lhsType, rhsType, exprType, out finalType, out isConst), (ES_TypeTag.Reference, ES_TypeTag.Reference) => BinaryOpCompat_RefRef(env, lhsType, rhsType, exprType, out finalType, out isConst), (ES_TypeTag.Array, ES_TypeTag.Array) => BinaryOpCompat_ArrayArray(env, lhsType, rhsType, exprType, out finalType, out isConst), _ => isConst = false, });