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