This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Okay, here's your official unofficial closure leak patch
[perl5.git] / opcode.pl
1 #!/usr/bin/perl
2
3 open(OC, ">opcode.h") || die "Can't create opcode.h: $!\n";
4 select OC;
5
6 # Read data.
7
8 while (<DATA>) {
9     chop;
10     next unless $_;
11     next if /^#/;
12     ($key, $name, $check, $flags, $args) = split(/\t+/, $_, 5);
13     push(@ops, $key);
14     $name{$key} = $name;
15     $check{$key} = $check;
16     $ckname{$check}++;
17     $flags{$key} = $flags;
18     $args{$key} = $args;
19 }
20
21 # Emit defines.
22
23 $i = 0;
24 print <<"END";
25 #define pp_i_preinc pp_preinc
26 #define pp_i_predec pp_predec
27 #define pp_i_postinc pp_postinc
28 #define pp_i_postdec pp_postdec
29
30 typedef enum {
31 END
32 for (@ops) {
33     print "\t", &tab(3,"OP_\U$_,"), "/* ", $i++, " */\n";
34 }
35 print "\t", &tab(3,"OP_max"), "\n";
36 print "} opcode;\n";
37 print "\n#define MAXO ", scalar @ops, "\n\n"; 
38
39 # Emit opnames.
40
41 print <<END;
42 #ifndef DOINIT
43 EXT char *op_name[];
44 #else
45 EXT char *op_name[] = {
46 END
47
48 for (@ops) {
49     print qq(\t"$name{$_}",\n);
50 }
51
52 print <<END;
53 };
54 #endif
55
56 END
57
58 # Emit function declarations.
59
60 for (sort keys %ckname) {
61     print "OP *\t", &tab(3,$_),"_((OP* op));\n";
62 }
63
64 print "\n";
65
66 for (@ops) {
67     print "OP *\t", &tab(3, "pp_\L$_"), "_((void));\n";
68 }
69
70 # Emit ppcode switch array.
71
72 print <<END;
73
74 #ifndef DOINIT
75 EXT OP * (*ppaddr[])();
76 #else
77 EXT OP * (*ppaddr[])() = {
78 END
79
80 for (@ops) {
81     print "\tpp_\L$_,\n";
82 }
83
84 print <<END;
85 };
86 #endif
87
88 END
89
90 # Emit check routines.
91
92 print <<END;
93 #ifndef DOINIT
94 EXT OP * (*check[])();
95 #else
96 EXT OP * (*check[])() = {
97 END
98
99 for (@ops) {
100     print "\t", &tab(3, "$check{$_},"), "/* \L$_ */\n";
101 }
102
103 print <<END;
104 };
105 #endif
106
107 END
108
109 # Emit allowed argument types.
110
111 print <<END;
112 #ifndef DOINIT
113 EXT U32 opargs[];
114 #else
115 EXT U32 opargs[] = {
116 END
117
118 %argnum = (
119     S,  1,              # scalar
120     L,  2,              # list
121     A,  3,              # array value
122     H,  4,              # hash value
123     C,  5,              # code value
124     F,  6,              # file value
125     R,  7,              # scalar reference
126 );
127
128 for (@ops) {
129     $argsum = 0;
130     $flags = $flags{$_};
131     $argsum |= 1 if $flags =~ /m/;              # needs stack mark
132     $argsum |= 2 if $flags =~ /f/;              # fold constants
133     $argsum |= 4 if $flags =~ /s/;              # always produces scalar
134     $argsum |= 8 if $flags =~ /t/;              # needs target scalar
135     $argsum |= 16 if $flags =~ /i/;             # always produces integer
136     $argsum |= 32 if $flags =~ /I/;             # has corresponding int op
137     $argsum |= 64 if $flags =~ /d/;             # danger, unknown side effects
138     $argsum |= 128 if $flags =~ /u/;            # defaults to $_
139     $mul = 256;
140     for $arg (split(' ',$args{$_})) {
141         $argnum = ($arg =~ s/\?//) ? 8 : 0;
142         $argnum += $argnum{$arg};
143         $argsum += $argnum * $mul;
144         $mul <<= 4;
145     }
146     $argsum = sprintf("0x%08x", $argsum);
147     print "\t", &tab(3, "$argsum,"), "/* \L$_ */\n";
148 }
149
150 print <<END;
151 };
152 #endif
153 END
154
155 ###########################################################################
156 sub tab {
157     local($l, $t) = @_;
158     $t .= "\t" x ($l - (length($t) + 1) / 8);
159     $t;
160 }
161 ###########################################################################
162 __END__
163
164 # Nothing.
165
166 null            null operation          ck_null         0       
167 stub            stub                    ck_null         0
168 scalar          scalar                  ck_fun          s       S
169
170 # Pushy stuff.
171
172 pushmark        pushmark                ck_null         s       
173 wantarray       wantarray               ck_null         is      
174
175 const           constant item           ck_svconst      s       
176
177 gvsv            scalar variable         ck_null         ds      
178 gv              glob value              ck_null         ds      
179 padsv           private variable        ck_null         ds
180 padav           private array           ck_null         d
181 padhv           private hash            ck_null         d
182 padany          private something       ck_null         d
183
184 pushre          push regexp             ck_null         0
185
186 # References and stuff.
187
188 rv2gv           ref-to-glob cast        ck_rvconst      ds      
189 sv2len          scalar value length     ck_null         ist     
190 rv2sv           scalar deref            ck_rvconst      ds      
191 av2arylen       array length            ck_null         is      
192 rv2cv           subroutine deref        ck_rvconst      d
193 anoncode        anonymous subroutine    ck_null         0       
194 refgen          reference constructor   ck_spair        m       L
195 srefgen         scalar ref constructor  ck_null         fs      S
196 ref             reference-type operator ck_fun          stu     S?
197 bless           bless                   ck_fun          s       S S?
198
199 # Pushy I/O.
200
201 backtick        backticks               ck_null         t       
202 glob            glob                    ck_glob         t       S S
203 readline        <HANDLE>                ck_null         t       
204 rcatline        append I/O operator     ck_null         t       
205
206 # Bindable operators.
207
208 regcmaybe       regexp comp once        ck_fun          s       S
209 regcomp         regexp compilation      ck_null         s       S
210 match           pattern match           ck_match        d
211 subst           substitution            ck_null         dis     S
212 substcont       substitution cont       ck_null         dis     
213 trans           character translation   ck_null         is      S
214
215 # Lvalue operators.
216
217 sassign         scalar assignment       ck_null         s
218 aassign         list assignment         ck_null         t       L L
219
220 chop            chop                    ck_spair        mts     L
221 schop           scalar chop             ck_null         stu     S?
222 chomp           safe chop               ck_spair        mts     L
223 schomp          scalar safe chop        ck_null         stu     S?
224 defined         defined operator        ck_rfun         isu     S?
225 undef           undef operator          ck_lfun         s       S?
226 study           study                   ck_fun          stu     S?
227 pos             match position          ck_lfun         stu     S?
228
229 preinc          preincrement            ck_lfun         dIs     S
230 i_preinc        integer preincrement    ck_lfun         dis     S
231 predec          predecrement            ck_lfun         dIs     S
232 i_predec        integer predecrement    ck_lfun         dis     S
233 postinc         postincrement           ck_lfun         dIst    S
234 i_postinc       integer postincrement   ck_lfun         dist    S
235 postdec         postdecrement           ck_lfun         dIst    S
236 i_postdec       integer postdecrement   ck_lfun         dist    S
237
238 # Ordinary operators.
239
240 pow             exponentiation          ck_null         fst     S S
241
242 multiply        multiplication          ck_null         Ifst    S S
243 i_multiply      integer multiplication  ck_null         ifst    S S
244 divide          division                ck_null         Ifst    S S
245 i_divide        integer division        ck_null         ifst    S S
246 modulo          modulus                 ck_null         Iifst   S S
247 i_modulo        integer modulus         ck_null         ifst    S S
248 repeat          repeat                  ck_repeat       mt      L S
249
250 add             addition                ck_null         Ifst    S S
251 i_add           integer addition        ck_null         ifst    S S
252 subtract        subtraction             ck_null         Ifst    S S
253 i_subtract      integer subtraction     ck_null         ifst    S S
254 concat          concatenation           ck_concat       fst     S S
255 stringify       string                  ck_fun          fst     S
256
257 left_shift      left bitshift           ck_null         ifst    S S
258 right_shift     right bitshift          ck_null         ifst    S S
259
260 lt              numeric lt              ck_null         Iifs    S S
261 i_lt            integer lt              ck_null         ifs     S S
262 gt              numeric gt              ck_null         Iifs    S S
263 i_gt            integer gt              ck_null         ifs     S S
264 le              numeric le              ck_null         Iifs    S S
265 i_le            integer le              ck_null         ifs     S S
266 ge              numeric ge              ck_null         Iifs    S S
267 i_ge            integer ge              ck_null         ifs     S S
268 eq              numeric eq              ck_null         Iifs    S S
269 i_eq            integer eq              ck_null         ifs     S S
270 ne              numeric ne              ck_null         Iifs    S S
271 i_ne            integer ne              ck_null         ifs     S S
272 ncmp            spaceship operator      ck_null         Iifst   S S
273 i_ncmp          integer spaceship       ck_null         ifst    S S
274
275 slt             string lt               ck_null         ifs     S S
276 sgt             string gt               ck_null         ifs     S S
277 sle             string le               ck_null         ifs     S S
278 sge             string ge               ck_null         ifs     S S
279 seq             string eq               ck_null         ifs     S S
280 sne             string ne               ck_null         ifs     S S
281 scmp            string comparison       ck_null         ifst    S S
282
283 bit_and         bitwise and             ck_null         fst     S S
284 bit_xor         bitwise xor             ck_null         fst     S S
285 bit_or          bitwise or              ck_null         fst     S S
286
287 negate          negate                  ck_null         Ifst    S
288 i_negate        integer negate          ck_null         ifst    S
289 not             not                     ck_null         ifs     S
290 complement      1's complement          ck_null         fst     S
291
292 # High falutin' math.
293
294 atan2           atan2                   ck_fun          fst     S S
295 sin             sin                     ck_fun          fstu    S?
296 cos             cos                     ck_fun          fstu    S?
297 rand            rand                    ck_fun          st      S?
298 srand           srand                   ck_fun          s       S?
299 exp             exp                     ck_fun          fstu    S?
300 log             log                     ck_fun          fstu    S?
301 sqrt            sqrt                    ck_fun          fstu    S?
302
303 int             int                     ck_fun          fstu    S?
304 hex             hex                     ck_fun          istu    S?
305 oct             oct                     ck_fun          istu    S?
306 abs             abs                     ck_fun          fstu    S?
307
308 # String stuff.
309
310 length          length                  ck_lengthconst  istu    S?
311 substr          substr                  ck_fun          st      S S S?
312 vec             vec                     ck_fun          ist     S S S
313
314 index           index                   ck_index        ist     S S S?
315 rindex          rindex                  ck_index        ist     S S S?
316
317 sprintf         sprintf                 ck_fun          mst     S L
318 formline        formline                ck_formline     ms      S L
319 ord             ord                     ck_fun          ifstu   S?
320 chr             chr                     ck_fun          fstu    S?
321 crypt           crypt                   ck_fun          fst     S S
322 ucfirst         upper case first        ck_fun          fst     S
323 lcfirst         lower case first        ck_fun          fst     S
324 uc              upper case              ck_fun          fst     S
325 lc              lower case              ck_fun          fst     S
326 quotemeta       quote metachars         ck_fun          fst     S
327
328 # Arrays.
329
330 rv2av           array deref             ck_rvconst      dt      
331 aelemfast       known array element     ck_null         s       A S
332 aelem           array element           ck_null         s       A S
333 aslice          array slice             ck_null         m       A L
334
335 # Associative arrays.
336
337 each            each                    ck_fun          t       H
338 values          values                  ck_fun          t       H
339 keys            keys                    ck_fun          t       H
340 delete          delete                  ck_delete       s       S
341 exists          exists operator         ck_delete       is      S
342 rv2hv           associative array deref ck_rvconst      dt      
343 helem           associative array elem  ck_null         s       H S
344 hslice          associative array slice ck_null         m       H L
345
346 # Explosives and implosives.
347
348 unpack          unpack                  ck_fun          0       S S
349 pack            pack                    ck_fun          mst     S L
350 split           split                   ck_split        t       S S S
351 join            join                    ck_fun          mst     S L
352
353 # List operators.
354
355 list            list                    ck_null         m       L
356 lslice          list slice              ck_null         0       H L L
357 anonlist        anonymous list          ck_fun          ms      L
358 anonhash        anonymous hash          ck_fun          ms      L
359
360 splice          splice                  ck_fun          m       A S? S? L
361 push            push                    ck_fun          imst    A L
362 pop             pop                     ck_shift        s       A
363 shift           shift                   ck_shift        s       A
364 unshift         unshift                 ck_fun          imst    A L
365 sort            sort                    ck_sort         m       C? L
366 reverse         reverse                 ck_fun          mt      L
367
368 grepstart       grep                    ck_grep         dm      C L
369 grepwhile       grep iterator           ck_null         dt      
370
371 mapstart        map                     ck_grep         dm      C L
372 mapwhile        map iterator            ck_null         dt
373
374 # Range stuff.
375
376 range           flipflop                ck_null         0       S S
377 flip            range (or flip)         ck_null         0       S S
378 flop            range (or flop)         ck_null         0
379
380 # Control.
381
382 and             logical and             ck_null         0       
383 or              logical or              ck_null         0       
384 xor             logical xor             ck_null         fs      S S     
385 cond_expr       conditional expression  ck_null         0       
386 andassign       logical and assignment  ck_null         s       
387 orassign        logical or assignment   ck_null         s       
388
389 method          method lookup           ck_null         d
390 entersub        subroutine entry        ck_subr         dmt     L
391 leavesub        subroutine exit         ck_null         0       
392 caller          caller                  ck_fun          t       S?
393 warn            warn                    ck_fun          imst    L
394 die             die                     ck_fun          dimst   L
395 reset           reset                   ck_fun          is      S?
396
397 lineseq         line sequence           ck_null         0       
398 nextstate       next statement          ck_null         s       
399 dbstate         debug next statement    ck_null         s       
400 unstack         unstack                 ck_null         s
401 enter           block entry             ck_null         0       
402 leave           block exit              ck_null         0       
403 scope           block                   ck_null         0       
404 enteriter       foreach loop entry      ck_null         d       
405 iter            foreach loop iterator   ck_null         0       
406 enterloop       loop entry              ck_null         d       
407 leaveloop       loop exit               ck_null         0       
408 return          return                  ck_null         dm      L
409 last            last                    ck_null         ds      
410 next            next                    ck_null         ds      
411 redo            redo                    ck_null         ds      
412 dump            dump                    ck_null         ds      
413 goto            goto                    ck_null         ds      
414 exit            exit                    ck_fun          ds      S?
415
416 #nswitch                numeric switch          ck_null         d       
417 #cswitch                character switch        ck_null         d       
418
419 # I/O.
420
421 open            open                    ck_fun          ist     F S?
422 close           close                   ck_fun          is      F?
423 pipe_op         pipe                    ck_fun          is      F F
424
425 fileno          fileno                  ck_fun          ist     F
426 umask           umask                   ck_fun          ist     S?
427 binmode         binmode                 ck_fun          s       F
428
429 tie             tie                     ck_fun          idms    R S L
430 untie           untie                   ck_fun          is      R
431 dbmopen         dbmopen                 ck_fun          is      H S S
432 dbmclose        dbmclose                ck_fun          is      H
433
434 sselect         select system call      ck_select       t       S S S S
435 select          select                  ck_select       st      F?
436
437 getc            getc                    ck_eof          st      F?
438 read            read                    ck_fun          imst    F R S S?
439 enterwrite      write                   ck_fun          dis     F?
440 leavewrite      write exit              ck_null         0       
441
442 prtf            printf                  ck_listiob      ims     F? L
443 print           print                   ck_listiob      ims     F? L
444
445 sysread         sysread                 ck_fun          imst    F R S S?
446 syswrite        syswrite                ck_fun          imst    F S S S?
447
448 send            send                    ck_fun          imst    F S S S?
449 recv            recv                    ck_fun          imst    F R S S
450
451 eof             eof                     ck_eof          is      F?
452 tell            tell                    ck_fun          st      F?
453 seek            seek                    ck_fun          s       F S S
454 truncate        truncate                ck_trunc        is      S S
455
456 fcntl           fcntl                   ck_fun          st      F S S
457 ioctl           ioctl                   ck_fun          st      F S S
458 flock           flock                   ck_fun          ist     F S
459
460 # Sockets.
461
462 socket          socket                  ck_fun          is      F S S S
463 sockpair        socketpair              ck_fun          is      F F S S S
464
465 bind            bind                    ck_fun          is      F S
466 connect         connect                 ck_fun          is      F S
467 listen          listen                  ck_fun          is      F S
468 accept          accept                  ck_fun          ist     F F
469 shutdown        shutdown                ck_fun          ist     F S
470
471 gsockopt        getsockopt              ck_fun          is      F S S
472 ssockopt        setsockopt              ck_fun          is      F S S S
473
474 getsockname     getsockname             ck_fun          is      F
475 getpeername     getpeername             ck_fun          is      F
476
477 # Stat calls.
478
479 lstat           lstat                   ck_ftst         u       F
480 stat            stat                    ck_ftst         u       F
481 ftrread         -R                      ck_ftst         isu     F
482 ftrwrite        -W                      ck_ftst         isu     F
483 ftrexec         -X                      ck_ftst         isu     F
484 fteread         -r                      ck_ftst         isu     F
485 ftewrite        -w                      ck_ftst         isu     F
486 fteexec         -x                      ck_ftst         isu     F
487 ftis            -e                      ck_ftst         isu     F
488 fteowned        -O                      ck_ftst         isu     F
489 ftrowned        -o                      ck_ftst         isu     F
490 ftzero          -z                      ck_ftst         isu     F
491 ftsize          -s                      ck_ftst         istu    F
492 ftmtime         -M                      ck_ftst         stu     F
493 ftatime         -A                      ck_ftst         stu     F
494 ftctime         -C                      ck_ftst         stu     F
495 ftsock          -S                      ck_ftst         isu     F
496 ftchr           -c                      ck_ftst         isu     F
497 ftblk           -b                      ck_ftst         isu     F
498 ftfile          -f                      ck_ftst         isu     F
499 ftdir           -d                      ck_ftst         isu     F
500 ftpipe          -p                      ck_ftst         isu     F
501 ftlink          -l                      ck_ftst         isu     F
502 ftsuid          -u                      ck_ftst         isu     F
503 ftsgid          -g                      ck_ftst         isu     F
504 ftsvtx          -k                      ck_ftst         isu     F
505 fttty           -t                      ck_ftst         is      F
506 fttext          -T                      ck_ftst         isu     F
507 ftbinary        -B                      ck_ftst         isu     F
508
509 # File calls.
510
511 chdir           chdir                   ck_fun          ist     S?
512 chown           chown                   ck_fun          imst    L
513 chroot          chroot                  ck_fun          istu    S?
514 unlink          unlink                  ck_fun          imstu   L
515 chmod           chmod                   ck_fun          imst    L
516 utime           utime                   ck_fun          imst    L
517 rename          rename                  ck_fun          ist     S S
518 link            link                    ck_fun          ist     S S
519 symlink         symlink                 ck_fun          ist     S S
520 readlink        readlink                ck_fun          stu     S?
521 mkdir           mkdir                   ck_fun          ist     S S
522 rmdir           rmdir                   ck_fun          istu    S?
523
524 # Directory calls.
525
526 open_dir        opendir                 ck_fun          is      F S
527 readdir         readdir                 ck_fun          0       F
528 telldir         telldir                 ck_fun          st      F
529 seekdir         seekdir                 ck_fun          s       F S
530 rewinddir       rewinddir               ck_fun          s       F
531 closedir        closedir                ck_fun          is      F
532
533 # Process control.
534
535 fork            fork                    ck_null         ist     
536 wait            wait                    ck_null         ist     
537 waitpid         waitpid                 ck_fun          ist     S S
538 system          system                  ck_exec         imst    S? L
539 exec            exec                    ck_exec         dimst   S? L
540 kill            kill                    ck_fun          dimst   L
541 getppid         getppid                 ck_null         ist     
542 getpgrp         getpgrp                 ck_fun          ist     S?
543 setpgrp         setpgrp                 ck_fun          ist     S? S?
544 getpriority     getpriority             ck_fun          ist     S S
545 setpriority     setpriority             ck_fun          ist     S S S
546
547 # Time calls.
548
549 time            time                    ck_null         ist     
550 tms             times                   ck_null         0       
551 localtime       localtime               ck_fun          t       S?
552 gmtime          gmtime                  ck_fun          t       S?
553 alarm           alarm                   ck_fun          istu    S?
554 sleep           sleep                   ck_fun          ist     S?
555
556 # Shared memory.
557
558 shmget          shmget                  ck_fun          imst    S S S
559 shmctl          shmctl                  ck_fun          imst    S S S
560 shmread         shmread                 ck_fun          imst    S S S S
561 shmwrite        shmwrite                ck_fun          ist     S S S S
562
563 # Message passing.
564
565 msgget          msgget                  ck_fun          imst    S S
566 msgctl          msgctl                  ck_fun          imst    S S S
567 msgsnd          msgsnd                  ck_fun          imst    S S S
568 msgrcv          msgrcv                  ck_fun          imst    S S S S S
569
570 # Semaphores.
571
572 semget          semget                  ck_fun          imst    S S S
573 semctl          semctl                  ck_fun          imst    S S S S
574 semop           semop                   ck_fun          imst    S S
575
576 # Eval.
577
578 require         require                 ck_require      du      S?
579 dofile          do 'file'               ck_fun          d       S
580 entereval       eval string             ck_eval         d       S
581 leaveeval       eval exit               ck_null         0       S
582 #evalonce       eval constant string    ck_null         d       S
583 entertry        eval block              ck_null         0       
584 leavetry        eval block exit         ck_null         0       
585
586 # Get system info.
587
588 ghbyname        gethostbyname           ck_fun          0       S
589 ghbyaddr        gethostbyaddr           ck_fun          0       S S
590 ghostent        gethostent              ck_null         0       
591 gnbyname        getnetbyname            ck_fun          0       S
592 gnbyaddr        getnetbyaddr            ck_fun          0       S S
593 gnetent         getnetent               ck_null         0       
594 gpbyname        getprotobyname          ck_fun          0       S
595 gpbynumber      getprotobynumber        ck_fun          0       S
596 gprotoent       getprotoent             ck_null         0       
597 gsbyname        getservbyname           ck_fun          0       S S
598 gsbyport        getservbyport           ck_fun          0       S S
599 gservent        getservent              ck_null         0       
600 shostent        sethostent              ck_fun          is      S
601 snetent         setnetent               ck_fun          is      S
602 sprotoent       setprotoent             ck_fun          is      S
603 sservent        setservent              ck_fun          is      S
604 ehostent        endhostent              ck_null         is      
605 enetent         endnetent               ck_null         is      
606 eprotoent       endprotoent             ck_null         is      
607 eservent        endservent              ck_null         is      
608 gpwnam          getpwnam                ck_fun          0       S
609 gpwuid          getpwuid                ck_fun          0       S
610 gpwent          getpwent                ck_null         0       
611 spwent          setpwent                ck_null         is      
612 epwent          endpwent                ck_null         is      
613 ggrnam          getgrnam                ck_fun          0       S
614 ggrgid          getgrgid                ck_fun          0       S
615 ggrent          getgrent                ck_null         0       
616 sgrent          setgrent                ck_null         is      
617 egrent          endgrent                ck_null         is      
618 getlogin        getlogin                ck_null         st      
619
620 # Miscellaneous.
621
622 syscall         syscall                 ck_fun          imst    S L