types.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 util
  11. import (
  12. "time"
  13. "devt.de/krotik/common/datautil"
  14. "devt.de/krotik/ecal/engine/pool"
  15. "devt.de/krotik/ecal/parser"
  16. )
  17. /*
  18. Processor models a top level execution instance for ECAL.
  19. */
  20. type Processor interface {
  21. }
  22. /*
  23. ECALImportLocator is used to resolve imports.
  24. */
  25. type ECALImportLocator interface {
  26. /*
  27. Resolve a given import path and parse the imported file into an AST.
  28. */
  29. Resolve(path string) (string, error)
  30. }
  31. /*
  32. ECALFunction models a callable function in ECAL.
  33. */
  34. type ECALFunction interface {
  35. /*
  36. Run executes this function. The envirnment provides a unique instanceID for
  37. every code location in the running code, the variable scope of the function,
  38. an instance state which can be used in combinartion with the instanceID
  39. to store instance specific state (e.g. for iterator functions) and a list
  40. of argument values which were passed to the function by the calling code.
  41. */
  42. Run(instanceID string, vs parser.Scope, is map[string]interface{}, tid uint64, args []interface{}) (interface{}, error)
  43. /*
  44. DocString returns a descriptive text about this function.
  45. */
  46. DocString() (string, error)
  47. }
  48. /*
  49. ECALPluginFunction models a callable function in ECAL which can be imported via a plugin.
  50. */
  51. type ECALPluginFunction interface {
  52. /*
  53. Run executes this function with a given list of arguments.
  54. */
  55. Run(args []interface{}) (interface{}, error)
  56. /*
  57. DocString returns a descriptive text about this function.
  58. */
  59. DocString() string
  60. }
  61. /*
  62. Logger is required external object to which the interpreter releases its log messages.
  63. */
  64. type Logger interface {
  65. /*
  66. LogError adds a new error log message.
  67. */
  68. LogError(v ...interface{})
  69. /*
  70. LogInfo adds a new info log message.
  71. */
  72. LogInfo(v ...interface{})
  73. /*
  74. LogDebug adds a new debug log message.
  75. */
  76. LogDebug(v ...interface{})
  77. }
  78. /*
  79. ContType represents a way how to resume code execution of a suspended thread.
  80. */
  81. type ContType int
  82. /*
  83. Available lexer token types
  84. */
  85. const (
  86. Resume ContType = iota // Resume code execution until the next breakpoint or the end
  87. StepIn // Step into a function call or over the next non-function call
  88. StepOver // Step over the current statement onto the next line
  89. StepOut // Step out of the current function call
  90. )
  91. /*
  92. ECALDebugger is a debugging object which can be used to inspect and modify a running
  93. ECAL environment.
  94. */
  95. type ECALDebugger interface {
  96. /*
  97. HandleInput handles a given debug instruction. It must be possible to
  98. convert the output data into a JSON string.
  99. */
  100. HandleInput(input string) (interface{}, error)
  101. /*
  102. StopThreads will continue all suspended threads and set them to be killed.
  103. Returns true if a waiting thread was resumed. Can wait for threads to end
  104. by ensuring that for at least d time no state change occurred.
  105. */
  106. StopThreads(d time.Duration) bool
  107. /*
  108. BreakOnStart breaks on the start of the next execution.
  109. */
  110. BreakOnStart(flag bool)
  111. /*
  112. BreakOnError breaks if an error occurs.
  113. */
  114. BreakOnError(flag bool)
  115. /*
  116. SetLockingState sets locking status information.
  117. */
  118. SetLockingState(mutexeOwners map[string]uint64, mutexLog *datautil.RingBuffer)
  119. /*
  120. SetThreadPool sets the reference to the current used thread pool.
  121. */
  122. SetThreadPool(tp *pool.ThreadPool)
  123. /*
  124. VisitState is called for every state during the execution of a program.
  125. */
  126. VisitState(node *parser.ASTNode, vs parser.Scope, tid uint64) TraceableRuntimeError
  127. /*
  128. VisitStepInState is called before entering a function call.
  129. */
  130. VisitStepInState(node *parser.ASTNode, vs parser.Scope, tid uint64) TraceableRuntimeError
  131. /*
  132. VisitStepOutState is called after returning from a function call.
  133. */
  134. VisitStepOutState(node *parser.ASTNode, vs parser.Scope, tid uint64, soErr error) TraceableRuntimeError
  135. /*
  136. RecordThreadFinished lets the debugger know that a thread has finished.
  137. */
  138. RecordThreadFinished(tid uint64)
  139. /*
  140. SetBreakPoint sets a break point.
  141. */
  142. SetBreakPoint(source string, line int)
  143. /*
  144. DisableBreakPoint disables a break point but keeps the code reference.
  145. */
  146. DisableBreakPoint(source string, line int)
  147. /*
  148. RemoveBreakPoint removes a break point.
  149. */
  150. RemoveBreakPoint(source string, line int)
  151. /*
  152. ExtractValue copies a value from a suspended thread into the
  153. global variable scope.
  154. */
  155. ExtractValue(threadID uint64, varName string, destVarName string) error
  156. /*
  157. InjectValue copies a value from an expression (using the global
  158. variable scope) into a suspended thread.
  159. */
  160. InjectValue(threadID uint64, varName string, expression string) error
  161. /*
  162. Continue will continue a suspended thread.
  163. */
  164. Continue(threadID uint64, contType ContType)
  165. /*
  166. Status returns the current status of the debugger.
  167. */
  168. Status() interface{}
  169. /*
  170. LockStatus returns the current locking status.
  171. */
  172. LockState() interface{}
  173. /*
  174. Describe describes a thread currently observed by the debugger.
  175. */
  176. Describe(threadID uint64) interface{}
  177. }
  178. /*
  179. DebugCommand is command which can modify and interrogate the debugger.
  180. */
  181. type DebugCommand interface {
  182. /*
  183. Execute the debug command and return its result. It must be possible to
  184. convert the output data into a JSON string.
  185. */
  186. Run(debugger ECALDebugger, args []string) (interface{}, error)
  187. /*
  188. DocString returns a descriptive text about this command.
  189. */
  190. DocString() string
  191. }