예제 #1
0
        public override void Generate(ModuleContext context)
        {
            var funcExp = new WordExpression(context.NewUID(), debugInfo);
            var statExp = new WordExpression(context.NewUID(), debugInfo);
            var varExp  = new WordExpression(context.NewUID(), debugInfo);
            var initExp = new DefineNExpression(new List <Expression> {
                funcExp, statExp, varExp
            }, items2List);
            var whileExp = new LoopExpression(moduleExp);
            var retExp   = new WordExpression(context.NewUID(), debugInfo);
            var retDef   = new DefineExpression(retExp, new CallExpression(funcExp, new RightList1Expression(new List <Expression> {
                statExp, varExp
            })));
            var callExp = new UnpackExpression(retExp);
            var nextExp = new BindNExpression(new LeftList2Expression(items1List), new RightList2Expression(new List <Expression> {
                callExp
            }));
            var rebindExp = new BindExpression(varExp, items1List[0]);
            var breakExp  = new BreakExpression();
            var exitExp   = new IfExpression(new EqualExpression(varExp, new NilExpression()), new ModuleExpression(new List <Expression> {
                breakExp
            }));

            moduleExp.itemsList.InsertRange(0, new Expression[] { retDef, nextExp, rebindExp, exitExp });
            initExp.Generate(context);
            whileExp.Generate(context);
        }
예제 #2
0
        public override void Generate(ModuleContext context)
        {
            context.BeginLoop();
            var bindIndex = new BindExpression(indexExp, beginExp);

            bindIndex.Generate(context);
            context.Add(new ByteCode {
                opCode = ByteCode.OpCode.Clear
            });
            var beginLabel = new LabelExpression(context.NewUID(), indexExp.debugInfo);

            beginLabel.Generate(context);
            var jumpBegin = new LuaLabel(context.vm, beginLabel.value, beginLabel.index);

            condExp.Generate(context);
            var endLabel = new LabelExpression(context.NewUID(), indexExp.debugInfo);
            var jumpEnd  = new LuaLabel(context.vm, endLabel.value, endLabel.index);

            context.Add(new ByteCode {
                opCode = ByteCode.OpCode.JumpIf, opArg = jumpEnd
            });
            context.Add(new ByteCode {
                opCode = ByteCode.OpCode.Clear
            });
            moduleExp.Generate(context);
            changeExp.Generate(context);
            context.Add(new ByteCode {
                opCode = ByteCode.OpCode.Jump, opArg = jumpBegin
            });
            endLabel.Generate(context);
            jumpEnd.index = endLabel.index;
            context.EndLoop(jumpEnd);
        }
예제 #3
0
        public override void Generate(ModuleContext context)
        {
            var funcExp = new FunctionAExpression(context.NewUID(), argsList, moduleExp);
            var propExp = new PropertyExpression(targetExp, ParserHelper.Word2String(nameExp));
            var bindExp = new BindExpression(propExp, funcExp);

            bindExp.Generate(context);
        }