perl 5.0 alpha 5
[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
ed6116ce 174padany private something ck_null 0
79072805 175
176pushre push regexp ck_null 0
177
178# References and stuff.
179
180rv2gv ref-to-glob cast ck_rvconst ds
181sv2len scalar value length ck_null ist
182rv2sv ref-to-scalar cast ck_rvconst ds
183av2arylen array length ck_null is
184rv2cv subroutine reference ck_rvconst d
185refgen backslash reference ck_null fst L
463ee0b2 186ref reference-type operator ck_fun st S?
187bless bless ck_fun s S S?
79072805 188
189# Pushy I/O.
190
191backtick backticks ck_null t
192glob glob ck_glob t
193readline <HANDLE> ck_null t
194rcatline append I/O operator ck_null t
195
196# Bindable operators.
197
463ee0b2 198regcmaybe regexp comp once ck_fun s S
79072805 199regcomp regexp compilation ck_null s S
200match pattern match ck_match d
201subst substitution ck_null dis S
202substcont substitution cont ck_null dis
203trans character translation ck_null is S
204
205# Lvalue operators.
206
207sassign scalar assignment ck_null s
208aassign list assignment ck_null t L L
209
210schop scalar chop ck_null t
211chop chop ck_chop mt L
212defined defined operator ck_lfun is S?
213undef undef operator ck_lfun s S?
214study study ck_fun st S?
215
216preinc preincrement ck_lfun s S
217predec predecrement ck_lfun s S
218postinc postincrement ck_lfun st S
219postdec postdecrement ck_lfun st S
220
221# Ordinary operators.
222
223pow exponentiation ck_null fst S S
224
225multiply multiplication ck_null fst S S
226divide division ck_null fst S S
227modulo modulus ck_null ifst S S
228repeat repeat ck_repeat mt L S
229
230add addition ck_null Ifst S S
231intadd integer addition ck_null ifst S S
232subtract subtraction ck_null fst S S
233concat concatenation ck_concat fst S S
234
235left_shift left bitshift ck_null ifst S S
236right_shift right bitshift ck_null ifst S S
237
238lt numeric lt ck_null ifs S S
239gt numeric gt ck_null ifs S S
240le numeric le ck_null ifs S S
241ge numeric ge ck_null ifs S S
242eq numeric eq ck_null ifs S S
243ne numeric ne ck_null ifs S S
244ncmp spaceship ck_null ifst S S
245
246slt string lt ck_null ifs S S
247sgt string gt ck_null ifs S S
248sle string le ck_null ifs S S
249sge string ge ck_null ifs S S
250seq string eq ck_null ifs S S
251sne string ne ck_null ifs S S
252scmp string comparison ck_null ifst S S
253
254bit_and bit and ck_null fst S S
255xor xor ck_null fst S S
256bit_or bit or ck_null fst S S
257
258negate negate ck_null fst S
259not not ck_null ifs S
260complement 1's complement ck_null fst S
261
262# High falutin' math.
263
264atan2 atan2 ck_fun fst S S
265sin sin ck_fun fst S?
266cos cos ck_fun fst S?
267rand rand ck_fun st S?
268srand srand ck_fun s S?
269exp exp ck_fun fst S?
270log log ck_fun fst S?
271sqrt sqrt ck_fun fst S?
272
273int int ck_fun fst S?
274hex hex ck_fun ist S?
275oct oct ck_fun ist S?
463ee0b2 276abs abs ck_fun fst S?
79072805 277
278# String stuff.
279
280length length ck_lengthconst ist S
281substr substr ck_fun st S S S?
282vec vec ck_fun ist S S S
283
284index index ck_index ist S S S?
285rindex rindex ck_index ist S S S?
286
287sprintf sprintf ck_fun mst S L
288formline formline ck_formline ms S L
289ord ord ck_fun ifst S?
463ee0b2 290chr chr ck_fun fst S?
79072805 291crypt crypt ck_fun fst S S
292ucfirst upper case first ck_fun ft S
293lcfirst lower case first ck_fun ft S
294uc upper case ck_fun ft S
295lc lower case ck_fun ft S
296
297# Arrays.
298
299rv2av array deref ck_rvconst dt
300aelemfast known array element ck_null s A S
301aelem array element ck_aelem s A S
302aslice array slice ck_null m A L
303
304# Associative arrays.
305
306each each ck_fun t H
307values values ck_fun t H
308keys keys ck_fun t H
309delete delete ck_null s H S
310rv2hv associative array deref ck_rvconst dt
311helem associative array elem ck_null s H S
312hslice associative array slice ck_null m H L
313
314# Explosives and implosives.
315
316unpack unpack ck_fun 0 S S
317pack pack ck_fun mst S L
318split split ck_split t S S S
319join join ck_fun mst S L
320
321# List operators.
322
323list list ck_null m L
324lslice list slice ck_null 0 H L L
325anonlist anonymous list ck_null m L
326anonhash anonymous hash ck_null m L
327
328splice splice ck_fun m A S S? L
329push push ck_fun imst A L
330pop pop ck_shift s A
331shift shift ck_shift s A
332unshift unshift ck_fun imst A L
333sort sort ck_sort m C? L
334reverse reverse ck_fun mt L
335
336grepstart grep ck_grep dm C L
337grepwhile grep iterator ck_null dt
338
339# Range stuff.
340
341range flipflop ck_null 0 S S
342flip range (or flip) ck_null 0 S S
343flop range (or flop) ck_null 0
344
345# Control.
346
347and logical and ck_null 0
348or logical or ck_null 0
349cond_expr conditional expression ck_null 0
350andassign logical and assignment ck_null s
351orassign logical or assignment ck_null s
352
463ee0b2 353method method lookup ck_null d
79072805 354entersubr subroutine entry ck_subr dm L
355leavesubr subroutine exit ck_null 0
356caller caller ck_fun t S?
357warn warn ck_fun imst L
358die die ck_fun dimst L
359reset reset ck_fun is S?
360
361lineseq line sequence ck_null 0
93a17b20 362nextstate next statement ck_null s
363dbstate debug next statement ck_null s
79072805 364unstack unstack ck_null s
365enter block entry ck_null 0
366leave block exit ck_null 0
463ee0b2 367scope block ck_null 0
79072805 368enteriter foreach loop entry ck_null d
369iter foreach loop iterator ck_null 0
370enterloop loop entry ck_null d
371leaveloop loop exit ck_null s
372return return ck_fun dm L
373last last ck_null ds
374next next ck_null ds
375redo redo ck_null ds
376dump dump ck_null ds
377goto goto ck_null ds
378exit exit ck_fun ds S?
379
380nswitch numeric switch ck_null d
381cswitch character switch ck_null d
382
383# I/O.
384
385open open ck_fun ist F S?
386close close ck_fun is F?
387pipe_op pipe ck_fun is F F
388
389fileno fileno ck_fun ist F
390umask umask ck_fun ist S?
391binmode binmode ck_fun s F
392
463ee0b2 393tie tie ck_fun idms R S L
394untie untie ck_fun is R
395dbmopen dbmopen ck_fun is H S S
79072805 396dbmclose dbmclose ck_fun is H
397
398sselect select system call ck_select t S S S S
399select select ck_select st F?
400
401getc getc ck_eof st F?
402read read ck_fun imst F R S S?
403enterwrite write ck_fun dis F?
404leavewrite write exit ck_null 0
405
463ee0b2 406prtf printf ck_listiob ims F? L
79072805 407print print ck_listiob ims F? L
408
409sysread sysread ck_fun imst F R S S?
410syswrite syswrite ck_fun imst F S S S?
411
412send send ck_fun imst F S S S?
413recv recv ck_fun imst F R S S
414
415eof eof ck_eof is F?
416tell tell ck_fun st F?
417seek seek ck_fun s F S S
418truncate truncate ck_trunc is S S
419
420fcntl fcntl ck_fun st F S S
421ioctl ioctl ck_fun st F S S
422flock flock ck_fun ist F S
423
424# Sockets.
425
426socket socket ck_fun is F S S S
427sockpair socketpair ck_fun is F F S S S
428
429bind bind ck_fun is F S
430connect connect ck_fun is F S
431listen listen ck_fun is F S
432accept accept ck_fun ist F F
433shutdown shutdown ck_fun ist F S
434
435gsockopt getsockopt ck_fun is F S S
436ssockopt setsockopt ck_fun is F S S S
437
438getsockname getsockname ck_fun is F
439getpeername getpeername ck_fun is F
440
441# Stat calls.
442
443lstat lstat ck_ftst 0 F
444stat stat ck_ftst 0 F
445ftrread -R ck_ftst is F
446ftrwrite -W ck_ftst is F
447ftrexec -X ck_ftst is F
448fteread -r ck_ftst is F
449ftewrite -w ck_ftst is F
450fteexec -x ck_ftst is F
451ftis -e ck_ftst is F
452fteowned -O ck_ftst is F
453ftrowned -o ck_ftst is F
454ftzero -z ck_ftst is F
455ftsize -s ck_ftst ist F
456ftmtime -M ck_ftst st F
457ftatime -A ck_ftst st F
458ftctime -C ck_ftst st F
459ftsock -S ck_ftst is F
460ftchr -c ck_ftst is F
461ftblk -b ck_ftst is F
462ftfile -f ck_ftst is F
463ftdir -d ck_ftst is F
464ftpipe -p ck_ftst is F
465ftlink -l ck_ftst is F
466ftsuid -u ck_ftst is F
467ftsgid -g ck_ftst is F
468ftsvtx -k ck_ftst is F
469fttty -t ck_ftst is F
470fttext -T ck_ftst is F
471ftbinary -B ck_ftst is F
472
473# File calls.
474
475chdir chdir ck_fun ist S?
476chown chown ck_fun imst L
477chroot chroot ck_fun ist S?
478unlink unlink ck_fun imst L
479chmod chmod ck_fun imst L
480utime utime ck_fun imst L
481rename rename ck_fun ist S S
482link link ck_fun ist S S
483symlink symlink ck_fun ist S S
484readlink readlink ck_fun st S?
485mkdir mkdir ck_fun ist S S
486rmdir rmdir ck_fun ist S?
487
488# Directory calls.
489
490open_dir opendir ck_fun is F S
491readdir readdir ck_fun 0 F
492telldir telldir ck_fun st F
493seekdir seekdir ck_fun s F S
494rewinddir rewinddir ck_fun s F
495closedir closedir ck_fun is F
496
497# Process control.
498
499fork fork ck_null ist
500wait wait ck_null ist
501waitpid waitpid ck_fun ist S S
502system system ck_exec imst S? L
503exec exec ck_exec dimst S? L
504kill kill ck_fun dimst L
505getppid getppid ck_null ist
506getpgrp getpgrp ck_fun ist S?
507setpgrp setpgrp ck_fun ist S S
508getpriority getpriority ck_fun ist S S
509setpriority setpriority ck_fun ist S S S
510
511# Time calls.
512
513time time ck_null ist
514tms times ck_null 0
515localtime localtime ck_fun t S?
516gmtime gmtime ck_fun t S?
517alarm alarm ck_fun ist S?
518sleep sleep ck_fun ist S?
519
520# Shared memory.
521
522shmget shmget ck_fun imst S S S
523shmctl shmctl ck_fun imst S S S
524shmread shmread ck_fun imst S S S S
525shmwrite shmwrite ck_fun ist S S S S
526
527# Message passing.
528
529msgget msgget ck_fun imst S S
530msgctl msgctl ck_fun imst S S S
531msgsnd msgsnd ck_fun imst S S S
532msgrcv msgrcv ck_fun imst S S S S S
533
534# Semaphores.
535
536semget semget ck_fun imst S S S
537semctl semctl ck_fun imst S S S S
538semop semop ck_fun imst S S S
539
540# Eval.
541
ed6116ce 542require require ck_fun d S?
79072805 543dofile do 'file' ck_fun d S
544entereval eval string ck_eval d S
545leaveeval eval exit ck_null 0 S
546evalonce eval constant string ck_null d S
547entertry eval block ck_null 0
548leavetry eval block exit ck_null 0
549
550# Get system info.
551
552ghbyname gethostbyname ck_fun 0 S
553ghbyaddr gethostbyaddr ck_fun 0 S S
554ghostent gethostent ck_null 0
555gnbyname getnetbyname ck_fun 0 S
556gnbyaddr getnetbyaddr ck_fun 0 S S
557gnetent getnetent ck_null 0
558gpbyname getprotobyname ck_fun 0 S
559gpbynumber getprotobynumber ck_fun 0 S
560gprotoent getprotoent ck_null 0
561gsbyname getservbyname ck_fun 0 S S
562gsbyport getservbyport ck_fun 0 S S
563gservent getservent ck_null 0
93a17b20 564shostent sethostent ck_fun is S
565snetent setnetent ck_fun is S
566sprotoent setprotoent ck_fun is S
567sservent setservent ck_fun is S
568ehostent endhostent ck_null is
569enetent endnetent ck_null is
570eprotoent endprotoent ck_null is
571eservent endservent ck_null is
79072805 572gpwnam getpwnam ck_fun 0 S
573gpwuid getpwuid ck_fun 0 S
574gpwent getpwent ck_null 0
575spwent setpwent ck_null ist
576epwent endpwent ck_null ist
577ggrnam getgrnam ck_fun 0 S
578ggrgid getgrgid ck_fun 0 S
579ggrent getgrent ck_null 0
580sgrent setgrent ck_null ist
581egrent endgrent ck_null ist
582getlogin getlogin ck_null st
583
584# Miscellaneous.
585
586syscall syscall ck_fun ist S L