macrocacheimpl.nim 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #
  2. #
  3. # The Nim Compiler
  4. # (c) Copyright 2018 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. ## This module implements helpers for the macro cache.
  10. import lineinfos, ast, vmdef
  11. proc append(c: PCtx; n: PNode) =
  12. c.vmstateDiff.add((c.module, n))
  13. proc recordInc*(c: PCtx; info: TLineInfo; key: string; by: BiggestInt) =
  14. var recorded = newNodeI(nkReplayAction, info)
  15. recorded.add newStrNode("inc", info)
  16. recorded.add newStrNode(key, info)
  17. recorded.add newIntNode(nkIntLit, by)
  18. c.append(recorded)
  19. proc recordPut*(c: PCtx; info: TLineInfo; key: string; k: string; val: PNode) =
  20. var recorded = newNodeI(nkReplayAction, info)
  21. recorded.add newStrNode("put", info)
  22. recorded.add newStrNode(key, info)
  23. recorded.add newStrNode(k, info)
  24. recorded.add copyTree(val)
  25. c.append(recorded)
  26. proc recordAdd*(c: PCtx; info: TLineInfo; key: string; val: PNode) =
  27. var recorded = newNodeI(nkReplayAction, info)
  28. recorded.add newStrNode("add", info)
  29. recorded.add newStrNode(key, info)
  30. recorded.add copyTree(val)
  31. c.append(recorded)
  32. proc recordIncl*(c: PCtx; info: TLineInfo; key: string; val: PNode) =
  33. var recorded = newNodeI(nkReplayAction, info)
  34. recorded.add newStrNode("incl", info)
  35. recorded.add newStrNode(key, info)
  36. recorded.add copyTree(val)
  37. c.append(recorded)