Skip to content

Commit

Permalink
Debugger changes and Xamarin first support
Browse files Browse the repository at this point in the history
  • Loading branch information
xanathar committed Dec 6, 2014
1 parent 2dd128e commit 9137b62
Show file tree
Hide file tree
Showing 38 changed files with 1,023 additions and 47 deletions.
26 changes: 24 additions & 2 deletions src/Flash/org.moonsharp.debugger.client/src/DebuggerViewLogic.as
Expand Up @@ -26,6 +26,8 @@ package

private var m_InstructionPtrHighlight : Highlight = null;

private var m_ErrorRx:String;


public function DebuggerViewLogic(view : Main, loaderInfo: LoaderInfo)
{
Expand Down Expand Up @@ -128,6 +130,10 @@ package
{
refreshBreakpoints(xml);
}
else if (cmd == "error_rx")
{
m_ErrorRx = xml.@arg;
}
}

public function getInstructionPtrHighlight():Highlight
Expand Down Expand Up @@ -264,14 +270,30 @@ package
}


public function toggleBreakpoint(src:int, line:int, col:int) : void
public function toggleBreakpoint(src:int, line:int, col:int, action:String) : void
{
var cmd:XML = <Command cmd="breakpoint" arg="toggle" />;
var cmd:XML = <Command cmd="breakpoint" />;
cmd.@arg = action;
cmd.@src = src;
cmd.@line = line;
cmd.@col = col;
m_Socket.send(cmd);
}

public function getErrorRx():String
{
return m_ErrorRx;
}

public function setErrorRx(val:String):void
{
m_ErrorRx = val;
var cmd:XML = <Command cmd="error_rx" />;
cmd.@arg = val;
m_Socket.send(cmd);
}



}
}
30 changes: 26 additions & 4 deletions src/Flash/org.moonsharp.debugger.client/src/Main.mxml
Expand Up @@ -51,9 +51,14 @@
<menuitem label="(R) - Run" data="run" icon="run" />
<menuitem label="(P) - Pause" data="pause" icon="pause" />
<menuitem type="separator"/>
<menuitem label="(G) - Go to current" data="step_current" icon="step_current" />
</menuitem>
<menuitem label="Breakpoints" data="top">
<menuitem label="(B) - Toggle breakpoint" data="breakpoint" icon="breakpoint" />
<menuitem label="Set breakpoint" data="set_breakpoint" />
<menuitem label="Clear breakpoint" data="clear_breakpoint" />
<menuitem type="separator"/>
<menuitem label="(G) - Go to current" data="step_current" icon="step_current" />
<menuitem label="(E) - Errors break regex..." data="error_rx" />
</menuitem>
<menuitem label="Watches" data="top">
<menuitem label="(Ins) - Add watches..." data="add" icon="add" />
Expand Down Expand Up @@ -238,15 +243,15 @@
event.preventDefault();
}
protected function toggleBreakpoint() : void
protected function toggleBreakpoint(cmdType:String) : void
{
if (m_CurrentSrc == null) return;
var cursor:int = txtCode.selectionActivePosition;
var line:int = m_CurrentSrc.inflateLocationLine(cursor);
var col:int = m_CurrentSrc.inflateLocationColumn(cursor, line);
m_Debugger.toggleBreakpoint(m_CurrentSrc.getId(), line, col);
m_Debugger.toggleBreakpoint(m_CurrentSrc.getId(), line, col, cmdType);
}
protected function moveCaret(where : int) : void
Expand Down Expand Up @@ -280,7 +285,24 @@
else if (cmd == "run") m_Debugger.run();
else if (cmd == "pause") m_Debugger.pause();
else if (cmd == "step_current") refreshInstructionPtrHighlight(true);
else if (cmd == "breakpoint") toggleBreakpoint();
else if (cmd == "breakpoint") toggleBreakpoint("toggle");
else if (cmd == "set_breakpoint") toggleBreakpoint("set");
else if (cmd == "clear_breakpoint") toggleBreakpoint("clear");
else if (cmd == "error_rx")
{
m_DisableKeys = true;
InputBox.show(this, "Error RegEx",
"Insert a regular expression which matches error messages you want to stop on.", m_Debugger.getErrorRx(),
function(str:String):void
{
m_DisableKeys = false;
if (str !== null && str !== "")
m_Debugger.setErrorRx(str);
});
}
else if (cmd == "add")
{
m_DisableKeys = true;
Expand Down
2 changes: 1 addition & 1 deletion src/Flash/org.moonsharp.debugger.client/src/Version.as
Expand Up @@ -2,7 +2,7 @@ package
{
public final class Version
{
public static var Version : String = "0.7.0.2";
public static var Version : String = "0.8.0.0";


public function Version()
Expand Down
7 changes: 7 additions & 0 deletions src/MoonSharp.Debugger/MainForm.cs
Expand Up @@ -428,5 +428,12 @@ public void SignalExecutionEnded()
public void RefreshBreakpoints(IEnumerable<SourceRef> refs)
{
}


public bool SignalRuntimeException(ScriptRuntimeException ex)
{
Console_WriteLine("Error: {0}", ex.DecoratedMessage);
return true;
}
}
}
16 changes: 16 additions & 0 deletions src/MoonSharp.Interpreter.Tests/EndToEnd/DynamicTests.cs
Expand Up @@ -85,5 +85,21 @@ function f()
//Assert.AreEqual(6, res.Number);
}

[Test]
public void DynamicAccessFromCSharp()
{
string code = @"
t = { ciao = { 'hello' } }
";

Script script = new Script();
script.DoString(code);

DynValue v = script.CreateDynamicExpression("t.ciao[1] .. ' world'").Evaluate();

Assert.AreEqual(v.String, "hello world");
}


}
}
104 changes: 104 additions & 0 deletions src/MoonSharp.Interpreter.Tests/EndToEnd/TableTests.cs
Expand Up @@ -340,5 +340,109 @@ function reader ()
Assert.AreEqual(DataType.Nil, res.Tuple[0].Type);
Assert.AreEqual(DataType.String, res.Tuple[1].Type);
}


[Test]
public void TableSimplifiedAccess1()
{
string script = @"
t = {
ciao = 'hello'
}
return t;
";

Script s = new Script();
DynValue t = s.DoString(script);

Assert.AreEqual("hello", t.Table["ciao"]);
}

[Test]
public void TableSimplifiedAccess2()
{
string script = @"
t = {
ciao = x
}
return t;
";

Script s = new Script();
s.Globals["x"] = "hello";
DynValue t = s.DoString(script);

Assert.AreEqual("hello", t.Table["ciao"]);
}

[Test]
public void TableSimplifiedAccess3()
{
string script = @"
t = {
}
return t;
";

Script s = new Script();
DynValue t = s.DoString(script);

s.Globals["t", "ciao"] = "hello";

Assert.AreEqual("hello", t.Table["ciao"]);
}

[Test]
public void TableSimplifiedAccess4()
{
string script = @"
t = {
}
";

Script s = new Script();
s.DoString(script);

s.Globals["t", "ciao"] = "hello";

Assert.AreEqual("hello", s.Globals["t", "ciao"]);
}


[Test]
public void TableSimplifiedAccess5()
{
string script = @"
t = {
ciao = 'hello'
}
";

Script s = new Script();
s.DoString(script);

Assert.AreEqual("hello", s.Globals["t", "ciao"]);
}

[Test]
public void TableSimplifiedAccess6()
{
string script = @"
t = {
ciao =
{ 'hello' }
}
";

Script s = new Script();
s.DoString(script);

Assert.AreEqual("hello", s.Globals["t", "ciao", 1]);
}


}
}
102 changes: 87 additions & 15 deletions src/MoonSharp.Interpreter/DataTypes/Table.cs
Expand Up @@ -57,40 +57,112 @@ private int GetIntegralKey(double d)
}

/// <summary>
/// Gets or sets the <see cref="System.Object"/> with the specified key.
/// Gets or sets the <see cref="System.Object"/> with the specified key(s).
/// This will marshall CLR and MoonSharp objects in the best possible way.
/// Multiple keys can be used to access subtables.
/// </summary>
/// <value>
/// The <see cref="System.Object"/>.
/// </value>
/// <param name="key">The key.</param>
/// <returns></returns>
public object this[object key]
public object this[object key, params object[] subkeys]
{
get
{
if (key is string)
return Get((string)key).ToObject();
else if (key is int)
return Get((int)key).ToObject();
Table t = ResolveMultipleKeys(ref key, subkeys);
return t.GetAsObject(key);
}

DynValue dynkey = DynValue.FromObject(this.OwnerScript, key);
return Get(dynkey).ToObject();
set
{
Table t = ResolveMultipleKeys(ref key, subkeys);
t.SetAsObject(key, value);
}
}

/// <summary>
/// Gets or sets the <see cref="System.Object"/> with the specified key(s).
/// This will marshall CLR and MoonSharp objects in the best possible way.
/// </summary>
/// <value>
/// The <see cref="System.Object"/>.
/// </value>
/// <param name="key">The key.</param>
/// <returns></returns>
public object this[object key]
{
get
{
return this.GetAsObject(key);
}

set
{
DynValue dynval = DynValue.FromObject(this.OwnerScript, value);
this.SetAsObject(key, value);
}
}

if (key is string)
Set((string)key, dynval);
else if (key is int)
Set((int)key, dynval);
else
Set(DynValue.FromObject(this.OwnerScript, key), dynval);
private Table ResolveMultipleKeys(ref object key, object[] subkeys)
{
if (subkeys.Length == 0)
return this;

Table t = this;
int i = -1;

do
{
DynValue vt = t.GetWithObjectKey(key);

if (vt.Type != DataType.Table)
throw new ScriptRuntimeException("Key '{0}' did not point to a table");

t = vt.Table;
key = subkeys[++i];
}
while (i < subkeys.Length - 1);

return t;
}

public DynValue GetWithObjectKey(object key)
{
if (key is string)
return Get((string)key);
else if (key is int)
return Get((int)key);

DynValue dynkey = DynValue.FromObject(this.OwnerScript, key);
return Get(dynkey);
}


public object GetAsObject(object key)
{
if (key is string)
return Get((string)key).ToObject();
else if (key is int)
return Get((int)key).ToObject();

DynValue dynkey = DynValue.FromObject(this.OwnerScript, key);
return Get(dynkey).ToObject();
}

public void SetAsObject(object key, object value)
{
DynValue dynval = DynValue.FromObject(this.OwnerScript, value);

if (key is string)
Set((string)key, dynval);
else if (key is int)
Set((int)key, dynval);
else
Set(DynValue.FromObject(this.OwnerScript, key), dynval);
}





/// <summary>
Expand Down

0 comments on commit 9137b62

Please sign in to comment.