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