IRET.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.ComponentModel;
  3. namespace OpenVIII.Fields.Scripts.Instructions
  4. {
  5. /// <summary>
  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. internal sealed class IRET : JsmInstruction
  9. {
  10. public Int32 Unknown { get; }
  11. public IRET(Int32 unknown)
  12. {
  13. Unknown = unknown;
  14. }
  15. public IRET(Int32 unknown, IStack<IJsmExpression> stack)
  16. : this(unknown)
  17. {
  18. }
  19. public override String ToString()
  20. {
  21. return $"{nameof(IRET)}({nameof(Unknown)}: {Unknown})";
  22. }
  23. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  24. {
  25. sw.AppendLine($"return {nameof(IRET)}({Unknown});");
  26. }
  27. public override IAwaitable TestExecute(IServices services)
  28. {
  29. if (Unknown != 8)
  30. {
  31. throw new NotSupportedException($"The most common case is {nameof(IRET)}(8)." +
  32. "Probably 8 is a set of some flags." +
  33. "But sometimes there are other combinations." +
  34. "What to do in this case is still unknown.");
  35. }
  36. return BreakAwaitable.Instance;
  37. }
  38. }
  39. }