<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * vim: set ts=4 sw=4 et tw=99 ft=cpp:
 */
#include <assert.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
#include <ctype.h>
#include <stdarg.h>

#include "ejs-ops.h"
#include "ejs-closureenv.h"

ejsval
_ejs_closureenv_new (uint32_t length)
{
    size_t value_size = sizeof(EJSClosureEnv) + sizeof(ejsval) * (length - 1);
    EJSClosureEnv* env = _ejs_gc_new_closureenv(value_size);
    return _ejs_closure_init (env, length);
}

ejsval
_ejs_closure_init (EJSClosureEnv* env, uint32_t length)
{
    env->length = length;
    for (int i = 0; i < length; i ++) {
        env->slots[i] = _ejs_undefined;
    }
    return CLOSUREENV_TO_EJSVAL_IMPL(env);
}

ejsval
_ejs_closureenv_get_slot (ejsval env, uint32_t slot)
{
    EJSClosureEnv* env_ = EJSVAL_TO_CLOSUREENV_IMPL(env);
    assert(slot < env_->length);
    return env_->slots[slot];
}

ejsval*
_ejs_closureenv_get_slot_ref (ejsval env, uint32_t slot)
{
    EJSClosureEnv* env_ = EJSVAL_TO_CLOSUREENV_IMPL(env);
    assert(slot < env_->length);<commit_msg>add some useful asserts for when we aren't opencoding this code directly into llvm ir<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * vim: set ts=4 sw=4 et tw=99 ft=cpp:
 */
#include <assert.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
#include <ctype.h>
#include <stdarg.h>

#include "ejs-ops.h"
#include "ejs-closureenv.h"

ejsval
_ejs_closureenv_new (uint32_t length)
{
    size_t value_size = sizeof(EJSClosureEnv) + sizeof(ejsval) * (length - 1);
    EJSClosureEnv* env = _ejs_gc_new_closureenv(value_size);
    return _ejs_closure_init (env, length);
}

ejsval
_ejs_closure_init (EJSClosureEnv* env, uint32_t length)
{
    assert (length > 0);

    env->length = length;
    for (int i = 0; i < length; i ++) {
        env->slots[i] = _ejs_undefined;
    }
    return CLOSUREENV_TO_EJSVAL_IMPL(env);
}

ejsval
_ejs_closureenv_get_slot (ejsval env, uint32_t slot)
{
    assert (EJSVAL_IS_CLOSUREENV(env));
    EJSClosureEnv* env_ = EJSVAL_TO_CLOSUREENV_IMPL(env);
    assert(slot < env_->length);
    return env_->slots[slot];
}

ejsval*
_ejs_closureenv_get_slot_ref (ejsval env, uint32_t slot)
{
    assert (EJSVAL_IS_CLOSUREENV(env));
    EJSClosureEnv* env_ = EJSVAL_TO_CLOSUREENV_IMPL(env);
    assert(slot < env_->length);
{'fraction_non_alphanumeric': 0.13745847176079734, 'fraction_numerical': 0.013704318936877076, 'mean_word_length': 4.329646017699115, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 26, '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': '4005000', 'n_tokens_mistral': 1037, 'n_tokens_neox': 1001, 'n_words': 204}