Mercurial > pub > Jint1
annotate Jint.Runtime/VM/Frame.cs @ 7:17543aa3aced
sync
author | cin |
---|---|
date | Tue, 29 Oct 2013 07:04:33 +0400 |
parents | cb13da6e3349 |
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 |
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 |
5 | 20 /// <summary> |
21 /// Return register at the specified index. | |
22 /// </summary> | |
23 /// <param name="index">The index of the register</param> | |
24 /// <returns>The register.</returns> | |
4 | 25 public AbstractBox this[int index] { |
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
26 get { |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
27 return m_registers[index]; |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
28 } |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
29 set { |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
30 m_registers[index] = value; |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
31 } |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
32 } |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
33 |
4 | 34 /// <summary> |
5 | 35 /// Extracts value stored in the register specified by the index. |
4 | 36 /// </summary> |
37 /// <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> | |
5 | 38 /// <typeparam name="T">The type of the value stored in the register.</typeparam> |
39 /// <param name="index">The index of the register.</param> | |
40 /// <returns>The value stored in the register.</returns> | |
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
41 public T GetValue<T>(int index) { |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
42 return ((Box<T>)m_registers[index]).holdingValue; |
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 |
4 | 45 /// <summary> |
46 /// Stores a new value in the register specified by the index. | |
47 /// </summary> | |
48 /// <remarks> | |
5 | 49 /// If the previous value has the same type as the value being stored in the register, |
50 /// the new value will replace the old one, otherwise the register will be reallocated to | |
4 | 51 /// store the new value. |
52 /// </remarks> | |
53 /// <typeparam name="T">The type of the value being stored</typeparam> | |
5 | 54 /// <param name="index">The index of the register where the value will be stored</param> |
55 /// <param name="value">The value to be stored in the register</param> | |
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
56 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
|
57 var reg = m_registers[index] as Box<T>; |
4 | 58 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
|
59 m_registers[index] = m_runtime.BoxValue(value); |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
60 else |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
61 reg.holdingValue = value; |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
62 } |
5 | 63 |
64 public T GetConverted<T>(int index) { | |
65 var reg = m_registers[index]; | |
66 | |
67 if (reg.holdingType == typeof(T)) | |
68 return ((Box<T>)reg).holdingValue; | |
69 else | |
70 return reg.Convert<T>(); | |
71 } | |
3
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
72 } |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
73 } |