Skip to content

Commit

Permalink
index/value array slice operation
Browse files Browse the repository at this point in the history
kvaslice operator that imlements %a[0,2,4] syntax which
result in list of index/value pairs. Implemented in
consistency with "key/value hash slice" operator.
  • Loading branch information
ruz authored and Father Chrysostomos committed Sep 13, 2013
1 parent ace8699 commit 6dd3e0f
Show file tree
Hide file tree
Showing 12 changed files with 1,151 additions and 1,054 deletions.
1 change: 1 addition & 0 deletions dist/B-Deparse/Deparse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3573,6 +3573,7 @@ sub slice {
}

sub pp_aslice { maybe_local(@_, slice(@_, "[", "]", "rv2av", "padav")) }
sub pp_kvaslice { slice(@_, "[", "]", "rv2av", "padav") }
sub pp_hslice { maybe_local(@_, slice(@_, "{", "}", "rv2hv", "padhv")) }
sub pp_kvhslice { slice(@_, "{", "}", "rv2hv", "padhv") }

Expand Down
11 changes: 10 additions & 1 deletion op.c
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,7 @@ Perl_scalarvoid(pTHX_ OP *o)
case OP_AELEMFAST:
case OP_AELEMFAST_LEX:
case OP_ASLICE:
case OP_KVASLICE:
case OP_HELEM:
case OP_HSLICE:
case OP_KVHSLICE:
Expand Down Expand Up @@ -2063,6 +2064,7 @@ Perl_op_lvalue_flags(pTHX_ OP *o, I32 type, U32 flags)
PL_modcount = RETURN_UNLIMITED_NUMBER;
break;
case OP_KVHSLICE:
case OP_KVASLICE:
if (type == OP_LEAVESUBLV)
o->op_private |= OPpMAYBE_LVSUB;
goto nomod;
Expand Down Expand Up @@ -5354,7 +5356,8 @@ S_is_list_assignment(pTHX_ const OP *o)

if (type == OP_LIST || flags & OPf_PARENS ||
type == OP_RV2AV || type == OP_RV2HV ||
type == OP_ASLICE || type == OP_HSLICE || type == OP_KVHSLICE)
type == OP_ASLICE || type == OP_HSLICE ||
type == OP_KVASLICE || type == OP_KVHSLICE)
return TRUE;

if (type == OP_PADAV || type == OP_PADHV)
Expand Down Expand Up @@ -6562,6 +6565,7 @@ S_ref_array_or_hash(pTHX_ OP *cond)

else if(cond
&& (cond->op_type == OP_ASLICE
|| cond->op_type == OP_KVASLICE
|| cond->op_type == OP_HSLICE
|| cond->op_type == OP_KVHSLICE)) {

Expand Down Expand Up @@ -8044,11 +8048,13 @@ Perl_oopsAV(pTHX_ OP *o)

switch (o->op_type) {
case OP_PADSV:
case OP_PADHV:
o->op_type = OP_PADAV;
o->op_ppaddr = PL_ppaddr[OP_PADAV];
return ref(o, OP_RV2AV);

case OP_RV2SV:
case OP_RV2HV:
o->op_type = OP_RV2AV;
o->op_ppaddr = PL_ppaddr[OP_RV2AV];
ref(o, OP_RV2AV);
Expand Down Expand Up @@ -8302,6 +8308,9 @@ Perl_ck_delete(pTHX_ OP *o)
/* FALL THROUGH */
case OP_HELEM:
break;
case OP_KVASLICE:
Perl_croak(aTHX_ "%s argument is index/value array slice, use array slice",
OP_DESC(o));
case OP_KVHSLICE:
Perl_croak(aTHX_ "%s argument is key/value hash slice, use hash slice",
OP_DESC(o));
Expand Down
5 changes: 5 additions & 0 deletions opcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ EXTCONST char* const PL_op_name[] = {
"aelemfast_lex",
"aelem",
"aslice",
"kvaslice",
"aeach",
"akeys",
"avalues",
Expand Down Expand Up @@ -666,6 +667,7 @@ EXTCONST char* const PL_op_desc[] = {
"constant lexical array element",
"array element",
"array slice",
"index/value array slice",
"each on array",
"keys on array",
"values on array",
Expand Down Expand Up @@ -1066,6 +1068,7 @@ EXT Perl_ppaddr_t PL_ppaddr[] /* or perlvars.h */
Perl_pp_aelemfast_lex, /* implemented by Perl_pp_aelemfast */
Perl_pp_aelem,
Perl_pp_aslice,
Perl_pp_kvaslice,
Perl_pp_aeach,
Perl_pp_akeys,
Perl_pp_avalues, /* implemented by Perl_pp_akeys */
Expand Down Expand Up @@ -1462,6 +1465,7 @@ EXT Perl_check_t PL_check[] /* or perlvars.h */
Perl_ck_null, /* aelemfast_lex */
Perl_ck_null, /* aelem */
Perl_ck_null, /* aslice */
Perl_ck_null, /* kvaslice */
Perl_ck_each, /* aeach */
Perl_ck_each, /* akeys */
Perl_ck_each, /* avalues */
Expand Down Expand Up @@ -1852,6 +1856,7 @@ EXTCONST U32 PL_opargs[] = {
0x00013040, /* aelemfast_lex */
0x00013204, /* aelem */
0x00023401, /* aslice */
0x00023401, /* kvaslice */
0x00003b00, /* aeach */
0x00003b08, /* akeys */
0x00003b08, /* avalues */
Expand Down
Loading

0 comments on commit 6dd3e0f

Please sign in to comment.