Mercurial > pub > Jint1
comparison Jint.Runtime/VM/Box.cs @ 5:cb13da6e3349
simple loop test
author | cin |
---|---|
date | Mon, 28 Oct 2013 00:49:15 +0400 |
parents | 1ae5b10f7a10 |
children | a6329b092499 |
comparison
equal
deleted
inserted
replaced
4:1ae5b10f7a10 | 5:cb13da6e3349 |
---|---|
1 using System; | 1 using System; |
2 using System.Collections.Generic; | 2 using System.Collections.Generic; |
3 using System.Linq; | 3 using System.Linq; |
4 using System.Text; | 4 using System.Text; |
5 using Jint.Runtime.VM.OpCodes; | 5 using Jint.Runtime.VM.OpCodes; |
6 using System.ComponentModel; | |
6 | 7 |
7 namespace Jint.Runtime.VM { | 8 namespace Jint.Runtime.VM { |
8 class Box<T>: AbstractBox, IGettter<T>, ISetter<T> { | 9 class Box<T>: AbstractBox, IGettter<T>, ISetter<T> { |
9 | 10 |
10 public T holdingValue; | 11 public T holdingValue; |
11 object[] m_impl; | 12 object[] m_impl; |
12 RuntimeContext m_runtime; | 13 RuntimeContext m_runtime; |
14 TypeConverter m_converter; | |
13 | 15 |
14 public Box(T value, RuntimeContext runtime): base(typeof(T)) { | 16 public Box(T value, RuntimeContext runtime): base(typeof(T)) { |
15 if (runtime == null) | 17 if (runtime == null) |
16 throw new ArgumentNullException("runtime"); | 18 throw new ArgumentNullException("runtime"); |
17 | 19 |
22 object[] Impl { | 24 object[] Impl { |
23 get { | 25 get { |
24 if (m_impl == null) | 26 if (m_impl == null) |
25 m_impl = m_runtime.GetImpl(typeof(T)); | 27 m_impl = m_runtime.GetImpl(typeof(T)); |
26 return m_impl; | 28 return m_impl; |
29 } | |
30 } | |
31 | |
32 TypeConverter TypeConverter { | |
33 get { | |
34 if (m_converter == null) | |
35 m_converter = TypeDescriptor.GetConverter(typeof(T)); | |
36 return m_converter; | |
27 } | 37 } |
28 } | 38 } |
29 | 39 |
30 public T Get() { | 40 public T Get() { |
31 return holdingValue; | 41 return holdingValue; |
43 public override void InvokeUnaryOperation(Codes code, int dest, Frame frame) { | 53 public override void InvokeUnaryOperation(Codes code, int dest, Frame frame) { |
44 var op = (UnaryOperation<T>)Impl[(int)code]; | 54 var op = (UnaryOperation<T>)Impl[(int)code]; |
45 frame.SetValue(dest, op(holdingValue)); | 55 frame.SetValue(dest, op(holdingValue)); |
46 } | 56 } |
47 | 57 |
48 public override void InvokeCompareOperation(int arg2, int dest, Frame frame) { | 58 public override int InvokeCompareOperation(int arg2, Frame frame) { |
49 var op = (CompareOperation<T>)Impl[(int)Codes.Cmp]; | 59 var op = (CompareOperation<T>)Impl[(int)Codes.Cmp]; |
50 frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2))); | 60 return op(holdingValue, frame.GetValue<T>(arg2)); |
51 } | 61 } |
52 | 62 |
53 public override void InvokeEqualityOperation(int arg2, int dest, Frame frame) { | 63 public override bool InvokeEqualityOperation(int arg2, Frame frame) { |
54 var op = (EqualityOperation<T>)Impl[(int)Codes.Cmp]; | 64 var op = (EqualityOperation<T>)Impl[(int)Codes.Cmp]; |
55 frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2))); | 65 return op(holdingValue, frame.GetValue<T>(arg2)); |
66 } | |
67 | |
68 public override T2 Convert<T2>() { | |
69 return (T2)TypeConverter.ConvertTo(holdingValue, typeof(T2)); | |
56 } | 70 } |
57 } | 71 } |
58 } | 72 } |