public void RegisterResumePoint ()
{
+ if (resume_pc != 0)
+ return;
+
if (inside_try_block == null) {
resume_pc = machine_initializer.AddResumePoint (this);
} else {
protected StateMachine (ParametersBlock block, TypeDefinition parent, MemberBase host, TypeParameters tparams, string name, MemberKind kind)
: base (block, parent, host, tparams, name, kind)
{
+ OriginalTypeParameters = tparams;
}
#region Properties
+ public TypeParameters OriginalTypeParameters { get; private set; }
+
public StateMachineMethod StateMachineMethod {
get {
return method;
//
// The state as we generate the machine
//
- Label move_next_ok;
- Label iterator_body_end;
+ protected Label move_next_ok;
protected Label move_next_error;
LocalBuilder skip_finally;
protected LocalBuilder current_pc;
#region Properties
- public Label BodyEnd {
- get {
- return iterator_body_end;
- }
- }
+ public Label BodyEnd { get; set; }
public LocalBuilder CurrentPC
{
// We only care if the PC is zero (start executing) or non-zero (don't do anything)
ec.Emit (OpCodes.Brtrue, move_next_error);
- iterator_body_end = ec.DefineLabel ();
+ BodyEnd = ec.DefineLabel ();
+
+ var async_init = this as AsyncInitializer;
+ if (async_init != null)
+ ec.BeginExceptionBlock ();
block.EmitEmbedded (ec);
- ec.MarkLabel (iterator_body_end);
+ if (async_init != null)
+ async_init.EmitCatchBlock (ec);
+
+ ec.MarkLabel (BodyEnd);
EmitMoveNextEpilogue (ec);
ec.EmitInt (0);
ec.Emit (OpCodes.Ret);
}
+
+ ec.MarkLabel (move_next_ok);
}
void EmitMoveNext (EmitContext ec)
ec.MarkLabel (labels[0]);
- iterator_body_end = ec.DefineLabel ();
+ BodyEnd = ec.DefineLabel ();
block.EmitEmbedded (ec);
- ec.MarkLabel (iterator_body_end);
+ ec.MarkLabel (BodyEnd);
if (async_init != null) {
- var catch_value = LocalVariable.CreateCompilerGenerated (ec.Module.Compiler.BuiltinTypes.Exception, block, Location);
-
- ec.BeginCatchBlock (catch_value.Type);
- catch_value.EmitAssign (ec);
-
- ec.EmitThis ();
- ec.EmitInt ((int) IteratorStorey.State.After);
- ec.Emit (OpCodes.Stfld, storey.PC.Spec);
-
- ((AsyncTaskStorey) async_init.Storey).EmitSetException (ec, new LocalVariableReference (catch_value, Location));
-
- ec.Emit (OpCodes.Leave, move_next_ok);
- ec.EndExceptionBlock ();
+ async_init.EmitCatchBlock (ec);
}
ec.Mark (Block.Original.EndLocation);