topt_refcursors.nim 764 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. discard """
  2. output: ''''''
  3. cmd: '''nim c --gc:arc --expandArc:traverse --hint:Performance:off $file'''
  4. nimout: '''--expandArc: traverse
  5. var it_cursor = root
  6. block :tmp:
  7. while (
  8. not (it_cursor == nil)):
  9. echo [it_cursor.s]
  10. it_cursor = it_cursor.ri
  11. var jt_cursor = root
  12. block :tmp_1:
  13. while (
  14. not (jt_cursor == nil)):
  15. let ri_1_cursor = jt_cursor.ri
  16. echo [jt_cursor.s]
  17. jt_cursor = ri_1_cursor
  18. -- end of expandArc ------------------------'''
  19. """
  20. type
  21. Node = ref object
  22. le, ri: Node
  23. s: string
  24. proc traverse(root: Node) =
  25. var it = root
  26. while it != nil:
  27. echo it.s
  28. it = it.ri
  29. var jt = root
  30. while jt != nil:
  31. let ri = jt.ri
  32. echo jt.s
  33. jt = ri
  34. traverse(nil)
  35. # XXX: This optimization is not sound