Skip to content

Commit

Permalink
Merge pull request #1608 from MasterDuke17/make_2_elem_infix_comma_sp…
Browse files Browse the repository at this point in the history
…ecial_cases_more_generic

Make 2 elem infix:<,> special cases more generic
  • Loading branch information
lizmat committed Mar 12, 2018
2 parents 470b38e + d5a148c commit 52e66ad
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/core/List.pm6
Expand Up @@ -1492,10 +1492,23 @@ my class List does Iterable does Positional { # declared in BOOTSTRAP
# The , operator produces a List.
proto sub infix:<,>(|) is pure {*}
multi sub infix:<,>() { nqp::create(List) }
multi sub infix:<,>(Int \a, Int \b) is default {
nqp::p6bindattrinvres(nqp::create(List),List,'$!reified',nqp::list(a,b))
multi sub infix:<,>(Slip:D \a, Slip:D \b) {
# now set up the List with a future
Rakudo::Internals.INFIX_COMMA_SLIP_HELPER(nqp::create(IterationBuffer), nqp::list(a,b))
}
multi sub infix:<,>(Any \a, Slip:D \b) {
nqp::stmts( # Slip seen, first copy non-slippy thing
(my $reified := nqp::create(IterationBuffer)),
nqp::bindpos($reified,0,a),
# now set up the List with a future
Rakudo::Internals.INFIX_COMMA_SLIP_HELPER($reified, nqp::list(b))
)
}
multi sub infix:<,>(Slip:D \a, Any \b) {
# now set up the List with a future
Rakudo::Internals.INFIX_COMMA_SLIP_HELPER(nqp::create(IterationBuffer), nqp::list(a,b))
}
multi sub infix:<,>(Str \a, Str \b) {
multi sub infix:<,>(Any \a, Any \b) {
nqp::p6bindattrinvres(nqp::create(List),List,'$!reified',nqp::list(a,b))
}
multi sub infix:<,>(|) {
Expand All @@ -1522,14 +1535,7 @@ multi sub infix:<,>(|) {
nqp::bindpos($reified,$i,nqp::shift(in))
),
# now set up the List with a future
(my $list :=
nqp::p6bindattrinvres(nqp::create(List),List,'$!reified',$reified)),
nqp::bindattr($list,List,'$!todo',
my $todo:= nqp::create(List::Reifier)),
nqp::bindattr($todo,List::Reifier,'$!reified',$reified),
nqp::bindattr($todo,List::Reifier,'$!future',in),
nqp::bindattr($todo,List::Reifier,'$!reification-target',$reified),
$list
Rakudo::Internals.INFIX_COMMA_SLIP_HELPER($reified, in)
)
)
}
Expand Down
14 changes: 14 additions & 0 deletions src/core/Rakudo/Internals.pm6
Expand Up @@ -3,6 +3,7 @@ my role IO { ... }
my class IO::Handle { ... }
my class IO::Path { ... }
my class Rakudo::Metaops { ... }
my class List::Reifier { ... }

my class X::Assignment::ToShaped { ... }
my class X::Cannot::Lazy { ... }
Expand Down Expand Up @@ -1562,6 +1563,19 @@ my class Rakudo::Internals {
nqp::iscont(obj) ?? retval.item !! retval;
}

method INFIX_COMMA_SLIP_HELPER(\reified, \future) {
nqp::stmts(
(my $list :=
nqp::p6bindattrinvres(nqp::create(List),List,'$!reified',reified)),
nqp::bindattr($list,List,'$!todo',
my $todo:= nqp::create(List::Reifier)),
nqp::bindattr($todo,List::Reifier,'$!reified',reified),
nqp::bindattr($todo,List::Reifier,'$!future',nqp::getattr(future,List,'$!reified')),
nqp::bindattr($todo,List::Reifier,'$!reification-target',reified),
$list
)
}

}

# expose the number of bits a native int has
Expand Down

0 comments on commit 52e66ad

Please sign in to comment.