public virtual void CompileBody(FunctionContext context) { var stack = 0; stack += context.Bind(context.Label); stack += context.Enter(); if (OtherArguments != null) { stack += context.VarArgs(Arguments.Count); } stack += Block.Compile(context); stack += context.LoadUndefined(); stack += context.Return(); CheckStack(stack, 0); }
public override void CompileBody(FunctionContext context) { var stack = 0; EndLabel = context.MakeLabel("state_end"); stack += context.Bind(context.Label); stack += context.Enter(); // jump to state label stack += context.Load(State); stack += context.JumpTable(0, _stateLabels); stack += context.Jump(EndLabel); // first state stack += context.Bind(MakeStateLabel(context)); // compile body stack += Block.Compile(context); // set enumerator.current to undefined // do this before EndLabel so we dont overwrite return values stack += context.LoadUndefined(); stack += context.Load(Enumerable); stack += context.StoreField(context.String("current")); stack += context.Bind(EndLabel); // set state to end stack += context.Load(context.Number(-1)); stack += context.Store(State); stack += context.LoadFalse(); stack += context.Return(); CheckStack(stack, 0); }
public override void CompileBody(FunctionContext context) { var state = context.DefineInternal("state"); var enumerable = context.DefineInternal("enumerable"); var stack = 0; var bodyToken = new Token(Token, TokenType.Fun, null); var body = new SequenceBodyExpression(bodyToken, null, Block, "moveNext", state, enumerable); var seqContext = new SequenceContext(context.Compiler, "moveNext", body, context); var getEnumerator = context.MakeFunction("getEnumerator"); getEnumerator.Function(getEnumerator.FullName); getEnumerator.Bind(getEnumerator.Label); getEnumerator.Enter(); getEnumerator.Load(enumerable); getEnumerator.Return(); var dispose = context.MakeFunction("dispose"); dispose.Function(dispose.FullName); dispose.Bind(dispose.Label); dispose.Enter(); dispose.LoadUndefined(); dispose.Return(); stack += context.Bind(context.Label); stack += context.Enter(); if (OtherArguments != null) { stack += context.VarArgs(Arguments.Count); } stack += context.Load(context.Number(0)); stack += context.Store(state); stack += context.NewObject(); stack += context.Dup(); stack += context.LoadUndefined(); stack += context.Swap(); stack += context.StoreField(context.String("current")); stack += context.Dup(); stack += body.Compile(seqContext); stack += context.Swap(); stack += context.StoreField(context.String("moveNext")); stack += context.Dup(); stack += context.Closure(getEnumerator.Label); stack += context.Swap(); stack += context.StoreField(context.String("getEnumerator")); stack += context.Dup(); stack += context.Closure(dispose.Label); stack += context.Swap(); stack += context.StoreField(context.String("dispose")); stack += context.Store(enumerable); stack += context.Load(enumerable); stack += context.Return(); CheckStack(stack, 0); }