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