summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2019-08-16 12:14:39 +0200
committerAraq <rumpf_a@web.de>2019-08-16 12:14:39 +0200
commit1fb9a6d94631bf7f3570d3382874ba2d59e6ddbb (patch)
tree5cb550f57833030b6f314a9004e37fea5fc34a5c /doc
parent922e2a5098cfec871a9bed7bff6b1e5298c9f931 (diff)
downloadNim-1fb9a6d94631bf7f3570d3382874ba2d59e6ddbb.tar.gz
added destructors.rst spec to the build documentation
Diffstat (limited to 'doc')
-rw-r--r--doc/manual.rst4
-rw-r--r--doc/manual_experimental.rst81
2 files changed, 10 insertions, 75 deletions
diff --git a/doc/manual.rst b/doc/manual.rst
index 61a73357d..0e4eb08a8 100644
--- a/doc/manual.rst
+++ b/doc/manual.rst
@@ -22,6 +22,10 @@ precise wording. This manual is constantly evolving into a proper specification.
 **Note**: The experimental features of Nim are
 covered `here <manual_experimental.html>`_.
 
+**Note**: Assignments, moves and destruction are specified in
+the `destructors <destructors.html>`_ document.
+
+
 This document describes the lexis, the syntax, and the semantics of the Nim language.
 
 To learn how to compile Nim programs and generate documentation see
diff --git a/doc/manual_experimental.rst b/doc/manual_experimental.rst
index 1b007722c..583f2734f 100644
--- a/doc/manual_experimental.rst
+++ b/doc/manual_experimental.rst
@@ -776,11 +776,12 @@ object inheritance syntax involving the ``of`` keyword:
 Type bound operations
 =====================
 
-There are 3 operations that are bound to a type:
+There are 4 operations that are bound to a type:
 
 1. Assignment
-2. Destruction
-3. Deep copying for communication between threads
+2. Moves
+3. Destruction
+4. Deep copying for communication between threads
 
 These operations can be *overridden* instead of *overloaded*. This means the
 implementation is automatically lifted to structured types. For instance if type
@@ -792,78 +793,8 @@ bound to ``T`` and not to ``ref T``. This also means that one cannot override
 ``deepCopy`` for both ``ptr T`` and ``ref T`` at the same time; instead a
 helper distinct or object type has to be used for one pointer type.
 
-
-operator `=`
-------------
-
-This operator is the assignment operator. Note that in the contexts
-``result = expr``, ``parameter = defaultValue`` or for
-parameter passing no assignment is performed. For a type ``T`` that has an
-overloaded assignment operator ``var v = T()`` is rewritten
-to ``var v: T; v = T()``; in other words ``var`` and ``let`` contexts do count
-as assignments.
-
-The assignment operator needs to be attached to an object or distinct
-type ``T``. Its signature has to be ``(var T, T)``. Example:
-
-.. code-block:: nim
-  type
-    Concrete = object
-      a, b: string
-
-  proc `=`(d: var Concrete; src: Concrete) =
-    shallowCopy(d.a, src.a)
-    shallowCopy(d.b, src.b)
-    echo "Concrete '=' called"
-
-  var x, y: array[0..2, Concrete]
-  var cA, cB: Concrete
-
-  var cATup, cBTup: tuple[x: int, ha: Concrete]
-
-  x = y
-  cA = cB
-  cATup = cBTup
-
-
-
-destructors
------------
-
-A destructor must have a single parameter with a concrete type (the name of a
-generic type is allowed too). The name of the destructor has to be ``=destroy``.
-
-``=destroy(v)`` will be automatically invoked for every local stack
-variable ``v`` that goes out of scope.
-
-If a structured type features a field with destructable type and
-the user has not provided an explicit implementation, a destructor for the
-structured type will be automatically generated. Calls to any base class
-destructors in both user-defined and generated destructors will be inserted.
-
-A destructor is attached to the type it destructs.
-
-.. code-block:: nim
-  type
-    MyObj = object
-      x, y: int
-      p: pointer
-
-  proc `=destroy`(o: var MyObj) =
-    if o.p != nil: dealloc o.p
-
-  proc open: MyObj =
-    result = MyObj(x: 1, y: 2, p: alloc(3))
-
-  proc work(o: MyObj) =
-    echo o.x
-    # No destructor invoked here for 'o' as 'o' is a parameter.
-
-  proc main() =
-    # destructor automatically invoked at the end of the scope:
-    var x = open()
-    # valid: pass 'x' to some other proc:
-    work(x)
+Assignments, moves and destruction are specified in
+the `destructors <destructors.html>`_ document.
 
 
 deepCopy