Mercurial > pub > Jint1
comparison Jint.Runtime/VM2/Machine.cs @ 2:4aed85a1f558
implemented simple vm2
author | cin |
---|---|
date | Fri, 25 Oct 2013 15:52:16 +0400 |
parents | 033ebe7432d5 |
children |
comparison
equal
deleted
inserted
replaced
1:033ebe7432d5 | 2:4aed85a1f558 |
---|---|
4 namespace Jint.Runtime.VM2 | 4 namespace Jint.Runtime.VM2 |
5 { | 5 { |
6 public class Machine | 6 public class Machine |
7 { | 7 { |
8 RuntimeContext m_context; | 8 RuntimeContext m_context; |
9 Stack<object[]> m_frames; | 9 //Stack<object[]> m_frames; |
10 object[] m_frame; | 10 Box[] m_frame; |
11 | 11 |
12 | 12 |
13 public Machine () | 13 public Machine () |
14 { | 14 { |
15 m_context = new RuntimeContext (); | |
16 } | |
17 | |
18 public void InitFrame(object[] values) { | |
19 m_frame = new Box[values.Length]; | |
20 for(int i = 0; i< values.Length; i++) | |
21 m_frame[i] = m_context.PackValue(values[i]); | |
15 } | 22 } |
16 | 23 |
17 public void Execute(Instruction[] instructions) { | 24 public void Execute(Instruction[] instructions) { |
18 foreach (var op in instructions) { | 25 foreach (var op in instructions) { |
19 | 26 m_frame [op.dest].value = m_frame [op.args [0]].impl [(int)op.code](MakeArgs(op.args)); |
20 } | 27 } |
21 } | 28 } |
22 | 29 |
23 private object[] MakeArgs(int[] regs) { | 30 private object[] MakeArgs(int[] regs) { |
24 object[] args = new object[regs.Length]; | 31 object[] args = new object[regs.Length]; |
25 for (int i=0; i< regs.Length; i++) | 32 for (int i=0; i< regs.Length; i++) |
26 args = m_frame [regs [i]]; | 33 args[i] = m_frame [regs [i]].value; |
34 return args; | |
35 } | |
36 | |
37 public object Get(int index) { | |
38 return m_frame [index]; | |
27 } | 39 } |
28 } | 40 } |
29 } | 41 } |
30 | 42 |