thallo.nim 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 =
  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. echo("Hi " & thallo.name & "!\n")
  41. debug(name)
  42. var testseq: seq[string] = @[
  43. "a", "b", "c", "d", "e"
  44. ]
  45. echo(repr(testseq))
  46. var dummy = "hello"
  47. echo(substr(dummy, 2, 3))
  48. echo($meC)
  49. # test tuples:
  50. for x, y in items([(1, 2), (3, 4), (6, 1), (5, 2)]):
  51. echo x
  52. echo y
  53. proc simpleConst(): int = return 34
  54. # test constant evaluation:
  55. const
  56. constEval3 = simpleConst()
  57. constEval = "abc".contains('b')
  58. constEval2 = fac(7)
  59. echo(constEval3)
  60. echo(constEval)
  61. echo(constEval2)
  62. echo(1.`+`(2))
  63. for i in 2..6:
  64. for j in countdown(i+4, 2):
  65. echo(fac(i * j))
  66. when true:
  67. {.hint: "this is the main file".}