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