summary refs log tree commit diff stats
path: root/koch.nim
Commit message (Expand)AuthorAgeFilesLines
* Improve Travis CI folding (#10473)Federico Ceratto2019-01-281-4/+4
* Enable log folding in Travis CI (#10414)Federico Ceratto2019-01-221-11/+14
* [CI] now enables `NIM_COMPILE_TO_CPP=true` to run without allow_failures (#10...Timothee Cour2019-01-171-8/+13
* koch.nim: Make bootstrapping in C++ mode robustAraq2019-01-161-4/+6
* properly fix #10030 by skipping all external configs (#10324)Timothee Cour2019-01-161-3/+4
* another attempt to fix https://github.com/nim-lang/nightlies/issues/17Araq2019-01-151-1/+1
* attempt to fix https://github.com/nim-lang/nightlies/issues/17Araq2019-01-151-1/+2
* [CI] runCI runs `kochExec "boot"` regardless of nim mode (#10312)Timothee Cour2019-01-151-2/+1
* fixes #10030 bootstrap is insulated from user config (#10244)Timothee Cour2019-01-101-2/+7
* fixes #10039 : CI now runs buildTools (eg, nimfind wasn't being compiled befo...Timothee Cour2019-01-101-22/+34
* [CI] fixes #10041 move bulk of `travis` and `appveyor` logic to koch.nim (#10...Timothee Cour2019-01-081-3/+43
* koch.nim: speed up tests for the 'testinstall' target for the nightly builds ...Araq2019-01-031-2/+1
* resolve merge conflictsAraq2018-12-121-1/+1
|\
| * Corrected erroneous vccexe tool path in kochFredrik Høisæther Rasch2017-03-211-1/+1
* | kick taint modeArne Döring2018-12-111-3/+1
* | Fixes #9913Neelesh Chandola2018-12-091-0/+2
* | add nimCompile to simplify koch; add nimfind to koch tools (#9723)Timothee Cour2018-11-151-20/+17
* | refs #9637 ; cleanup installation of nimsuggest (#9703)Timothee Cour2018-11-151-12/+9
* | change dir when koch starts (#9663)Arne Döring2018-11-091-0/+2
* | remove redundant -p:compiler in koch.nim given modules use import compiler/fooTimothee Cour2018-11-071-3/+3
* | make Nim take roughly 100MB less RAM for bootstrapping via a new compiler swi...Andreas Rumpf2018-11-071-0/+3
* | fixes #9276 (#9317)Arne Döring2018-10-241-3/+4
* | koch: bootstrap with C++ for NIM_COMPILE_TO_CPP env varAraq2018-10-181-1/+2
* | Testament pre parallel (#9137)Jacek Sieka2018-10-121-2/+2
* | koch tools: build Nimble in release modeAndreas Rumpf2018-10-031-1/+1
* | koch: add a --stable flag to build Nimble; refs #9017Araq2018-09-221-2/+9
* | koch: adapt winrelease to appveyorAraq2018-09-201-2/+2
* | koch: code cleanups, easier testing for 'testinstall' and 'winrelease'Araq2018-09-191-49/+56
* | koch: fix doc generation with Google Analytics enabledAraq2018-09-191-2/+0
* | attempt to make travis green for 'koch testinstall'Andreas Rumpf2018-09-181-0/+1
* | travis: run 'koch testinstall' on OSXAndreas Rumpf2018-09-181-28/+32
* | integrate 'koch web' features into koch; deprecate 'nimweb' toolAraq2018-09-131-66/+20
* | build nimble in debug mode to enable stack tracesAraq2018-09-101-1/+1
* | Merge branch 'devel' into araq-miscAraq2018-08-131-1/+2
|\ \
| * | Clarify usage of "Test" argument in Koch (#8613)Naveen Arunachalam2018-08-121-1/+2
* | | build Nimble with --nilseqs:on until Nimble is fixedAraq2018-08-131-2/+2
|/ /
* | make 'koch xz' enforce a clean 'git diff'; fixes #7292Araq2018-08-041-0/+8
* | fixes #8419 fixes #8420 ; workaround #6071 workaround nim-lang/website#98 (#8...Timothee Cour2018-07-301-0/+1
* | readded -d:debug flagArne Döring2018-06-261-1/+1
* | make basic debugging possibleArne Döring2018-06-261-1/+1
* | nimpretty: proper command line handling; added tests; travis ensures these st...Andreas Rumpf2018-06-191-5/+3
* | remove hardly used TimeMachine featureAndreas Rumpf2018-05-061-1/+0
* | make Nimble not crash after the refactoringAndreas Rumpf2018-05-051-1/+1
* | Fix lists of paths in posix environment (#7034)Dennis Felsing2018-01-081-2/+2
* | Faster nimgrep (#6983)Mathias Stearn2018-01-031-1/+1
* | Prep for tester parallel: private nimcache for each test (#6937)Mathias Stearn2017-12-181-1/+1
* | koch temp uses '-d:debug'Andreas Rumpf2017-11-141-2/+2
* | made nimresolve part of the compilerAndreas Rumpf2017-10-291-1/+1
* | Use findNim() in koch temp() (#6592)Stefan Rakel2017-10-251-1/+2
* | implemented new experimental scriptable import mechanismAndreas Rumpf2017-10-011-0/+3
.. code-block:: nim # create a type class that will match all tuple and object types type RecordType = tuple or object proc printFields(rec: RecordType) = for key, value in fieldPairs(rec): echo key, " = ", value Procedures utilizing type classes in such manner are considered to be `implicitly generic`:idx:. They will be instantiated once for each unique combination of param types used within the program. Nim also allows for type classes and regular types to be specified as `type constraints`:idx: of the generic type parameter: .. code-block:: nim proc onlyIntOrString[T: int|string](x, y: T) = discard onlyIntOrString(450, 616) # valid onlyIntOrString(5.0, 0.0) # type mismatch onlyIntOrString("xy", 50) # invalid as 'T' cannot be both at the same time By default, during overload resolution each named type class will bind to exactly one concrete type. Here is an example taken directly from the system module to illustrate this: .. code-block:: nim proc `==`*(x, y: tuple): bool = ## requires `x` and `y` to be of the same tuple type ## generic ``==`` operator for tuples that is lifted from the components ## of `x` and `y`. result = true for a, b in fields(x, y): if a != b: result = false Alternatively, the ``distinct`` type modifier can be applied to the type class to allow each param matching the type class to bind to a different type. If a proc param doesn't have a type specified, Nim will use the ``distinct auto`` type class (also known as ``any``). Note this behavior is deprecated for procs; templates, however, support them: .. code-block:: nim # allow any combination of param types proc concat(a, b): string = $a & $b # deprecated proc concat(a, b: any): string = $a & $b # preferred Procs written with the implicitly generic style will often need to refer to the type parameters of the matched generic type. They can be easily accessed using the dot syntax: .. code-block:: nim type Matrix[T, Rows, Columns] = object ... proc `[]`(m: Matrix, row, col: int): Matrix.T = m.data[col * high(Matrix.Columns) + row] Alternatively, the `type` operator can be used over the proc params for similar effect when anonymous or distinct type classes are used. When a generic type is instantiated with a type class instead of a concrete type, this results in another more specific type class: .. code-block:: nim seq[ref object] # Any sequence storing references to any object type type T1 = auto proc foo(s: seq[T1], e: T1) # seq[T1] is the same as just `seq`, but T1 will be allowed to bind # to a single type, while the signature is being matched Matrix[Ordinal] # Any Matrix instantiation using integer values As seen in the previous example, in such instantiations, it's not necessary to supply all type parameters of the generic type, because any missing ones will be inferred to have the equivalent of the `any` type class and thus they will match anything without discrimination. Concepts -------- **Note**: Concepts are still in development. Concepts, also known as "user-defined type classes", are used to specify an arbitrary set of requirements that the matched type must satisfy. Concepts are written in the following form: .. code-block:: nim type Comparable = concept x, y (x < y) is bool Container[T] = concept c c.len is Ordinal items(c) is iterator for value in c: type(value) is T The concept is a match if: a) all of the expressions within the body can be compiled for the tested type b) all statically evaluatable boolean expressions in the body must be true The identifiers following the ``concept`` keyword represent instances of the currently matched type. These instances can act both as variables of the type, when used in contexts where a value is expected, and as the type itself when used in contexts where a type is expected. Please note that the ``is`` operator allows one to easily verify the precise type signatures of the required operations, but since type inference and default parameters are still applied in the provided block, it's also possible to encode usage protocols that do not reveal implementation details. As a special rule providing further convenience when writing concepts, any type value appearing in a callable expression will be treated as a variable of the designated type for overload resolution purposes, unless the type value was passed in its explicit ``typedesc[T]`` form: .. code-block:: nim type OutputStream = concept s write(var s, string) Much like generics, concepts are instantiated exactly once for each tested type and any static code included within them is also executed once. Symbol lookup in generics ------------------------- The symbol binding rules in generics are slightly subtle: There are "open" and "closed" symbols. A "closed" symbol cannot be re-bound in the instantiation context, an "open" symbol can. Per default overloaded symbols are open and every other symbol is closed. Open symbols are looked up in two different contexts: Both the context at definition and the context at instantiation are considered: .. code-block:: nim type Index = distinct int proc `==` (a, b: Index): bool {.borrow.} var a = (0, 0.Index) var b = (0, 0.Index) echo a == b # works! In the example the generic ``==`` for tuples (as defined in the system module) uses the ``==`` operators of the tuple's components. However, the ``==`` for the ``Index`` type is defined *after* the ``==`` for tuples; yet the example compiles as the instantiation takes the currently defined symbols into account too. A symbol can be forced to be open by a `mixin`:idx: declaration: .. code-block:: nim proc create*[T](): ref T = # there is no overloaded 'init' here, so we need to state that it's an # open symbol explicitly: mixin init new result init result Bind statement -------------- The ``bind`` statement is the counterpart to the ``mixin`` statement. It can be used to explicitly declare identifiers that should be bound early (i.e. the identifiers should be looked up in the scope of the template/generic definition): .. code-block:: nim # Module A var lastId = 0 template genId*: expr = bind lastId inc(lastId) lastId .. code-block:: nim # Module B import A echo genId() But a ``bind`` is rarely useful because symbol binding from the definition scope is the default.