comparison 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
comparison
equal deleted inserted replaced
2:4aed85a1f558 3:aced2ae9957f
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Jint.Runtime.VM.OpCodes;
3 6
4 namespace Jint.Runtime.VM 7 namespace Jint.Runtime.VM {
5 { 8 class RuntimeContext {
6 public class RuntimeContext 9 Dictionary<Type, object[]> m_impls;
7 {
8 Dictionary<Type,object> m_binders;
9 10
10 public RuntimeContext () 11 public RuntimeContext() {
11 { 12 m_impls = new Dictionary<Type, object[]>();
12 m_binders = new Dictionary<Type,object> (); 13 }
13 m_binders.Add (typeof(int), new IntegerBinder ());
14 }
15 14
16 public Box<T> BoxValue<T>(T value) { 15 public object[] GetImpl(Type type) {
17 return new Box<T> (value, GetBinder<T> ()); 16 return m_impls[type];
18 } 17 }
19 18
20 public IBinder<T> GetBinder<T>() { 19 public Box<T> BoxValue<T>(T value) {
21 return (IBinder<T>) m_binders [typeof(T)]; 20 return new Box<T>(value, this);
22 } 21 }
23 } 22
23 public void DefineBinaryOperation<T>(Codes code, BinaryOperation<T> op) {
24 object[] ops;
25 if (!m_impls.TryGetValue(typeof(T), out ops))
26 ops = m_impls[typeof(T)] = new object[(int)Codes.MaxOp];
27
28 ops[(int)code] = op;
29 }
30 }
24 } 31 }
25