Mercurial > pub > Jint1
view Jint.Runtime/VM/Box.cs @ 3:aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
author | cin |
---|---|
date | Sun, 27 Oct 2013 17:23:25 +0400 |
parents | e113095f1de0 |
children | 1ae5b10f7a10 |
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>: IBox, IGettter<T>, ISetter<T> { public T holdingValue; object[] m_impl; RuntimeContext m_runtime; public Box(T value, RuntimeContext runtime) { if (runtime == null) throw new ArgumentNullException("runtime"); holdingValue = value; m_runtime = runtime; } public object[] Impl { get { if (m_impl == null) m_impl = m_runtime.GetImpl(typeof(T)); return m_impl; } } 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; } public void Set(T value) { holdingValue = value; } } }