Merge pp_index and pp_rindex - we have another mathom.
[p5sagit/p5-mst-13.2.git] / opcode.pl
1 #!/usr/bin/perl
2 BEGIN {
3     # Get function prototypes
4     require 'regen_lib.pl';
5 }
6
7 $opcode_new = 'opcode.h-new';
8 $opname_new = 'opnames.h-new';
9 open(OC, ">$opcode_new") || die "Can't create $opcode_new: $!\n";
10 binmode OC;
11 open(ON, ">$opname_new") || die "Can't create $opname_new: $!\n";
12 binmode ON;
13 select OC;
14
15 # Read data.
16
17 while (<DATA>) {
18     chop;
19     next unless $_;
20     next if /^#/;
21     ($key, $desc, $check, $flags, $args) = split(/\t+/, $_, 5);
22
23     warn qq[Description "$desc" duplicates $seen{$desc}\n] if $seen{$desc};
24     die qq[Opcode "$key" duplicates $seen{$key}\n] if $seen{$key};
25     $seen{$desc} = qq[description of opcode "$key"];
26     $seen{$key} = qq[opcode "$key"];
27
28     push(@ops, $key);
29     $desc{$key} = $desc;
30     $check{$key} = $check;
31     $ckname{$check}++;
32     $flags{$key} = $flags;
33     $args{$key} = $args;
34 }
35
36 # Set up aliases
37
38 my %alias;
39
40 # Format is "this function" => "does these op names"
41 my @raw_alias = (
42                  Perl_do_kv => [qw( keys values )],
43                  Perl_unimplemented_op => [qw(padany threadsv mapstart)],
44                  # All the ops with a body of { return NORMAL; }
45                  Perl_pp_null => [qw(scalar regcmaybe lineseq scope)],
46
47                  Perl_pp_goto => ['dump'],
48                  Perl_pp_require => ['dofile'],
49                  Perl_pp_untie => ['dbmclose'],
50                  Perl_pp_sysread => [qw(read recv)],
51                  Perl_pp_sysseek => ['seek'],
52                  Perl_pp_ioctl => ['fcntl'],
53                  Perl_pp_ssockopt => ['gsockopt'],
54                  Perl_pp_getpeername => ['getsockname'],
55                  Perl_pp_stat => ['lstat'],
56                  Perl_pp_ftrowned => [qw(fteowned ftzero ftsock ftchr ftblk
57                                          ftfile ftdir ftpipe ftsuid ftsgid
58                                          ftsvtx)],
59                  Perl_pp_fttext => ['ftbinary'],
60                  Perl_pp_gmtime => ['localtime'],
61                  Perl_pp_semget => [qw(shmget msgget)],
62                  Perl_pp_semctl => [qw(shmctl msgctl)],
63                  Perl_pp_ghostent => [qw(ghbyname ghbyaddr)],
64                  Perl_pp_gnetent => [qw(gnbyname gnbyaddr)],
65                  Perl_pp_gprotoent => [qw(gpbyname gpbynumber)],
66                  Perl_pp_gservent => [qw(gsbyname gsbyport)],
67                  Perl_pp_gpwent => [qw(gpwnam gpwuid)],
68                  Perl_pp_ggrent => [qw(ggrnam ggrgid)],
69                  Perl_pp_ftis => [qw(ftsize ftmtime ftatime ftctime)],
70                  Perl_pp_chown => [qw(unlink chmod utime kill)],
71                  Perl_pp_link => ['symlink'],
72                  Perl_pp_ftrread => [qw(ftrwrite ftrexec fteread ftewrite
73                                         fteexec)],
74                  Perl_pp_shmwrite => [qw(shmread msgsnd msgrcv semop)],
75                  Perl_pp_send => ['syswrite'],
76                  Perl_pp_defined => [qw(dor dorassign)],
77                  Perl_pp_and => ['andassign'],
78                  Perl_pp_or => ['orassign'],
79                  Perl_pp_ucfirst => ['lcfirst'],
80                  Perl_pp_sle => [qw(slt sgt sge)],
81                  Perl_pp_print => ['say'],
82                  Perl_pp_index => ['rindex'],
83                 );
84
85 while (my ($func, $names) = splice @raw_alias, 0, 2) {
86     $alias{$_} = $func for @$names;
87 }
88
89 # Emit defines.
90
91 $i = 0;
92 print <<"END";
93 /* -*- buffer-read-only: t -*-
94  *
95  *    opcode.h
96  *
97  *    Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999,
98  *    2000, 2001, 2002, 2003, 2004, 2005, 2006 by Larry Wall and others
99  *
100  *    You may distribute under the terms of either the GNU General Public
101  *    License or the Artistic License, as specified in the README file.
102  *
103  * !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
104  *  This file is built by opcode.pl from its data.  Any changes made here
105  *  will be lost!
106  */
107
108 #ifndef PERL_GLOBAL_STRUCT_INIT
109
110 #define Perl_pp_i_preinc Perl_pp_preinc
111 #define Perl_pp_i_predec Perl_pp_predec
112 #define Perl_pp_i_postinc Perl_pp_postinc
113 #define Perl_pp_i_postdec Perl_pp_postdec
114
115 PERL_PPDEF(Perl_unimplemented_op)
116
117 END
118
119 print ON <<"END";
120 /* -*- buffer-read-only: t -*-
121  *
122  *    opnames.h
123  *
124  *    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
125  *    by Larry Wall and others
126  *
127  *    You may distribute under the terms of either the GNU General Public
128  *    License or the Artistic License, as specified in the README file.
129  *
130  *
131  * !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
132  *  This file is built by opcode.pl from its data.  Any changes made here
133  *  will be lost!
134  */
135
136 typedef enum opcode {
137 END
138
139 for (@ops) {
140     print ON "\t", &tab(3,"OP_\U$_,"), "/* ", $i++, " */\n";
141 }
142 print ON "\t", &tab(3,"OP_max"), "\n";
143 print ON "} opcode;\n";
144 print ON "\n#define MAXO ", scalar @ops, "\n";
145 print ON "#define OP_phoney_INPUT_ONLY -1\n";
146 print ON "#define OP_phoney_OUTPUT_ONLY -2\n\n";
147
148 # Emit op names and descriptions.
149
150 print <<END;
151 START_EXTERN_C
152
153 #define OP_NAME(o) ((o)->op_type == OP_CUSTOM ? custom_op_name(o) : \\
154                     PL_op_name[(o)->op_type])
155 #define OP_DESC(o) ((o)->op_type == OP_CUSTOM ? custom_op_desc(o) : \\
156                     PL_op_desc[(o)->op_type])
157
158 #ifndef DOINIT
159 EXTCONST char* const PL_op_name[];
160 #else
161 EXTCONST char* const PL_op_name[] = {
162 END
163
164 for (@ops) {
165     print qq(\t"$_",\n);
166 }
167
168 print <<END;
169 };
170 #endif
171
172 END
173
174 print <<END;
175 #ifndef DOINIT
176 EXTCONST char* const PL_op_desc[];
177 #else
178 EXTCONST char* const PL_op_desc[] = {
179 END
180
181 for (@ops) {
182     my($safe_desc) = $desc{$_};
183
184     # Have to escape double quotes and escape characters.
185     $safe_desc =~ s/(^|[^\\])([\\"])/$1\\$2/g;
186
187     print qq(\t"$safe_desc",\n);
188 }
189
190 print <<END;
191 };
192 #endif
193
194 END_EXTERN_C
195
196 #endif /* !PERL_GLOBAL_STRUCT_INIT */
197 END
198
199 # Emit function declarations.
200
201 #for (sort keys %ckname) {
202 #    print "OP *\t", &tab(3,$_),"(pTHX_ OP* o);\n";
203 #}
204 #
205 #print "\n";
206 #
207 #for (@ops) {
208 #    print "OP *\t", &tab(3, "pp_$_"), "(pTHX);\n";
209 #}
210
211 # Emit ppcode switch array.
212
213 print <<END;
214
215 START_EXTERN_C
216
217 #ifdef PERL_GLOBAL_STRUCT_INIT
218 #  define PERL_PPADDR_INITED
219 static const Perl_ppaddr_t Gppaddr[]
220 #else
221 #  ifndef PERL_GLOBAL_STRUCT
222 #    define PERL_PPADDR_INITED
223 EXT Perl_ppaddr_t PL_ppaddr[] /* or perlvars.h */
224 #  endif
225 #endif /* PERL_GLOBAL_STRUCT */
226 #if (defined(DOINIT) && !defined(PERL_GLOBAL_STRUCT)) || defined(PERL_GLOBAL_STRUCT_INIT)
227 #  define PERL_PPADDR_INITED
228 = {
229 END
230
231 for (@ops) {
232     $_ eq "custom" and next;
233     if (my $name = $alias{$_}) {
234         print "\tMEMBER_TO_FPTR($name),\t/* Perl_pp_$_ */\n";
235     }
236     else {
237         print "\tMEMBER_TO_FPTR(Perl_pp_$_),\n";
238     }
239 }
240
241 print <<END;
242 }
243 #endif
244 #ifdef PERL_PPADDR_INITED
245 ;
246 #endif
247
248 END
249
250 # Emit check routines.
251
252 print <<END;
253 #ifdef PERL_GLOBAL_STRUCT_INIT
254 #  define PERL_CHECK_INITED
255 static const Perl_check_t Gcheck[]
256 #else
257 #  ifndef PERL_GLOBAL_STRUCT
258 #    define PERL_CHECK_INITED
259 EXT Perl_check_t PL_check[] /* or perlvars.h */
260 #  endif
261 #endif
262 #if (defined(DOINIT) && !defined(PERL_GLOBAL_STRUCT)) || defined(PERL_GLOBAL_STRUCT_INIT)
263 #  define PERL_CHECK_INITED
264 = {
265 END
266
267 for (@ops) {
268     print "\t", &tab(3, "MEMBER_TO_FPTR(Perl_$check{$_}),"), "\t/* $_ */\n";
269 }
270
271 print <<END;
272 }
273 #endif
274 #ifdef PERL_CHECK_INITED
275 ;
276 #endif /* #ifdef PERL_CHECK_INITED */
277
278 END
279
280 # Emit allowed argument types.
281
282 print <<END;
283 #ifndef PERL_GLOBAL_STRUCT_INIT
284
285 #ifndef DOINIT
286 EXT const U32 PL_opargs[];
287 #else
288 EXT const U32 PL_opargs[] = {
289 END
290
291 %argnum = (
292     S,  1,              # scalar
293     L,  2,              # list
294     A,  3,              # array value
295     H,  4,              # hash value
296     C,  5,              # code value
297     F,  6,              # file value
298     R,  7,              # scalar reference
299 );
300
301 %opclass = (
302     '0',  0,            # baseop
303     '1',  1,            # unop
304     '2',  2,            # binop
305     '|',  3,            # logop
306     '@',  4,            # listop
307     '/',  5,            # pmop
308     '$',  6,            # svop_or_padop
309     '#',  7,            # padop
310     '"',  8,            # pvop_or_svop
311     '{',  9,            # loop
312     ';',  10,           # cop
313     '%',  11,           # baseop_or_unop
314     '-',  12,           # filestatop
315     '}',  13,           # loopexop
316 );
317
318 my %OP_IS_SOCKET;
319 my %OP_IS_FILETEST;
320
321 for (@ops) {
322     $argsum = 0;
323     $flags = $flags{$_};
324     $argsum |= 1 if $flags =~ /m/;              # needs stack mark
325     $argsum |= 2 if $flags =~ /f/;              # fold constants
326     $argsum |= 4 if $flags =~ /s/;              # always produces scalar
327     $argsum |= 8 if $flags =~ /t/;              # needs target scalar
328     $argsum |= (8|256) if $flags =~ /T/;        # ... which may be lexical
329     $argsum |= 16 if $flags =~ /i/;             # always produces integer
330     $argsum |= 32 if $flags =~ /I/;             # has corresponding int op
331     $argsum |= 64 if $flags =~ /d/;             # danger, unknown side effects
332     $argsum |= 128 if $flags =~ /u/;            # defaults to $_
333     $flags =~ /([\W\d_])/ or die qq[Opcode "$_" has no class indicator];
334     $argsum |= $opclass{$1} << 9;
335     $mul = 0x2000;                              # 2 ^ OASHIFT
336     for $arg (split(' ',$args{$_})) {
337         if ($arg =~ /^F/) {
338            $OP_IS_SOCKET{$_}   = 1 if $arg =~ s/s//;
339            $OP_IS_FILETEST{$_} = 1 if $arg =~ s/-//;
340         }
341         $argnum = ($arg =~ s/\?//) ? 8 : 0;
342         die "op = $_, arg = $arg\n" unless length($arg) == 1;
343         $argnum += $argnum{$arg};
344         warn "# Conflicting bit 32 for '$_'.\n"
345             if $argnum & 8 and $mul == 0x10000000;
346         $argsum += $argnum * $mul;
347         $mul <<= 4;
348     }
349     $argsum = sprintf("0x%08x", $argsum);
350     print "\t", &tab(3, "$argsum,"), "/* $_ */\n";
351 }
352
353 print <<END;
354 };
355 #endif
356
357 END_EXTERN_C
358
359 #endif /* !PERL_GLOBAL_STRUCT_INIT */
360 END
361
362 if (keys %OP_IS_SOCKET) {
363     print ON "\n#define OP_IS_SOCKET(op)        \\\n\t(";
364     print ON join(" || \\\n\t ",
365                map { "(op) == OP_" . uc() } sort keys %OP_IS_SOCKET);
366     print ON ")\n\n";
367 }
368
369 if (keys %OP_IS_FILETEST) {
370     print ON "\n#define OP_IS_FILETEST(op)      \\\n\t(";
371     print ON join(" || \\\n\t ",
372                map { "(op) == OP_" . uc() } sort keys %OP_IS_FILETEST);
373     print ON ")\n\n";
374 }
375
376 print OC "/* ex: set ro: */\n";
377 print ON "/* ex: set ro: */\n";
378
379 close OC or die "Error closing opcode.h: $!";
380 close ON or die "Error closing opnames.h: $!";
381
382 foreach ('opcode.h', 'opnames.h') {
383     safer_rename_silent $_, "$_-old";
384 }
385 safer_rename $opcode_new, 'opcode.h';
386 safer_rename $opname_new, 'opnames.h';
387
388 $pp_proto_new = 'pp_proto.h-new';
389 $pp_sym_new  = 'pp.sym-new';
390
391 open PP, ">$pp_proto_new" or die "Error creating $pp_proto_new: $!";
392 binmode PP;
393 open PPSYM, ">$pp_sym_new" or die "Error creating $pp_sym_new: $!";
394 binmode PPSYM;
395
396 print PP <<"END";
397 /* -*- buffer-read-only: t -*-
398    !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
399    This file is built by opcode.pl from its data.  Any changes made here
400    will be lost!
401 */
402
403 END
404
405 print PPSYM <<"END";
406 # -*- buffer-read-only: t -*-
407 #
408 # !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
409 #   This file is built by opcode.pl from its data.  Any changes made here
410 #   will be lost!
411 #
412
413 END
414
415
416 for (sort keys %ckname) {
417     print PP "PERL_CKDEF(Perl_$_)\n";
418     print PPSYM "Perl_$_\n";
419 #OP *\t", &tab(3,$_),"(OP* o);\n";
420 }
421
422 print PP "\n\n";
423
424 for (@ops) {
425     next if /^i_(pre|post)(inc|dec)$/;
426     next if /^custom$/;
427     print PP "PERL_PPDEF(Perl_pp_$_)\n";
428     print PPSYM "Perl_pp_$_\n";
429 }
430 print PP "\n/* ex: set ro: */\n";
431 print PPSYM "\n# ex: set ro:\n";
432
433 close PP or die "Error closing pp_proto.h: $!";
434 close PPSYM or die "Error closing pp.sym: $!";
435
436 foreach ('pp_proto.h', 'pp.sym') {
437     safer_rename_silent $_, "$_-old";
438 }
439 safer_rename $pp_proto_new, 'pp_proto.h';
440 safer_rename $pp_sym_new, 'pp.sym';
441
442 END {
443   foreach ('opcode.h', 'opnames.h', 'pp_proto.h', 'pp.sym') {
444     1 while unlink "$_-old";
445   }
446 }
447
448 ###########################################################################
449 sub tab {
450     local($l, $t) = @_;
451     $t .= "\t" x ($l - (length($t) + 1) / 8);
452     $t;
453 }
454 ###########################################################################
455
456 # Some comments about 'T' opcode classifier:
457
458 # Safe to set if the ppcode uses:
459 #       tryAMAGICbin, tryAMAGICun, SETn, SETi, SETu, PUSHn, PUSHTARG, SETTARG,
460 #       SETs(TARG), XPUSHn, XPUSHu,
461
462 # Unsafe to set if the ppcode uses dTARG or [X]RETPUSH[YES|NO|UNDEF]
463
464 # lt and friends do SETs (including ncmp, but not scmp)
465
466 # Additional mode of failure: the opcode can modify TARG before it "used"
467 # all the arguments (or may call an external function which does the same).
468 # If the target coincides with one of the arguments ==> kaboom.
469
470 # pp.c  pos substr each not OK (RETPUSHUNDEF)
471 #       substr vec also not OK due to LV to target (are they???)
472 #       ref not OK (RETPUSHNO)
473 #       trans not OK (dTARG; TARG = sv_newmortal();)
474 #       ucfirst etc not OK: TMP arg processed inplace
475 #       quotemeta not OK (unsafe when TARG == arg)
476 #       each repeat not OK too due to list context
477 #       pack split - unknown whether they are safe
478 #       sprintf: is calling do_sprintf(TARG,...) which can act on TARG
479 #         before other args are processed.
480
481 #       Suspicious wrt "additional mode of failure" (and only it):
482 #       schop, chop, postinc/dec, bit_and etc, negate, complement.
483
484 #       Also suspicious: 4-arg substr, sprintf, uc/lc (POK_only), reverse, pack.
485
486 #       substr/vec: doing TAINT_off()???
487
488 # pp_hot.c
489 #       readline - unknown whether it is safe
490 #       match subst not OK (dTARG)
491 #       grepwhile not OK (not always setting)
492 #       join not OK (unsafe when TARG == arg)
493
494 #       Suspicious wrt "additional mode of failure": concat (dealt with
495 #       in ck_sassign()), join (same).
496
497 # pp_ctl.c
498 #       mapwhile flip caller not OK (not always setting)
499
500 # pp_sys.c
501 #       backtick glob warn die not OK (not always setting)
502 #       warn not OK (RETPUSHYES)
503 #       open fileno getc sysread syswrite ioctl accept shutdown
504 #        ftsize(etc) readlink telldir fork alarm getlogin not OK (RETPUSHUNDEF)
505 #       umask select not OK (XPUSHs(&PL_sv_undef);)
506 #       fileno getc sysread syswrite tell not OK (meth("FILENO" "GETC"))
507 #       sselect shm* sem* msg* syscall - unknown whether they are safe
508 #       gmtime not OK (list context)
509
510 #       Suspicious wrt "additional mode of failure": warn, die, select.
511
512 __END__
513
514 # New ops always go at the end, just before 'custom'
515
516 # A recapitulation of the format of this file:
517 # The file consists of five columns: the name of the op, an English
518 # description, the name of the "check" routine used to optimize this
519 # operation, some flags, and a description of the operands.
520
521 # The flags consist of options followed by a mandatory op class signifier
522
523 # The classes are:
524 # baseop      - 0            unop     - 1            binop      - 2
525 # logop       - |            listop   - @            pmop       - /
526 # padop/svop  - $            padop    - # (unused)   loop       - {
527 # baseop/unop - %            loopexop - }            filestatop - -
528 # pvop/svop   - "            cop      - ;
529
530 # Other options are:
531 #   needs stack mark                    - m
532 #   needs constant folding              - f
533 #   produces a scalar                   - s
534 #   produces an integer                 - i
535 #   needs a target                      - t
536 #   target can be in a pad              - T
537 #   has a corresponding integer version - I
538 #   has side effects                    - d
539 #   uses $_ if no argument given        - u
540
541 # Values for the operands are:
542 # scalar      - S            list     - L            array     - A
543 # hash        - H            sub (CV) - C            file      - F
544 # socket      - Fs           filetest - F-           reference - R
545 # "?" denotes an optional operand.
546
547 # Nothing.
548
549 null            null operation          ck_null         0       
550 stub            stub                    ck_null         0
551 scalar          scalar                  ck_fun          s%      S
552
553 # Pushy stuff.
554
555 pushmark        pushmark                ck_null         s0      
556 wantarray       wantarray               ck_null         is0     
557
558 const           constant item           ck_svconst      s$      
559
560 gvsv            scalar variable         ck_null         ds$     
561 gv              glob value              ck_null         ds$     
562 gelem           glob elem               ck_null         d2      S S
563 padsv           private variable        ck_null         ds0
564 padav           private array           ck_null         d0
565 padhv           private hash            ck_null         d0
566 padany          private value           ck_null         d0
567
568 pushre          push regexp             ck_null         d/
569
570 # References and stuff.
571
572 rv2gv           ref-to-glob cast        ck_rvconst      ds1     
573 rv2sv           scalar dereference      ck_rvconst      ds1     
574 av2arylen       array length            ck_null         is1     
575 rv2cv           subroutine dereference  ck_rvconst      d1
576 anoncode        anonymous subroutine    ck_anoncode     $       
577 prototype       subroutine prototype    ck_null         s%      S
578 refgen          reference constructor   ck_spair        m1      L
579 srefgen         single ref constructor  ck_null         fs1     S
580 ref             reference-type operator ck_fun          stu%    S?
581 bless           bless                   ck_fun          s@      S S?
582
583 # Pushy I/O.
584
585 backtick        quoted execution (``, qx)       ck_open         t%      
586 # glob defaults its first arg to $_
587 glob            glob                    ck_glob         t@      S?
588 readline        <HANDLE>                ck_null         t%      F?
589 rcatline        append I/O operator     ck_null         t$
590
591 # Bindable operators.
592
593 regcmaybe       regexp internal guard   ck_fun          s1      S
594 regcreset       regexp internal reset   ck_fun          s1      S
595 regcomp         regexp compilation      ck_null         s|      S
596 match           pattern match (m//)     ck_match        d/
597 qr              pattern quote (qr//)    ck_match        s/
598 subst           substitution (s///)     ck_match        dis/    S
599 substcont       substitution iterator   ck_null         dis|    
600 trans           transliteration (tr///) ck_match        is"     S
601
602 # Lvalue operators.
603 # sassign is special-cased for op class
604
605 sassign         scalar assignment       ck_sassign      s0
606 aassign         list assignment         ck_null         t2      L L
607
608 chop            chop                    ck_spair        mts%    L
609 schop           scalar chop             ck_null         stu%    S?
610 chomp           chomp                   ck_spair        mTs%    L
611 schomp          scalar chomp            ck_null         sTu%    S?
612 defined         defined operator        ck_defined      isu%    S?
613 undef           undef operator          ck_lfun         s%      S?
614 study           study                   ck_fun          su%     S?
615 pos             match position          ck_lfun         stu%    S?
616
617 preinc          preincrement (++)               ck_lfun         dIs1    S
618 i_preinc        integer preincrement (++)       ck_lfun         dis1    S
619 predec          predecrement (--)               ck_lfun         dIs1    S
620 i_predec        integer predecrement (--)       ck_lfun         dis1    S
621 postinc         postincrement (++)              ck_lfun         dIst1   S
622 i_postinc       integer postincrement (++)      ck_lfun         disT1   S
623 postdec         postdecrement (--)              ck_lfun         dIst1   S
624 i_postdec       integer postdecrement (--)      ck_lfun         disT1   S
625
626 # Ordinary operators.
627
628 pow             exponentiation (**)     ck_null         fsT2    S S
629
630 multiply        multiplication (*)      ck_null         IfsT2   S S
631 i_multiply      integer multiplication (*)      ck_null         ifsT2   S S
632 divide          division (/)            ck_null         IfsT2   S S
633 i_divide        integer division (/)    ck_null         ifsT2   S S
634 modulo          modulus (%)             ck_null         IifsT2  S S
635 i_modulo        integer modulus (%)     ck_null         ifsT2   S S
636 repeat          repeat (x)              ck_repeat       mt2     L S
637
638 add             addition (+)            ck_null         IfsT2   S S
639 i_add           integer addition (+)    ck_null         ifsT2   S S
640 subtract        subtraction (-)         ck_null         IfsT2   S S
641 i_subtract      integer subtraction (-) ck_null         ifsT2   S S
642 concat          concatenation (.) or string     ck_concat       fsT2    S S
643 stringify       string                  ck_fun          fsT@    S
644
645 left_shift      left bitshift (<<)      ck_bitop        fsT2    S S
646 right_shift     right bitshift (>>)     ck_bitop        fsT2    S S
647
648 lt              numeric lt (<)          ck_null         Iifs2   S S
649 i_lt            integer lt (<)          ck_null         ifs2    S S
650 gt              numeric gt (>)          ck_null         Iifs2   S S
651 i_gt            integer gt (>)          ck_null         ifs2    S S
652 le              numeric le (<=)         ck_null         Iifs2   S S
653 i_le            integer le (<=)         ck_null         ifs2    S S
654 ge              numeric ge (>=)         ck_null         Iifs2   S S
655 i_ge            integer ge (>=)         ck_null         ifs2    S S
656 eq              numeric eq (==)         ck_null         Iifs2   S S
657 i_eq            integer eq (==)         ck_null         ifs2    S S
658 ne              numeric ne (!=)         ck_null         Iifs2   S S
659 i_ne            integer ne (!=)         ck_null         ifs2    S S
660 ncmp            numeric comparison (<=>)        ck_null         Iifst2  S S
661 i_ncmp          integer comparison (<=>)        ck_null         ifst2   S S
662
663 slt             string lt               ck_null         ifs2    S S
664 sgt             string gt               ck_null         ifs2    S S
665 sle             string le               ck_null         ifs2    S S
666 sge             string ge               ck_null         ifs2    S S
667 seq             string eq               ck_null         ifs2    S S
668 sne             string ne               ck_null         ifs2    S S
669 scmp            string comparison (cmp) ck_null         ifst2   S S
670
671 bit_and         bitwise and (&)         ck_bitop        fst2    S S
672 bit_xor         bitwise xor (^)         ck_bitop        fst2    S S
673 bit_or          bitwise or (|)          ck_bitop        fst2    S S
674
675 negate          negation (-)            ck_null         Ifst1   S
676 i_negate        integer negation (-)    ck_null         ifsT1   S
677 not             not                     ck_null         ifs1    S
678 complement      1's complement (~)      ck_bitop        fst1    S
679
680 # High falutin' math.
681
682 atan2           atan2                   ck_fun          fsT@    S S
683 sin             sin                     ck_fun          fsTu%   S?
684 cos             cos                     ck_fun          fsTu%   S?
685 rand            rand                    ck_fun          sT%     S?
686 srand           srand                   ck_fun          s%      S?
687 exp             exp                     ck_fun          fsTu%   S?
688 log             log                     ck_fun          fsTu%   S?
689 sqrt            sqrt                    ck_fun          fsTu%   S?
690
691 # Lowbrow math.
692
693 int             int                     ck_fun          fsTu%   S?
694 hex             hex                     ck_fun          fsTu%   S?
695 oct             oct                     ck_fun          fsTu%   S?
696 abs             abs                     ck_fun          fsTu%   S?
697
698 # String stuff.
699
700 length          length                  ck_lengthconst  isTu%   S?
701 substr          substr                  ck_substr       st@     S S S? S?
702 vec             vec                     ck_fun          ist@    S S S
703
704 index           index                   ck_index        isT@    S S S?
705 rindex          rindex                  ck_index        isT@    S S S?
706
707 sprintf         sprintf                 ck_fun          mst@    S L
708 formline        formline                ck_fun          ms@     S L
709 ord             ord                     ck_fun          ifsTu%  S?
710 chr             chr                     ck_fun          fsTu%   S?
711 crypt           crypt                   ck_fun          fsT@    S S
712 ucfirst         ucfirst                 ck_fun          fstu%   S?
713 lcfirst         lcfirst                 ck_fun          fstu%   S?
714 uc              uc                      ck_fun          fstu%   S?
715 lc              lc                      ck_fun          fstu%   S?
716 quotemeta       quotemeta               ck_fun          fstu%   S?
717
718 # Arrays.
719
720 rv2av           array dereference       ck_rvconst      dt1     
721 aelemfast       constant array element  ck_null         s$      A S
722 aelem           array element           ck_null         s2      A S
723 aslice          array slice             ck_null         m@      A L
724
725 # Hashes.
726
727 each            each                    ck_fun          %       H
728 values          values                  ck_fun          t%      H
729 keys            keys                    ck_fun          t%      H
730 delete          delete                  ck_delete       %       S
731 exists          exists                  ck_exists       is%     S
732 rv2hv           hash dereference        ck_rvconst      dt1     
733 helem           hash element            ck_null         s2@     H S
734 hslice          hash slice              ck_null         m@      H L
735
736 # Explosives and implosives.
737
738 unpack          unpack                  ck_unpack       @       S S?
739 pack            pack                    ck_fun          mst@    S L
740 split           split                   ck_split        t@      S S S
741 join            join or string          ck_join         mst@    S L
742
743 # List operators.
744
745 list            list                    ck_null         m@      L
746 lslice          list slice              ck_null         2       H L L
747 anonlist        anonymous list ([])     ck_fun          ms@     L
748 anonhash        anonymous hash ({})     ck_fun          ms@     L
749
750 splice          splice                  ck_fun          m@      A S? S? L
751 push            push                    ck_fun          imsT@   A L
752 pop             pop                     ck_shift        s%      A?
753 shift           shift                   ck_shift        s%      A?
754 unshift         unshift                 ck_fun          imsT@   A L
755 sort            sort                    ck_sort         dm@     C? L
756 reverse         reverse                 ck_fun          mt@     L
757
758 grepstart       grep                    ck_grep         dm@     C L
759 grepwhile       grep iterator           ck_null         dt|     
760
761 mapstart        map                     ck_grep         dm@     C L
762 mapwhile        map iterator            ck_null         dt|
763
764 # Range stuff.
765
766 range           flipflop                ck_null         |       S S
767 flip            range (or flip)         ck_null         1       S S
768 flop            range (or flop)         ck_null         1
769
770 # Control.
771
772 and             logical and (&&)                ck_null         |       
773 or              logical or (||)                 ck_null         |       
774 xor             logical xor                     ck_null         fs2     S S     
775 cond_expr       conditional expression          ck_null         d|      
776 andassign       logical and assignment (&&=)    ck_null         s|      
777 orassign        logical or assignment (||=)     ck_null         s|      
778
779 method          method lookup           ck_method       d1
780 entersub        subroutine entry        ck_subr         dmt1    L
781 leavesub        subroutine exit         ck_null         1       
782 leavesublv      lvalue subroutine return        ck_null         1       
783 caller          caller                  ck_fun          t%      S?
784 warn            warn                    ck_fun          imst@   L
785 die             die                     ck_die          dimst@  L
786 reset           symbol reset            ck_fun          is%     S?
787
788 lineseq         line sequence           ck_null         @       
789 nextstate       next statement          ck_null         s;      
790 dbstate         debug next statement    ck_null         s;      
791 unstack         iteration finalizer     ck_null         s0
792 enter           block entry             ck_null         0       
793 leave           block exit              ck_null         @       
794 scope           block                   ck_null         @       
795 enteriter       foreach loop entry      ck_null         d{      
796 iter            foreach loop iterator   ck_null         0       
797 enterloop       loop entry              ck_null         d{      
798 leaveloop       loop exit               ck_null         2       
799 return          return                  ck_return       dm@     L
800 last            last                    ck_null         ds}     
801 next            next                    ck_null         ds}     
802 redo            redo                    ck_null         ds}     
803 dump            dump                    ck_null         ds}     
804 goto            goto                    ck_null         ds}     
805 exit            exit                    ck_exit         ds%     S?
806 # continued below
807
808 #nswitch        numeric switch          ck_null         d       
809 #cswitch        character switch        ck_null         d       
810
811 # I/O.
812
813 open            open                    ck_open         ismt@   F S? L
814 close           close                   ck_fun          is%     F?
815 pipe_op         pipe                    ck_fun          is@     F F
816
817 fileno          fileno                  ck_fun          ist%    F
818 umask           umask                   ck_fun          ist%    S?
819 binmode         binmode                 ck_fun          s@      F S?
820
821 tie             tie                     ck_fun          idms@   R S L
822 untie           untie                   ck_fun          is%     R
823 tied            tied                    ck_fun          s%      R
824 dbmopen         dbmopen                 ck_fun          is@     H S S
825 dbmclose        dbmclose                ck_fun          is%     H
826
827 sselect         select system call      ck_select       t@      S S S S
828 select          select                  ck_select       st@     F?
829
830 getc            getc                    ck_eof          st%     F?
831 read            read                    ck_fun          imst@   F R S S?
832 enterwrite      write                   ck_fun          dis%    F?
833 leavewrite      write exit              ck_null         1       
834
835 prtf            printf                  ck_listiob      ims@    F? L
836 print           print                   ck_listiob      ims@    F? L
837
838 sysopen         sysopen                 ck_fun          s@      F S S S?
839 sysseek         sysseek                 ck_fun          s@      F S S
840 sysread         sysread                 ck_fun          imst@   F R S S?
841 syswrite        syswrite                ck_fun          imst@   F S S? S?
842
843 send            send                    ck_fun          imst@   Fs S S S?
844 recv            recv                    ck_fun          imst@   Fs R S S
845
846 eof             eof                     ck_eof          is%     F?
847 tell            tell                    ck_fun          st%     F?
848 seek            seek                    ck_fun          s@      F S S
849 # truncate really behaves as if it had both "S S" and "F S"
850 truncate        truncate                ck_trunc        is@     S S
851
852 fcntl           fcntl                   ck_fun          st@     F S S
853 ioctl           ioctl                   ck_fun          st@     F S S
854 flock           flock                   ck_fun          isT@    F S
855
856 # Sockets.
857
858 socket          socket                  ck_fun          is@     Fs S S S
859 sockpair        socketpair              ck_fun          is@     Fs Fs S S S
860
861 bind            bind                    ck_fun          is@     Fs S
862 connect         connect                 ck_fun          is@     Fs S
863 listen          listen                  ck_fun          is@     Fs S
864 accept          accept                  ck_fun          ist@    Fs Fs
865 shutdown        shutdown                ck_fun          ist@    Fs S
866
867 gsockopt        getsockopt              ck_fun          is@     Fs S S
868 ssockopt        setsockopt              ck_fun          is@     Fs S S S
869
870 getsockname     getsockname             ck_fun          is%     Fs
871 getpeername     getpeername             ck_fun          is%     Fs
872
873 # Stat calls.
874
875 lstat           lstat                   ck_ftst         u-      F
876 stat            stat                    ck_ftst         u-      F
877 ftrread         -R                      ck_ftst         isu-    F-
878 ftrwrite        -W                      ck_ftst         isu-    F-
879 ftrexec         -X                      ck_ftst         isu-    F-
880 fteread         -r                      ck_ftst         isu-    F-
881 ftewrite        -w                      ck_ftst         isu-    F-
882 fteexec         -x                      ck_ftst         isu-    F-
883 ftis            -e                      ck_ftst         isu-    F-
884 fteowned        -o                      ck_ftst         isu-    F-
885 ftrowned        -O                      ck_ftst         isu-    F-
886 ftzero          -z                      ck_ftst         isu-    F-
887 ftsize          -s                      ck_ftst         istu-   F-
888 ftmtime         -M                      ck_ftst         stu-    F-
889 ftatime         -A                      ck_ftst         stu-    F-
890 ftctime         -C                      ck_ftst         stu-    F-
891 ftsock          -S                      ck_ftst         isu-    F-
892 ftchr           -c                      ck_ftst         isu-    F-
893 ftblk           -b                      ck_ftst         isu-    F-
894 ftfile          -f                      ck_ftst         isu-    F-
895 ftdir           -d                      ck_ftst         isu-    F-
896 ftpipe          -p                      ck_ftst         isu-    F-
897 ftlink          -l                      ck_ftst         isu-    F-
898 ftsuid          -u                      ck_ftst         isu-    F-
899 ftsgid          -g                      ck_ftst         isu-    F-
900 ftsvtx          -k                      ck_ftst         isu-    F-
901 fttty           -t                      ck_ftst         is-     F-
902 fttext          -T                      ck_ftst         isu-    F-
903 ftbinary        -B                      ck_ftst         isu-    F-
904
905 # File calls.
906
907 chdir           chdir                   ck_fun          isT%    S?
908 chown           chown                   ck_fun          imsT@   L
909 chroot          chroot                  ck_fun          isTu%   S?
910 unlink          unlink                  ck_fun          imsTu@  L
911 chmod           chmod                   ck_fun          imsT@   L
912 utime           utime                   ck_fun          imsT@   L
913 rename          rename                  ck_fun          isT@    S S
914 link            link                    ck_fun          isT@    S S
915 symlink         symlink                 ck_fun          isT@    S S
916 readlink        readlink                ck_fun          stu%    S?
917 mkdir           mkdir                   ck_fun          isTu@   S? S?
918 rmdir           rmdir                   ck_fun          isTu%   S?
919
920 # Directory calls.
921
922 open_dir        opendir                 ck_fun          is@     F S
923 readdir         readdir                 ck_fun          %       F
924 telldir         telldir                 ck_fun          st%     F
925 seekdir         seekdir                 ck_fun          s@      F S
926 rewinddir       rewinddir               ck_fun          s%      F
927 closedir        closedir                ck_fun          is%     F
928
929 # Process control.
930
931 fork            fork                    ck_null         ist0    
932 wait            wait                    ck_null         isT0    
933 waitpid         waitpid                 ck_fun          isT@    S S
934 system          system                  ck_exec         imsT@   S? L
935 exec            exec                    ck_exec         dimsT@  S? L
936 kill            kill                    ck_fun          dimsT@  L
937 getppid         getppid                 ck_null         isT0    
938 getpgrp         getpgrp                 ck_fun          isT%    S?
939 setpgrp         setpgrp                 ck_fun          isT@    S? S?
940 getpriority     getpriority             ck_fun          isT@    S S
941 setpriority     setpriority             ck_fun          isT@    S S S
942
943 # Time calls.
944
945 # NOTE: MacOS patches the 'i' of time() away later when the interpreter
946 # is created because in MacOS time() is already returning times > 2**31-1,
947 # that is, non-integers.
948
949 time            time                    ck_null         isT0    
950 tms             times                   ck_null         0       
951 localtime       localtime               ck_fun          t%      S?
952 gmtime          gmtime                  ck_fun          t%      S?
953 alarm           alarm                   ck_fun          istu%   S?
954 sleep           sleep                   ck_fun          isT%    S?
955
956 # Shared memory.
957
958 shmget          shmget                  ck_fun          imst@   S S S
959 shmctl          shmctl                  ck_fun          imst@   S S S
960 shmread         shmread                 ck_fun          imst@   S S S S
961 shmwrite        shmwrite                ck_fun          imst@   S S S S
962
963 # Message passing.
964
965 msgget          msgget                  ck_fun          imst@   S S
966 msgctl          msgctl                  ck_fun          imst@   S S S
967 msgsnd          msgsnd                  ck_fun          imst@   S S S
968 msgrcv          msgrcv                  ck_fun          imst@   S S S S S
969
970 # Semaphores.
971
972 semget          semget                  ck_fun          imst@   S S S
973 semctl          semctl                  ck_fun          imst@   S S S S
974 semop           semop                   ck_fun          imst@   S S
975
976 # Eval.
977
978 require         require                 ck_require      du%     S?
979 dofile          do "file"               ck_fun          d1      S
980 entereval       eval "string"           ck_eval         d%      S
981 leaveeval       eval "string" exit      ck_null         1       S
982 #evalonce       eval constant string    ck_null         d1      S
983 entertry        eval {block}            ck_null         |       
984 leavetry        eval {block} exit       ck_null         @       
985
986 # Get system info.
987
988 ghbyname        gethostbyname           ck_fun          %       S
989 ghbyaddr        gethostbyaddr           ck_fun          @       S S
990 ghostent        gethostent              ck_null         0       
991 gnbyname        getnetbyname            ck_fun          %       S
992 gnbyaddr        getnetbyaddr            ck_fun          @       S S
993 gnetent         getnetent               ck_null         0       
994 gpbyname        getprotobyname          ck_fun          %       S
995 gpbynumber      getprotobynumber        ck_fun          @       S
996 gprotoent       getprotoent             ck_null         0       
997 gsbyname        getservbyname           ck_fun          @       S S
998 gsbyport        getservbyport           ck_fun          @       S S
999 gservent        getservent              ck_null         0       
1000 shostent        sethostent              ck_fun          is%     S
1001 snetent         setnetent               ck_fun          is%     S
1002 sprotoent       setprotoent             ck_fun          is%     S
1003 sservent        setservent              ck_fun          is%     S
1004 ehostent        endhostent              ck_null         is0     
1005 enetent         endnetent               ck_null         is0     
1006 eprotoent       endprotoent             ck_null         is0     
1007 eservent        endservent              ck_null         is0     
1008 gpwnam          getpwnam                ck_fun          %       S
1009 gpwuid          getpwuid                ck_fun          %       S
1010 gpwent          getpwent                ck_null         0       
1011 spwent          setpwent                ck_null         is0     
1012 epwent          endpwent                ck_null         is0     
1013 ggrnam          getgrnam                ck_fun          %       S
1014 ggrgid          getgrgid                ck_fun          %       S
1015 ggrent          getgrent                ck_null         0       
1016 sgrent          setgrent                ck_null         is0     
1017 egrent          endgrent                ck_null         is0     
1018 getlogin        getlogin                ck_null         st0     
1019
1020 # Miscellaneous.
1021
1022 syscall         syscall                 ck_fun          imst@   S L
1023
1024 # For multi-threading
1025 lock            lock                    ck_rfun         s%      R
1026 threadsv        per-thread value        ck_null         ds0
1027
1028 # Control (contd.)
1029 setstate        set statement info      ck_null         s;
1030 method_named    method with known name  ck_null         d$
1031
1032 dor             defined or (//)                 ck_null         |
1033 dorassign       defined or assignment (//=)     ck_null         s|
1034
1035 entergiven      given()                 ck_null         d|
1036 leavegiven      leave given block       ck_null         1
1037 enterwhen       when()                  ck_null         d|
1038 leavewhen       leave when block        ck_null         1
1039 break           break                   ck_null         0
1040 continue        continue                ck_null         0
1041 smartmatch      smart match             ck_smartmatch   s2
1042
1043 say             say                     ck_say          ims@    F? L
1044
1045 # Add new ops before this, the custom operator.
1046
1047 custom          unknown custom operator         ck_null         0