<commit_before>## $Id$

=head1 NAME

src/classes/Associative.pir - Associative Role

=head1 DESCRIPTION

=cut

.namespace ['Associative[::T]']

.sub '_associative_role_body'
    .param pmc type :optional
    
    $P0 = get_hll_global ['Associative[::T]'], 'postcircumfix:{ }'
    capture_lex $P0
    $P0 = get_hll_global ['Associative[::T]'], 'of'
    capture_lex $P0

    # Capture type.
    if null type goto no_type
    type = type.'WHAT'()
    goto type_done
  no_type:
    type = get_hll_global 'Object'
  type_done:
    .lex 'T', type
    
    # Create role.
    .local pmc metarole
    metarole = "!meta_create"("role", "Associative[::T]", 0)
    .tailcall '!create_parametric_role'(metarole)
.end
.sub '' :load :init :outer('_associative_role_body')
    .local pmc block, signature
    block = get_hll_global ['Associative[::T]'], '_associative_role_body'
    signature = new ["Signature"]
    setprop block, "$!signature", signature
    signature."!add_param"("T", 1 :named("optional"))
    "!ADDTOROLE"(block)
.end


=head2 Operators

=over

=item postcircumfix:<{ }>

Returns a list element or slice.

=cut

.sub 'postcircumfix:{ }' :method :outer('_associative_role_body')
    .param pmc args            :slurpy
    .param pmc options         :slurpy :named
    .local pmc result, type
    type = find_lex 'T'
    if args goto do_index
    ## return complete invocant as a list
    .tailcall self.'list'()
  do_index:
    args.'!flatten'()
    $I0 = args.'elems'()
    if $I0 != 1 goto slice
    $S0 = args[0]
    result = self[$S0]
    unless null result goto end
    result = 'undef'()
    setprop result, 'type', type
    self[$S0] = result
    goto end
  slice:
    result = new 'List'
  slice_loop:
    unless args goto slice_done
    $S0 = shift args
    .local pmc elem
    elem = self[$S0]
    unless null elem goto slice_elem
    elem = 'undef'()
    setprop elem, 'type', type
    self[$S0] = elem
  slice_elem:
    push result, elem
    goto slice_loop
  slice_done:
  end:<commit_msg>%h<> should return everything in the hash, like @a[] returns everything in the array.<commit_after>## $Id$

=head1 NAME

src/classes/Associative.pir - Associative Role

=head1 DESCRIPTION

=cut

.namespace ['Associative[::T]']

.sub '_associative_role_body'
    .param pmc type :optional
    
    $P0 = get_hll_global ['Associative[::T]'], 'postcircumfix:{ }'
    capture_lex $P0
    $P0 = get_hll_global ['Associative[::T]'], 'of'
    capture_lex $P0

    # Capture type.
    if null type goto no_type
    type = type.'WHAT'()
    goto type_done
  no_type:
    type = get_hll_global 'Object'
  type_done:
    .lex 'T', type
    
    # Create role.
    .local pmc metarole
    metarole = "!meta_create"("role", "Associative[::T]", 0)
    .tailcall '!create_parametric_role'(metarole)
.end
.sub '' :load :init :outer('_associative_role_body')
    .local pmc block, signature
    block = get_hll_global ['Associative[::T]'], '_associative_role_body'
    signature = new ["Signature"]
    setprop block, "$!signature", signature
    signature."!add_param"("T", 1 :named("optional"))
    "!ADDTOROLE"(block)
.end


=head2 Operators

=over

=item postcircumfix:<{ }>

Returns a list element or slice.

=cut

.sub 'postcircumfix:{ }' :method :outer('_associative_role_body')
    .param pmc args            :slurpy
    .param pmc options         :slurpy :named
    .local pmc result, type
    type = find_lex 'T'
    args.'!flatten'()
    if args goto do_index
    ## return complete set of values as a list
    .tailcall self.'values'()
  do_index:
    $I0 = args.'elems'()
    if $I0 != 1 goto slice
    $S0 = args[0]
    result = self[$S0]
    unless null result goto end
    result = 'undef'()
    setprop result, 'type', type
    self[$S0] = result
    goto end
  slice:
    result = new 'List'
  slice_loop:
    unless args goto slice_done
    $S0 = shift args
    .local pmc elem
    elem = self[$S0]
    unless null elem goto slice_elem
    elem = 'undef'()
    setprop elem, 'type', type
    self[$S0] = elem
  slice_elem:
    push result, elem
    goto slice_loop
  slice_done:
  end:
{'fraction_non_alphanumeric': 0.1308913308913309, 'fraction_numerical': 0.00927960927960928, 'mean_word_length': 2.9960975609756098, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '1976853', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1452, 'n_words': 404}