Пример #1
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;
}
Пример #2
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;
}
Пример #3
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;
}
Пример #4
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;
}
Пример #5
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;
}