// examples/varargs translated by mycpp #include "mycpp/examples/varargs_preamble.h" // BEGIN mycpp output #include "mycpp/runtime.h" GLOBAL_STR(str0, "myconst"); GLOBAL_STR(str1, "constant string"); GLOBAL_STR(str2, "stderr_line"); GLOBAL_STR(str3, "log %d %s"); GLOBAL_STR(str4, "LL"); GLOBAL_STR(str5, "[%%] %d %s"); GLOBAL_STR(str6, "LL"); GLOBAL_STR(str7, "'repr'"); GLOBAL_STR(str8, " \"repr\""); GLOBAL_STR(str9, "[%%] %d %s %r"); GLOBAL_STR(str10, "string"); namespace varargs { // forward declare } // forward declare namespace varargs namespace varargs { // declare extern BigStr* CONST; void run_tests(); void run_benchmarks(); } // declare namespace varargs namespace varargs { // define using mylib::print_stderr; BigStr* CONST = str0; void run_tests() { mylib::print_stderr(str1); print_stderr(str2); mylib::print_stderr(StrFormat("log %d %s", 42, str4)); mylib::print_stderr(StrFormat("[%%] %d %s", 42, str6)); mylib::print_stderr(CONST); } void run_benchmarks() { BigStr* r = nullptr; StackRoot _root0(&r); r = str_concat(str7, str8); for (int i = 0; i < 10000; ++i) { mylib::print_stderr(StrFormat("[%%] %d %s %r", 123456789, str10, r)); } } } // define namespace varargs int main(int argc, char **argv) { gHeap.Init(); char* b = getenv("BENCHMARK"); if (b && strlen(b)) { // match Python's logic fprintf(stderr, "Benchmarking...\n"); varargs::run_benchmarks(); } else { varargs::run_tests(); } gHeap.CleanProcessExit(); }