Mercurial > pub > Jint1
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 2:4aed85a1f558 | 3:aced2ae9957f |
|---|---|
| 1 using System; | 1 using System; |
| 2 using System.Collections.Generic; | |
| 3 using System.Linq; | |
| 4 using System.Text; | |
| 2 | 5 |
| 3 namespace Jint.Runtime.VM | 6 namespace Jint.Runtime.VM { |
| 4 { | 7 class Frame { |
| 5 public class Frame | 8 IBox[] m_registers; |
| 6 { | 9 RuntimeContext m_runtime; |
| 7 BoxBase[] m_data; | |
| 8 RuntimeContext m_runtimeContext; | |
| 9 | 10 |
| 10 public Frame (int size, RuntimeContext runtime) | 11 public Frame(int size, RuntimeContext runtime) { |
| 11 { | 12 if (runtime == null) |
| 12 if (size < 0) | 13 throw new ArgumentNullException("runtime"); |
| 13 throw new ArgumentOutOfRangeException ("size"); | 14 if (size < 0) |
| 14 if (runtime == null) | 15 throw new ArgumentOutOfRangeException("size"); |
| 15 throw new ArgumentNullException ("runtime"); | 16 m_runtime = runtime; |
| 17 m_registers = new IBox[size]; | |
| 18 } | |
| 16 | 19 |
| 17 m_data = new BoxBase[size]; | 20 public IBox this[int index] { |
| 18 m_runtimeContext = runtime; | 21 get { |
| 19 } | 22 return m_registers[index]; |
| 23 } | |
| 24 set { | |
| 25 m_registers[index] = value; | |
| 26 } | |
| 27 } | |
| 20 | 28 |
| 21 public RuntimeContext Runtime { | 29 public T GetValue<T>(int index) { |
| 22 get { return m_runtimeContext; } | 30 // TODO handle conversion errors |
| 23 } | 31 return ((Box<T>)m_registers[index]).holdingValue; |
| 32 } | |
| 24 | 33 |
| 25 public T Get<T> (int index) | 34 public void SetValue<T>(int index, T value) { |
| 26 { | 35 var reg = m_registers[index] as Box<T>; |
| 27 var bbox = m_data [index]; | 36 if (reg == null) |
| 28 | 37 m_registers[index] = m_runtime.BoxValue(value); |
| 29 if (bbox == null) | 38 else |
| 30 return default(T); | 39 reg.holdingValue = value; |
| 31 | 40 } |
| 32 var box = bbox as IGetter<T>; | 41 } |
| 33 if (box != null) | |
| 34 return box.Get(); | |
| 35 else | |
| 36 return bbox.Convert<T>(); | |
| 37 } | |
| 38 | |
| 39 public void Set<T> (int index, T value) | |
| 40 { | |
| 41 var bbox = m_data [index]; | |
| 42 var box = bbox as ISetter<T>; | |
| 43 if (box != null) | |
| 44 box.Set (value); | |
| 45 else | |
| 46 m_data [index] = m_runtimeContext.BoxValue(value); | |
| 47 } | |
| 48 | |
| 49 public BoxBase GetBox(int index) { | |
| 50 return m_data[index]; | |
| 51 } | |
| 52 | |
| 53 public void SetBox(int index, BoxBase box) { | |
| 54 m_data [index] = box; | |
| 55 } | |
| 56 | |
| 57 } | |
| 58 } | 42 } |
| 59 |
