annotate Jint.Runtime/Main.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 4aed85a1f558
children cb13da6e3349
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;
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
2 using Jint.Runtime.VM;
0
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
3
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
4 namespace Jint.Runtime
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
5 {
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
6 using VM;
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
7 using System.IO;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
8 using Jint.Runtime.VM.OpCodes;
0
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
9 class MainClass
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
10 {
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
11 public static void Main(string[] args)
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
12 {
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
13 RuntimeContext runtime = new RuntimeContext();
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
14 runtime.DefineBinaryOperation<int>(Codes.Add, (x, y) => x + y);
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
15
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
16 var frame = new Frame(4,runtime);
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
17 frame.SetValue(2,0);
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
18 frame.SetValue(3,1);
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
19
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
20 var op = new BinaryOp(Codes.Add, 2, 3, 2);
0
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
21
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
22 var t = Environment.TickCount;
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
23
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
24 /*
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
25 * mov r1, 10 000 000
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
26 * mov r2, 0
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
27 * mov r3, 1
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
28 * loop
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
29 * condition:
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
30 * gte r2, r1
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
31 * body:
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
32 * add r2,r3,r2
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
33 */
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
34
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
35 for (int i = 0; i < 10000000; i++)
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
36 op.Invoke(frame);
0
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
37
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
38 Console.WriteLine ("vm: {0}, int {1} ms", frame.GetValue<int>(2), Environment.TickCount - t );
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
39
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
40 t = Environment.TickCount;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
41
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
42 /*
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
43 * mov r1, 10 000 000
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
44 * mov r2, 0
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
45 * mov r3, 1
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
46 * loop
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
47 * condition:
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
48 * gte r2, r1
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
49 * body:
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
50 * add r2,r3,r2
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
51 */
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
52 object count = 0, inc = 1;
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
53
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
54 for (int i = 0; i < 10000000; i++)
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
55 count = Add(count,inc);
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
56
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
57 Console.WriteLine("native: {0}, int {1} ms", frame.GetValue<int>(2), Environment.TickCount - t);
0
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
58
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
59 t = Environment.TickCount;
3
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
60 }
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
61
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
62 public static object Add(object arg1, object arg2) {
aced2ae9957f temp commit, new virtual machine concept (strongly typed version of VM2).
cin
parents: 2
diff changeset
63 return (int)arg1 + (int)arg2;
0
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
64 }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
65 }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
66 }