Commit Graph

61 Commits

Author SHA1 Message Date
Qi Xiao
a12e1be189 Implement Hash for *big.Int and *big.Rat. 2021-06-27 17:01:12 +01:00
Qi Xiao
4afab8804b Fixup for #1342. 2021-06-27 16:41:07 +01:00
Kurtis Rader
3da541c719 Other float64 cases that should be generalized
While pondering issue #1340 I looked at the other `case float64:`
blocks. This change generalizes the few places that need it.

Fixes #1340
2021-06-27 16:32:38 +01:00
Qi Xiao
3b7c18c6c5 pkg/eval/vals: Improve test coverage of index.go and iterate_keys.go.
This addresses #1234.
2021-06-15 19:22:58 +01:00
Qi Xiao
2e9e0289cc Make the kind of int, *big.Int and *big.Rat "number". 2021-06-15 19:22:38 +01:00
Qi Xiao
3f0e89d223 pkg/eval/vals: Test expected panics in num.go. 2021-06-15 19:11:57 +01:00
Qi Xiao
2093ac680f Increase coverage of pkg/eval/vals/index_list.go to 100%.
This addresses #1234.
2021-06-15 18:53:31 +01:00
Qi Xiao
af3292418f Change math:pow to produce exact results in certain cases; deprecate math:pow10. 2021-06-10 01:47:59 +01:00
Qi Xiao
59b96f27d8
Merge branch 'master' into testutil-test-coverage 2021-06-06 22:03:34 +01:00
Qi Xiao
16dc290775
Merge branch 'master' into sleep-values 2021-06-06 21:52:27 +01:00
Qi Xiao
3cf5ab996f pkg/eval/vals: Make Pipe a PseudoStructMap.
It is in theory better implemented as a StructMap because it is a transparent
data type. However, the reflection-based algorithm for StructMap will create a
"kind" field for it, and we don't want to remove the custom kind of Pipe yet, so
this has to be a PseudoStructMap now.
2021-06-06 21:48:39 +01:00
Qi Xiao
a69ce8461e
Merge branch 'master' into pipe-close 2021-06-06 21:40:35 +01:00
Kurtis Rader
ff9341eb91 More error deduplication 2021-06-06 14:54:47 +01:00
Kurtis Rader
2b6b11c230 Exercise testutil.MustPipe
I noticed that testutil.MustPipe was not covered by any unit tests. This
converts the handful of places that should use it to do so. This changes
the coverage of pkg/testutil/must.go from 61.5% to 73.1%. There isn't
any way to increase that further without explicitly testing the panic
paths.
2021-06-02 20:29:34 -07:00
Qi Xiao
8a2c9a24db pkg/eval/vals: Add an optimized version of UnifyNums for two numbers. 2021-05-31 21:02:12 +01:00
Kurtis Rader
956c4c9d8f Fix sleep handling of the new num type
Fixes #1317
2021-05-23 20:17:51 -07:00
Kurtis Rader
3ded2fb772 Replace prclose and pwclose with file:close
Rather than having specialized commands make a `file:pipe` object
indexable so we can use the generic `file:close` command. This does not
address existing problems; such as builtins not failing when writing to
a `file:pipe` object if the read-end is closed.

Related #1316
2021-05-22 20:55:53 -07:00
Qi Xiao
320b77ea1b pkg/eval/vals: Convert any number type to float64.
This addresses #1300.
2021-05-09 14:32:50 +01:00
Qi Xiao
91b6f6dd72 Use the integrated persistent package. 2021-05-03 22:17:46 +01:00
Qi Xiao
543b123661 Add some design notes in eval/vals/num.go. 2021-05-02 01:17:27 +01:00
Qi Xiao
90acb4a242 Minor fixup for path:temp-{dir file}.
* Remove `MatchesRegexp` from eval/vals since it is not part of the
  Elvish value protocol.

* Simplify implementation of value matching in `eval/evaltest`.

* Documentation wording tweaks.
2021-04-25 23:03:44 +01:00
Kurtis Rader
bc37099c92 Add equivalent of mktemp as builtin commands.
This implements `path:temp-dir` and `path:temp-file`.

Resolves #1255
2021-04-25 17:34:23 -04:00
Qi Xiao
42d6e94dd7 Remove support for $-exports-. 2021-04-09 00:02:40 +01:00
Qi Xiao
a5baad65f8 pkg/eval/vals: Clean up FromGo. 2021-04-06 22:38:56 +01:00
Qi Xiao
6052a4dc4a Remove the "fix int" terminology; just call it "int". 2021-04-06 22:35:58 +01:00
Qi Xiao
5c643181a4 Cleanup, docs and tests. 2021-04-05 20:48:22 +01:00
Qi Xiao
da67ba8a4a Use machine word (int) instead of int64 for fixnum. 2021-04-04 13:37:38 +01:00
Qi Xiao
4612b58759 Support exact integer and rational numbers. 2021-04-04 00:58:53 +01:00
Qi Xiao
196eea21d4 Change module import path to src.elv.sh 2021-01-27 01:30:25 +00:00
Qi Xiao
5c55e72e78 pkg/eval: Update comments about the Elvish-Go interface. 2021-01-05 05:23:28 +00:00
Shengjing Zhu
6c08de0ff3 Fix typos found by codespell 2020-10-10 22:47:50 +01:00
Qi Xiao
735b1cf973 pkg: Move util/feed.go to eval/vals. 2020-09-03 05:22:44 +01:00
Qi Xiao
53dfbe21b3 pkg/eval/vals: Simply use math.MinInt32 for NoPretty. 2020-09-03 05:19:33 +01:00
Qi Xiao
eae14f91b9 pkg: Move camel_to_dashed from util/ to strutil/. 2020-09-03 05:10:59 +01:00
Kurtis Rader
fd64782e2c Improve test coverage of pkg/eval/external_cmd.go
Improve coverage of pkg/eval/external_cmd.go from 58.3% to 86.1% as
measured by `make test` on macOS.

This would have been a smaller change but I felt it was important to
actually validate the exception raised when an external command fails
rather than simply using `.ThrowsAny()`. That necessitated augmenting
the pkg/eval/testutils.go module.

Related #1062
2020-09-03 04:14:26 +01:00
Qi Xiao
8b2e669a5f Remove unused code. 2020-08-23 16:04:44 +01:00
Qi Xiao
821e414fc9 pkg/eval/errs: Change OutOfRange.Valid{Low High} to strings. 2020-08-18 21:23:26 +01:00
Kurtis Rader
28798ac053 Convert "XXX" to "TODO" comments
I stumbled across a comment that began with "XXX". It was clearly meant as
a "TODO" comment. This changes all such occurrences. However, a few "XXX"
comments are ambiguous and a better prefix might be "WARNING". The "TODO"
prefix at least ensures someone, eventually, looks into the situation
and either rewords the comment or fixes the problem. This change means
everyone can assume searching for "// TODO" will find all such comments
rather than requiring they also know to search for "// XXX".
2020-08-16 16:29:34 +01:00
Qi Xiao
e2f08af91b Change slice syntax to use .. instead of :.
Also support ..= for closed-range slices, a la Rust.

The old syntax is still supported, but deprecated.

This fixes #669.
2020-08-15 22:52:50 +01:00
Kurtis Rader
eb2a792301 Fix some lint warnings
In addition to an uncontroversial spelling fix this addresses several,
related, warnings produced by the `golint` tool. In general I agree with
golint that unnecessary "else" blocks should be avoided. So this change
refactors those cases.

Note: I recognize that `golint` is deprecated (see
https://github.com/golang/go/issues/38968) since it is no longer being
maintained and there is controversy about its set of warnings. Nonetheless,
it appears that the warnings it emits for this project are all reasonable
and actionable with one potential exception: the naming of the `map_`
method in pkg/eval/compile_value.go.
2020-08-01 23:07:50 +01:00
Qi Xiao
1f562505f3 Rework the API for introspecting exception causes.
* Use a "type" field to identify the type, instead of predicates in the exc:
  module.

* Make the reason values behave more like structmaps, including a Repr that
  mimics a map.

This fixes #208.
2020-06-30 22:27:07 +01:00
Qi Xiao
bd8130ee07 pkg/eval/vals: Introduce "pseudo struct maps".
See code comment for details.
2020-06-29 00:22:36 +01:00
Qi Xiao
3c5f34a217 pkg/eval/vals: In operation $op, check the ${op}er interface first.
This is so that structmaps can override the implementation of specific operations.
2020-06-28 11:56:09 +01:00
Qi Xiao
bd1a6e98dc pkg/eval/vals: Rework the structmap mechanism.
* Fields may now be exposed via getter methods.

* Field names are automatically converted to dashed-case.

* Assoc behavior is no longer implemented for structmaps.

* The IsStructMap marker method no longer takes a special marker argument. There
  is a little danger of a value accidentally implementing this method.
2020-06-28 01:26:58 +01:00
Qi Xiao
43054831e6 pkg/eval/vals: Support float64 in Kind. 2020-04-26 15:38:09 +01:00
Qi Xiao
56e36ad77e pkg/eval: Add and use a structured OutOfRange error type.
This commit introduces new pkg/eval/errs package, where structured error types
will be added.
2020-04-12 19:12:05 +01:00
Qi Xiao
8811be7e44 pkg/eval: Support testing stack traces in exceptions.
Currently only one test case tests the stack trace, but all the tests against
compile_*.go will be changed to test stack traces.
2020-04-10 21:20:57 +01:00
Qi Xiao
8c47630af3 pkg/eval: Improve test coverage for exception.go.
This addresses #944.
2020-03-29 17:54:05 +01:00
Qi Xiao
88ccec5475 pkg/eval/vals: Use the same algorithm as ToString in the Repr of float numbers. 2020-02-02 16:10:41 +00:00
Qi Xiao
0d58fea6fd pkg/eval/vals: Further refine the float printing algorithm.
This fixes #811 (for real).
2020-01-12 11:11:47 -05:00