1
|
1 using System;
|
|
2 using System.Collections.Generic;
|
|
3
|
|
4 namespace Jint.Runtime.VM2
|
|
5 {
|
|
6 public class Machine
|
|
7 {
|
|
8 RuntimeContext m_context;
|
2
|
9 //Stack<object[]> m_frames;
|
|
10 Box[] m_frame;
|
1
|
11
|
|
12
|
|
13 public Machine ()
|
|
14 {
|
2
|
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]);
|
1
|
22 }
|
|
23
|
|
24 public void Execute(Instruction[] instructions) {
|
|
25 foreach (var op in instructions) {
|
2
|
26 m_frame [op.dest].value = m_frame [op.args [0]].impl [(int)op.code](MakeArgs(op.args));
|
1
|
27 }
|
|
28 }
|
|
29
|
|
30 private object[] MakeArgs(int[] regs) {
|
|
31 object[] args = new object[regs.Length];
|
|
32 for (int i=0; i< regs.Length; i++)
|
2
|
33 args[i] = m_frame [regs [i]].value;
|
|
34 return args;
|
|
35 }
|
|
36
|
|
37 public object Get(int index) {
|
|
38 return m_frame [index];
|
1
|
39 }
|
|
40 }
|
|
41 }
|
|
42
|