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