Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Only array slices (not list slices) are handled so far, and they are buggy:
• Negative indices do not work yet.
• @A[1.., 2..] dies at compile time.
  • Loading branch information
Father Chrysostomos committed Aug 19, 2013
1 parent 32c6a98 commit b3fb563
Show file tree
Hide file tree
Showing 14 changed files with 1,173 additions and 1,084 deletions.
1 change: 1 addition & 0 deletions embed.h
Expand Up @@ -1056,6 +1056,7 @@
#define ck_sassign(a) Perl_ck_sassign(aTHX_ a)
#define ck_select(a) Perl_ck_select(aTHX_ a)
#define ck_shift(a) Perl_ck_shift(aTHX_ a)
#define ck_slice(a) Perl_ck_slice(aTHX_ a)
#define ck_smartmatch(a) Perl_ck_smartmatch(aTHX_ a)
#define ck_sort(a) Perl_ck_sort(aTHX_ a)
#define ck_spair(a) Perl_ck_spair(aTHX_ a)
Expand Down
4 changes: 2 additions & 2 deletions ext/Opcode/Opcode.pm
Expand Up @@ -6,7 +6,7 @@ use strict;

our($VERSION, @ISA, @EXPORT_OK);

$VERSION = "1.25";
$VERSION = "1.26";

use Carp;
use Exporter ();
Expand Down Expand Up @@ -350,7 +350,7 @@ These memory related ops are not included in :base_core because they
can easily be used to implement a resource attack (e.g., consume all
available memory).
concat repeat join range
concat repeat join range postdotdot
anonlist anonhash
Expand Down
26 changes: 25 additions & 1 deletion op.c
Expand Up @@ -1752,7 +1752,7 @@ S_finalize_op(pTHX_ OP* o)
/* Relocate sv to the pad for thread safety.
* Despite being a "constant", the SV is written to,
* for reference counts, sv_upgrade() etc. */
if (cSVOPo->op_sv) {
if (cSVOPo->op_sv && cSVOPo->op_sv != &PL_sv_placeholder) {
const PADOFFSET ix = pad_alloc(OP_CONST, SVf_READONLY);
if (o->op_type != OP_METHOD_NAMED
&& cSVOPo->op_sv == &PL_sv_undef) {
Expand Down Expand Up @@ -1881,6 +1881,8 @@ S_finalize_op(pTHX_ OP* o)
break;
}

case OP_POSTDOTDOT: Perl_croak(aTHX_ "Postfix .. outside of slice");

case OP_SUBST: {
if (cPMOPo->op_pmreplrootu.op_pmreplroot)
finalize_op(cPMOPo->op_pmreplrootu.op_pmreplroot);
Expand Down Expand Up @@ -9602,6 +9604,28 @@ Perl_ck_shift(pTHX_ OP *o)
return scalar(ck_fun(o));
}

OP *
Perl_ck_slice(pTHX_ OP *o)
{
dVAR;
OP *kid;

PERL_ARGS_ASSERT_CK_SLICE;

kid = cBINOPo->op_first;
if (kid->op_type != OP_PUSHMARK && kid->op_flags & OPf_KIDS)
kid = kUNOP->op_first;

for (kid = kid->op_sibling; kid; kid = kid->op_sibling) {
if (kid->op_type == OP_POSTDOTDOT) {
kid->op_type = OP_CONST;
kid->op_ppaddr = PL_ppaddr[OP_CONST];
}
}

return o;
}

OP *
Perl_ck_sort(pTHX_ OP *o)
{
Expand Down
10 changes: 8 additions & 2 deletions opcode.h
Expand Up @@ -142,6 +142,7 @@
#define Perl_pp_custom Perl_unimplemented_op
#define Perl_pp_reach Perl_pp_rkeys
#define Perl_pp_rvalues Perl_pp_rkeys
#define Perl_pp_postdotdot Perl_unimplemented_op
START_EXTERN_C

#ifndef DOINIT
Expand Down Expand Up @@ -525,6 +526,7 @@ EXTCONST char* const PL_op_name[] = {
"introcv",
"clonecv",
"padrange",
"postdotdot",
"freed",
};
#endif
Expand Down Expand Up @@ -910,6 +912,7 @@ EXTCONST char* const PL_op_desc[] = {
"private subroutine",
"private subroutine",
"list of private variables",
"postfix .. in slice",
"freed op",
};
#endif
Expand Down Expand Up @@ -1309,6 +1312,7 @@ EXT Perl_ppaddr_t PL_ppaddr[] /* or perlvars.h */
Perl_pp_introcv,
Perl_pp_clonecv,
Perl_pp_padrange,
Perl_pp_postdotdot, /* implemented by Perl_unimplemented_op */
}
#endif
#ifdef PERL_PPADDR_INITED
Expand Down Expand Up @@ -1458,7 +1462,7 @@ EXT Perl_check_t PL_check[] /* or perlvars.h */
Perl_ck_null, /* aelemfast */
Perl_ck_null, /* aelemfast_lex */
Perl_ck_null, /* aelem */
Perl_ck_null, /* aslice */
Perl_ck_slice, /* aslice */
Perl_ck_each, /* aeach */
Perl_ck_each, /* akeys */
Perl_ck_each, /* avalues */
Expand All @@ -1475,7 +1479,7 @@ EXT Perl_check_t PL_check[] /* or perlvars.h */
Perl_ck_split, /* split */
Perl_ck_join, /* join */
Perl_ck_null, /* list */
Perl_ck_null, /* lslice */
Perl_ck_slice, /* lslice */
Perl_ck_fun, /* anonlist */
Perl_ck_fun, /* anonhash */
Perl_ck_fun, /* splice */
Expand Down Expand Up @@ -1704,6 +1708,7 @@ EXT Perl_check_t PL_check[] /* or perlvars.h */
Perl_ck_null, /* introcv */
Perl_ck_null, /* clonecv */
Perl_ck_null, /* padrange */
Perl_ck_null, /* postdotdot */
}
#endif
#ifdef PERL_CHECK_INITED
Expand Down Expand Up @@ -2093,6 +2098,7 @@ EXTCONST U32 PL_opargs[] = {
0x00000040, /* introcv */
0x00000040, /* clonecv */
0x00000040, /* padrange */
0x00000600, /* postdotdot */
};
#endif

Expand Down
3 changes: 2 additions & 1 deletion opnames.h
Expand Up @@ -391,10 +391,11 @@ typedef enum opcode {
OP_INTROCV = 374,
OP_CLONECV = 375,
OP_PADRANGE = 376,
OP_POSTDOTDOT = 377,
OP_max
} opcode;

#define MAXO 377
#define MAXO 378
#define OP_FREED MAXO

/* the OP_IS_* macros are optimized to a simple range check because
Expand Down

0 comments on commit b3fb563

Please sign in to comment.