Mercurial > pub > Jint1
diff 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 |
line wrap: on
line diff
--- a/Jint.Runtime/VM/Box.cs Sun Oct 27 17:23:25 2013 +0400 +++ b/Jint.Runtime/VM/Box.cs Sun Oct 27 21:20:59 2013 +0400 @@ -5,13 +5,13 @@ using Jint.Runtime.VM.OpCodes; namespace Jint.Runtime.VM { - class Box<T>: IBox, IGettter<T>, ISetter<T> { + class Box<T>: AbstractBox, IGettter<T>, ISetter<T> { public T holdingValue; object[] m_impl; RuntimeContext m_runtime; - public Box(T value, RuntimeContext runtime) { + public Box(T value, RuntimeContext runtime): base(typeof(T)) { if (runtime == null) throw new ArgumentNullException("runtime"); @@ -19,7 +19,7 @@ m_runtime = runtime; } - public object[] Impl { + object[] Impl { get { if (m_impl == null) m_impl = m_runtime.GetImpl(typeof(T)); @@ -27,15 +27,6 @@ } } - public Type HoldingType { - get { return typeof(T); } - } - - public void InvokeBinaryOperation(Codes code, int arg2, int dest, Frame frame) { - var op = (BinaryOperation<T>)Impl[(int)code]; - frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2))); - } - public T Get() { return holdingValue; } @@ -43,5 +34,25 @@ public void Set(T value) { holdingValue = value; } + + public override void InvokeBinaryOperation(Codes code, int arg2, int dest, Frame frame) { + var op = (BinaryOperation<T>)Impl[(int)code]; + frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2))); + } + + public override void InvokeUnaryOperation(Codes code, int dest, Frame frame) { + var op = (UnaryOperation<T>)Impl[(int)code]; + frame.SetValue(dest, op(holdingValue)); + } + + public override void InvokeCompareOperation(int arg2, int dest, Frame frame) { + var op = (CompareOperation<T>)Impl[(int)Codes.Cmp]; + frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2))); + } + + public override void InvokeEqualityOperation(int arg2, int dest, Frame frame) { + var op = (EqualityOperation<T>)Impl[(int)Codes.Cmp]; + frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2))); + } } }