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