PageRenderTime 26ms CodeModel.GetById 18ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_Main/Runtime/Microsoft.Dynamic/Interpreter/Instructions/DynamicSplatInstruction.cs

#
C# | 55 lines | 29 code | 9 blank | 17 comment | 0 complexity | 748ef2f2f2350598ebd4fe359a833c12 MD5 | raw file
 1/* ****************************************************************************
 2 *
 3 * Copyright (c) Microsoft Corporation. 
 4 *
 5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
 6 * copy of the license can be found in the License.html file at the root of this distribution. If 
 7 * you cannot locate the  Apache License, Version 2.0, please send an email to 
 8 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 9 * by the terms of the Apache License, Version 2.0.
10 *
11 * You must not remove this notice, or any other, from this software.
12 *
13 *
14 * ***************************************************************************/
15
16
17using System;
18using System.Collections.Generic;
19using System.Runtime.CompilerServices;
20using System.Reflection;
21
22using Microsoft.Scripting.Utils;
23using Microsoft.Scripting.Ast;
24using Microsoft.Scripting.Runtime;
25
26namespace Microsoft.Scripting.Interpreter {
27    /// <summary>
28    /// Implements dynamic call site with many arguments. Wraps the arguments into <see cref="ArgumentArray"/>.
29    /// </summary>
30    internal sealed partial class DynamicSplatInstruction : Instruction {
31        private readonly CallSite<Func<CallSite, ArgumentArray, object>> _site;
32        private readonly int _argumentCount;
33
34        internal DynamicSplatInstruction(int argumentCount, CallSite<Func<CallSite, ArgumentArray, object>> site) {
35            _site = site;
36            _argumentCount = argumentCount;
37        }
38
39        public override int ProducedStack { get { return 1; } }
40        public override int ConsumedStack { get { return _argumentCount; } }
41
42        public override int Run(InterpretedFrame frame) {
43            int first = frame.StackIndex - _argumentCount;
44            object ret = _site.Target(_site, new ArgumentArray(frame.Data, first, _argumentCount));
45            frame.Data[first] = ret;
46            frame.StackIndex = first + 1;
47
48            return 1;
49        }
50
51        public override string ToString() {
52            return "DynamicSplatInstruction(" + _site + ")";
53        }
54    }
55}