<commit_before>=head1 NAME

src/builtins/assign.pir - assignment operations

=head1 Functions

=over 4

=cut

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

  cont_loop:
    # If the lhs isn't marked rw, throw exception
    .local pmc rw
    rw = getprop 'rw', cont
    unless null rw goto rw_ok
    '&die'('Cannot assign to readonly value')
  rw_ok:

    # If the lhs isn't a scalar container, delegate to
    # object's STORE method.
    $P0 = getprop 'scalar', cont
    if null $P0 goto cont_store

  scalar_store:
    # perform any needed typecheck
    .local pmc type
    type = getprop 'type', cont
    if null type goto type_ok
    $P0 = type.'ACCEPTS'(source)
    if $P0 goto type_ok
    '&die'('Type check failed for assignment')
  type_ok:

    # Dereference the scalar LHS.  If the thing we're
    # currently referencing is itself an ObjectRef, delegate
    # the assignment to it.
    .local pmc tgt
    tgt = deref cont
    $I0 = isa tgt, ['ObjectRef']
    unless $I0 goto scalar_assign
    cont = tgt
    goto cont_loop

  scalar_assign:
    # put the source in item context, fully dereference it, and set the 
    # lhs objectref to it
    $I0 = can source, 'item'
    unless $I0 goto have_source
    source = source.'item'()
  have_source:
    source = descalarref source
    setref cont, source
    .return (cont)

  cont_store:
    .tailcall cont.'!STORE'(source)
.end


.sub '&infix:<=>' :multi(['Proxy'], _)
    .param pmc cont
    .param pmc source<commit_msg>Assigning Nil to a container resets it to type.<commit_after>=head1 NAME

src/builtins/assign.pir - assignment operations

=head1 Functions

=over 4

=cut

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

  cont_loop:
    # If the lhs isn't marked rw, throw exception
    .local pmc rw
    rw = getprop 'rw', cont
    unless null rw goto rw_ok
    '&die'('Cannot assign to readonly value')
  rw_ok:

    # If the lhs isn't a scalar container, delegate to
    # object's STORE method.
    $P0 = getprop 'scalar', cont
    if null $P0 goto cont_store

  scalar_store:
    # perform any needed typecheck
    .local pmc type
    type = getprop 'type', cont
    if null type goto type_ok
    $P0 = type.'ACCEPTS'(source)
    if $P0 goto type_ok
    '&die'('Type check failed for assignment')
  type_ok:

    # Dereference the scalar LHS.  If the thing we're
    # currently referencing is itself an ObjectRef, delegate
    # the assignment to it.
    .local pmc tgt
    tgt = deref cont
    $I0 = isa tgt, ['ObjectRef']
    unless $I0 goto scalar_assign
    cont = tgt
    goto cont_loop

  scalar_assign:
    # check for Nil assignment
    $I0 = isa source, ['Parcel']
    unless $I0 goto item_assign
    $I0 = elements source
    if $I0 goto item_assign
  nil_assign:
    source = getprop 'type', cont
    unless null source goto have_source
    source = get_hll_global '$!OBJECTREF'
    goto have_source
  item_assign:
    # put the source in item context
    $I0 = can source, 'item'
    unless $I0 goto have_source
    source = source.'item'()
  have_source:
    source = descalarref source
    setref cont, source
    .return (cont)

  cont_store:
    .tailcall cont.'!STORE'(source)
.end


.sub '&infix:<=>' :multi(['Proxy'], _)
    .param pmc cont
    .param pmc source
{'fraction_non_alphanumeric': 0.09513805522208883, 'fraction_numerical': 0.0078031212484993995, 'mean_word_length': 2.744943820224719, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2096955', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1113, 'n_words': 398}