StackFrame.cs 1.7 KB

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