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