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