using System; using System.Collections.Generic; using System.Linq; using NTERA.Core; using NTERA.EmuEra.Game.EraEmu.Content; using NTERA.Engine.Compiler; namespace NTERA.Engine.Runtime { public class EraRuntime : IScriptEngine { public IExecutionProvider ExecutionProvider { get; } public IConsole Console { get; protected set; } public Stack ExecutionStack { get; } = new Stack(); public EraRuntime(IExecutionProvider executionProvider) { ExecutionProvider = executionProvider; } public bool Initialize(IConsole console) { Console = console; return true; } public void Start() { Console.PrintSystemLine("EraJIT x64 0.0.0.0"); Console.PrintSystemLine(""); Call(ExecutionProvider.DefinedProcedures.First(x => x.Name == "SYSTEM_TITLE")); System.Threading.Thread.Sleep(-1); } public void Call(FunctionDefinition function) { var executionContents = ExecutionProvider.GetExecutionNodes(function); var executionSet = new ExecutionSet { Nodes = executionContents.ToList(), SelfDefinition = function }; ExecutionStack.Push(executionSet); ExecuteSet(executionSet); ExecutionStack.Pop(); } protected void ExecuteSet(ExecutionSet set) { for (; set.Position < set.Nodes.Count; set.Position++) { ExecutionNode node = set.Nodes[set.Position]; switch (node.Type) { case "statement": string statement = node.Metadata["name"]; if (statement == "DRAWLINE") Base.Keywords.DrawLine(this, set); else { throw new Exception($"Unknown statement: '{statement}'"); } break; default: throw new Exception($"Unknown node type: '{node.Type}'"); } } } public void InputString(string input) { throw new NotImplementedException(); } public void InputInteger(long input) { throw new NotImplementedException(); } public void InputSystemInteger(long input) { throw new NotImplementedException(); } public CroppedImage GetImage(string name) { throw new NotImplementedException(); } } }