Commit Graph

87 Commits

Author SHA1 Message Date
Jordan Hrycaj 4cab7b0879
Added `IntervalSet`, sets of non-adjacent intervals (#121)
* Added `IntervalSet`, sets of non-adjacent intervals

Relocated from nimbus-eth1 snap sync development

* Fix local import directive

* Fix --styleCheck complaints

* Attempt to get around CI problem by varying items

details:
  Vary all_tests exec list
  Hide useless globalness of `noisy` constant in non-debugging mode
2022-06-20 15:04:47 +01:00
Jacek Sieka dad28a269f
result: add `Opt.some` / `Opt.none` (#117) 2022-06-17 13:45:22 +03:00
zah 9fe9cb7002
Add byteutils.hexToByteArrayStrict (#120) 2022-06-17 11:37:06 +03:00
lchenut c2f0cbf0d9
Add enum utilities and add enum with holes support (#115) 2022-06-10 02:29:07 +03:00
zah 412a691f5d
Remote a test that doesn't work with Nim 1.2 (#114) 2022-05-23 15:27:04 +03:00
Jordan Hrycaj 779ba052c8
Refactor lruFetch() item rotation (#112)
* Re-route KeyError exceptions as Defect for all except the `[]` function

why:
  Access via key is verified, error is returned via Result[]

* Refactor lruFetch() item rotation

why:
  Previously, the item was deleted and re-inserted in the table although
  for rotation, only the queue links need to be updated.

* Delete some KeyError annotations

why:
  Was overlooked earlier

* More KeyError fixes
2022-05-19 18:51:47 +01:00
Zahary Karadjov b87fd80b0f
Add tests for recordFields being used with empty objects 2022-03-03 17:36:28 +02:00
Jacek Sieka 9d0f1167ca
results: `[]` for void (#103)
mostly for consistency.. but it's used in nim-eth tests
2022-01-13 22:02:44 +01:00
Jacek Sieka 6ad35b876f result: expose value/error in errorOr/valueOr
* fix error type as well
2022-01-11 16:39:12 +02:00
Jacek Sieka d2ae2889e8
`Result` refresh (#96)
* `Result` refresh

* add full support for `Result[T, void]` (aka `Opt[T]` aka `Option[T]`)
* expand tests
* add `flatten`, `filter` of `Option` fame
* add `tryError` that raises a regular exception when result holds a
value
* fix `$` to print `ok`/`err` in lower-case, like the functions that
created the result
* add `orErr` that collapses all errors to a single value of a
potentially different type - useful when translating errors between
layers
* `capture` should work with `CatchableError`
* remove `Defect`-dependent tests

* Update stew/results.nim

* avoid redundant error message when converting error to string
* avoid multiple evaluation in `valueOr`
* add `unsafeError` to match `unsafeGet`
* let `valueOr` evaluate a block
* add `errorOr` to mirror `valueOr`
2022-01-10 00:22:09 +02:00
Jacek Sieka 17cd8c846f
add `to0xHex` which returns a `0x`-prefixed hex string 2022-01-06 17:05:47 +01:00
Jacek Sieka 4e223b95a7
endians2: use copyMem instead of loop outside of vm (#95)
Looking at generated assembly, it turns out the optimizer is not smart
enough to get rid of the loop - use `copyMem` instead.

At least the compiler is smart enough to constant-propagate runtime
endian direction, resolving the review comment.

Also clarify why a minimum length is enfored - it could perhaps be
revisited, but that would leave a slightly odd API.

the `array` overloads are actually unnecessary with an optimizing
compiler - as long as it can prove the length, any extra checks will go
away on their own

also add `initCopyFrom`

* document optimizations
2022-01-03 14:53:01 +01:00
Zahary Karadjov a98ec09b0b
Add sets.keepItIf 2021-12-03 13:28:59 +02:00
Zahary Karadjov 7ab114e159
Add templateutils.evalTemplateParamOnce 2021-12-03 13:28:54 +02:00
Jacek Sieka 8a405309c6
enable styleCheck:usages (#93) 2021-12-02 16:24:02 +01:00
Jordan Hrycaj b002c1fad0
New data structures - SortedSet and KeyedQueue
See the modules' documentation for more details
2021-11-04 13:17:50 +02:00
Zahary Karadjov 478cc6efde Add object.isZeroMemory 2021-09-13 19:02:32 +03:00
Jacek Sieka 3c91b8694e
add void tests (#84) 2021-07-07 10:12:20 +02:00
jangko e10da4a90e
fixes bug in base64 decoder when decoding byte sequence
the decoder accepts string or byte sequence but assume
the inner type is a char, now fixed
2021-06-17 08:16:56 +07:00
Jacek Sieka 7fb220d1e8
assign2: string support (#81) 2021-04-16 15:23:36 +02:00
Jacek Sieka 7d2790fdf4
fix `countZeros` (#80)
should return zeros based on bits, not bytes!
2021-04-12 22:55:09 +02:00
Eugene Kabanov ede0651741
Fix issue with `uint` type. (#79)
* Fix issue with `uint` type.
Add tests for `uint` type.

* Add decode tests for `uint` type.
2021-04-09 19:01:50 +03:00
Eugene Kabanov 6bcb21184a
Optimized and exception-less encoding/decoding procedures for decimal integers (#78)
* Optimized and exception-less encoding/decoding procedures for decimal integers.

* Add tests.

* Fix import path.

* Fix review comments.

* Code simplification.

* Make toBytes() allocation free.

* Do not perform conversion to signed type to avoid compiler's overflow checks.
2021-03-05 20:50:36 +02:00
Gabben 04f8150a08
Fix #62 (#75)
* Fix #62

- Supports more than one pragma parameter (return tuple)
- Returns nil if there are zero parameters in the pragma (like std)
2021-02-10 15:10:08 +02:00
Mamy Ratsimbazafy 6d3e6a21ca
results.`==` with void, Reboot #73 addressing comments (#74) 2021-01-26 15:06:17 +01:00
Mamy Ratsimbazafy b4b3841a85
Revert "Allow comparing Result[void, E] (#71)" (#73)
This reverts commit 068412ff4e.
2021-01-26 14:20:09 +01:00
Mamy Ratsimbazafy 068412ff4e
Allow comparing Result[void, E] (#71) 2021-01-26 14:12:08 +01:00
Jacek Sieka 5cf4feabea
leb128 + bitops fixes (#66)
Leb128 is a variable-length encoding for unsigned integers that is used
in a number of contexts - in particular, wasm, dwarf and protobuf.

This is an optimized low-level implementation that unrolls the loop
reading/writing the buffer - it is suitable to use as base for a more
specific API - no memory allocations, no exceptions.

This PR also fixes bitops2 to not raise on certaing uint->int
conversions, adapting bitops to nim 1.0 conversion rules by using a cast
instead of raising on uint->int conversion
2020-12-15 17:07:20 +02:00
Jacek Sieka d8d914332d
random helpers (#64)
* random helpers

* arrayops as a home for small array/openArray utilities
* assign2 - a replacement for genericAssign and assignment operators in
general which in nim are very slow
* use assign2 in a few places to speed things up

* fixes

* fixes
2020-12-10 12:05:22 +01:00
Jacek Sieka e15c1ae012
results: prevent dangling cstring pointers in result (#63) 2020-12-09 17:21:12 +01:00
Eugene Kabanov ff524ed832
Fix getCurrentDir() gcc compilation warning. (#61)
* Fix GCC warning on getcwd usage.
* Check returned value of getCurrentDir() in tests.
2020-11-04 15:22:38 +02:00
Eugene Kabanov bc3b4cf2de
Fix inherited objects problem. (#59) 2020-10-20 17:43:38 +03:00
Eugene Kabanov 7018fb0b5e
Procedures to set user-only Windows ACL settings for files and folders. (#58)
* Initial commit of UserOnly Windows ACL settings for files and folders.

* Move ACL procedures to windows/acl.
Move ACL tests to test_winacl.nim.

* Add test_winacl.nim

* Fix *nix compilation problem.

* More proper fix for *nix targets.
2020-10-15 14:27:58 +02:00
jangko 999d3ca7ce
fixes bitops2: 'countOnesBuiltin' and 'parityBuiltin' when feeded 'unsigned' on 32 bit platform 2020-09-30 18:28:36 +07:00
Eugene Kabanov 7a2b6dbdda
IO2 (#53)
* Initial commit of io2 module

* Rename to io2.
Add createPath with permissions.
Add writeFile with permissions.
Add tests.

* Add test_io2 to all tests.

* Add posix permissions.

* Add toString procedure for set[Permission] and tests.

* Remove safeio.nim

* Add setPermissions procedures.
Fix writeFile() to change permissions.
Add more writeFile() tests.

* Change C ReadOnly/WriteOnly/ReadWrite to pair of Read/Write.
Add tests for openFile.

* File handles is no inherited by default, with option to turn on inheritance.

* Review comments fixes.
More tests.

* Fix x86 compilation problems.

* Rename toSet -> toPermissions.

* Avoid race condition on writeFile permissions.
2020-09-22 08:53:00 +03:00
Eugene Kabanov 4c695e5933
Allow any integer type to use CT.isEqual(). (#51)
* Allow any integer type to use CT.isEqual().
* Add tests for different integer types.
2020-07-30 20:09:49 +03:00
cheatfate a5560c1ea6
Add constant isEqual operation for openarrays. 2020-07-29 01:43:09 +03:00
Jacek Sieka ec2f52b0ce
results: make `?` work with void (#50) 2020-07-13 18:09:45 +02:00
Zahary Karadjov 32b86bfd1f
Faux closures: a facility for creating closure-like non-closure procs
This code is extracted from the error-handling proposal where it's
used to implement `Try` blocks (Faux closures are created there in
order to assign raises lists to them). The desktop team faced a
similar problem where the `spawn` API doesn't support closures,
but the restriction can be easily worked-around with faux closures.
2020-07-07 20:29:04 +03:00
Zahary Karadjov 61d5cfc376
Add array[N, byte].fromHex(string) 2020-07-02 18:00:39 +03:00
Zahary Karadjov 152eb1b58c Add 'checkedEnumAssign' for validating tainted enum inputs 2020-06-24 14:15:45 +03:00
jangko e1b6d5c92f
add test for vcc compiler 2020-06-15 21:09:41 +07:00
Zahary Karadjov b9e847a143
Add bitops2.getBitsBE 2020-06-01 19:49:46 +03:00
Zahary Karadjov a99dafab42
Handle another corner case in recordFields 2020-05-27 11:30:56 +03:00
Zahary Karadjov 4ffd3e1f59
Support type hierarchies in recordFields 2020-05-26 18:56:41 +03:00
Zahary Karadjov f003557674
typedParams will now handle parameters with pragmas 2020-05-23 20:12:56 +03:00
Zahary Karadjov d0f5be4971
Fix a compilation error when using a 32-bit varint parser 2020-05-12 22:59:46 +03:00
Zahary Karadjov c500d3dda1
Some renames to cater to the latest FastStreams API 2020-05-12 15:02:06 +03:00
Jacek Sieka f125f6e8d1 space 2020-05-08 18:54:36 +03:00
Jacek Sieka 2d9226464d heterogenous `or`
Useful for translating `error` results
2020-05-08 18:54:36 +03:00