diff options
Diffstat (limited to 'doc')
-rw-r--r-- | doc/advopt.txt | 3 | ||||
-rw-r--r-- | doc/astspec.txt | 1 | ||||
-rw-r--r-- | doc/basicopt.txt | 2 | ||||
-rw-r--r-- | doc/contributing.rst | 226 | ||||
-rw-r--r-- | doc/docs.rst (renamed from doc/docs.txt) | 0 | ||||
-rw-r--r-- | doc/docstyle.rst | 140 | ||||
-rw-r--r-- | doc/gc.rst | 30 | ||||
-rw-r--r-- | doc/intern.txt | 2 | ||||
-rw-r--r-- | doc/lib.rst | 5 | ||||
-rw-r--r-- | doc/manual/exceptions.txt | 2 | ||||
-rw-r--r-- | doc/manual/types.txt | 3 | ||||
-rw-r--r-- | doc/nimc.rst | 4 | ||||
-rw-r--r-- | doc/nims.rst | 18 | ||||
-rw-r--r-- | doc/overview.rst (renamed from doc/overview.txt) | 2 |
14 files changed, 396 insertions, 42 deletions
diff --git a/doc/advopt.txt b/doc/advopt.txt index b8980fa9c..991f06397 100644 --- a/doc/advopt.txt +++ b/doc/advopt.txt @@ -61,6 +61,9 @@ Advanced options: --taintMode:on|off turn taint mode on|off --implicitStatic:on|off turn implicit compile time evaluation on|off --patterns:on|off turn pattern matching on|off + --memTracker:on|off turn memory tracker on|off + --excessiveStackTrace:on|off + stack traces use full file paths --skipCfg do not read the general configuration file --skipUserCfg do not read the user's configuration file --skipParentCfg do not read the parent dirs' configuration files diff --git a/doc/astspec.txt b/doc/astspec.txt index 35eb1727b..f430677af 100644 --- a/doc/astspec.txt +++ b/doc/astspec.txt @@ -1184,6 +1184,7 @@ Nim type Corresponding AST ``proc`` ``nnkProcTy`` ``iterator`` ``nnkIteratorTy`` ``object`` ``nnkObjectTy`` +------------- --------------------------------------------- Take special care when declaring types as ``proc``. The behavior is similar to ``Procedure declaration``, below, but does not treat ``nnkGenericParams``. diff --git a/doc/basicopt.txt b/doc/basicopt.txt index 9a1cfd956..eabd531a1 100644 --- a/doc/basicopt.txt +++ b/doc/basicopt.txt @@ -5,7 +5,7 @@ Command: //compile, c compile project with default code generator (C) //doc generate the documentation for inputfile - //doc2 generate the documentation for the whole project + //doc2 generate the documentation for inputfile Arguments: arguments are passed to the program being run (if --run option is selected) diff --git a/doc/contributing.rst b/doc/contributing.rst new file mode 100644 index 000000000..31f04a5e0 --- /dev/null +++ b/doc/contributing.rst @@ -0,0 +1,226 @@ +Writing tests +============= + +Not all the tests follow this scheme, feel free to change the ones +that don't. Always leave the code cleaner than you found it. + +Stdlib +------ + +If you change the stdlib (anything under ``lib/``), put a test in the +file you changed. Add the tests under an ``when isMainModule:`` +condition so they only get executed when the tester is building the +file. Each test should be in a separate ``block:`` statement, such that +each has its own scope. Use boolean conditions and ``doAssert`` for the +testing by itself, don't rely on echo statements or similar. + +Sample test: + +.. code-block:: nim + + when isMainModule: + block: # newSeqWith tests + var seq2D = newSeqWith(4, newSeq[bool](2)) + seq2D[0][0] = true + seq2D[1][0] = true + seq2D[0][1] = true + doAssert seq2D == @[@[true, true], @[true, false], + @[false, false], @[false, false]] + +Compiler +-------- + +The tests for the compiler work differently, they are all located in +``tests/``. Each test has its own file, which is different from the +stdlib tests. All test files are prefixed with ``t``. If you want to +create a file for import into another test only, use the prefix ``m``. + +At the beginning of every test is the expected side of the test. +Possible keys are: + +- output: The expected output, most likely via ``echo`` +- exitcode: Exit code of the test (via ``exit(number)``) +- errormsg: The expected error message +- file: The file the errormsg +- line: The line the errormsg was produced at + +An example for a test: + +.. code-block:: nim + + discard """ + errormsg: "type mismatch: got (PTest)" + """ + + type + PTest = ref object + + proc test(x: PTest, y: int) = nil + + var buf: PTest + buf.test() + +Running tests +============= + +You can run the tests with + +:: + + ./koch tests + +which will run a good subset of tests. Some tests may fail. If you +only want to see the output of failing tests, go for + +:: + + ./koch tests --failing all + +You can also run only a single category of tests. A category is a subdirectory +in the ``tests`` directory. There are a couple of special categories; for a +list of these, see ``tests/testament/categories.nim``, at the bottom. + +:: + + ./koch tests c lib + +Comparing tests +=============== + +Because some tests fail in the current ``devel`` branch, not every fail +after your change is necessarily caused by your changes. + +The tester can compare two test runs. First, you need to create the +reference test. You'll also need to the commit id, because that's what +the tester needs to know in order to compare the two. + +:: + + git checkout devel + DEVEL_COMMIT=$(git rev-parse HEAD) + ./koch tests + +Then switch over to your changes and run the tester again. + +:: + + git checkout your-changes + ./koch tests + +Then you can ask the tester to create a ``testresults.html`` which will +tell you if any new tests passed/failed. + +:: + + ./koch tests --print html $DEVEL_COMMIT + + +Deprecation +=========== + +Backward compatibility is important, so if you are renaming a proc or +a type, you can use + + +.. code-block:: nim + + {.deprecated: [oldName: new_name].} + +Or you can simply use + +.. code-block:: nim + + proc oldProc() {.deprecated.} + +to mark a symbol as deprecated. Works for procs/types/vars/consts, +etc. Note that currently the ``deprecated`` statement does not work well with +overloading so for routines the latter variant is better. + + +`Deprecated <http://nim-lang.org/docs/manual.html#pragmas-deprecated-pragma>`_ +pragma in the manual. + + +Documentation +============= + +When contributing new procedures, be sure to add documentation, especially if +the procedure is exported from the module. Documentation begins on the line +following the ``proc`` definition, and is prefixed by ``##`` on each line. + +Code examples are also encouraged. The RestructuredText Nim uses has a special +syntax for including examples. + +.. code-block:: nim + + proc someproc*(): string = + ## Return "something" + ## + ## .. code-block:: nim + ## + ## echo someproc() # "something" + result = "something" # single-hash comments do not produce documentation + +The ``.. code-block:: nim`` followed by a newline and an indentation instructs the +``nim doc`` and ``nim doc2`` commands to produce syntax-highlighted example code with +the documentation. + +When forward declaration is used, the documentation should be included with the +first appearance of the proc. + +.. code-block:: nim + + proc hello*(): string + ## Put documentation here + proc nothing() = discard + proc hello*(): string = + ## Ignore this + echo "hello" + +The preferred documentation style is to begin with a capital letter and use +the imperative (command) form. That is, between: + +.. code-block:: nim + + proc hello*(): string = + # Return "hello" + result = "hello" +or + +.. code-block:: nim + + proc hello*(): string = + # says hello + result = "hello" + +the first is preferred. + +The Git stuff +============= + +General commit rules +-------------------- + +1. All changes introduced by the commit (diff lines) must be related to the + subject of the commit. + + If you change some other unrelated to the subject parts of the file, because + your editor reformatted automatically the code or whatever different reason, + this should be excluded from the commit. + + *Tip:* Never commit everything as is using ``git commit -a``, but review + carefully your changes with ``git add -p``. + +2. Changes should not introduce any trailing whitespace. + + Always check your changes for whitespace errors using ``git diff --check`` + or add following ``pre-commit`` hook: + + .. code-block:: sh + + #!/bin/sh + git diff --check --cached || exit $? + +3. Describe your commit and use your common sense. + +.. include:: docstyle.rst diff --git a/doc/docs.txt b/doc/docs.rst index 4484784ae..4484784ae 100644 --- a/doc/docs.txt +++ b/doc/docs.rst diff --git a/doc/docstyle.rst b/doc/docstyle.rst new file mode 100644 index 000000000..d789b1df9 --- /dev/null +++ b/doc/docstyle.rst @@ -0,0 +1,140 @@ +Documentation Style +=================== + +General Guidelines +------------------ + +* Authors should document anything that is exported. +* Within documentation, a period (`.`) should follow each sentence (or sentence fragment) in a comment block. The documentation may be limited to one sentence fragment, but if multiple sentences are within the documentation, each sentence after the first should be complete and in present tense. +* Documentation is parsed as ReStructuredText (RST). +* Inline code should be surrounded by double tick marks ("``````"). If you would like a character to immediately follow inline code (e.g., "``int8``s are great!"), escape the following character with a backslash (``\``). The preceding is typed as ``` ``int8``\s are great!```. + +Module-level documentation +-------------------------- + +Documentation of a module is placed at the top of the module itself. Each line of documentation begins with double hashes (``##``). +Code samples are encouraged, and should follow the general RST syntax: + +.. code-block:: Nim + + ## The ``universe`` module computes the answer to life, the universe, and everything. + ## + ## .. code-block:: Nim + ## echo computeAnswerString() # "42" + + +Within this top-level comment, you can indicate the authorship and copyright of the code, which will be featured in the produced documentation. + +.. code-block:: Nim + + ## This is the best module ever. It provides answers to everything! + ## + ## :Author: Steve McQueen + ## :Copyright: 1965 + ## + +Leave a space between the last line of top-level documentation and the beginning of Nim code (the imports, etc.). + +Procs, Templates, Macros, Converters, and Iterators +--------------------------------------------------- + +The documentation of a procedure should begin with a capital letter and should be in present tense. Variables referenced in the documentation should be surrounded by double tick marks (``````). + +.. code-block:: Nim + + proc example1*(x: int) = + ## Prints the value of ``x``. + echo x + +Whenever an example of usage would be helpful to the user, you should include one within the documentation in RST format as below. + +.. code-block:: Nim + + proc addThree*(x, y, z: int8): int = + ## Adds three ``int8`` values, treating them as unsigned and + ## truncating the result. + ## + ## .. code-block:: nim + ## echo addThree(3, 125, 6) # -122 + result = x +% y +% z + +The commands ``nim doc`` and ``nim doc2`` will then correctly syntax highlight the Nim code within the documentation. + +Types +----- + +Exported types should also be documented. This documentation can also contain code samples, but those are better placed with the functions to which they refer. + +.. code-block:: Nim + + type + NamedQueue*[T] = object ## Provides a linked data structure with names + ## throughout. It is named for convenience. I'm making + ## this comment long to show how you can, too. + name*: string ## The name of the item + val*: T ## Its value + next*: ref NamedQueue[T] ## The next item in the queue + + +You have some flexibility when placing the documentation: + +.. code-block:: Nim + + type + NamedQueue*[T] = object + ## Provides a linked data structure with names + ## throughout. It is named for convenience. I'm making + ## this comment long to show how you can, too. + name*: string ## The name of the item + val*: T ## Its value + next*: ref NamedQueue[T] ## The next item in the queue + +Make sure to place the documentation beside or within the object. + +.. code-block:: Nim + + type + ## This documentation disappears because it annotates the ``type`` keyword + ## above, not ``NamedQueue``. + NamedQueue*[T] = object + name*: string ## This becomes the main documentation for the object, which + ## is not what we want. + val*: T ## Its value + next*: ref NamedQueue[T] ## The next item in the queue + +Var, Let, and Const +------------------- + +When declaring module-wide constants and values, documentation is encouraged. The placement of doc comments is similar to the ``type`` sections. + +.. code-block:: Nim + + const + X* = 42 ## An awesome number. + SpreadArray* = [ + [1,2,3], + [2,3,1], + [3,1,2], + ] ## Doc comment for ``SpreadArray``. + +Placement of comments in other areas is usually allowed, but will not become part of the documentation output and should therefore be prefaced by a single hash (``#``). + +.. code-block:: Nim + + const + BadMathVals* = [ + 3.14, # pi + 2.72, # e + 0.58, # gamma + ] ## A bunch of badly rounded values. + +Nim supports Unicode in comments, so the above can be replaced with the following: + +.. code-block:: Nim + + const + BadMathVals* = [ + 3.14, # π + 2.72, # e + 0.58, # γ + ] ## A bunch of badly rounded values (including π!). diff --git a/doc/gc.rst b/doc/gc.rst index 1c8cb9122..bb0088617 100644 --- a/doc/gc.rst +++ b/doc/gc.rst @@ -19,8 +19,10 @@ This document describes how the GC works and how to tune it for The basic algorithm is *Deferred Reference Counting* with cycle detection. References on the stack are not counted for better performance (and easier C -code generation). The GC **never** scans the whole heap but it may scan the -delta-subgraph of the heap that changed since its last run. +code generation). Cycle detection is currently done by a simple mark&sweep +GC that has to scan the full (thread local heap). ``--gc:v2`` replaces this +with an incremental mark and sweep. That it is not production ready yet, +however. The GC is only triggered in a memory allocation operation. It is not triggered @@ -34,17 +36,7 @@ Cycle collector =============== The cycle collector can be en-/disabled independently from the other parts of -the GC with ``GC_enableMarkAndSweep`` and ``GC_disableMarkAndSweep``. The -compiler analyses the types for their possibility to build cycles, but often -it is necessary to help this analysis with the ``acyclic`` pragma (see -`acyclic <manual.html#acyclic-pragma>`_ for further information). - -You can also use the ``acyclic`` pragma for data that is cyclic in reality and -then break up the cycles explicitly with ``GC_addCycleRoot``. This can be a -very valuable optimization; the Nim compiler itself relies on this -optimization trick to improve performance. Note that ``GC_addCycleRoot`` is -a quick operation; the root is only registered for the next run of the -cycle collector. +the GC with ``GC_enableMarkAndSweep`` and ``GC_disableMarkAndSweep``. Realtime support @@ -55,19 +47,19 @@ defined via ``--define:useRealtimeGC`` (you can put this into your config file as well). With this switch the GC supports the following operations: .. code-block:: nim - proc GC_setMaxPause*(MaxPauseInUs: int) + proc GC_setMaxPause*(maxPauseInUs: int) proc GC_step*(us: int, strongAdvice = false, stackSize = -1) -The unit of the parameters ``MaxPauseInUs`` and ``us`` is microseconds. +The unit of the parameters ``maxPauseInUs`` and ``us`` is microseconds. These two procs are the two modus operandi of the realtime GC: (1) GC_SetMaxPause Mode You can call ``GC_SetMaxPause`` at program startup and then each triggered - GC run tries to not take longer than ``MaxPause`` time. However, it is + GC run tries to not take longer than ``maxPause`` time. However, it is possible (and common) that the work is nevertheless not evenly distributed - as each call to ``new`` can trigger the GC and thus take ``MaxPause`` + as each call to ``new`` can trigger the GC and thus take ``maxPause`` time. (2) GC_step Mode @@ -86,8 +78,8 @@ These two procs are the two modus operandi of the realtime GC: These procs provide a "best effort" realtime guarantee; in particular the cycle collector is not aware of deadlines yet. Deactivate it to get more predictable realtime behaviour. Tests show that a 2ms max pause -time will be met in almost all cases on modern CPUs unless the cycle collector -is triggered. +time will be met in almost all cases on modern CPUs (with the cycle collector +disabled). Time measurement diff --git a/doc/intern.txt b/doc/intern.txt index 05847169f..d0aaa283a 100644 --- a/doc/intern.txt +++ b/doc/intern.txt @@ -459,7 +459,7 @@ This should produce roughly this code: PEnv = ref object x: int # data - proc anon(y: int, c: PClosure): int = + proc anon(y: int, c: PEnv): int = return y + c.x proc add(x: int): tuple[prc, data] = diff --git a/doc/lib.rst b/doc/lib.rst index 828889968..8bb602b78 100644 --- a/doc/lib.rst +++ b/doc/lib.rst @@ -77,8 +77,9 @@ Collections and algorithms * `lists <lists.html>`_ Nim linked list support. Contains singly and doubly linked lists and circular lists ("rings"). -* `queues <queues.html>`_ - Implementation of a queue. The underlying implementation uses a ``seq``. +* `deques <deques.html>`_ + Implementation of a double-ended queue. + The underlying implementation uses a ``seq``. * `intsets <intsets.html>`_ Efficient implementation of a set of ints as a sparse bit set. * `critbits <critbits.html>`_ diff --git a/doc/manual/exceptions.txt b/doc/manual/exceptions.txt index d06c13df4..0f1240a4a 100644 --- a/doc/manual/exceptions.txt +++ b/doc/manual/exceptions.txt @@ -147,7 +147,7 @@ the ``raise`` statement is the only way to raise an exception. If no exception name is given, the current exception is `re-raised`:idx:. The `ReraiseError`:idx: exception is raised if there is no exception to re-raise. It follows that the ``raise`` statement *always* raises an -exception (unless a raise hook has been provided). +exception. Exception hierarchy diff --git a/doc/manual/types.txt b/doc/manual/types.txt index 02426e0d9..c81bc042b 100644 --- a/doc/manual/types.txt +++ b/doc/manual/types.txt @@ -716,7 +716,8 @@ untraced references are *unsafe*. However for certain low-level operations (accessing the hardware) untraced references are unavoidable. Traced references are declared with the **ref** keyword, untraced references -are declared with the **ptr** keyword. +are declared with the **ptr** keyword. In general, a `ptr T` is implicitly +convertible to the `pointer` type. An empty subscript ``[]`` notation can be used to derefer a reference, the ``addr`` procedure returns the address of an item. An address is always diff --git a/doc/nimc.rst b/doc/nimc.rst index eb1beb549..5d9ed03ab 100644 --- a/doc/nimc.rst +++ b/doc/nimc.rst @@ -258,6 +258,10 @@ Define Effect ``ssl`` Enables OpenSSL support for the sockets module. ``memProfiler`` Enables memory profiling for the native GC. ``uClibc`` Use uClibc instead of libc. (Relevant for Unix-like OSes) +``checkAbi`` When using types from C headers, add checks that compare + what's in the Nim file with what's in the C header + (requires a C compiler with _Static_assert support, like + any C11 compiler) ================== ========================================================= diff --git a/doc/nims.rst b/doc/nims.rst index 7c76efe42..12d86a905 100644 --- a/doc/nims.rst +++ b/doc/nims.rst @@ -75,22 +75,8 @@ done: Nimble integration ================== -A ``project.nims`` file can also be used as an alternative to -a ``project.nimble`` file to specify the meta information (for example, author, -description) and dependencies of a Nimble package. This means you can easily -have platform specific dependencies: - -.. code-block:: nim - - version = "1.0" - author = "The green goo." - description = "Lexer generation and regex implementation for Nim." - license = "MIT" - - when defined(windows): - requires "oldwinapi >= 1.0" - else: - requires "gtk2 >= 1.0" +See the `Nimble readme <https://github.com/nim-lang/nimble#readme>`_ +for more information. diff --git a/doc/overview.txt b/doc/overview.rst index 5b41752ae..e01520d7c 100644 --- a/doc/overview.txt +++ b/doc/overview.rst @@ -5,5 +5,5 @@ Nim Documentation Overview :Author: Andreas Rumpf :Version: |nimversion| -.. include:: ../doc/docs.txt +.. include:: docs.rst |