Start support for fake threads.
[p5sagit/p5-mst-13.2.git] / opcode.pl
index 351f6af..5250d57 100755 (executable)
--- a/opcode.pl
+++ b/opcode.pl
@@ -1,5 +1,6 @@
 #!/usr/bin/perl
 
+unlink "opcode.h";
 open(OC, ">opcode.h") || die "Can't create opcode.h: $!\n";
 select OC;
 
@@ -9,9 +10,15 @@ while (<DATA>) {
     chop;
     next unless $_;
     next if /^#/;
-    ($key, $name, $check, $flags, $args) = split(/\t+/, $_, 5);
+    ($key, $desc, $check, $flags, $args) = split(/\t+/, $_, 5);
+
+    warn qq[Description "$desc" duplicates $seen{$desc}\n] if $seen{$desc};
+    die qq[Opcode "$key" duplicates $seen{$key}\n] if $seen{$key};
+    $seen{$desc} = qq[description of opcode "$key"];
+    $seen{$key} = qq[opcode "$key"];
+
     push(@ops, $key);
-    $name{$key} = $name;
+    $desc{$key} = $desc;
     $check{$key} = $check;
     $ckname{$check}++;
     $flags{$key} = $flags;
@@ -21,7 +28,14 @@ while (<DATA>) {
 # Emit defines.
 
 $i = 0;
-print "typedef enum {\n";
+print <<"END";
+#define pp_i_preinc pp_preinc
+#define pp_i_predec pp_predec
+#define pp_i_postinc pp_postinc
+#define pp_i_postdec pp_postdec
+
+typedef enum {
+END
 for (@ops) {
     print "\t", &tab(3,"OP_\U$_,"), "/* ", $i++, " */\n";
 }
@@ -29,7 +43,7 @@ print "\t", &tab(3,"OP_max"), "\n";
 print "} opcode;\n";
 print "\n#define MAXO ", scalar @ops, "\n\n"; 
 
-# Emit opnames.
+# Emit op names and descriptions.
 
 print <<END;
 #ifndef DOINIT
@@ -39,7 +53,24 @@ EXT char *op_name[] = {
 END
 
 for (@ops) {
-    print qq(\t"$name{$_}",\n);
+    print qq(\t"$_",\n);
+}
+
+print <<END;
+};
+#endif
+
+END
+
+print <<END;
+#ifndef DOINIT
+EXT char *op_desc[];
+#else
+EXT char *op_desc[] = {
+END
+
+for (@ops) {
+    print qq(\t"$desc{$_}",\n);
 }
 
 print <<END;
@@ -51,13 +82,13 @@ END
 # Emit function declarations.
 
 for (sort keys %ckname) {
-    print "OP *\t", &tab(3,$_),"_((OP* op));\n";
+    print "OP *\t", &tab(3,$_),"_((OP* o));\n";
 }
 
 print "\n";
 
 for (@ops) {
-    print "OP *\t", &tab(3, "pp_\L$_"), "_((void));\n";
+    print "OP *\t", &tab(3, "pp_\L$_"), "_((ARGSproto));\n";
 }
 
 # Emit ppcode switch array.
@@ -84,9 +115,9 @@ END
 
 print <<END;
 #ifndef DOINIT
-EXT OP * (*check[])();
+EXT OP * (*check[]) _((OP *op));
 #else
-EXT OP * (*check[])() = {
+EXT OP * (*check[]) _((OP *op)) = {
 END
 
 for (@ops) {
@@ -169,21 +200,22 @@ const             constant item           ck_svconst      s
 
 gvsv           scalar variable         ck_null         ds      
 gv             glob value              ck_null         ds      
-padsv          private variable        ck_null         s
-padav          private array           ck_null         0
-padhv          private hash            ck_null         0
-padany         private something       ck_null         0
+gelem          glob elem               ck_null         d       S S
+padsv          private variable        ck_null         ds
+padav          private array           ck_null         d
+padhv          private hash            ck_null         d
+padany         private something       ck_null         d
 
 pushre         push regexp             ck_null         0
 
 # References and stuff.
 
 rv2gv          ref-to-glob cast        ck_rvconst      ds      
-sv2len         scalar value length     ck_null         ist     
 rv2sv          scalar deref            ck_rvconst      ds      
 av2arylen      array length            ck_null         is      
 rv2cv          subroutine deref        ck_rvconst      d
-anoncode       anonymous subroutine    ck_null         0       
+anoncode       anonymous subroutine    ck_anoncode     0       
+prototype      subroutine prototype    ck_null         s       S
 refgen         reference constructor   ck_spair        m       L
 srefgen                scalar ref constructor  ck_null         fs      S
 ref            reference-type operator ck_fun          stu     S?
@@ -192,7 +224,8 @@ bless               bless                   ck_fun          s       S S?
 # Pushy I/O.
 
 backtick       backticks               ck_null         t       
-glob           glob                    ck_glob         t       S S
+# glob defaults its first arg to $_
+glob           glob                    ck_glob         t       S? S?
 readline       <HANDLE>                ck_null         t       
 rcatline       append I/O operator     ck_null         t       
 
@@ -216,7 +249,7 @@ chomp               safe chop               ck_spair        mts     L
 schomp         scalar safe chop        ck_null         stu     S?
 defined                defined operator        ck_rfun         isu     S?
 undef          undef operator          ck_lfun         s       S?
-study          study                   ck_fun          stu     S?
+study          study                   ck_fun          su      S?
 pos            match position          ck_lfun         stu     S?
 
 preinc         preincrement            ck_lfun         dIs     S
@@ -247,8 +280,8 @@ i_subtract  integer subtraction     ck_null         ifst    S S
 concat         concatenation           ck_concat       fst     S S
 stringify      string                  ck_fun          fst     S
 
-left_shift     left bitshift           ck_null         ifst    S S
-right_shift    right bitshift          ck_null         ifst    S S
+left_shift     left bitshift           ck_bitop        fst     S S
+right_shift    right bitshift          ck_bitop        fst     S S
 
 lt             numeric lt              ck_null         Iifs    S S
 i_lt           integer lt              ck_null         ifs     S S
@@ -265,22 +298,22 @@ i_ne              integer ne              ck_null         ifs     S S
 ncmp           spaceship operator      ck_null         Iifst   S S
 i_ncmp         integer spaceship       ck_null         ifst    S S
 
-slt            string lt               ck_null         ifs     S S
-sgt            string gt               ck_null         ifs     S S
-sle            string le               ck_null         ifs     S S
-sge            string ge               ck_null         ifs     S S
+slt            string lt               ck_scmp         ifs     S S
+sgt            string gt               ck_scmp         ifs     S S
+sle            string le               ck_scmp         ifs     S S
+sge            string ge               ck_scmp         ifs     S S
 seq            string eq               ck_null         ifs     S S
 sne            string ne               ck_null         ifs     S S
-scmp           string comparison       ck_null         ifst    S S
+scmp           string comparison       ck_scmp         ifst    S S
 
-bit_and                bitwise and             ck_null         fst     S S
-bit_xor                bitwise xor             ck_null         fst     S S
-bit_or         bitwise or              ck_null         fst     S S
+bit_and                bitwise and             ck_bitop        fst     S S
+bit_xor                bitwise xor             ck_bitop        fst     S S
+bit_or         bitwise or              ck_bitop        fst     S S
 
 negate         negate                  ck_null         Ifst    S
 i_negate       integer negate          ck_null         ifst    S
 not            not                     ck_null         ifs     S
-complement     1's complement          ck_null         fst     S
+complement     1's complement          ck_bitop        fst     S
 
 # High falutin' math.
 
@@ -293,9 +326,11 @@ exp                exp                     ck_fun          fstu    S?
 log            log                     ck_fun          fstu    S?
 sqrt           sqrt                    ck_fun          fstu    S?
 
+# Lowbrow math.
+
 int            int                     ck_fun          fstu    S?
-hex            hex                     ck_fun          istu    S?
-oct            oct                     ck_fun          istu    S?
+hex            hex                     ck_fun          fstu    S?
+oct            oct                     ck_fun          fstu    S?
 abs            abs                     ck_fun          fstu    S?
 
 # String stuff.
@@ -307,16 +342,16 @@ vec               vec                     ck_fun          ist     S S S
 index          index                   ck_index        ist     S S S?
 rindex         rindex                  ck_index        ist     S S S?
 
-sprintf                sprintf                 ck_fun          mst     S L
-formline       formline                ck_formline     ms      S L
+sprintf                sprintf                 ck_fun_locale   mst     S L
+formline       formline                ck_fun          ms      S L
 ord            ord                     ck_fun          ifstu   S?
 chr            chr                     ck_fun          fstu    S?
 crypt          crypt                   ck_fun          fst     S S
-ucfirst                upper case first        ck_fun          fst     S
-lcfirst                lower case first        ck_fun          fst     S
-uc             upper case              ck_fun          fst     S
-lc             lower case              ck_fun          fst     S
-quotemeta      quote metachars         ck_fun          fst     S
+ucfirst                upper case first        ck_fun_locale   fstu    S?
+lcfirst                lower case first        ck_fun_locale   fstu    S?
+uc             upper case              ck_fun_locale   fstu    S?
+lc             lower case              ck_fun_locale   fstu    S?
+quotemeta      quote metachars         ck_fun          fstu    S?
 
 # Arrays.
 
@@ -325,16 +360,16 @@ aelemfast known array element     ck_null         s       A S
 aelem          array element           ck_null         s       A S
 aslice         array slice             ck_null         m       A L
 
-# Associative arrays.
+# Hashes.
 
 each           each                    ck_fun          t       H
 values         values                  ck_fun          t       H
 keys           keys                    ck_fun          t       H
-delete         delete                  ck_delete       s       S
-exists         exists operator         ck_delete       is      S
-rv2hv          associative array deref ck_rvconst      dt      
-helem          associative array elem  ck_null         s       H S
-hslice         associative array slice ck_null         m       H L
+delete         delete                  ck_delete       0       S
+exists         exists operator         ck_exists       is      S
+rv2hv          hash deref              ck_rvconst      dt      
+helem          hash elem               ck_null         s       H S
+hslice         hash slice              ck_null         m       H L
 
 # Explosives and implosives.
 
@@ -375,7 +410,7 @@ flop                range (or flop)         ck_null         0
 and            logical and             ck_null         0       
 or             logical or              ck_null         0       
 xor            logical xor             ck_null         fs      S S     
-cond_expr      conditional expression  ck_null         0       
+cond_expr      conditional expression  ck_null         d       
 andassign      logical and assignment  ck_null         s       
 orassign       logical or assignment   ck_null         s       
 
@@ -398,7 +433,7 @@ enteriter   foreach loop entry      ck_null         d
 iter           foreach loop iterator   ck_null         0       
 enterloop      loop entry              ck_null         d       
 leaveloop      loop exit               ck_null         0       
-return         return                  ck_fun          dm      L
+return         return                  ck_null         dm      L
 last           last                    ck_null         ds      
 next           next                    ck_null         ds      
 redo           redo                    ck_null         ds      
@@ -421,6 +456,7 @@ binmode             binmode                 ck_fun          s       F
 
 tie            tie                     ck_fun          idms    R S L
 untie          untie                   ck_fun          is      R
+tied           tied                    ck_fun          s       R
 dbmopen                dbmopen                 ck_fun          is      H S S
 dbmclose       dbmclose                ck_fun          is      H
 
@@ -435,6 +471,8 @@ leavewrite  write exit              ck_null         0
 prtf           printf                  ck_listiob      ims     F? L
 print          print                   ck_listiob      ims     F? L
 
+sysopen                sysopen                 ck_fun          s       F S S S?
+sysseek                sysseek                 ck_fun          s       F S S
 sysread                sysread                 ck_fun          imst    F R S S?
 syswrite       syswrite                ck_fun          imst    F S S S?
 
@@ -444,6 +482,7 @@ recv                recv                    ck_fun          imst    F R S S
 eof            eof                     ck_eof          is      F?
 tell           tell                    ck_fun          st      F?
 seek           seek                    ck_fun          s       F S S
+# truncate really behaves as if it had both "S S" and "F S"
 truncate       truncate                ck_trunc        is      S S
 
 fcntl          fcntl                   ck_fun          st      F S S
@@ -551,7 +590,7 @@ sleep               sleep                   ck_fun          ist     S?
 shmget         shmget                  ck_fun          imst    S S S
 shmctl         shmctl                  ck_fun          imst    S S S
 shmread                shmread                 ck_fun          imst    S S S S
-shmwrite       shmwrite                ck_fun          ist     S S S S
+shmwrite       shmwrite                ck_fun          imst    S S S S
 
 # Message passing.
 
@@ -564,7 +603,7 @@ msgrcv              msgrcv                  ck_fun          imst    S S S S S
 
 semget         semget                  ck_fun          imst    S S S
 semctl         semctl                  ck_fun          imst    S S S S
-semop          semop                   ck_fun          imst    S S S
+semop          semop                   ck_fun          imst    S S
 
 # Eval.
 
@@ -613,3 +652,6 @@ getlogin    getlogin                ck_null         st
 # Miscellaneous.
 
 syscall                syscall                 ck_fun          imst    S L
+
+# For multi-threading
+lock           lock                    ck_null         s       S