diff Jint.Runtime/VM/Frame.cs @ 0:e113095f1de0

initial commit, proof of concept
author cin
date Wed, 23 Oct 2013 13:24:57 +0400
parents
children aced2ae9957f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Jint.Runtime/VM/Frame.cs	Wed Oct 23 13:24:57 2013 +0400
@@ -0,0 +1,59 @@
+using System;
+
+namespace Jint.Runtime.VM
+{
+	public class Frame
+	{
+		BoxBase[] m_data;
+		RuntimeContext m_runtimeContext;
+
+		public Frame (int size, RuntimeContext runtime)
+		{
+			if (size < 0)
+				throw new ArgumentOutOfRangeException ("size");
+			if (runtime == null)
+				throw new ArgumentNullException ("runtime");
+
+			m_data = new BoxBase[size];
+			m_runtimeContext = runtime;
+		}
+
+		public RuntimeContext Runtime {
+			get { return m_runtimeContext; }
+		}
+
+		public T Get<T> (int index)
+		{
+			var bbox = m_data [index];
+
+			if (bbox == null)
+				return default(T);
+
+			var box = bbox as IGetter<T>;
+			if (box != null)
+				return box.Get();
+			else
+				return bbox.Convert<T>();
+		}
+
+		public void Set<T> (int index, T value)
+		{
+			var bbox = m_data [index];
+			var box = bbox as ISetter<T>;
+			if (box != null)
+				box.Set (value);
+			else
+				m_data [index] = m_runtimeContext.BoxValue(value);
+		}
+
+		public BoxBase GetBox(int index) {
+			return m_data[index];
+		}
+
+		public void SetBox(int index, BoxBase box) {
+			m_data [index] = box;
+		}
+
+	}
+}
+