Commit Graph

2084 Commits

Author SHA1 Message Date
Tomohiro
de1f7188eb Fix example code in Nim manual that cannot be compiled without error (#23722) 2024-06-15 10:34:26 +08:00
Antonis Geralis
63398b11f5 Add a note about the sideeffect pragma (#23543) 2024-05-08 14:53:29 -06:00
yojiyama7
47594eb909 fix typo: "As can been seen" to "As can be seen" (#23544) 2024-04-28 12:36:51 +02:00
ringabout
9e1d0d1513 fixes #4695; closure iterators support for JS backend (#23493)
fixes #4695

ref https://github.com/nim-lang/Nim/pull/15818

Since `nkState` is only for the main loop state labels and `nkGotoState`
is used only for dispatching the `:state` (since
https://github.com/nim-lang/Nim/pull/7770), it's feasible to rewrite the
loop body into a single case-based dispatcher, which enables support for
JS, VM backend. `nkState` Node is replaced by a label and Node pair and
`nkGotoState` is only used for intermediary processing. Backends only
need to implement `nkBreakState` and `closureIterSetupExc` to support
closure iterators.

pending https://github.com/nim-lang/Nim/pull/23484

<del> I also observed some performance boost for C backend in the
release mode (not in the danger mode though, I suppose the old
implementation is optimized into computed goto in the danger mode)
</del>

allPathsAsgnResult???
2024-04-18 18:52:30 +02:00
arkanoid87
cbf48a253f Update manual.md (#23393)
adding link to generic == for tuples in Open and Closed symbols example
2024-03-16 06:23:44 +01:00
ringabout
c2d2b6344d remove mention of GC_ref and GC_unref for strings (#23373) 2024-03-06 21:24:55 +01:00
ringabout
e217bb24a1 fixes #20945; fixes #18262; provides C API NimDestroyGlobals for static/dynlib libraries (#23357)
fixes #20945
fixes #18262

todo
- [ ] perhaps export with lib prefix when the option is enabled
2024-03-04 10:14:25 +01:00
ringabout
a619434904 remove obselete doc with nimrtl (#23358)
since nimrtl.dll is created with `--threads:on`
2024-03-04 09:57:40 +01:00
Silly Carbon
243f1e6cd5 Fixes #23085: update grammars for 'concept' (#23256)
Fixes #23085
2024-01-26 08:03:41 +01:00
ringabout
0b363442e5 fixes broken doc links (#23255)
https://nim-lang.github.io/Nim/testament.html#writing-unit-tests 

https://nim-lang.github.io/Nim/testament.html#writing-unit-tests-output-message-variable-interpolation
2024-01-25 14:10:32 +08:00
Ryan McConnell
af8b1d0cb9 Fixing overload resolution documentation (#23171)
As requested. Let me know where adjustments are wanted.
2024-01-19 13:12:31 +01:00
Tomohiro
527d1e1977 Nim Compiler User Guide: Add explanations about lto and strip (#23227) 2024-01-18 21:25:31 +01:00
Ethosa
ade5295fd5 fix link to jsfetch stdlib (#23203) 2024-01-12 20:50:20 +08:00
metagn
6650b41777 document the new ambiguous identifier resolution (#23166)
refs #23123

Not sure if detailed enough.
2024-01-11 12:39:51 +01:00
Tomohiro
e20a2b1f2b Nim manual: better byref pragma explanation (#23192)
Nim manual says:
> When using the Cpp backend, params marked as byref will translate to
cpp references `&`

But how `byref` pragma translate to depends on whether it is used with
`importc` or `importcpp`.
When `byref` pragma used with `importc` types and compiled with the Cpp
backend, it is not traslated to cpp reference `&`.

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2024-01-09 17:37:41 +01:00
Ryan McConnell
74fa8ed59a Changing generic weight of tyGenericParam (#22143)
This is in reference to a [feature
request](https://github.com/nim-lang/Nim/issues/22142) that I posted.

I'm making this PR to demonstrate the suggested change and expect that
this should be scrutinized

---------

Co-authored-by: Bung <crc32@qq.com>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2024-01-05 09:42:21 +01:00
Jacek Sieka
c4f98b7696 Recommend hanging indent in NEP1 (#23105)
This PR modernises the NEP1 style guide to prefer hanging indent over
vertial alignment for long code statements while still allowing
alignment in legacy code.

The change is based on research and study of existing style guides for
both braced and indented languages that have seen wide adoption as well
as working with a large Nim codebase with several teams touching the
same code regularly.

The research was done as part of due diligence leading up to
[nph](https://github.com/arnetheduck/nph) which uses this style
throughout.

There are several reasons why hanging indent works well for
collaboration, good code practices and modern Nim features:

* as NEP1 itself points out, alignment causes unnecessary friction when
refactoring, adding/removing items to lists and otherwise improving code
style or due to the need for realignment - the new recommendation aligns
NEP1 with itself
* When collaborating, alignment leads to unnecessary git conflicts and
blame changes - with hanging indent, such conflicts are minimised.
* Vertical alignment pushes much of the code to the right where often
there is little space - when using modern features such as generics
where types may be composed of several (descriptively named) components,
there is simply no more room for parameters or comments
* The space to the left of the alignemnt cannot productively be used for
anything (unlike on the right, where comments may be placed)
* Double hanging indent maintaines visual separation between parameters
/ condition and the body that follows.

This may seem like a drastic change, but in reality, it is not:

* the most popular editor for Nim (vscode) already promotes this style
by default (if you press enter after `(`, it will jump to an indent on
the next line)
* although orthogonal to these changes, tools such as `nph` can be used
to reformat existing code should this be desired - when done in a single
commit, `git blame` is not lost and neither are exsting PRs (they can
simply be reformatted deterministically) - `nph` is also integrated with
vscode.
* It only affects long lines - ie most code remains unchanged

Examples of vertical alignment in the wild, for wildly successful
languages and formatters:

* [PEP-8](https://peps.python.org/pep-0008/#indentation) 
*
[black](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#how-black-wraps-lines)
* [prettier](https://prettier.io/docs/en/)

The above examples are useful mainly to show that hanging-indent
_generally_ is no impediment to efficient code reading and on the whole
is an uncontroversial choice as befits the standard library.
2024-01-03 14:06:39 +01:00
ASVIEST
1324d2e04c Asm syntax pragma (#23119)
(Inspired by this pragma in nir asm PR)

`inlineAsmSyntax` pragma allowing specify target inline assembler syntax
in `asm` stmt.

It prevents compiling code with different of the target CC inline asm
syntax, i.e. it will not allow gcc inline asm code to be compiled with
vcc.

```nim
proc nothing() =
  asm {.inlineAsmSyntax: "gcc".} """
    nop
  """
```

The current C(C++) backend implementation cannot generate code for gcc
and for vcc at the same time. For example, `{.inlineAsmSyntax: "vcc".}`
with the ICC compiler will not generate code with intel asm syntax, even
though ICC can use both gcc-like asm and vcc-like. For implement support
for gcc and for vcc at the same time in ICC compiler, we need to
refactor extccomp

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-12-25 07:12:54 +01:00
metagn
4b1a841707 add switch, warning, and bind support for new generic injection behavior (#23102)
refs #23091, especially post merge comments

Unsure if `experimental` and `bind` are the perfect constructs to use
but they seem to get the job done here. Symbol nodes do not get marked
`nfOpenSym` if the `bind` statement is used for their symbol, and
`nfOpenSym` nodes do not get replaced by new local symbols if the
experimental switch is not enabled in the local context (meaning it also
works with `push experimental`). However this incurs a warning as the
fact that the node is marked `nfOpenSym` means we did not `bind` it, so
we might want to do that or turn on the experimental switch if we didn't
intend to bind it.

The experimental switch name is arbitrary and could be changed.

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-12-22 08:49:51 +01:00
ringabout
b15463948c document --experimental:vtables (#23111) 2023-12-21 08:56:02 +01:00
ringabout
4321ce2635 fixes nimdoc warnings (#23110) 2023-12-21 14:58:17 +08:00
ringabout
434e062e82 fixes #18073; fixes #14730; document notnil is only applied to local … (#23084)
…symbols

fixes #18073
fixes #14730
2023-12-19 10:24:22 +01:00
ringabout
0c3e703960 fixes not nil examples (#23080) 2023-12-15 21:12:28 +08:00
Marko Schütz-Schmuck
80ffbd4571 Minor documentation change (#22951)
I've made a small change in the explanation of `void` types.
2023-11-17 10:21:21 +01:00
Ikko Eltociear Ashimine
cd84cd45ea doc: update manual_experimental.md (#22949)
sematics -> semantics
2023-11-16 22:30:08 +08:00
ringabout
4d11d0619d complete std prefixes for stdlib (#22887)
follow up https://github.com/nim-lang/Nim/pull/22851
follow up https://github.com/nim-lang/Nim/pull/22873
2023-10-30 17:03:04 +01:00
ringabout
cef5e57eb5 fixes #22867; fixes cstring modification example on Nim Manual (#22871)
fixes #22867
2023-10-26 10:06:44 +02:00
shuoer86
7c3917d1dd doc: fix typos (#22869)
doc: fix typos
2023-10-25 20:53:15 +08:00
Juan M Gómez
bf72d87f24 adds support for noDecl in constructor (#22811)
Notice the test wouldnt link before
2023-10-11 08:28:00 +02:00
Juan M Gómez
8ac466980f marking a field with noInit allows to skip constructor initialiser (#22802)
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-10-08 23:51:44 +02:00
Levi Notik
f111009e5d Fix typo/grammar in exception tracking section (#22801)
I came across this sentence in the Nim Manual and couldn't make sense of
it. I believe this is the correct fix for the sentence.

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2023-10-07 07:43:17 +02:00
daylin
c3b95cbd2c docs: add another switch example for nimscript (#22772)
I couldn't find any documentation on the syntax for --hint:X:on|off with
`nimscript` except in [this old forum
post](https://forum.nim-lang.org/t/8526#55236).
2023-09-30 14:53:09 +02:00
Ryan McConnell
b2ca6bedae Make typeRel behave to spec (#22261)
The goal of this PR is to make `typeRel` accurate to it's definition for
generics:
```
# 3) When used with two type classes, it will check whether the types
# matching the first type class (aOrig) are a strict subset of the types matching
# the other (f). This allows us to compare the signatures of generic procs in
# order to give preferrence to the most specific one:
```

I don't want this PR to break any code, and I want to preserve all of
Nims current behaviors. I think that making this more accurate will help
serve as ground work for the future. It may not be possible to not break
anything but this is my attempt.

So that it is understood, this code was part of another PR (#22143) but
that problem statement only needed this change by extension. It's more
organized to split two problems into two PRs and this issue, being
non-breaking, should be a more immediate improvement.

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-09-30 06:34:14 +02:00
Juan Carlos
a9e6660a74 Documentation only (#22760)
- Documentation only.
- Sometimes newbies try to use Valgrind with RefC etc.
2023-09-27 17:59:26 +02:00
Juan Carlos
21218d743f Documentation only (#22761)
- Mention Bisect bot in Bisect documentation.
2023-09-27 05:49:17 +02:00
Juan Carlos
b289617013 Documentation only (#22735)
- Add Atomic ARC to Documentation. Documentation only, tiny diff.
2023-09-21 09:05:23 +02:00
Juan M Gómez
af617be67a removes references to this in the constructor section (#22730) 2023-09-20 12:02:55 +02:00
Juan M Gómez
cd0d0ca530 Document C++ Initializers (#22704)
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-09-15 12:08:41 +02:00
Andrey Makarov
c5495f40d5 docgen: add Pandoc footnotes (fixes #21080) (#22591)
This implements Pandoc Markdown-style footnotes,
that are compatible with Pandoc referencing syntax:

    Ref. [^ftn].

    [^ftn]: Block.

See https://pandoc.org/MANUAL.html#footnotes for more examples.
2023-09-03 16:09:36 +02:00
metagn
ba158d73dc type annotations for variable tuple unpacking, better error messages (#22611)
* type annotations for variable tuple unpacking, better error messages

closes #17989, closes https://github.com/nim-lang/RFCs/issues/339

* update grammar

* fix test
2023-09-01 06:26:53 +02:00
Hamid Bluri
a26ccb3476 fix #22492 (#22511)
* fix #22492

* Update nimdoc.css

remove scroll-y

* Update nimdoc.out.css

* Update nimdoc.css

* make it sticky again

* Update nimdoc.out.css

* danm sticky, use fixed

* Update nimdoc.out.css

* fix margin

* Update nimdoc.out.css

* make search input react to any change (not just keyboard events) according to https://github.com/nim-lang/Nim/pull/22511#issuecomment-1685218787
2023-08-22 18:31:21 +02:00
PhilippMDoerner
93407096db #22514 expand testament option docs (#22516)
* #22514 Expand docs on testament spec options

The file, line and column options of testament are not in the docs,
but can be very important to know.
They allow you to specify where a compile-time error originated from.

Particularly given that testament assumes the origin to always be
the test-file, this is important to know.

* #22514 Specify nimout relevance a bit more

* #22514 Fix slightly erroneous doc-link

* #22514 Add example

* #22514 Add some docs on ccodecheck
2023-08-19 17:25:38 +02:00
Juan M Gómez
60307cc373 updates manual with codegenDecl on params docs (#22333)
* documents member

* Update doc/manual_experimental.md

Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
2023-08-17 12:20:22 +02:00
Juan M Gómez
f642c9dbf1 documents member (#22460)
* documents member

* Apply suggestions from code review

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>

* Update doc/manual_experimental.md

* Update doc/manual_experimental.md

* Update doc/manual_experimental.md

* Update doc/manual_experimental.md

* Update doc/manual_experimental.md

* Update doc/manual_experimental.md

---------

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-08-12 10:37:52 +02:00
ringabout
e7b4c7cddb unify starting blank lines in the experimental manual (#22396)
unify starting blank lines in the experimental manal
2023-08-06 17:59:43 +02:00
Bung
d2b197bdcd Stick search result (#22394)
* nimdoc: stick search result inside browser viewport

* fix nimdoc.out.css

---------

Co-authored-by: Locria Cyber <74560659+locriacyber@users.noreply.github.com>
2023-08-06 19:07:36 +08:00
Andreas Rumpf
9872453365 destructors: better docs [backport:2.0] (#22391) 2023-08-05 19:35:37 +02:00
ringabout
7c2a2c8dc8 fixes a typo in the manual (#22383)
ref 0d3bde95f5 (commitcomment-122093273)
2023-08-04 18:00:00 +08:00
SirOlaf
8d8d75706c Add experimental inferGenericTypes switch (#22317)
* Infer generic bindings

* Simple test

* Add t

* Allow it to work for templates too

* Fix some builds by putting bindings in a template

* Fix builtins

* Slightly more exotic seq test

* Test value-based generics using array

* Pass expectedType into buildBindings

* Put buildBindings into a proc

* Manual entry

* Remove leftover `

* Improve language used in the manual

* Experimental flag and fix basic constructors

* Tiny commend cleanup

* Move to experimental manual

* Use 'kind' so tuples continue to fail like before

* Explicitly disallow tuples

* Table test and document tuples

* Test type reduction

* Disable inferGenericTypes check for CI tests

* Remove tuple info in manual

* Always reduce types. Testing CI

* Fixes

* Ignore tyGenericInst

* Prevent binding already bound generic params

* tyUncheckedArray

* Few more types

* Update manual and check for flag again

* Update tests/generics/treturn_inference.nim

* var candidate, remove flag check again for CI

* Enable check once more

---------

Co-authored-by: SirOlaf <>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-08-03 22:49:52 +02:00
ringabout
569ccc50ff fixes #22174; fixes destructor examples (#22349)
* fixes #22174; fixes destructor examples

* Update doc/destructors.md

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-07-31 15:37:24 +02:00