[inseparable changes from patch from perl5.003_12 to perl5.003_13]
[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
a0d0e21e 227glob glob ck_glob t S S
79072805 228readline <HANDLE> ck_null t
229rcatline append I/O operator ck_null t
230
231# Bindable operators.
232
463ee0b2 233regcmaybe regexp comp once ck_fun s S
79072805 234regcomp regexp compilation ck_null s S
235match pattern match ck_match d
236subst substitution ck_null dis S
237substcont substitution cont ck_null dis
238trans character translation ck_null is S
239
240# Lvalue operators.
241
242sassign scalar assignment ck_null s
243aassign list assignment ck_null t L L
244
a0d0e21e 245chop chop ck_spair mts L
246schop scalar chop ck_null stu S?
247chomp safe chop ck_spair mts L
248schomp scalar safe chop ck_null stu S?
249defined defined operator ck_rfun isu S?
79072805 250undef undef operator ck_lfun s S?
c07a80fd 251study study ck_fun su S?
a0d0e21e 252pos match position ck_lfun stu S?
253
254preinc preincrement ck_lfun dIs S
255i_preinc integer preincrement ck_lfun dis S
256predec predecrement ck_lfun dIs S
257i_predec integer predecrement ck_lfun dis S
258postinc postincrement ck_lfun dIst S
259i_postinc integer postincrement ck_lfun dist S
260postdec postdecrement ck_lfun dIst S
261i_postdec integer postdecrement ck_lfun dist S
79072805 262
263# Ordinary operators.
264
a0d0e21e 265pow exponentiation ck_null fst S S
79072805 266
85e6fe83 267multiply multiplication ck_null Ifst S S
268i_multiply integer multiplication ck_null ifst S S
269divide division ck_null Ifst S S
270i_divide integer division ck_null ifst S S
271modulo modulus ck_null Iifst S S
272i_modulo integer modulus ck_null ifst S S
79072805 273repeat repeat ck_repeat mt L S
274
275add addition ck_null Ifst S S
85e6fe83 276i_add integer addition ck_null ifst S S
277subtract subtraction ck_null Ifst S S
278i_subtract integer subtraction ck_null ifst S S
79072805 279concat concatenation ck_concat fst S S
a0d0e21e 280stringify string ck_fun fst S
79072805 281
55497cff 282left_shift left bitshift ck_bitop fst S S
283right_shift right bitshift ck_bitop fst S S
79072805 284
85e6fe83 285lt numeric lt ck_null Iifs S S
286i_lt integer lt ck_null ifs S S
287gt numeric gt ck_null Iifs S S
288i_gt integer gt ck_null ifs S S
289le numeric le ck_null Iifs S S
290i_le integer le ck_null ifs S S
291ge numeric ge ck_null Iifs S S
292i_ge integer ge ck_null ifs S S
293eq numeric eq ck_null Iifs S S
294i_eq integer eq ck_null ifs S S
295ne numeric ne ck_null Iifs S S
296i_ne integer ne ck_null ifs S S
a0d0e21e 297ncmp spaceship operator ck_null Iifst S S
85e6fe83 298i_ncmp integer spaceship ck_null ifst S S
79072805 299
bbce6d69 300slt string lt ck_scmp ifs S S
301sgt string gt ck_scmp ifs S S
302sle string le ck_scmp ifs S S
303sge string ge ck_scmp ifs S S
36477c24 304seq string eq ck_null ifs S S
305sne string ne ck_null ifs S S
bbce6d69 306scmp string comparison ck_scmp ifst S S
79072805 307
55497cff 308bit_and bitwise and ck_bitop fst S S
309bit_xor bitwise xor ck_bitop fst S S
310bit_or bitwise or ck_bitop fst S S
79072805 311
85e6fe83 312negate negate ck_null Ifst S
313i_negate integer negate ck_null ifst S
79072805 314not not ck_null ifs S
55497cff 315complement 1's complement ck_bitop fst S
79072805 316
317# High falutin' math.
318
319atan2 atan2 ck_fun fst S S
a0d0e21e 320sin sin ck_fun fstu S?
321cos cos ck_fun fstu S?
79072805 322rand rand ck_fun st S?
323srand srand ck_fun s S?
a0d0e21e 324exp exp ck_fun fstu S?
325log log ck_fun fstu S?
326sqrt sqrt ck_fun fstu S?
79072805 327
a0d0e21e 328int int ck_fun fstu S?
329hex hex ck_fun istu S?
330oct oct ck_fun istu S?
331abs abs ck_fun fstu S?
79072805 332
333# String stuff.
334
a0d0e21e 335length length ck_lengthconst istu S?
79072805 336substr substr ck_fun st S S S?
337vec vec ck_fun ist S S S
338
339index index ck_index ist S S S?
340rindex rindex ck_index ist S S S?
341
bbce6d69 342sprintf sprintf ck_fun_locale mst S L
343formline formline ck_fun ms S L
a0d0e21e 344ord ord ck_fun ifstu S?
345chr chr ck_fun fstu S?
79072805 346crypt crypt ck_fun fst S S
bbce6d69 347ucfirst upper case first ck_fun_locale fstu S?
348lcfirst lower case first ck_fun_locale fstu S?
349uc upper case ck_fun_locale fstu S?
350lc lower case ck_fun_locale fstu S?
55497cff 351quotemeta quote metachars ck_fun fstu S?
79072805 352
353# Arrays.
354
355rv2av array deref ck_rvconst dt
356aelemfast known array element ck_null s A S
8990e307 357aelem array element ck_null s A S
79072805 358aslice array slice ck_null m A L
359
360# Associative arrays.
361
362each each ck_fun t H
363values values ck_fun t H
364keys keys ck_fun t H
5f05dabc 365delete delete ck_delete 0 S
366exists exists operator ck_exists is S
79072805 367rv2hv associative array deref ck_rvconst dt
368helem associative array elem ck_null s H S
369hslice associative array slice ck_null m H L
370
371# Explosives and implosives.
372
373unpack unpack ck_fun 0 S S
374pack pack ck_fun mst S L
375split split ck_split t S S S
376join join ck_fun mst S L
377
378# List operators.
379
380list list ck_null m L
381lslice list slice ck_null 0 H L L
a0d0e21e 382anonlist anonymous list ck_fun ms L
383anonhash anonymous hash ck_fun ms L
79072805 384
a0d0e21e 385splice splice ck_fun m A S? S? L
79072805 386push push ck_fun imst A L
387pop pop ck_shift s A
388shift shift ck_shift s A
389unshift unshift ck_fun imst A L
390sort sort ck_sort m C? L
391reverse reverse ck_fun mt L
392
393grepstart grep ck_grep dm C L
394grepwhile grep iterator ck_null dt
395
a0d0e21e 396mapstart map ck_grep dm C L
397mapwhile map iterator ck_null dt
398
79072805 399# Range stuff.
400
401range flipflop ck_null 0 S S
402flip range (or flip) ck_null 0 S S
403flop range (or flop) ck_null 0
404
405# Control.
406
407and logical and ck_null 0
408or logical or ck_null 0
a0d0e21e 409xor logical xor ck_null fs S S
4633a7c4 410cond_expr conditional expression ck_null d
79072805 411andassign logical and assignment ck_null s
412orassign logical or assignment ck_null s
413
463ee0b2 414method method lookup ck_null d
a0d0e21e 415entersub subroutine entry ck_subr dmt L
416leavesub subroutine exit ck_null 0
79072805 417caller caller ck_fun t S?
418warn warn ck_fun imst L
419die die ck_fun dimst L
420reset reset ck_fun is S?
421
422lineseq line sequence ck_null 0
93a17b20 423nextstate next statement ck_null s
424dbstate debug next statement ck_null s
79072805 425unstack unstack ck_null s
426enter block entry ck_null 0
427leave block exit ck_null 0
463ee0b2 428scope block ck_null 0
79072805 429enteriter foreach loop entry ck_null d
430iter foreach loop iterator ck_null 0
431enterloop loop entry ck_null d
a0d0e21e 432leaveloop loop exit ck_null 0
748a9306 433return return ck_null dm L
79072805 434last last ck_null ds
435next next ck_null ds
436redo redo ck_null ds
437dump dump ck_null ds
438goto goto ck_null ds
439exit exit ck_fun ds S?
440
a0d0e21e 441#nswitch numeric switch ck_null d
442#cswitch character switch ck_null d
79072805 443
444# I/O.
445
446open open ck_fun ist F S?
447close close ck_fun is F?
448pipe_op pipe ck_fun is F F
449
450fileno fileno ck_fun ist F
451umask umask ck_fun ist S?
452binmode binmode ck_fun s F
453
463ee0b2 454tie tie ck_fun idms R S L
455untie untie ck_fun is R
a5f75d66 456tied tied ck_fun s R
463ee0b2 457dbmopen dbmopen ck_fun is H S S
79072805 458dbmclose dbmclose ck_fun is H
459
460sselect select system call ck_select t S S S S
461select select ck_select st F?
462
463getc getc ck_eof st F?
464read read ck_fun imst F R S S?
465enterwrite write ck_fun dis F?
466leavewrite write exit ck_null 0
467
463ee0b2 468prtf printf ck_listiob ims F? L
79072805 469print print ck_listiob ims F? L
470
a5f75d66 471sysopen sysopen ck_fun s F S S S?
79072805 472sysread sysread ck_fun imst F R S S?
473syswrite syswrite ck_fun imst F S S S?
474
475send send ck_fun imst F S S S?
476recv recv ck_fun imst F R S S
477
478eof eof ck_eof is F?
479tell tell ck_fun st F?
480seek seek ck_fun s F S S
9b01e405 481# truncate really behaves as if it had both "S S" and "F S"
482truncate truncate ck_trunc is S S
79072805 483
484fcntl fcntl ck_fun st F S S
485ioctl ioctl ck_fun st F S S
486flock flock ck_fun ist F S
487
488# Sockets.
489
490socket socket ck_fun is F S S S
491sockpair socketpair ck_fun is F F S S S
492
493bind bind ck_fun is F S
494connect connect ck_fun is F S
495listen listen ck_fun is F S
496accept accept ck_fun ist F F
497shutdown shutdown ck_fun ist F S
498
499gsockopt getsockopt ck_fun is F S S
500ssockopt setsockopt ck_fun is F S S S
501
502getsockname getsockname ck_fun is F
503getpeername getpeername ck_fun is F
504
505# Stat calls.
506
a0d0e21e 507lstat lstat ck_ftst u F
508stat stat ck_ftst u F
509ftrread -R ck_ftst isu F
510ftrwrite -W ck_ftst isu F
511ftrexec -X ck_ftst isu F
512fteread -r ck_ftst isu F
513ftewrite -w ck_ftst isu F
514fteexec -x ck_ftst isu F
515ftis -e ck_ftst isu F
516fteowned -O ck_ftst isu F
517ftrowned -o ck_ftst isu F
518ftzero -z ck_ftst isu F
519ftsize -s ck_ftst istu F
520ftmtime -M ck_ftst stu F
521ftatime -A ck_ftst stu F
522ftctime -C ck_ftst stu F
523ftsock -S ck_ftst isu F
524ftchr -c ck_ftst isu F
525ftblk -b ck_ftst isu F
526ftfile -f ck_ftst isu F
527ftdir -d ck_ftst isu F
528ftpipe -p ck_ftst isu F
529ftlink -l ck_ftst isu F
530ftsuid -u ck_ftst isu F
531ftsgid -g ck_ftst isu F
532ftsvtx -k ck_ftst isu F
79072805 533fttty -t ck_ftst is F
a0d0e21e 534fttext -T ck_ftst isu F
535ftbinary -B ck_ftst isu F
79072805 536
537# File calls.
538
539chdir chdir ck_fun ist S?
540chown chown ck_fun imst L
a0d0e21e 541chroot chroot ck_fun istu S?
542unlink unlink ck_fun imstu L
79072805 543chmod chmod ck_fun imst L
544utime utime ck_fun imst L
545rename rename ck_fun ist S S
546link link ck_fun ist S S
547symlink symlink ck_fun ist S S
a0d0e21e 548readlink readlink ck_fun stu S?
79072805 549mkdir mkdir ck_fun ist S S
a0d0e21e 550rmdir rmdir ck_fun istu S?
79072805 551
552# Directory calls.
553
554open_dir opendir ck_fun is F S
555readdir readdir ck_fun 0 F
556telldir telldir ck_fun st F
557seekdir seekdir ck_fun s F S
558rewinddir rewinddir ck_fun s F
559closedir closedir ck_fun is F
560
561# Process control.
562
563fork fork ck_null ist
564wait wait ck_null ist
565waitpid waitpid ck_fun ist S S
566system system ck_exec imst S? L
567exec exec ck_exec dimst S? L
568kill kill ck_fun dimst L
569getppid getppid ck_null ist
570getpgrp getpgrp ck_fun ist S?
a0d0e21e 571setpgrp setpgrp ck_fun ist S? S?
79072805 572getpriority getpriority ck_fun ist S S
573setpriority setpriority ck_fun ist S S S
574
575# Time calls.
576
577time time ck_null ist
578tms times ck_null 0
579localtime localtime ck_fun t S?
580gmtime gmtime ck_fun t S?
a0d0e21e 581alarm alarm ck_fun istu S?
79072805 582sleep sleep ck_fun ist S?
583
584# Shared memory.
585
586shmget shmget ck_fun imst S S S
587shmctl shmctl ck_fun imst S S S
588shmread shmread ck_fun imst S S S S
16d20bd9 589shmwrite shmwrite ck_fun imst S S S S
79072805 590
591# Message passing.
592
593msgget msgget ck_fun imst S S
594msgctl msgctl ck_fun imst S S S
595msgsnd msgsnd ck_fun imst S S S
596msgrcv msgrcv ck_fun imst S S S S S
597
598# Semaphores.
599
600semget semget ck_fun imst S S S
601semctl semctl ck_fun imst S S S S
ecfc5424 602semop semop ck_fun imst S S
79072805 603
604# Eval.
605
a0d0e21e 606require require ck_require du S?
79072805 607dofile do 'file' ck_fun d S
608entereval eval string ck_eval d S
609leaveeval eval exit ck_null 0 S
a0d0e21e 610#evalonce eval constant string ck_null d S
79072805 611entertry eval block ck_null 0
612leavetry eval block exit ck_null 0
613
614# Get system info.
615
616ghbyname gethostbyname ck_fun 0 S
617ghbyaddr gethostbyaddr ck_fun 0 S S
618ghostent gethostent ck_null 0
619gnbyname getnetbyname ck_fun 0 S
620gnbyaddr getnetbyaddr ck_fun 0 S S
621gnetent getnetent ck_null 0
622gpbyname getprotobyname ck_fun 0 S
623gpbynumber getprotobynumber ck_fun 0 S
624gprotoent getprotoent ck_null 0
625gsbyname getservbyname ck_fun 0 S S
626gsbyport getservbyport ck_fun 0 S S
627gservent getservent ck_null 0
93a17b20 628shostent sethostent ck_fun is S
629snetent setnetent ck_fun is S
630sprotoent setprotoent ck_fun is S
631sservent setservent ck_fun is S
632ehostent endhostent ck_null is
633enetent endnetent ck_null is
634eprotoent endprotoent ck_null is
635eservent endservent ck_null is
79072805 636gpwnam getpwnam ck_fun 0 S
637gpwuid getpwuid ck_fun 0 S
638gpwent getpwent ck_null 0
a0d0e21e 639spwent setpwent ck_null is
640epwent endpwent ck_null is
79072805 641ggrnam getgrnam ck_fun 0 S
642ggrgid getgrgid ck_fun 0 S
643ggrent getgrent ck_null 0
a0d0e21e 644sgrent setgrent ck_null is
645egrent endgrent ck_null is
79072805 646getlogin getlogin ck_null st
647
648# Miscellaneous.
649
a0d0e21e 650syscall syscall ck_fun imst S L