annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
1 using System;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
2 using System.Collections.Generic;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
3 using System.Linq;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
4 using System.Text;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
5 using Jint.Runtime.VM.OpCodes;
5
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
6 using System.ComponentModel;
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
7
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
8 namespace Jint.Runtime.VM {
4
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
9 class Box<T>: AbstractBox, IGettter<T>, ISetter<T> {
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
10
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
11 public T holdingValue;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
12 object[] m_impl;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
13 RuntimeContext m_runtime;
5
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
14 TypeConverter m_converter;
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
15
4
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
16 public Box(T value, RuntimeContext runtime): base(typeof(T)) {
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
17 if (runtime == null)
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
18 throw new ArgumentNullException("runtime");
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
19
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
20 holdingValue = value;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
21 m_runtime = runtime;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
22 }
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
23
4
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
24 object[] Impl {
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
25 get {
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
26 if (m_impl == null)
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
27 m_impl = m_runtime.GetImpl(typeof(T));
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
28 return m_impl;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
29 }
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
30 }
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
31
5
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
32 TypeConverter TypeConverter {
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
33 get {
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
34 if (m_converter == null)
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
35 m_converter = TypeDescriptor.GetConverter(typeof(T));
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
36 return m_converter;
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
37 }
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
38 }
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
39
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
40 public T Get() {
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
41 return holdingValue;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
42 }
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
43
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
44 public void Set(T value) {
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
45 holdingValue = value;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
46 }
4
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
47
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
48 public override void InvokeBinaryOperation(Codes code, int arg2, int dest, Frame frame) {
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
49 var op = (BinaryOperation<T>)Impl[(int)code];
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
50 frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2)));
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
51 }
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
52
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
53 public override void InvokeUnaryOperation(Codes code, int dest, Frame frame) {
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
54 var op = (UnaryOperation<T>)Impl[(int)code];
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
55 frame.SetValue(dest, op(holdingValue));
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
56 }
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
57
5
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
58 public override int InvokeCompareOperation(int arg2, Frame frame) {
4
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
59 var op = (CompareOperation<T>)Impl[(int)Codes.Cmp];
5
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
60 return op(holdingValue, frame.GetValue<T>(arg2));
4
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
61 }
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
62
5
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
63 public override bool InvokeEqualityOperation(int arg2, Frame frame) {
4
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
64 var op = (EqualityOperation<T>)Impl[(int)Codes.Cmp];
5
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
65 return op(holdingValue, frame.GetValue<T>(arg2));
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
66 }
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
67
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
68 public override T2 Convert<T2>() {
cb13da6e3349 simple loop test
cin
parents: 4
diff changeset
69 return (T2)TypeConverter.ConvertTo(holdingValue, typeof(T2));
4
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
70 }
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
71 }
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
72 }