Exemplo n.º 1
0
        public override void VisitLoadParenthesized(LoadParenthesized node)
        {
            Contract.Assert(node.Targets.Length == 1);
            Contract.Assert(node.Subject.StaticRepr.IsArray);

            // TODO: Handle the zero-argument case specially
            if (node.Arguments.Length == 1 && node.Arguments[0].IsColon)
            {
                // foo(:), linearization
                EmitCall(node.Targets, pseudoBuiltins.Lookup("Linearize", node.Subject.StaticRepr), node.Subject);
                return;
            }

            var argumentReprsBuilder = new ImmutableArray <MRepr> .Builder(node.Arguments.Length + 1);

            argumentReprsBuilder[0] = node.Subject.StaticRepr;
            for (int i = 0; i < node.Arguments.Length; ++i)
            {
                var argument = node.Arguments[i];
                argumentReprsBuilder[1 + i] = argument.IsColon
                                        ? new MRepr(MClass.Double, MStructuralClass.IntegralRange)
                                        : argument.Variable.StaticRepr;
            }
            var argumentReprs = argumentReprsBuilder.Complete();

            var function = pseudoBuiltins.Lookup("ArrayGet", argumentReprs);

            using (BeginEmitStore(node.Targets[0]))
            {
                EmitLoadAndConvert(node.Subject, function.Signature.Inputs[0]);

                for (int i = 0; i < node.Arguments.Length; ++i)
                {
                    var argument     = node.Arguments[i];
                    var expectedRepr = function.Signature.Inputs[1 + i];
                    if (argument.IsColon)
                    {
                        EmitColonRange(node.Subject, i);
                        EmitConvert(new MRepr(MClass.Double, MStructuralClass.IntegralRange), expectedRepr);
                    }
                    else
                    {
                        EmitLoadAndConvert(argument.Variable, expectedRepr);
                    }
                }

                cil.Invoke(function.Method);
                EmitConvert(function.Signature.Outputs[0], node.Targets[0].StaticRepr);
            }
        }