Commit Graph

137 Commits

Author SHA1 Message Date
Jacek Sieka 763147cf82
arraybuf: new constructor (#236)
* arraybuf: new constructor

also add a block to avoid symbol leaks

* speed up for same length
2024-10-07 22:13:34 +02:00
Jacek Sieka 9501d3d60c
assign2: compile-time assignment support (#234) 2024-09-26 18:16:03 +02:00
Jacek Sieka 41f48efee9
staticfor: compile-time loop unrolling (#232)
* staticfor: compile-time loop unrolling

* better code, preserve line info

* one more line info

* license
2024-09-24 10:36:50 +02:00
Jacek Sieka 68e8ae6413
arraybuf: fix iterator, setLen (#231) 2024-09-17 11:54:28 +00:00
Eugene Kabanov d4634c5405
Add updateFilePos() primitive and tests. (#229) 2024-09-04 03:12:02 +00:00
Jacek Sieka fc09b2e023
arraybuf: seq-like fixed-capacity container stored on the stack (#227)
Also includes `evalOnceAs`, a handy utility for avoiding creating a
temporary in templates when seeking to avoid double-evaluation of
parameters.
2024-09-02 13:02:11 +02:00
Eugene Kabanov af07b0a70d
Fix OpenFlags.Append mode for io2.openFile() (#226)
* Initial commit.

* Fix Windows version.

* Remove debugging echoes.

* Fix Posix version.

* Add one more test.
2024-08-02 05:32:31 +00:00
Eugene Kabanov 8e0e344f0f
Add truncate()/ftruncate() cross-platform implementation. (#225) 2024-07-28 23:03:43 +00:00
tersec e00fea1f6e
fix deprecation warnings from results; deprecate shims/io module; rm deprecated shims/os module (#223) 2024-06-27 11:48:32 +00:00
Eugene Kabanov bb086e69da
Fix Windows ACL flakiness issue (Windows error 1336). (#221)
* Add getHomePath(), getConfigPath() and getCachePath() implementations.
Fix ACL flakiness issue.
Add tests.

* Add getTempPath().
Normalize path endings for all xxPath() functions.

* Fix 2.0/devel compilation errors.
2024-06-17 07:04:14 +00:00
Jacek Sieka a0c085a51f
strformat: compile-time format string parser (backport Nim 2.2) (#216)
https://github.com/nim-lang/Nim/pull/23356
2024-03-13 09:45:09 +01:00
Etan Kissling 1662762c01
rename `RangeError` -> `RangeDefect` in test name (#214)
The `Allocating with a negative size throws a RangeError` test actually
tests for `RangeDefect`, so rename the test accordingly.
2024-02-17 19:31:52 +00:00
Jacek Sieka 2c2544aec1
byteutils: `openArray[char]` version of `toBytes` (#210)
and compile-time tests
2023-11-14 11:53:47 +01:00
Jordan Hrycaj b17ac2e753
Disentangle cascaded unit tests for interval sets (#208)
why:
  Some sub-tests failed when run directly
2023-08-22 10:38:16 +01:00
tersec 326ef09a46
remove dead code under Nim 1.6+ (#206) 2023-07-31 21:07:48 +00:00
Jacek Sieka 2cf408b960
Graduate stew/results -> results (#185)
Since the results package has seen "stable" use for quite a while now,
it's as good time a time as any to release 1.0 and migrate it out of
stew, thus signalling API stability of some sort.

Part of that "stabilization" is underway in the nim-results [issue
tracker](https://github.com/arnetheduck/nim-results/issues/30).
2023-07-05 12:50:21 +02:00
andri lim 5c519d8582
fix results compiletime regression (#203)
* fix results compiletime regression

* disable results.value compiletime test for pre 1.6 nim
2023-07-05 10:07:17 +02:00
Jacek Sieka 8bb07fac39
results: fix `catch` template for statements (#201)
* results: fix `catch` template for statements

* disable void catch tests on pre-1.6
2023-06-28 10:57:00 +02:00
Jacek Sieka d085e48e89
results: add `mapConvertErr`, `mapCastErr` (#178)
We already have `mapConvert` and `mapCast` - this completes the API with
corresponding `Err` versions similar to `mapErr`.

The `Convert` / `Cast` operators are of somewhat dubious value - ie
they exist as "efficiency" shortcuts for `map` for the case that the
mapping should be done as a simple cast / conversion - an alternative
would be to deprecate these features and aim for some other, more
generic version that involves a type conversion library such as
https://github.com/status-im/nim-stew/pull/34, though this inherently,
and perhaps rightly, would be limited to "error-free" conversions.

Regardless, these helpers provide balance to the existing API.
2023-06-28 10:27:45 +02:00
tersec 607059fe31
rm copy of parseHex() from 1.2+ stdlib; some proc -> func (#197) 2023-06-15 14:21:51 +02:00
Jacek Sieka ebbb391b9e
ptrops: add makeUncheckedArray (#193)
turns a pointer into an array pointer of the same type
2023-06-12 14:13:18 +02:00
Jacek Sieka 36e0eb8d89
varints: remove (#195) 2023-06-12 11:42:27 +02:00
Jacek Sieka 6c97f11c7c
results: work around nim codegen bug (#192)
https://github.com/nim-lang/Nim/issues/22049
2023-06-08 17:24:19 +02:00
Jacek Sieka 13e55ed27a
results: collections integration (#179)
This set of helpers allows treating Result and Opt as collections of 0
or 1 item, allowing iterating over them and checking "membership" - such
integration is useful in generic code which can then be generalised to
handle more complex cases - the integration is most useful with Opt.

One design tradeoff here is the "explicitness" of `items` vs `values`
for `Result` - technically error and value are "equal" and therefore we
shouldn't give preference to the value, but there exists a convenience
argument to treat the value as the "default" and therefore define
`items` / `contains` for `Result` as well - this PR chooses the more
conservative and explicit approach - a more liberal version can easily
be added later should motivating examples emerge.
2023-06-07 16:45:53 +02:00
Etan Kissling 7b4c9407f2
add `enumStyle` helper macro (#189)
For serialization and parsing, distinguishing enums with numeric values
from enums with associated strings for each value is useful. This adds
foundational helpers to allow such distinction.
2023-05-26 15:41:13 +03:00
Jacek Sieka 266e9002f3
results: Add Opt/Result converters (#177)
Add `optError`, `optValue`, to convert back and forth between Opt and Result
These conversions end up being more common than others since "trivial"  success/fail-style API often use Opt while combining such API into combined operations tends to prefer richer error reporting.
2023-05-11 16:34:41 +03:00
Jacek Sieka 9b985e8ea8
results: Add `isOkOr`, `isErrOr` (#176)
These two helpers complete `valueOr` and `errorOr` to cover `void` cases
where no value should be returned or `Result[void, E]` /
`Result[T, void]` is being used - they can be used for a convient
early-return style in side-effectful proc:s:

```nim
v.update().isOkOr:
  echo "update failed: ", error
```
2023-04-20 13:08:54 +02:00
jangko faabd40c30
reduce compiler warnings 2023-02-14 21:35:54 +07:00
Eugene Kabanov 407a598836
Fix Windows MAX_PATH limitation for absolute paths in io2 module. (#169)
* Fix Windows MAX_PATH limitation for absolute paths.

* Update algorithm to be more compatible with both directory and file paths.

* Add test.
2023-02-02 09:30:40 +01:00
Jacek Sieka 447b23d3bf
results: work around field access bugs (#167)
* results: work around field access bugs

See:

* https://github.com/nim-lang/Nim/issues/3770
* https://github.com/nim-lang/Nim/issues/20900

* comment fixes

* add test

* document test better
2023-01-20 15:32:51 +01:00
Jordan Hrycaj 609edbb5db
Updated unit tests using setup facility (#166)
why:
  Allows executing sub-tests independently.
2023-01-19 20:23:21 +00:00
Jacek Sieka 32d6f43fff
byteutils: allow empty output buffers (#157)
* byteutils: allow empty output buffers

* er, closed
2023-01-19 08:19:26 +01:00
Jacek Sieka ac602b5086
results: print `none` for empty Opt instances (#164)
* results: print `none` for empty Opt instances

* fix test too
2023-01-16 09:01:31 +01:00
Zahary Karadjov f5846de7b2
Add objects.isDefaultValue 2022-12-15 17:11:53 +02:00
Jacek Sieka aba51f1d29
normalise nimble file (#158)
* normalise nimble file

* loop args
2022-11-21 11:02:24 +01:00
Jacek Sieka d087c039c2
fix `baseAddr`, move to `ptrops` (#156)
* return `nil` for empty openArrays / avoid returning `16`
* move to `ptrops`, deprecate `ptr_arith` fully
2022-11-18 15:22:29 +02:00
Jacek Sieka f295d00db9
remove `stew/ranges` (#152)
* deprecated for years
* relies on unavailable (shallowCopy) or broken (missing range checks)
features in nim
2022-11-18 12:52:55 +01:00
Jordan Hrycaj 665e1d1604
Fix issues #151 and #153 (#154) 2022-11-17 14:54:48 +00:00
Jacek Sieka 8a1b6ab4dc
results: work around void member codegen issue (#150) 2022-11-11 14:26:59 +01:00
Tanguy 989047dd76
Deprecate baseType (#148)
* Switch to compile time error for ARC / ORC

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2022-11-10 08:35:52 +01:00
Tanguy 23da07c9b5
Fix compilation on devel (#146) 2022-10-29 21:48:51 +02:00
Jordan Hrycaj 1e86bd1ef3
Fixing overlapping intervals bug (#138)
why:
  did not properly merge
2022-08-16 14:21:01 +01:00
Eugene Kabanov 0476bcad1b
Cross-platform lockFile()/unlockFile() procedures for io2. (#116) 2022-08-05 19:58:34 +03:00
Jordan Hrycaj a812fd3fae
Retrive envelop interval for point (#136) 2022-08-02 09:08:17 +01:00
Miran 2ab76e2cc2
fix warnings encountered with Nim 1.6 (#128)
* fix warnings encountered with Nim 1.6

* Create shims/stddefects.nim with aliases for all defects
2022-07-27 10:10:26 +02:00
Jordan Hrycaj c020fd80f1
Fix ge() fringe case (#135)
why:
  The point `high(P)` is treated separately and added to the top adjacent
  interval or is treated as a sigle point interval.
2022-07-25 15:05:27 +01:00
Jordan Hrycaj 598246620d
Fix fringe case (#130)
why:
 Merging [a,a] in to {[a+1,b]} caused assertion violation, doAssert
 condition was too strict.
2022-07-19 09:19:41 +01:00
Jordan Hrycaj 8a9816ac02
Fix iterator edge cases for [high(P),high(P)] (#129)
also:
  cascaded `if` in rbtree (for unrelated troubleshooting)
2022-07-18 18:56:31 +01:00
tersec f173efc500
stylecheck: nnkArglist -> nnkArgList (#127)
* stylecheck: nnkArglist -> nnkArgList

* --stylecheck:error iff >= 1.6.0
2022-07-18 11:02:40 +00:00
Jordan Hrycaj 9c3596d9de
Migrate to `unittest2` (#125)
* Migrate to `unittest2`

why:
  Global symbol overflow when running NIM 1.2 on Github ci suggests that
  unit tests run sort of separately. The replacement library `unittest2`
  provides that.

* Build ci dependencies
2022-07-08 10:34:21 +01:00