From ab9c7b85593d84d6af46870ceec96911ea7343b1 Mon Sep 17 00:00:00 2001 From: Jonathan Protzenko Date: Thu, 20 Aug 2015 18:35:30 -0700 Subject: [PATCH] Wrap all the C++-generated code in a namespace. Avoids collisions with the global functions defined by the DAL. --- editor/embedded.ts | 16 ++++++++++------ embedded/emitter.ts | 7 ++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/editor/embedded.ts b/editor/embedded.ts index f4c99608..cfd410da 100644 --- a/editor/embedded.ts +++ b/editor/embedded.ts @@ -73,17 +73,21 @@ module TDev { var compiled = everything.map((a: J.JApp, i: number) => compile1(everything, resolveMap[i], a)); return Promise.as( compiled.map(x => x.prelude) - .concat(compiled.map(x => x.tPrototypes)) - .concat(compiled.map(x => x.tCode)) - .concat(compiled.map(x => x.prototypes)) - .concat(compiled.map(x => x.code)) + .concat(["namespace touch_develop {"]) + .concat(compiled.map(x => x.tPrototypes)) + .concat(compiled.map(x => x.tCode)) + .concat(compiled.map(x => x.prototypes)) + .concat(compiled.map(x => x.code)) + .concat(["}"]) .filter(x => x != "") - .join("\n") + + .join("\n") + "\n" + (a.isLibrary ? "\nvoid app_main() {\n"+ " uBit.display.scroll(\"Error: trying to run a library\");\n"+ "}\n" - : "") + : "\nvoid app_main() {\n"+ + " touch_develop::app_main();\n"+ + "}\n") ); }); } diff --git a/embedded/emitter.ts b/embedded/emitter.ts index 1c685a4c..36a0ee20 100644 --- a/embedded/emitter.ts +++ b/embedded/emitter.ts @@ -480,16 +480,16 @@ module TDev { var n = H.mangleName(r.name); return [ e.indent + "struct " + n + "_;", - e.indent + "typedef ManagedType< " + n + "_> " + n + ";", + e.indent + "typedef ManagedType<" + n + "_> " + n + ";", ].join("\n"); } private wrapNamespaceIf(s: string) { if (this.libName != null) return (s.length - ? "namespace "+this.libName+" {\n"+ + ? " namespace "+this.libName+" {\n"+ s + - "\n}" + "\n }" : ""); else return s; @@ -506,6 +506,7 @@ module TDev { // This function runs over all declarations. After execution, the three // member fields [prelude], [prototypes] and [code] are filled accordingly. public visitApp(e: EmitterEnv, decls: J.JDecl[]) { + e = indent(e); if (this.libName) e = indent(e);