topt_no_cursor.nim 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. discard """
  2. output: '''(repo: "", package: "meo", ext: "")
  3. doing shady stuff...
  4. 3
  5. 6
  6. (@[1], @[2])'''
  7. cmd: '''nim c --gc:arc --expandArc:newTarget --expandArc:delete --expandArc:p1 --expandArc:tt --hint:Performance:off $file'''
  8. nimout: '''--expandArc: newTarget
  9. var
  10. splat
  11. :tmp
  12. :tmp_1
  13. :tmp_2
  14. splat = splitFile(path)
  15. :tmp = splat.dir
  16. wasMoved(splat.dir)
  17. :tmp_1 = splat.name
  18. wasMoved(splat.name)
  19. :tmp_2 = splat.ext
  20. wasMoved(splat.ext)
  21. result = (
  22. let blitTmp = :tmp
  23. blitTmp,
  24. let blitTmp_1 = :tmp_1
  25. blitTmp_1,
  26. let blitTmp_2 = :tmp_2
  27. blitTmp_2)
  28. `=destroy`(splat)
  29. -- end of expandArc ------------------------
  30. --expandArc: delete
  31. var
  32. sibling
  33. saved
  34. `=copy`(sibling, target.parent.left)
  35. `=copy`(saved, sibling.right)
  36. `=copy`(sibling.right, saved.left)
  37. `=sink`(sibling.parent, saved)
  38. `=destroy`(sibling)
  39. -- end of expandArc ------------------------
  40. --expandArc: p1
  41. var
  42. lresult
  43. lvalue
  44. lnext
  45. _
  46. `=copy`(lresult, [123])
  47. _ = (
  48. let blitTmp = lresult
  49. blitTmp, ";")
  50. lvalue = _[0]
  51. lnext = _[1]
  52. `=sink`(result.value, move lvalue)
  53. `=destroy`(lnext)
  54. `=destroy_1`(lvalue)
  55. -- end of expandArc ------------------------
  56. --expandArc: tt
  57. var
  58. a
  59. :tmpD
  60. :tmpD_1
  61. :tmpD_2
  62. try:
  63. var it_cursor = x
  64. a = (
  65. wasMoved(:tmpD)
  66. `=copy`(:tmpD, it_cursor.key)
  67. :tmpD,
  68. wasMoved(:tmpD_1)
  69. `=copy`(:tmpD_1, it_cursor.val)
  70. :tmpD_1)
  71. echo [
  72. :tmpD_2 = `$`(a)
  73. :tmpD_2]
  74. finally:
  75. `=destroy`(:tmpD_2)
  76. `=destroy_1`(a)
  77. -- end of expandArc ------------------------'''
  78. """
  79. import os
  80. type Target = tuple[repo, package, ext: string]
  81. proc newTarget*(path: string): Target =
  82. let splat = path.splitFile
  83. result = (repo: splat.dir, package: splat.name, ext: splat.ext)
  84. echo newTarget("meo")
  85. type
  86. Node = ref object
  87. left, right, parent: Node
  88. value: int
  89. proc delete(target: var Node) =
  90. var sibling = target.parent.left # b3
  91. var saved = sibling.right # b3.right -> r4
  92. sibling.right = saved.left # b3.right -> r4.left = nil
  93. sibling.parent = saved # b3.parent -> r5 = r4
  94. #[after this proc:
  95. b 5
  96. / \
  97. b 3 b 6
  98. ]#
  99. #[before:
  100. r 5
  101. / \
  102. b 3 b 6 - to delete
  103. / \
  104. empty r 4
  105. ]#
  106. proc main =
  107. var five = Node(value: 5)
  108. var six = Node(value: 6)
  109. six.parent = five
  110. five.right = six
  111. var three = Node(value: 3)
  112. three.parent = five
  113. five.left = three
  114. var four = Node(value: 4)
  115. four.parent = three
  116. three.right = four
  117. echo "doing shady stuff..."
  118. delete(six)
  119. # need both of these echos
  120. echo five.left.value
  121. echo five.right.value
  122. main()
  123. type
  124. Maybe = object
  125. value: seq[int]
  126. proc p1(): Maybe =
  127. let lresult = @[123]
  128. var lvalue: seq[int]
  129. var lnext: string
  130. (lvalue, lnext) = (lresult, ";")
  131. result.value = move lvalue
  132. proc tissue15130 =
  133. doAssert p1().value == @[123]
  134. tissue15130()
  135. type
  136. KeyValue = tuple[key, val: seq[int]]
  137. proc tt(x: KeyValue) =
  138. var it = x
  139. let a = (it.key, it.val)
  140. echo a
  141. proc encodedQuery =
  142. var query: seq[KeyValue]
  143. query.add (key: @[1], val: @[2])
  144. for elem in query:
  145. elem.tt()
  146. encodedQuery()
  147. # bug #15147
  148. proc s(input: string): (string, string) =
  149. result = (";", "")
  150. proc charmatch(input: string): (string, string) =
  151. result = ("123", input[0 .. input.high])
  152. proc plus(input: string) =
  153. var
  154. lvalue, rvalue: string # cursors
  155. lnext: string # must be cursor!!!
  156. rnext: string # cursor
  157. let lresult = charmatch(input)
  158. (lvalue, lnext) = lresult
  159. let rresult = s(lnext)
  160. (rvalue, rnext) = rresult
  161. plus("123;")