Jsm.Control.Goto.cs 1.3 KB

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