Skip to content

Commit f2ec8d6

Browse files
committed
fix(translate): detect unclosed control flow and add REPEAT mismatch tests
1 parent 1f63df0 commit f2ec8d6

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

lib/Translation/ForthToMLIR/ForthToMLIR.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,11 @@ LogicalResult ForthParser::parseBody(Value &stack) {
10311031
}
10321032
}
10331033

1034+
if (!cfStack.empty()) {
1035+
cfStack.clear();
1036+
return emitError("unclosed control flow (missing THEN, REPEAT, or UNTIL?)");
1037+
}
1038+
10341039
return success();
10351040
}
10361041

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
\ RUN: %not %warpforth-translate --forth-to-mlir %s 2>&1 | %FileCheck %s
2+
\ CHECK: REPEAT without matching WHILE
3+
\! kernel main
4+
BEGIN BEGIN REPEAT
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
\ RUN: %not %warpforth-translate --forth-to-mlir %s 2>&1 | %FileCheck %s
2+
\ CHECK: REPEAT without matching WHILE
3+
\! kernel main
4+
1 IF REPEAT
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
\ RUN: %not %warpforth-translate --forth-to-mlir %s 2>&1 | %FileCheck %s
2+
\ CHECK: unclosed control flow (missing THEN, REPEAT, or UNTIL?)
3+
\! kernel main
4+
BEGIN 1 WHILE 42
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
\ RUN: %not %warpforth-translate --forth-to-mlir %s 2>&1 | %FileCheck %s
2+
\ CHECK: unclosed control flow (missing THEN, REPEAT, or UNTIL?)
3+
\! kernel main
4+
1 IF 42

0 commit comments

Comments
 (0)