Closure * loadClosure(const char *filename, FILE *f, const StringTabEntry *strings, HashTable *itbls, HashTable *closures) { u4 i; u4 magic = fget_u4(f); assert(magic == CLOSURE_MAGIC); char *clos_name = loadId(f, strings, "."); u4 payloadsize = fget_varuint(f); char *itbl_name = loadId(f, strings, "."); Closure *cl = allocStaticClosure(wordsof(ClosureHeader) + payloadsize); Closure *fwd_ref; InfoTable* info = HashTable_lookup(itbls, itbl_name); LC_ASSERT(info != NULL && info->type != INVALID_OBJECT); // Fill in closure payload. May create forward references to // the current closure. setInfo(cl, info); xfree(itbl_name); for (i = 0; i < payloadsize; i++) { LD_DBG_PR(1, "Loading payload for: %s [%d]\n", clos_name, i); u1 dummy; loadLiteral(filename, f, &dummy, &cl->payload[i], strings, itbls, closures); } fwd_ref = HashTable_lookup(closures, clos_name); if (fwd_ref != NULL) { LD_DBG_PR(2, "Fixing closure forward ref: %s, %p -> %p\n", clos_name, fwd_ref, cl); // fixup forward refs void **p, *next; for (p = (void**)fwd_ref->payload[0]; p != NULL; p = next) { next = *p; *p = (void*)cl; } xfree(fwd_ref); HashTable_update(closures, clos_name, cl); // The key has been allocated by whoever installed the first // forward reference. xfree(clos_name); } else { HashTable_insert(closures, clos_name, cl); } return cl; }
// __________________________________________________________________________________________________ void KikiCellText::display () { loadId(); glPushAttrib (GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT); glPushMatrix (); glTranslatef (position[X], position[Y], position[Z]); KMatrix (current_orientation).glMultMatrix(); if (offset) { glTranslatef ((*offset)[X], (*offset)[Y], (*offset)[Z]); } float factor = cell_height/height; glScalef (factor, factor, factor); if (picked) { glPushAttrib (GL_CURRENT_BIT); glDisable (GL_LIGHTING); glColor4f (1.0, 1.0, 1.0, 1.0); glPushMatrix(); glScalef (width, height, 1); kDisplayWireCube (1.0); glPopMatrix(); glEnable (GL_LIGHTING); glPopAttrib(); } KikiText::display(); glPopMatrix(); glPopAttrib(); }
/** Constructor */ GxsCircleLabel::GxsCircleLabel(QWidget *parent) :QLabel(parent), mTimer(NULL), mCount(0) { mTimer = new QTimer(this); mTimer->setSingleShot(true); connect(mTimer, SIGNAL(timeout()), this, SLOT(loadId())); return; }
// __________________________________________________________________________________________________ void KikiObject::preDisplay () { loadId(); glPushAttrib (GL_CURRENT_BIT | GL_ENABLE_BIT); glPushMatrix (); current_position.glTranslate(); if (picked) { glDisable (GL_LIGHTING); glColor4f (1.0, 1.0, 1.0, 1.0); kDisplayWireCube (1.0); glEnable (GL_LIGHTING); } }
// -------------------------------------------------------------------------------------------------------- void KWidget::render () { loadId(); if (flags[KDL_WIDGET_FLAG_FRAMED]) { KSize ws = getSize(); if (getBGColor()) { glPushAttrib (GL_CURRENT_BIT | GL_POLYGON_BIT); glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); getBGColor()->glColor(); glRecti (0, -ws.h, ws.w, 0); glPopAttrib(); } glRecti(0, -ws.h, ws.w, 0); } }
WalkOptimisationProvider::WalkOptimisationProvider(Behaviour* manager) : BehaviourFSMProvider(manager) { #if DEBUG_BEHAVIOUR_VERBOSITY > 1 debug << "WalkOptimisationProvider::WalkOptimisationProvider" << endl; #endif loadId(); loadWayPoints(); loadParameters("ALWalkStart"); initOptimiser(); if (not m_optimiser) m_log.open((DATA_DIR + "/Optimisation/" + m_parameters.getName() + ".log").c_str(), fstream::out); else m_log.open((DATA_DIR + "/Optimisation/" + m_id + "Log.log").c_str(), fstream::out | fstream::app); m_generate = new GenerateWalkParametersState(this); m_evaluate = new EvaluateWalkParametersState(this); m_paused = new PausedWalkOptimisationState(this); m_state = m_paused; m_iteration_count = 0; m_fall_count = 0; }
void ESM::CellRef::load (ESMReader& esm, bool wideRefNum) { loadId(esm, wideRefNum); loadData(esm); }
void loadLiteral(const char *filename, FILE *f, u1 *littype /*out*/, Word *literal /*out*/, const StringTabEntry *strings, HashTable *itbls, HashTable *closures) { u4 i; *littype = fget_u1(f); switch (*littype) { case LIT_INT: *literal = (Word)fget_varsint(f); break; case LIT_CHAR: *literal = (Word)fget_varuint(f); break; case LIT_WORD: *literal = (Word)fget_varuint(f); break; case LIT_FLOAT: *literal = (Word)fget_u4(f); break; case LIT_STRING: i = fget_varuint(f); *literal = (Word)strings[i].str; break; case LIT_CLOSURE: { char *clname = loadId(f, strings, "."); Closure *cl = HashTable_lookup(closures, clname); if (cl == NULL) { // 1st forward ref, create the link cl = xmalloc(sizeof(ClosureHeader) + sizeof(Word)); setInfo(cl, NULL); cl->payload[0] = (Word)literal; *literal = (Word)NULL; LD_DBG_PR(2, "Creating forward reference %p for `%s', %p\n", cl, clname, literal); HashTable_insert(closures, clname, cl); } else if (getInfo(cl) == NULL) { // forward ref (not the first), insert into linked list LD_DBG_PR(2, "Linking forward reference %p (%s, target: %p)\n", cl, clname, literal); *literal = (Word)cl->payload[0]; cl->payload[0] = (Word)literal; xfree(clname); } else { *literal = (Word)cl; xfree(clname); } } break; case LIT_INFO: { char *infoname = loadId(f, strings, "."); InfoTable *info = HashTable_lookup(itbls, infoname); FwdRefInfoTable *info2; if (info == NULL) { // 1st forward ref info2 = xmalloc(sizeof(FwdRefInfoTable)); info2->i.type = INVALID_OBJECT; info2->next = (void**)literal; *literal = (Word)NULL; HashTable_insert(itbls, infoname, info2); } else if (info->type == INVALID_OBJECT) { // subsequent forward ref info2 = (FwdRefInfoTable*)info; *literal = (Word)info2->next; info2->next = (void**)literal; xfree(infoname); } else { *literal = (Word)info; xfree(infoname); } } break; default: fprintf(stderr, "ERROR: Unknown literal type (%d) " "when loading file: %s\n", *littype, filename); exit(1); } }
InfoTable * loadInfoTable(const char *filename, FILE *f, const StringTabEntry *strings, HashTable *itbls, HashTable *closures) { u4 magic = fget_u4(f); assert(magic == INFO_MAGIC); char *itbl_name = loadId(f, strings, "."); u2 cl_type = fget_varuint(f); InfoTable *new_itbl = NULL; FwdRefInfoTable *old_itbl = HashTable_lookup(itbls, itbl_name); if (old_itbl && old_itbl->i.type != INVALID_OBJECT) { fprintf(stderr, "ERROR: Duplicate info table: %s\n", itbl_name); exit(1); } switch (cl_type) { case CONSTR: // A statically allocated constructor { ConInfoTable *info = allocInfoTable(wordsof(ConInfoTable)); info->i.type = cl_type; info->i.tagOrBitmap = fget_varuint(f); // tag Word sz = fget_varuint(f); assert(sz <= 32); info->i.size = sz; info->i.layout.bitmap = sz > 0 ? fget_u4(f) : 0; // info->i.layout.payload.ptrs = fget_varuint(f); // info->i.layout.payload.nptrs = fget_varuint(f); info->name = loadId(f, strings, "."); new_itbl = (InfoTable*)info; } break; case FUN: { FuncInfoTable *info = allocInfoTable(wordsof(FuncInfoTable)); info->i.type = cl_type; info->i.tagOrBitmap = 0; // TODO: anything useful to put in here? Word sz = fget_varuint(f); assert(sz <= 32); info->i.size = sz; info->i.layout.bitmap = sz > 0 ? fget_u4(f) : 0; info->name = loadId(f, strings, "."); loadCode(filename, f, &info->code, strings, itbls, closures); new_itbl = (InfoTable*)info; } break; case CAF: case THUNK: { ThunkInfoTable *info = allocInfoTable(wordsof(ThunkInfoTable)); info->i.type = cl_type; info->i.tagOrBitmap = 0; // TODO: anything useful to put in here? Word sz = fget_varuint(f); assert(sz <= 32); info->i.size = sz; info->i.layout.bitmap = sz > 0 ? fget_u4(f) : 0; info->name = loadId(f, strings, "."); loadCode(filename, f, &info->code, strings, itbls, closures); new_itbl = (InfoTable*)info; } break; default: fprintf(stderr, "ERROR: Unknown info table type (%d)", cl_type); exit(1); } // new_itbl is the new info table. There may have been forward // references (even during loading the code for this info table). if (old_itbl != NULL) { LD_DBG_PR(1, "Fixing itable forward reference for: %s, %p\n", itbl_name, new_itbl); void **p, *next; LC_ASSERT(old_itbl->i.type == INVALID_OBJECT); for (p = old_itbl->next; p != NULL; p = next) { next = *p; *p = (void*)new_itbl; } // TODO: fixup forward refs xfree(old_itbl); HashTable_update(itbls, itbl_name, new_itbl); xfree(itbl_name); } else { HashTable_insert(itbls, itbl_name, new_itbl); } return new_itbl; }
// Load the module and Module * loadModuleHeader(FILE *f, const char *filename) { Module *mdl; char magic[5]; u2 major, minor; u4 flags; u4 secmagic; u4 i; LC_ASSERT(f != NULL); fread(magic, 4, 1, f); magic[4] = '\0'; if (strcmp(magic, "KHCB") != 0) { fprintf(stderr, "ERROR: Module '%s' is not a bytecode file. %s\n", filename, magic); exit(1); } mdl = xmalloc(sizeof(Module)); major = fget_u2(f); minor = fget_u2(f); if (major != VERSION_MAJOR || minor != VERSION_MINOR) { fprintf(stderr, "ERROR: Module '%s' version mismatch. Version: %d.%d, Expected: %d.%d\n", filename, major, minor, VERSION_MAJOR, VERSION_MINOR); exit(1); } flags = fget_u4(f); mdl->numStrings = fget_u4(f); mdl->numInfoTables = fget_u4(f); mdl->numClosures = fget_u4(f); mdl->numImports = fget_u4(f); //printf("strings = %d, itbls = %d, closures = %d\n", // mdl->numStrings, mdl->numInfoTables, mdl->numClosures); // String table starts with a 4 byte magic. secmagic = fget_u4(f); assert(secmagic == STR_SEC_HDR_MAGIC); mdl->strings = xmalloc(sizeof(StringTabEntry) * mdl->numStrings); for (i = 0; i < mdl->numStrings; i++) { loadStringTabEntry(f, &mdl->strings[i]); } //printStringTable(mdl->strings, mdl->numStrings); mdl->name = loadId(f, mdl->strings, "."); // printf("mdl name = %s\n", mdl->name); mdl->imports = xmalloc(sizeof(*mdl->imports) * mdl->numImports); for (i = 0; i < mdl->numImports; i++) { mdl->imports[i] = loadId(f, mdl->strings, "."); // printf("import: %s\n", mdl->imports[i]); } return mdl; }