Esempio n. 1
0
	AnyObjectPtr create_object_without_initialize(ClassPtr cls) {
		ASSERT(cls != NULL); // cls is not a class!
		Object* obj = gc_allocate_object(cls->instance_type);
		obj->cls = cls;
		obj->type = cls->instance_type;
		obj->num_alloc_members = 0;
		obj->members = NULL;
		return obj;
	}
Esempio n. 2
0
/** 
 * Create a new VMInteger with initial value
 */
pVMInteger VMInteger_new_with(const int64_t integer) {
    pVMInteger result = (pVMInteger)gc_allocate_object(sizeof(VMInteger));
    if(result) {
        result->_vtable = VMInteger_vtable();
        gc_start_uninterruptable_allocation();
        INIT(result, integer);
        gc_end_uninterruptable_allocation();
    }
    return result;
}
Esempio n. 3
0
/** 
 *  Create a new VMBigInteger
 * 
 */
pVMBigInteger VMBigInteger_new(void) {
    pVMBigInteger result =
        (pVMBigInteger)gc_allocate_object(sizeof(VMBigInteger));
    if(result) {
        result->_vtable = VMBigInteger_vtable();
        gc_start_uninterruptable_allocation();
        INIT(result, 0);
        gc_end_uninterruptable_allocation();
    }
    return result;
}
Esempio n. 4
0
/** 
 *  Create a new VMArray
 *
 */
pVMArray VMArray_new(size_t size) {
    pVMArray result = (pVMArray)gc_allocate_object(
        sizeof(VMArray) + sizeof(pVMObject) * size);
    if(result) {
        result->_vtable = VMArray_vtable();
        gc_start_uninterruptable_allocation();
        INIT(result, size);
        gc_end_uninterruptable_allocation();
    }
    return result;
}
Esempio n. 5
0
/**
 * Create a new VMMethod
 */
pVMMethod VMMethod_new(size_t number_of_bytecodes, size_t number_of_constants,
                       size_t number_of_locals,
                       size_t max_number_of_stack_elements,
                       pVMSymbol signature) {
    pVMMethod result = (pVMMethod)gc_allocate_object(
        sizeof(VMMethod) + (sizeof(pVMObject) * number_of_constants) +
        (sizeof(uint8_t) * number_of_bytecodes));
    if(result) {
        result->_vtable = VMMethod_vtable();
		gc_start_uninterruptable_allocation();
        INIT(result, number_of_constants, number_of_bytecodes,
             number_of_locals, max_number_of_stack_elements, signature);
        gc_end_uninterruptable_allocation();
    }
    return result;
}
Esempio n. 6
0
/**
 * Create a new VMClass with a specific number of fields
 */
pVMClass VMClass_new_num_fields(intptr_t number_of_fields) {
    // calculate Class size without fields
    size_t class_stub_size = sizeof(VMClass) - 
                             sizeof(pVMObject) * 
                            (SIZE_DIFF_VMOBJECT(VMClass) - 1);
    pVMClass result = 
        (pVMClass)gc_allocate_object(class_stub_size +
                              sizeof(pVMObject) * number_of_fields);

    if(result) {
        result->_vtable = VMClass_vtable();
        gc_start_uninterruptable_allocation();
        INIT(result, number_of_fields);
        gc_end_uninterruptable_allocation();
    }
    
    return result;
}
Esempio n. 7
0
	ObjectPtr<Class> get_class_class() {
		static Value* root = NULL;
		if (!root) {
			// bootstrapping
			AnyObjectPtr class_class = gc_allocate_object(get_type<Class>());
			class_class->cls = class_class;
			Class* priv = snow::object_get_private<Class>(class_class);
			priv->instance_type = get_type<Class>();
			root = gc_create_root(class_class);
			
			SN_DEFINE_METHOD(class_class, "initialize", bindings::class_initialize);
			SN_DEFINE_METHOD(class_class, "define_method", bindings::class_define_method);
			SN_DEFINE_METHOD(class_class, "define_property", bindings::class_define_property);
			SN_DEFINE_METHOD(class_class, "inspect", bindings::class_inspect);
			SN_DEFINE_METHOD(class_class, "to_string", bindings::class_inspect);
			SN_DEFINE_METHOD(class_class, "__call__", bindings::class_call);
			SN_DEFINE_PROPERTY(class_class, "instance_methods", bindings::class_get_instance_methods, NULL);
		}
		return *root;
	}
Esempio n. 8
0
#include "VMSymbol.h"

#include <memory/gc.h>

#include <string.h>

//
//  Class Methods (Starting with VMSymbol_) 
//


/**
 * Create a new VMSymbol with an initial C-string
 */
pVMSymbol VMSymbol_new(const char* restrict string) {
    pVMSymbol result = (pVMSymbol)gc_allocate_object(
        sizeof(VMSymbol) + sizeof(char) * (strlen(string) + 1));
    if(result) {
        result->_vtable = VMSymbol_vtable();
        gc_start_uninterruptable_allocation();
        INIT(result, string);
        gc_end_uninterruptable_allocation();
    }
    return result;
}


/**
 * Initialize a VMSymbol
 */
void _VMSymbol_init(void* _self, ...) {
    pVMSymbol self = (pVMSymbol)_self;