void parseFile( char *filename ) { FILE *fp; int inp, index = 0; char word[MAX_WORD_LEN+1]; int first = 1; fp = fopen(filename, "r"); while (!feof(fp)) { inp = fgetc(fp); if (inp == EOF) { if (index > 0) { word[index++] = 0; loadWord(word, LAST_WORD); index = 0; } } else if (((char)inp == 0x0d) || ((char)inp == 0x0a) || ((char)inp == ' ')) { if (index > 0) { word[index++] = 0; if (first) { loadWord(word, FIRST_WORD); index = 0; first = 0; } else { loadWord(word, MIDDLE_WORD); index = 0; } } } else if (((char)inp == '.') || ((char)inp == '?')) { word[index++] = 0; loadWord(word, MIDDLE_WORD); loadWord(word, LAST_WORD); index = 0; first = 1; } else { if (((char)inp != 0x0a) && ((char)inp != ',')) { word[index++] = (char)inp; } } } fclose(fp); }
/* Compiler */ void test_compiler(char *expr, long eval) { initialize(); compiler(expr,TESTFILE); loadFile(TESTFILE); run(); assert(loadWord(SP) == eval); }
/* SW */ void test_sw() { word location1 = 0x00001000; word location2 = 0x00001004; word w = 0xFFFFFFFF; T0 = w; T1 = location1; test_execute(create_itype_hex(0x0000, I_T0, I_T1, OC_SW)); assert(loadWord(location1) == w); w =0x12345678; T0 = w; T1 = location2; test_execute(create_itype_hex(0xFFFC, I_T0, I_T1, OC_SW)); assert(loadWord(location1) == w); }
static status loadDate(Date d, IOSTREAM *fd, ClassDef def) { if ( restoreVersion != 2 ) TRY(loadSlotsObject(d, fd, def)); d->unix_date = loadWord(fd); succeed; }
// // findWord() // Search for a character string using a binary search. // Returns the index of the word on success, or -1 on // failure. // bool WordsFile::findWord(const char* str, int& index) throw(AiksaurusException) { // Create copy of str, so that we can turn spaces into colons. // We only need to copy the first s_wordlen + 1 bytes to ensure // that we will get a correct match. char* s = new char[maxWordLength() + 2]; s[maxWordLength() + 1] = 0; for(int i = 0; i < (maxWordLength() + 2); ++i) { s[i] = str[i]; if (!str[i]) break; } // In the datafile, spaces are stored as colons. Convert spaces // on search word into colons so that we can do a simple case // insensitive compare. strReplace(s, ASCII_SPACE, ASCII_COLON); // Initialize low/high for classic binary search. int low = 0, high = getSize() - 1; index = -1; // Perform our binary search. while(low <= high) { int mid = (high + low) / 2; loadWord(mid); int compare = AsciiCompare(s, d_word); if (compare < 0) high = mid - 1; else if (compare > 0) low = mid + 1; else { index = mid; break; } } delete[] s; bool ret = true; if (index == -1) { index = low; return false; } return ret; }
static status loadStyle(Style s, IOSTREAM *fd, ClassDef def) { loadSlotsObject(s, fd, def); s->attributes = loadWord(fd); if ( s->font == NIL ) /* prior version 10 */ assign(s, font, DEFAULT); if ( s->colour == NIL ) assign(s, colour, DEFAULT); succeed; }
/* Fetch and execute */ void run() { while (doRun) { /* Fetch Instruction*/ word w = loadWord(pc); Instruction *instruction = (Instruction *) &w; pc += 4; /* Execute Instruction*/ operations[instruction->i.opcode].operation(instruction); /* In case you want to watch the machine */ if (verbose) { printInstruction(instruction); } } }
void test_execute(word instr) { word w; Instruction *instruction; /* Store the executable word */ storeWord(instr, pc); /* Fetch the next Instruction */ w = loadWord(pc); instruction = (Instruction *) &w; pc += 4; /* Execute the fetched instruction*/ operations[instruction->i.opcode].operation(instruction); assert(ZERO == 0); }
/* LW */ void mips_lw(Instruction *instruction) { InstructionTypeI i = instruction->i; registers[i.rt] = loadWord(registers[i.rs] + (signed)signExtend(i.immediate)); }
void parseFile( char *filename ) { FILE *fp; int inp, index = 0; char word[MAX_WORD_LEN+1]; int first = 1; fp = fopen(filename, "r"); while (!feof(fp)) { inp = fgetc(fp); if (inp == EOF) { if (index > 0) { /* For the last word, update the matrix accordingly */ word[index++] = 0; loadWord(word, LAST_WORD); index = 0; } } else if (((char)inp == 0x0d) || ((char)inp == 0x0a) || ((char)inp == ' ')) { if (index > 0) { word[index++] = 0; if (first) { /* First word in a sequence */ loadWord(word, FIRST_WORD); index = 0; first = 0; } else { /* Middle word of a sequence */ loadWord(word, MIDDLE_WORD); index = 0; } } } else if (((char)inp == '.') || ((char)inp == '?')) { /* Handle punctuation by ending the current sequence */ word[index++] = 0; loadWord(word, MIDDLE_WORD); loadWord(word, LAST_WORD); index = 0; first = 1; } else { /* Skip white space */ if (((char)inp != 0x0a) && ((char)inp != ',')) { word[index++] = (char)inp; } } } fclose(fp); }