summary refs log tree commit diff stats
path: root/lib/system.nim
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2011-12-11 11:26:50 +0200
committerZahary Karadjov <zahary@gmail.com>2011-12-11 11:26:50 +0200
commit67bc23bb60dda2895c47ae0747d106b6075c6a90 (patch)
tree4f4c66fad9ae5c42beefd31274091e295f31b639 /lib/system.nim
parentd171a8b36f10f42d35e64a7ddefa57376b419908 (diff)
parentaf792da0bbee6e9587b8aafafcd8f898f8fe9fd4 (diff)
downloadNim-67bc23bb60dda2895c47ae0747d106b6075c6a90.tar.gz
Merge branch 'master' of github.com:Araq/Nimrod into upstream
Diffstat (limited to 'lib/system.nim')
-rwxr-xr-xlib/system.nim14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/system.nim b/lib/system.nim
index c7e26230a..8a99781cc 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -2071,14 +2071,24 @@ proc astToStr*[T](x: T): string {.magic: "AstToStr", noSideEffect.}
   ## converts the AST of `x` into a string representation. This is very useful
   ## for debugging.
   
+proc raiseAssert(msg: string) {.noinline.} =
+  raise newException(EAssertionFailed, msg)
+  
 template assert*(cond: expr, msg = "") =
   ## provides a means to implement `programming by contracts`:idx: in Nimrod.
   ## ``assert`` evaluates expression ``cond`` and if ``cond`` is false, it
   ## raises an ``EAssertionFailure`` exception. However, the compiler may
   ## not generate any code at all for ``assert`` if it is advised to do so.
   ## Use ``assert`` for debugging purposes only.
+  bind raiseAssert
   when compileOption("assertions"):
     if not cond:
-      raise newException(EAssertionFailed, astToStr(cond) & ' ' & msg)
-
+      raiseAssert(astToStr(cond) & ' ' & msg)
+
+template doAssert*(cond: expr, msg = "") =
+  ## same as `assert' but is always turned on and not affected by the
+  ## ``--assertions`` command line switch.
+  bind raiseAssert
+  if not cond:
+    raiseAssert(astToStr(cond) & ' ' & msg)