private static void MakeBranch(TokenizerOutput program, TLine line, Stack <LoopData> loopStack) { var kwif = (KwIf)line.Statement; var newIf = new KwrJumpIfNotTrue(kwif.Condition, -1); program.Program.Add(line.Clone(newIf)); // placeholder foreach (Statement s in kwif.Statements) { TokenizeStatement(program, line.Clone(s), loopStack); } if (kwif.ElseStatements == null) { newIf.JumpPos = program.Program.Count; } else { var gt = new KwrGoto(-1, true); program.Program.Add(line.Clone(gt)); newIf.JumpPos = program.Program.Count; foreach (Statement s in kwif.ElseStatements) { TokenizeStatement(program, line.Clone(s), loopStack); } gt.JumpPos = program.Program.Count; } }
private static void MakeOnStatement(TokenizerOutput program, TLine line) { var kw = (KwOn)line.Statement; for (int j = 0; j < kw.JumpList.Count; ++j) { var cnd = new NumBoolBinaryOperator(kw.Statement, new NumConstant((j + 1).ToString()), "=="); var ifc = new KwrJumpIfNotTrue(cnd, -1); program.Program.Add(line.Clone(ifc)); int jumpPos = kw.JumpList[j].Value; KwrJump jmp = kw.Kind == KwOn.OnKind.Goto ? new KwrGoto(jumpPos, false) : (KwrJump) new KwrGosub(jumpPos, false); program.Program.Add(line.Clone(jmp)); ifc.JumpPos = program.Program.Count; } }