t17198.nim 709 B

123456789101112131415161718192021222324252627282930313233
  1. discard """
  2. cmd: '''nim c --gc:arc $file'''
  3. output: '''
  4. other
  5. '''
  6. """
  7. import std/macros
  8. macro bigCaseStmt(arg: untyped): untyped =
  9. result = nnkCaseStmt.newTree(arg)
  10. # try to change 2000 to a bigger value if it doesn't crash
  11. for x in 0 ..< 2000:
  12. result.add nnkOfBranch.newTree(newStrLitNode($x), newStrLitNode($x))
  13. result.add nnkElse.newTree(newStrLitNode("other"))
  14. macro bigIfElseExpr(): untyped =
  15. result = nnkIfExpr.newTree()
  16. for x in 0 ..< 1000:
  17. result.add nnkElifExpr.newTree(newLit(false), newStrLitNode($x))
  18. result.add nnkElseExpr.newTree(newStrLitNode("other"))
  19. proc test(arg: string): string =
  20. echo bigIfElseExpr()
  21. result = bigCaseStmt(arg)
  22. discard test("test")