diff --git a/embedded/emitter.ts b/embedded/emitter.ts index be3141ac..41d573fe 100644 --- a/embedded/emitter.ts +++ b/embedded/emitter.ts @@ -88,7 +88,10 @@ module TDev { env.indent + this.visit(env, expr.tree) + ";"); } - public visitExprHolder(env: H.Env, locals: J.JLocalDef[], expr: J.JExprHolder) { + public visitExprHolder(env: H.Env, locals: J.JLocalDef[], expr: J.JExpr) { + if (H.isInitialRecordAssignment(locals, expr)) + return this.visit(env, locals[0])+"(new "+H.mkType(env, this.libraryMap, locals[0].type)+"_)"; + var decls = locals.map(d => { // Side-effect: marks [d] as promoted, if needed. var decl = this.visit(env, d); @@ -122,7 +125,7 @@ module TDev { var l = H.resolveLocal(env, name, id); if (H.shouldPromoteToRef(env, type, isByRef)) { H.markPromoted(env, id); - return "ManagedType<"+ t + "> " + l + "(new "+t+")"; + return "Ref<"+ t + "> " + l; } else { return t + " " + l; } diff --git a/embedded/helpers.ts b/embedded/helpers.ts index a9182a69..89f5765a 100644 --- a/embedded/helpers.ts +++ b/embedded/helpers.ts @@ -479,6 +479,21 @@ module TDev { return x.nodeType == "stringLiteral" && ( x).value; } + export function isInitialRecordAssignment(locals: J.JLocalDef[], expr: J.JExpr) { + return ( + locals.length == 1 && + expr.nodeType == "call" && + ( expr).name == ":=" && + ( expr).args.length == 2 && + ( expr).args[1].nodeType == "call" && + isRecordConstructor( + ( ( expr).args[1]).name, + ( ( expr).args[1]).args) && + ( expr).args[0].nodeType == "localRef" && + ( ( expr).args[0]).localId == locals[0].id + ); + } + export function willCompile (f: J.JAction) { return isShimBody(f.body) == null; }