void Universe::initialize(long _argc, char** _argv) { #ifdef GENERATE_ALLOCATION_STATISTICS allocationStats["VMArray"] = {0,0}; #endif heapSize = 1 * 1024 * 1024; vector<StdString> argv = handleArguments(_argc, _argv); // remember file that was executed (for writing statistics) if (argv.size() > 0) bm_name = argv[0]; Heap<HEAP_CLS>::InitializeHeap(heapSize); interpreter = new Interpreter(); #if CACHE_INTEGER # warning is _store_ptr sufficient/correct here? // create prebuilt integers for (long it = INT_CACHE_MIN_VALUE; it <= INT_CACHE_MAX_VALUE; ++it) { prebuildInts[(unsigned long)(it - INT_CACHE_MIN_VALUE)] = _store_ptr(new (GetHeap<HEAP_CLS>()) VMInteger(it)); } #endif InitializeGlobals(); VMObject* systemObject = NewInstance(load_ptr(systemClass)); SetGlobal(SymbolForChars("nil"), load_ptr(nilObject)); SetGlobal(SymbolForChars("true"), load_ptr(trueObject)); SetGlobal(SymbolForChars("false"), load_ptr(falseObject)); SetGlobal(SymbolForChars("system"), systemObject); SetGlobal(SymbolForChars("System"), load_ptr(systemClass)); SetGlobal(SymbolForChars("Block"), load_ptr(blockClass)); symbolIfTrue = _store_ptr(SymbolForChars("ifTrue:")); symbolIfFalse = _store_ptr(SymbolForChars("ifFalse:")); VMMethod* bootstrapMethod = NewMethod(SymbolForChars("bootstrap"), 1, 0); bootstrapMethod->SetBytecode(0, BC_HALT); bootstrapMethod->SetNumberOfLocals(0); bootstrapMethod->SetMaximumNumberOfStackElements(2); bootstrapMethod->SetHolder(load_ptr(systemClass)); if (argv.size() == 0) { Shell* shell = new Shell(bootstrapMethod); shell->Start(); return; } /* only trace bootstrap if the number of cmd-line "-d"s is > 2 */ short trace = 2 - dumpBytecodes; if (!(trace > 0)) dumpBytecodes = 1; VMArray* argumentsArray = NewArrayFromStrings(argv); VMFrame* bootstrapFrame = interpreter->PushNewFrame(bootstrapMethod); bootstrapFrame->Push(systemObject); bootstrapFrame->Push(argumentsArray); VMInvokable* initialize = load_ptr(systemClass)->LookupInvokable( SymbolForChars("initialize:")); (*initialize)(bootstrapFrame); // reset "-d" indicator if (!(trace > 0)) dumpBytecodes = 2 - trace; interpreter->Start(); }