Mercurial > pub > Jint1
comparison Jint.Runtime/VM/Box.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; | |
5 using Jint.Runtime.VM.OpCodes; | |
2 | 6 |
3 namespace Jint.Runtime.VM | 7 namespace Jint.Runtime.VM { |
4 { | 8 class Box<T>: IBox, IGettter<T>, ISetter<T> { |
5 public class Box<T>: BoxBase, IGetter<T>, ISetter<T> | |
6 { | |
7 T m_value; | |
8 IBinder<T> m_binder; | |
9 | 9 |
10 public Box(T value,IBinder<T> binder) { | 10 public T holdingValue; |
11 m_value = value; | 11 object[] m_impl; |
12 m_binder = binder; | 12 RuntimeContext m_runtime; |
13 } | |
14 | 13 |
15 public override bool IsReference { | 14 public Box(T value, RuntimeContext runtime) { |
16 get { | 15 if (runtime == null) |
17 return true; | 16 throw new ArgumentNullException("runtime"); |
18 } | |
19 } | |
20 | 17 |
21 public override Type HoldingType | 18 holdingValue = value; |
22 { | 19 m_runtime = runtime; |
20 } | |
21 | |
22 public object[] Impl { | |
23 get { | |
24 if (m_impl == null) | |
25 m_impl = m_runtime.GetImpl(typeof(T)); | |
26 return m_impl; | |
27 } | |
28 } | |
29 | |
30 public Type HoldingType { | |
23 get { return typeof(T); } | 31 get { return typeof(T); } |
24 } | 32 } |
25 | 33 |
26 #region IGetter implementation | 34 public void InvokeBinaryOperation(Codes code, int arg2, int dest, Frame frame) { |
35 var op = (BinaryOperation<T>)Impl[(int)code]; | |
36 frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2))); | |
37 } | |
27 | 38 |
28 public T Get () | 39 public T Get() { |
29 { | 40 return holdingValue; |
30 return m_value; | 41 } |
31 } | |
32 | 42 |
33 #endregion | 43 public void Set(T value) { |
34 | 44 holdingValue = value; |
35 #region ISetter implementation | 45 } |
36 | 46 } |
37 public void Set (T value) | |
38 { | |
39 m_value = value; | |
40 } | |
41 | |
42 #endregion | |
43 | |
44 public override T2 Convert<T2> () | |
45 { | |
46 if (m_binder == null) | |
47 throw new ArgumentNullException (); | |
48 return m_binder.Convert<T2> (m_value); | |
49 } | |
50 | |
51 public override void Invoke(IBinaryOperation op, BoxBase arg2,Frame frame) { | |
52 op.Invoke (m_value, ((IGetter<T>)arg2).Get (), m_binder, frame); | |
53 } | |
54 } | |
55 } | 47 } |
56 |