1 /* ****************************************************************************
3 * Copyright (c) Microsoft Corporation.
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.
11 * You must not remove this notice, or any other, from this software.
14 * ***************************************************************************/
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;
24 namespace Microsoft.Scripting.Interpreter {
25 internal sealed class LoadStaticFieldInstruction : Instruction {
26 private readonly FieldInfo _field;
28 public LoadStaticFieldInstruction(FieldInfo field) {
29 Debug.Assert(field.IsStatic);
33 public override int ProducedStack { get { return 1; } }
35 public override int Run(InterpretedFrame frame) {
36 frame.Push(_field.GetValue(null));
41 internal sealed class LoadFieldInstruction : Instruction {
42 private readonly FieldInfo _field;
44 public LoadFieldInstruction(FieldInfo field) {
45 Assert.NotNull(field);
49 public override int ConsumedStack { get { return 1; } }
50 public override int ProducedStack { get { return 1; } }
52 public override int Run(InterpretedFrame frame) {
53 frame.Push(_field.GetValue(frame.Pop()));
58 internal sealed class StoreFieldInstruction : Instruction {
59 private readonly FieldInfo _field;
61 public StoreFieldInstruction(FieldInfo field) {
62 Assert.NotNull(field);
66 public override int ConsumedStack { get { return 2; } }
67 public override int ProducedStack { get { return 0; } }
69 public override int Run(InterpretedFrame frame) {
70 object value = frame.Pop();
71 object self = frame.Pop();
72 _field.SetValue(self, value);
77 internal sealed class StoreStaticFieldInstruction : Instruction {
78 private readonly FieldInfo _field;
80 public StoreStaticFieldInstruction(FieldInfo field) {
81 Assert.NotNull(field);
85 public override int ConsumedStack { get { return 1; } }
86 public override int ProducedStack { get { return 0; } }
88 public override int Run(InterpretedFrame frame) {
89 object value = frame.Pop();
90 _field.SetValue(null, value);