Mercurial > pub > Jint1
view 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 source
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Jint.Runtime.VM.OpCodes; namespace Jint.Runtime.VM { class Box<T>: AbstractBox, IGettter<T>, ISetter<T> { public T holdingValue; object[] m_impl; RuntimeContext m_runtime; public Box(T value, RuntimeContext runtime): base(typeof(T)) { if (runtime == null) throw new ArgumentNullException("runtime"); holdingValue = value; m_runtime = runtime; } object[] Impl { get { if (m_impl == null) m_impl = m_runtime.GetImpl(typeof(T)); return m_impl; } } public T Get() { return holdingValue; } 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))); } } }