Merge pull request #901 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Dynamic / Interpreter / Instructions / Instruction.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 using System;
17 using System.Collections.Generic;
18 using System.Diagnostics;
19 using System.Reflection;
20 using System.Runtime.CompilerServices;
21 using Microsoft.Scripting.Runtime;
22 using Microsoft.Scripting.Utils;
23
24 namespace Microsoft.Scripting.Interpreter {
25     public interface IInstructionProvider {
26         void AddInstructions(LightCompiler compiler);
27     }
28
29     public abstract partial class Instruction {
30         public virtual int ConsumedStack { get { return 0; } }
31         public virtual int ProducedStack { get { return 0; } }
32         public virtual int ConsumedContinuations { get { return 0; } }
33         public virtual int ProducedContinuations { get { return 0; } }
34
35         public int StackBalance {
36             get { return ProducedStack - ConsumedStack; }
37         }
38
39         public int ContinuationsBalance {
40             get { return ProducedContinuations - ConsumedContinuations; }
41         }
42
43         public abstract int Run(InterpretedFrame frame);
44
45         public virtual string InstructionName {
46             get { return GetType().Name.Replace("Instruction", ""); }
47         }
48
49         public override string ToString() {
50             return InstructionName + "()";
51         }
52
53         public virtual string ToDebugString(int instructionIndex, object cookie, Func<int, int> labelIndexer, IList<object> objects) {
54             return ToString();
55         }
56
57         public virtual object GetDebugCookie(LightCompiler compiler) {
58             return null;
59         }
60     }
61 }