// 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, "CONST module1"); GLOBAL_STR(str1, "func1"); GLOBAL_STR(str2, "cat"); GLOBAL_STR(str3, "CONST module2"); GLOBAL_STR(str4, "func2"); GLOBAL_STR(str5, "white"); GLOBAL_STR(str6, "brown"); GLOBAL_STR(str7, "result = %d"); GLOBAL_STR(str8, "%s dog: meow"); GLOBAL_STR(str9, "%s sphinx"); GLOBAL_STR(str10, "abstract"); namespace module1 { // forward declare class Cat; } // forward declare namespace module1 namespace module2 { // forward declare } // forward declare namespace module2 namespace modules { // forward declare class Dog; class Sphinx; } // forward declare namespace modules namespace module1 { // declare extern Str* CONST1; void func1(); int fortytwo(); class Cat : public gc_heap::Obj { public: Cat(); virtual void Speak(); virtual void AbstractMethod(); DISALLOW_COPY_AND_ASSIGN(Cat) }; } // declare namespace module1 namespace module2 { // declare extern Str* CONST2; void func2(); } // declare namespace module2 namespace modules { // declare void run_tests(); void run_benchmarks(); class Dog : public gc_heap::Obj { public: Dog(Str* color); void Speak(); Str* color; DISALLOW_COPY_AND_ASSIGN(Dog) }; class Sphinx : public module1::Cat { public: Sphinx(Str* color); virtual void Speak(); virtual void AbstractMethod(); Str* color; DISALLOW_COPY_AND_ASSIGN(Sphinx) }; inline Str* fmt0(int a0) { gBuf.reset(); gBuf.write_const("result = ", 9); gBuf.format_d(a0); return gBuf.getvalue(); } inline Str* fmt1(Str* a0) { gBuf.reset(); gBuf.format_s(a0); gBuf.write_const(" dog: meow", 10); return gBuf.getvalue(); } inline Str* fmt2(Str* a0) { gBuf.reset(); gBuf.format_s(a0); gBuf.write_const(" sphinx", 7); return gBuf.getvalue(); } } // declare namespace modules namespace module1 { // define Str* CONST1 = str0; void func1() { println_stderr(str1); println_stderr(module2::CONST2); } int fortytwo() { return 42; } Cat::Cat() : gc_heap::Obj(Tag::FixedSize, kZeroMask, sizeof(Cat)) { ; // pass } void Cat::Speak() { println_stderr(str2); } void Cat::AbstractMethod() { throw Alloc(); } } // define namespace module1 namespace module2 { // define Str* CONST2 = str3; void func2() { println_stderr(str4); println_stderr(module1::CONST1); } } // define namespace module2 namespace modules { // define using module2::func2; void run_tests() { modules::Dog* dog = nullptr; module1::Cat* cat = nullptr; modules::Sphinx* cat2 = nullptr; StackRoots _roots({&dog, &cat, &cat2}); module1::func1(); func2(); dog = Alloc(str5); dog->Speak(); cat = Alloc(); cat->Speak(); cat2 = Alloc(str6); cat2->Speak(); cat = cat2; cat->Speak(); cat->AbstractMethod(); } void run_benchmarks() { int i; int n; int result; i = 0; n = 2000000; result = 0; while (i < n) { result += module1::fortytwo(); i = (i + 1); } println_stderr(fmt0(result)); } Dog::Dog(Str* color) : gc_heap::Obj(Tag::FixedSize, kZeroMask, sizeof(Dog)) { this->color = color; } void Dog::Speak() { println_stderr(fmt1(this->color)); } Sphinx::Sphinx(Str* color) : module1::Cat() { this->color = color; } void Sphinx::Speak() { println_stderr(fmt2(this->color)); } void Sphinx::AbstractMethod() { println_stderr(str10); } } // define namespace modules