# HG changeset patch # User cin # Date 1382880205 -14400 # Node ID aced2ae9957f17b69e68f199b559b1cd2e3bc991 # Parent 4aed85a1f558da528b5d4939e534a60495297e2e temp commit, new virtual machine concept (strongly typed version of VM2). diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/AssemblyInfo.cs --- 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("")] diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/ClassDescriptor.cs --- 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 m_props = new Dictionary(); - - - 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) { - - } - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/ClassTransition.cs --- 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; - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/Jint.Runtime.csproj --- 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 @@ - - - - Debug - x86 - 10.0.0 - 2.0 - {F3FDE0D1-748F-4DFE-9C1C-D17D7FD4E642} - Exe - Jint.Runtime - Jint.Runtime - - - True - full - False - bin\Debug - DEBUG; - prompt - 4 - x86 - True - - - none - True - bin\Release - prompt - 4 - x86 - True - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + Debug + x86 + 10.0.0 + 2.0 + {F3FDE0D1-748F-4DFE-9C1C-D17D7FD4E642} + Exe + Jint.Runtime + Jint.Runtime + + + True + full + False + bin\Debug + DEBUG; + prompt + 4 + x86 + True + + + none + True + bin\Release + prompt + 4 + x86 + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/Jint.Runtime.csproj.user --- /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 @@ + + + + ProjectFiles + + \ No newline at end of file diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/JsObject.cs --- 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 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; - } - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/Main.cs --- 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(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 (0); - - Console.WriteLine ("got: {0}, int {1} ms", res, Environment.TickCount - t ); + Console.WriteLine ("vm: {0}, int {1} ms", frame.GetValue(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(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; - } } } diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/PropertyDescriptor.cs --- 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; - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/PropertyFlags.cs --- 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 - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/TransitionAction.cs --- 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 - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/Box.cs --- 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: BoxBase, IGetter, ISetter - { - T m_value; - IBinder m_binder; - - public Box(T value,IBinder 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: IBox, IGettter, ISetter { + + 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 () - { - if (m_binder == null) - throw new ArgumentNullException (); - return m_binder.Convert (m_value); - } - - public override void Invoke(IBinaryOperation op, BoxBase arg2,Frame frame) { - op.Invoke (m_value, ((IGetter)arg2).Get (), m_binder, frame); - } - } -} - + } + + public void InvokeBinaryOperation(Codes code, int arg2, int dest, Frame frame) { + var op = (BinaryOperation)Impl[(int)code]; + frame.SetValue(dest, op(holdingValue, frame.GetValue(arg2))); + } + + public T Get() { + return holdingValue; + } + + public void Set(T value) { + holdingValue = value; + } + } +} diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/BoxBase.cs --- 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 (); - - public abstract void Invoke(IBinaryOperation op,BoxBase arg2, Frame frame); - - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/DummyConverter.cs --- 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 src) - { - return (TDst)(object)src; - } - - #endregion - - - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/Frame.cs --- 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 (int index) - { - var bbox = m_data [index]; - - if (bbox == null) - return default(T); - - var box = bbox as IGetter; - if (box != null) - return box.Get(); - else - return bbox.Convert(); - } - - public void Set (int index, T value) - { - var bbox = m_data [index]; - var box = bbox as ISetter; - 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(int index) { + // TODO handle conversion errors + return ((Box)m_registers[index]).holdingValue; + } + + public void SetValue(int index, T value) { + var reg = m_registers[index] as Box; + if (reg == null) + m_registers[index] = m_runtime.BoxValue(value); + else + reg.holdingValue = value; + } + } +} diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/IBinder.cs --- 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 - { - bool Equals (T arg1, T arg2); - int Compare (T arg1, T arg2); - T2 Convert (T arg); - - T OpAdd (T arg1, T arg2); - T OpSub (T arg1, T arg2); - T OpMul (T arg1, T arg2); - - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/IBox.cs --- /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); + } +} diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/IConverter.cs --- 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 src); - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/IGetter.cs --- 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 - { - T Get(); - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/IGettter.cs --- /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 { + T Get(); + } +} diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/IInstruction.cs --- /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); + } +} diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/IReference.cs --- 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 - { - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/ISetter.cs --- 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 - { - void Set (T value); - } -} - +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Jint.Runtime.VM { + interface ISetter { + void Set(T value); + } +} diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/IValueHolder.cs --- 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 Get(); - void Set(T value); - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/IntegerBinder.cs --- 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 - { - #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 (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 - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/Machine.cs --- /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); + } + } +} diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/OpCodes/Add.cs --- 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 arg1, T arg2, IBinder binder, Frame frame) - { - frame.Set(m_res, binder.OpAdd(arg1,arg2)); - } - #endregion - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/OpCodes/BinaryOp.cs --- 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; + } + } +} diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/OpCodes/BinaryOperation.cs --- 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 arg1, T arg2, IBinder 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 - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/OpCodes/Codes.cs --- 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 + } +} diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/OpCodes/IBinaryOperation.cs --- 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 arg1, T arg2, IBinder binder, Frame frame); - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/OpCodes/IBinaryOperation2.cs --- 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 - { - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/OpCodes/IOpCode.cs --- 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); - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/OpCodes/IOperation.cs --- 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); - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/OpCodes/Instruction.cs --- 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; - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/OpCodes/Loop.cs --- /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 { + + } +} diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/OperationDelegates.cs --- /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 arg1, T arg2); + public delegate T UnaryOperation(T arg); + public delegate int CompareOperation(T arg1, T arg2); + public delegate bool EqualsOperation(T arg1, T arg2); +} diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM/RuntimeContext.cs --- 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 m_binders; - - public RuntimeContext () - { - m_binders = new Dictionary (); - m_binders.Add (typeof(int), new IntegerBinder ()); - } - - public Box BoxValue(T value) { - return new Box (value, GetBinder ()); - } - - public IBinder GetBinder() { - return (IBinder) 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 m_impls; + + public RuntimeContext() { + m_impls = new Dictionary(); + } + + public object[] GetImpl(Type type) { + return m_impls[type]; + } + + public Box BoxValue(T value) { + return new Box(value, this); + } + + public void DefineBinaryOperation(Codes code, BinaryOperation 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; + } + } +} diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM2/Box.cs --- 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 (); - } - } - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM2/Frame.cs --- 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() { - } - - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM2/Instruction.cs --- 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; - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM2/IntegerBinder.cs --- 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; - } - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM2/Machine.cs --- 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 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]; - } - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM2/OpCodes/Add.cs --- 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 () - { - } - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM2/OpCodes/Codes.cs --- 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 - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM2/OpCodes/Operation.cs --- 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); -} diff -r 4aed85a1f558 -r aced2ae9957f Jint.Runtime/VM2/RuntimeContext.cs --- 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 m_bindings; - public RuntimeContext () - { - m_bindings = new Dictionary(); - 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()]); - } - } -} - diff -r 4aed85a1f558 -r aced2ae9957f Jint.sln --- 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 diff -r 4aed85a1f558 -r aced2ae9957f Jint.suo Binary file Jint.suo has changed