Jsm.Control.Goto.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using OpenVIII.Fields.Scripts.Instructions;
  2. using System.Collections.Generic;
  3. namespace OpenVIII.Fields.Scripts
  4. {
  5. public static partial class Jsm
  6. {
  7. #region Classes
  8. public static partial class Control
  9. {
  10. #region Classes
  11. public sealed class Goto : IJsmControl, IFormattableScript
  12. {
  13. #region Fields
  14. private readonly List<JsmInstruction> _instructions;
  15. private readonly int _label;
  16. private readonly Segment _segment;
  17. #endregion Fields
  18. #region Constructors
  19. public Goto(List<JsmInstruction> instructions, int from, int label)
  20. {
  21. _instructions = instructions;
  22. _segment = new ExecutableSegment(from, from + 1)
  23. {
  24. _instructions[from]
  25. };
  26. _label = label;
  27. }
  28. #endregion Constructors
  29. #region Methods
  30. public IEnumerable<Segment> EnumerateSegments()
  31. {
  32. yield return _segment;
  33. }
  34. public void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.AppendLine($"goto LABEL{_label};");
  35. public override string ToString() => $"goto {_segment.From} -> {_label} ({_instructions[_label]})";
  36. #endregion Methods
  37. }
  38. #endregion Classes
  39. }
  40. #endregion Classes
  41. }
  42. }