Skip to content

Commit ffc1720

Browse files
committed
see ref values
1 parent c3c4cf1 commit ffc1720

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

FadeBasic/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Debugger would emit exit event during partial budget runs.
1212
- Debugger can render `byte` variables.
1313
- Debugger can set non `int` and non `float` values.
14+
- Debugger can discovery variables declared through `ref` commands, such as
15+
`INC` or `INPUT`
1416
- Commands with `ref` parameters can access globally scoped variables.
1517

1618
### Added

FadeBasic/FadeBasic/Ast/ExpressionNode.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,12 @@ public class LiteralStringExpression : AstNode, ILiteralNode
360360

361361
public LiteralStringExpression(Token token) : base(token)
362362
{
363-
364363
value = token.raw.Substring(1, token.raw.Length - 2); // account for quotes
365364
}
365+
public LiteralStringExpression(Token token, string value) : base(token)
366+
{
367+
this.value = value;
368+
}
366369

367370

368371
protected override string GetString()

FadeBasic/FadeBasic/Virtual/Compiler.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ private void Compile(AddressExpression expression)
13601360
variable = refNode.variableName,
13611361
type = new TypeReferenceNode(refNode.DefaultTypeByName, refNode.startToken)
13621362
};
1363-
Compile(fakeDeclStatement);
1363+
Compile(fakeDeclStatement, includeDefaultInitializer: true);
13641364
if (!scope.TryGetVariable(refNode.variableName, out variable))
13651365
{
13661366
throw new Exception(
@@ -1575,7 +1575,7 @@ public void Compile(CommandStatement commandStatement)
15751575

15761576
}
15771577

1578-
public void Compile(DeclarationStatement declaration)
1578+
public void Compile(DeclarationStatement declaration, bool includeDefaultInitializer=false)
15791579
{
15801580
/*
15811581
* the declaration tells us that we need a register
@@ -1757,6 +1757,38 @@ public void Compile(DeclarationStatement declaration)
17571757
};
17581758
Compile(fakeAssignment);
17591759
}
1760+
else if (includeDefaultInitializer)
1761+
{
1762+
1763+
if (declaration.ranks == null)
1764+
{
1765+
switch (tc)
1766+
{
1767+
case TypeCodes.STRUCT:
1768+
// TODO: it isn't possible to pass structs as refs atm, but if it was, this would be a problem.
1769+
break;
1770+
case TypeCodes.STRING: // TODO: handle the empty string?
1771+
// if the variable is a string, then always assign it to the empty string, which will get interned.
1772+
var fadeStrAssignment = new AssignmentStatement
1773+
{
1774+
expression = new LiteralStringExpression(declaration.startToken, ""),
1775+
variable = new VariableRefNode(declaration.startToken, declaration.variable)
1776+
};
1777+
Compile(fadeStrAssignment);
1778+
break;
1779+
default:
1780+
// if the variable is a primitive, then always assign it to a default value.
1781+
var fakeAssignment = new AssignmentStatement
1782+
{
1783+
expression = new LiteralIntExpression(declaration.startToken, 0),
1784+
variable = new VariableRefNode(declaration.startToken, declaration.variable)
1785+
};
1786+
Compile(fakeAssignment);
1787+
break;
1788+
}
1789+
1790+
}
1791+
}
17601792
}
17611793

17621794
public void PushAddress(ArrayIndexReference arrayRefNode)

FadeBasic/Tests/DebuggerTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ dim x(3,5) as vec
7777
}
7878

7979
[TestCase("x# = 4.2", "x#+1", "5.2")]
80+
[TestCase("inc x", "x", "1")]
81+
[TestCase("tuna x$", "x$", "tuna")]
8082
[TestCase("x = 4", "x+1", "5")]
8183
[TestCase(@"
8284
x = 1

0 commit comments

Comments
 (0)