topt_cursor.nim 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. discard """
  2. output: '''("string here", 80)'''
  3. cmd: '''nim c --gc:arc --expandArc:main --expandArc:sio --hint:Performance:off $file'''
  4. nimout: '''--expandArc: main
  5. var
  6. x_cursor
  7. :tmpD
  8. try:
  9. x_cursor = ("hi", 5)
  10. if cond:
  11. x_cursor = ("different", 54) else:
  12. x_cursor = ("string here", 80)
  13. echo [
  14. :tmpD = `$`(x_cursor)
  15. :tmpD]
  16. finally:
  17. `=destroy`(:tmpD)
  18. -- end of expandArc ------------------------
  19. --expandArc: sio
  20. block :tmp:
  21. var x_cursor
  22. var f = open("debug.txt", fmRead, 8000)
  23. try:
  24. var res
  25. try:
  26. res = newStringOfCap(80)
  27. block :tmp_1:
  28. while readLine(f, res):
  29. x_cursor = res
  30. echo [x_cursor]
  31. finally:
  32. `=destroy`(res)
  33. finally:
  34. close(f)
  35. -- end of expandArc ------------------------'''
  36. """
  37. proc main(cond: bool) =
  38. var x = ("hi", 5) # goal: computed as cursor
  39. x = if cond:
  40. ("different", 54)
  41. else:
  42. ("string here", 80)
  43. echo x
  44. main(false)
  45. proc sio =
  46. for x in lines("debug.txt"):
  47. echo x
  48. if false:
  49. sio()