protected override void TranslateForLoop(List<string> output, ForLoop exec) { this.Translate(output, exec.Init); output.Add(this.CurrentTabIndention); output.Add(this.Shorten("while (")); this.TranslateExpression(output, exec.Condition); if (this.isEgyptian) { output.Add(this.Shorten(") {") + this.NL); } else { output.Add(")"); output.Add(this.NL); output.Add(this.CurrentTabIndention); output.Add("{"); output.Add(this.NL); } this.CurrentIndention++; this.Translate(output, exec.Code); this.Translate(output, exec.Step); this.CurrentIndention--; output.Add(this.CurrentTabIndention); output.Add("}" + this.NL); }
private void CompileForLoop(Parser parser, ByteBuffer buffer, ForLoop forLoop) { this.Compile(parser, buffer, forLoop.Init); ByteBuffer codeBuffer = new ByteBuffer(); this.Compile(parser, codeBuffer, forLoop.Code); codeBuffer.ResolveContinues(true); // resolve continues as jump-to-end before you add the step instructions. this.Compile(parser, codeBuffer, forLoop.Step); ByteBuffer forBuffer = new ByteBuffer(); this.CompileExpression(parser, forBuffer, forLoop.Condition, true); forBuffer.Add(forLoop.Condition.FirstToken, OpCode.JUMP_IF_FALSE, codeBuffer.Size + 1); // +1 to go past the jump I'm about to add. forBuffer.Concat(codeBuffer); forBuffer.Add(null, OpCode.JUMP, -forBuffer.Size - 1); forBuffer.ResolveBreaks(); buffer.Concat(forBuffer); }
protected abstract void TranslateForLoop(List<string> output, ForLoop forLoop);