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