Mercurial > pub > Jint1
annotate Jint.Runtime/VM/Frame.cs @ 4:1ae5b10f7a10
Code cleanup, minor refactoring
| author | cin |
|---|---|
| date | Sun, 27 Oct 2013 21:20:59 +0400 |
| parents | aced2ae9957f |
| children | cb13da6e3349 |
| 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 |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
6 namespace Jint.Runtime.VM { |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
7 class Frame { |
| 4 | 8 AbstractBox[] m_registers; |
|
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
9 RuntimeContext m_runtime; |
|
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 Frame(int size, RuntimeContext runtime) { |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
12 if (runtime == null) |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
13 throw new ArgumentNullException("runtime"); |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
14 if (size < 0) |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
15 throw new ArgumentOutOfRangeException("size"); |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
16 m_runtime = runtime; |
| 4 | 17 m_registers = new AbstractBox[size]; |
|
3
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 |
| 4 | 20 public AbstractBox this[int index] { |
|
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
21 get { |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
22 return m_registers[index]; |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
23 } |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
24 set { |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
25 m_registers[index] = value; |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
26 } |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
27 } |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
28 |
| 4 | 29 /// <summary> |
| 30 /// Extracts value stored in the registry specified by the index. | |
| 31 /// </summary> | |
| 32 /// <remarks>This method doesn't do any cast, if the specified type isn't the same as the type of the stored value a type cast exception will occur.</remarks> | |
| 33 /// <typeparam name="T">The type of the value stored in the registry.</typeparam> | |
| 34 /// <param name="index">The index of the registry.</param> | |
| 35 /// <returns>The value stored in the registry.</returns> | |
|
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
36 public T GetValue<T>(int index) { |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
37 return ((Box<T>)m_registers[index]).holdingValue; |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
38 } |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
39 |
| 4 | 40 /// <summary> |
| 41 /// Stores a new value in the register specified by the index. | |
| 42 /// </summary> | |
| 43 /// <remarks> | |
| 44 /// If the previous value has the same type as the value being stored in the registry, | |
| 45 /// the new value will replace the old one, otherwise the registry will be reallocated to | |
| 46 /// store the new value. | |
| 47 /// </remarks> | |
| 48 /// <typeparam name="T">The type of the value being stored</typeparam> | |
| 49 /// <param name="index">The index of the registry where the value will be stored</param> | |
| 50 /// <param name="value">The value to be stored in the registry</param> | |
|
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
51 public void SetValue<T>(int index, T value) { |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
52 var reg = m_registers[index] as Box<T>; |
| 4 | 53 if (reg == null || reg.holdingType != typeof(T)) |
|
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
54 m_registers[index] = m_runtime.BoxValue(value); |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
55 else |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
56 reg.holdingValue = value; |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
57 } |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
58 } |
|
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
59 } |
