protected void EmitGeneratorBody() { this.BeginBlock(); var asyncTryVisitor = new AsyncTryVisitor(); this.Node.AcceptChildren(asyncTryVisitor); var needTry = true; this.Emitter.AsyncVariables.Add(JS.Vars.ASYNC_JUMP); if (needTry) { this.Emitter.AsyncVariables.Add(JS.Vars.ASYNC_RETURN_VALUE); this.WriteTry(); this.BeginBlock(); } this.WriteFor(); this.Write("(;;) "); this.BeginBlock(); this.WriteSwitch(); this.Write("(" + JS.Vars.ASYNC_STEP + ") "); this.BeginBlock(); this.Step = 0; var writer = this.SaveWriter(); this.AddAsyncStep(); this.Body.AcceptVisitor(this.Emitter); this.RestoreWriter(writer); this.InjectSteps(); this.WriteNewLine(); this.EndBlock(); this.WriteNewLine(); this.EndBlock(); if (needTry) { if (!this.Emitter.Locals.ContainsKey(JS.Vars.ASYNC_E)) { this.AddLocal(JS.Vars.ASYNC_E, null, AstType.Null); } this.WriteNewLine(); this.EndBlock(); this.Write(" catch(" + JS.Vars.ASYNC_E1 + ") "); this.BeginBlock(); this.Write(JS.Vars.ASYNC_E + " = " + JS.Types.System.Exception.CREATE + "(" + JS.Vars.ASYNC_E1 + ");"); this.WriteNewLine(); this.InjectCatchHandlers(); this.WriteNewLine(); this.EndBlock(); } this.WriteNewLine(); this.EndBlock(); }
protected void EmitAsyncBody() { this.BeginBlock(); var asyncTryVisitor = new AsyncTryVisitor(); this.Node.AcceptChildren(asyncTryVisitor); var needTry = asyncTryVisitor.Found || this.IsTaskReturn; this.Emitter.AsyncVariables.Add(JS.Vars.ASYNC_JUMP); if (needTry) { if (this.IsTaskReturn) { this.Emitter.AsyncVariables.Add(JS.Vars.ASYNC_TCS + " = new " + JS.Types.TASK_COMPLETION_SOURCE + "()"); } this.Emitter.AsyncVariables.Add(JS.Vars.ASYNC_RETURN_VALUE); this.Write("try"); this.WriteSpace(); this.BeginBlock(); } this.Write("for (;;) "); this.BeginBlock(); this.WriteIndent(); int checkerPos = this.Emitter.Output.Length; this.WriteNewLine(); this.Write("switch (" + JS.Vars.ASYNC_STEP + ") "); this.BeginBlock(); this.Step = 0; var writer = this.SaveWriter(); this.AddAsyncStep(); if (this.Body.Parent is LambdaExpression && this.Body is Expression && this.IsTaskReturn) { new ReturnBlock(this.Emitter, (Expression)this.Body).Emit(); } else { this.Body.AcceptVisitor(this.Emitter); } this.RestoreWriter(writer); this.InjectSteps(); this.WriteNewLine(); this.EndBlock(); this.InjectStepsChecker(checkerPos); this.WriteNewLine(); this.EndBlock(); if (needTry) { if (!this.Emitter.Locals.ContainsKey(JS.Vars.ASYNC_E)) { this.AddLocal(JS.Vars.ASYNC_E, null, AstType.Null); } this.WriteNewLine(); this.EndBlock(); this.Write(" catch(" + JS.Vars.ASYNC_E1 + ") "); this.BeginBlock(); this.Write(JS.Vars.ASYNC_E + " = " + JS.Types.SYSTEM_EXCEPTION + ".create(" + JS.Vars.ASYNC_E1 + ");"); this.WriteNewLine(); this.InjectCatchHandlers(); this.WriteNewLine(); this.EndBlock(); } this.WriteNewLine(); this.EndBlock(); }
protected void EmitAsyncBody() { var isLambda = this.LambdaExpression != null || this.AnonymousMethodExpression != null; this.BeginBlock(); var asyncTryVisitor = new AsyncTryVisitor(); this.Node.AcceptVisitor(asyncTryVisitor); var needTry = asyncTryVisitor.Found || this.IsTaskReturn; this.Emitter.AsyncVariables.Add("$jumpFromFinally"); if (needTry) { if (this.IsTaskReturn) { this.Emitter.AsyncVariables.Add("$returnTask = new Bridge.Task()"); } this.Emitter.AsyncVariables.Add("$returnValue"); this.Write("try"); this.WriteSpace(); this.BeginBlock(); } this.Write("for (;;) "); this.BeginBlock(); this.Write("switch ($step) "); this.BeginBlock(); this.Step = 0; var writer = this.SaveWriter(); this.AddAsyncStep(); this.Body.AcceptVisitor(this.Emitter); this.RestoreWriter(writer); this.InjectSteps(); this.WriteNewLine(); this.EndBlock(); this.WriteNewLine(); this.EndBlock(); if (needTry) { this.WriteNewLine(); this.EndBlock(); this.Write(" catch($e1) "); this.BeginBlock(); this.Write("$e1 = Bridge.Exception.create($e1);"); this.WriteNewLine(); this.InjectCatchHandlers(); this.WriteNewLine(); this.EndBlock(); } this.WriteNewLine(); this.EndBlock(); }
protected void EmitAsyncBody() { this.BeginBlock(); var asyncTryVisitor = new AsyncTryVisitor(); this.Node.AcceptChildren(asyncTryVisitor); var needTry = asyncTryVisitor.Found || this.IsTaskReturn; this.Emitter.AsyncVariables.Add("$jumpFromFinally"); if (needTry) { if (this.IsTaskReturn) { this.Emitter.AsyncVariables.Add("$tcs = new Bridge.TaskCompletionSource()"); } this.Emitter.AsyncVariables.Add("$returnValue"); this.Write("try"); this.WriteSpace(); this.BeginBlock(); } this.Write("for (;;) "); this.BeginBlock(); this.WriteIndent(); int checkerPos = this.Emitter.Output.Length; this.WriteNewLine(); this.Write("switch ($step) "); this.BeginBlock(); this.Step = 0; var writer = this.SaveWriter(); this.AddAsyncStep(); this.Body.AcceptVisitor(this.Emitter); this.RestoreWriter(writer); this.InjectSteps(); this.WriteNewLine(); this.EndBlock(); this.InjectStepsChecker(checkerPos); this.WriteNewLine(); this.EndBlock(); if (needTry) { if (!this.Emitter.Locals.ContainsKey("$async_e")) { this.AddLocal("$async_e", AstType.Null); } this.WriteNewLine(); this.EndBlock(); this.Write(" catch($async_e1) "); this.BeginBlock(); this.Write("$async_e = Bridge.Exception.create($async_e1);"); this.WriteNewLine(); this.InjectCatchHandlers(); this.WriteNewLine(); this.EndBlock(); } this.WriteNewLine(); this.EndBlock(); }
protected void EmitAsyncBody() { this.BeginBlock(); var asyncTryVisitor = new AsyncTryVisitor(); this.Node.AcceptVisitor(asyncTryVisitor); var needTry = asyncTryVisitor.Found || this.IsTaskReturn; this.Emitter.AsyncVariables.Add("$jumpFromFinally"); if (needTry) { if (this.IsTaskReturn) { this.Emitter.AsyncVariables.Add("$returnTask = new Bridge.Task()"); } this.Emitter.AsyncVariables.Add("$returnValue"); this.Write("try"); this.WriteSpace(); this.BeginBlock(); } this.Write("for (;;) "); this.BeginBlock(); this.WriteIndent(); int checkerPos = this.Emitter.Output.Length; this.WriteNewLine(); this.Write("switch ($step) "); this.BeginBlock(); this.Step = 0; var writer = this.SaveWriter(); this.AddAsyncStep(); this.Body.AcceptVisitor(this.Emitter); this.RestoreWriter(writer); this.InjectSteps(); this.WriteNewLine(); this.EndBlock(); this.InjectStepsChecker(checkerPos); this.WriteNewLine(); this.EndBlock(); if (needTry) { this.WriteNewLine(); this.EndBlock(); this.Write(" catch($e1) "); this.BeginBlock(); this.Write("$e1 = Bridge.Exception.create($e1);"); this.WriteNewLine(); this.InjectCatchHandlers(); this.WriteNewLine(); this.EndBlock(); } this.WriteNewLine(); this.EndBlock(); }