Skip to content

Commit

Permalink
fix debugger set value
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbeamable committed Feb 27, 2025
1 parent ef5c336 commit c3c4cf1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions FadeBasic/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Debugger would emit exit event during partial budget runs.
- Debugger can render `byte` variables.
- Debugger can set non `int` and non `float` values.
- Commands with `ref` parameters can access globally scoped variables.

### Added
Expand Down
12 changes: 11 additions & 1 deletion FadeBasic/FadeBasic/Launch/DebugSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -841,11 +841,21 @@ void AddVariable(DebugVariable local, bool isGlobal)
{
finalDeclare = null;
// TypeInfo.FromVariableType()

var finalType = finalStatement.expression.ParsedType.type;
if (overwriteVariableId > 1 && variableDb.TryGetTypeCodeForVariableId(overwriteVariableId, out var finaltypeCode))
{
if (!VmUtil.TryGetVariableType(finaltypeCode, out finalType))
{
throw new Exception("invalid type code");
}
}

finalDeclare = new DeclarationStatement(new Token
{
caseInsensitiveRaw = "local"
}, new VariableRefNode(Token.Blank, SYNTHETIC_NAME2),
new TypeReferenceNode(finalStatement.expression.ParsedType.type, Token.Blank));
new TypeReferenceNode(finalType, Token.Blank));
node.statements.Insert(node.statements.Count - 1, finalDeclare);
}

Expand Down
15 changes: 15 additions & 0 deletions FadeBasic/FadeBasic/Virtual/DebugUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,21 @@ public DebugEvalResult AddWatchedExpression(DebugRuntimeVariable runtimeSynth, C
return res;
}

public bool TryGetTypeCodeForVariableId(int variableId, out byte typeCode)
{
typeCode = TypeCodes.ANY;
if (idToVariable.TryGetValue(variableId, out var dbgVar) && dbgVar.runtimeVariable != null)
{
typeCode = dbgVar.runtimeVariable.typeCode;
return true;
} else if (idToTopLevelVariable.TryGetValue(variableId, out var tuple))
{
typeCode = tuple.Item2.typeCode;
return true;
}

return false;
}

public bool TrySetValue(int variableId, int valueId, out string error)
{
Expand Down
13 changes: 13 additions & 0 deletions FadeBasic/Tests/DebuggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ public async Task Exploration_Eval(string src, string evalGroup, string expected
[TestCase(@"`basic float
x# = 5.2
", "x#", "8.3", "8.3", 3, new int[]{})]

[TestCase(@"`basic float (but looks like int)
x# = 5.2
", "x#", "8", "8", 3, new int[]{})]

[TestCase(@"`basic byte
x as byte = 5
", "x", "8", "8", 3, new int[]{})]

[TestCase(@"`basic double integer
x as double integer = 5
", "x", "8", "8", 3, new int[]{})]

[TestCase(@"`accessor
type vec
x
Expand Down

0 comments on commit c3c4cf1

Please sign in to comment.