Skip to content

Commit 99491e3

Browse files
committed
fix the stack checker
1 parent e1d867f commit 99491e3

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

source/stackCheck.d

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,12 @@ class StackChecker {
137137
) {
138138
Push(node, 1);
139139
}
140-
else {
141-
Error(node.error, "Unknown word '%s'", node.name);
140+
else switch (node.name) {
141+
case "throw": {
142+
Pop(node, 1);
143+
break;
144+
}
145+
default: Error(node.error, "Unknown word '%s'", node.name);
142146
}
143147
}
144148

@@ -173,15 +177,32 @@ class StackChecker {
173177
identifiers = oldIdentifiers;
174178
}
175179

180+
private void EvaluateSingleIf(IfNode node) {
181+
auto oldStack = stack.dup;
182+
Evaluate(node.condition[0]);
183+
184+
Pop(node, 1);
185+
oldStack = stack.dup;
186+
187+
Evaluate(node.doIf[0]);
188+
189+
if (oldStack.length != stack.length) {
190+
Error(node.error, "Single if condition must have a body with no stack effect");
191+
}
192+
}
193+
176194
void EvaluateIf(IfNode node) {
177195
bool setExpect = false;
178196
size_t expectSize;
179197
string note;
180198
bool allowCondPop = false;
181199

182200
if (!node.hasElse && (node.condition.length == 1)) {
183-
allowCondPop = true;
184-
note = "Single if condition must have no stack effect";
201+
EvaluateSingleIf(node);
202+
return;
203+
// allowCondPop = true;
204+
// setExpect = true;
205+
// note = "Single if condition must have a body with no stack effect";
185206
}
186207
else if (node.hasElse) {
187208
auto oldStack = stack.dup;

0 commit comments

Comments
 (0)