Skip to content

Commit c3c4cf1

Browse files
committed
fix debugger set value
1 parent ef5c336 commit c3c4cf1

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

FadeBasic/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111
- Debugger would emit exit event during partial budget runs.
1212
- Debugger can render `byte` variables.
13+
- Debugger can set non `int` and non `float` values.
1314
- Commands with `ref` parameters can access globally scoped variables.
1415

1516
### Added

FadeBasic/FadeBasic/Launch/DebugSession.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,11 +841,21 @@ void AddVariable(DebugVariable local, bool isGlobal)
841841
{
842842
finalDeclare = null;
843843
// TypeInfo.FromVariableType()
844+
845+
var finalType = finalStatement.expression.ParsedType.type;
846+
if (overwriteVariableId > 1 && variableDb.TryGetTypeCodeForVariableId(overwriteVariableId, out var finaltypeCode))
847+
{
848+
if (!VmUtil.TryGetVariableType(finaltypeCode, out finalType))
849+
{
850+
throw new Exception("invalid type code");
851+
}
852+
}
853+
844854
finalDeclare = new DeclarationStatement(new Token
845855
{
846856
caseInsensitiveRaw = "local"
847857
}, new VariableRefNode(Token.Blank, SYNTHETIC_NAME2),
848-
new TypeReferenceNode(finalStatement.expression.ParsedType.type, Token.Blank));
858+
new TypeReferenceNode(finalType, Token.Blank));
849859
node.statements.Insert(node.statements.Count - 1, finalDeclare);
850860
}
851861

FadeBasic/FadeBasic/Virtual/DebugUtil.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,21 @@ public DebugEvalResult AddWatchedExpression(DebugRuntimeVariable runtimeSynth, C
576576
return res;
577577
}
578578

579+
public bool TryGetTypeCodeForVariableId(int variableId, out byte typeCode)
580+
{
581+
typeCode = TypeCodes.ANY;
582+
if (idToVariable.TryGetValue(variableId, out var dbgVar) && dbgVar.runtimeVariable != null)
583+
{
584+
typeCode = dbgVar.runtimeVariable.typeCode;
585+
return true;
586+
} else if (idToTopLevelVariable.TryGetValue(variableId, out var tuple))
587+
{
588+
typeCode = tuple.Item2.typeCode;
589+
return true;
590+
}
591+
592+
return false;
593+
}
579594

580595
public bool TrySetValue(int variableId, int valueId, out string error)
581596
{

FadeBasic/Tests/DebuggerTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ public async Task Exploration_Eval(string src, string evalGroup, string expected
170170
[TestCase(@"`basic float
171171
x# = 5.2
172172
", "x#", "8.3", "8.3", 3, new int[]{})]
173+
174+
[TestCase(@"`basic float (but looks like int)
175+
x# = 5.2
176+
", "x#", "8", "8", 3, new int[]{})]
177+
178+
[TestCase(@"`basic byte
179+
x as byte = 5
180+
", "x", "8", "8", 3, new int[]{})]
181+
182+
[TestCase(@"`basic double integer
183+
x as double integer = 5
184+
", "x", "8", "8", 3, new int[]{})]
185+
173186
[TestCase(@"`accessor
174187
type vec
175188
x

0 commit comments

Comments
 (0)