void main (void) { c_char(); c_int(); c_long(); success = failures; done (); }
static void GC_Set(var self, var key, var val) { struct GC* gc = self; if (not gc->running) { return; } gc->nitems++; gc->maxptr = (uintptr_t)key > gc->maxptr ? (uintptr_t)key : gc->maxptr; gc->minptr = (uintptr_t)key < gc->minptr ? (uintptr_t)key : gc->minptr; GC_Resize_More(gc); GC_Set_Ptr(gc, key, (bool)c_int(val)); if (gc->nitems > gc->mitems) { GC_Mark(gc); GC_Sweep(gc); } }
void main (void) { c_char(); c_int(); c_long(); int0 = -1; c_uminus(); if(int1 != 1) failures++; success = failures; done (); }
static void c_code(struct s_node *n, enum opt_assign a) { /* XXX except for a couple of desugared cases, there is always a coords as * a first child of expr, so it would be better to fix sugar.c and assert * here */ if (n->first && n->first->type == coords) { int i; c_strln(""); c_str("#line "); c_int(n->first->pair[0]); c_str(" \""); c_str(arg_input()); c_strln("\""); /* 1-based counting; subtract 1 for upcoming '(' and maybe '=' */ for (i = 1; i < n->first->pair[1] - 1 - assign; ++i) putchar(' '); } if (a) putchar('='); putchar('('); c_raw(n->text); putchar(')'); if (a) putchar(';'); c_raw("\n"); /* now a #line to take us back to the C output; line number of next line */ c_str("#line "); c_long(nr + 1); c_str(" \""); c_str(arg_output()); c_strln("\""); }
int main (void) { opentest(OUTFILE); c_char(); c_int(); c_long(); int0 = -1; c_uminus(); if(int1 != 1) failures++; success = failures; done (); fprintf(outfile,"failures: %d\n",failures); closetest(THISFILE); return (0); }
bool qp_box( size_t level , const Vector& a , const Vector& b , const Vector& c , const Vector& C , const Vector& g , const Vector& G , double epsilon , size_t maxitr , const Vector& xin , Vector& xout ) // END PROTOTYPE { double inf = std::numeric_limits<double>::infinity(); // size_t n = a.size(); size_t m = c.size(); // CPPAD_ASSERT_KNOWN(level <= 2, "qp_interior: level is greater than 2"); CPPAD_ASSERT_KNOWN( size_t(b.size()) == n, "qp_box: size of b is not n" ); CPPAD_ASSERT_KNOWN( size_t(C.size()) == m * n, "qp_box: size of C is not m * n" ); CPPAD_ASSERT_KNOWN( size_t(g.size()) == n, "qp_box: size of g is not n" ); CPPAD_ASSERT_KNOWN( size_t(G.size()) == n * n, "qp_box: size of G is not n * n" ); if( level > 0 ) { std::cout << "start qp_box\n"; CppAD::abs_print_mat("a", n, 1, a); CppAD::abs_print_mat("b", n, 1, b); CppAD::abs_print_mat("c", m, 1, c); CppAD::abs_print_mat("C", m, n, C); CppAD::abs_print_mat("g", 1, n, g); CppAD::abs_print_mat("G", n, n, G); CppAD::abs_print_mat("xin", n, 1, xin); } // // count number of lower and upper limits size_t n_limit = 0; for(size_t j = 0; j < n; j++) { CPPAD_ASSERT_KNOWN(G[j * n + j] >= 0.0, "qp_box: G_{j,j} < 0.0"); if( -inf < a[j] ) ++n_limit; if( b[j] < inf ) ++n_limit; } // // C_int and c_int define the extended constraints Vector C_int((m + n_limit) * n ), c_int(m + n_limit); for(size_t i = 0; i < size_t(C_int.size()); i++) C_int[i] = 0.0; // // put C * x + c <= 0 in C_int, c_int for(size_t i = 0; i < m; i++) { c_int[i] = c[i]; for(size_t j = 0; j < n; j++) C_int[i * n + j] = C[i * n + j]; } // // put I * x - b <= 0 in C_int, c_int size_t i_limit = 0; for(size_t j = 0; j < n; j++) if( b[j] < inf ) { c_int[m + i_limit] = - b[j]; C_int[(m + i_limit) * n + j] = 1.0; ++i_limit; } // // put a - I * x <= 0 in C_int, c_int for(size_t j = 0; j < n; j++) if( -inf < a[j] ) { c_int[m + i_limit] = a[j]; C_int[(m + i_limit) * n + j] = -1.0; ++i_limit; } Vector yout(m + n_limit), sout(m + n_limit); size_t level_int = 0; if( level == 2 ) level_int = 1; bool ok = qp_interior( level_int, c_int, C_int, g, G, epsilon, maxitr, xin, xout, yout, sout ); if( level > 0 ) { if( level < 2 ) CppAD::abs_print_mat("xout", n, 1, xout); if( ok ) std::cout << "end q_box: ok = true\n"; else std::cout << "end q_box: ok = false\n"; } return ok; }
static void grammar_pre(struct s_node *n) { int i, r = 0; struct s_node *p; static int cooked = 0; g_node = n; if (arg_defines()) { c_str("#include \"");c_str(arg_defines());c_strln("\""); if (arg_feed() && cooked) { c_strln("#undef PACC_NAME"); c_strln("#define PACC_NAME PACC_FEED_NAME"); } } else c_defines(); ++cooked; pre_decl(); /* We slightly simplify both building & walking the tree and insist * that every grammar starts with a preamble, which may be null. * It's a bit odd to represent no preamble with an empty preamble * node. */ p = n->first; assert(p->type == preamble); if (!arg_defines() && p->text) c_raw(p->text); p = p->next; for ( ; p; p = p->next) { assert(p->type == rule); ++r; } c_str("static const int n_rules = "); c_int(r); c_semi(); c_str("static const int start_rule_id = "); c_long(n->first->next->id); c_semi(); g_name = n->text; /* type of start rule is always u0 */ type_list(n->first->next->first->text); for (p = n->first; p; p = p->next) if (p->type == rule) type_list(p->first->text); c_str("union PACC_SYM(vals)"); c_open(); for (i = 0; i < t_max; ++i) { c_str(t_list[i]); c_str(" u"); c_int(i); c_semi(); } c_close(); c_semi(); /* XXX just for debugging */ c_str("#define TYPE_PRINTF "); if (strcmp(n->first->next->first->text, "int") == 0) c_str("\"%d\""); else if (strcmp(n->first->next->first->text, "char *") == 0) c_str("\"%s\""); else c_str("\"%p\""); c_strln(""); c_str("#define PACC_TYPE "); c_strln(n->first->next->first->text); pre_engine(); c_str("_st="); c_long(n->first->type == preamble ? n->first->next->id : n->first->id); c_semi(); c_strln("goto top;"); c_strln("contin:"); c_strln("_st=_cont;"); c_strln("PACC_TRACE fprintf(stderr, \"continuing in state %d\\n\", _cont);"); c_strln("top:"); c_strln("PACC_TRACE fprintf(stderr, \"switch to state %d\\n\", _st);"); c_str("switch(_st)"); c_open(); }
int main() { //basic std::cout << Double(Double(2)) << std::endl; std::cout << Double(3.14) << std::endl; std::cout << Double(2.222222) << std::endl; PrintPower(10); PrintPower(3.14); PrintPower(2.222); Neshto drugo(20); PrintPower(drugo); std::cout << add(5, 10) << std::endl; int a = 10, b = 20; std::cout << "a: " << a << std::endl << "b: " << b << std::endl; std::cout << "swap..." << std::endl; swap(a, b); std::cout << "a: " << a << std::endl << "b: " << b << std::endl; //arrays int p(); std::cout << "p: " << p << std::endl; int q(); std::cout << "q: " << q << std::endl; std::cout << "int(): " << int() << std::endl; int arr[10] = {1,2,3,4,5,6,7,8,9,10}; std::cout << "GET AVERAGE: " << GetAverage<int>(arr, 10) << std::endl; float f_arr[5] = {1.1,2.2,3.3,4.4,5.5}; std::cout << "int args: " << GetAverage<int>(arr, 10) << std::endl; std::cout << "float args: " << GetAverage<float>(&f_arr[0], 5) << std::endl; std::cout << "float args with int function: " << GetAverage<int>(arr, 5); int t = 10; std::cout << "t: " << t << std::endl; RefAdd(t, 5); std::cout << "t: " << t << std::endl; // This will not be compiled // Because we take a const & as // argument and the return type // is not const When break // the constness of the argument //int immutable_number = 10; //++GetTrival(immutable_number); Pair pesho = {20, "Pesho"}; PrintPair(pesho.age, pesho.name); std::string pi_key = "PI"; double pi_value = 3.14; PrintPair(pi_key, pi_value); PrintPair("Pesho", "Goshov"); // print gosho User gosho("Gosho", 2000); int user_id=25; PrintPair(user_id, gosho); // Note: // When we use a template function // with similar parameters (e.g. short, int, long) // which can be converted to one another // the template engine will not reuse the created // functions and implicitly convert the arguments // Example: // short a = 10; // int b = 200000000; // double c = 2.15; // long d = 40000000000; 40 bilions // // PrintPair(a, b); same as PrintPair<short, int> // PrintPair(b, a); --|-- PrintPair<int, short> // PrintPair(a, d); --|-- PrintPair<short, long> // PrintPair(d, c); --|-- PrintPair<long, double> Show(120); Show('B'); Show(21.5); TemplateShow(120); // will produce TemplateShow<int> TemplateShow('X'); // will produce TemplateShow<char> TemplateShow(21.5); // will produce TemplateShow<double> // the compiler will not make an analisys // of the parameter because the function // is called explicitly with type double // and the argument will be taken as double // although it can be put in int TemplateShow<double>(1234); // SizeOfElement(); // cannot be called SizeOfElement<float>(); SizeOfElement<int>(); SizeOfElement<short>(); SizeOfElement<User>(); int int_arr[10] = {1,2,3,0,4,0,2,0,9,10}; PrintNumbers(int_arr, 10); // this will skip 0-s PrintNumbers(int_arr, 10, 2); // this will skip 2-s // TEMPLATE CLASSES USAGE Item i1; i1.SetData(120); i1.PrintData(); TemplateItem<double> t1; t1.SetData(3.14); t1.PrintData(); TemplateItem<char> t2; t2.SetData('X'); char big_x = t2.GetData(); std::cout << big_x << std::endl; t2.PrintData(); //t1 = t2; //this will cause error // because t1 is instace of the template // class with double and t2 is instance with char TemplatePair<int, std::string> t_pair1; TemplatePair<int, int> salary; salary.first = 200; // leva salary.second = 30; // coins std::cout << "salary: "; salary.Print(); TemplatePair<int, int> int_pair1(10, 20); TemplatePair<int, int> int_pair2(int_pair1); int_pair1.Print(); int_pair2.Print(); // it will cause an error //TemplatePair<int, float> int_float_pair(int_pair2); // Exercise: Implement // 1. operator = // 2. operator < // 3. operator > // 4. swap method // 5. modify the constructor with default arguments int pp; int qq = int(); std::cout << "pp: " << pp << std::endl; std::cout << "qq: " << qq << std::endl; // Template of template TemplateArray<TemplatePair<int, int>, 10> t_arr_t_pair; t_arr_t_pair[0] = TemplatePair<int, int>(5, 5); t_arr_t_pair.Print(); typedef TemplatePair<int, int> Salary; TemplatePair<std::string, Salary> peshko; std::vector<int> int_vector; std::vector<TemplatePair<int, int> > int_pair_vector; // this will make a int array of 100 elements DefaultTemplateArray<> default_arr_int; DefaultTemplateArray<double> def_size_d_arr; // TEMPLATE METHODS IntArray int_arr_obj; float float_arr[11]; int_arr_obj.Copy(float_arr); // or more explicitely int_arr_obj.Copy<float>(float_arr); std::cout << "Print int_arr_obj: " << std::endl; for(int i = 0; i < 10; ++i) { std::cout << int_arr_obj[i] << " "; } std::cout << std::endl; std::cout << "Print float_arr: " << std::endl; for(int i = 0; i < 10; ++i) { std::cout << int_arr_obj[i] << " "; } std::cout << std::endl; Comparer<int> c_int(10); float c_float = 10; std::cout << std::boolalpha << c_int.IsEqual(c_float) << std::endl; Comparer<int> cc_int(40); float cc_float; double cc_double; cc_float = cc_int; cc_double = cc_int; // which will invoke // Comparer<int>::operator<float> float(); // Comparer<int>::operator<double> double(); std::cout << "cc_int: " << cc_int.Data() << "\n" << "cc_float: " << cc_float << "\n" << "cc_double: " << cc_double << "\n"; return 0; }
object_t *lisp_hash (object_t * lst) { DOC ("Return integer hash of object."); REQ (lst, 1, c_sym ("hash")); return c_int (obj_hash (CAR (lst))); }