Mercurial > pub > Jint1
comparison Jint.Runtime/VM/Frame.cs @ 5:cb13da6e3349
simple loop test
author | cin |
---|---|
date | Mon, 28 Oct 2013 00:49:15 +0400 |
parents | 1ae5b10f7a10 |
children | a6329b092499 |
comparison
equal
deleted
inserted
replaced
4:1ae5b10f7a10 | 5:cb13da6e3349 |
---|---|
15 throw new ArgumentOutOfRangeException("size"); | 15 throw new ArgumentOutOfRangeException("size"); |
16 m_runtime = runtime; | 16 m_runtime = runtime; |
17 m_registers = new AbstractBox[size]; | 17 m_registers = new AbstractBox[size]; |
18 } | 18 } |
19 | 19 |
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> | |
20 public AbstractBox this[int index] { | 25 public AbstractBox this[int index] { |
21 get { | 26 get { |
22 return m_registers[index]; | 27 return m_registers[index]; |
23 } | 28 } |
24 set { | 29 set { |
25 m_registers[index] = value; | 30 m_registers[index] = value; |
26 } | 31 } |
27 } | 32 } |
28 | 33 |
29 /// <summary> | 34 /// <summary> |
30 /// Extracts value stored in the registry specified by the index. | 35 /// Extracts value stored in the register specified by the index. |
31 /// </summary> | 36 /// </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> | 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> |
33 /// <typeparam name="T">The type of the value stored in the registry.</typeparam> | 38 /// <typeparam name="T">The type of the value stored in the register.</typeparam> |
34 /// <param name="index">The index of the registry.</param> | 39 /// <param name="index">The index of the register.</param> |
35 /// <returns>The value stored in the registry.</returns> | 40 /// <returns>The value stored in the register.</returns> |
36 public T GetValue<T>(int index) { | 41 public T GetValue<T>(int index) { |
37 return ((Box<T>)m_registers[index]).holdingValue; | 42 return ((Box<T>)m_registers[index]).holdingValue; |
38 } | 43 } |
39 | 44 |
40 /// <summary> | 45 /// <summary> |
41 /// Stores a new value in the register specified by the index. | 46 /// Stores a new value in the register specified by the index. |
42 /// </summary> | 47 /// </summary> |
43 /// <remarks> | 48 /// <remarks> |
44 /// If the previous value has the same type as the value being stored in the registry, | 49 /// If the previous value has the same type as the value being stored in the register, |
45 /// the new value will replace the old one, otherwise the registry will be reallocated to | 50 /// the new value will replace the old one, otherwise the register will be reallocated to |
46 /// store the new value. | 51 /// store the new value. |
47 /// </remarks> | 52 /// </remarks> |
48 /// <typeparam name="T">The type of the value being stored</typeparam> | 53 /// <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> | 54 /// <param name="index">The index of the register where the value will be stored</param> |
50 /// <param name="value">The value to be stored in the registry</param> | 55 /// <param name="value">The value to be stored in the register</param> |
51 public void SetValue<T>(int index, T value) { | 56 public void SetValue<T>(int index, T value) { |
52 var reg = m_registers[index] as Box<T>; | 57 var reg = m_registers[index] as Box<T>; |
53 if (reg == null || reg.holdingType != typeof(T)) | 58 if (reg == null || reg.holdingType != typeof(T)) |
54 m_registers[index] = m_runtime.BoxValue(value); | 59 m_registers[index] = m_runtime.BoxValue(value); |
55 else | 60 else |
56 reg.holdingValue = value; | 61 reg.holdingValue = value; |
57 } | 62 } |
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 } | |
58 } | 72 } |
59 } | 73 } |