diff options
author | Araq <rumpf_a@web.de> | 2012-09-13 08:46:24 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-09-13 08:46:24 +0200 |
commit | a783077cfde0f542c1cc155fde617b0ceb977b21 (patch) | |
tree | c39f054064849b12b6e9444d7582b2fac6a56cb7 | |
parent | 23c3af80f60c1da49a1c979642e712358d960301 (diff) | |
download | Nim-a783077cfde0f542c1cc155fde617b0ceb977b21.tar.gz |
splitted echo into echo/debugEcho
-rw-r--r-- | compiler/sempass2.nim | 3 | ||||
-rw-r--r-- | doc/trmacros.txt | 13 | ||||
-rwxr-xr-x | lib/system.nim | 11 |
3 files changed, 8 insertions, 19 deletions
diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index 139f8f15e..78653bb44 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -19,4 +19,5 @@ # * checks for invalid usages of PNimNode # * later: will do an escape analysis for closures at least - +proc sem2(c: PContext, n: PNode): PNode = + nil diff --git a/doc/trmacros.txt b/doc/trmacros.txt index e740e6890..d5ad74e6e 100644 --- a/doc/trmacros.txt +++ b/doc/trmacros.txt @@ -44,19 +44,6 @@ Fortunately Nimrod supports side effect analysis: echo "side effect!" result = 55 - echo f() * 2 # and still optimized ;-) - -The reason is that the compiler does not consider 'echo' to have side effects -for debugging convenience (this is comparable to Haskell's ``UnsafeIO`` monad). -So lets try it with a "real" side effect: - -.. code-block:: nimrod - template optMul{`*`(a, 2)}(a: int{noSideEffect}): int = a+a - - proc f(): int = - writeln stdout, "side effect!" - result = 55 - echo f() * 2 # not optimized ;-) So what about ``2 * a``? We should tell the compiler ``*`` is commutative. We diff --git a/lib/system.nim b/lib/system.nim index 100707687..911b134e2 100755 --- a/lib/system.nim +++ b/lib/system.nim @@ -1648,7 +1648,7 @@ else: proc add*(x: var cstring, y: cstring) {.magic: "AppendStrStr".} -proc echo*[T](x: varargs[T, `$`]) {.magic: "Echo", noSideEffect.} +proc echo*[T](x: varargs[T, `$`]) {.magic: "Echo".} ## special built-in that takes a variable number of arguments. Each argument ## is converted to a string via ``$``, so it works for user-defined ## types that have an overloaded ``$`` operator. @@ -1656,10 +1656,11 @@ proc echo*[T](x: varargs[T, `$`]) {.magic: "Echo", noSideEffect.} ## available for the ECMAScript target too. ## Unlike other IO operations this is guaranteed to be thread-safe as ## ``echo`` is very often used for debugging convenience. - ## - ## As a special semantic rule, ``echo`` pretends to be free of - ## side effects, so that it can be used for debugging routines marked as - ## ``noSideEffect``. + +proc debugEcho*[T](x: varargs[T, `$`]) {.magic: "Echo", noSideEffect.} + ## Same as ``echo``, but as a special semantic rule, ``debugEcho`` pretends + ## to be free of side effects, so that it can be used for debugging routines + ## marked as ``noSideEffect``. template newException*(exceptn: typeDesc, message: string): expr = ## creates an exception object of type ``exceptn`` and sets its ``msg`` field |