<commit_before>//
//  orbit_value.c
//  OrbitVM
//
//  Created by <NAME> on 2016-12-26.
//  Copyright © 2016 cesarparent. All rights reserved.
//
#include <string.h>
#include "orbit_value.h"
#include "orbit_utils.h"
#include "orbit_vm.h"

// Initialises [object] as an instance of [class]. [class] can be NULL if the
// object being initialized is a class itself.
static void orbit_objectInit(OrbitVM* vm, GCObject* object, GCClass* class) {
    OASSERT(vm != NULL, "Null instance error");
    OASSERT(object != NULL, "Null instance error");
    
    object->class = class;
    object->mark = false;
    object->next = vm->gcHead;
    vm->gcHead = object;
}

GCString* orbit_gcStringNew(OrbitVM* vm, const char* string) {
    OASSERT(vm != NULL, "Null instance error");
    
    size_t length = strlen(string);
    GCString* object = orbit_gcStringReserve(vm, length);
    
    memcpy(object->data, string, length);
    object->data[length] = '\0';
    orbit_gcStringComputeHash(object);
    return object;
}

GCString* orbit_gcStringReserve(OrbitVM* vm, size_t length) {
    OASSERT(vm != NULL, "Null instance error");
    
    GCString* object = ALLOC_FLEX(vm, GCString, char, length+1);
    orbit_objectInit(vm, (GCObject*)object, NULL);
    
    object->base.type = OBJ_STRING;
    object->hash = 0;
    object->length = length;
    memset(object->data, '\0', length);
    return object;
}

void orbit_gcStringComputeHash(GCString* string) {
    OASSERT(string != NULL, "Null instance error");
    string->hash = orbit_hashString(string->data, string->length);
}

GCInstance* orbit_gcInstanceNew(OrbitVM* vm, GCClass* class) {
    OASSERT(vm != NULL, "Null instance error");
    OASSERT(class != NULL, "Null class error");
    
    GCInstance* object = ALLOC_FLEX(vm, GCInstance, GCValue, class->fieldCount);
    orbit_objectInit(vm, (GCObject*)object, class);
    object->base.type = OBJ_INSTANCE;
    return object;
}

GCClass* orbit_gcClassNew(OrbitVM* vm, GCString* name, uint16_t fieldCount) {
    OASSERT(vm != NULL, "Null instance error");
    OASSERT(name != NULL, "Null instance error");
    
    GCClass* class = ALLOC(vm, GCClass);
    orbit_objectInit(vm, (GCObject*)class, NULL);
    class->base.type = OBJ_CLASS;
    class->super = NULL;
    class->fieldCount = fieldCount;
    class->name = name;
    
    return class;
}

VMFunction* orbit_gcFunctionNew(OrbitVM* vm, uint16_t byteCodeLength) {
    OASSERT(vm != NULL, "Null instance error");
    
    VMFunction* function = ALLOC(vm, VMFunction);
    orbit_objectInit(vm, (GCObject*)function, NULL);
    function->base.type = OBJ_FUNCTION;
    function->type = FN_NATIVE;
    
    // By default the function lives in the wild
    function->module = NULL;
    
    function->native.byteCode = ALLOC_ARRAY(vm, uint8_t, byteCodeLength);
    function->native.byteCodeLength = byteCodeLength;
    
    function->arity = 0;
    function->localCount = 0;
    function->stackEffect = 0;
    
    return function;
}

VMModule* orbit_gcModuleNew(OrbitVM* vm) {
    OASSERT(vm != NULL, "Null instance error");
    
    VMModule* module = ALLOC(vm, VMModule);
    orbit_objectInit(vm, (GCObject*)module, NULL);
    module->base.type = OBJ_MODULE;
    
    module->classes = orbit_gcMapNew(vm);
    module->dispatchTable = orbit_gcMapNew(vm);
    
    module->constantCount = 0;
    module->constants = NULL;
    module->globalCount = 0;
    module->globals = NULL;
    
    return module;
}

VMTask* orbit_gcTaskNew(OrbitVM* vm, VMFunction* function) {
    
    VMTask* task = ALLOC(vm, VMTask);
    orbit_objectInit(vm, (GCObject*)task, NULL);
    task->base.type = OBJ_TASK;
    
    task->stack = task->sp = ALLOC_ARRAY(vm, GCValue, 512);
    task->stackCapacity = 16;
    
    task->frames = ALLOC_ARRAY(vm, VMTask, 32);
    task->frameCapacity = 32;
    
    // Create the first frame
    task->frameCount = 1;
    VMCallFrame* frame = &task->frames[0];
    
    frame->task = task;
    frame->function = function;
    frame->ip = function->native.byteCode;
    frame->stackBase = task->stack;
    
    return task;
}<commit_msg>raise default stack size to 512 values<commit_after>//
//  orbit_value.c
//  OrbitVM
//
//  Created by <NAME> on 2016-12-26.
//  Copyright © 2016 cesarparent. All rights reserved.
//
#include <string.h>
#include "orbit_value.h"
#include "orbit_utils.h"
#include "orbit_vm.h"

// Initialises [object] as an instance of [class]. [class] can be NULL if the
// object being initialized is a class itself.
static void orbit_objectInit(OrbitVM* vm, GCObject* object, GCClass* class) {
    OASSERT(vm != NULL, "Null instance error");
    OASSERT(object != NULL, "Null instance error");
    
    object->class = class;
    object->mark = false;
    object->next = vm->gcHead;
    vm->gcHead = object;
}

GCString* orbit_gcStringNew(OrbitVM* vm, const char* string) {
    OASSERT(vm != NULL, "Null instance error");
    
    size_t length = strlen(string);
    GCString* object = orbit_gcStringReserve(vm, length);
    
    memcpy(object->data, string, length);
    object->data[length] = '\0';
    orbit_gcStringComputeHash(object);
    return object;
}

GCString* orbit_gcStringReserve(OrbitVM* vm, size_t length) {
    OASSERT(vm != NULL, "Null instance error");
    
    GCString* object = ALLOC_FLEX(vm, GCString, char, length+1);
    orbit_objectInit(vm, (GCObject*)object, NULL);
    
    object->base.type = OBJ_STRING;
    object->hash = 0;
    object->length = length;
    memset(object->data, '\0', length);
    return object;
}

void orbit_gcStringComputeHash(GCString* string) {
    OASSERT(string != NULL, "Null instance error");
    string->hash = orbit_hashString(string->data, string->length);
}

GCInstance* orbit_gcInstanceNew(OrbitVM* vm, GCClass* class) {
    OASSERT(vm != NULL, "Null instance error");
    OASSERT(class != NULL, "Null class error");
    
    GCInstance* object = ALLOC_FLEX(vm, GCInstance, GCValue, class->fieldCount);
    orbit_objectInit(vm, (GCObject*)object, class);
    object->base.type = OBJ_INSTANCE;
    return object;
}

GCClass* orbit_gcClassNew(OrbitVM* vm, GCString* name, uint16_t fieldCount) {
    OASSERT(vm != NULL, "Null instance error");
    OASSERT(name != NULL, "Null instance error");
    
    GCClass* class = ALLOC(vm, GCClass);
    orbit_objectInit(vm, (GCObject*)class, NULL);
    class->base.type = OBJ_CLASS;
    class->super = NULL;
    class->fieldCount = fieldCount;
    class->name = name;
    
    return class;
}

VMFunction* orbit_gcFunctionNew(OrbitVM* vm, uint16_t byteCodeLength) {
    OASSERT(vm != NULL, "Null instance error");
    
    VMFunction* function = ALLOC(vm, VMFunction);
    orbit_objectInit(vm, (GCObject*)function, NULL);
    function->base.type = OBJ_FUNCTION;
    function->type = FN_NATIVE;
    
    // By default the function lives in the wild
    function->module = NULL;
    
    function->native.byteCode = ALLOC_ARRAY(vm, uint8_t, byteCodeLength);
    function->native.byteCodeLength = byteCodeLength;
    
    function->arity = 0;
    function->localCount = 0;
    function->stackEffect = 0;
    
    return function;
}

VMModule* orbit_gcModuleNew(OrbitVM* vm) {
    OASSERT(vm != NULL, "Null instance error");
    
    VMModule* module = ALLOC(vm, VMModule);
    orbit_objectInit(vm, (GCObject*)module, NULL);
    module->base.type = OBJ_MODULE;
    
    module->classes = orbit_gcMapNew(vm);
    module->dispatchTable = orbit_gcMapNew(vm);
    
    module->constantCount = 0;
    module->constants = NULL;
    module->globalCount = 0;
    module->globals = NULL;
    
    return module;
}

VMTask* orbit_gcTaskNew(OrbitVM* vm, VMFunction* function) {
    
    VMTask* task = ALLOC(vm, VMTask);
    orbit_objectInit(vm, (GCObject*)task, NULL);
    task->base.type = OBJ_TASK;
    
    task->stack = task->sp = ALLOC_ARRAY(vm, GCValue, 512);
    task->stackCapacity = 512;
    
    task->frames = ALLOC_ARRAY(vm, VMTask, 32);
    task->frameCapacity = 32;
    
    // Create the first frame
    task->frameCount = 1;
    VMCallFrame* frame = &task->frames[0];
    
    frame->task = task;
    frame->function = function;
    frame->ip = function->native.byteCode;
    frame->stackBase = task->stack;
    
    return task;
}
{'fraction_non_alphanumeric': 0.13422655298416566, 'fraction_numerical': 0.009500609013398295, 'mean_word_length': 3.3652312599681022, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 105, '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': '3681782', 'n_tokens_mistral': 2765, 'n_tokens_neox': 2707, 'n_words': 646}