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