targ_lefttoright.nim 947 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. discard """
  2. nimout: '''1,2
  3. 2,3
  4. 2,2
  5. 1,2
  6. 1,2
  7. 2,2
  8. 1,2
  9. '''
  10. output: '''1,2
  11. 2,3
  12. 1,2
  13. 2,2
  14. 1,2
  15. 1,2
  16. 2,2
  17. 1,2
  18. '''
  19. cmd: "nim c --gc:orc $file"
  20. """
  21. template test =
  22. proc say(a, b: int) =
  23. echo a,",",b
  24. var a = 1
  25. say a, (a += 1; a) #1,2
  26. var b = 1
  27. say (b += 1; b), (b += 1; b) #2,3
  28. type C {.byRef.} = object
  29. i: int
  30. proc say(a, b: C) =
  31. echo a.i,",",b.i
  32. proc `+=`(x: var C, y: C) = x.i += y.i
  33. var c = C(i: 1)
  34. when nimvm: #XXX: This would output 2,2 in the VM, which is wrong
  35. discard
  36. else:
  37. say c, (c += C(i: 1); c) #1,2
  38. proc sayVar(a: var int, b: int) =
  39. echo a,",",b
  40. var d = 1
  41. sayVar d, (d += 1; d) #2,2
  42. var e = 1
  43. say (addr e)[], (e += 1; e) #1,2
  44. var f = 1
  45. say f, if false: f
  46. else: f += 1; f #1,2
  47. var g = 1
  48. say g + 1, if false: g
  49. else: g += 1; g #2,2
  50. proc `+=+`(x: var int, y: int): int = (inc(x, y); x)
  51. var h = 1
  52. say h, h +=+ 1 # 1,2
  53. test
  54. static:
  55. test