Mercurial > pub > Jint1
annotate Jint.Runtime/VM/Box.cs @ 5:cb13da6e3349
simple loop test
| author | cin |
|---|---|
| date | Mon, 28 Oct 2013 00:49:15 +0400 |
| parents | 1ae5b10f7a10 |
| children | a6329b092499 |
| 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; |
| 5 | 6 using System.ComponentModel; |
|
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
7 |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
8 namespace Jint.Runtime.VM { |
| 4 | 9 class Box<T>: AbstractBox, IGettter<T>, ISetter<T> { |
|
3
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 T holdingValue; |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
12 object[] m_impl; |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
13 RuntimeContext m_runtime; |
| 5 | 14 TypeConverter m_converter; |
|
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
15 |
| 4 | 16 public Box(T value, RuntimeContext runtime): base(typeof(T)) { |
|
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
17 if (runtime == null) |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
18 throw new ArgumentNullException("runtime"); |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
19 |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
20 holdingValue = value; |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
21 m_runtime = runtime; |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
22 } |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
23 |
| 4 | 24 object[] Impl { |
|
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
25 get { |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
26 if (m_impl == null) |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
27 m_impl = m_runtime.GetImpl(typeof(T)); |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
28 return m_impl; |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
29 } |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
30 } |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
31 |
| 5 | 32 TypeConverter TypeConverter { |
| 33 get { | |
| 34 if (m_converter == null) | |
| 35 m_converter = TypeDescriptor.GetConverter(typeof(T)); | |
| 36 return m_converter; | |
| 37 } | |
| 38 } | |
| 39 | |
|
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
40 public T Get() { |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
41 return holdingValue; |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
42 } |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
43 |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
44 public void Set(T value) { |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
45 holdingValue = value; |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
46 } |
| 4 | 47 |
| 48 public override void InvokeBinaryOperation(Codes code, int arg2, int dest, Frame frame) { | |
| 49 var op = (BinaryOperation<T>)Impl[(int)code]; | |
| 50 frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2))); | |
| 51 } | |
| 52 | |
| 53 public override void InvokeUnaryOperation(Codes code, int dest, Frame frame) { | |
| 54 var op = (UnaryOperation<T>)Impl[(int)code]; | |
| 55 frame.SetValue(dest, op(holdingValue)); | |
| 56 } | |
| 57 | |
| 5 | 58 public override int InvokeCompareOperation(int arg2, Frame frame) { |
| 4 | 59 var op = (CompareOperation<T>)Impl[(int)Codes.Cmp]; |
| 5 | 60 return op(holdingValue, frame.GetValue<T>(arg2)); |
| 4 | 61 } |
| 62 | |
| 5 | 63 public override bool InvokeEqualityOperation(int arg2, Frame frame) { |
| 4 | 64 var op = (EqualityOperation<T>)Impl[(int)Codes.Cmp]; |
| 5 | 65 return op(holdingValue, frame.GetValue<T>(arg2)); |
| 66 } | |
| 67 | |
| 68 public override T2 Convert<T2>() { | |
| 69 return (T2)TypeConverter.ConvertTo(holdingValue, typeof(T2)); | |
| 4 | 70 } |
|
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
71 } |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
72 } |
