Mercurial > pub > Jint1
comparison Jint.Runtime/VM/Frame.cs @ 0:e113095f1de0
initial commit, proof of concept
author | cin |
---|---|
date | Wed, 23 Oct 2013 13:24:57 +0400 |
parents | |
children | aced2ae9957f |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e113095f1de0 |
---|---|
1 using System; | |
2 | |
3 namespace Jint.Runtime.VM | |
4 { | |
5 public class Frame | |
6 { | |
7 BoxBase[] m_data; | |
8 RuntimeContext m_runtimeContext; | |
9 | |
10 public Frame (int size, RuntimeContext runtime) | |
11 { | |
12 if (size < 0) | |
13 throw new ArgumentOutOfRangeException ("size"); | |
14 if (runtime == null) | |
15 throw new ArgumentNullException ("runtime"); | |
16 | |
17 m_data = new BoxBase[size]; | |
18 m_runtimeContext = runtime; | |
19 } | |
20 | |
21 public RuntimeContext Runtime { | |
22 get { return m_runtimeContext; } | |
23 } | |
24 | |
25 public T Get<T> (int index) | |
26 { | |
27 var bbox = m_data [index]; | |
28 | |
29 if (bbox == null) | |
30 return default(T); | |
31 | |
32 var box = bbox as IGetter<T>; | |
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 } | |
59 |