123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- 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<ExecutionSet> ExecutionStack { get; } = new Stack<ExecutionSet>();
- 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();
- }
- }
- }
|