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 d442b325e8d40eb33bb1d9ae3882828c50e30273..b9ef465967389c77ccb746c18a76c3de66e1efcc 100644 (file)
@@ -3399,5 +3399,5 @@ unknown:
 }
 
 /* Generated from:
- * 34be1269b3c67c86c758c60794ddba6eadc528e0435f954d514c14a2f1c73a2e regen/keywords.pl
+ * 6563b55da87af894b79ef9d777217633eee6c7b5f352ff4c17317f562247f5fc regen/keywords.pl
  * ex: set ro: */
index 4631b671e0b508eb46badc88971bf606e2cbd839..83ad0efb562b04070a1c305f1c329e3505a26c99 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 74d27dd4f4a19d88bcaebad46b01119f717baea6..1ca495c749c6ed0ef4d852495b802ab2693c0a03 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 b2860504d5362008281a7ff229332325159bf5b9..5f7f1ef851e2938c0acd94b7359d78d0250b1b6c 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