IRET.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. namespace OpenVIII.Fields.Scripts.Instructions
  3. {
  4. /// <summary>
  5. /// <para>Return</para>
  6. /// If the script was called by another script, return to the another script where the current script was requested. Else the script is halted.
  7. /// </summary>
  8. /// <see cref="http://wiki.ffrtt.ru/index.php?title=FF8/Field/Script/Opcodes/006_RET"/>
  9. public sealed class IRET : JsmInstruction
  10. {
  11. #region Constructors
  12. public IRET(int unknown) => Unknown = unknown;
  13. public IRET(int unknown, IStack<IJsmExpression> stack)
  14. : this(unknown)
  15. {
  16. }
  17. #endregion Constructors
  18. #region Properties
  19. public int Unknown { get; }
  20. #endregion Properties
  21. #region Methods
  22. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services) => sw.AppendLine($"return {nameof(IRET)}({Unknown});");
  23. public override IAwaitable TestExecute(IServices services)
  24. {
  25. if (Unknown != 8)
  26. {
  27. throw new NotSupportedException($"The most common case is {nameof(IRET)}(8)." +
  28. "Probably 8 is a set of some flags." +
  29. "But sometimes there are other combinations." +
  30. "What to do in this case is still unknown.");
  31. }
  32. return BreakAwaitable.Instance;
  33. }
  34. public override string ToString() => $"{nameof(IRET)}({nameof(Unknown)}: {Unknown})";
  35. #endregion Methods
  36. }
  37. }