types.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. "devt.de/krotik/ecal/parser"
  13. )
  14. /*
  15. Processor models a top level execution instance for ECAL.
  16. */
  17. type Processor interface {
  18. }
  19. /*
  20. ECALImportLocator is used to resolve imports.
  21. */
  22. type ECALImportLocator interface {
  23. /*
  24. Resolve a given import path and parse the imported file into an AST.
  25. */
  26. Resolve(path string) (string, error)
  27. }
  28. /*
  29. ECALFunction models a callable function in ECAL.
  30. */
  31. type ECALFunction interface {
  32. /*
  33. Run executes this function. The envirnment provides a unique instanceID for
  34. every code location in the running code, the variable scope of the function,
  35. an instance state which can be used in combinartion with the instanceID
  36. to store instance specific state (e.g. for iterator functions) and a list
  37. of argument values which were passed to the function by the calling code.
  38. */
  39. Run(instanceID string, vs parser.Scope, is map[string]interface{}, tid uint64, args []interface{}) (interface{}, error)
  40. /*
  41. DocString returns a descriptive text about this function.
  42. */
  43. DocString() (string, error)
  44. }
  45. /*
  46. Logger is required external object to which the interpreter releases its log messages.
  47. */
  48. type Logger interface {
  49. /*
  50. LogError adds a new error log message.
  51. */
  52. LogError(v ...interface{})
  53. /*
  54. LogInfo adds a new info log message.
  55. */
  56. LogInfo(v ...interface{})
  57. /*
  58. LogDebug adds a new debug log message.
  59. */
  60. LogDebug(v ...interface{})
  61. }
  62. /*
  63. ContType represents a way how to resume code execution of a suspended thread.
  64. */
  65. type ContType int
  66. /*
  67. Available lexer token types
  68. */
  69. const (
  70. Resume ContType = iota // Resume code execution until the next breakpoint or the end
  71. StepIn // Step into a function call or over the next non-function call
  72. StepOver // Step over the current statement onto the next line
  73. StepOut // Step out of the current function call
  74. )
  75. /*
  76. ECALDebugger is a debugging object which can be used to inspect and modify a running
  77. ECAL environment.
  78. */
  79. type ECALDebugger interface {
  80. /*
  81. HandleInput handles a given debug instruction. It must be possible to
  82. convert the output data into a JSON string.
  83. */
  84. HandleInput(input string) (interface{}, error)
  85. /*
  86. Break on the start of the next execution.
  87. */
  88. BreakOnStart(flag bool)
  89. /*
  90. VisitState is called for every state during the execution of a program.
  91. */
  92. VisitState(node *parser.ASTNode, vs parser.Scope, tid uint64) TraceableRuntimeError
  93. /*
  94. VisitStepInState is called before entering a function call.
  95. */
  96. VisitStepInState(node *parser.ASTNode, vs parser.Scope, tid uint64) TraceableRuntimeError
  97. /*
  98. VisitStepOutState is called after returning from a function call.
  99. */
  100. VisitStepOutState(node *parser.ASTNode, vs parser.Scope, tid uint64) TraceableRuntimeError
  101. /*
  102. SetBreakPoint sets a break point.
  103. */
  104. SetBreakPoint(source string, line int)
  105. /*
  106. DisableBreakPoint disables a break point but keeps the code reference.
  107. */
  108. DisableBreakPoint(source string, line int)
  109. /*
  110. RemoveBreakPoint removes a break point.
  111. */
  112. RemoveBreakPoint(source string, line int)
  113. /*
  114. ExtractValue copies a value from a suspended thread into the
  115. global variable scope.
  116. */
  117. ExtractValue(threadId uint64, varName string, destVarName string) error
  118. /*
  119. InjectValue copies a value from an expression (using the global
  120. variable scope) into a suspended thread.
  121. */
  122. InjectValue(threadId uint64, varName string, expression string) error
  123. /*
  124. Continue will continue a suspended thread.
  125. */
  126. Continue(threadId uint64, contType ContType)
  127. /*
  128. Status returns the current status of the debugger.
  129. */
  130. Status() interface{}
  131. /*
  132. Describe decribes a thread currently observed by the debugger.
  133. */
  134. Describe(threadId uint64) interface{}
  135. }
  136. /*
  137. DebugCommand is command which can modify and interrogate the debugger.
  138. */
  139. type DebugCommand interface {
  140. /*
  141. Execute the debug command and return its result. It must be possible to
  142. convert the output data into a JSON string.
  143. */
  144. Run(debugger ECALDebugger, args []string) (interface{}, error)
  145. /*
  146. DocString returns a descriptive text about this command.
  147. */
  148. DocString() string
  149. }