diff options
author | Araq <rumpf_a@web.de> | 2017-02-25 11:18:48 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2017-02-25 11:18:48 +0100 |
commit | 1961e444c32903d5046f078630e90716c17dff62 (patch) | |
tree | 21334eb10390c005f162c6a821bd03d91f1e8b4b /doc | |
parent | 667acb06a53a47f47dde29c381df0d4bcbf61b94 (diff) | |
parent | 16aafddee598da750dba378cca5bea0126fdf992 (diff) | |
download | Nim-1961e444c32903d5046f078630e90716c17dff62.tar.gz |
Merge branch 'devel' into feature/async-streams
Diffstat (limited to 'doc')
-rw-r--r-- | doc/backends.txt | 8 | ||||
-rw-r--r-- | doc/manual/locking.txt | 19 | ||||
-rw-r--r-- | doc/manual/pragmas.txt | 32 | ||||
-rw-r--r-- | doc/tut1.rst | 22 |
4 files changed, 64 insertions, 17 deletions
diff --git a/doc/backends.txt b/doc/backends.txt index 5846cce9b..6446103ed 100644 --- a/doc/backends.txt +++ b/doc/backends.txt @@ -461,3 +461,11 @@ can then attach a GC to this thread via It is **not** safe to disable the garbage collector and enable it after the call from your background thread even if the code you are calling is short lived. + +Before the thread exits, you should tear down the thread's GC to prevent memory +leaks by calling + +.. code-block:: nim + + system.tearDownForeignThreadGc() + diff --git a/doc/manual/locking.txt b/doc/manual/locking.txt index c00efdd91..c1bd5ca46 100644 --- a/doc/manual/locking.txt +++ b/doc/manual/locking.txt @@ -198,3 +198,22 @@ This is essential so that procs can be called within a ``locks`` section: As usual ``locks`` is an inferred effect and there is a subtype relation: ``proc () {.locks: N.}`` is a subtype of ``proc () {.locks: M.}`` iff (M <= N). + +The ``locks`` pragma can also take the special value ``"unknown"``. This +is useful in the context of dynamic method dispatching. In the following +example, the compiler can infer a lock level of 0 for the ``base`` case. +However, one of the overloaded methods calls a procvar which is +potentially locking. Thus, the lock level of calling ``g.testMethod`` +cannot be inferred statically, leading to compiler warnings. By using +``{.locks: "unknown".}``, the base method can be marked explicitly as +having unknown lock level as well: + +.. code-block:: nim + type SomeBase* = ref object of RootObj + type SomeDerived* = ref object of SomeBase + memberProc*: proc () + + method testMethod(g: SomeBase) {.base, locks: "unknown".} = discard + method testMethod(g: SomeDerived) = + if g.memberProc != nil: + g.memberProc() diff --git a/doc/manual/pragmas.txt b/doc/manual/pragmas.txt index 2a276c2e7..d30c37ff7 100644 --- a/doc/manual/pragmas.txt +++ b/doc/manual/pragmas.txt @@ -503,6 +503,26 @@ identifier that can be used to enable or disable it: This is often better than disabling all warnings at once. +used pragma +----------- + +Nim produces a warning for symbols that are not exported and not used either. +The ``used`` pragma can be attached to a symbol to suppress this warning. This +is particularly useful when the symbol was generated by a macro: + +.. code-block:: nim + template implementArithOps(T) = + proc echoAdd(a, b: T) {.used.} = + echo a + b + proc echoSub(a, b: T) {.used.} = + echo a - b + + # no warning produced for the unused 'echoSub' + implementArithOps(int) + echoAdd 3, 5 + + + experimental pragma ------------------- @@ -1018,12 +1038,12 @@ the -d/--define option at compile time. The implementation currently provides the following possible options (various others may be added later). -=============== ============================================ -pragma description -=============== ============================================ -intdefine Reads in a build-time define as an integer -strdefine Reads in a build-time define as a string -=============== ============================================ +================= ============================================ +pragma description +================= ============================================ +`intdefine`:idx: Reads in a build-time define as an integer +`strdefine`:idx: Reads in a build-time define as a string +================= ============================================ .. code-block:: nim const FooBar {.intdefine.}: int = 5 diff --git a/doc/tut1.rst b/doc/tut1.rst index 47cafc7fa..e79214dee 100644 --- a/doc/tut1.rst +++ b/doc/tut1.rst @@ -361,7 +361,7 @@ iterator: .. code-block:: nim echo "Counting to ten: " for i in countup(1, 10): - echo $i + echo i # --> Outputs 1 2 3 4 5 6 7 8 9 10 on different lines The built-in `$ <system.html#$>`_ operator turns an integer (``int``) and many @@ -374,7 +374,7 @@ Each value is ``echo``-ed. This code does the same: echo "Counting to 10: " var i = 1 while i <= 10: - echo $i + echo i inc(i) # increment i by 1 # --> Outputs 1 2 3 4 5 6 7 8 9 10 on different lines @@ -383,7 +383,7 @@ Counting down can be achieved as easily (but is less often needed): .. code-block:: nim echo "Counting down from 10 to 1: " for i in countdown(10, 1): - echo $i + echo i # --> Outputs 10 9 8 7 6 5 4 3 2 1 on different lines Since counting up occurs so often in programs, Nim also has a `.. @@ -827,7 +827,7 @@ Let's return to the boring counting example: .. code-block:: nim echo "Counting to ten: " for i in countup(1, 10): - echo $i + echo i Can a `countup <system.html#countup>`_ proc be written that supports this loop? Lets try: @@ -1035,15 +1035,15 @@ there is a difference between the ``$`` and ``repr`` outputs: myString = "nim" myInteger = 42 myFloat = 3.14 - echo $myBool, ":", repr(myBool) + echo myBool, ":", repr(myBool) # --> true:true - echo $myCharacter, ":", repr(myCharacter) + echo myCharacter, ":", repr(myCharacter) # --> n:'n' - echo $myString, ":", repr(myString) + echo myString, ":", repr(myString) # --> nim:0x10fa8c050"nim" - echo $myInteger, ":", repr(myInteger) + echo myInteger, ":", repr(myInteger) # --> 42:42 - echo $myFloat, ":", repr(myFloat) + echo myFloat, ":", repr(myFloat) # --> 3.1400000000000001e+00:3.1400000000000001e+00 @@ -1075,7 +1075,7 @@ at runtime by 0, the second by 1 and so on. Example: north, east, south, west var x = south # `x` is of type `Direction`; its value is `south` - echo $x # writes "south" to `stdout` + echo x # writes "south" to `stdout` All comparison operators can be used with enumeration types. @@ -1289,7 +1289,7 @@ value. Here the ``for`` statement is looping over the results from the .. code-block:: nim for i in @[3, 4, 5]: - echo $i + echo i # --> 3 # --> 4 # --> 5 |