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