diff --git a/CLRSharp/CLRSharp/Execute/StackFrame.cs b/CLRSharp/CLRSharp/Execute/StackFrame.cs index 3bbdec5..8b67aeb 100644 --- a/CLRSharp/CLRSharp/Execute/StackFrame.cs +++ b/CLRSharp/CLRSharp/Execute/StackFrame.cs @@ -208,12 +208,19 @@ public void Init(CodeBody body) } public object Return() { - + if (_params != null) + { + foreach (var i in _params) + { + VBox box = i as VBox; + if (box != null) + ValueOnStack.UnUse(box); + } + } this.slotVar.ClearVBox(); if (this.stackCalc.Count == 0) return null; object ret = stackCalc.Pop(); this.stackCalc.ClearVBox(); - return ret; } void FillArray(object array, byte[] bytes) @@ -1013,7 +1020,16 @@ public void Set(object obj) { if (type == RefType.arg) { - frame._params[pos] = obj; + var p = frame._params[pos]; + if (p is VBox) + { + if (obj is VBox) + ((VBox)p).Set((VBox)obj); + else + ((VBox)p).SetDirect(obj); + } + else + frame._params[pos] = obj; } else if (type == RefType.loc) { @@ -1021,7 +1037,16 @@ public void Set(object obj) { frame.slotVar.Add(null); } - frame.slotVar[pos] = obj; + var loc = frame.slotVar[pos]; + if (loc is VBox) + { + if (obj is VBox) + ((VBox)loc).Set((VBox)obj); + else + ((VBox)loc).SetDirect(obj); + } + else + frame.slotVar[pos] = obj; } else if (type == RefType.field) { @@ -1242,15 +1267,22 @@ public VBox GetVBox(object obj) } return box; } - - - - - - - - - + + public VBox GetVBoxCloned(object obj) + { + VBox box = null; + if (obj is VBox) + { + box = obj as VBox; + box = box.Clone(); + } + else + { + box = ValueOnStack.MakeVBox(obj.GetType()); + box.SetDirect(obj); + } + return box; + } public void Sub() { @@ -2678,6 +2710,7 @@ public void Switch(ThreadContext context, int[] index) //_pos = poss[pos]; } } + public void Ldind_I1() { object obje = stackCalc.Pop(); @@ -2685,15 +2718,14 @@ public void Ldind_I1() { RefObj _ref = obje as RefObj; object value = _ref.Get(); - VBox box = ValueOnStack.MakeVBox(value.GetType()); - box.SetDirect(value); - stackCalc.Push(box); + stackCalc.Push(GetVBoxCloned(value)); _codepos++; return; } throw new Exception("not impl Ldind_I1:"); //_codepos++; } + public void Ldind_U1() { object obje = stackCalc.Pop(); @@ -2701,9 +2733,7 @@ public void Ldind_U1() { RefObj _ref = obje as RefObj; object value = _ref.Get(); - VBox box = ValueOnStack.MakeVBox(value.GetType()); - box.SetDirect(value); - stackCalc.Push(box); + stackCalc.Push(GetVBoxCloned(value)); _codepos++; return; } @@ -2717,9 +2747,7 @@ public void Ldind_I2() { RefObj _ref = obje as RefObj; object value = _ref.Get(); - VBox box = ValueOnStack.MakeVBox(value.GetType()); - box.SetDirect(value); - stackCalc.Push(box); + stackCalc.Push(GetVBoxCloned(value)); _codepos++; return; } @@ -2733,9 +2761,7 @@ public void Ldind_U2() { RefObj _ref = obje as RefObj; object value = _ref.Get(); - VBox box = ValueOnStack.MakeVBox(value.GetType()); - box.SetDirect(value); - stackCalc.Push(box); + stackCalc.Push(GetVBoxCloned(value)); _codepos++; return; } @@ -2749,9 +2775,7 @@ public void Ldind_I4() { RefObj _ref = obje as RefObj; object value = _ref.Get(); - VBox box = ValueOnStack.MakeVBox(value.GetType()); - box.SetDirect(value); - stackCalc.Push(box); + stackCalc.Push(GetVBoxCloned(value)); _codepos++; return; } @@ -2765,9 +2789,7 @@ public void Ldind_U4() { RefObj _ref = obje as RefObj; object value = _ref.Get(); - VBox box = ValueOnStack.MakeVBox(value.GetType()); - box.SetDirect(value); - stackCalc.Push(box); + stackCalc.Push(GetVBoxCloned(value)); _codepos++; return; } @@ -2781,9 +2803,7 @@ public void Ldind_I8() { RefObj _ref = obje as RefObj; object value = _ref.Get(); - VBox box = ValueOnStack.MakeVBox(value.GetType()); - box.SetDirect(value); - stackCalc.Push(box); + stackCalc.Push(GetVBoxCloned(value)); _codepos++; return; } @@ -2797,9 +2817,7 @@ public void Ldind_I() { RefObj _ref = obje as RefObj; object value = _ref.Get(); - VBox box = ValueOnStack.MakeVBox(value.GetType()); - box.SetDirect(value); - stackCalc.Push(box); + stackCalc.Push(GetVBoxCloned(value)); _codepos++; return; } @@ -2813,9 +2831,7 @@ public void Ldind_R4() { RefObj _ref = obje as RefObj; object value = _ref.Get(); - VBox box = ValueOnStack.MakeVBox(value.GetType()); - box.SetDirect(value); - stackCalc.Push(box); + stackCalc.Push(GetVBoxCloned(value)); _codepos++; return; } @@ -2829,9 +2845,7 @@ public void Ldind_R8() { RefObj _ref = obje as RefObj; object value = _ref.Get(); - VBox box = ValueOnStack.MakeVBox(value.GetType()); - box.SetDirect(value); - stackCalc.Push(box); + stackCalc.Push(GetVBoxCloned(value)); _codepos++; return; }