コード例 #1
0
ファイル: MethodCall.cs プロジェクト: aslakhellesoy/ironruby
        // arguments: complex arguments (expressions, maplets, splat, block) 
        // singleArgument: siple argument (complex are not used)
        // assignmentRhsArgument: rhs of the assignment: target.method=(rhs)
        internal static MSA.Expression/*!*/ TransformRead(Expression/*!*/ node, AstGenerator/*!*/ gen, bool hasImplicitSelf, 
            string/*!*/ methodName, MSA.Expression/*!*/ transformedTarget,
            Arguments arguments, Block block, MSA.Expression singleArgument, MSA.Expression assignmentRhsArgument) {

            Debug.Assert(assignmentRhsArgument == null || block == null, "Block not allowed in assignment");
            Debug.Assert(singleArgument == null || arguments == null && assignmentRhsArgument == null);
            Assert.NotNull(gen, transformedTarget);
            Assert.NotEmpty(methodName);

            // Pass args in this order:
            // 1. instance
            // 2. block (if present)
            // 3. passed args: normal args, maplets, array
            // 4. RHS of assignment (if present)

            CallBuilder callBuilder = new CallBuilder(gen);
            callBuilder.Instance = transformedTarget;
            
            MSA.Expression blockArgVariable = null;
            MSA.Expression transformedBlock = null;

            if (block != null) {
                blockArgVariable = gen.CurrentScope.DefineHiddenVariable("#block-def", typeof(Proc));
                transformedBlock = block.Transform(gen);
                callBuilder.Block = blockArgVariable;
            }

            if (arguments != null) {
                arguments.TransformToCall(gen, callBuilder);
            } else if (singleArgument != null) {
                callBuilder.Add(singleArgument);
            }

            MSA.Expression rhsVariable = null;
            if (assignmentRhsArgument != null) {
                rhsVariable = gen.CurrentScope.DefineHiddenVariable("#rhs", assignmentRhsArgument.Type);
                callBuilder.RhsArgument = Ast.Assign(rhsVariable, assignmentRhsArgument);
            }

            var dynamicSite = callBuilder.MakeCallAction(methodName, hasImplicitSelf);
            gen.TraceCallSite(node, dynamicSite);

            MSA.Expression result = gen.DebugMark(dynamicSite, methodName);

            if (block != null) {
                result = gen.DebugMark(MakeCallWithBlockRetryable(gen, result, blockArgVariable, transformedBlock, block.IsDefinition),
                    "#RB: method call with a block ('" + methodName + "')");
            }

            if (assignmentRhsArgument != null) {
                result = AstFactory.Block(result, rhsVariable);
            }

            return result;
        }
コード例 #2
0
ファイル: MethodCall.cs プロジェクト: gaybro8777/ironruby
        // arguments: complex arguments (expressions, maplets, splat, block)
        // singleArgument: siple argument (complex are not used)
        // assignmentRhsArgument: rhs of the assignment: target.method=(rhs)
        internal static MSA.Expression /*!*/ TransformRead(Expression /*!*/ node, AstGenerator /*!*/ gen, bool hasImplicitSelf,
                                                           string /*!*/ methodName, MSA.Expression /*!*/ transformedTarget,
                                                           Arguments arguments, Block block, MSA.Expression singleArgument, MSA.Expression assignmentRhsArgument)
        {
            Debug.Assert(assignmentRhsArgument == null || block == null, "Block not allowed in assignment");
            Debug.Assert(singleArgument == null || arguments == null && assignmentRhsArgument == null);
            Assert.NotNull(gen, transformedTarget);
            Assert.NotEmpty(methodName);

            // Pass args in this order:
            // 1. instance
            // 2. block (if present)
            // 3. passed args: normal args, maplets, array
            // 4. RHS of assignment (if present)

            CallBuilder callBuilder = new CallBuilder(gen);

            callBuilder.Instance = transformedTarget;

            MSA.Expression blockArgVariable = null;
            MSA.Expression transformedBlock = null;

            if (block != null)
            {
                blockArgVariable  = gen.CurrentScope.DefineHiddenVariable("#block-def", typeof(Proc));
                transformedBlock  = block.Transform(gen);
                callBuilder.Block = blockArgVariable;
            }

            if (arguments != null)
            {
                arguments.TransformToCall(gen, callBuilder);
            }
            else if (singleArgument != null)
            {
                callBuilder.Add(singleArgument);
            }

            MSA.Expression rhsVariable = null;
            if (assignmentRhsArgument != null)
            {
                rhsVariable             = gen.CurrentScope.DefineHiddenVariable("#rhs", assignmentRhsArgument.Type);
                callBuilder.RhsArgument = Ast.Assign(rhsVariable, assignmentRhsArgument);
            }

            var dynamicSite = callBuilder.MakeCallAction(methodName, hasImplicitSelf);

            gen.TraceCallSite(node, dynamicSite);

            MSA.Expression result = gen.DebugMark(dynamicSite, methodName);

            if (block != null)
            {
                result = gen.DebugMark(MakeCallWithBlockRetryable(gen, result, blockArgVariable, transformedBlock, block.IsDefinition),
                                       "#RB: method call with a block ('" + methodName + "')");
            }

            if (assignmentRhsArgument != null)
            {
                result = AstFactory.Block(result, rhsVariable);
            }

            return(result);
        }