Esempio n. 1
0
        public override Block CompileNewState(Runtime runtime,
                                              StateForCompiler state)
        {
            ParserBlock block = new ParserBlock();

            block.Comment("start of token --------------------");

            // todo enter

            block.BeginScope();

            BlockLocal start = block.SavePosition();

            block.Emit(body.Compile(runtime, state));

            BlockLocal bodyTree = new BlockLocal(typeof(ParseTree));

            block.DeclareLocal(bodyTree);
            block.Dup();
            block.StoreLocal(bodyTree);

            BlockLabel yes = new BlockLabel("yes");

            block.BranchIfNotNo(yes);

            // todo no

            block.LoadNo();

            BlockLabel returnLabel = new BlockLabel("return");

            block.Branch(returnLabel);

            block.MarkLabel(yes);

            // todo yes

            block.LoadLexer();
            block.GetProperty(typeof(Lexer).GetProperty("Text"));
            block.LoadLocal(start);
            block.LoadLexer();
            block.GetProperty(typeof(Lexer).GetProperty("Position"));
            block.LoadLocal(start);
            block.Sub();
            block.Call(typeof(string).GetMethod("Substring", new Type[] { typeof(int), typeof(int) }));
            block.New(typeof(ParseTree).GetConstructor(new Type[] { typeof(object) }));

            block.LoadLocal(bodyTree);
            block.Call(typeof(ParseTree).GetMethod("ExtendFields"));

            block.MarkLabel(returnLabel);

            block.EndScope();

            block.Comment("end of token --------------------");

            return(block);
        }