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