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