annotate Jint.Runtime/VM/Box.cs @ 4:1ae5b10f7a10

Code cleanup, minor refactoring
author cin
date Sun, 27 Oct 2013 21:20:59 +0400
parents aced2ae9957f
children cb13da6e3349
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;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
6
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
7 namespace Jint.Runtime.VM {
4
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
8 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
9
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
10 public T holdingValue;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
11 object[] m_impl;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
12 RuntimeContext m_runtime;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
13
4
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
14 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
15 if (runtime == null)
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
16 throw new ArgumentNullException("runtime");
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
17
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
18 holdingValue = value;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
19 m_runtime = runtime;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
20 }
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
21
4
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
22 object[] Impl {
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
23 get {
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
24 if (m_impl == null)
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
25 m_impl = m_runtime.GetImpl(typeof(T));
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
26 return m_impl;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
27 }
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
28 }
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 public T Get() {
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
31 return holdingValue;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
32 }
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
33
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
34 public void Set(T value) {
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
35 holdingValue = value;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
36 }
4
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
37
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
38 public override void InvokeBinaryOperation(Codes code, int arg2, int dest, Frame frame) {
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
39 var op = (BinaryOperation<T>)Impl[(int)code];
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
40 frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2)));
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
41 }
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
42
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
43 public override void InvokeUnaryOperation(Codes code, int dest, Frame frame) {
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
44 var op = (UnaryOperation<T>)Impl[(int)code];
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
45 frame.SetValue(dest, op(holdingValue));
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
46 }
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 InvokeCompareOperation(int arg2, int dest, Frame frame) {
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
49 var op = (CompareOperation<T>)Impl[(int)Codes.Cmp];
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 InvokeEqualityOperation(int arg2, int dest, Frame frame) {
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
54 var op = (EqualityOperation<T>)Impl[(int)Codes.Cmp];
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
55 frame.SetValue(dest, op(holdingValue, frame.GetValue<T>(arg2)));
1ae5b10f7a10 Code cleanup, minor refactoring
cin
parents: 3
diff changeset
56 }
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
57 }
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 0
diff changeset
58 }