summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2012-04-10 22:32:23 +0300
committerZahary Karadjov <zahary@gmail.com>2012-04-10 22:32:23 +0300
commit97ab16d46b55aa9a4b2acbc72777fb6a8d5a162f (patch)
treea03290071c0f4788f6f3484571c1e6f4909501d1
parenta64f03230afa69f2143b0eb159c9294998c5e19b (diff)
downloadNim-97ab16d46b55aa9a4b2acbc72777fb6a8d5a162f.tar.gz
typetraits module and tests
-rw-r--r--lib/pure/typetraits.nim15
-rw-r--r--tests/run/ttypetraits.nim24
2 files changed, 39 insertions, 0 deletions
diff --git a/lib/pure/typetraits.nim b/lib/pure/typetraits.nim
new file mode 100644
index 000000000..45b79dcb6
--- /dev/null
+++ b/lib/pure/typetraits.nim
@@ -0,0 +1,15 @@
+#
+#
+#            Nimrod's Runtime Library
+#        (c) Copyright 2012 Nimrod Contributors
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+## This module defines compile-time reflection procs for
+## working with types
+
+proc name*(t: typedesc): string {.magic: "TypeTrait".}
+  ## Returns the name of the given type
+
diff --git a/tests/run/ttypetraits.nim b/tests/run/ttypetraits.nim
new file mode 100644
index 000000000..5b683bef0
--- /dev/null
+++ b/tests/run/ttypetraits.nim
@@ -0,0 +1,24 @@
+discard """
+  msg:    "int\nstring\nTBar[int]"
+  output: "int\nstring\nTBar[int]"
+"""
+
+import typetraits
+
+proc foo(x) =
+  static:
+    var t = type(x)
+    echo t.name
+
+  echo x.type.name
+
+type
+  TBar[U] = object
+    x: U
+
+var bar: TBar[int]
+
+foo 10
+foo "test"
+foo bar
+