Simplify the CORE::__FOO__ op-generation code
authorFather Chrysostomos <sprout@cpan.org>
Fri, 19 Aug 2011 05:19:25 +0000 (22:19 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 25 Aug 2011 06:38:27 +0000 (23:38 -0700)
It just happens that the (caller)[...] offsets for file and line are
the same as the keyword numbers.  KEY___PACKAGE__ is 3 and (caller)[0]
returns the package, so keyword_number % 3 can be used for the offset
instead of an unwieldy switch block.

keywords.c
keywords.h
op.c
regen/keywords.pl

index d442b32..b9ef465 100644 (file)
@@ -3399,5 +3399,5 @@ unknown:
 }
 
 /* Generated from:
- * 34be1269b3c67c86c758c60794ddba6eadc528e0435f954d514c14a2f1c73a2e regen/keywords.pl
+ * 6563b55da87af894b79ef9d777217633eee6c7b5f352ff4c17317f562247f5fc regen/keywords.pl
  * ex: set ro: */
index 4631b67..83ad0ef 100644 (file)
 #define KEY_y                  252
 
 /* Generated from:
- * 34be1269b3c67c86c758c60794ddba6eadc528e0435f954d514c14a2f1c73a2e regen/keywords.pl
+ * 6563b55da87af894b79ef9d777217633eee6c7b5f352ff4c17317f562247f5fc regen/keywords.pl
  * ex: set ro: */
diff --git a/op.c b/op.c
index 74d27dd..1ca495c 100644 (file)
--- a/op.c
+++ b/op.c
@@ -10336,20 +10336,13 @@ Perl_coresub_op(pTHX_ SV * const coreargssv, const int code,
 
     switch(opnum) {
     case 0:
-       {
-           IV index = 0;
-           switch(-code) {
-           case KEY___FILE__   : index = 1; break;
-           case KEY___LINE__   : index = 2; break;
-           }
-           return op_append_elem(OP_LINESEQ,
+       return op_append_elem(OP_LINESEQ,
                       argop,
                       newSLICEOP(0,
-                                 newSVOP(OP_CONST, 0, newSViv(index)),
+                                 newSVOP(OP_CONST, 0, newSViv(-code % 3)),
                                  newOP(OP_CALLER,0)
                       )
-                  );
-       }
+              );
     default:
        switch (PL_opargs[opnum] & OA_CLASS_MASK) {
        case OA_BASEOP:
index b286050..5f7f1ef 100755 (executable)
@@ -101,6 +101,10 @@ END
 
 read_only_bottom_close_and_rename($_, [$0]) foreach $c, $h;
 
+
+# coresub_op in op.c expects __FILE__, __LINE__ and __PACKAGE__ to be the
+# first three.
+
 __END__
 
  NULL