コード例 #1
0
ファイル: SequenceExpression.cs プロジェクト: DatZach/Mond
        public SequenceBodyContext(ExpressionCompiler compiler, string name, SequenceBodyExpression sequenceBody, FunctionContext forward)
            : base(compiler, forward.FrameIndex + 1, forward.Scope, forward.FullName, name)
        {
            _forward       = forward;
            _identifierMap = new IdentifierMap();
            _index         = 0;

            SequenceBody = sequenceBody;
        }
コード例 #2
0
ファイル: SequenceExpression.cs プロジェクト: xserve98/Mond
 public SequenceBodyContext(ExpressionCompiler compiler, string name, FunctionContext parent, SequenceBodyExpression sequenceBody)
     : base(compiler, parent.ArgIndex + 1, parent.LocalIndex + 1, parent.Scope, parent.FullName, name)
 {
     SequenceBody = sequenceBody;
 }
コード例 #3
0
ファイル: SequenceExpression.cs プロジェクト: xserve98/Mond
 public SequenceContext(ExpressionCompiler compiler, string name, SequenceBodyExpression sequenceBody, FunctionContext forward)
     : base(compiler, forward.ArgIndex, forward.LocalIndex, forward.Scope, forward.FullName, name)
 {
     _sequenceBody = sequenceBody;
     _forward      = forward;
 }
コード例 #4
0
ファイル: SequenceExpression.cs プロジェクト: xserve98/Mond
        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);
        }