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