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