Mercurial > pub > Jint1
diff Jint.Runtime/VM/RuntimeContext.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 | cb13da6e3349 |
line wrap: on
line diff
--- 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; + } + } +}