int main(int argc, char* argv[]) { /* Creation of the tree of characters.*/ initClass(); printf("Example 1 :\n"); ptr_example e1=createExample(senator, 1, 3); displayExample(e1); printf("Example 2 :\n"); ptr_example e2=createExample(droid, 5, 2); displayExample(e2); printf("Example 3 :\n"); ptr_example e3=createExample(jedi, 4, 2); displayExample(e3); printf("\nModel initialization...\n\n"); ptr_model model; model=initModel(e1); displayModel(model); printf("Comparison between model and example 2...\n"); comparison(model, e2); displayModel(model); printf("Comparison between model and example 3...\n"); comparison(model, e3); displayModel(model); return 0; }
/** * Evaluates the 2 expressions: equality (a == b), and inequality (a != b), * which have the same operator precedence, by recursively calling the * functions for evaluating expressions with higher precedence. * * @param[out] ret: the integer value the logical and expression evaluates to * * @return: whether at the current location the expression can be evaluated */ bool MacroParser::equalNeq(int64_t *ret) { int64_t term2 = 0; if (comparison(ret)) { for (;;) { if (_scanner.atSymbol(EQ_EQ)) { if (comparison(&term2)) { *ret = *ret == term2; } else { return false; } } else if (_scanner.atSymbol(NOT_EQ)) { if (comparison(&term2)) { *ret = *ret != term2; } else { return false; } } else { return true; } } } return false; }
std::vector<Staff *> TimePointInterface::GetTstampStaves(Measure *measure) { std::vector<Staff *> staves; std::vector<int>::iterator iter; std::vector<int> staffList; if (this->HasStaff()) { staffList = this->GetStaff(); } else if (m_start) { Staff *staff = dynamic_cast<Staff *>(m_start->GetFirstParent(STAFF)); if (staff) staffList.push_back(staff->GetN()); } for (iter = staffList.begin(); iter != staffList.end(); iter++) { AttCommonNComparison comparison(STAFF, *iter); Staff *staff = dynamic_cast<Staff *>(measure->FindChildByAttComparison(&comparison, 1)); if (!staff) { // LogDebug("Staff with @n '%d' not found in measure '%s'", *iter, measure->GetUuid().c_str()); continue; } staves.push_back(staff); } if (staves.empty()) LogDebug("Empty @staff array"); return staves; }
void addSolution(const Permutation& sol) { permutations.push_back(sol); D_ASSERT(sol.size() == orbit_mins.size()); debug_out(3, "SS", "Old orbit_mins:" << orbit_mins); for(int i : range1(sol.size())) { if(sol[i] != i) { int val1 = walkToMinimum(i); int val2 = walkToMinimum(sol[i]); int orbit_min = -1; if(comparison(val1, val2)) orbit_min = val1; else orbit_min = val2; update_orbit_mins(orbit_min, val1); update_orbit_mins(orbit_min, val2); update_orbit_mins(orbit_min, i); update_orbit_mins(orbit_min, sol[i]); } } debug_out(1, "SS", "Solution found"); debug_out(3, "SS", "Sol:" << sol); debug_out(3, "SS", "New orbit_mins:" << orbit_mins); }
void CollationRegressionTest::compareArray(Collator &c, const UChar tests[][CollationRegressionTest::MAX_TOKEN_LEN], int32_t testCount) { int32_t i; Collator::EComparisonResult expectedResult = Collator::EQUAL; for (i = 0; i < testCount; i += 3) { UnicodeString source(tests[i]); UnicodeString comparison(tests[i + 1]); UnicodeString target(tests[i + 2]); if (comparison == "<") { expectedResult = Collator::LESS; } else if (comparison == ">") { expectedResult = Collator::GREATER; } else if (comparison == "=") { expectedResult = Collator::EQUAL; } else { UnicodeString bogus1("Bogus comparison string \""); UnicodeString bogus2("\""); errln(bogus1 + comparison + bogus2); } Collator::EComparisonResult compareResult = c.compare(source, target); CollationKey sourceKey, targetKey; UErrorCode status = U_ZERO_ERROR; c.getCollationKey(source, sourceKey, status); if (U_FAILURE(status)) { errln("Couldn't get collationKey for source"); continue; } c.getCollationKey(target, targetKey, status); if (U_FAILURE(status)) { errln("Couldn't get collationKey for target"); continue; } Collator::EComparisonResult keyResult = sourceKey.compareTo(targetKey); reportCResult( source, target, sourceKey, targetKey, compareResult, keyResult, compareResult, expectedResult ); } }
int main() { int a, b, c; printf("Enter a numbers a, b, c:\n"); scanf("%d%d%d", &a, &b, &c); comparison(a, b, c); return 0; }
int walkToMinimum(int pos) const { while(orbit_mins[pos] != -1) { D_ASSERT(comparison(orbit_mins[pos], pos)); pos = orbit_mins[pos]; } return pos; }
void sort() { for (size_t i = 0; i < data->size(); ++i) { indexes[i] = i; } std::sort(indexes, indexes + this->data->size(), comparison(this->data)); for (size_t i = 0; i < data->size(); ++i) { reverse_indexes[indexes[i]] = i; } }
Json::Value genDetailMinTreeData(const std::vector<T> & reads, uint32_t numThreads) { uint64_t maxSize = 0; readVec::getMaxLength(reads, maxSize); aligner alignerObj(maxSize, gapScoringParameters(5, 1), substituteMatrix(2, -2)); std::unordered_map<std::string, std::unique_ptr<aligner>> aligners; std::mutex alignerLock; return genDetailMinTreeData(reads, alignerObj, aligners, alignerLock, numThreads, comparison(), false, false, false); }
bool Table::AND( expression * ep, string tuple ) { bool lhs = false; bool rhs = false; if ( ep->values[0].ep->func == OP_AND ) lhs = AND ( ep->values[0].ep, tuple ); else if ( ep->values[0].ep->func == OP_OR ) lhs = OR ( ep->values[0].ep, tuple ); else lhs = comparison ( ep->values[0].ep, tuple ); if ( ep->values[1].ep->func == OP_AND ) rhs = AND ( ep->values[1].ep, tuple ); else if ( ep->values[1].ep->func == OP_OR ) rhs = OR ( ep->values[1].ep, tuple ); else rhs = comparison ( ep->values[1].ep, tuple ); return lhs && rhs; }
bool OR( expression * ep, std::string header, std::string tuple ) { bool lhs = false; bool rhs = false; if ( ep->values[0].ep->func == OP_AND ) lhs = AND ( ep->values[0].ep, header, tuple ); else if ( ep->values[0].ep->func == OP_OR ) lhs = OR ( ep->values[0].ep, header, tuple ); else lhs = comparison ( ep->values[0].ep, header, tuple ); if ( ep->values[1].ep->func == OP_AND ) rhs = AND ( ep->values[1].ep, header, tuple ); else if ( ep->values[1].ep->func == OP_OR ) rhs = OR ( ep->values[1].ep, header, tuple ); else rhs = comparison ( ep->values[1].ep, header, tuple ); return lhs || rhs; }
/* START of SETTERS... */ void board::setUserGuessRowCount() { if( rowIsSet ) { if( rowCount > numCols ) { comparison(); } rowCunt++; } }
int main(int argc, char** argv) { std::cerr << "# Args:"; for ( int i = 0; i < argc; ++i ) std::cerr << " " << argv[ i ]; std::cerr << std::endl; if (argc < 3) { std::cerr << "# Usage: " << argv[0] << " resultsFile1 resultsFile2 configsFile" << std::endl; std::cerr << "# Compare line per line resultsFile1 and resultsFile2 with respect to configsFile" << std::endl; return 0; } //////////////////////////////////////////////////////parameters //files std::ifstream f1( argv[1] ); std::ifstream f2( argv[2] ); std::ifstream f3( argv[3] ); ///////////////////////////////////////////////////read and compare unsigned int nEq = 0; //number of lines that match unsigned int nDif1 = 0; //number of lines for which f1 contains 1 but f2 0 unsigned int nDif2 = 0; //number of lines for which f2 contains 1 but f1 0 if ( f1 && f2 && f3) { std::string l1, l2, l3; // current lines of file1 and file2 and file3 while ( std::getline( f1, l1 ) && std::getline( f2, l2 ) ) { unsigned int nDifs = nDif1; comparison(l1, l2, nEq, nDif1, nDif2); std::getline( f3, l3); if (nDif1 != nDifs) std::cout << l3 << std::endl; } } else { std::cerr << "# Error. files not open" << std::endl; return 0; } unsigned int n = nEq + nDif1 + nDif2; std::cerr << "# equa: " << nEq << " / " << n << std::endl; std::cerr << "# diff: " << (nDif1+nDif2) << " / " << n << std::endl; std::cerr << "# true in " << argv[1] << " but false in " << argv[2] << ": " << nDif1 << std::endl; std::cerr << "# true in " << argv[2] << " but false in " << argv[1] << ": " << nDif2 << std::endl; return 1; }
/*In return founded information in type Row_t */ Row_t search(Row_t mpn_table[], int actual_size, const triplet_t triplet_to_search) { int i; Row_t res; /*return value*/ res = (Row_t){{0,0,0},0,0,0}; /*Initializing to zero*/ /*Searching...*/ for(i=0;i<actual_size;++i) { if(comparison(mpn_table[i].triple,triplet_to_search) == 1) res = mpn_table[i]; } return res; }
void TestWriteAverageRadialPdeSolution() throw(Exception) { EXIT_IF_PARALLEL; // Create a cell population using a circular mesh HoneycombMeshGenerator generator(5, 5, 0); MutableMesh<2,2>* p_mesh = generator.GetMesh(); std::vector<CellPtr> cells; CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 2> cells_generator; cells_generator.GenerateBasic(cells, p_mesh->GetNumNodes()); MeshBasedCellPopulation<2> cell_population(*p_mesh, cells); // Put random data on the cells for (AbstractCellPopulation<2>::Iterator cell_iter = cell_population.Begin(); cell_iter != cell_population.End(); ++cell_iter) { cell_iter->GetCellData()->SetItem("averaged quantity", RandomNumberGenerator::Instance()->ranf()); } // Create a PDE handler object using this cell population CellBasedPdeHandler<2> pde_handler(&cell_population); pde_handler.SetWriteAverageRadialPdeSolution("averaged quantity", 2); // Open result file ourselves OutputFileHandler output_file_handler("TestWriteAverageRadialPdeSolution", false); pde_handler.mpAverageRadialPdeSolutionResultsFile = output_file_handler.OpenOutputFile("radial_dist.dat"); // Write average radial PDE solution to file pde_handler.WriteAverageRadialPdeSolution(SimulationTime::Instance()->GetTime()); // Test that this is correct by comparing with an existing results file std::string results_dir = output_file_handler.GetOutputDirectoryFullPath(); NumericFileComparison comparison(results_dir + "/radial_dist.dat", "cell_based/test/data/TestCellBasedPdeHandler/radial_dist.dat"); TS_ASSERT(comparison.CompareFiles()); // Close result file ourselves pde_handler.mpAverageRadialPdeSolutionResultsFile->close(); }
/* preform a bubble sort on the linked list */ void sort_board_list( BOOL (*comparison)(struct stBoardInfo *a, struct stBoardInfo *b) ) { struct stBoardInfo *a = NULL; struct stBoardInfo *b = NULL; struct stBoardInfo *c = NULL; struct stBoardInfo *e = NULL; struct stBoardInfo *tmp = NULL; /* // the `c' node precedes the `a' and `e' node // pointing up the node to which the comparisons // are being made. */ while(e != boards_present_head->Next) { c = a = boards_present_head; b = a->Next; while(a != e) { if(comparison(a, b)) { if(a == boards_present_head) { tmp = b->Next; b->Next = a; a->Next = tmp; boards_present_head = b; c = b; } else { tmp = b->Next; b->Next = a; a->Next = tmp; c->Next = b; c = b; } } else { c = a; a = a->Next; } b = a->Next; if(b == e) e = a; } } }
inline bool more_than(ST1 str1,ST2 str2) { return comparison(str1,str2)==1; }
void TestSolvePdeAndWriteResultsToFileAndGetPDESolutionAtPointWithoutCoarsePdeMeshDirichlet() throw(Exception) { EXIT_IF_PARALLEL; // Set up SimulationTime SimulationTime::Instance()->SetEndTimeAndNumberOfTimeSteps(0.5, 6); // Set up mesh MutableMesh<2,2> mesh; TrianglesMeshReader<2,2> mesh_reader("mesh/test/data/disk_522_elements"); mesh.ConstructFromMeshReader(mesh_reader); // Set up cells std::vector<CellPtr> cells; CellsGenerator<FixedDurationGenerationBasedCellCycleModel, 2> cells_generator; cells_generator.GenerateBasic(cells, mesh.GetNumNodes()); // Set up cell population MeshBasedCellPopulation<2> cell_population(mesh, cells); // Create a PDE handler object using this cell population CellBasedPdeHandler<2> pde_handler(&cell_population); // Create a single PDE and pass to the handler SimplePdeForTesting pde; ConstBoundaryCondition<2> bc(1.0); PdeAndBoundaryConditions<2> pde_and_bc(&pde, &bc, false); pde_and_bc.SetDependentVariableName("variable"); // For coverage, provide an initial guess for the solution std::vector<double> data(mesh.GetNumNodes()); for (unsigned i=0; i<mesh.GetNumNodes(); i++) { data[i] = 1.0; } Vec vector = PetscTools::CreateVec(data); pde_and_bc.SetSolution(vector); pde_handler.AddPdeAndBc(&pde_and_bc); // Open result file ourselves OutputFileHandler output_file_handler("TestWritePdeSolution", false); pde_handler.mpVizPdeSolutionResultsFile = output_file_handler.OpenOutputFile("results.vizpdesolution"); // Solve PDE (set sampling timestep multiple to be large doesn't do anything as always output on 1st timestep) pde_handler.SolvePdeAndWriteResultsToFile(10); // Close result file ourselves pde_handler.mpVizPdeSolutionResultsFile->close(); // Test that this is correct by comparing with an existing results file std::string results_dir = output_file_handler.GetOutputDirectoryFullPath(); NumericFileComparison comparison(results_dir + "results.vizpdesolution", "cell_based/test/data/TestCellBasedPdeHandler/results.vizpdesolution"); TS_ASSERT(comparison.CompareFiles()); // Check the correct solution was obtained for (AbstractCellPopulation<2>::Iterator cell_iter = cell_population.Begin(); cell_iter != cell_population.End(); ++cell_iter) { double radius = norm_2(cell_population.GetLocationOfCellCentre(*cell_iter)); double analytic_solution = 1.0 - 0.25*(1 - pow(radius,2.0)); // Test that PDE solver is working correctly TS_ASSERT_DELTA(cell_iter->GetCellData()->GetItem("variable"), analytic_solution, 0.02); } // Now check the GetPdeSolutionAtPoint method // First loop over nodes and check it works // Check the correct solution was obtained for (AbstractCellPopulation<2>::Iterator cell_iter = cell_population.Begin(); cell_iter != cell_population.End(); ++cell_iter) { double cell_data_solution(cell_iter->GetCellData()->GetItem("variable")); c_vector<double,2> cell_location = cell_population.GetLocationOfCellCentre(*cell_iter); TS_ASSERT_DELTA(pde_handler.GetPdeSolutionAtPoint(cell_location,"variable"), cell_data_solution, 1e-6); } // Now choose some other points // Centre c_vector<double,2> point; point(0) = 0.0; point(1) = 0.0; TS_ASSERT_DELTA(pde_handler.GetPdeSolutionAtPoint(point,"variable"), 0.75, 0.01); // Cover exception TS_ASSERT_THROWS_CONTAINS(pde_handler.GetPdeSolutionAtPoint(point, "not_a_var"), "There is no PDE with that variable."); // Random point point(0) = 0.5; point(1) = 0.5; TS_ASSERT_DELTA(pde_handler.GetPdeSolutionAtPoint(point,"variable"), 1.0 - (1.0-2.0*0.5*0.5)/4.0, 0.01); // Point on the boundary point(0) = 1.0; point(1) = 0.0; TS_ASSERT_DELTA(pde_handler.GetPdeSolutionAtPoint(point,"variable"), 1.0, 1e-6); }
inline bool equals(ST1 str1,ST2 str2) { return comparison(str1,str2)==0; }
/* ** Execute the given opcode, until a RET. Parameters are between ** [stack+base,top). Returns n such that the the results are between ** [stack+n,top). */ static StkId lua_execute (Byte *pc, StkId base) { void* table[] = { &&pushnil, &&push0, &&push1, &&push2, &&pushbyte, &&pushword, &&pushfloat, &&pushstring, &&pushfunction, &&pushlocal0, &&pushlocal1, &&pushlocal2, &&pushlocal3, &&pushlocal4, &&pushlocal5, &&pushlocal6, &&pushlocal7, &&pushlocal8, &&pushlocal9, &&pushlocal, &&pushglobal, &&pushindexed, &&pushself, &&storelocal0, &&storelocal1, &&storelocal2, &&storelocal3, &&storelocal4, &&storelocal5, &&storelocal6, &&storelocal7, &&storelocal8, &&storelocal9, &&storelocal, &&storeglobal, &&storeindexed0, &&storeindexed, &&storelist0, &&storelist, &&storerecord, &&adjust0, &&adjust, &&createarray, &&eqop, &<op, &&leop, &>op, &&geop, &&addop, &&subop, &&multop, &&divop, &&powop, &&concop, &&minusop, &¬op, &&ontjmp, &&onfjmp, &&jmp, &&upjmp, &&iffjmp, &&iffupjmp, &&pop, &&callfunc, &&retcode0, &&retcode, &&setline, &&varargs }; if (lua_callhook) callHook (base, LUA_T_MARK, 0); goto *table[*pc++]; pushnil: tag(top) = LUA_T_NIL; incr_top; goto *table[*pc++]; push0: push1: push2: tag(top) = LUA_T_NUMBER; nvalue(top) = ((OpCode)*(pc-1))-PUSH0; incr_top; goto *table[*pc++]; pushbyte: tag(top) = LUA_T_NUMBER; nvalue(top) = *pc++; incr_top; goto *table[*pc++]; pushword: { Word w; get_word(w,pc); tag(top) = LUA_T_NUMBER; nvalue(top) = w; incr_top; } goto *table[*pc++]; pushfloat: { real num; get_float(num,pc); tag(top) = LUA_T_NUMBER; nvalue(top) = num; incr_top; } goto *table[*pc++]; pushstring: { Word w; get_word(w,pc); tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; incr_top; } goto *table[*pc++]; pushfunction: { TFunc *f; get_code(f,pc); luaI_insertfunction(f); /* may take part in GC */ top->tag = LUA_T_FUNCTION; top->value.tf = f; incr_top; } goto *table[*pc++]; pushlocal0: pushlocal1: pushlocal2: pushlocal3: pushlocal4: pushlocal5: pushlocal6: pushlocal7: pushlocal8: pushlocal9: *top = *((stack+base) + (int)(((OpCode)*(pc-1))-PUSHLOCAL0)); incr_top; goto *table[*pc++]; pushlocal: *top = *((stack+base) + (*pc++)); incr_top; goto *table[*pc++]; pushglobal: { Word w; get_word(w,pc); getglobal(w); } goto *table[*pc++]; pushindexed: pushsubscript(); goto *table[*pc++]; pushself: { Object receiver = *(top-1); Word w; get_word(w,pc); tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; incr_top; pushsubscript(); *top = receiver; incr_top; goto *table[*pc++]; } storelocal0: storelocal1: storelocal2: storelocal3: storelocal4: storelocal5: storelocal6: storelocal7: storelocal8: storelocal9: *((stack+base) + (int)(((OpCode)*(pc-1))-STORELOCAL0)) = *(--top); goto *table[*pc++]; storelocal: *((stack+base) + (*pc++)) = *(--top); goto *table[*pc++]; storeglobal: { Word w; get_word(w,pc); s_object(w) = *(--top); } goto *table[*pc++]; storeindexed0: storesubscript(); goto *table[*pc++]; storeindexed: { int n = *pc++; if (tag(top-3-n) != LUA_T_ARRAY) { lua_checkstack(top+2); *(top+1) = *(top-1); *(top) = *(top-2-n); *(top-1) = *(top-3-n); top += 2; callFB(FB_SETTABLE); } else { Object *h = lua_hashdefine (avalue(top-3-n), top-2-n); *h = *(top-1); top--; } } goto *table[*pc++]; storelist0: storelist: { int m, n; Object *arr; if (((OpCode)*(pc-1)) == STORELIST0) m = 0; else m = *(pc++) * FIELDS_PER_FLUSH; n = *(pc++); arr = top-n-1; while (n) { tag(top) = LUA_T_NUMBER; nvalue(top) = n+m; *(lua_hashdefine (avalue(arr), top)) = *(top-1); top--; n--; } } goto *table[*pc++]; storerecord: { int n = *(pc++); Object *arr = top-n-1; while (n) { Word w; get_word(w,pc); tag(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; *(lua_hashdefine (avalue(arr), top)) = *(top-1); top--; n--; } } goto *table[*pc++]; adjust0: adjust_top(base); goto *table[*pc++]; adjust: adjust_top(base + *(pc++)); goto *table[*pc++]; varargs: adjust_varargs(base + *(pc++)); goto *table[*pc++]; createarray: { Word size; get_word(size,pc); avalue(top) = lua_createarray(size); tag(top) = LUA_T_ARRAY; incr_top; } goto *table[*pc++]; eqop: { int res = lua_equalObj(top-2, top-1); --top; tag(top-1) = res ? LUA_T_NUMBER : LUA_T_NIL; nvalue(top-1) = 1; } goto *table[*pc++]; ltop: comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, "lt"); goto *table[*pc++]; leop: comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, "le"); goto *table[*pc++]; gtop: comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, "gt"); goto *table[*pc++]; geop: comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, "ge"); goto *table[*pc++]; addop: { Object *l = top-2; Object *r = top-1; if (tonumber(r) || tonumber(l)) call_arith("add"); else { nvalue(l) += nvalue(r); --top; } } goto *table[*pc++]; subop: { Object *l = top-2; Object *r = top-1; if (tonumber(r) || tonumber(l)) call_arith("sub"); else { nvalue(l) -= nvalue(r); --top; } } goto *table[*pc++]; multop: { Object *l = top-2; Object *r = top-1; if (tonumber(r) || tonumber(l)) call_arith("mul"); else { nvalue(l) *= nvalue(r); --top; } } goto *table[*pc++]; divop: { Object *l = top-2; Object *r = top-1; if (tonumber(r) || tonumber(l)) call_arith("div"); else { nvalue(l) /= nvalue(r); --top; } } goto *table[*pc++]; powop: call_arith("pow"); goto *table[*pc++]; concop: { Object *l = top-2; Object *r = top-1; if (tostring(r) || tostring(l)) callFB(FB_CONCAT); else { tsvalue(l) = lua_createstring (lua_strconc(svalue(l),svalue(r))); --top; } } goto *table[*pc++]; minusop: if (tonumber(top-1)) { tag(top) = LUA_T_NIL; incr_top; call_arith("unm"); } else nvalue(top-1) = - nvalue(top-1); goto *table[*pc++]; notop: tag(top-1) = (tag(top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL; nvalue(top-1) = 1; goto *table[*pc++]; ontjmp: { Word w; get_word(w,pc); if (tag(top-1) != LUA_T_NIL) pc += w; } goto *table[*pc++]; onfjmp: { Word w; get_word(w,pc); if (tag(top-1) == LUA_T_NIL) pc += w; } goto *table[*pc++]; jmp: { Word w; get_word(w,pc); pc += w; } goto *table[*pc++]; upjmp: { Word w; get_word(w,pc); pc -= w; } goto *table[*pc++]; iffjmp: { Word w; get_word(w,pc); top--; if (tag(top) == LUA_T_NIL) pc += w; } goto *table[*pc++]; iffupjmp: { Word w; get_word(w,pc); top--; if (tag(top) == LUA_T_NIL) pc -= w; } goto *table[*pc++]; pop: --top; goto *table[*pc++]; callfunc: { int nParams = *(pc++); int nResults = *(pc++); StkId newBase = (top-stack)-nParams; do_call(newBase, nResults); } goto *table[*pc++]; retcode0: retcode: if (lua_callhook) callHook (base, LUA_T_MARK, 1); return (base + ((((OpCode)*(pc-1))==RETCODE0) ? 0 : *pc)); setline: { Word line; get_word(line,pc); if ((stack+base-1)->tag != LUA_T_LINE) { /* open space for LINE value */ open_stack((top-stack)-base); base++; (stack+base-1)->tag = LUA_T_LINE; } (stack+base-1)->value.i = line; if (lua_linehook) lineHook (line); goto *table[*pc++]; } lua_error ("internal error - opcode doesn't match"); }
/* ** Execute the given opcode, until a RET. Parameters are between ** [stack+base,top). Returns n such that the the results are between ** [stack+n,top). */ static StkId lua_execute (Byte *pc, StkId base) { if (lua_callhook) callHook (base, LUA_T_MARK, 0); while (1) { OpCode opcode; switch (opcode = (OpCode)*pc++) { case PUSHNIL: ttype(top) = LUA_T_NIL; incr_top; break; case PUSH0: case PUSH1: case PUSH2: ttype(top) = LUA_T_NUMBER; nvalue(top) = opcode-PUSH0; incr_top; break; case PUSHBYTE: ttype(top) = LUA_T_NUMBER; nvalue(top) = *pc++; incr_top; break; case PUSHWORD: { Word w; get_word(w,pc); ttype(top) = LUA_T_NUMBER; nvalue(top) = w; incr_top; } break; case PUSHFLOAT: { real num; get_float(num,pc); ttype(top) = LUA_T_NUMBER; nvalue(top) = num; incr_top; } break; case PUSHSTRING: { Word w; get_word(w,pc); ttype(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; incr_top; } break; case PUSHFUNCTION: { TFunc *f; get_code(f,pc); luaI_insertfunction(f); /* may take part in GC */ top->ttype = LUA_T_FUNCTION; top->value.tf = f; incr_top; } break; case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: case PUSHLOCAL3: case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7: case PUSHLOCAL8: case PUSHLOCAL9: *top = *((stack+base) + (int)(opcode-PUSHLOCAL0)); incr_top; break; case PUSHLOCAL: *top = *((stack+base) + (*pc++)); incr_top; break; case PUSHGLOBAL: { Word w; get_word(w,pc); getglobal(w); } break; case PUSHINDEXED: pushsubscript(); break; case PUSHSELF: { TObject receiver = *(top-1); Word w; get_word(w,pc); ttype(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; incr_top; pushsubscript(); *top = receiver; incr_top; break; } case STORELOCAL0: case STORELOCAL1: case STORELOCAL2: case STORELOCAL3: case STORELOCAL4: case STORELOCAL5: case STORELOCAL6: case STORELOCAL7: case STORELOCAL8: case STORELOCAL9: *((stack+base) + (int)(opcode-STORELOCAL0)) = *(--top); break; case STORELOCAL: *((stack+base) + (*pc++)) = *(--top); break; case STOREGLOBAL: { Word w; get_word(w,pc); setglobal(w); } break; case STOREINDEXED0: storesubscript(top-3, 1); break; case STOREINDEXED: { int n = *pc++; storesubscript(top-3-n, 2); break; } case STORELIST0: case STORELIST: { int m, n; TObject *arr; if (opcode == STORELIST0) m = 0; else m = *(pc++) * FIELDS_PER_FLUSH; n = *(pc++); arr = top-n-1; while (n) { ttype(top) = LUA_T_NUMBER; nvalue(top) = n+m; *(lua_hashdefine (avalue(arr), top)) = *(top-1); top--; n--; } } break; case STORERECORD: /* opcode obsolete: supersed by STOREMAP */ { int n = *(pc++); TObject *arr = top-n-1; while (n) { Word w; get_word(w,pc); ttype(top) = LUA_T_STRING; tsvalue(top) = lua_constant[w]; *(lua_hashdefine (avalue(arr), top)) = *(top-1); top--; n--; } } break; case STOREMAP: { int n = *(pc++); TObject *arr = top-(2*n)-1; while (n--) { *(lua_hashdefine (avalue(arr), top-2)) = *(top-1); top-=2; } } break; case ADJUST0: adjust_top(base); break; case ADJUST: { StkId newtop = base + *(pc++); adjust_top(newtop); break; } case VARARGS: adjust_varargs(base + *(pc++)); break; case CREATEARRAY: { Word size; get_word(size,pc); avalue(top) = lua_createarray(size); ttype(top) = LUA_T_ARRAY; incr_top; } break; case EQOP: { int res = lua_equalObj(top-2, top-1); --top; ttype(top-1) = res ? LUA_T_NUMBER : LUA_T_NIL; nvalue(top-1) = 1; } break; case LTOP: comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, IM_LT); break; case LEOP: comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, IM_LE); break; case GTOP: comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, IM_GT); break; case GEOP: comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, IM_GE); break; case ADDOP: { TObject *l = top-2; TObject *r = top-1; if (tonumber(r) || tonumber(l)) call_arith(IM_ADD); else { nvalue(l) += nvalue(r); --top; } } break; case SUBOP: { TObject *l = top-2; TObject *r = top-1; if (tonumber(r) || tonumber(l)) call_arith(IM_SUB); else { nvalue(l) -= nvalue(r); --top; } } break; case MULTOP: { TObject *l = top-2; TObject *r = top-1; if (tonumber(r) || tonumber(l)) call_arith(IM_MUL); else { nvalue(l) *= nvalue(r); --top; } } break; case DIVOP: { TObject *l = top-2; TObject *r = top-1; if (tonumber(r) || tonumber(l)) call_arith(IM_DIV); else { nvalue(l) /= nvalue(r); --top; } } break; case POWOP: call_arith(IM_POW); break; case CONCOP: { TObject *l = top-2; TObject *r = top-1; if (tostring(l) || tostring(r)) call_binTM(IM_CONCAT, "unexpected type for concatenation"); else { tsvalue(l) = lua_createstring(lua_strconc(svalue(l),svalue(r))); --top; } } break; case MINUSOP: if (tonumber(top-1)) { ttype(top) = LUA_T_NIL; incr_top; call_arith(IM_UNM); } else nvalue(top-1) = - nvalue(top-1); break; case NOTOP: ttype(top-1) = (ttype(top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL; nvalue(top-1) = 1; break; case ONTJMP: { Word w; get_word(w,pc); if (ttype(top-1) != LUA_T_NIL) pc += w; } break; case ONFJMP: { Word w; get_word(w,pc); if (ttype(top-1) == LUA_T_NIL) pc += w; } break; case JMP: { Word w; get_word(w,pc); pc += w; } break; case UPJMP: { Word w; get_word(w,pc); pc -= w; } break; case IFFJMP: { Word w; get_word(w,pc); top--; if (ttype(top) == LUA_T_NIL) pc += w; } break; case IFFUPJMP: { Word w; get_word(w,pc); top--; if (ttype(top) == LUA_T_NIL) pc -= w; } break; case POP: --top; break; case CALLFUNC: { int nParams = *(pc++); int nResults = *(pc++); StkId newBase = (top-stack)-nParams; do_call(newBase, nResults); } break; case RETCODE0: case RETCODE: if (lua_callhook) callHook (base, LUA_T_MARK, 1); return (base + ((opcode==RETCODE0) ? 0 : *pc)); case SETLINE: { Word line; get_word(line,pc); if ((stack+base-1)->ttype != LUA_T_LINE) { /* open space for LINE value */ open_stack((top-stack)-base); base++; (stack+base-1)->ttype = LUA_T_LINE; } (stack+base-1)->value.i = line; if (lua_linehook) lineHook (line); break; } default: lua_error ("internal error - opcode doesn't match"); } } }
/** compare string with standard terms *******************************************************************************/ template<class T> inline bool comparison(char const* str, T const&) { return comparison(str, std::strlen(str), T()); }
inline bool less_than(ST1 str1,ST2 str2) { return comparison(str1,str2)==-1; }
//============================================================================= // Standard constructor, initializes variables //============================================================================= void makeplots(TString runmode = "d", TString drawopt = "norm") { gROOT->SetBatch(kTRUE); cout<<endl<<"If you want to use custom parameters, option 'b' for branch, 'c' for cuts,"; cout<<", 'o' to specify the output, or 'f' to select the files and trees to include."<<endl; cout<<"Option 'C' saves canvases as .C files."<<endl; cout<<"The second parameter is the draw option. 'norm' by default."<<endl<<endl; cout<<"This program handles a specified number of variations and generates plots from the files corresponding to these."; cout<<" E.g., year, decay, and filetype would plot stuff from nYears*nDecays*nFileTypes files, labeled accordingly."; cout<<" This is in addition to however many branches and cuts you would like to perform."<<endl<<endl; TString placeholder;//this is to avoid adding strings in functions; assign right before use TString placeholder2; TString response;//this is for user input; assign right before use //default parameters TString outputlocation="./"; TString filename="plots.pdf"; int nFiles=8; vector<TFile*> f(nFiles); TString tuplelocation = "/afs/cern.ch/work/m/mwilkins/b_b-bar_cross-section/"; placeholder = tuplelocation+"Strp20r1_SL_D0andDp_MD.root"; f[0] = TFile::Open(placeholder);//2011 data B-D0 placeholder = tuplelocation+"Strp20r1_SL_D0andDp_MD.root"; f[1] = TFile::Open(placeholder);//2011 data B0D- placeholder = tuplelocation+"Bu_D0Xmunu_cocktail_12873441_MC2011_S20r1_noPID_Tuples.root"; f[2] = TFile::Open(placeholder);//2011 MC B-D0 placeholder = tuplelocation+"Bd_DpXmunu_cocktail_11874401_MC2011_S20r1_noPID_Tuples.root"; f[3] = TFile::Open(placeholder);//2011 MC B0D- placeholder = tuplelocation+"B2DMuNuX_tuples_05082015.root"; f[4] = TFile::Open(placeholder);//2015 data B-D0 placeholder = tuplelocation+"B2DMuNuX_tuples_05082015.root"; f[5] = TFile::Open(placeholder);//2015 data B0D- placeholder = tuplelocation+"Bu_D0Xmunu_cocktail_12873441_MC2015_S22_noPID_Tuples.root"; f[6] = TFile::Open(placeholder);//2015 MC B-D0 placeholder = tuplelocation+"Bd_DpXmunu_cocktail_11874401_MC2015_S22_noPID_Tuples.root"; f[7] = TFile::Open(placeholder);//2015 MC B0D- vector<TString> tree(nFiles); tree[0] = "tupleb2D0Mu/tupleb2D0Mu"; tree[1] = "tupleb2DpMu/tupleb2DpMu"; tree[2] = "Tuple_b2D0MuX/DecayTree"; tree[3] = "Tuple_b2DpMuX/DecayTree"; tree[4] = "Tuple_b2D0MuX/DecayTree"; tree[5] = "Tuple_b2DpMuX/DecayTree"; tree[6] = "Tuple_b2D0MuX/DecayTree"; tree[7] = "Tuple_b2DpMuX/DecayTree"; int nLayers=5;//year, filetype, decay, branch, cuts vector<TString> Lresponse(nLayers); Lresponse[0]="year"; Lresponse[1]="filetype"; Lresponse[2]="decay"; Lresponse[3]="branch"; Lresponse[4]="cut"; vector<int> nL(nLayers); nL[0]=2; nL[1]=2; nL[2]=2; nL[3]=1; nL[4]=1; vector< vector<TString> > L;//L[layer][layerelement] L.resize(nLayers); for(int i=0; i<nLayers; i++) { L[i].resize(nL[i]); } L[0][0]="2011"; L[0][1]="2015"; L[1][0]="data"; L[1][1]="MC"; L[2][0]="B^{-}->(D^{0}->K^{-} #pi^{+})#mu^{-}"; L[2][1]="B^{0}->(D^{-}->K^{+} #pi^{-} #pi^{-})#mu^{+}"; L[3][0]=""; L[4][0]=""; int bL=3;//index corresponding to branch layer int nBranches=1; int cL=4;//index corresponding to cut layer int nCuts=1; vector< vector<TString> > branch;//branch[file][branches] branch.resize(nFiles);//finished resizing below in loop with cut vector vector<int> nBins(nBranches); nBins[0]=131;//these are for nLongTracks vector<int> loBin(nBranches); loBin[0]=0; vector<int> hiBin(nBranches); hiBin[0]=262; vector< vector< vector<TString> > > cut;//cut[file][branch][cuts] cut.resize(nFiles); for(int i=0; i<nFiles; i++) { //resize and fill branch and cut vectors cut[i].resize(nBranches); branch[i].resize(nBranches); for(int j=0; j<nBranches; j++) { cut[i][j].resize(nCuts); branch[i][j]="nLongTracks";//only one branch; same for all these files for(int k=0; k<nCuts; k++) { if(i%2==0) { //since I've listed the files alternating by decay cut[i][j][k]="(B_M>3500)&&(B_M<5000)&&(D_M>1849.84)&&(D_M<1879.84)"; } else { cut[i][j][k]="(B_M>3500)&&(B_M<5000)&&(D_M>1854.61)&&(D_M<1884.61)"; } } } } int nComparisons=1; vector<TString> comparison(nComparisons); comparison[0]="decay"; int nhpc=1; int nCanvases=1; for(int i=0; i<nLayers; i++) { if(i>=(nLayers-nComparisons)) { nhpc*=nL[i];//now we're in the realm of comparisons } else { nCanvases *= nL[i]; } } vector<TString> list(0);//this holds the combinations of things used to describe the files; // keep empty as the combinations are appended in get custom parameters //-----------------------------get custom parameters-----------------------// if(runmode.Contains("o")) { cout<<"Where should the output be stored? (make sure the directory exists; include / at end)"<<endl; cin>>outputlocation; cout<<"What should the output file be called? (include extension, e.g., 'plots.pdf')"<<endl; cin>>filename; }
StkId luaV_execute(lua_Task *task) { if (!task->some_flag) { luaD_checkstack((*task->pc++) + EXTRA_STACK); if (*task->pc < ZEROVARARG) { luaD_adjusttop(task->base + *(task->pc++)); } else { luaC_checkGC(); adjust_varargs(task->base + (*task->pc++) - ZEROVARARG); } task->some_flag = 1; } lua_state->state_counter2++; while (1) { switch ((OpCode)(task->aux = *task->pc++)) { case PUSHNIL0: ttype(task->S->top++) = LUA_T_NIL; break; case PUSHNIL: task->aux = *task->pc++; do { ttype(task->S->top++) = LUA_T_NIL; } while (task->aux--); break; case PUSHNUMBER: task->aux = *task->pc++; goto pushnumber; case PUSHNUMBERW: task->aux = next_word(task->pc); goto pushnumber; case PUSHNUMBER0: case PUSHNUMBER1: case PUSHNUMBER2: task->aux -= PUSHNUMBER0; pushnumber: ttype(task->S->top) = LUA_T_NUMBER; nvalue(task->S->top) = (float)task->aux; task->S->top++; break; case PUSHLOCAL: task->aux = *task->pc++; goto pushlocal; case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: case PUSHLOCAL3: case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7: task->aux -= PUSHLOCAL0; pushlocal: *task->S->top++ = *((task->S->stack + task->base) + task->aux); break; case GETGLOBALW: task->aux = next_word(task->pc); goto getglobal; case GETGLOBAL: task->aux = *task->pc++; goto getglobal; case GETGLOBAL0: case GETGLOBAL1: case GETGLOBAL2: case GETGLOBAL3: case GETGLOBAL4: case GETGLOBAL5: case GETGLOBAL6: case GETGLOBAL7: task->aux -= GETGLOBAL0; getglobal: luaV_getglobal(tsvalue(&task->consts[task->aux])); break; case GETTABLE: luaV_gettable(); break; case GETDOTTEDW: task->aux = next_word(task->pc); goto getdotted; case GETDOTTED: task->aux = *task->pc++; goto getdotted; case GETDOTTED0: case GETDOTTED1: case GETDOTTED2: case GETDOTTED3: case GETDOTTED4: case GETDOTTED5: case GETDOTTED6: case GETDOTTED7: task->aux -= GETDOTTED0; getdotted: *task->S->top++ = task->consts[task->aux]; luaV_gettable(); break; case PUSHSELFW: task->aux = next_word(task->pc); goto pushself; case PUSHSELF: task->aux = *task->pc++; goto pushself; case PUSHSELF0: case PUSHSELF1: case PUSHSELF2: case PUSHSELF3: case PUSHSELF4: case PUSHSELF5: case PUSHSELF6: case PUSHSELF7: task->aux -= PUSHSELF0; pushself: { TObject receiver = *(task->S->top - 1); *task->S->top++ = task->consts[task->aux]; luaV_gettable(); *task->S->top++ = receiver; break; } case PUSHCONSTANTW: task->aux = next_word(task->pc); goto pushconstant; case PUSHCONSTANT: task->aux = *task->pc++; goto pushconstant; case PUSHCONSTANT0: case PUSHCONSTANT1: case PUSHCONSTANT2: case PUSHCONSTANT3: case PUSHCONSTANT4: case PUSHCONSTANT5: case PUSHCONSTANT6: case PUSHCONSTANT7: task->aux -= PUSHCONSTANT0; pushconstant: *task->S->top++ = task->consts[task->aux]; break; case PUSHUPVALUE: task->aux = *task->pc++; goto pushupvalue; case PUSHUPVALUE0: case PUSHUPVALUE1: task->aux -= PUSHUPVALUE0; pushupvalue: *task->S->top++ = task->cl->consts[task->aux + 1]; break; case SETLOCAL: task->aux = *task->pc++; goto setlocal; case SETLOCAL0: case SETLOCAL1: case SETLOCAL2: case SETLOCAL3: case SETLOCAL4: case SETLOCAL5: case SETLOCAL6: case SETLOCAL7: task->aux -= SETLOCAL0; setlocal: *((task->S->stack + task->base) + task->aux) = *(--task->S->top); break; case SETGLOBALW: task->aux = next_word(task->pc); goto setglobal; case SETGLOBAL: task->aux = *task->pc++; goto setglobal; case SETGLOBAL0: case SETGLOBAL1: case SETGLOBAL2: case SETGLOBAL3: case SETGLOBAL4: case SETGLOBAL5: case SETGLOBAL6: case SETGLOBAL7: task->aux -= SETGLOBAL0; setglobal: luaV_setglobal(tsvalue(&task->consts[task->aux])); break; case SETTABLE0: luaV_settable(task->S->top - 3, 1); break; case SETTABLE: luaV_settable(task->S->top - 3 - (*task->pc++), 2); break; case SETLISTW: task->aux = next_word(task->pc); task->aux *= LFIELDS_PER_FLUSH; goto setlist; case SETLIST: task->aux = *(task->pc++) * LFIELDS_PER_FLUSH; goto setlist; case SETLIST0: task->aux = 0; setlist: { int32 n = *(task->pc++); TObject *arr = task->S->top - n - 1; for (; n; n--) { ttype(task->S->top) = LUA_T_NUMBER; nvalue(task->S->top) = (float)(n + task->aux); *(luaH_set(avalue(arr), task->S->top)) = *(task->S->top - 1); task->S->top--; } break; } case SETMAP0: task->aux = 0; goto setmap; case SETMAP: task->aux = *task->pc++; setmap: { TObject *arr = task->S->top - (2 * task->aux) - 3; do { *(luaH_set(avalue(arr), task->S->top - 2)) = *(task->S->top - 1); task->S->top -= 2; } while (task->aux--); break; } case POP: task->aux = *task->pc++; goto pop; case POP0: case POP1: task->aux -= POP0; pop: task->S->top -= (task->aux + 1); break; case CREATEARRAYW: task->aux = next_word(task->pc); goto createarray; case CREATEARRAY0: case CREATEARRAY1: task->aux -= CREATEARRAY0; goto createarray; case CREATEARRAY: task->aux = *task->pc++; createarray: luaC_checkGC(); avalue(task->S->top) = luaH_new(task->aux); ttype(task->S->top) = LUA_T_ARRAY; task->S->top++; break; case EQOP: case NEQOP: { int32 res = luaO_equalObj(task->S->top - 2, task->S->top - 1); task->S->top--; if (task->aux == NEQOP) res = !res; ttype(task->S->top - 1) = res ? LUA_T_NUMBER : LUA_T_NIL; nvalue(task->S->top - 1) = 1; break; } case LTOP: comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, IM_LT); break; case LEOP: comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, IM_LE); break; case GTOP: comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, IM_GT); break; case GEOP: comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, IM_GE); break; case ADDOP: { TObject *l = task->S->top - 2; TObject *r = task->S->top - 1; if (tonumber(r) || tonumber(l)) call_arith(IM_ADD); else { nvalue(l) += nvalue(r); --task->S->top; } break; } case SUBOP: { TObject *l = task->S->top - 2; TObject *r = task->S->top - 1; if (tonumber(r) || tonumber(l)) call_arith(IM_SUB); else { nvalue(l) -= nvalue(r); --task->S->top; } break; } case MULTOP: { TObject *l = task->S->top - 2; TObject *r = task->S->top - 1; if (tonumber(r) || tonumber(l)) call_arith(IM_MUL); else { nvalue(l) *= nvalue(r); --task->S->top; } break; } case DIVOP: { TObject *l = task->S->top - 2; TObject *r = task->S->top - 1; if (tonumber(r) || tonumber(l)) call_arith(IM_DIV); else { nvalue(l) /= nvalue(r); --task->S->top; } break; } case POWOP: call_arith(IM_POW); break; case CONCOP: { TObject *l = task->S->top - 2; TObject *r = task->S->top - 1; if (tostring(l) || tostring(r)) call_binTM(IM_CONCAT, "unexpected type for concatenation"); else { tsvalue(l) = strconc(svalue(l), svalue(r)); --task->S->top; } luaC_checkGC(); break; } case MINUSOP: if (tonumber(task->S->top - 1)) { ttype(task->S->top) = LUA_T_NIL; task->S->top++; call_arith(IM_UNM); } else nvalue(task->S->top - 1) = -nvalue(task->S->top - 1); break; case NOTOP: ttype(task->S->top - 1) = (ttype(task->S->top - 1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL; nvalue(task->S->top - 1) = 1; break; case ONTJMPW: task->aux = next_word(task->pc); goto ontjmp; case ONTJMP: task->aux = *task->pc++; ontjmp: if (ttype(task->S->top - 1) != LUA_T_NIL) task->pc += task->aux; else task->S->top--; break; case ONFJMPW: task->aux = next_word(task->pc); goto onfjmp; case ONFJMP: task->aux = *task->pc++; onfjmp: if (ttype(task->S->top - 1) == LUA_T_NIL) task->pc += task->aux; else task->S->top--; break; case JMPW: task->aux = next_word(task->pc); goto jmp; case JMP: task->aux = *task->pc++; jmp: task->pc += task->aux; break; case IFFJMPW: task->aux = next_word(task->pc); goto iffjmp; case IFFJMP: task->aux = *task->pc++; iffjmp: if (ttype(--task->S->top) == LUA_T_NIL) task->pc += task->aux; break; case IFTUPJMPW: task->aux = next_word(task->pc); goto iftupjmp; case IFTUPJMP: task->aux = *task->pc++; iftupjmp: if (ttype(--task->S->top) != LUA_T_NIL) task->pc -= task->aux; break; case IFFUPJMPW: task->aux = next_word(task->pc); goto iffupjmp; case IFFUPJMP: task->aux = *task->pc++; iffupjmp: if (ttype(--task->S->top) == LUA_T_NIL) task->pc -= task->aux; break; case CLOSURE: task->aux = *task->pc++; goto closure; case CLOSURE0: case CLOSURE1: task->aux -= CLOSURE0; closure: luaV_closure(task->aux); luaC_checkGC(); break; case CALLFUNC: task->aux = *task->pc++; goto callfunc; case CALLFUNC0: case CALLFUNC1: task->aux -= CALLFUNC0; callfunc: lua_state->state_counter2--; return -((task->S->top - task->S->stack) - (*task->pc++)); case ENDCODE: task->S->top = task->S->stack + task->base; // goes through case RETCODE: lua_state->state_counter2--; return (task->base + ((task->aux == 123) ? *task->pc : 0)); case SETLINEW: task->aux = next_word(task->pc); goto setline; case SETLINE: task->aux = *task->pc++; setline: if ((task->S->stack + task->base - 1)->ttype != LUA_T_LINE) { // open space for LINE value */ luaD_openstack((task->S->top - task->S->stack) - task->base); task->base++; (task->S->stack + task->base - 1)->ttype = LUA_T_LINE; } (task->S->stack + task->base - 1)->value.i = task->aux; if (lua_linehook) luaD_lineHook(task->aux); break; #ifdef LUA_DEBUG default: LUA_INTERNALERROR("internal error - opcode doesn't match"); #endif } } }
void update_orbit_mins(int min_val, int pos) { D_ASSERT(!comparison(pos, min_val)); if(min_val != pos) orbit_mins[pos] = min_val; }
/* ** Execute the given opcode, until a RET. Parameters are between ** [stack+base,top). Returns n such that the the results are between ** [stack+n,top). */ StkId luaV_execute (struct CallInfo *ci) { /* Save index in case CallInfo array is realloc'd */ int32 ci_index = ci - L->base_ci; struct Stack *S = &L->stack; /* to optimize */ Closure *cl; TProtoFunc *tf; StkId base; Byte *pc; TObject *consts; newfunc: cl = L->ci->c; tf = L->ci->tf; base = L->ci->base; if (S->top-S->stack > base && ttype(S->stack+base) == LUA_T_LINE) base++; pc = L->ci->pc; consts = tf->consts; while (1) { int32 aux; switch ((OpCode)(aux = *pc++)) { case PUSHNIL0: ttype(S->top++) = LUA_T_NIL; break; case PUSHNIL: aux = *pc++; do { ttype(S->top++) = LUA_T_NIL; } while (aux--); break; case PUSHNUMBER: aux = *pc++; goto pushnumber; case PUSHNUMBERW: aux = next_word(pc); goto pushnumber; case PUSHNUMBER0: case PUSHNUMBER1: case PUSHNUMBER2: aux -= PUSHNUMBER0; pushnumber: ttype(S->top) = LUA_T_NUMBER; nvalue(S->top) = (real)aux; S->top++; break; case PUSHLOCAL: aux = *pc++; goto pushlocal; case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: case PUSHLOCAL3: case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7: aux -= PUSHLOCAL0; pushlocal: *S->top++ = *((S->stack+base) + aux); break; case GETGLOBALW: aux = next_word(pc); goto getglobal; case GETGLOBAL: aux = *pc++; goto getglobal; case GETGLOBAL0: case GETGLOBAL1: case GETGLOBAL2: case GETGLOBAL3: case GETGLOBAL4: case GETGLOBAL5: case GETGLOBAL6: case GETGLOBAL7: aux -= GETGLOBAL0; getglobal: luaV_getglobal(tsvalue(&consts[aux])); break; case GETTABLE: luaV_gettable(); break; case GETDOTTEDW: aux = next_word(pc); goto getdotted; case GETDOTTED: aux = *pc++; goto getdotted; case GETDOTTED0: case GETDOTTED1: case GETDOTTED2: case GETDOTTED3: case GETDOTTED4: case GETDOTTED5: case GETDOTTED6: case GETDOTTED7: aux -= GETDOTTED0; getdotted: *S->top++ = consts[aux]; luaV_gettable(); break; case PUSHSELFW: aux = next_word(pc); goto pushself; case PUSHSELF: aux = *pc++; goto pushself; case PUSHSELF0: case PUSHSELF1: case PUSHSELF2: case PUSHSELF3: case PUSHSELF4: case PUSHSELF5: case PUSHSELF6: case PUSHSELF7: aux -= PUSHSELF0; pushself: { TObject receiver = *(S->top-1); *S->top++ = consts[aux]; luaV_gettable(); *S->top++ = receiver; break; } case PUSHCONSTANTW: aux = next_word(pc); goto pushconstant; case PUSHCONSTANT: aux = *pc++; goto pushconstant; case PUSHCONSTANT0: case PUSHCONSTANT1: case PUSHCONSTANT2: case PUSHCONSTANT3: case PUSHCONSTANT4: case PUSHCONSTANT5: case PUSHCONSTANT6: case PUSHCONSTANT7: aux -= PUSHCONSTANT0; pushconstant: *S->top++ = consts[aux]; break; case PUSHUPVALUE: aux = *pc++; goto pushupvalue; case PUSHUPVALUE0: case PUSHUPVALUE1: aux -= PUSHUPVALUE0; pushupvalue: *S->top++ = cl->consts[aux+1]; break; case SETLOCAL: aux = *pc++; goto setlocal; case SETLOCAL0: case SETLOCAL1: case SETLOCAL2: case SETLOCAL3: case SETLOCAL4: case SETLOCAL5: case SETLOCAL6: case SETLOCAL7: aux -= SETLOCAL0; setlocal: *((S->stack+base) + aux) = *(--S->top); break; case SETGLOBALW: aux = next_word(pc); goto setglobal; case SETGLOBAL: aux = *pc++; goto setglobal; case SETGLOBAL0: case SETGLOBAL1: case SETGLOBAL2: case SETGLOBAL3: case SETGLOBAL4: case SETGLOBAL5: case SETGLOBAL6: case SETGLOBAL7: aux -= SETGLOBAL0; setglobal: luaV_setglobal(tsvalue(&consts[aux])); break; case SETTABLE0: luaV_settable(S->top-3, 1); break; case SETTABLE: luaV_settable(S->top-3-(*pc++), 2); break; case SETLISTW: aux = next_word(pc); aux *= LFIELDS_PER_FLUSH; goto setlist; case SETLIST: aux = *(pc++) * LFIELDS_PER_FLUSH; goto setlist; case SETLIST0: aux = 0; setlist: { int32 n = *(pc++); TObject *arr = S->top-n-1; for (; n; n--) { ttype(S->top) = LUA_T_NUMBER; nvalue(S->top) = (real)(n+aux); *(luaH_set(avalue(arr), S->top)) = *(S->top-1); S->top--; } break; } case SETMAP0: aux = 0; goto setmap; case SETMAP: aux = *pc++; setmap: { TObject *arr = S->top-(2*aux)-3; do { *(luaH_set(avalue(arr), S->top-2)) = *(S->top-1); S->top-=2; } while (aux--); break; } case POP: aux = *pc++; goto pop; case POP0: case POP1: aux -= POP0; pop: S->top -= (aux+1); break; case CREATEARRAYW: aux = next_word(pc); goto createarray; case CREATEARRAY0: case CREATEARRAY1: aux -= CREATEARRAY0; goto createarray; case CREATEARRAY: aux = *pc++; createarray: luaC_checkGC(); avalue(S->top) = luaH_new(aux); ttype(S->top) = LUA_T_ARRAY; S->top++; break; case EQOP: case NEQOP: { int32 res = luaO_equalObj(S->top-2, S->top-1); S->top--; if (aux == NEQOP) res = !res; ttype(S->top-1) = res ? LUA_T_NUMBER : LUA_T_NIL; nvalue(S->top-1) = 1; break; } case LTOP: comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, IM_LT); break; case LEOP: comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, IM_LE); break; case GTOP: comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, IM_GT); break; case GEOP: comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, IM_GE); break; case ADDOP: { TObject *l = S->top-2; TObject *r = S->top-1; if (tonumber(r) || tonumber(l)) call_arith(IM_ADD); else { nvalue(l) += nvalue(r); --S->top; } break; } case SUBOP: { TObject *l = S->top-2; TObject *r = S->top-1; if (tonumber(r) || tonumber(l)) call_arith(IM_SUB); else { nvalue(l) -= nvalue(r); --S->top; } break; } case MULTOP: { TObject *l = S->top-2; TObject *r = S->top-1; if (tonumber(r) || tonumber(l)) call_arith(IM_MUL); else { nvalue(l) *= nvalue(r); --S->top; } break; } case DIVOP: { TObject *l = S->top-2; TObject *r = S->top-1; if (tonumber(r) || tonumber(l)) call_arith(IM_DIV); else { nvalue(l) /= nvalue(r); --S->top; } break; } case POWOP: call_binTM(IM_POW, "undefined operation"); break; case CONCOP: { TObject *l = S->top-2; TObject *r = S->top-1; if (tostring(l) || tostring(r)) call_binTM(IM_CONCAT, "unexpected type for concatenation"); else { tsvalue(l) = strconc(tsvalue(l), tsvalue(r)); --S->top; } luaC_checkGC(); break; } case MINUSOP: if (tonumber(S->top-1)) { ttype(S->top) = LUA_T_NIL; S->top++; call_arith(IM_UNM); } else nvalue(S->top-1) = - nvalue(S->top-1); break; case NOTOP: ttype(S->top-1) = (ttype(S->top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL; nvalue(S->top-1) = 1; break; case ONTJMPW: aux = next_word(pc); goto ontjmp; case ONTJMP: aux = *pc++; ontjmp: if (ttype(S->top-1) != LUA_T_NIL) pc += aux; else S->top--; break; case ONFJMPW: aux = next_word(pc); goto onfjmp; case ONFJMP: aux = *pc++; onfjmp: if (ttype(S->top-1) == LUA_T_NIL) pc += aux; else S->top--; break; case JMPW: aux = next_word(pc); goto jmp; case JMP: aux = *pc++; jmp: pc += aux; break; case IFFJMPW: aux = next_word(pc); goto iffjmp; case IFFJMP: aux = *pc++; iffjmp: if (ttype(--S->top) == LUA_T_NIL) pc += aux; break; case IFTUPJMPW: aux = next_word(pc); goto iftupjmp; case IFTUPJMP: aux = *pc++; iftupjmp: if (ttype(--S->top) != LUA_T_NIL) pc -= aux; break; case IFFUPJMPW: aux = next_word(pc); goto iffupjmp; case IFFUPJMP: aux = *pc++; iffupjmp: if (ttype(--S->top) == LUA_T_NIL) pc -= aux; break; case CLOSURE: aux = *pc++; goto closure; case CLOSURE0: aux = 0; goto closure; case CLOSURE1: aux = 1; closure: luaV_closure(aux); luaC_checkGC(); break; case CALLFUNC: aux = *pc++; goto callfunc; case CALLFUNC0: case CALLFUNC1: aux -= CALLFUNC0; callfunc: { StkId newBase = (S->top-S->stack)-(*pc++); TObject *func = S->stack+newBase-1; L->ci->pc = pc; if (ttype(func) == LUA_T_PROTO || (ttype(func) == LUA_T_CLOSURE && ttype(&clvalue(func)->consts[0]) == LUA_T_PROTO)) { /* Calling another Lua function */ luaD_precall(func, newBase, aux); ttype(func) = (ttype(func) == LUA_T_PROTO) ? LUA_T_PMARK : LUA_T_CLMARK; goto newfunc; } luaD_call(newBase, aux); if (L->Tstate != RUN) { if (ci_index > 1) /* C functions detected by break_here */ lua_error("Cannot yield through method call"); return -1; } break; } case ENDCODE: S->top = S->stack + base; /* goes through */ case RETCODE: { StkId firstResult = (base + ((aux==RETCODE) ? *pc : 0)); if (lua_callhook) luaD_callHook(base, NULL, 1); /* If returning from the original stack frame, terminate */ if (L->ci == L->base_ci + ci_index) return firstResult; luaD_postret(firstResult); goto newfunc; } case SETLINEW: aux = next_word(pc); goto setline; case SETLINE: aux = *pc++; setline: if ((S->stack+base-1)->ttype != LUA_T_LINE) { /* open space for LINE value */ luaD_openstack((S->top-S->stack)-base); base++; (S->stack+base-1)->ttype = LUA_T_LINE; } (S->stack+base-1)->value.i = aux; if (lua_linehook) luaD_lineHook(aux); break; #ifdef DEBUG default: LUA_INTERNALERROR("opcode doesn't match"); #endif } } }
int sc_main(int argc , char *argv[]) { sc_signal< sc_uint<NN_DIGIT_BITS> > in_a, in_b; sc_signal< sc_uint<3> > write_select; sc_signal< bool > write_enable; sc_signal< sc_uint<3> > read_a_select, read_b_select; sc_signal< bool > read_enable, input_load; sc_signal< sc_uint<2> > input_mux_select; sc_signal< bool > reg_file_in_mux_select; sc_signal< sc_uint<NN_DIGIT_BITS> > out_a; sc_signal< sc_uint<NN_DIGIT_BITS> > out_b; sc_signal< sc_uint<NN_DIGIT_BITS> > b_high, b_low, c_high, c_low; sc_signal< sc_uint<NN_DIGIT_BITS> > input_reg_value, data_path_calculated_value, regfile_input; sc_signal< sc_uint<2> > adder_mux_select, output_mux_select; sc_signal< bool > mult_enable, adder_enable; sc_signal< bool > shifter_enable, shifter_direction; sc_signal< bool > comp_eq, comp_gt, comp_lt; sc_signal< sc_uint<NN_DIGIT_BITS> > high_1_value, low_1_value, zero_value; sc_signal< sc_uint<NN_DIGIT_BITS> > adder_mux_output, adder_output, shifter_output, mult_output; sc_clock Clk("Clock", 10, SC_NS); Driver driver("driver"); hw_const<NN_DIGIT_BITS> high_1_const("high_1_const", 0x00010000), low_1_const("low_1_const", 0x00000001), zero_const("zero_const", 0x00000000); register_wt_half_index b_reg("b_reg"), c_reg("c_reg"); mux4 input_mux("input_mux"), adder_mux("adder_mux"), output_mux("output_mux"); mux2 reg_file_in_mux("reg_file_in_mux"); register_file reg_file("reg_file"); multiplier mult("mult"); adder add("add"); shifter16 shifter("shifter"); comparator comparison("comparison"); Viewer viewer("viewer"); // Constant Connections high_1_const.output(high_1_value); low_1_const.output(low_1_value); zero_const.output(zero_value); // Driver driver.CLK(Clk); driver.in_a(in_a); driver.in_b(in_b); driver.write_enable(write_enable); driver.write_select(write_select); driver.read_a_select(read_a_select); driver.read_b_select(read_b_select); driver.read_enable(read_enable); driver.input_load(input_load); driver.input_mux_select(input_mux_select); driver.reg_file_in_mux_select(reg_file_in_mux_select); driver.adder_mux_select(adder_mux_select); driver.output_mux_select(output_mux_select); driver.mult_enable(mult_enable); driver.adder_enable(adder_enable); driver.shifter_enable(shifter_enable); driver.shifter_direction(shifter_direction); driver.comp_eq(comp_eq); driver.comp_gt(comp_gt); driver.comp_lt(comp_lt); // Init Load b_reg.in(in_a); b_reg.out_high(b_high); b_reg.out_low(b_low); b_reg.clk(Clk); b_reg.load(input_load); c_reg.in(in_b); c_reg.out_high(c_high); c_reg.out_low(c_low); c_reg.clk(Clk); c_reg.load(input_load); // FSM Input Mux input_mux.in_a(b_high); input_mux.in_b(b_low); input_mux.in_c(c_high); input_mux.in_d(c_low); input_mux.out(input_reg_value); input_mux.select(input_mux_select); // Register File Input Mux reg_file_in_mux.in_a(input_reg_value); reg_file_in_mux.in_b(data_path_calculated_value); reg_file_in_mux.out(regfile_input); reg_file_in_mux.select(reg_file_in_mux_select); reg_file.clk(Clk); reg_file.in_a(regfile_input); reg_file.write_enable(write_enable); reg_file.write_select(write_select); reg_file.read_a_select(read_a_select); reg_file.read_b_select(read_b_select); reg_file.read_enable(read_enable); reg_file.out_a(out_a); reg_file.out_b(out_b); // Multiplier mult.in_a(out_a); mult.in_b(out_b); mult.out(mult_output); mult.enable(mult_enable); // Adder Input Mux adder_mux.in_a(out_b); adder_mux.in_b(high_1_value); adder_mux.in_c(low_1_value); adder_mux.in_d(zero_value); adder_mux.out(adder_mux_output); adder_mux.select(adder_mux_select); // Adder add.in_a(out_a); add.in_b(adder_mux_output); add.out(adder_output); add.enable(adder_enable); // Shifter shifter.in(out_a); shifter.out(shifter_output); shifter.direction(shifter_direction); shifter.enable(shifter_enable); // Comparator comparison.in_a(out_a); comparison.in_b(out_b); comparison.eq(comp_eq); comparison.lt(comp_lt); comparison.gt(comp_gt); // Output Mux output_mux.in_a(mult_output); output_mux.in_b(adder_output); output_mux.in_c(shifter_output); output_mux.in_d(zero_value); output_mux.out(data_path_calculated_value); output_mux.select(output_mux_select); // Viewer viewer.out_a(out_a); viewer.out_b(out_b); sc_start(); return(0); }