StackFrame.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using NTERA.Engine.Compiler;
  4. namespace NTERA.Engine.Runtime
  5. {
  6. public class StackFrame
  7. {
  8. public Dictionary<string, Variable> Variables { get; set; }
  9. public List<Parameter> Parameters { get; set; }
  10. public FunctionDefinition SelfDefinition { get; set; }
  11. public bool IsAnonymous { get; set; }
  12. public int ExecutionIndex { get; set; }
  13. public IList<ExecutionNode> ExecutionNodes { get; set; }
  14. public Func<StackFrame, bool> AnonymousExitCondition { get; set; } = null;
  15. public StackFrame Clone(IList<ExecutionNode> nodes, bool anonymous = true)
  16. {
  17. return new StackFrame
  18. {
  19. Variables = Variables,
  20. Parameters = Parameters,
  21. SelfDefinition = SelfDefinition,
  22. IsAnonymous = anonymous,
  23. ExecutionIndex = 0,
  24. ExecutionNodes = nodes
  25. };
  26. }
  27. }
  28. public enum ExecutionResultType
  29. {
  30. None,
  31. AnonymousCall,
  32. FunctionReturn
  33. }
  34. public class ExecutionResult
  35. {
  36. public static ExecutionResult None { get; } = new ExecutionResult(ExecutionResultType.None);
  37. public static ExecutionResult AnonymousCall { get; } = new ExecutionResult(ExecutionResultType.AnonymousCall);
  38. public ExecutionResultType Type { get; }
  39. public Value? Result { get; }
  40. public ExecutionResult(ExecutionResultType type, Value? value = null)
  41. {
  42. Type = type;
  43. Result = value;
  44. }
  45. }
  46. public class Parameter
  47. {
  48. public Value Value { get; }
  49. public Variable BackingVariable { get; }
  50. public int[] BackingVariableIndex { get; }
  51. public Parameter(Value value, Variable backingVariable = null, int[] variableIndex = null)
  52. {
  53. Value = value;
  54. BackingVariable = backingVariable;
  55. BackingVariableIndex = variableIndex ?? new[] { 0 };
  56. }
  57. public static implicit operator Value(Parameter parameter)
  58. {
  59. return parameter.Value;
  60. }
  61. }
  62. }