Mercurial > pub > Jint1
annotate Jint.Runtime/VM/Frame.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 | 1ae5b10f7a10 |
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 { |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
8 IBox[] m_registers; |
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; |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
17 m_registers = new IBox[size]; |
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 |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
20 public IBox this[int index] { |
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 |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
29 public T GetValue<T>(int index) { |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
30 // TODO handle conversion errors |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
31 return ((Box<T>)m_registers[index]).holdingValue; |
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 |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
34 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
|
35 var reg = m_registers[index] as Box<T>; |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
36 if (reg == null) |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
37 m_registers[index] = m_runtime.BoxValue(value); |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
38 else |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
39 reg.holdingValue = value; |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
40 } |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
41 } |
aced2ae9957f
temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents:
0
diff
changeset
|
42 } |