void dj_init() { // initialise memory manager dj_mem_init(mem, HEAPSIZE); // initialise timer dj_timer_init(); // create a new VM vm = dj_vm_create(); // tell the execution engine to use the newly created VM instance dj_exec_setVM(vm); // load the embedded infusions dj_named_native_handler handlers[] = { { "base", &base_native_handler }, { "darjeeling2", &darjeeling2_native_handler } }; int length = sizeof(handlers) / sizeof(handlers[0]); dj_archive archive; archive.start = (dj_di_pointer)di_archive_data; archive.end = (dj_di_pointer)(di_archive_data + di_archive_size); dj_vm_loadInfusionArchive(vm, &archive, handlers, length); // load the embedded infusions // pre-allocate an OutOfMemoryError object dj_object *obj = dj_vm_createSysLibObject(vm, BASE_CDEF_java_lang_OutOfMemoryError); vm_mem_setPanicExceptionObject(obj); }
int main(int argc,char* argv[]) { dj_vm * vm; dj_object * obj; conio_init(); // initialise timer dj_timer_init(); initLed(); // initialise memory manager dj_mem_init(mem, HEAPSIZE); // Create a new VM vm = dj_vm_create(); // tell the execution engine to use the newly created VM instance dj_exec_setVM(vm); dj_named_native_handler handlers[] = { { "base", &base_native_handler }, { "darjeeling2", &darjeeling2_native_handler }, }; int length = sizeof(handlers)/ sizeof(handlers[0]); dj_archive archive; archive.start = (dj_di_pointer)di_archive_data; archive.end = (dj_di_pointer)di_archive_data_end; dj_vm_loadInfusionArchive(vm, &archive, handlers, length); // pre-allocate an OutOfMemoryError object obj = dj_vm_createSysLibObject(vm, BASE_CDEF_java_lang_OutOfMemoryError); dj_mem_setPanicExceptionObject(obj); // start the main execution loop while (dj_vm_countLiveThreads(vm)>0) { dj_vm_schedule(vm); if (vm->currentThread!=NULL) if (vm->currentThread->status==THREADSTATUS_RUNNING) dj_exec_run(RUNSIZE); } dj_vm_schedule(vm); dj_mem_gc(); dj_vm_destroy(vm); conio_shutdown(); return 0; }
void dj_init() { //before anything starts, define global variables struct tossim_global_variables* global_variables = malloc(sizeof(struct tossim_global_variables)); struct tossim_UGLY_global_variables* UGLY_global_variables = malloc(sizeof(struct tossim_UGLY_global_variables)); setGlobalVariables(global_variables); setUglyGlobalVariables(UGLY_global_variables); dj_vm *vm; unsigned char *mem = malloc(HEAPSIZE); // initialise memory manager dj_mem_init(mem, HEAPSIZE); _global_ref_t_base_address = (char*)mem - 42; // initialise timer dj_timer_init(); // create a new VM vm = dj_vm_create(); if (vm == nullref) { //fail with a unknown type exception dj_panic(-1); } // tell the execution engine to use the newly created VM instance dj_exec_setVM(vm); // load the embedded infusions dj_named_native_handler handlers[] = { { "base", &base_native_handler }, { "darjeeling", &darjeeling_native_handler } #ifdef WITH_RADIO ,{ "radio", &radio_native_handler } #endif }; int length = sizeof(handlers)/ sizeof(handlers[0]); archive.start = (dj_di_pointer)di_archive_data; archive.end = (dj_di_pointer)(di_archive_data + di_archive_size); dj_vm_loadInfusionArchive(vm, &archive, handlers, length); // load the embedded infusions DARJEELING_PRINTF("%d infusions loaded\n", dj_vm_countInfusions(dj_exec_getVM())); // pre-allocate an OutOfMemoryError object dj_object *obj = dj_vm_createSysLibObject(dj_exec_getVM(), BASE_CDEF_java_lang_OutOfMemoryError); dj_mem_setPanicExceptionObject(obj); }
/** * Main function that creates the vm and runs until either all threads stop or runlevel is set to RUNLEVEL_REBOOT * This code was in the main() of each config before, but has been extracted to make rebooting easier. */ void dj_vm_main(void *mem, uint32_t memsize, dj_di_pointer di_lib_infusions_archive_data, dj_di_pointer di_app_infusion_archive_data, dj_named_native_handler handlers[], uint8_t handlers_length) { dj_vm *vm; dj_object * obj; // initialise timer dj_timer_init(); // initialise memory managerw dj_mem_init(mem, memsize); // create a new VM vm = dj_vm_create(); // tell the execution engine to use the newly created VM instance dj_exec_setVM(vm); // set run level before loading libraries since they need to execute initialisation code dj_exec_setRunlevel(RUNLEVEL_RUNNING); dj_vm_loadInfusionArchive(vm, di_lib_infusions_archive_data, handlers, handlers_length); dj_di_pointer di_app_infusion_data = dj_archive_get_file(di_app_infusion_archive_data, 0); dj_vm_loadInfusion(vm, di_app_infusion_data, NULL, 0); // pre-allocate an OutOfMemoryError object obj = dj_vm_createSysLibObject(vm, BASE_CDEF_java_lang_OutOfMemoryError); dj_mem_setPanicExceptionObject(obj); DEBUG_LOG(true, "Darjeeling is go!\n\r"); // start the main execution loop while (dj_vm_countLiveThreads(vm)>0) { dj_vm_schedule(vm); if (vm->currentThread!=NULL) if (vm->currentThread->status==THREADSTATUS_RUNNING) dj_exec_run(RUNSIZE); } DEBUG_LOG(true, "All threads terminated.\n\r"); }