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