diff options
author | Araq <rumpf_a@web.de> | 2011-12-10 01:06:32 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-12-10 01:06:32 +0100 |
commit | af792da0bbee6e9587b8aafafcd8f898f8fe9fd4 (patch) | |
tree | 65d93113d605187b0dcbde0b26818e18da260a53 /lib/system.nim | |
parent | 2962ca7890160e20796292320a3f56eccd00cc90 (diff) | |
download | Nim-af792da0bbee6e9587b8aafafcd8f898f8fe9fd4.tar.gz |
codegen uses alias analysis to generate better code
Diffstat (limited to 'lib/system.nim')
-rwxr-xr-x | lib/system.nim | 14 |
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) |