示例#1
0
    def v_ArrayExpression(self, node, ctx=None):
        assert isinstance(node, ast.ArrayExpression)
        node.GetExpression().AcceptVisitor(self, ctx)

        # We allow Integer or UnsignedInteger as the index
        exprType = node.GetExpression().GetType()
        if exprType != types.Integer () and exprType != types.UnsignedInteger():
            # Non-integer means it must be float, which is signed -- cast to
            # integer
            assert isinstance(exprType, types.Float)
            node.SetExpression (ast.CastExpression (node.GetExpression (),
                types.Integer (), True))
示例#2
0
文件: test_types.py 项目: Anteru/nsl
    def testResolveBinaryExpressionScalar(self):
        it = types.Integer()
        ft = types.Float()

        rt = types.ResolveBinaryExpressionType(op.Operation.ADD, it, ft)

        assert rt.GetReturnType() == ft
示例#3
0
文件: test_types.py 项目: Anteru/nsl
    def testResolveBinaryExpressionTypeMVPromotesRightSide(self):
        m44 = types.MatrixType(types.Float(), 4, 4)
        f4 = types.VectorType(types.Integer(), 4)

        r = types.ResolveBinaryExpressionType(op.Operation.MUL, m44, f4)

        assert r.GetOperandType(1) == types.VectorType(types.Float(), 4)
示例#4
0
文件: test_types.py 项目: Anteru/nsl
    def testResolveBinaryExpressionVectorScalarDiv(self):
        vt = types.VectorType(types.Float(), 4)
        it = types.Integer()

        rt = types.ResolveBinaryExpressionType(op.Operation.DIV, vt, it)

        assert rt.GetReturnType() == vt
示例#5
0
文件: test_types.py 项目: Anteru/nsl
    def testResolveBinaryExpressionForScalarVectorPromotes(self):
        left = types.Integer()
        right = types.VectorType(types.Float(), 4)

        t = types.ResolveBinaryExpressionType(op.Operation.MUL, left, right)

        assert t.GetOperandType(0) == types.Float()
        assert t.GetOperandType(1) == right
示例#6
0
文件: test_parser.py 项目: Anteru/nsl
    def testParseBinaryExpression(self, ExprParser):
        expr = '23 + 48 * 18'
        exprNode = ExprParser.Parse(expr)

        assert isinstance(exprNode, ast.BinaryExpression)
        l0, r0 = exprNode.GetLeft(), exprNode.GetRight()
        assert exprNode.GetOperation() == op.Operation.ADD
        assert isinstance(l0, ast.LiteralExpression)
        assert isinstance(r0, ast.BinaryExpression)

        l1, r1 = r0.GetLeft(), r0.GetRight()
        assert r0.GetOperation() == op.Operation.MUL
        assert isinstance(l1, ast.LiteralExpression)
        assert isinstance(r1, ast.LiteralExpression)

        assert l0.GetValue() == 23
        assert l0.GetType() == types.Integer()
        assert l1.GetValue() == 48
        assert l1.GetType() == types.Integer()
        assert r1.GetValue() == 18
        assert r1.GetType() == types.Integer()
示例#7
0
    def _ValidateArrayExpression(self, expr):
        rhsType = expr.GetExpression().GetType()

        if rhsType != types.Integer() and rhsType != types.UnsignedInteger():
            self.valid = False
            Errors.ERROR_ARRAY_ACCESS_WITH_NONINTEGER.Raise(rhsType)
示例#8
0
文件: test_types.py 项目: Anteru/nsl
    def testIsCompatibleFloat2Int2(self):
        f2 = types.VectorType(types.Float(), 2)
        i2 = types.VectorType(types.Integer(), 2)

        assert types.IsCompatible(f2, i2)
示例#9
0
文件: test_types.py 项目: Anteru/nsl
    def testIsCompatibleIntInt1(self):
        i = types.Integer()
        i1 = types.VectorType(types.Integer(), 1)

        assert types.IsCompatible(i, i1)
示例#10
0
文件: test_types.py 项目: Anteru/nsl
    def testIsCompatibleFloat2Int4(self):
        f2 = types.VectorType(types.Float(), 2)
        i4 = types.VectorType(types.Integer(), 4)

        assert not types.IsCompatible(f2, i4)