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