<commit_before>/* This was a bad use of my time. */

#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <stdint.h>
#include <stdlib.h>

/* There isn't a C API for array.array so I make own API. */
typedef struct arrayobject {
    PyObject_VAR_HEAD
    char *ob_item;
} arrayobjectprefix;

#define _get_array(o) ((int64_t *)((arrayobjectprefix *)o)->ob_item)

static int grow_array(PyObject *array, int amount, ssize_t *psize, int64_t **pmem)
{
    // this could be a lot better but I expect it won't come up that much
    for (int i = 0; i < amount; i++) {
        PyObject *res = PyObject_CallMethod(array, "append", "i", 0);
        if (!res) return -1;
        Py_DECREF(res);
    }
    *psize = Py_SIZE(array);
    *pmem = _get_array(array);
    return 0;
}

static int mode_divs[] = { 0, 100, 1000, 10000 };

static int64_t compute_addr(int64_t *mem, int i, int64_t instr, int64_t ip, int64_t relative_base) {
    // XXX: could this be better
    int mode = (instr / mode_divs[i]) % 10;
    switch (mode) {
    case 0:
        return mem[ip+i];
    case 1:
        return ip+i;
    case 2:
        return mem[ip+i] + relative_base;
    }
    abort();
}

static int64_t read_mem(int64_t *mem, ssize_t size, int64_t addr) {
    return addr < 0 || addr >= size ? 0 : mem[addr];
}

#define ADDR(i) compute_addr(mem, i, instr, ip, relative_base)<commit_msg>tweak scaling<commit_after>/* This was a bad use of my time. */

#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <stdint.h>
#include <stdlib.h>

/* There isn't a C API for array.array so I make own API. */
typedef struct arrayobject {
    PyObject_VAR_HEAD
    char *ob_item;
} arrayobjectprefix;

#define _get_array(o) ((int64_t *)((arrayobjectprefix *)o)->ob_item)

static int grow_array(PyObject *array, int amount, ssize_t *psize, int64_t **pmem)
{
    ssize_t start = Py_SIZE(array);
    amount = amount * 8 / 7;
    // this could be a lot better but I expect it won't come up that much
    for (int i = start; i < amount; i++) {
        PyObject *res = PyObject_CallMethod(array, "append", "i", 0);
        if (!res) return -1;
        Py_DECREF(res);
    }
    *psize = Py_SIZE(array);
    *pmem = _get_array(array);
    return 0;
}

static int mode_divs[] = { 0, 100, 1000, 10000 };

static int64_t compute_addr(int64_t *mem, int i, int64_t instr, int64_t ip, int64_t relative_base) {
    // XXX: could this be better
    int mode = (instr / mode_divs[i]) % 10;
    switch (mode) {
    case 0:
        return mem[ip+i];
    case 1:
        return ip+i;
    case 2:
        return mem[ip+i] + relative_base;
    }
    abort();
}

static int64_t read_mem(int64_t *mem, ssize_t size, int64_t addr) {
    return addr < 0 || addr >= size ? 0 : mem[addr];
}

#define ADDR(i) compute_addr(mem, i, instr, ip, relative_base)
{'fraction_non_alphanumeric': 0.1312298314808175, 'fraction_numerical': 0.031911079239870924, 'mean_word_length': 3.0789473684210527, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2171670', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1039, 'n_words': 321}