This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.002beta2 patch: toke.c
[perl5.git] / opcode.pl
CommitLineData
79072805
LW
1#!/usr/bin/perl
2
3open(OC, ">opcode.h") || die "Can't create opcode.h: $!\n";
4select OC;
5
6# Read data.
7
8while (<DATA>) {
9 chop;
10 next unless $_;
11 next if /^#/;
12 ($key, $name, $check, $flags, $args) = split(/\t+/, $_, 5);
13 push(@ops, $key);
14 $name{$key} = $name;
15 $check{$key} = $check;
16 $ckname{$check}++;
17 $flags{$key} = $flags;
18 $args{$key} = $args;
19}
20
21# Emit defines.
22
23$i = 0;
748a9306
LW
24print <<"END";
25#define pp_i_preinc pp_preinc
26#define pp_i_predec pp_predec
27#define pp_i_postinc pp_postinc
28#define pp_i_postdec pp_postdec
29
30typedef enum {
31END
79072805
LW
32for (@ops) {
33 print "\t", &tab(3,"OP_\U$_,"), "/* ", $i++, " */\n";
34}
85e6fe83 35print "\t", &tab(3,"OP_max"), "\n";
79072805
LW
36print "} opcode;\n";
37print "\n#define MAXO ", scalar @ops, "\n\n";
38
39# Emit opnames.
40
41print <<END;
42#ifndef DOINIT
a0d0e21e 43EXT char *op_name[];
79072805 44#else
a0d0e21e 45EXT char *op_name[] = {
79072805
LW
46END
47
48for (@ops) {
49 print qq(\t"$name{$_}",\n);
50}
51
52print <<END;
53};
54#endif
55
56END
57
58# Emit function declarations.
59
60for (sort keys %ckname) {
a0d0e21e 61 print "OP *\t", &tab(3,$_),"_((OP* op));\n";
79072805
LW
62}
63
64print "\n";
65
66for (@ops) {
a0d0e21e 67 print "OP *\t", &tab(3, "pp_\L$_"), "_((void));\n";
79072805
LW
68}
69
70# Emit ppcode switch array.
71
72print <<END;
73
74#ifndef DOINIT
a0d0e21e 75EXT OP * (*ppaddr[])();
79072805 76#else
a0d0e21e 77EXT OP * (*ppaddr[])() = {
79072805
LW
78END
79
80for (@ops) {
81 print "\tpp_\L$_,\n";
82}
83
84print <<END;
85};
86#endif
87
88END
89
90# Emit check routines.
91
92print <<END;
93#ifndef DOINIT
a0d0e21e 94EXT OP * (*check[])();
79072805 95#else
a0d0e21e 96EXT OP * (*check[])() = {
79072805
LW
97END
98
99for (@ops) {
100 print "\t", &tab(3, "$check{$_},"), "/* \L$_ */\n";
101}
102
103print <<END;
104};
105#endif
106
107END
108
109# Emit allowed argument types.
110
111print <<END;
112#ifndef DOINIT
113EXT U32 opargs[];
114#else
a0d0e21e 115EXT U32 opargs[] = {
79072805
LW
116END
117
118%argnum = (
119 S, 1, # scalar
120 L, 2, # list
121 A, 3, # array value
122 H, 4, # hash value
123 C, 5, # code value
124 F, 6, # file value
125 R, 7, # scalar reference
126);
127
128for (@ops) {
129 $argsum = 0;
130 $flags = $flags{$_};
131 $argsum |= 1 if $flags =~ /m/; # needs stack mark
132 $argsum |= 2 if $flags =~ /f/; # fold constants
133 $argsum |= 4 if $flags =~ /s/; # always produces scalar
134 $argsum |= 8 if $flags =~ /t/; # needs target scalar
135 $argsum |= 16 if $flags =~ /i/; # always produces integer
136 $argsum |= 32 if $flags =~ /I/; # has corresponding int op
137 $argsum |= 64 if $flags =~ /d/; # danger, unknown side effects
a0d0e21e 138 $argsum |= 128 if $flags =~ /u/; # defaults to $_
79072805
LW
139 $mul = 256;
140 for $arg (split(' ',$args{$_})) {
141 $argnum = ($arg =~ s/\?//) ? 8 : 0;
142 $argnum += $argnum{$arg};
143 $argsum += $argnum * $mul;
144 $mul <<= 4;
145 }
146 $argsum = sprintf("0x%08x", $argsum);
147 print "\t", &tab(3, "$argsum,"), "/* \L$_ */\n";
148}
149
150print <<END;
151};
152#endif
153END
154
155###########################################################################
156sub tab {
157 local($l, $t) = @_;
158 $t .= "\t" x ($l - (length($t) + 1) / 8);
159 $t;
160}
161###########################################################################
162__END__
163
164# Nothing.
165
166null null operation ck_null 0
93a17b20
LW
167stub stub ck_null 0
168scalar scalar ck_fun s S
79072805
LW
169
170# Pushy stuff.
171
172pushmark pushmark ck_null s
173wantarray wantarray ck_null is
174
8990e307 175const constant item ck_svconst s
79072805
LW
176
177gvsv scalar variable ck_null ds
178gv glob value ck_null ds
748a9306
LW
179padsv private variable ck_null ds
180padav private array ck_null d
181padhv private hash ck_null d
182padany private something ck_null d
79072805
LW
183
184pushre push regexp ck_null 0
185
186# References and stuff.
187
188rv2gv ref-to-glob cast ck_rvconst ds
189sv2len scalar value length ck_null ist
a0d0e21e 190rv2sv scalar deref ck_rvconst ds
79072805 191av2arylen array length ck_null is
a0d0e21e
LW
192rv2cv subroutine deref ck_rvconst d
193anoncode anonymous subroutine ck_null 0
194refgen reference constructor ck_spair m L
195srefgen scalar ref constructor ck_null fs S
196ref reference-type operator ck_fun stu S?
463ee0b2 197bless bless ck_fun s S S?
79072805
LW
198
199# Pushy I/O.
200
201backtick backticks ck_null t
a0d0e21e 202glob glob ck_glob t S S
79072805
LW
203readline <HANDLE> ck_null t
204rcatline append I/O operator ck_null t
205
206# Bindable operators.
207
463ee0b2 208regcmaybe regexp comp once ck_fun s S
79072805
LW
209regcomp regexp compilation ck_null s S
210match pattern match ck_match d
211subst substitution ck_null dis S
212substcont substitution cont ck_null dis
213trans character translation ck_null is S
214
215# Lvalue operators.
216
217sassign scalar assignment ck_null s
218aassign list assignment ck_null t L L
219
a0d0e21e
LW
220chop chop ck_spair mts L
221schop scalar chop ck_null stu S?
222chomp safe chop ck_spair mts L
223schomp scalar safe chop ck_null stu S?
224defined defined operator ck_rfun isu S?
79072805 225undef undef operator ck_lfun s S?
a0d0e21e
LW
226study study ck_fun stu S?
227pos match position ck_lfun stu S?
228
229preinc preincrement ck_lfun dIs S
230i_preinc integer preincrement ck_lfun dis S
231predec predecrement ck_lfun dIs S
232i_predec integer predecrement ck_lfun dis S
233postinc postincrement ck_lfun dIst S
234i_postinc integer postincrement ck_lfun dist S
235postdec postdecrement ck_lfun dIst S
236i_postdec integer postdecrement ck_lfun dist S
79072805
LW
237
238# Ordinary operators.
239
a0d0e21e 240pow exponentiation ck_null fst S S
79072805 241
85e6fe83
LW
242multiply multiplication ck_null Ifst S S
243i_multiply integer multiplication ck_null ifst S S
244divide division ck_null Ifst S S
245i_divide integer division ck_null ifst S S
246modulo modulus ck_null Iifst S S
247i_modulo integer modulus ck_null ifst S S
79072805
LW
248repeat repeat ck_repeat mt L S
249
250add addition ck_null Ifst S S
85e6fe83
LW
251i_add integer addition ck_null ifst S S
252subtract subtraction ck_null Ifst S S
253i_subtract integer subtraction ck_null ifst S S
79072805 254concat concatenation ck_concat fst S S
a0d0e21e 255stringify string ck_fun fst S
79072805
LW
256
257left_shift left bitshift ck_null ifst S S
258right_shift right bitshift ck_null ifst S S
259
85e6fe83
LW
260lt numeric lt ck_null Iifs S S
261i_lt integer lt ck_null ifs S S
262gt numeric gt ck_null Iifs S S
263i_gt integer gt ck_null ifs S S
264le numeric le ck_null Iifs S S
265i_le integer le ck_null ifs S S
266ge numeric ge ck_null Iifs S S
267i_ge integer ge ck_null ifs S S
268eq numeric eq ck_null Iifs S S
269i_eq integer eq ck_null ifs S S
270ne numeric ne ck_null Iifs S S
271i_ne integer ne ck_null ifs S S
a0d0e21e 272ncmp spaceship operator ck_null Iifst S S
85e6fe83 273i_ncmp integer spaceship ck_null ifst S S
79072805
LW
274
275slt string lt ck_null ifs S S
276sgt string gt ck_null ifs S S
277sle string le ck_null ifs S S
278sge string ge ck_null ifs S S
279seq string eq ck_null ifs S S
280sne string ne ck_null ifs S S
281scmp string comparison ck_null ifst S S
282
a0d0e21e
LW
283bit_and bitwise and ck_null fst S S
284bit_xor bitwise xor ck_null fst S S
285bit_or bitwise or ck_null fst S S
79072805 286
85e6fe83
LW
287negate negate ck_null Ifst S
288i_negate integer negate ck_null ifst S
79072805
LW
289not not ck_null ifs S
290complement 1's complement ck_null fst S
291
292# High falutin' math.
293
294atan2 atan2 ck_fun fst S S
a0d0e21e
LW
295sin sin ck_fun fstu S?
296cos cos ck_fun fstu S?
79072805
LW
297rand rand ck_fun st S?
298srand srand ck_fun s S?
a0d0e21e
LW
299exp exp ck_fun fstu S?
300log log ck_fun fstu S?
301sqrt sqrt ck_fun fstu S?
79072805 302
a0d0e21e
LW
303int int ck_fun fstu S?
304hex hex ck_fun istu S?
305oct oct ck_fun istu S?
306abs abs ck_fun fstu S?
79072805
LW
307
308# String stuff.
309
a0d0e21e 310length length ck_lengthconst istu S?
79072805
LW
311substr substr ck_fun st S S S?
312vec vec ck_fun ist S S S
313
314index index ck_index ist S S S?
315rindex rindex ck_index ist S S S?
316
317sprintf sprintf ck_fun mst S L
318formline formline ck_formline ms S L
a0d0e21e
LW
319ord ord ck_fun ifstu S?
320chr chr ck_fun fstu S?
79072805 321crypt crypt ck_fun fst S S
a0d0e21e
LW
322ucfirst upper case first ck_fun fst S
323lcfirst lower case first ck_fun fst S
324uc upper case ck_fun fst S
325lc lower case ck_fun fst S
326quotemeta quote metachars ck_fun fst S
79072805
LW
327
328# Arrays.
329
330rv2av array deref ck_rvconst dt
331aelemfast known array element ck_null s A S
8990e307 332aelem array element ck_null s A S
79072805
LW
333aslice array slice ck_null m A L
334
335# Associative arrays.
336
337each each ck_fun t H
338values values ck_fun t H
339keys keys ck_fun t H
a0d0e21e
LW
340delete delete ck_delete s S
341exists exists operator ck_delete is S
79072805
LW
342rv2hv associative array deref ck_rvconst dt
343helem associative array elem ck_null s H S
344hslice associative array slice ck_null m H L
345
346# Explosives and implosives.
347
348unpack unpack ck_fun 0 S S
349pack pack ck_fun mst S L
350split split ck_split t S S S
351join join ck_fun mst S L
352
353# List operators.
354
355list list ck_null m L
356lslice list slice ck_null 0 H L L
a0d0e21e
LW
357anonlist anonymous list ck_fun ms L
358anonhash anonymous hash ck_fun ms L
79072805 359
a0d0e21e 360splice splice ck_fun m A S? S? L
79072805
LW
361push push ck_fun imst A L
362pop pop ck_shift s A
363shift shift ck_shift s A
364unshift unshift ck_fun imst A L
365sort sort ck_sort m C? L
366reverse reverse ck_fun mt L
367
368grepstart grep ck_grep dm C L
369grepwhile grep iterator ck_null dt
370
a0d0e21e
LW
371mapstart map ck_grep dm C L
372mapwhile map iterator ck_null dt
373
79072805
LW
374# Range stuff.
375
376range flipflop ck_null 0 S S
377flip range (or flip) ck_null 0 S S
378flop range (or flop) ck_null 0
379
380# Control.
381
382and logical and ck_null 0
383or logical or ck_null 0
a0d0e21e 384xor logical xor ck_null fs S S
4633a7c4 385cond_expr conditional expression ck_null d
79072805
LW
386andassign logical and assignment ck_null s
387orassign logical or assignment ck_null s
388
463ee0b2 389method method lookup ck_null d
a0d0e21e
LW
390entersub subroutine entry ck_subr dmt L
391leavesub subroutine exit ck_null 0
79072805
LW
392caller caller ck_fun t S?
393warn warn ck_fun imst L
394die die ck_fun dimst L
395reset reset ck_fun is S?
396
397lineseq line sequence ck_null 0
93a17b20
LW
398nextstate next statement ck_null s
399dbstate debug next statement ck_null s
79072805
LW
400unstack unstack ck_null s
401enter block entry ck_null 0
402leave block exit ck_null 0
463ee0b2 403scope block ck_null 0
79072805
LW
404enteriter foreach loop entry ck_null d
405iter foreach loop iterator ck_null 0
406enterloop loop entry ck_null d
a0d0e21e 407leaveloop loop exit ck_null 0
748a9306 408return return ck_null dm L
79072805
LW
409last last ck_null ds
410next next ck_null ds
411redo redo ck_null ds
412dump dump ck_null ds
413goto goto ck_null ds
414exit exit ck_fun ds S?
415
a0d0e21e
LW
416#nswitch numeric switch ck_null d
417#cswitch character switch ck_null d
79072805
LW
418
419# I/O.
420
421open open ck_fun ist F S?
422close close ck_fun is F?
423pipe_op pipe ck_fun is F F
424
425fileno fileno ck_fun ist F
426umask umask ck_fun ist S?
427binmode binmode ck_fun s F
428
463ee0b2
LW
429tie tie ck_fun idms R S L
430untie untie ck_fun is R
431dbmopen dbmopen ck_fun is H S S
79072805
LW
432dbmclose dbmclose ck_fun is H
433
434sselect select system call ck_select t S S S S
435select select ck_select st F?
436
437getc getc ck_eof st F?
438read read ck_fun imst F R S S?
439enterwrite write ck_fun dis F?
440leavewrite write exit ck_null 0
441
463ee0b2 442prtf printf ck_listiob ims F? L
79072805
LW
443print print ck_listiob ims F? L
444
445sysread sysread ck_fun imst F R S S?
446syswrite syswrite ck_fun imst F S S S?
447
448send send ck_fun imst F S S S?
449recv recv ck_fun imst F R S S
450
451eof eof ck_eof is F?
452tell tell ck_fun st F?
453seek seek ck_fun s F S S
454truncate truncate ck_trunc is S S
455
456fcntl fcntl ck_fun st F S S
457ioctl ioctl ck_fun st F S S
458flock flock ck_fun ist F S
459
460# Sockets.
461
462socket socket ck_fun is F S S S
463sockpair socketpair ck_fun is F F S S S
464
465bind bind ck_fun is F S
466connect connect ck_fun is F S
467listen listen ck_fun is F S
468accept accept ck_fun ist F F
469shutdown shutdown ck_fun ist F S
470
471gsockopt getsockopt ck_fun is F S S
472ssockopt setsockopt ck_fun is F S S S
473
474getsockname getsockname ck_fun is F
475getpeername getpeername ck_fun is F
476
477# Stat calls.
478
a0d0e21e
LW
479lstat lstat ck_ftst u F
480stat stat ck_ftst u F
481ftrread -R ck_ftst isu F
482ftrwrite -W ck_ftst isu F
483ftrexec -X ck_ftst isu F
484fteread -r ck_ftst isu F
485ftewrite -w ck_ftst isu F
486fteexec -x ck_ftst isu F
487ftis -e ck_ftst isu F
488fteowned -O ck_ftst isu F
489ftrowned -o ck_ftst isu F
490ftzero -z ck_ftst isu F
491ftsize -s ck_ftst istu F
492ftmtime -M ck_ftst stu F
493ftatime -A ck_ftst stu F
494ftctime -C ck_ftst stu F
495ftsock -S ck_ftst isu F
496ftchr -c ck_ftst isu F
497ftblk -b ck_ftst isu F
498ftfile -f ck_ftst isu F
499ftdir -d ck_ftst isu F
500ftpipe -p ck_ftst isu F
501ftlink -l ck_ftst isu F
502ftsuid -u ck_ftst isu F
503ftsgid -g ck_ftst isu F
504ftsvtx -k ck_ftst isu F
79072805 505fttty -t ck_ftst is F
a0d0e21e
LW
506fttext -T ck_ftst isu F
507ftbinary -B ck_ftst isu F
79072805
LW
508
509# File calls.
510
511chdir chdir ck_fun ist S?
512chown chown ck_fun imst L
a0d0e21e
LW
513chroot chroot ck_fun istu S?
514unlink unlink ck_fun imstu L
79072805
LW
515chmod chmod ck_fun imst L
516utime utime ck_fun imst L
517rename rename ck_fun ist S S
518link link ck_fun ist S S
519symlink symlink ck_fun ist S S
a0d0e21e 520readlink readlink ck_fun stu S?
79072805 521mkdir mkdir ck_fun ist S S
a0d0e21e 522rmdir rmdir ck_fun istu S?
79072805
LW
523
524# Directory calls.
525
526open_dir opendir ck_fun is F S
527readdir readdir ck_fun 0 F
528telldir telldir ck_fun st F
529seekdir seekdir ck_fun s F S
530rewinddir rewinddir ck_fun s F
531closedir closedir ck_fun is F
532
533# Process control.
534
535fork fork ck_null ist
536wait wait ck_null ist
537waitpid waitpid ck_fun ist S S
538system system ck_exec imst S? L
539exec exec ck_exec dimst S? L
540kill kill ck_fun dimst L
541getppid getppid ck_null ist
542getpgrp getpgrp ck_fun ist S?
a0d0e21e 543setpgrp setpgrp ck_fun ist S? S?
79072805
LW
544getpriority getpriority ck_fun ist S S
545setpriority setpriority ck_fun ist S S S
546
547# Time calls.
548
549time time ck_null ist
550tms times ck_null 0
551localtime localtime ck_fun t S?
552gmtime gmtime ck_fun t S?
a0d0e21e 553alarm alarm ck_fun istu S?
79072805
LW
554sleep sleep ck_fun ist S?
555
556# Shared memory.
557
558shmget shmget ck_fun imst S S S
559shmctl shmctl ck_fun imst S S S
560shmread shmread ck_fun imst S S S S
16d20bd9 561shmwrite shmwrite ck_fun imst S S S S
79072805
LW
562
563# Message passing.
564
565msgget msgget ck_fun imst S S
566msgctl msgctl ck_fun imst S S S
567msgsnd msgsnd ck_fun imst S S S
568msgrcv msgrcv ck_fun imst S S S S S
569
570# Semaphores.
571
572semget semget ck_fun imst S S S
573semctl semctl ck_fun imst S S S S
ecfc5424 574semop semop ck_fun imst S S
79072805
LW
575
576# Eval.
577
a0d0e21e 578require require ck_require du S?
79072805
LW
579dofile do 'file' ck_fun d S
580entereval eval string ck_eval d S
581leaveeval eval exit ck_null 0 S
a0d0e21e 582#evalonce eval constant string ck_null d S
79072805
LW
583entertry eval block ck_null 0
584leavetry eval block exit ck_null 0
585
586# Get system info.
587
588ghbyname gethostbyname ck_fun 0 S
589ghbyaddr gethostbyaddr ck_fun 0 S S
590ghostent gethostent ck_null 0
591gnbyname getnetbyname ck_fun 0 S
592gnbyaddr getnetbyaddr ck_fun 0 S S
593gnetent getnetent ck_null 0
594gpbyname getprotobyname ck_fun 0 S
595gpbynumber getprotobynumber ck_fun 0 S
596gprotoent getprotoent ck_null 0
597gsbyname getservbyname ck_fun 0 S S
598gsbyport getservbyport ck_fun 0 S S
599gservent getservent ck_null 0
93a17b20
LW
600shostent sethostent ck_fun is S
601snetent setnetent ck_fun is S
602sprotoent setprotoent ck_fun is S
603sservent setservent ck_fun is S
604ehostent endhostent ck_null is
605enetent endnetent ck_null is
606eprotoent endprotoent ck_null is
607eservent endservent ck_null is
79072805
LW
608gpwnam getpwnam ck_fun 0 S
609gpwuid getpwuid ck_fun 0 S
610gpwent getpwent ck_null 0
a0d0e21e
LW
611spwent setpwent ck_null is
612epwent endpwent ck_null is
79072805
LW
613ggrnam getgrnam ck_fun 0 S
614ggrgid getgrgid ck_fun 0 S
615ggrent getgrent ck_null 0
a0d0e21e
LW
616sgrent setgrent ck_null is
617egrent endgrent ck_null is
79072805
LW
618getlogin getlogin ck_null st
619
620# Miscellaneous.
621
a0d0e21e 622syscall syscall ck_fun imst S L