diff 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 diff
--- a/Jint.Runtime/VM/Box.cs	Fri Oct 25 15:52:16 2013 +0400
+++ b/Jint.Runtime/VM/Box.cs	Sun Oct 27 17:23:25 2013 +0400
@@ -1,56 +1,47 @@
-using System;
-
-namespace Jint.Runtime.VM
-{
-	public class Box<T>: BoxBase, IGetter<T>, ISetter<T>
-	{
-		T m_value;
-		IBinder<T> m_binder;
-
-		public Box(T value,IBinder<T> binder) {
-			m_value = value;
-			m_binder = binder;
-		}
-
-		public override bool IsReference {
-			get {
-				return true;
-			}
-		}
-
-        public override Type HoldingType
-        {
+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); }
-        }
-
-		#region IGetter implementation
-
-		public T Get ()
-		{
-			return m_value;
-		}
-
-		#endregion
-
-		#region ISetter implementation
-
-		public void Set (T value)
-		{
-			m_value = value;
-		}
-
-		#endregion
-
-		public override T2 Convert<T2> ()
-		{
-			if (m_binder == null)
-				throw new ArgumentNullException ();
-			return m_binder.Convert<T2> (m_value);
-		}
-
-		public override void Invoke(IBinaryOperation op, BoxBase arg2,Frame frame) {
-			op.Invoke (m_value, ((IGetter<T>)arg2).Get (), m_binder, frame);
-		}
-	}
-}
-
+        }
+
+        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;
+        }
+    }
+}