<commit_before>## $Id$

=head1 NAME

src/builtins/assign.pir - assignments

=head1 Functions

=over 4

=cut

.namespace []
.sub 'infix:=' :multi(_,_)
    .param pmc cont
    .param pmc source

    .local pmc ro, type
    getprop ro, 'readonly', cont
    if null ro goto ro_ok
    unless ro goto ro_ok
    'die'('Cannot assign to readonly variable.')
  ro_ok:

    # This is a workaround because Parrot's multi-dispatch sometimes gets us
    # here by accident when we have a Perl6Array that got re-blessed.
    $I0 = isa cont, 'Perl6Scalar'
    if $I0 goto not_hash
    $I0 = isa cont, 'Perl6Array'
    unless $I0 goto not_array
    .tailcall cont.'!STORE'(source)
  not_array:
    $I0 = isa cont, 'Perl6Hash'
    unless $I0 goto not_hash
    .tailcall cont.'!STORE'(source)
  not_hash:

    source = '!CALLMETHOD'('Scalar', source)
    $I0 = defined source
    unless $I0 goto do_assign
    getprop type, 'type', cont
    if null type goto do_assign
    # XXX FIXME We should instead translate this to a proto.
    $I0 = isa type, 'NameSpace'
    if $I0 goto do_assign
    $I0 = type.'ACCEPTS'(source)
    if $I0 goto do_assign
    $S0 = type.'perl'()
    $S1 = source.'WHAT'()
    'die'("Type mismatch in assignment; expected something matching type ", $S0, " but got something of type ", $S1)
  do_assign:
    eq_addr cont, source, assign_done<commit_msg>Better handling of assignment of ObjectRef values.  Fixes RT #66280.<commit_after>## $Id$

=head1 NAME

src/builtins/assign.pir - assignments

=head1 Functions

=over 4

=cut

.namespace []
.sub 'infix:=' :multi(_,_)
    .param pmc cont
    .param pmc source

    .local pmc ro, type
    getprop ro, 'readonly', cont
    if null ro goto ro_ok
    unless ro goto ro_ok
    'die'('Cannot assign to readonly variable.')
  ro_ok:

    # This is a workaround because Parrot's multi-dispatch sometimes gets us
    # here by accident when we have a Perl6Array that got re-blessed.
    $I0 = isa cont, 'Perl6Scalar'
    if $I0 goto not_hash
    $I0 = isa cont, 'Perl6Array'
    unless $I0 goto not_array
    .tailcall cont.'!STORE'(source)
  not_array:
    $I0 = isa cont, 'Perl6Hash'
    unless $I0 goto not_hash
    .tailcall cont.'!STORE'(source)
  not_hash:

    source = '!CALLMETHOD'('Scalar', source)
    $I0 = defined source
    unless $I0 goto do_assign
    getprop type, 'type', cont
    if null type goto do_assign
    # XXX FIXME We should instead translate this to a proto.
    $I0 = isa type, 'NameSpace'
    if $I0 goto do_assign
    $I0 = type.'ACCEPTS'(source)
    if $I0 goto do_assign
    $S0 = type.'perl'()
    $S1 = source.'WHAT'()
    'die'("Type mismatch in assignment; expected something matching type ", $S0, " but got something of type ", $S1)
  do_assign:
    source = deobjectref source
    eq_addr cont, source, assign_done
{'fraction_non_alphanumeric': 0.10560114163396361, 'fraction_numerical': 0.018194791295041028, 'mean_word_length': 3.0, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6055326', 'n_tokens_mistral': 994, 'n_tokens_neox': 965, 'n_words': 335}