<commit_before># Turbine builtin container operations

namespace eval turbine {
    namespace export container_f_get container_f_insert
    namespace export f_reference
    namespace export f_container_create_nested

    # When i is closed, set d := c[i]
    # d: the destination, an integer
    # inputs: [ list c i ]
    # c: the container
    # i: the subscript
    proc container_f_get_integer { parent d inputs } {
        set c [ lindex $inputs 0 ]
        set i [ lindex $inputs 1 ]
        set rule_id [ rule_new ]
        rule $rule_id "container_f_get-$c-$i" $i $d \
            "tl: turbine::container_f_get_integer_body $d $c $i"
    }

    proc container_f_get_integer_body { d c i } {
        set t1 [ get $i ]
        set t2 [ container_get $c $t1 ]
        if { $t2 == 0 } {
            error "lookup failed: container_f_get <$c>\[$t1\]"
        }
        set t3 [ get $t2 ]
        set_integer $d $t3
    }

    # When i is closed, set c[i] := d
    # inputs: [ list c i d ]
    # c: the container
    # i: the subscript
    # d: the data
    # outputs: ignored.  To block on this, use turbine::reference
    proc container_f_insert { parent outputs inputs } {
        set c [ lindex $inputs 0 ]
        set i [ lindex $inputs 1 ]
        set d [ lindex $inputs 2 ]
        nonempty c i d
        adlb::slot_create $c
        set rule_id [ rule_new ]
        rule $rule_id "container_f_insert-$c-$i" $i "" \
            "tp: turbine::container_f_insert_body $c $i $d"
    }

    proc container_f_insert_body { c i d } {
        set t1 [ get $i ]
        container_insert $c $t1 $d
    }

    # When i and r are closed, set c[i] := *(r)
    # inputs: [ list c i r ]
    # r: a reference to a turbine ID
    #
    proc container_f_deref_insert { parent outputs inputs } {
        set c [ lindex $inputs 0 ]
        set i [ lindex $inputs 1 ]
        set r [ lindex $inputs 2 ]

        nonempty c i r
        adlb::slot_create $c
        set rule_id [ rule_new ]
        rule $rule_id "container_f_deref_insert-$c-$i" "$i $r" "" \
            "tp: turbine::container_f_deref_insert_body $c $i $r"
    }

    proc container_f_deref_insert_body { c i r } {
        set t1 [ get $i ]
        set d [ get $r ]
        container_insert $c $t1 $d
    }

    # When r is closed, set c[i] := *(r)
    # inputs: [ list c i r ]
    # i: an integer which is the index to insert into
    # r: a reference to a turbine ID
    #
    proc container_deref_insert { parent outputs inputs } {
        set c [ lindex $inputs 0 ]
        set i [ lindex $inputs 1 ]
        set r [ lindex $inputs 2 ]

        nonempty c i r
        adlb::slot_create $c
        set rule_id [ rule_new ]
        rule $rule_id "container_deref_insert-$c-$i" "$r" "" \
            "tp: turbine::container_deref_insert_body $c $i $r"
    }

    proc container_deref_insert_body { c i r } {
        set d [ get $r ]
        container_insert $c $i $d
    }

    # Immediately insert data into container without affecting open slot count
    # c: the container
    # i: the subscript
    # d: the data
    # outputs: ignored.
    proc container_immediate_insert { c i d } {
        adlb::slot_create $c
        container_insert $c $i $d
    }

    # When i is closed, get a reference on c[i] in TD r
    # Thus, you can block on r and be notified when c[i] exists
    # r is an integer.  The value of r is the TD of c[i]
    # inputs: [ list c i r ]
    # outputs: None.  You can block on d with turbine::dereference
    # c: the container
    # i: the subscript
    # r: the reference TD
    proc f_reference { parent outputs inputs } {
        set c [ lindex $inputs 0 ]
        set i [ lindex $inputs 1 ]
        set r [ lindex $inputs 2 ]
        # nonempty c i r
        set rule_id [ rule_new ]
        rule $rule_id "f_reference_body-$c-$i" $i "" \
            "tp: turbine::f_reference_body $c $i $r"
    }
    proc f_reference_body { c i r } {
        set t1 [ get $i ]
        adlb::container_reference $c $t1 $r
    }

    # When reference r is closed, store its (integer) value in v
    proc f_dereference_integer { parent v r } {
        set rule_id [ rule_new ]
        rule $rule_id "f_dereference-$v-$r" $r $v \
            "tp: turbine::f_dereference_integer_body $v $r"
    }
    proc f_dereference_integer_body { v r } {
        # Get the TD from the reference
        set id [ get $r ]
        # When the TD has a value, copy the value
        copy_integer no_stack $v $a
    }

    # When reference r is closed, store its (float) value in v
    proc f_dereference_float { parent v r } {
        set rule_id [ rule_new ]
        rule $rule_id "f_dereference-$v-$r" $r $v \
            "tp: turbine::f_dereference_float_body $v $r"
    }

    proc f_dereference_float_body { v r } {
        set t [ get [ get $r ] ]
        set_float $v $t
    }

    # When reference r is closed, store its (string) value in v
    proc f_dereference_string { parent v r } {
        set rule_id [ rule_new ]
        rule $rule_id "f_dereference-$v-$r" $r $v \
            "tp: turbine::f_dereference_string_body $v $r"
    }
    proc f_dereference_string_body { v r } {
        set t [ get [ get $r ] ]
        set_string $v $t
    }

    # When reference cr is closed, store d = (*cr)[i]<commit_msg>Update other dereference functions wrt new less buggy pattern<commit_after># Turbine builtin container operations

namespace eval turbine {
    namespace export container_f_get container_f_insert
    namespace export f_reference
    namespace export f_container_create_nested

    # When i is closed, set d := c[i]
    # d: the destination, an integer
    # inputs: [ list c i ]
    # c: the container
    # i: the subscript
    proc container_f_get_integer { parent d inputs } {
        set c [ lindex $inputs 0 ]
        set i [ lindex $inputs 1 ]
        set rule_id [ rule_new ]
        rule $rule_id "container_f_get-$c-$i" $i $d \
            "tl: turbine::container_f_get_integer_body $d $c $i"
    }

    proc container_f_get_integer_body { d c i } {
        set t1 [ get $i ]
        set t2 [ container_get $c $t1 ]
        if { $t2 == 0 } {
            error "lookup failed: container_f_get <$c>\[$t1\]"
        }
        set t3 [ get $t2 ]
        set_integer $d $t3
    }

    # When i is closed, set c[i] := d
    # inputs: [ list c i d ]
    # c: the container
    # i: the subscript
    # d: the data
    # outputs: ignored.  To block on this, use turbine::reference
    proc container_f_insert { parent outputs inputs } {
        set c [ lindex $inputs 0 ]
        set i [ lindex $inputs 1 ]
        set d [ lindex $inputs 2 ]
        nonempty c i d
        adlb::slot_create $c
        set rule_id [ rule_new ]
        rule $rule_id "container_f_insert-$c-$i" $i "" \
            "tp: turbine::container_f_insert_body $c $i $d"
    }

    proc container_f_insert_body { c i d } {
        set t1 [ get $i ]
        container_insert $c $t1 $d
    }

    # When i and r are closed, set c[i] := *(r)
    # inputs: [ list c i r ]
    # r: a reference to a turbine ID
    #
    proc container_f_deref_insert { parent outputs inputs } {
        set c [ lindex $inputs 0 ]
        set i [ lindex $inputs 1 ]
        set r [ lindex $inputs 2 ]

        nonempty c i r
        adlb::slot_create $c
        set rule_id [ rule_new ]
        rule $rule_id "container_f_deref_insert-$c-$i" "$i $r" "" \
            "tp: turbine::container_f_deref_insert_body $c $i $r"
    }

    proc container_f_deref_insert_body { c i r } {
        set t1 [ get $i ]
        set d [ get $r ]
        container_insert $c $t1 $d
    }

    # When r is closed, set c[i] := *(r)
    # inputs: [ list c i r ]
    # i: an integer which is the index to insert into
    # r: a reference to a turbine ID
    #
    proc container_deref_insert { parent outputs inputs } {
        set c [ lindex $inputs 0 ]
        set i [ lindex $inputs 1 ]
        set r [ lindex $inputs 2 ]

        nonempty c i r
        adlb::slot_create $c
        set rule_id [ rule_new ]
        rule $rule_id "container_deref_insert-$c-$i" "$r" "" \
            "tp: turbine::container_deref_insert_body $c $i $r"
    }

    proc container_deref_insert_body { c i r } {
        set d [ get $r ]
        container_insert $c $i $d
    }

    # Immediately insert data into container without affecting open slot count
    # c: the container
    # i: the subscript
    # d: the data
    # outputs: ignored.
    proc container_immediate_insert { c i d } {
        adlb::slot_create $c
        container_insert $c $i $d
    }

    # When i is closed, get a reference on c[i] in TD r
    # Thus, you can block on r and be notified when c[i] exists
    # r is an integer.  The value of r is the TD of c[i]
    # inputs: [ list c i r ]
    # outputs: None.  You can block on d with turbine::dereference
    # c: the container
    # i: the subscript
    # r: the reference TD
    proc f_reference { parent outputs inputs } {
        set c [ lindex $inputs 0 ]
        set i [ lindex $inputs 1 ]
        set r [ lindex $inputs 2 ]
        # nonempty c i r
        set rule_id [ rule_new ]
        rule $rule_id "f_reference_body-$c-$i" $i "" \
            "tp: turbine::f_reference_body $c $i $r"
    }
    proc f_reference_body { c i r } {
        set t1 [ get $i ]
        adlb::container_reference $c $t1 $r
    }

    # When reference r is closed, copy its (integer) value in v
    proc f_dereference_integer { parent v r } {
        set rule_id [ rule_new ]
        rule $rule_id "f_dereference-$v-$r" $r $v \
            "tp: turbine::f_dereference_integer_body $v $r"
    }
    proc f_dereference_integer_body { v r } {
        # Get the TD from the reference
        set id [ get $r ]
        # When the TD has a value, copy the value
        copy_integer no_stack $v $a
    }

    # When reference r is closed, copy its (float) value into v
    proc f_dereference_float { parent v r } {
        set rule_id [ rule_new ]
        rule $rule_id "f_dereference-$v-$r" $r $v \
            "tp: turbine::f_dereference_float_body $v $r"
    }

    proc f_dereference_float_body { v r } {
        # Get the TD from the reference
        set id [ get $r ]
        # When the TD has a value, copy the value
        copy_float no_stack $v $a
    }

    # When reference r is closed, copy its (string) value into v
    proc f_dereference_string { parent v r } {
        set rule_id [ rule_new ]
        rule $rule_id "f_dereference-$v-$r" $r $v \
            "tp: turbine::f_dereference_string_body $v $r"
    }
    proc f_dereference_string_body { v r } {
        # Get the TD from the reference
        set id [ get $r ]
        # When the TD has a value, copy the value
        copy_string no_stack $v $a
    }

    # When reference cr is closed, store d = (*cr)[i]
{'fraction_non_alphanumeric': 0.09442537797977923, 'fraction_numerical': 0.0053798348947221965, 'mean_word_length': 1.969429909115946, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5793828', 'n_tokens_mistral': 3687, 'n_tokens_neox': 3549, 'n_words': 1275}