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