<commit_before>/*
 * Copyright (c) 2013, Regents of the University of California
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package edu.uci.python.nodes.subscript;

import com.oracle.truffle.api.dsl.*;

import edu.uci.python.nodes.*;
import edu.uci.python.runtime.array.*;
import edu.uci.python.runtime.datatype.*;
import edu.uci.python.runtime.sequence.*;
import edu.uci.python.runtime.sequence.storage.*;

public abstract class SubscriptStoreIndexNode extends SubscriptStoreNode {

    @Override
    public PNode makeReadNode() {
        return SubscriptLoadIndexNodeFactory.create(getPrimary(), getSlice());
    }

    @Specialization(order = 1, guards = {"isIntStorage", "isIndexPositive"})
    public Object doPListInt(PList primary, int idx, int value) {
        final IntSequenceStorage store = (IntSequenceStorage) primary.getStorage();
        store.setIntItemNormalized(idx, value);
        return PNone.NONE;
    }

    @Specialization(order = 2, guards = {"isIntStorage", "isIndexNegative"})
    public Object doPListIntNegative(PList primary, int idx, int value) {
        final IntSequenceStorage store = (IntSequenceStorage) primary.getStorage();
        store.setIntItemNormalized(idx + store.length(), value);
        return PNone.NONE;
    }

    @Specialization(order = 3, guards = "isDoubleStorage")
    public Object doPListDouble(PList primary, int idx, double value) {
        final DoubleSequenceStorage store = (DoubleSequenceStorage) primary.getStorage();
        final int index = SequenceUtil.normalizeIndex(idx, store.length());
        store.setDoubleItemNormalized(index, value);
        return PNone.NONE;
    }

    @Specialization(order = 5, guards = "isObjectStorage")
    public Object doPListObject(PList primary, int idx, Object value) {
        final ObjectSequenceStorage store = (ObjectSequenceStorage) primary.getStorage();
        final int index = SequenceUtil.normalizeIndex(idx, store.length());
        store.setItemNormalized(index, value);
        return PNone.NONE;
    }

    @Specialization(order = 7)
    public Object doPList(PList list, int idx, Object value) {
        list.setItem(idx, value);
        return PNone.NONE;
    }

    /**
     * PDict key & value store.
     */
    @Specialization(order = 8)
    public Object doPDict(PDict primary, Object key, Object value) {
        primary.setItem(key, value);
        return PNone.NONE;
    }

    /**
     * Unboxed array stores.
     */
    @Specialization(order = 10)
    public Object doPArrayInt(PIntArray primary, int index, int value) {
        primary.setIntItemNormalized(index, value);
        return PNone.NONE;
    }

    @Specialization(order = 11)
    public double doPArrayDouble(PDoubleArray primary, int index, double value) {
        primary.setDoubleItemNormalized(index, value);
        return 0;
    }

    @Specialization(order = 12)
    public char doPArrayChar(PCharArray primary, int index, char value) {
        primary.setCharItemNormalized(index, value);
        return 0;
    }

    @Specialization(order = 17)
    public Object doPArrayChar(PArray primary, int index, char value) {
        primary.setItem(index, value);
        return PNone.NONE;
    }

}<commit_msg>More index value guards in SubscriptStoreIndexNode<commit_after>/*
 * Copyright (c) 2013, Regents of the University of California
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package edu.uci.python.nodes.subscript;

import com.oracle.truffle.api.dsl.*;

import edu.uci.python.nodes.*;
import edu.uci.python.runtime.array.*;
import edu.uci.python.runtime.datatype.*;
import edu.uci.python.runtime.sequence.*;
import edu.uci.python.runtime.sequence.storage.*;

public abstract class SubscriptStoreIndexNode extends SubscriptStoreNode {

    @Override
    public PNode makeReadNode() {
        return SubscriptLoadIndexNodeFactory.create(getPrimary(), getSlice());
    }

    @Specialization(order = 1, guards = {"isIntStorage", "isIndexPositive"})
    public Object doPListInt(PList primary, int idx, int value) {
        final IntSequenceStorage store = (IntSequenceStorage) primary.getStorage();
        store.setIntItemNormalized(idx, value);
        return PNone.NONE;
    }

    @Specialization(order = 2, guards = {"isIntStorage", "isIndexNegative"})
    public Object doPListIntNegative(PList primary, int idx, int value) {
        final IntSequenceStorage store = (IntSequenceStorage) primary.getStorage();
        store.setIntItemNormalized(idx + store.length(), value);
        return PNone.NONE;
    }

    @Specialization(order = 3, guards = {"isDoubleStorage", "isIndexPositive"})
    public Object doPListDouble(PList primary, int idx, double value) {
        final DoubleSequenceStorage store = (DoubleSequenceStorage) primary.getStorage();
        store.setDoubleItemNormalized(idx, value);
        return PNone.NONE;
    }

    @Specialization(order = 4, guards = {"isDoubleStorage", "isIndexNegative"})
    public Object doPListDoubleNegative(PList primary, int idx, double value) {
        final DoubleSequenceStorage store = (DoubleSequenceStorage) primary.getStorage();
        store.setDoubleItemNormalized(idx + store.length(), value);
        return PNone.NONE;
    }

    @Specialization(order = 5, guards = {"isObjectStorage", "isIndexPositive"})
    public Object doPListObject(PList primary, int idx, Object value) {
        final ObjectSequenceStorage store = (ObjectSequenceStorage) primary.getStorage();
        store.setItemNormalized(idx, value);
        return PNone.NONE;
    }

    @Specialization(order = 6, guards = {"isObjectStorage", "isIndexNegative"})
    public Object doPListObjectNegative(PList primary, int idx, Object value) {
        final ObjectSequenceStorage store = (ObjectSequenceStorage) primary.getStorage();
        store.setItemNormalized(idx + store.length(), value);
        return PNone.NONE;
    }

    @Specialization(order = 14)
    public Object doPList(PList list, int idx, Object value) {
        list.setItem(idx, value);
        return PNone.NONE;
    }

    /**
     * PDict key & value store.
     */
    @Specialization(order = 15)
    public Object doPDict(PDict primary, Object key, Object value) {
        primary.setItem(key, value);
        return PNone.NONE;
    }

    /**
     * Unboxed array stores.
     */
    @Specialization(order = 20)
    public Object doPArrayInt(PIntArray primary, int index, int value) {
        primary.setIntItemNormalized(index, value);
        return PNone.NONE;
    }

    @Specialization(order = 22)
    public double doPArrayDouble(PDoubleArray primary, int index, double value) {
        primary.setDoubleItemNormalized(index, value);
        return 0;
    }

    @Specialization(order = 24)
    public char doPArrayChar(PCharArray primary, int index, char value) {
        primary.setCharItemNormalized(index, value);
        return 0;
    }

}
{'fraction_non_alphanumeric': 0.08808564765740937, 'fraction_numerical': 0.004875980496078016, 'mean_word_length': 3.6159491193737767, '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': '4268678', 'n_tokens_mistral': 2672, 'n_tokens_neox': 2481, 'n_words': 855}