Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1557 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
8 changed files with 366 additions and 81 deletions
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: User |
||||
* Date: 10/07/2006 |
||||
* Time: 01:47 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
|
||||
using System; |
||||
|
||||
using Debugger.Wrappers.CorDebug; |
||||
using Debugger.Wrappers.MetaData; |
||||
|
||||
namespace Debugger |
||||
{ |
||||
public class InterpreterWrapper |
||||
{ |
||||
const string booDll = "Boo.Lang.Interpreter.dll"; |
||||
|
||||
NDebugger debugger; |
||||
PersistentValue interpreter; |
||||
|
||||
public NDebugger Debugger { |
||||
get { |
||||
return debugger; |
||||
} |
||||
} |
||||
|
||||
public static InterpreterWrapper InjectBooInterpreter(NDebugger debugger, string booPath) |
||||
{ |
||||
return new InterpreterWrapper(debugger, booPath); |
||||
} |
||||
|
||||
private InterpreterWrapper(NDebugger debugger, string booInterpreterPath) |
||||
{ |
||||
this.debugger = debugger; |
||||
|
||||
PersistentValue assemblyPath = Eval.NewString(debugger, booInterpreterPath).EvaluateNow(); |
||||
PersistentValue assembly = Eval.CallFunction(debugger, "mscorlib.dll", "System.Reflection.Assembly", "LoadFrom", false, null, new PersistentValue[] {assemblyPath}).EvaluateNow(); |
||||
PersistentValue interpreterType = Eval.NewString(debugger, "Boo.Lang.Interpreter.InteractiveInterpreter").EvaluateNow(); |
||||
interpreter = Eval.CallFunction(debugger, "mscorlib.dll", "System.Reflection.Assembly", "CreateInstance", false, assembly, new PersistentValue[] {interpreterType}).EvaluateNow(); |
||||
RunCommand("interpreter.RememberLastValue = true"); |
||||
|
||||
// Testing:
|
||||
RunCommand("1 + 2"); |
||||
PersistentValue res = GetLastValue(); |
||||
SetValue("a", res); |
||||
RunCommand("a = a + 100"); |
||||
PersistentValue a = GetValue("a"); |
||||
PersistentValue sug = SuggestCodeCompletion("interpreter.__codecomplete__"); |
||||
} |
||||
|
||||
|
||||
public void RunCommand(string code) |
||||
{ |
||||
PersistentValue cmd = Eval.NewString(debugger, code).EvaluateNow(); |
||||
Eval.CallFunction(debugger, booDll, "Boo.Lang.Interpreter.InteractiveInterpreter", "LoopEval", false, interpreter, new PersistentValue[] {cmd}).EvaluateNow(); |
||||
} |
||||
|
||||
public void SetValue(string valueName, PersistentValue newValue) |
||||
{ |
||||
PersistentValue name = Eval.NewString(debugger, valueName).EvaluateNow(); |
||||
Eval.CallFunction(debugger, booDll, "Boo.Lang.Interpreter.InteractiveInterpreter", "SetValue", false, interpreter, new PersistentValue[] {name, newValue}).EvaluateNow(); |
||||
} |
||||
|
||||
public PersistentValue GetValue(string valueName) |
||||
{ |
||||
PersistentValue name = Eval.NewString(debugger, valueName).EvaluateNow(); |
||||
return Eval.CallFunction(debugger, booDll, "Boo.Lang.Interpreter.InteractiveInterpreter", "GetValue", false, interpreter, new PersistentValue[] {name}).EvaluateNow(); |
||||
} |
||||
|
||||
public PersistentValue GetLastValue() |
||||
{ |
||||
return Eval.CallFunction(debugger, booDll, "Boo.Lang.Interpreter.InteractiveInterpreter", "get_LastValue", false, interpreter, new PersistentValue[] {}).EvaluateNow(); |
||||
} |
||||
|
||||
public PersistentValue SuggestCodeCompletion(string code) |
||||
{ |
||||
PersistentValue cmd = Eval.NewString(debugger, code).EvaluateNow(); |
||||
return Eval.CallFunction(debugger, booDll, "Boo.Lang.Interpreter.AbstractInterpreter", "SuggestCodeCompletion", false, interpreter, new PersistentValue[] {cmd}).EvaluateNow(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,117 @@
@@ -0,0 +1,117 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
|
||||
// <version>$Revision: 1556 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
using Debugger.Wrappers.CorDebug; |
||||
|
||||
namespace Debugger |
||||
{ |
||||
public partial class Eval |
||||
{ |
||||
class CallFunctionEval: Eval |
||||
{ |
||||
string moduleName; |
||||
string containgType; |
||||
string functionName; |
||||
ICorDebugFunction corFunction; |
||||
PersistentValue thisValue; |
||||
PersistentValue[] args; |
||||
|
||||
static List<T> MergeLists<T>(IEnumerable<T> a, IEnumerable<T> b) |
||||
{ |
||||
List<T> newList = new List<T>(); |
||||
if (a != null) newList.AddRange(a); |
||||
if (b != null) newList.AddRange(b); |
||||
return newList; |
||||
} |
||||
|
||||
public CallFunctionEval(NDebugger debugger, string moduleName, string containgType, string functionName, bool reevaluateAfterDebuggeeStateChange, PersistentValue thisValue, PersistentValue[] args) |
||||
:this(debugger, null, reevaluateAfterDebuggeeStateChange, thisValue, args) |
||||
{ |
||||
this.moduleName = moduleName; |
||||
this.containgType = containgType; |
||||
this.functionName = functionName; |
||||
} |
||||
|
||||
public CallFunctionEval(NDebugger debugger, ICorDebugFunction corFunction, bool reevaluateAfterDebuggeeStateChange, PersistentValue thisValue, PersistentValue[] args) |
||||
:base(debugger, reevaluateAfterDebuggeeStateChange, thisValue == null? args : MergeLists(new PersistentValue[] {thisValue}, args).ToArray()) |
||||
{ |
||||
this.corFunction = corFunction; |
||||
this.thisValue = thisValue; |
||||
this.args = args; |
||||
} |
||||
|
||||
internal override bool SetupEvaluation(Thread targetThread) |
||||
{ |
||||
debugger.AssertPaused(); |
||||
|
||||
if (targetThread.IsLastFunctionNative) { |
||||
OnError("Can not evaluate because native frame is on top of stack"); |
||||
return false; |
||||
} |
||||
|
||||
if (corFunction == null) { |
||||
try { |
||||
Module module = debugger.GetModule(moduleName); |
||||
corFunction = module.GetMethod(containgType, functionName, args.Length); |
||||
} catch (DebuggerException) { |
||||
// Error thrown later on
|
||||
} |
||||
} |
||||
|
||||
List<ICorDebugValue> corArgs = new List<ICorDebugValue>(); |
||||
try { |
||||
if (thisValue != null) { |
||||
Value val = thisValue.Value; |
||||
if (!(val is ObjectValue)) { |
||||
OnError("Can not evaluate on a value which is not an object"); |
||||
return false; |
||||
} |
||||
if (corFunction != null && !((ObjectValue)val).IsSuperClass(corFunction.Class)) { |
||||
OnError("Can not evaluate because the object does not contain specified function"); |
||||
return false; |
||||
} |
||||
corArgs.Add(thisValue.SoftReference); |
||||
} |
||||
foreach(PersistentValue arg in args) { |
||||
corArgs.Add(arg.SoftReference); |
||||
} |
||||
} catch (CannotGetValueException e) { |
||||
OnError(e.Message); |
||||
return false; |
||||
} |
||||
|
||||
if (corFunction == null) { |
||||
OnError("Can not find or load function " + functionName); |
||||
return false; |
||||
} |
||||
|
||||
// TODO: What if this thread is not suitable?
|
||||
corEval = targetThread.CorThread.CreateEval(); |
||||
|
||||
try { |
||||
corEval.CallFunction(corFunction, (uint)corArgs.Count, corArgs.ToArray()); |
||||
} catch (COMException e) { |
||||
if ((uint)e.ErrorCode == 0x80131C26) { |
||||
OnError("Can not evaluate in optimized code"); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
EvalState = EvalState.Evaluating; |
||||
|
||||
OnEvalStarted(new EvalEventArgs(this)); |
||||
|
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
|
||||
// <version>$Revision: 1556 $</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
using Debugger.Wrappers.CorDebug; |
||||
|
||||
namespace Debugger |
||||
{ |
||||
public partial class Eval |
||||
{ |
||||
class NewStringEval: Eval |
||||
{ |
||||
string textToCreate; |
||||
|
||||
public NewStringEval(NDebugger debugger, string textToCreate):base(debugger, false, new IExpirable[] {}) |
||||
{ |
||||
this.textToCreate = textToCreate; |
||||
} |
||||
|
||||
internal override bool SetupEvaluation(Thread targetThread) |
||||
{ |
||||
debugger.AssertPaused(); |
||||
|
||||
if (targetThread.IsLastFunctionNative) { |
||||
OnError("Can not evaluate because native frame is on top of stack"); |
||||
return false; |
||||
} |
||||
|
||||
// TODO: What if this thread is not suitable?
|
||||
corEval = targetThread.CorThread.CreateEval(); |
||||
|
||||
try { |
||||
corEval.NewString(textToCreate); |
||||
} catch (COMException e) { |
||||
if ((uint)e.ErrorCode == 0x80131C26) { |
||||
OnError("Can not evaluate in optimized code"); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
EvalState = EvalState.Evaluating; |
||||
|
||||
OnEvalStarted(new EvalEventArgs(this)); |
||||
|
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue