// examples/asdl_generated // BEGIN mycpp output #include "gc_heap.h" using gc_heap::Alloc; using gc_heap::kZeroMask; using gc_heap::StackRoots; #include "my_runtime.h" #include "mylib2.h" using gc_heap::NewStr; using gc_heap::NewList; using gc_heap::NewDict; GLOBAL_STR(str0, "x = %d"); namespace asdl_generated { // forward declare class arith_expr_t; class arith_expr__Const; } // forward declare namespace asdl_generated namespace asdl_generated { // declare class arith_expr_t : public gc_heap::Obj { public: arith_expr_t(); DISALLOW_COPY_AND_ASSIGN(arith_expr_t) }; class arith_expr__Const : public arith_expr_t { public: arith_expr__Const(int i); int i; DISALLOW_COPY_AND_ASSIGN(arith_expr__Const) }; void run_tests(); void run_benchmarks(); inline Str* fmt0(int a0) { gBuf.reset(); gBuf.write_const("x = ", 4); gBuf.format_d(a0); return gBuf.getvalue(); } } // declare namespace asdl_generated namespace asdl_generated { // define arith_expr_t::arith_expr_t() : gc_heap::Obj(Tag::FixedSize, kZeroMask, sizeof(arith_expr_t)) { ; // pass } arith_expr__Const::arith_expr__Const(int i) : arith_expr_t() { this->i = i; } void run_tests() { asdl_generated::arith_expr__Const* x = nullptr; StackRoots _roots({&x}); x = Alloc(5); println_stderr(fmt0(x->i)); } void run_benchmarks() { int i; int n; asdl_generated::arith_expr__Const* x = nullptr; StackRoots _roots({&x}); i = 0; n = 1000000; while (i < n) { x = Alloc(i); i = (i + 1); } } } // define namespace asdl_generated int main(int argc, char **argv) { // gc_heap::gHeap.Init(512); gc_heap::gHeap.Init(128 << 10); // 128 KiB; doubling in size // gc_heap::gHeap.Init(400 << 20); // 400 MiB to avoid garbage collection if (getenv("BENCHMARK")) { fprintf(stderr, "Benchmarking...\n"); asdl_generated::run_benchmarks(); } else { asdl_generated::run_tests(); } }