Commit Graph

58 Commits

Author SHA1 Message Date
Qi Xiao
da576e221c pkg/eval: Use a Context inside Frame to pass interrupts. 2023-05-07 21:44:28 +01:00
Qi Xiao
97a73e2d95 evaltest.capturePort -> eval.CapturePort.
Also rename the original eval.CapturePort to ValueCapturePort.
2023-01-15 16:44:25 +00:00
Qi Xiao
5a237d7888 pkg/eval: When compiling, emit autofixes for using unimported builtin modules. 2022-12-11 14:21:09 +00:00
Kurtis Rader
358e52a7f5 Make testing compilation errors more deterministic
A year ago I submitted a change to replace AnyError with tests for specific
errors (see https://github.com/elves/elvish/commit/87656c99).  This does
something similar for DoesNotCompile. This ensures the test does what
is implied and makes correlating specific unit tests with compilation
errors easier.

This includes a couple of changes to compilation error messages to improve
readability (IMHO) but those are not the primary purpose of this change.

Related #1560
2022-11-20 16:33:29 +00:00
Kurtis Rader
e896ac3c0e
Improve some compilation errors (#1617)
Quote variable names appearing in some compilation errors to improve
the clarity of those errors.
2022-10-03 04:22:46 +01:00
Qi Xiao
786b679509 pkg/eval: Cover more tilde expansion errors. 2022-06-20 00:08:33 +01:00
Qi Xiao
94e43cd2fd pkg/eval: Add tests for errors in tilde expansion. 2022-06-19 23:34:36 +01:00
Qi Xiao
51e4d97568 interface{} -> any now that Elvish requires Go 1.18. 2022-03-20 16:17:19 +00:00
Qi Xiao
59459793e3 pkg/persistent: Cons -> Conj.
Cons was a misnomer for the operation of adding an element at the end of a
vector. Follow Clojure's naming here and call this operation Conj.
2022-01-05 22:34:55 +00:00
Qi Xiao
003557c22a Remove support for the legacy lambda syntax.
This fixes #664.
2022-01-03 00:47:41 +00:00
Qi Xiao
d9e14da0db Export eval.Closure and (*eval.Frame).Fork. 2021-12-31 14:28:30 +00:00
Qi Xiao
4b218d9859 Deprecate the legacy lambda syntax from 0.17.x.
This addresses #664.
2021-10-14 23:10:29 +01:00
Qi Xiao
6a92571a23 Check assignments to read-only variable during compilation. 2021-10-13 23:57:14 +01:00
Qi Xiao
4d62732ebc Fix "indicies" -> indices. 2021-08-22 23:31:26 +01:00
Kurtis Rader
9a576529a3 Replace ErrArgs with more specific errors
This also replaces the slightly awkward "arguments here" reason with
"argument count" as the "what" for a typical errs.ArityMismatch
exception. It also reformats most of the constructors so that the "what"
is on the same line. This makes `grep errs.ArityMismatch **.go` more
useful as a result.
2021-06-13 22:42:04 +01:00
Qi Xiao
42d6e94dd7 Remove support for $-exports-. 2021-04-09 00:02:40 +01:00
Qi Xiao
634d71dcba Extract utilities for compound nodes into pkg/parse/cmpd. 2021-02-24 00:02:47 +00:00
Qi Xiao
e3b0b27931 Do not append slash after expanding ~username.
This fixes #1246.
2021-02-23 23:25:48 +00:00
Qi Xiao
196eea21d4 Change module import path to src.elv.sh 2021-01-27 01:30:25 +00:00
Qi Xiao
ae98cc5272 Add a new "deprecate" command. 2021-01-24 15:32:24 +00:00
Qi Xiao
47d9766f5c Control deprecation warnings with a number instead of a bool.
Previously, to avoid showing deprecation warnings for the next release when the
user is running on HEAD, a boolean CLI flag -show-deprecations is introduced,
and is set to false in the master branch. The idea is that release branches will
have this default to true, so people running released versions will see
deprecations.

However, this means that people running on HEAD will never see any deprecations
unless they use this CLI flag, which is not ideal. This commit replaces the flag
bool -show-deprecations with a numerical -deprecation-level flag, which requests
deprecations that are active as of release 0.X to be shown. The default value of
this flag will be the minor version number of the *last* release, so that people
running HEAD will see as many deprecation warnings as people running the last
release would. This number will be bumped just before releases.
2021-01-19 21:37:36 +00:00
Qi Xiao
072677351b Introduce "var" and "set".
Assignment using "foo = bar" instead of "var foo = bar" or "set foo = bar" is
not yet deprecated, but will be soon.

This addresses #645.
2021-01-16 06:11:37 +00:00
Qi Xiao
56ceeedd21 pkg/eval: Store variable deletion information in *Ns.
This fixes #1213.
2021-01-10 00:54:02 +00:00
Qi Xiao
af906f1d76 pkg/eval: Change all the *Op types to return Exception instead of error.
Also change the variable name used to keep the Exception returned from "err" to
"exc".

This uncovers several error scenarios that were not returning Exception, and
would result in the absense of stack traces when such errors occur.
2021-01-09 00:25:32 +00:00
Qi Xiao
b77a052e7e pkg/eval: Make Exception an interface.
This change is a preparation step for refining all *Op types to return Exception
as the error.

Keeping Exception as a struct type will make such a change error-prone, since
a (*Exception)(nil) != error(nil), so if an *Op returns a nil *Exception, it
is not nil if the return value is stored in an error-typed variable.
2021-01-08 00:56:45 +00:00
Qi Xiao
6e8ecc8bd5 pkg/eval: Cleanups for reducing the API surface area number of files.
- Move NewEnvListVar to pkg/eval/vars.

- De-export GlobPattern, GlobFlag and ExternalCmd.

- Merge editor.go and chdir.go into eval.go, value_helper.go into compile_value.go.

- Remove eval_internal_test.go and replace it with a new test for $pid.
2021-01-05 04:33:52 +00:00
Qi Xiao
01612e291b pkg/eval: Clean up closure call implementation.
- Remove reliance on scopeOp, concentrating all the scope for creating the local
  scope in (*closure).call.

- Check options at the very beginning, and include all unsupported options in the
  error.
2021-01-04 13:46:00 +00:00
Qi Xiao
4f037aeb2a pkg/eval: Implement output capture in terms of simpler primitives.
Introduces two functions, PipePort and CapturePort, and implement output capture
in terms of them. These two functions return *Port instances, which can also be
used in (*Evaler).Eval calls.
2021-01-02 01:40:04 +00:00
Qi Xiao
719314c029 pkg/eval: Various cleanups for qname handling code. 2020-12-25 22:31:52 +00:00
Qi Xiao
6419f4524a Implement namespaces using slices instead of maps.
More related improvements and cleanups will be done in followup commits.

This fixes #1139.
2020-12-25 17:46:46 +00:00
Shengjing Zhu
6c08de0ff3 Fix typos found by codespell 2020-10-10 22:47:50 +01:00
Qi Xiao
2af7361bd5 pkg/eval: De-export Closure. 2020-09-04 22:18:50 +01:00
Qi Xiao
27fa20d65e pkg/eval: Move ChopLineEnding to the strutil package.
Also add unit tests.
2020-09-04 21:16:06 +01:00
Qi Xiao
11898f763a pkg/util: Break into fsutil/ and logutil/. 2020-09-03 05:27:18 +01:00
Kurtis Rader
b5b3a0d607 go vet cleanup
Most of the code uses keyed fields in composite literals; i.e., struct
literals. However, running `go vet ./...` reports a few places that use
anonymous fields. This modifies those composite literals to use keyed
fields. This does make the code a bit more verbose without reducing
the likelihood of a bug. But it does make the code more consistent, use
best practices, and make it easier to notice if a potential problem is
introduced when running `go vet ./...` since that command now produces
no diagnostic output.

I considered adding a `make vet` target that explicitly ran

    go vet -composites=false ./...

I decided not to do that since consistently using keyed composite literals
is preferable to having a mix of keyed and unkeyed composite literals.

This also removes the unused `ExampleLoop` function which causes this
`go vet` warning:

    pkg/cli/loop_test.go:130:1: ExampleLoop refers to unknown identifier: Loop
2020-09-03 04:24:06 +01:00
Qi Xiao
8b2e669a5f Remove unused code. 2020-08-23 16:04:44 +01:00
Qi Xiao
b04ea12d48 pkg/eval: Refactor effectOp and valuesOp, remove lvaluesOp.
* Make effectOp and valuesOp interfaces - implementations now handle the
  range information themselves.

* Remove lvaluesOp; it is no longer used.
2020-08-22 19:57:11 +01:00
Qi Xiao
1e2ead56e2 pkg/eval: Rewrite the lvalue parsing code.
Also lift the restriction on rest variables and rest arguments - they may now
appear anywhere, as long as there is only one.
2020-08-20 13:15:00 +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
e8a8ee04b8 Add a wildcard [type:xxx] modifier
This allows filtering the wildcard expansion by path type. For example,
whether the path is a directory, regular file, or something else. So
instead of `find . -type f` you can now do `**[type:file]`.

Resolves #1015
2020-06-28 01:25:32 +01:00
Qi Xiao
eb37f92300 pkg/eval: Use eval.ChopLineEnding everywhere for removing line ending. 2020-05-06 23:10:57 +01:00
Qi Xiao
ba7bedcbd9 Support \r\n everywhere output is processed as individual lines.
This fixes #970.
2020-05-03 23:30:23 +01:00
Qi Xiao
c211679f0c Move all variable creations to start of lexical scope.
Commit 8c71635ca3 moved the creation to the start
of pipelines; the approach works for simplistic cases like "x = 1 | nop", but
fails in more complex cases, such as "nop (x = 1) | nop".

The correct place to hoist variable creations is the lexical scope, and this
commit implements this approach.

This fixes #623.
2020-04-26 19:05:16 +01:00
Qi Xiao
c767f92d01 Support compile-time deprecation.
This fixes #898.
2020-04-26 13:14:51 +01:00
Qi Xiao
20979b44a2 pkg/parse: Use Source values, not pointers.
The Source type is small enough that using values is likely more efficient.
2020-04-25 19:22:38 +01:00
Qi Xiao
21f5a6f7c3 pkg/parse: Turn most public methods of Node into functions.
This make the godoc of the parse package much cleaner and removes some
boilerplate.
2020-04-25 18:55:44 +01:00
Qi Xiao
b8505c7065 pkg/eval/source.go -> pkg/parse/source.go. 2020-04-25 18:26:17 +01:00
Qi Xiao
64e282c828 pkg/eval: Replace ValuesUnwrapper with simple functions.
Also add structured BadValue error type to pkg/eval/errs.
2020-04-13 13:27:55 +01:00
Qi Xiao
096ee354d6 pkg/eval: Simplify API for output capture. 2020-04-10 01:12:25 +01:00