annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
1 using System;
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
2
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
3 namespace Jint.Runtime.VM
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
4 {
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
5 public class Frame
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
6 {
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
7 BoxBase[] m_data;
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
8 RuntimeContext m_runtimeContext;
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
9
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
10 public Frame (int size, RuntimeContext runtime)
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
11 {
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
12 if (size < 0)
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
13 throw new ArgumentOutOfRangeException ("size");
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
14 if (runtime == null)
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
15 throw new ArgumentNullException ("runtime");
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
16
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
17 m_data = new BoxBase[size];
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
18 m_runtimeContext = runtime;
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
19 }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
20
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
21 public RuntimeContext Runtime {
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
22 get { return m_runtimeContext; }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
23 }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
24
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
25 public T Get<T> (int index)
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
26 {
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
27 var bbox = m_data [index];
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
28
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
29 if (bbox == null)
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
30 return default(T);
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
31
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
32 var box = bbox as IGetter<T>;
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
33 if (box != null)
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
34 return box.Get();
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
35 else
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
36 return bbox.Convert<T>();
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
37 }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
38
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
39 public void Set<T> (int index, T value)
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
40 {
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
41 var bbox = m_data [index];
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
42 var box = bbox as ISetter<T>;
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
43 if (box != null)
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
44 box.Set (value);
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
45 else
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
46 m_data [index] = m_runtimeContext.BoxValue(value);
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
47 }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
48
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
49 public BoxBase GetBox(int index) {
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
50 return m_data[index];
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
51 }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
52
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
53 public void SetBox(int index, BoxBase box) {
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
54 m_data [index] = box;
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
55 }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
56
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
57 }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
58 }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
59