annotate Jint.Runtime/Main.cs @ 1:033ebe7432d5

vm v2
author cin
date Thu, 24 Oct 2013 19:45:57 +0400
parents e113095f1de0
children 4aed85a1f558
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;
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
2 using Jint.Runtime.VM.OpCodes;
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;
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
7 using System.IO;
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
8 class MainClass
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
9 {
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
10 public static void Main(string[] args)
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
11 {
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
12 var runtime = new RuntimeContext ();
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
13
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
14 var frame = new Frame (3,runtime);
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
15
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
16 frame.Set (0, 0);
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
17 frame.Set (1, 1);
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
18
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
19 var op = new Add (0,1,0);
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
20
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
21 var t = Environment.TickCount;
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
22
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
23 for(int i=0; i < 10000000; i++)
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
24 op.Invoke (frame);
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
25
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
26 var res = frame.Get<int> (0);
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
27
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
28 Console.WriteLine ("got: {0}, int {1} ms", res, Environment.TickCount - t );
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
29
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
30 t = Environment.TickCount;
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
31
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
32 object count = 0, inc = 1;
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
33 for (int i=0; i< 10000000; i++)
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
34 count = OpAdd(count,inc);
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
35
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
36 Console.WriteLine ("reference results: {0}, int {1} ms", count, Environment.TickCount - t );
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
37 }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
38
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
39 public static object OpAdd(object arg1, object arg2) {
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
40 if (arg1.GetType () == arg2.GetType ()) {
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
41 return OpAddIntegers(arg1,arg2);
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
42 }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
43 throw new Exception ();
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
44 }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
45
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
46 public static object OpAddIntegers(object arg1, object arg2) {
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
47 return (int)arg1 + (int)arg2;
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
48 }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
49 }
e113095f1de0 initial commit, proof of concept
cin
parents:
diff changeset
50 }