fix grammar
This commit is contained in:
parent
f6243d5900
commit
eef0e1bde1
2 changed files with 22 additions and 22 deletions
|
|
@ -70,8 +70,8 @@ the compiler to pass the type by reference (hidden pointer) to procs.
|
||||||
|
|
||||||
Varargs pragma
|
Varargs pragma
|
||||||
--------------
|
--------------
|
||||||
The ``varargs`` pragma can be applied to procedures only (and procedure
|
The ``varargs`` pragma can be applied to procedures only (and procedure
|
||||||
types). It tells Nim that the proc can take a variable number of parameters
|
types). It tells Nim that the proc can take a variable number of parameters
|
||||||
after the last specified parameter. Nim string values will be converted to C
|
after the last specified parameter. Nim string values will be converted to C
|
||||||
strings automatically:
|
strings automatically:
|
||||||
|
|
||||||
|
|
@ -94,20 +94,20 @@ should scan unions conservatively.
|
||||||
|
|
||||||
Packed pragma
|
Packed pragma
|
||||||
-------------
|
-------------
|
||||||
The ``packed`` pragma can be applied to any ``object`` type. It ensures
|
The ``packed`` pragma can be applied to any ``object`` type. It ensures
|
||||||
that the fields of an object are packed back-to-back in memory. It is useful
|
that the fields of an object are packed back-to-back in memory. It is useful
|
||||||
to store packets or messages from/to network or hardware drivers, and for
|
to store packets or messages from/to network or hardware drivers, and for
|
||||||
interoperability with C. Combining packed pragma with inheritance is not
|
interoperability with C. Combining packed pragma with inheritance is not
|
||||||
defined, and it should not be used with GC'ed memory (ref's).
|
defined, and it should not be used with GC'ed memory (ref's).
|
||||||
|
|
||||||
**Future directions**: Using GC'ed memory in packed pragma will result in
|
**Future directions**: Using GC'ed memory in packed pragma will result in
|
||||||
compile-time error. Usage with inheritance should be defined and documented.
|
compile-time error. Usage with inheritance should be defined and documented.
|
||||||
|
|
||||||
Unchecked pragma
|
Unchecked pragma
|
||||||
----------------
|
----------------
|
||||||
The ``unchecked`` pragma can be used to mark a named array as ``unchecked``
|
The ``unchecked`` pragma can be used to mark a named array as ``unchecked``
|
||||||
meaning its bounds are not checked. This is often useful when one wishes to
|
meaning its bounds are not checked. This is often useful to
|
||||||
implement their own flexibly sized arrays. Additionally an unchecked array is
|
implement customized flexibly sized arrays. Additionally an unchecked array is
|
||||||
translated into a C array of undetermined size:
|
translated into a C array of undetermined size:
|
||||||
|
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
|
|
@ -141,7 +141,7 @@ runtime size of the array.
|
||||||
Dynlib pragma for import
|
Dynlib pragma for import
|
||||||
------------------------
|
------------------------
|
||||||
With the ``dynlib`` pragma a procedure or a variable can be imported from
|
With the ``dynlib`` pragma a procedure or a variable can be imported from
|
||||||
a dynamic library (``.dll`` files for Windows, ``lib*.so`` files for UNIX).
|
a dynamic library (``.dll`` files for Windows, ``lib*.so`` files for UNIX).
|
||||||
The non-optional argument has to be the name of the dynamic library:
|
The non-optional argument has to be the name of the dynamic library:
|
||||||
|
|
||||||
.. code-block:: Nim
|
.. code-block:: Nim
|
||||||
|
|
@ -152,17 +152,17 @@ In general, importing a dynamic library does not require any special linker
|
||||||
options or linking with import libraries. This also implies that no *devel*
|
options or linking with import libraries. This also implies that no *devel*
|
||||||
packages need to be installed.
|
packages need to be installed.
|
||||||
|
|
||||||
The ``dynlib`` import mechanism supports a versioning scheme:
|
The ``dynlib`` import mechanism supports a versioning scheme:
|
||||||
|
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
proc Tcl_Eval(interp: pTcl_Interp, script: cstring): int {.cdecl,
|
proc Tcl_Eval(interp: pTcl_Interp, script: cstring): int {.cdecl,
|
||||||
importc, dynlib: "libtcl(|8.5|8.4|8.3).so.(1|0)".}
|
importc, dynlib: "libtcl(|8.5|8.4|8.3).so.(1|0)".}
|
||||||
|
|
||||||
At runtime the dynamic library is searched for (in this order)::
|
At runtime the dynamic library is searched for (in this order)::
|
||||||
|
|
||||||
libtcl.so.1
|
libtcl.so.1
|
||||||
libtcl.so.0
|
libtcl.so.0
|
||||||
libtcl8.5.so.1
|
libtcl8.5.so.1
|
||||||
libtcl8.5.so.0
|
libtcl8.5.so.0
|
||||||
libtcl8.4.so.1
|
libtcl8.4.so.1
|
||||||
libtcl8.4.so.0
|
libtcl8.4.so.0
|
||||||
|
|
@ -175,22 +175,22 @@ string expressions in general:
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
import os
|
import os
|
||||||
|
|
||||||
proc getDllName: string =
|
proc getDllName: string =
|
||||||
result = "mylib.dll"
|
result = "mylib.dll"
|
||||||
if existsFile(result): return
|
if existsFile(result): return
|
||||||
result = "mylib2.dll"
|
result = "mylib2.dll"
|
||||||
if existsFile(result): return
|
if existsFile(result): return
|
||||||
quit("could not load dynamic library")
|
quit("could not load dynamic library")
|
||||||
|
|
||||||
proc myImport(s: cstring) {.cdecl, importc, dynlib: getDllName().}
|
proc myImport(s: cstring) {.cdecl, importc, dynlib: getDllName().}
|
||||||
|
|
||||||
**Note**: Patterns like ``libtcl(|8.5|8.4).so`` are only supported in constant
|
**Note**: Patterns like ``libtcl(|8.5|8.4).so`` are only supported in constant
|
||||||
strings, because they are precompiled.
|
strings, because they are precompiled.
|
||||||
|
|
||||||
**Note**: Passing variables to the ``dynlib`` pragma will fail at runtime
|
**Note**: Passing variables to the ``dynlib`` pragma will fail at runtime
|
||||||
because of order of initialization problems.
|
because of order of initialization problems.
|
||||||
|
|
||||||
**Note**: A ``dynlib`` import can be overriden with
|
**Note**: A ``dynlib`` import can be overriden with
|
||||||
the ``--dynlibOverride:name`` command line option. The Compiler User Guide
|
the ``--dynlibOverride:name`` command line option. The Compiler User Guide
|
||||||
contains further information.
|
contains further information.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -333,7 +333,7 @@ The while statement is a simple looping construct:
|
||||||
name = readLine(stdin)
|
name = readLine(stdin)
|
||||||
# no ``var``, because we do not declare a new variable here
|
# no ``var``, because we do not declare a new variable here
|
||||||
|
|
||||||
The example uses a while loop to keep asking the user for their name, as long
|
The example uses a while loop to keep asking the users for their name, as long
|
||||||
as the user types in nothing (only presses RETURN).
|
as the user types in nothing (only presses RETURN).
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -774,7 +774,7 @@ proc even(n: int): bool =
|
||||||
Here ``odd`` depends on ``even`` and vice versa. Thus ``even`` needs to be
|
Here ``odd`` depends on ``even`` and vice versa. Thus ``even`` needs to be
|
||||||
introduced to the compiler before it is completely defined. The syntax for
|
introduced to the compiler before it is completely defined. The syntax for
|
||||||
such a forward declaration is simple: just omit the ``=`` and the
|
such a forward declaration is simple: just omit the ``=`` and the
|
||||||
procedure's body. The ``assert`` just adds border conditions, and will be
|
procedure's body. The ``assert`` just adds border conditions, and will be
|
||||||
covered later in `Modules`_ section.
|
covered later in `Modules`_ section.
|
||||||
|
|
||||||
Later versions of the language will weaken the requirements for forward
|
Later versions of the language will weaken the requirements for forward
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue