Skip to content

Commit

Permalink
Fix string optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
colinator27 committed Mar 1, 2025
1 parent cb91ad8 commit 2529a1b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Underanalyzer/Compiler/Nodes/BinaryChainNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public IASTNode Duplicate(ParseContext context)
new NumberNode(leftInt64.Value + rightNumber.Value, leftInt64.NearbyToken),
(BinaryOperation.Add, Int64Node leftInt64, Int64Node rightInt64) =>
new Int64Node(leftInt64.Value + rightInt64.Value, leftInt64.NearbyToken),
(BinaryOperation.Add, StringNode leftString, Int64Node rightString) =>
(BinaryOperation.Add, StringNode leftString, StringNode rightString) =>
new StringNode(leftString.Value + rightString.Value, leftString.NearbyToken),

(BinaryOperation.Subtract, NumberNode leftNumber, NumberNode rightNumber) =>
Expand Down
14 changes: 14 additions & 0 deletions UnderanalyzerTest/BytecodeContext.GenerateCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2431,4 +2431,18 @@ pop.v.i self.a
"""
);
}

[Fact]
public void TestStringOptimization()
{
TestUtil.AssertBytecode(
"""
a = "b" + "c" + "d";
""",
"""
push.s "bcd"
pop.v.s self.a
"""
);
}
}

0 comments on commit 2529a1b

Please sign in to comment.