Skip to content

Commit

Permalink
fix the stack checker
Browse files Browse the repository at this point in the history
  • Loading branch information
MESYETI committed Feb 4, 2025
1 parent e1d867f commit 99491e3
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions source/stackCheck.d
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,12 @@ class StackChecker {
) {
Push(node, 1);
}
else {
Error(node.error, "Unknown word '%s'", node.name);
else switch (node.name) {
case "throw": {
Pop(node, 1);
break;
}
default: Error(node.error, "Unknown word '%s'", node.name);
}
}

Expand Down Expand Up @@ -173,15 +177,32 @@ class StackChecker {
identifiers = oldIdentifiers;
}

private void EvaluateSingleIf(IfNode node) {
auto oldStack = stack.dup;
Evaluate(node.condition[0]);

Pop(node, 1);
oldStack = stack.dup;

Evaluate(node.doIf[0]);

if (oldStack.length != stack.length) {
Error(node.error, "Single if condition must have a body with no stack effect");
}
}

void EvaluateIf(IfNode node) {
bool setExpect = false;
size_t expectSize;
string note;
bool allowCondPop = false;

if (!node.hasElse && (node.condition.length == 1)) {
allowCondPop = true;
note = "Single if condition must have no stack effect";
EvaluateSingleIf(node);
return;
// allowCondPop = true;
// setExpect = true;
// note = "Single if condition must have a body with no stack effect";
}
else if (node.hasElse) {
auto oldStack = stack.dup;
Expand Down

0 comments on commit 99491e3

Please sign in to comment.