Exemplo n.º 1
0
        public override LllType TryInferType(CIntermediateLang cil)
        {
            var lhsTy = Lhs.TryInferType(cil);
            var rhsTy = Rhs.TryInferType(cil);

            if (lhsTy is LllIntegerType && rhsTy is LllIntegerType)
            {
                if (Rhs is AstNumber)
                {
                    return(lhsTy);
                }
                if (Lhs is AstNumber)
                {
                    return(rhsTy);
                }
            }
            if (lhsTy.Equals(rhsTy))
            {
                return(lhsTy);
            }
            if (rhsTy.TryCast(lhsTy))
            {
                return(lhsTy);
            }
            if (lhsTy.TryCast(rhsTy))
            {
                return(rhsTy);
            }
            // not primitive, make a call to lhs.__op__(rhs);
            var opAlias = _binOpInfo[Op].CallAlias;
            var member  = new AstMemberAccess(SourceInfo, Lhs, opAlias);
            var opCall  = new AstCall(SourceInfo, member, new List <AstExpression> {
                Rhs
            });

            return(opCall.TryInferType(cil));
        }
Exemplo n.º 2
0
        public override CILExpression ToCILExpression(CIntermediateLang cil)
        {
            if (IsConditionalOp())
            {
                return(ToCILCondition(cil));
            }
            var lhsTy = Lhs.TryInferType(cil);
            var lhs   = lhsTy.IsAReference
                ? new CILDereference(Lhs.SourceInfo, Lhs.ToCILExpression(cil))
                : Lhs.ToCILExpression(cil);


            var rhsTy = Rhs.TryInferType(cil);
            var rhs   = rhsTy.IsAReference
                ? new CILDereference(Rhs.SourceInfo, Rhs.ToCILExpression(cil))
                : Rhs.ToCILExpression(cil);

            // primitives, just use the builtin operators
            if (lhsTy.IsPrimitive && rhsTy.IsPrimitive)
            {
                return(new CILBinaryOp(
                           SourceInfo,
                           lhs,
                           _binOpInfo[Op].CILOpType,
                           rhs));
            }

            // not primitive, make a call to lhs.__op__(rhs);
            var opAlias = _binOpInfo[Op].CallAlias;
            var member  = new AstMemberAccess(SourceInfo, Lhs, opAlias);
            var opCall  = new AstCall(SourceInfo, member, new List <AstExpression> {
                Rhs
            });

            return(opCall.ToCILExpression(cil));
        }
Exemplo n.º 3
0
        private AstCall CreateCallAst()
        {
            var membAccess = new AstMemberAccess(SourceInfo, From, "__index__");

            return(new AstCall(SourceInfo, membAccess, Subscript));
        }