Merge pull request #900 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Dynamic / Interpreter / Instructions / DynamicSplatInstruction.cs
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
17 using System;
18 using System.Collections.Generic;
19 using System.Runtime.CompilerServices;
20 using System.Reflection;
21
22 using Microsoft.Scripting.Utils;
23 using Microsoft.Scripting.Ast;
24 using Microsoft.Scripting.Runtime;
25
26 namespace 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 }