What is `null vK` in Perl?

Using Perl, I have two similar syntaxes,

if ($a && $b) { exit() }
do { exit() } if ($a && $b)

I believe that this is the same thing, but the top one creates the operation code null vK,

<1> null vK*/1 ->-

What is the meaning null vKand what is it doing?

$ perl -MO=Concise -e'if ($a && $b) { exit() }'
8  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 1 -e:1) v:{ ->3
-     <1> null vK/1 ->8
6        <|> and(other->7) vK/1 ->8
-           <1> null sK/1 ->6
4              <|> and(other->5) sK/1 ->8
-                 <1> ex-rv2sv sK/1 ->4
3                    <#> gvsv[*a] s ->4
-                 <1> ex-rv2sv sK/1 ->-
5                    <#> gvsv[*b] s ->6
-           <@> scope vK ->-
-              <;> ex-nextstate(main 3 -e:1) v ->7
7              <0> exit v* ->8
-e syntax OK

Poems follow

$ perl -MO=Concise -e'do { exit() } if ($a && $b)'
8  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 1 -e:1) v:{ ->3
-     <1> null vK/1 ->8
6        <|> and(other->7) vK/1 ->8
-           <1> null sKP/1 ->6
4              <|> and(other->5) sK/1 ->8
-                 <1> ex-rv2sv sK/1 ->4
3                    <#> gvsv[*a] s ->4
-                 <1> ex-rv2sv sK/1 ->-
5                    <#> gvsv[*b] s ->6
-           <1> null vK*/1 ->-
-              <@> scope vK ->-
-                 <;> ex-nextstate(main 2 -e:1) v ->7
7                 <0> exit v* ->8
+4
source share
1 answer

A β€œ-” at the beginning of the line indicates that op will not be executed, which can also be seen with perl -MO=Concise,-exec.

However, the opcode null vK...or null sK...in the output of B :: Concise does not mean that some operating systems have been optimized. perldocon B :: Concise clearly says that such an optimization is indicated in ex-the output:

Nullops "ex-opname", opname - op, perl. '-', ( ), , .

:

> perl  -MO=Concise -e "$a"
4  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 1 -e:1) v:{ ->3
-     **<1> ex-rv2sv vK/1 ->4**
3        <#> gvsv[*a] s ->4

, ?

, yacc, Perl , .

null vk do BLOCK (perly.y):

termdo  :       DO term %prec UNIOP                     /* do $filename */
            { $$ = dofile($2, $1);}
    |   DO block    %prec '('               /* do { code */
            { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
        ;

:

>perl -MO=Concise -e "do{}"
4  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 2 -e:1) v:{ ->3
-     <1> null vK*/1 ->4
-        <@> scope vK ->-
3           <0> stub v ->4

nulls yacc. -, , -, , , Perl .

op, :

>perl  -MO=Concise -e "$a||$b"
6  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 1 -e:1) v:{ ->3
-     <1> null vK/1 ->6
4        <|> or(other->5) vK/1 ->6
-           <1> ex-rv2sv sK/1 ->4
3              <#> gvsv[*a] s ->4
-           <1> ex-rv2sv vK/1 ->-
5              <#> gvsv[*b] s ->6

null? :

>perl -MO=Concise -e "!$a&&!$b"
7  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 1 -e:1) v:{ ->3
6     <1> not vK/1 ->7
4        <|> or(other->5) sK/1 ->6
-           <1> ex-not sK/1 ->4
-              <1> ex-rv2sv sK/1 ->-
3                 <#> gvsv[*a] s ->4
-           <1> ex-not sK/1 ->6
-              <1> ex-rv2sv sK/1 ->-
5                 <#> gvsv[*b] s ->6

, null vk not vK. , , Perl !$a&&!$b !($a||$b) not(!), null. , Perl , not Perl not null .

: NULL, ex- in B::Concise, , NULL, null, . .

+5

Source: https://habr.com/ru/post/1695787/


All Articles