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); }
public override void Generate(ModuleContext context) { var jumpEnd = new LuaLabel(context.vm, null, 0); context.OnBreak(jumpEnd); context.Add(new ByteCode { opCode = ByteCode.OpCode.Jump, opArg = jumpEnd }); }
public void EndLoop(LuaLabel endLabel) { var queue = breakStack.Pop(); while (queue.Count > 0) { var item = queue.Dequeue(); item.value = endLabel.value; item.index = endLabel.index; } }
public override void Generate(ModuleContext context) { condExp.Generate(context); var endLabel = new LabelExpression(context.NewUID(), condExp.debugInfo); var jumpEnd = new LuaLabel(context.vm, endLabel.value, endLabel.index); context.Add(new ByteCode { opCode = ByteCode.OpCode.JumpNot, opArg = jumpEnd }); moduleExp.Generate(context); endLabel.Generate(context); jumpEnd.index = endLabel.index; }
public void Jump(LuaLabel label) { position = label.index; }
public void OnBreak(LuaLabel label) { breakStack.Peek().Enqueue(label); }