Mercurial > pub > Jint1
diff 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 |
line wrap: on
line diff
--- a/Jint.Runtime/VM/Frame.cs Sun Oct 27 17:23:25 2013 +0400 +++ b/Jint.Runtime/VM/Frame.cs Sun Oct 27 21:20:59 2013 +0400 @@ -5,7 +5,7 @@ namespace Jint.Runtime.VM { class Frame { - IBox[] m_registers; + AbstractBox[] m_registers; RuntimeContext m_runtime; public Frame(int size, RuntimeContext runtime) { @@ -14,10 +14,10 @@ if (size < 0) throw new ArgumentOutOfRangeException("size"); m_runtime = runtime; - m_registers = new IBox[size]; + m_registers = new AbstractBox[size]; } - public IBox this[int index] { + public AbstractBox this[int index] { get { return m_registers[index]; } @@ -26,14 +26,31 @@ } } + /// <summary> + /// Extracts value stored in the registry specified by the index. + /// </summary> + /// <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> + /// <typeparam name="T">The type of the value stored in the registry.</typeparam> + /// <param name="index">The index of the registry.</param> + /// <returns>The value stored in the registry.</returns> public T GetValue<T>(int index) { - // TODO handle conversion errors return ((Box<T>)m_registers[index]).holdingValue; } + /// <summary> + /// Stores a new value in the register specified by the index. + /// </summary> + /// <remarks> + /// If the previous value has the same type as the value being stored in the registry, + /// the new value will replace the old one, otherwise the registry will be reallocated to + /// store the new value. + /// </remarks> + /// <typeparam name="T">The type of the value being stored</typeparam> + /// <param name="index">The index of the registry where the value will be stored</param> + /// <param name="value">The value to be stored in the registry</param> public void SetValue<T>(int index, T value) { var reg = m_registers[index] as Box<T>; - if (reg == null) + if (reg == null || reg.holdingType != typeof(T)) m_registers[index] = m_runtime.BoxValue(value); else reg.holdingValue = value;