annotate Jint.Runtime/VM/Frame.cs @ 7:17543aa3aced

sync
author cin
date Tue, 29 Oct 2013 07:04:33 +0400
parents cb13da6e3349
children a6329b092499
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
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
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
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
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
20 /// <summary>
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
21 /// Return register at the specified index.
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
22 /// </summary>
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
23 /// <param name="index">The index of the register</param>
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
24 /// <returns>The register.</returns>
4
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
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
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
34 /// <summary>
5
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
35 /// Extracts value stored in the register specified by the index.
4
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
36 /// </summary>
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
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
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
38 /// <typeparam name="T">The type of the value stored in the register.</typeparam>
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
39 /// <param name="index">The index of the register.</param>
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
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
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
45 /// <summary>
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
46 /// Stores a new value in the register specified by the index.
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
47 /// </summary>
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
48 /// <remarks>
5
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
49 /// If the previous value has the same type as the value being stored in the register,
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
50 /// the new value will replace the old one, otherwise the register will be reallocated to
4
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
51 /// store the new value.
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
52 /// </remarks>
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
53 /// <typeparam name="T">The type of the value being stored</typeparam>
5
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
54 /// <param name="index">The index of the register where the value will be stored</param>
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
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
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
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
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
63
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
64 public T GetConverted<T>(int index) {
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
65 var reg = m_registers[index];
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
66
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
67 if (reg.holdingType == typeof(T))
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
68 return ((Box<T>)reg).holdingValue;
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
69 else
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
70 return reg.Convert<T>();
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
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 }