void CppiaVar::load(CppiaStream &stream) { readAccess = getAccess(stream); writeAccess = getAccess(stream); isVirtual = stream.getBool(); nameId = stream.getInt(); typeId = stream.getInt(); if (stream.getInt()) init = createCppiaExpr(stream); }
CppiaLoadedModule LoadCppia(const unsigned char *inData, int inDataLength) { if (!gAllCppiaModules.mPtr) { gAllCppiaModules = Array_obj<Dynamic>::__new(); GCAddRoot( (hx::Object **)&gAllCppiaModules.mPtr ); } CppiaModule *cppiaPtr = new CppiaModule(); CppiaLoadedModule loadedModule = new CppiaObject(cppiaPtr); gAllCppiaModules->push(loadedModule); CppiaModule &cppia = *cppiaPtr; CppiaStream stream(cppiaPtr,inData, inDataLength); String error; try { std::string tok = stream.getAsciiToken(); if (tok!="CPPIA" && tok!="CPPIB") throw "Bad magic"; stream.setBinary(tok=="CPPIB"); int stringCount = stream.getAsciiInt(); for(int s=0;s<stringCount;s++) cppia.strings[s] = stream.readString(); int typeCount = stream.getAsciiInt(); cppia.types.resize(typeCount); DBGLOG("Type count : %d\n", typeCount); for(int t=0;t<typeCount;t++) cppia.types[t] = new TypeData(stream.readString()); int classCount = stream.getAsciiInt(); DBGLOG("Class count : %d\n", classCount); if (stream.binary) { int newLine = stream.getByte(); if (newLine!='\n') throw "Missing new-line after class count"; } cppia.classes.reserve(classCount); for(int c=0;c<classCount;c++) { CppiaClassInfo *info = new CppiaClassInfo(cppia); if (info->load(stream)) cppia.classes.push_back(info); } tok = stream.getToken(); if (tok=="MAIN") { DBGLOG("Main...\n"); cppia.main = new ScriptCallable(createCppiaExpr(stream)); cppia.main->className = "cppia"; cppia.main->functionName = "__cppia_main"; } else if (tok!="NOMAIN") throw "no main specified"; tok = stream.getToken(); if (tok=="RESOURCES") { int count = stream.getInt( ); scriptResources.resize(count+1); for(int r=0;r<count;r++) { tok = stream.getToken(); if (tok!="RESO") throw "no reso tag"; scriptResources[r].mName = cppia.strings[stream.getInt()]; scriptResources[r].mDataLength = stream.getInt(); } if (!stream.binary) stream.skipChar(); for(int r=0;r<count;r++) { int len = scriptResources[r].mDataLength; unsigned char *buffer = (unsigned char *)malloc(len+5); *(unsigned int *)buffer = HX_GC_CONST_ALLOC_BIT; buffer[len+5-1] = '\0'; stream.readBytes(buffer+4, len); #ifdef HX_SMART_STRINGS_1 unsigned char *p = (unsigned char *)buffer+4; unsigned char *end = p + len; while(!hasBig && p<end) if (*p++>127) { *(unsigned int *)buffer |= HX_GC_STRING_CHAR16_T; break; } #endif scriptResources[r].mData = buffer + 4; } scriptResources[count].mDataLength = 0; scriptResources[count].mData = 0; scriptResources[count].mName = String(); RegisterResources(&scriptResources[0]); } else throw "no resources tag"; } catch(const char *errorString) { error = HX_CSTRING("Error reading file ") + String(errorString) + HX_CSTRING(", line ") + String(stream.line) + HX_CSTRING(", char ") + String(stream.pos); } if (!error.__s) try { DBGLOG("Link...\n"); cppia.link(); } catch(const char *errorString) { error = String(errorString); } if (gEnableJit) { #ifdef CPPIA_JIT if (!error.__s) try { DBGLOG("Compile...\n"); cppia.compile(); } catch(const char *errorString) { error = String(errorString); } #endif } if (error.__s) hx::Throw(error); cppia.registerDebugger(); return loadedModule; }