Mercurial > pub > Jint1
comparison Jint.Runtime/VM/Box.cs @ 4:1ae5b10f7a10
Code cleanup, minor refactoring
| author | cin |
|---|---|
| date | Sun, 27 Oct 2013 21:20:59 +0400 |
| parents | aced2ae9957f |
| children | cb13da6e3349 |
comparison
equal
deleted
inserted
replaced
| 3:aced2ae9957f | 4:1ae5b10f7a10 |
|---|---|
| 3 using System.Linq; | 3 using System.Linq; |
| 4 using System.Text; | 4 using System.Text; |
| 5 using Jint.Runtime.VM.OpCodes; | 5 using Jint.Runtime.VM.OpCodes; |
| 6 | 6 |
| 7 namespace Jint.Runtime.VM { | 7 namespace Jint.Runtime.VM { |
| 8 class Box<T>: IBox, IGettter<T>, ISetter<T> { | 8 class Box<T>: AbstractBox, IGettter<T>, ISetter<T> { |
| 9 | 9 |
| 10 public T holdingValue; | 10 public T holdingValue; |
| 11 object[] m_impl; | 11 object[] m_impl; |
| 12 RuntimeContext m_runtime; | 12 RuntimeContext m_runtime; |
| 13 | 13 |
| 14 public Box(T value, RuntimeContext runtime) { | 14 public Box(T value, RuntimeContext runtime): base(typeof(T)) { |
| 15 if (runtime == null) | 15 if (runtime == null) |
| 16 throw new ArgumentNullException("runtime"); | 16 throw new ArgumentNullException("runtime"); |
| 17 | 17 |
| 18 holdingValue = value; | 18 holdingValue = value; |
| 19 m_runtime = runtime; | 19 m_runtime = runtime; |
| 20 } | 20 } |
| 21 | 21 |
| 22 public object[] Impl { | 22 object[] Impl { |
| 23 get { | 23 get { |
| 24 if (m_impl == null) | 24 if (m_impl == null) |
| 25 m_impl = m_runtime.GetImpl(typeof(T)); | 25 m_impl = m_runtime.GetImpl(typeof(T)); |
| 26 return m_impl; | 26 return m_impl; |
| 27 } | 27 } |
| 28 } | |
| 29 | |
| 30 public Type HoldingType { | |
| 31 get { return typeof(T); } | |
| 32 } | |
| 33 | |
| 34 public void InvokeBinaryOperation(Codes code, int arg2, int dest, Frame frame) { | |
| 35 var op = (BinaryOperation<T>)Impl[(int)code]; | |
| 36 frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2))); | |
| 37 } | 28 } |
| 38 | 29 |
| 39 public T Get() { | 30 public T Get() { |
| 40 return holdingValue; | 31 return holdingValue; |
| 41 } | 32 } |
| 42 | 33 |
| 43 public void Set(T value) { | 34 public void Set(T value) { |
| 44 holdingValue = value; | 35 holdingValue = value; |
| 45 } | 36 } |
| 37 | |
| 38 public override void InvokeBinaryOperation(Codes code, int arg2, int dest, Frame frame) { | |
| 39 var op = (BinaryOperation<T>)Impl[(int)code]; | |
| 40 frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2))); | |
| 41 } | |
| 42 | |
| 43 public override void InvokeUnaryOperation(Codes code, int dest, Frame frame) { | |
| 44 var op = (UnaryOperation<T>)Impl[(int)code]; | |
| 45 frame.SetValue(dest, op(holdingValue)); | |
| 46 } | |
| 47 | |
| 48 public override void InvokeCompareOperation(int arg2, int dest, Frame frame) { | |
| 49 var op = (CompareOperation<T>)Impl[(int)Codes.Cmp]; | |
| 50 frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2))); | |
| 51 } | |
| 52 | |
| 53 public override void InvokeEqualityOperation(int arg2, int dest, Frame frame) { | |
| 54 var op = (EqualityOperation<T>)Impl[(int)Codes.Cmp]; | |
| 55 frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2))); | |
| 56 } | |
| 46 } | 57 } |
| 47 } | 58 } |
