runtime.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * ECAL
  3. *
  4. * Copyright 2020 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the MIT
  7. * License, If a copy of the MIT License was not distributed with this
  8. * file, You can obtain one at https://opensource.org/licenses/MIT.
  9. */
  10. package parser
  11. /*
  12. RuntimeProvider provides runtime components for a parse tree.
  13. */
  14. type RuntimeProvider interface {
  15. /*
  16. Runtime returns a runtime component for a given ASTNode.
  17. */
  18. Runtime(node *ASTNode) Runtime
  19. }
  20. /*
  21. Runtime provides the runtime for an ASTNode.
  22. */
  23. type Runtime interface {
  24. /*
  25. Validate this runtime component and all its child components.
  26. */
  27. Validate() error
  28. /*
  29. Eval evaluate this runtime component. It gets passed the current variable
  30. scope an instance state and a thread ID.
  31. The instance state is created per execution instance and can be used
  32. for generator functions to store their current state. It gets replaced
  33. by a new object in certain situations (e.g. a function call).
  34. The thread ID can be used to identify a running process.
  35. */
  36. Eval(Scope, map[string]interface{}, uint64) (interface{}, error)
  37. }
  38. /*
  39. Scope models an environment which stores data.
  40. */
  41. type Scope interface {
  42. /*
  43. Name returns the name of this scope.
  44. */
  45. Name() string
  46. /*
  47. NewChild creates a new child scope.
  48. */
  49. NewChild(name string) Scope
  50. /*
  51. Clear clears this scope of all stored values. This will clear children scopes
  52. but not remove parent scopes.
  53. */
  54. Clear()
  55. /*
  56. Parent returns the parent scope or nil.
  57. */
  58. Parent() Scope
  59. /*
  60. SetValue sets a new value for a variable.
  61. */
  62. SetValue(varName string, varValue interface{}) error
  63. /*
  64. SetLocalValue sets a new value for a local variable.
  65. */
  66. SetLocalValue(varName string, varValue interface{}) error
  67. /*
  68. GetValue gets the current value of a variable.
  69. */
  70. GetValue(varName string) (interface{}, bool, error)
  71. /*
  72. String returns a string representation of this scope.
  73. */
  74. String() string
  75. /*
  76. ToJSONObject returns this ASTNode and all its children as a JSON object.
  77. */
  78. ToJSONObject() map[string]interface{}
  79. }