|
@@ -26,9 +26,12 @@ namespace NTERA.Engine.Runtime
|
|
|
public Value LastInputValue { get; protected set; }
|
|
|
public AutoResetEvent InputResetEvent { get; } = new AutoResetEvent(false);
|
|
|
|
|
|
- public EraRuntime(IExecutionProvider executionProvider)
|
|
|
+ public bool IgnoreErrors = false;
|
|
|
+
|
|
|
+ public EraRuntime(IExecutionProvider executionProvider, bool ignoreErrors)
|
|
|
{
|
|
|
ExecutionProvider = executionProvider;
|
|
|
+ IgnoreErrors = ignoreErrors;
|
|
|
}
|
|
|
|
|
|
public bool Initialize(IConsole console)
|
|
@@ -44,7 +47,7 @@ namespace NTERA.Engine.Runtime
|
|
|
|
|
|
TotalProcedureDefinitions.AddRange(ExecutionProvider.DefinedProcedures);
|
|
|
TotalProcedureDefinitions.AddRange(BaseDefinitions.DefaultGlobalFunctions);
|
|
|
-
|
|
|
+
|
|
|
foreach (var variable in BaseDefinitions.DefaultGlobalVariables)
|
|
|
{
|
|
|
var globalVariable = new Variable(variable.Name, variable.ValueType)
|
|
@@ -63,6 +66,17 @@ namespace NTERA.Engine.Runtime
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ private void PrintStackTrace()
|
|
|
+ {
|
|
|
+ Console.PrintError("Stack trace:");
|
|
|
+
|
|
|
+ foreach (var stackMember in ExecutionStack)
|
|
|
+ {
|
|
|
+ string name = stackMember.IsAnonymous ? "<anonymous>" : $"@{stackMember.SelfDefinition.Name}";
|
|
|
+ Console.PrintError($" - {name} ({stackMember.SelfDefinition.Position} > {stackMember.SelfDefinition.Filename})");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void Start()
|
|
|
{
|
|
|
Console.PrintSystemLine("EraJIT x64 0.0.0.0");
|
|
@@ -79,14 +93,8 @@ namespace NTERA.Engine.Runtime
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- Console.PrintSystemLine($"Unhandled exception: {ex.Message}");
|
|
|
- Console.PrintSystemLine("Stack trace:");
|
|
|
-
|
|
|
- foreach (var stackMember in ExecutionStack)
|
|
|
- {
|
|
|
- string name = stackMember.IsAnonymous ? "<anonymous>" : $"@{stackMember.SelfDefinition.Name}";
|
|
|
- Console.PrintSystemLine($" - {name} ({stackMember.SelfDefinition.Position} > {stackMember.SelfDefinition.Filename})");
|
|
|
- }
|
|
|
+ Console.PrintError($"Unhandled exception: {ex.Message}");
|
|
|
+ PrintStackTrace();
|
|
|
|
|
|
throw;
|
|
|
}
|
|
@@ -183,7 +191,7 @@ namespace NTERA.Engine.Runtime
|
|
|
}
|
|
|
|
|
|
ExecutionNode node = context.ExecutionNodes[context.ExecutionIndex++];
|
|
|
-
|
|
|
+
|
|
|
if (node.Type == "for")
|
|
|
{
|
|
|
ExecutionNode forContext = node[0];
|
|
@@ -194,7 +202,7 @@ namespace NTERA.Engine.Runtime
|
|
|
var endNumber = ComputeExpression(context, forContext[2]);
|
|
|
|
|
|
iterationVariable[iterationIndex] = beginNumber;
|
|
|
-
|
|
|
+
|
|
|
var newContext = context.Clone(node.Skip(1).ToList());
|
|
|
|
|
|
newContext.AnonymousExitCondition = frame =>
|
|
@@ -212,13 +220,13 @@ namespace NTERA.Engine.Runtime
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (node.Type == "do")
|
|
|
{
|
|
|
ExecutionNode loopContext = node[0];
|
|
|
-
|
|
|
+
|
|
|
var loopVariable = ComputeVariable(context, loopContext[0], out var loopIndex);
|
|
|
-
|
|
|
+
|
|
|
var newContext = context.Clone(node.Skip(1).ToList());
|
|
|
|
|
|
newContext.AnonymousExitCondition = frame =>
|
|
@@ -242,7 +250,19 @@ namespace NTERA.Engine.Runtime
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- ExecuteNode(context, node);
|
|
|
+ try {
|
|
|
+ ExecuteNode(context, node);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ if (!IgnoreErrors)
|
|
|
+ {
|
|
|
+ throw ex;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ System.Console.Write($"Error: {ex.Message}\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void ExecuteNode(StackFrame context, ExecutionNode node)
|
|
@@ -417,4 +437,4 @@ namespace NTERA.Engine.Runtime
|
|
|
return new CroppedImage(name, bitmap, definition.Dimensions ?? new Rectangle(Point.Empty, bitmap.Size), false);
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|