changeset 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 4aed85a1f558
children 1ae5b10f7a10
files Jint.Runtime/AssemblyInfo.cs Jint.Runtime/ClassDescriptor.cs Jint.Runtime/ClassTransition.cs Jint.Runtime/Jint.Runtime.csproj Jint.Runtime/Jint.Runtime.csproj.user Jint.Runtime/JsObject.cs Jint.Runtime/Main.cs Jint.Runtime/PropertyDescriptor.cs Jint.Runtime/PropertyFlags.cs Jint.Runtime/TransitionAction.cs Jint.Runtime/VM/Box.cs Jint.Runtime/VM/BoxBase.cs Jint.Runtime/VM/DummyConverter.cs Jint.Runtime/VM/Frame.cs Jint.Runtime/VM/IBinder.cs Jint.Runtime/VM/IBox.cs Jint.Runtime/VM/IConverter.cs Jint.Runtime/VM/IGetter.cs Jint.Runtime/VM/IGettter.cs Jint.Runtime/VM/IInstruction.cs Jint.Runtime/VM/IReference.cs Jint.Runtime/VM/ISetter.cs Jint.Runtime/VM/IValueHolder.cs Jint.Runtime/VM/IntegerBinder.cs Jint.Runtime/VM/Machine.cs Jint.Runtime/VM/OpCodes/Add.cs Jint.Runtime/VM/OpCodes/BinaryOp.cs Jint.Runtime/VM/OpCodes/BinaryOperation.cs Jint.Runtime/VM/OpCodes/Codes.cs Jint.Runtime/VM/OpCodes/IBinaryOperation.cs Jint.Runtime/VM/OpCodes/IBinaryOperation2.cs Jint.Runtime/VM/OpCodes/IOpCode.cs Jint.Runtime/VM/OpCodes/IOperation.cs Jint.Runtime/VM/OpCodes/Instruction.cs Jint.Runtime/VM/OpCodes/Loop.cs Jint.Runtime/VM/OperationDelegates.cs Jint.Runtime/VM/RuntimeContext.cs Jint.Runtime/VM2/Box.cs Jint.Runtime/VM2/Frame.cs Jint.Runtime/VM2/Instruction.cs Jint.Runtime/VM2/IntegerBinder.cs Jint.Runtime/VM2/Machine.cs Jint.Runtime/VM2/OpCodes/Add.cs Jint.Runtime/VM2/OpCodes/Codes.cs Jint.Runtime/VM2/OpCodes/Operation.cs Jint.Runtime/VM2/RuntimeContext.cs Jint.sln Jint.suo
diffstat 48 files changed, 382 insertions(+), 825 deletions(-) [+]
line wrap: on
line diff
--- a/Jint.Runtime/AssemblyInfo.cs	Fri Oct 25 15:52:16 2013 +0400
+++ b/Jint.Runtime/AssemblyInfo.cs	Sun Oct 27 17:23:25 2013 +0400
@@ -9,7 +9,7 @@
 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyCompany("")]
 [assembly: AssemblyProduct("")]
-[assembly: AssemblyCopyright("sergey")]
+[assembly: AssemblyCopyright("")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]
 
--- a/Jint.Runtime/ClassDescriptor.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-
-namespace Jint.Runtime
-{
-	public class ClassDescriptor
-	{
-		int m_classId;
-		
-		Dictionary<string,PropertyDescriptor> m_props = new Dictionary<string, PropertyDescriptor>();
-		
-		
-		public int ClassId {
-			get { return m_classId; }
-		}
-		
-		public ClassDescriptor (int classId)
-		{
-			m_classId = classId;
-		}
-		
-		public bool TryGet (string name, out PropertyDescriptor descriptor)
-		{
-			return m_props.TryGetValue (name, out descriptor);
-		}
-		
-		public void DefineProperty(string name, PropertyDescriptor descriptor) {
-			
-		}
-	}
-}
-
--- a/Jint.Runtime/ClassTransition.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-using System;
-namespace Jint.Runtime
-{
-	public struct ClassTransition
-	{
-		public int classId;
-		
-		public TransitionAction action;
-		
-		public string propertyName;
-	}
-}
-
--- a/Jint.Runtime/Jint.Runtime.csproj	Fri Oct 25 15:52:16 2013 +0400
+++ b/Jint.Runtime/Jint.Runtime.csproj	Sun Oct 27 17:23:25 2013 +0400
@@ -1,75 +1,60 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
-    <ProductVersion>10.0.0</ProductVersion>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectGuid>{F3FDE0D1-748F-4DFE-9C1C-D17D7FD4E642}</ProjectGuid>
-    <OutputType>Exe</OutputType>
-    <RootNamespace>Jint.Runtime</RootNamespace>
-    <AssemblyName>Jint.Runtime</AssemblyName>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
-    <DebugSymbols>True</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>False</Optimize>
-    <OutputPath>bin\Debug</OutputPath>
-    <DefineConstants>DEBUG;</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-    <PlatformTarget>x86</PlatformTarget>
-    <Externalconsole>True</Externalconsole>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
-    <DebugType>none</DebugType>
-    <Optimize>True</Optimize>
-    <OutputPath>bin\Release</OutputPath>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-    <PlatformTarget>x86</PlatformTarget>
-    <Externalconsole>True</Externalconsole>
-  </PropertyGroup>
-  <ItemGroup>
-    <Reference Include="System" />
-  </ItemGroup>
-  <ItemGroup>
-    <Compile Include="Main.cs" />
-    <Compile Include="AssemblyInfo.cs" />
-    <Compile Include="VM\Box.cs" />
-    <Compile Include="VM\BoxBase.cs" />
-    <Compile Include="VM\Frame.cs" />
-    <Compile Include="VM\OpCodes\Add.cs" />
-    <Compile Include="VM\ISetter.cs" />
-    <Compile Include="VM\IGetter.cs" />
-    <Compile Include="VM\IBinder.cs" />
-    <Compile Include="VM\IntegerBinder.cs" />
-    <Compile Include="VM\RuntimeContext.cs" />
-    <Compile Include="VM\OpCodes\IOperation.cs" />
-    <Compile Include="VM\OpCodes\IBinaryOperation.cs" />
-    <Compile Include="VM\OpCodes\BinaryOperation.cs" />
-    <Compile Include="VM\IReference.cs" />
-    <Compile Include="VM\OpCodes\Codes.cs" />
-    <Compile Include="VM2\Instruction.cs" />
-    <Compile Include="VM2\OpCodes\Codes.cs" />
-    <Compile Include="VM2\Box.cs" />
-    <Compile Include="VM2\OpCodes\Operation.cs" />
-    <Compile Include="VM2\IntegerBinder.cs" />
-    <Compile Include="VM2\Machine.cs" />
-    <Compile Include="VM2\RuntimeContext.cs" />
-  </ItemGroup>
-  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
-  <ProjectExtensions>
-    <MonoDevelop>
-      <Properties>
-        <Deployment.LinuxDeployData generateScript="False" />
-      </Properties>
-    </MonoDevelop>
-  </ProjectExtensions>
-  <ItemGroup>
-    <Folder Include="VM\" />
-    <Folder Include="VM\OpCodes\" />
-    <Folder Include="VM2\" />
-    <Folder Include="VM2\OpCodes\" />
-  </ItemGroup>
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProductVersion>10.0.0</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{F3FDE0D1-748F-4DFE-9C1C-D17D7FD4E642}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>Jint.Runtime</RootNamespace>
+    <AssemblyName>Jint.Runtime</AssemblyName>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>True</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>False</Optimize>
+    <OutputPath>bin\Debug</OutputPath>
+    <DefineConstants>DEBUG;</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <PlatformTarget>x86</PlatformTarget>
+    <Externalconsole>True</Externalconsole>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <DebugType>none</DebugType>
+    <Optimize>True</Optimize>
+    <OutputPath>bin\Release</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <PlatformTarget>x86</PlatformTarget>
+    <Externalconsole>True</Externalconsole>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Main.cs" />
+    <Compile Include="AssemblyInfo.cs" />
+    <Compile Include="VM\Box.cs" />
+    <Compile Include="VM\Frame.cs" />
+    <Compile Include="VM\IBox.cs" />
+    <Compile Include="VM\IGettter.cs" />
+    <Compile Include="VM\IInstruction.cs" />
+    <Compile Include="VM\ISetter.cs" />
+    <Compile Include="VM\Machine.cs" />
+    <Compile Include="VM\OpCodes\BinaryOp.cs" />
+    <Compile Include="VM\OpCodes\Codes.cs" />
+    <Compile Include="VM\OperationDelegates.cs" />
+    <Compile Include="VM\RuntimeContext.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+  <ProjectExtensions>
+    <MonoDevelop>
+      <Properties>
+        <Deployment.LinuxDeployData generateScript="False" />
+      </Properties>
+    </MonoDevelop>
+  </ProjectExtensions>
+  <ItemGroup />
 </Project>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Jint.Runtime/Jint.Runtime.csproj.user	Sun Oct 27 17:23:25 2013 +0400
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <ProjectView>ProjectFiles</ProjectView>
+  </PropertyGroup>
+</Project>
\ No newline at end of file
--- a/Jint.Runtime/JsObject.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-
-namespace Jint.Runtime
-{
-	public class JsObject
-	{
-		ClassDescriptor m_classDescriptor;
-		List<object> m_data;
-		
-		public JsObject ()
-		{
-		}
-		
-		public object Get (string name)
-		{
-			PropertyDescriptor descriptor;
-			if (m_classDescriptor.TryGet (name, out descriptor))
-				return m_data.Count <= descriptor.index ? null : m_data [descriptor.index];
-			else
-				return null;			
-		}
-	}
-}
-
--- a/Jint.Runtime/Main.cs	Fri Oct 25 15:52:16 2013 +0400
+++ b/Jint.Runtime/Main.cs	Sun Oct 27 17:23:25 2013 +0400
@@ -1,63 +1,66 @@
 using System;
-using Jint.Runtime.VM.OpCodes;
+using Jint.Runtime.VM;
 
 namespace Jint.Runtime
 {
     using VM;
-    using System.IO;
+    using System.IO;
+    using Jint.Runtime.VM.OpCodes;
     class MainClass
     {
         public static void Main(string[] args)
-        {
-			var runtime = new RuntimeContext ();
-
-			var frame = new Frame (3,runtime);
-
-			frame.Set (0, 0);
-			frame.Set (1, 1);
-
-			var op = new Add (0,1,0);
+        {
+            RuntimeContext runtime = new RuntimeContext();
+            runtime.DefineBinaryOperation<int>(Codes.Add, (x, y) => x + y);
+
+            var frame = new Frame(4,runtime);
+            frame.SetValue(2,0);
+            frame.SetValue(3,1);
+
+            var op = new BinaryOp(Codes.Add, 2, 3, 2);
 
 			var t = Environment.TickCount;
 
-			for(int i=0; i < 10000000; i++)
-				op.Invoke (frame);
+            /*
+             *          mov r1, 10 000 000
+             *          mov r2, 0
+             *          mov r3, 1
+             *          loop
+             *              condition:
+             *                  gte r2, r1
+             *              body:
+             *                  add r2,r3,r2
+             */
+
+            for (int i = 0; i < 10000000; i++)
+                op.Invoke(frame);
 
-			var res = frame.Get<int> (0);
-
-			Console.WriteLine ("got: {0}, int {1} ms", res, Environment.TickCount - t );
+			Console.WriteLine ("vm: {0}, int {1} ms", frame.GetValue<int>(2), Environment.TickCount - t );
+
+            t = Environment.TickCount;
+
+            /*
+             *          mov r1, 10 000 000
+             *          mov r2, 0
+             *          mov r3, 1
+             *          loop
+             *              condition:
+             *                  gte r2, r1
+             *              body:
+             *                  add r2,r3,r2
+             */
+            object count = 0, inc = 1;
+            
+            for (int i = 0; i < 10000000; i++)
+                count = Add(count,inc);
+
+            Console.WriteLine("native: {0}, int {1} ms", frame.GetValue<int>(2), Environment.TickCount - t);
 
 			t = Environment.TickCount;
-
-			object count = 0, inc = 1;
-			for (int i=0; i< 10000000; i++)
-				count = OpAdd(count,inc);
-
-			Console.WriteLine ("reference results: {0}, int {1} ms", count, Environment.TickCount - t );
-
-			var code = new VM2.Instruction[10000000];
-
-			for (int i = 0; i < code.Length; i++)
-				code[i] = new VM2.Instruction(){ code = VM2.OpCodes.Codes.Add, dest = 0, args = new int[] {0,1} };
-			var machine = new VM2.Machine ();
-
-			t = Environment.TickCount;
-
-			machine.InitFrame (new object[] { 0, 1 });
-			machine.Execute (code);
-
-			Console.WriteLine ("vm2: {0}, int {1} ms", machine.Get(0), Environment.TickCount - t );
+        }
+
+        public static object Add(object arg1, object arg2) {
+            return (int)arg1 + (int)arg2;
         }
-
-		public static object OpAdd(object arg1, object arg2) {
-			if (arg1.GetType () == arg2.GetType ()) {
-				return OpAddIntegers(arg1,arg2);
-			}
-			throw new Exception ();
-		}
-
-		public static object OpAddIntegers(object arg1, object arg2) {
-			return (int)arg1 + (int)arg2;
-		}
     }
 }
--- a/Jint.Runtime/PropertyDescriptor.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-using System;
-namespace Jint.Runtime
-{
-	public struct PropertyDescriptor
-	{
-		public PropertyFlags flags;
-		
-		public int index;
-	}
-}
-
--- a/Jint.Runtime/PropertyFlags.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-using System;
-namespace Jint.Runtime
-{
-	[Flags]
-	public enum PropertyFlags
-	{
-		Read = 0x1,
-		
-		Write = 0x2,
-		
-		Enumerable = 0x4
-	}
-}
-
--- a/Jint.Runtime/TransitionAction.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-using System;
-namespace Jint.Runtime
-{
-	public enum TransitionAction
-	{
-		DefineProperty,
-		
-		DeleteProperty
-	}
-}
-
--- 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;
+        }
+    }
+}
--- a/Jint.Runtime/VM/BoxBase.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM
-{
-	public abstract class BoxBase
-	{
-		public abstract bool IsReference { get; }
-        public abstract Type HoldingType { get; }
-		public abstract T Convert<T> ();
-
-		public abstract void Invoke(IBinaryOperation op,BoxBase arg2, Frame frame);
-
-	}
-}
-
--- a/Jint.Runtime/VM/DummyConverter.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-using System;
-
-namespace Jint.Runtime
-{
-	public class DummyConverter: IConverter
-	{
-		#region IConverter implementation
-
-		public TDst Convert<TSrc, TDst> (TSrc src)
-		{
-			return (TDst)(object)src;
-		}
-
-		#endregion
-
-
-	}
-}
-
--- a/Jint.Runtime/VM/Frame.cs	Fri Oct 25 15:52:16 2013 +0400
+++ b/Jint.Runtime/VM/Frame.cs	Sun Oct 27 17:23:25 2013 +0400
@@ -1,59 +1,42 @@
-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;
-		}
-
-	}
-}
-
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Jint.Runtime.VM {
+    class Frame {
+        IBox[] m_registers;
+        RuntimeContext m_runtime;
+
+        public Frame(int size, RuntimeContext runtime) {
+            if (runtime == null)
+                throw new ArgumentNullException("runtime");
+            if (size < 0)
+                throw new ArgumentOutOfRangeException("size");
+            m_runtime = runtime;
+            m_registers = new IBox[size];
+        }
+
+        public IBox this[int index] {
+            get {
+                return m_registers[index];
+            }
+            set {
+                m_registers[index] = value;
+            }
+        }
+
+        public T GetValue<T>(int index) {
+            // TODO handle conversion errors
+            return ((Box<T>)m_registers[index]).holdingValue;
+        }
+
+        public void SetValue<T>(int index, T value) {
+            var reg = m_registers[index] as Box<T>;
+            if (reg == null)
+                m_registers[index] = m_runtime.BoxValue(value);
+            else
+                reg.holdingValue = value;
+        }
+    }
+}
--- a/Jint.Runtime/VM/IBinder.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM
-{
-	public interface IBinder<T>
-	{
-		bool Equals (T arg1, T arg2);
-		int Compare (T arg1, T arg2);
-		T2 Convert<T2> (T arg);
-
-		T OpAdd (T arg1, T arg2);
-		T OpSub (T arg1, T arg2);
-		T OpMul (T arg1, T arg2);
-
-	}
-}
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Jint.Runtime/VM/IBox.cs	Sun Oct 27 17:23:25 2013 +0400
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Jint.Runtime.VM.OpCodes;
+
+namespace Jint.Runtime.VM {
+    interface IBox {
+        Type HoldingType {
+            get;
+        }
+        void InvokeBinaryOperation(Codes code, int arg2, int dest, Frame frame);
+    }
+}
--- a/Jint.Runtime/VM/IConverter.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-using System;
-
-namespace Jint.Runtime
-{
-	public interface IConverter
-	{
-		TDst Convert<TSrc,TDst> (TSrc src);
-	}
-}
-
--- a/Jint.Runtime/VM/IGetter.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM
-{
-	public interface IGetter<out T>
-	{
-		T Get();
-	}
-}
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Jint.Runtime/VM/IGettter.cs	Sun Oct 27 17:23:25 2013 +0400
@@ -0,0 +1,10 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Jint.Runtime.VM {
+    interface IGettter<out T> {
+        T Get();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Jint.Runtime/VM/IInstruction.cs	Sun Oct 27 17:23:25 2013 +0400
@@ -0,0 +1,10 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Jint.Runtime.VM {
+    interface IInstruction {
+        IInstruction Invoke(Frame frame);
+    }
+}
--- a/Jint.Runtime/VM/IReference.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-using System;
-
-namespace Jint.Runtime
-{
-	public interface IReference
-	{
-	}
-}
-
--- a/Jint.Runtime/VM/ISetter.cs	Fri Oct 25 15:52:16 2013 +0400
+++ b/Jint.Runtime/VM/ISetter.cs	Sun Oct 27 17:23:25 2013 +0400
@@ -1,10 +1,10 @@
-using System;
-
-namespace Jint.Runtime.VM
-{
-	public interface ISetter<in T>
-	{
-		void Set (T value);
-	}
-}
-
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Jint.Runtime.VM {
+    interface ISetter<in T> {
+        void Set(T value);
+    }
+}
--- a/Jint.Runtime/VM/IValueHolder.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM
-{
-	public interface IValueHolder<T>
-	{
-		T Get<T>();
-		void Set<T>(T value);
-	}
-}
-
--- a/Jint.Runtime/VM/IntegerBinder.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM
-{
-	public class IntegerBinder: IBinder<int>
-	{
-		#region IBinder implementation
-
-
-
-		#endregion
-
-		#region IBinder implementation
-
-		public bool Equals (int arg1, int arg2)
-		{
-			throw new NotImplementedException ();
-		}
-
-		public int Compare (int arg1, int arg2)
-		{
-			throw new NotImplementedException ();
-		}
-
-		public T2 Convert<T2> (int arg)
-		{
-			return (T2)Convert.ChangeType(arg,typeof(T2)) ;
-		}
-		public int OpAdd (int arg1, int arg2)
-		{
-			return arg1 + arg2;
-		}
-
-		public int OpSub (int arg1, int arg2)
-		{
-			return arg1 - arg2;
-		}
-
-		public int OpMul (int arg1, int arg2)
-		{
-			return arg1 * arg2;
-		}
-
-		#endregion
-	}
-}
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Jint.Runtime/VM/Machine.cs	Sun Oct 27 17:23:25 2013 +0400
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Jint.Runtime.VM {
+    class Machine {
+        Frame m_frame;
+
+        public void Run(IInstruction prog) {
+            while (prog != null)
+                prog = prog.Invoke(m_frame);
+        }
+    }
+}
--- a/Jint.Runtime/VM/OpCodes/Add.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM.OpCodes
-{
-	public class Add: BinaryOperation
-	{
-		public Add(int a1,int a2, int res) : base(a1,a2,res) {
-		}
-
-		#region IBinaryOp implementation
-		public override void Invoke<T> (T arg1, T arg2, IBinder<T> binder, Frame frame)
-		{
-			frame.Set(m_res, binder.OpAdd(arg1,arg2));
-		}
-		#endregion
-	}
-}
-
--- a/Jint.Runtime/VM/OpCodes/BinaryOp.cs	Fri Oct 25 15:52:16 2013 +0400
+++ b/Jint.Runtime/VM/OpCodes/BinaryOp.cs	Sun Oct 27 17:23:25 2013 +0400
@@ -1,19 +1,36 @@
-using System;
-
-namespace Jint.Runtime.VM.OpCodes
-{
-	public abstract class BinaryOp: IOpCode
-	{
-		#region IOpCode implementation
-
-		public void Invoke (Frame frame)
-		{
-
-		}
-
-		#endregion
-
-
-	}
-}
-
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Jint.Runtime.VM.OpCodes {
+    delegate void BinaryInstructionImpl(int arg1, int arg2, int dest, Frame frame);
+
+    class BinaryOp: IInstruction {
+
+        int m_dest;
+        int m_arg1;
+        int m_arg2;
+        Codes m_code;
+        IInstruction m_next;
+
+        public BinaryOp(Codes code, int arg1, int arg2, int dest) {
+            m_code = code;
+            m_arg1 = arg1;
+            m_arg2 = arg2;
+            m_dest = dest;
+        }
+
+        public IInstruction Chain(IInstruction next) {
+            m_next = next;
+            return next;
+        }
+
+        public IInstruction Invoke(Frame frame) {
+            //frame[m_arg1].GetBinaryImpl(m_code)(m_arg1, m_arg2, m_dest, frame);
+            frame[m_arg1].InvokeBinaryOperation(m_code, m_arg2, m_dest, frame);
+
+            return m_next;
+        }
+    }
+}
--- a/Jint.Runtime/VM/OpCodes/BinaryOperation.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM
-{
-	public abstract class BinaryOperation: IBinaryOperation
-	{
-		protected int m_arg1;
-		protected int m_arg2;
-		protected int m_res;
-
-		protected BinaryOperation(int arg1, int arg2, int res) {
-			m_arg1 = arg1;
-			m_arg2 = arg2;
-			m_res = res;
-		}
-
-		public virtual void Fallback(BoxBase arg1, BoxBase arg2, Frame frame) {
-			throw new InvalidOperationException ("Unable to perform a binary operation on the specified arguments");
-		}
-
-		#region IBinaryOperation implementation
-
-		public abstract void Invoke<T> (T arg1, T arg2, IBinder<T> binder, Frame frame);
-
-		#endregion
-
-		#region IOperation implementation
-
-		public void Invoke (Frame frame)
-		{
-			var box1 = frame.GetBox (m_arg1);
-			var box2 = frame.GetBox (m_arg2);
-
-			if (box1 != null && box2 != null && box1.HoldingType == box2.HoldingType) {
-				box1.Invoke (this, box2, frame);
-			} else {
-				Fallback (box1, box2, frame);
-			}
-		}
-
-		#endregion
-	}
-}
-
--- a/Jint.Runtime/VM/OpCodes/Codes.cs	Fri Oct 25 15:52:16 2013 +0400
+++ b/Jint.Runtime/VM/OpCodes/Codes.cs	Sun Oct 27 17:23:25 2013 +0400
@@ -1,10 +1,32 @@
-using System;
-
-namespace Jint.Runtime
-{
-	public enum Codes: int
-	{
-		Add = 1
-	}
-}
-
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Jint.Runtime.VM.OpCodes {
+    enum Codes: int {
+        Noop = 0,
+        
+        Add,
+        Sub,
+        Div,
+        Mul,
+        
+        BAnd,
+        BOr,
+        BNot,
+        
+        LAnd,
+        LOr,
+        LNot,
+        
+        Gte,
+        Lte,
+        Gt,
+        Lt,
+        Eq,
+        Ne,
+
+        MaxOp
+    }
+}
--- a/Jint.Runtime/VM/OpCodes/IBinaryOperation.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM
-{
-	public interface IBinaryOperation: IOperation
-	{
-		void Invoke<T> (T arg1, T arg2, IBinder<T> binder, Frame frame);
-	}
-}
-
--- a/Jint.Runtime/VM/OpCodes/IBinaryOperation2.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM.OpCodes
-{
-	public interface IBinaryOperation2
-	{
-	}
-}
-
--- a/Jint.Runtime/VM/OpCodes/IOpCode.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM.OpCodes
-{
-	public interface IOpCode
-	{
-		void Invoke (Frame frame);
-	}
-}
-
--- a/Jint.Runtime/VM/OpCodes/IOperation.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM
-{
-	public interface IOperation
-	{
-		void Invoke (Frame frame);
-	}
-}
-
--- a/Jint.Runtime/VM/OpCodes/Instruction.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-using System;
-
-namespace Jint.Runtime
-{
-	public struct Instruction
-	{
-		public Codes code;
-		public int[] operands;
-	}
-}
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Jint.Runtime/VM/OpCodes/Loop.cs	Sun Oct 27 17:23:25 2013 +0400
@@ -0,0 +1,10 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Jint.Runtime.VM.OpCodes {
+    class Loop {
+
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Jint.Runtime/VM/OperationDelegates.cs	Sun Oct 27 17:23:25 2013 +0400
@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Jint.Runtime.VM {
+    public delegate T BinaryOperation<T>(T arg1, T arg2);
+    public delegate T UnaryOperation<T>(T arg);
+    public delegate int CompareOperation<T>(T arg1, T arg2);
+    public delegate bool EqualsOperation<T>(T arg1, T arg2);
+}
--- a/Jint.Runtime/VM/RuntimeContext.cs	Fri Oct 25 15:52:16 2013 +0400
+++ b/Jint.Runtime/VM/RuntimeContext.cs	Sun Oct 27 17:23:25 2013 +0400
@@ -1,25 +1,31 @@
-using System;
-using System.Collections.Generic;
-
-namespace Jint.Runtime.VM
-{
-	public class RuntimeContext
-	{
-		Dictionary<Type,object> m_binders;
-
-		public RuntimeContext ()
-		{
-			m_binders = new Dictionary<Type,object> ();
-			m_binders.Add (typeof(int), new IntegerBinder ());
-		}
-
-		public Box<T> BoxValue<T>(T value) {
-			return new Box<T> (value, GetBinder<T> ());
-		}
-
-		public IBinder<T> GetBinder<T>() {
-			return (IBinder<T>) m_binders [typeof(T)];
-		}
-	}
-}
-
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Jint.Runtime.VM.OpCodes;
+
+namespace Jint.Runtime.VM {
+    class RuntimeContext {
+        Dictionary<Type, object[]> m_impls;
+
+        public RuntimeContext() {
+            m_impls = new Dictionary<Type, object[]>();
+        }
+
+        public object[] GetImpl(Type type) {
+            return m_impls[type];
+        }
+
+        public Box<T> BoxValue<T>(T value) {
+            return new Box<T>(value, this);
+        }
+
+        public void DefineBinaryOperation<T>(Codes code, BinaryOperation<T> op) {
+            object[] ops;
+            if (!m_impls.TryGetValue(typeof(T), out ops))
+                ops = m_impls[typeof(T)] = new object[(int)Codes.MaxOp];
+
+            ops[(int)code] = op;
+        }
+    }
+}
--- a/Jint.Runtime/VM2/Box.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM2
-{
-	using OpCodes;
-
-	public class Box
-	{
-		public Operation[] impl;
-		public object value;
-
-		public Box(object boxValue,Operation[] opImpl) {
-			value = boxValue;
-			impl = opImpl;
-		}
-
-		public Type HoldingType {
-			get {
-				return value == null ? null : value.GetType ();
-			}
-		}
-	}
-}
-
--- a/Jint.Runtime/VM2/Frame.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM2
-{
-	public class Frame
-	{
-		Box m_values;
-		public Frame (int size)
-		{
-		}
-
-		public Box Get() {
-		}
-
-	}
-}
-
--- a/Jint.Runtime/VM2/Instruction.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM2
-{
-	using OpCodes;
-	public struct Instruction
-	{
-		public Codes code;
-		public int dest;
-		public int[] args;
-	}
-}
-
--- a/Jint.Runtime/VM2/IntegerBinder.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-using System;
-
-namespace Jint.Runtime
-{
-	public class IntegerBinder
-	{
-		public int OpAdd(int arg1, int arg2) {
-			return arg1 + arg2;
-		}
-	}
-}
-
--- a/Jint.Runtime/VM2/Machine.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Jint.Runtime.VM2
-{
-	public class Machine
-	{
-		RuntimeContext m_context;
-		//Stack<object[]> m_frames;
-		Box[] m_frame;
-
-
-		public Machine ()
-		{
-			m_context = new RuntimeContext ();
-		}
-
-		public void InitFrame(object[] values) {
-			m_frame = new Box[values.Length];
-			for(int i = 0; i< values.Length; i++)
-				m_frame[i] = m_context.PackValue(values[i]);
-		}
-
-		public void Execute(Instruction[] instructions) {
-			foreach (var op in instructions) {
-				m_frame [op.dest].value = m_frame [op.args [0]].impl [(int)op.code](MakeArgs(op.args));
-			}
-		}
-
-		private object[] MakeArgs(int[] regs) {
-			object[] args = new object[regs.Length];
-			for (int i=0; i< regs.Length; i++)
-				args[i] = m_frame [regs [i]].value;
-			return args;
-		}
-
-		public object Get(int index) {
-			return m_frame [index];
-		}
-	}
-}
-
--- a/Jint.Runtime/VM2/OpCodes/Add.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-using System;
-
-namespace Jint.Runtime
-{
-	public class Add
-	{
-		public Add ()
-		{
-		}
-	}
-}
-
--- a/Jint.Runtime/VM2/OpCodes/Codes.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM2.OpCodes
-{
-	public enum Codes: int
-	{
-		Noop = 0,
-		Add,
-		MaxCode
-	}
-}
-
--- a/Jint.Runtime/VM2/OpCodes/Operation.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-using System;
-
-namespace Jint.Runtime.VM2.OpCodes {
-	public delegate object Operation(object[] args);
-}
--- a/Jint.Runtime/VM2/RuntimeContext.cs	Fri Oct 25 15:52:16 2013 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Jint.Runtime.VM2
-{
-	using OpCodes;
-
-	public class RuntimeContext
-	{
-		Dictionary<Type, Operation[]> m_bindings;
-		public RuntimeContext ()
-		{
-			m_bindings = new Dictionary<Type, Operation[]>();
-			m_bindings[typeof(int)] = new Operation[] {
-				(args) => {return null;},
-				(args) => {
-					return (int)args[0]+(int)args[1];
-				}
-			};
-		}
-
-		public Box PackValue(object value) {
-			return new Box (value,m_bindings[value.GetType()]);
-		}
-	}
-}
-
--- a/Jint.sln	Fri Oct 25 15:52:16 2013 +0400
+++ b/Jint.sln	Sun Oct 27 17:23:25 2013 +0400
@@ -6,10 +6,6 @@
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jint.Experimental", "Jint.Experimental\Jint.Experimental.csproj", "{8AC3346E-5A4E-4B8C-A225-E4C47F912730}"
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{96947B34-64F4-4A7A-B432-19D7B6B36D14}"
-	ProjectSection(SolutionItems) = preProject
-		Performance1.psess = Performance1.psess
-		Performance2.psess = Performance2.psess
-	EndProjectSection
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
Binary file Jint.suo has changed