Skip to content

Commit e4796ce

Browse files
committed
feat: add match examples
1 parent 5c21051 commit e4796ce

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

playground/match.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
function match1()
4+
{
5+
match (true) {
6+
123 => 2,
7+
'text' => 1,
8+
default => 0,
9+
};
10+
}
11+
12+
13+
function match2()
14+
{
15+
/**
16+
* @var $arg
17+
*/
18+
$variable = null;
19+
20+
$res = match ($arg ?: false ?? null) {
21+
my_func($variable, true) => 4,
22+
null => 4,
23+
$variable => 3,
24+
123 => 2,
25+
'text' => 1,
26+
default => 0,
27+
};
28+
}

playground/match.phpo

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
$_main:
3+
; (lines=1, args=0, vars=0, tmps=1)
4+
; (before optimizer)
5+
; /Users/xepozz/IdeaProjects/xepozz/php-opcodes-lang-plugin/playground/match.php:1-28
6+
; return [] RANGE[0..0]
7+
0000 RETURN int(1)
8+
9+
match1:
10+
; (lines=11, args=0, vars=0, tmps=3)
11+
; (before optimizer)
12+
; /Users/xepozz/IdeaProjects/xepozz/php-opcodes-lang-plugin/playground/match.php:3-10
13+
; return [] RANGE[0..0]
14+
0000 EXT_STMT
15+
0001 MATCH bool(true) 123: 0002, "text": 0004, default: 0006
16+
0002 T1 = QM_ASSIGN int(2)
17+
0003 JMP 0008
18+
0004 T1 = QM_ASSIGN int(1)
19+
0005 JMP 0008
20+
0006 T1 = QM_ASSIGN int(0)
21+
0007 JMP 0008
22+
0008 FREE T1
23+
0009 EXT_STMT
24+
0010 RETURN null
25+
LIVE RANGES:
26+
1: 0007 - 0008 (tmp/var)
27+
28+
match2:
29+
; (lines=38, args=0, vars=3, tmps=8)
30+
; (before optimizer)
31+
; /Users/xepozz/IdeaProjects/xepozz/php-opcodes-lang-plugin/playground/match.php:13-28
32+
; return [] RANGE[0..0]
33+
0000 EXT_STMT
34+
0001 ASSIGN CV0($variable) null
35+
0002 EXT_STMT
36+
0003 T4 = JMP_SET CV2($arg) 0007
37+
0004 T5 = COALESCE bool(false) 0006
38+
0005 T5 = QM_ASSIGN null
39+
0006 T4 = QM_ASSIGN T5
40+
0007 INIT_FCALL_BY_NAME 2 string("my_func")
41+
0008 SEND_VAR_EX CV0($variable) 1
42+
0009 SEND_VAL_EX bool(true) 2
43+
0010 V7 = DO_FCALL
44+
0011 T6 = CASE_STRICT T4 V7
45+
0012 JMPNZ T6 0022
46+
0013 T6 = CASE_STRICT T4 null
47+
0014 JMPNZ T6 0024
48+
0015 T6 = CASE_STRICT T4 CV0($variable)
49+
0016 JMPNZ T6 0026
50+
0017 T6 = CASE_STRICT T4 int(123)
51+
0018 JMPNZ T6 0028
52+
0019 T6 = CASE_STRICT T4 string("text")
53+
0020 JMPNZ T6 0030
54+
0021 JMP 0032
55+
0022 T8 = QM_ASSIGN int(4)
56+
0023 JMP 0034
57+
0024 T8 = QM_ASSIGN int(4)
58+
0025 JMP 0034
59+
0026 T8 = QM_ASSIGN int(3)
60+
0027 JMP 0034
61+
0028 T8 = QM_ASSIGN int(2)
62+
0029 JMP 0034
63+
0030 T8 = QM_ASSIGN int(1)
64+
0031 JMP 0034
65+
0032 T8 = QM_ASSIGN int(0)
66+
0033 JMP 0034
67+
0034 FREE T4
68+
0035 ASSIGN CV1($res) T8
69+
0036 EXT_STMT
70+
0037 RETURN null
71+
LIVE RANGES:
72+
4: 0007 - 0034 (tmp/var)
73+
8: 0033 - 0035 (tmp/var)

0 commit comments

Comments
 (0)