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