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