Skip to content

Commit cf15034

Browse files
committed
[GR-41032] Pattern Matching - match value and singleton.
PullRequest: graalpython/2500
2 parents 0290fb3 + bbfedd4 commit cf15034

File tree

8 files changed

+341
-23
lines changed

8 files changed

+341
-23
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/CompilerTests.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,55 @@ public void testNamedExpr() {
809809
doTest(s);
810810
}
811811

812+
// @Test skip until 3.10
813+
public void testMatchValueConst() {
814+
String source = "" +
815+
"match 1:\n" +
816+
" case 1:\n" +
817+
" pass\n";
818+
doTest(source);
819+
}
820+
821+
// @Test skip until 3.10
822+
public void testMatchValue() {
823+
String source = "" +
824+
"s = 1\n" +
825+
"match s:\n" +
826+
" case 1:\n" +
827+
" pass\n";
828+
doTest(source);
829+
}
830+
831+
// @Test skip until 3.10
832+
public void testMatchValueWithDefault() {
833+
String source = "" +
834+
"s = 1\n" +
835+
"match s:\n" +
836+
" case 1:\n" +
837+
" pass\n" +
838+
" case _:\n" +
839+
" pass\n";
840+
doTest(source);
841+
}
842+
843+
// @Test skip until 3.10
844+
public void testMatchSingletonBoolean() {
845+
String source = "" +
846+
"match 1:\n" +
847+
" case True:\n" +
848+
" pass\n";
849+
doTest(source);
850+
}
851+
852+
// @Test skip until 3.10
853+
public void testMatchSingletonNone() {
854+
String source = "" +
855+
"match 1:\n" +
856+
" case None:\n" +
857+
" pass\n";
858+
doTest(source);
859+
}
860+
812861
@Test
813862
public void testAssignToDebug() {
814863
checkSyntaxErrorMessage("obj.__debug__ = 1", "cannot assign to __debug__");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Disassembly of <module>:
2+
1:6 - 1:7 0 LOAD_BYTE_O 1 can quicken
3+
2:8 - 2:12 2 LOAD_TRUE_O can quicken
4+
2:8 - 2:12 3 BINARY_OP 31 (IS) can quicken, generalizes: 2, 0
5+
2:8 - 2:12 5 POP_AND_JUMP_IF_FALSE 6 (to 11) generalizes: 3
6+
3:7 - 3:11 9 JUMP_FORWARD 2 (to 11)
7+
2:3 - 3:11 >> 11 LOAD_NONE
8+
2:3 - 3:11 12 RETURN_VALUE
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Disassembly of <module>:
2+
1:6 - 1:7 0 LOAD_BYTE_O 1
3+
2:8 - 2:12 2 LOAD_NONE
4+
2:8 - 2:12 3 BINARY_OP 31 (IS) can quicken
5+
2:8 - 2:12 5 POP_AND_JUMP_IF_FALSE 6 (to 11) generalizes: 3
6+
3:7 - 3:11 9 JUMP_FORWARD 2 (to 11)
7+
2:3 - 3:11 >> 11 LOAD_NONE
8+
2:3 - 3:11 12 RETURN_VALUE
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Disassembly of <module>:
2+
1:4 - 1:5 0 LOAD_BYTE_O 1
3+
1:0 - 1:1 2 STORE_NAME 0 (s)
4+
2:6 - 2:7 4 LOAD_NAME 0 (s)
5+
3:8 - 3:9 6 LOAD_BYTE_O 1
6+
3:8 - 3:9 8 BINARY_OP 12 (EQ) can quicken
7+
3:8 - 3:9 10 POP_AND_JUMP_IF_FALSE 6 (to 16) generalizes: 8
8+
4:7 - 4:11 14 JUMP_FORWARD 2 (to 16)
9+
3:3 - 4:11 >> 16 LOAD_NONE
10+
3:3 - 4:11 17 RETURN_VALUE
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Disassembly of <module>:
2+
1:6 - 1:7 0 LOAD_BYTE_I 1 can quicken
3+
2:8 - 2:9 2 LOAD_BYTE_I 1 can quicken
4+
2:8 - 2:9 4 BINARY_OP 12 (EQ) can quicken, generalizes: 2, 0
5+
2:8 - 2:9 6 POP_AND_JUMP_IF_FALSE 6 (to 12) generalizes: 4
6+
3:7 - 3:11 10 JUMP_FORWARD 2 (to 12)
7+
2:3 - 3:11 >> 12 LOAD_NONE
8+
2:3 - 3:11 13 RETURN_VALUE
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Disassembly of <module>:
2+
1:4 - 1:5 0 LOAD_BYTE_O 1
3+
1:0 - 1:1 2 STORE_NAME 0 (s)
4+
2:6 - 2:7 4 LOAD_NAME 0 (s)
5+
3:8 - 3:9 6 LOAD_BYTE_O 1
6+
3:8 - 3:9 8 BINARY_OP 12 (EQ) can quicken
7+
3:8 - 3:9 10 POP_AND_JUMP_IF_FALSE 6 (to 16) generalizes: 8
8+
4:7 - 4:11 14 JUMP_FORWARD 3 (to 17)
9+
5:3 - 6:11 >> 16 NOP
10+
6:7 - 6:11 >> 17 LOAD_NONE
11+
6:7 - 6:11 18 RETURN_VALUE

0 commit comments

Comments
 (0)