JMP.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. namespace OpenVIII.Fields.Scripts.Instructions
  3. {
  4. internal sealed class JMP : JsmInstruction, IJumpToOpcode
  5. {
  6. public Int32 Offset { get; set; }
  7. public JMP(Int32 offset)
  8. {
  9. Offset = offset;
  10. }
  11. public JMP(Int32 offset, IStack<IJsmExpression> stack)
  12. : this(offset)
  13. {
  14. }
  15. private Int32 _index = -1;
  16. public Int32 Index
  17. {
  18. get
  19. {
  20. if (_index == -1)
  21. throw new ArgumentException($"{nameof(JMP)} instruction isn't indexed yet.", nameof(Index));
  22. return _index;
  23. }
  24. set
  25. {
  26. //if (_index != -1)
  27. // throw new ArgumentException($"{nameof(JMP)} instruction has already been indexed: {_index}.", nameof(Index));
  28. _index = value;
  29. }
  30. }
  31. public override String ToString()
  32. {
  33. return _index < 0
  34. ? $"{nameof(JMP)}({nameof(Offset)}: {Offset})"
  35. : $"{nameof(JMP)}({nameof(Index)}: {Index})";
  36. }
  37. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  38. {
  39. // This instruction is part of conditional jumps and isn't exists as is.
  40. }
  41. public override IAwaitable Execute(IServices services)
  42. {
  43. // This instruction is part of conditional jumps and isn't exists as is.
  44. return DummyAwaitable.Instance;
  45. }
  46. }
  47. }