add default field support for object in ARC/ORC (#20480)
* fresh start * add cpp target * add result support * add nimPreviewRangeDefault * reduce * use orc * refactor common parts * add tuple support * add testcase for tuple * cleanup; fixes nimsuggest tests * there is something wrong with cpp * remove * add support for seqs * fixes style * addd initial distinct support * remove links * typo * fixes tuple defaults * add rangedefault * add cpp support * fixes one more bugs * add more hasDefaults * fixes ordinal types * add testcase for #16744 * add testcase for #3608 * fixes docgen * small fix * recursive * fixes * cleanup and remove tuple support * fixes nimsuggest * fixes generics procs * refactor * increases timeout * refactor hasDefault * zero default; disable i386 * add tuples back * fixes bugs * fixes tuple * add more tests * fix one more bug regarding tuples * more tests and cleanup * remove messy distinct types which must be initialized by original types * add tests * fixes zero default * fixes grammar * fixes tests * fixes tests * fixes tests * fixes comments * fixes and add testcase * undo default values for results Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
This commit is contained in:
parent
6cf0727192
commit
f89ba2c951
23 changed files with 727 additions and 80 deletions
|
|
@ -24,6 +24,9 @@
|
|||
|
||||
include "system/basic_types"
|
||||
|
||||
func zeroDefault*[T](_: typedesc[T]): T {.magic: "ZeroDefault".} =
|
||||
## returns the default value of the type `T`.
|
||||
|
||||
include "system/compilation"
|
||||
|
||||
{.push warning[GcMem]: off, warning[Uninit]: off.}
|
||||
|
|
@ -911,6 +914,7 @@ proc default*[T](_: typedesc[T]): T {.magic: "Default", noSideEffect.} =
|
|||
# note: the doc comment also explains why `default` can't be implemented
|
||||
# via: `template default*[T](t: typedesc[T]): T = (var v: T; v)`
|
||||
|
||||
|
||||
proc reset*[T](obj: var T) {.noSideEffect.} =
|
||||
## Resets an object `obj` to its default value.
|
||||
obj = default(typeof(obj))
|
||||
|
|
@ -2753,3 +2757,8 @@ when notJSnotNims and not defined(nimSeqsV2):
|
|||
moveMem(addr y[0], addr x[0], x.len)
|
||||
assert y == "abcgh"
|
||||
discard
|
||||
|
||||
proc arrayWith*[T](y: T, size: static int): array[size, T] {.noinit.} = # ? exempt from default value for result
|
||||
## Creates a new array filled with `y`.
|
||||
for i in 0..size-1:
|
||||
result[i] = y
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue