thallo.nim 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. discard """
  2. action: compile
  3. """
  4. # noted this seems to be an old test file designed for manual testing.
  5. import
  6. os, strutils, macros
  7. type
  8. TMyEnum = enum
  9. meA, meB, meC, meD
  10. when true:
  11. {.hint: "this is the main file".}
  12. proc fac[T](x: T): T =
  13. # test recursive generic procs
  14. if x <= 1: return 1
  15. else: return x.`*`(fac(x-1))
  16. macro macrotest(n: varargs[untyped]): untyped =
  17. let n = callsite()
  18. expectKind(n, nnkCall)
  19. expectMinLen(n, 2)
  20. result = newNimNode(nnkStmtList, n)
  21. for i in 2..n.len-1:
  22. result.add(newCall("write", n[1], n[i]))
  23. result.add(newCall("writeLine", n[1], newStrLitNode("")))
  24. macro debug(n: untyped): untyped {.immediate.} =
  25. let n = callsite()
  26. result = newNimNode(nnkStmtList, n)
  27. for i in 1..n.len-1:
  28. result.add(newCall("write", newIdentNode("stdout"), toStrLit(n[i])))
  29. result.add(newCall("write", newIdentNode("stdout"), newStrLitNode(": ")))
  30. result.add(newCall("writeLine", newIdentNode("stdout"), n[i]))
  31. macrotest(stdout, "finally", 4, 5, "variable", "argument lists")
  32. macrotest(stdout)
  33. #GC_disable()
  34. echo("This was compiled by Nim version " & system.NimVersion)
  35. writeLine(stdout, "Hello", " World", "!")
  36. echo(["a", "b", "c", "d"].len)
  37. for x in items(["What's", "your", "name", "?", ]):
  38. echo(x)
  39. var `name` = readLine(stdin)
  40. {.breakpoint.}
  41. echo("Hi " & thallo.name & "!\n")
  42. debug(name)
  43. var testseq: seq[string] = @[
  44. "a", "b", "c", "d", "e"
  45. ]
  46. echo(repr(testseq))
  47. var dummy = "hello"
  48. echo(substr(dummy, 2, 3))
  49. echo($meC)
  50. # test tuples:
  51. for x, y in items([(1, 2), (3, 4), (6, 1), (5, 2)]):
  52. echo x
  53. echo y
  54. proc simpleConst(): int = return 34
  55. # test constant evaluation:
  56. const
  57. constEval3 = simpleConst()
  58. constEval = "abc".contains('b')
  59. constEval2 = fac(7)
  60. echo(constEval3)
  61. echo(constEval)
  62. echo(constEval2)
  63. echo(1.`+`(2))
  64. for i in 2..6:
  65. for j in countdown(i+4, 2):
  66. echo(fac(i * j))
  67. when true:
  68. {.hint: "this is the main file".}