hotcodereloading.nim 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2019 Nim contributors
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. ## Unstable API.
  10. when defined(hotcodereloading):
  11. import
  12. std/macros
  13. template beforeCodeReload*(body: untyped) =
  14. hcrAddEventHandler(true, proc = body) {.executeOnReload.}
  15. template afterCodeReload*(body: untyped) =
  16. hcrAddEventHandler(false, proc = body) {.executeOnReload.}
  17. macro hasModuleChanged*(module: typed): untyped =
  18. if module.kind != nnkSym or module.symKind != nskModule:
  19. error "hasModuleChanged expects a module symbol", module
  20. return newCall(bindSym"hcrHasModuleChanged", newLit(module.signatureHash))
  21. proc hasAnyModuleChanged*(): bool = hcrReloadNeeded()
  22. when not defined(js):
  23. template performCodeReload* =
  24. when isMainModule:
  25. {.warning: "Code residing in the main module will not be changed from calling a code-reload".}
  26. hcrPerformCodeReload()
  27. else:
  28. template performCodeReload* = discard
  29. else:
  30. template beforeCodeReload*(body: untyped) = discard
  31. template afterCodeReload*(body: untyped) = discard
  32. template hasModuleChanged*(module: typed): bool = false
  33. proc hasAnyModuleChanged*(): bool = false
  34. template performCodeReload*() = discard