Beispiel #1
0
/** 
 * Dispatch an object to its content and write out
 */
static inline void _Disassembler_dispatch(pVMObject o) {
    //dispatch
    // can't switch() objects, so:
    if(!o) return; // NULL isn't interesting.
    else if(o == nil_object)
        debug_print("{Nil}");
    else if(o == true_object)
        debug_print("{True}");
    else if(o == false_object)
        debug_print("{False}"); 
    else if((pVMClass)o == system_class)
        debug_print("{System Class object}");
    else if((pVMClass)o == block_class)
        debug_print("{Block Class object}");
    else if(o == Universe_get_global(Universe_symbol_for("system")))
        debug_print("{System}");
    else {
        pVMClass c = SEND(o, get_class);
        if(c == string_class) {
            debug_print("\"%s\"", SEND((pVMString)o, get_chars));
        } else if(c == double_class)
            debug_print("%g", SEND((pVMDouble)o, get_embedded_double));
        else if(c == biginteger_class)
            debug_print("%lld", SEND((pVMBigInteger)o,
                                     get_embedded_biginteger));
        else if(c == integer_class)
            debug_print("%d", SEND((pVMInteger)o, get_embedded_integer));
        else if(c == symbol_class) {
            debug_print("#%s", SEND((pVMSymbol)o, get_chars));
        } else
            debug_print("address: %p", (void*)o);
    }
}
Beispiel #2
0
pVMClass VMClass_assemble(class_generation_context* cgc) {
    // build class class name
    const char* cgc_name = SEND(cgc->name, get_chars);
    char* ccname =
        (char*)internal_allocate(strlen(cgc_name) + 6 + 1); // 6: " class"
    strcpy(ccname, cgc_name);
    strcat(ccname, " class");
    pVMSymbol ccname_sym = Universe_symbol_for(ccname);
    internal_free(ccname);
    
    // Load the super class
    pVMClass super_class = Universe_load_class(cgc->super_name);
    
    // Allocate the class of the resulting class
    pVMClass result_class = Universe_new_class(metaclass_class);

    // Initialize the class of the resulting class
    SEND(result_class, set_instance_fields,
         Universe_new_array_list(cgc->class_fields));
    SEND(result_class, set_instance_invokables,
         Universe_new_array_list(cgc->class_methods));
    SEND(result_class, set_name, ccname_sym);
    pVMClass super_mclass = SEND(super_class, get_class);
    SEND(result_class, set_super_class, super_mclass);
    
    // Allocate the resulting class
    pVMClass result = Universe_new_class(result_class);
    
    // Initialize the resulting class
    SEND(result, set_instance_fields,
         Universe_new_array_list(cgc->instance_fields));
    SEND(result, set_instance_invokables,
         Universe_new_array_list(cgc->instance_methods));
    SEND(result, set_name, cgc->name);
    SEND(result, set_super_class, super_class);
    
    return result;
}