Mercurial > pub > Jint1
annotate Jint.Runtime/VM/RuntimeContext.cs @ 8:5b2302d3ac4f default tip
Слияние
author | cin |
---|---|
date | Wed, 30 Oct 2013 20:44:42 +0400 |
parents | cb13da6e3349 |
children |
rev | line source |
---|---|
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
1 using System; |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
2 using System.Collections.Generic; |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
3 using System.Linq; |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
4 using System.Text; |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
5 using Jint.Runtime.VM.OpCodes; |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
6 |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
7 namespace Jint.Runtime.VM { |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
8 class RuntimeContext { |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
9 Dictionary<Type, object[]> m_impls; |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
10 |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
11 public RuntimeContext() { |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
12 m_impls = new Dictionary<Type, object[]>(); |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
13 } |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
14 |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
15 public object[] GetImpl(Type type) { |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
16 return m_impls[type]; |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
17 } |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
18 |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
19 public Box<T> BoxValue<T>(T value) { |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
20 return new Box<T>(value, this); |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
21 } |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
22 |
5 | 23 object[] GetOrCreateOps(Type type) { |
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
24 object[] ops; |
5 | 25 if (!m_impls.TryGetValue(type, out ops)) |
26 ops = m_impls[type] = new object[(int)Codes.MaxOp]; | |
27 return ops; | |
28 } | |
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
29 |
5 | 30 public void DefineBinaryOperation<T>(Codes code, BinaryOperation<T> op) { |
31 object[] ops = GetOrCreateOps(typeof(T)); | |
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
32 ops[(int)code] = op; |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
33 } |
5 | 34 |
35 public void DefineCompareOperation<T>(CompareOperation<T> op) { | |
36 object[] ops = GetOrCreateOps(typeof(T)); | |
37 ops[(int)Codes.Cmp] = op; | |
38 } | |
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
39 } |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
40 } |