EraRuntime.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using NTERA.Core;
  5. using NTERA.EmuEra.Game.EraEmu.Content;
  6. using NTERA.Engine.Compiler;
  7. namespace NTERA.Engine.Runtime
  8. {
  9. public class EraRuntime : IScriptEngine
  10. {
  11. public IExecutionProvider ExecutionProvider { get; }
  12. public IConsole Console { get; protected set; }
  13. public Stack<ExecutionSet> ExecutionStack { get; } = new Stack<ExecutionSet>();
  14. public EraRuntime(IExecutionProvider executionProvider)
  15. {
  16. ExecutionProvider = executionProvider;
  17. }
  18. public bool Initialize(IConsole console)
  19. {
  20. Console = console;
  21. return true;
  22. }
  23. public void Start()
  24. {
  25. Console.PrintSystemLine("EraJIT x64 0.0.0.0");
  26. Console.PrintSystemLine("");
  27. Call(ExecutionProvider.DefinedProcedures.First(x => x.Name == "SYSTEM_TITLE"));
  28. System.Threading.Thread.Sleep(-1);
  29. }
  30. public void Call(FunctionDefinition function)
  31. {
  32. var executionContents = ExecutionProvider.GetExecutionNodes(function);
  33. var executionSet = new ExecutionSet
  34. {
  35. Nodes = executionContents.ToList(),
  36. SelfDefinition = function
  37. };
  38. ExecutionStack.Push(executionSet);
  39. ExecuteSet(executionSet);
  40. ExecutionStack.Pop();
  41. }
  42. protected void ExecuteSet(ExecutionSet set)
  43. {
  44. for (; set.Position < set.Nodes.Count; set.Position++)
  45. {
  46. ExecutionNode node = set.Nodes[set.Position];
  47. switch (node.Type)
  48. {
  49. case "statement":
  50. string statement = node.Metadata["name"];
  51. if (statement == "DRAWLINE")
  52. Base.Keywords.DrawLine(this, set);
  53. else
  54. {
  55. throw new Exception($"Unknown statement: '{statement}'");
  56. }
  57. break;
  58. default:
  59. throw new Exception($"Unknown node type: '{node.Type}'");
  60. }
  61. }
  62. }
  63. public void InputString(string input)
  64. {
  65. throw new NotImplementedException();
  66. }
  67. public void InputInteger(long input)
  68. {
  69. throw new NotImplementedException();
  70. }
  71. public void InputSystemInteger(long input)
  72. {
  73. throw new NotImplementedException();
  74. }
  75. public CroppedImage GetImage(string name)
  76. {
  77. throw new NotImplementedException();
  78. }
  79. }
  80. }