Permalink
Browse files

Simplify the CORE::__FOO__ op-generation code

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.
  • Loading branch information...
1 parent 1e4b6aa commit c2f605db621edfb16309200bbba8ced984d34476 Father Chrysostomos committed Aug 19, 2011
Showing with 9 additions and 12 deletions.
  1. +1 −1 keywords.c
  2. +1 −1 keywords.h
  3. +3 −10 op.c
  4. +4 −0 regen/keywords.pl
View
@@ -3399,5 +3399,5 @@ Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
}
/* Generated from:
- * 34be1269b3c67c86c758c60794ddba6eadc528e0435f954d514c14a2f1c73a2e regen/keywords.pl
+ * 6563b55da87af894b79ef9d777217633eee6c7b5f352ff4c17317f562247f5fc regen/keywords.pl
* ex: set ro: */
View
@@ -268,5 +268,5 @@
#define KEY_y 252
/* Generated from:
- * 34be1269b3c67c86c758c60794ddba6eadc528e0435f954d514c14a2f1c73a2e regen/keywords.pl
+ * 6563b55da87af894b79ef9d777217633eee6c7b5f352ff4c17317f562247f5fc regen/keywords.pl
* ex: set ro: */
View
13 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:
View
@@ -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

0 comments on commit c2f605d

Please sign in to comment.