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