Commit Graph

65 Commits

Author SHA1 Message Date
Qi Xiao
5775c8b3ed pkg/diag: Rework API and presentation of Context and Error.
- Change Context to export all its fields.

- Include end position in Context, and include it in Show.

- Remove the Type field from Error, and express it using an ErrorTag type
  parameter instead.

- Make {Pack Unpack}CognateErrors type-safe with the new ErrorTag mechanism, and
  rename them to just {Pack Unpack}Errors.
2024-01-16 11:04:52 +00:00
Qi Xiao
ae087dc1e4 pkg/eval: Don't use the new context.Cause API.
Elvish should still be buildable with Go 1.19.
2023-05-07 22:37:08 +01:00
Qi Xiao
f54fe608e8 Clean up some code from adding Context to Frame. 2023-05-07 21:49:27 +01:00
Qi Xiao
da576e221c pkg/eval: Use a Context inside Frame to pass interrupts. 2023-05-07 21:44:28 +01:00
Qi Xiao
6ecc2b306c Fixup for #1691. 2023-05-06 23:55:34 +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
Qi Xiao
7e6bd950b1 pkg/diag: Increase test coverage. 2022-11-30 12:57:02 +00:00
Qi Xiao
eed2f7dabc pkg/mods/file: file:is-tty interprets numbers as port numbers instead of FDs. 2022-11-21 11:30:14 +00:00
Qi Xiao
51e4d97568 interface{} -> any now that Elvish requires Go 1.18. 2022-03-20 16:17:19 +00:00
Qi Xiao
957c8a7521 evaltest: Check that stderr is empty if PrintsStderrWith is not called.
Among other things, this will check for deprecation warnings. Also fix test code
that uses deprecated features.
2022-03-20 09:50:05 +00:00
Qi Xiao
d9e14da0db Export eval.Closure and (*eval.Frame).Fork. 2021-12-31 14:28:30 +00:00
Qi Xiao
973fe39798 Implement the tmp special command.
This addresses #1114.
2021-12-09 22:12:38 +00:00
Qi Xiao
ce08c4a7d5 Throw exception when writing values to a port without a value component.
This is done by generalizing the mechanism used to detect that the reader of
value output has terminated.
2021-06-22 00:35:30 +01:00
Qi Xiao
53dbece608 Fix style. 2021-06-18 00:16:20 +01:00
Qi Xiao
657b73122f Change all builtin commands writing value output to surface ReaderGone.
Also replace (*Frame).OutputChan with (*Frame).ValueOutput, which returns a
small interface for writing to the value output that is also aware when the
reader is gone.
2021-06-18 00:14:59 +01:00
Qi Xiao
321a4e78eb Merge branch 'master' into reader-gone 2021-06-15 22:09:40 +01:00
Qi Xiao
067c809fc5 Change all builtin commands that write to byte output to surface write errors.
Also replace (*Frame).OutputFile with (*Frame).ByteOutput, which returns a
small interface for writing bytes and converts EPIPE to ReaderGone.
2021-06-11 22:20:27 +01:00
Kurtis Rader
267e015bd6 Add from-terminated and to-terminated commands
This change makes feeding output to commands which handle NUL terminated
"lines" (e.g., `fzf -read0` or `xargs -0`) extremely fast compared to
using an explicit Elvish loop that does `print $val"\x00"`. Similarly for
handling input from commands that produce NUL terminated "lines" (e.g.,
`find . -print0`) compared to an Elvish loop using `read-upto "\x00"`.

Resolves #1070
Related #1053
2021-06-10 09:06:15 +01:00
Kurtis Rader
9b61cdc727 Be consistent about sync.WaitGroup var naming
Also, remove the unused dbStore.Waits() method. This came to my
attention while writing `peach` unit tests.
2021-05-30 00:40:42 +01:00
Qi Xiao
7b66e9f104 Minor fixups for #1273.
Also fix a test broken by bad merge.
2021-05-02 00:13:22 +01:00
Kurtis Rader
1e0885310e Include name in error msg setting a readonly var
When attempting to update a read-only var return an error struct rather
than a simple string (i.e., a Go `error` type).  This makes it possible
to include the var name in the error message.  This builds on commit
a33ecb2d that highlights the offending var name in the stack trace but
does not include the var name in the error message. With this change the
error message includes the offending var name.

Related #255
2021-03-26 18:38:22 -07:00
Qi Xiao
c96bfade21 pkg/parse: Small API tweak. 2021-02-01 14:20:56 +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
b87cc7b5de Add back support for circular module dependency.
This fixes #1226.
2021-01-24 14:10:45 +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
363b712f66 pkg/eval: Eliminate in-place mutations of *Ns.
This commit replaces scopeOp, the only remaining place that mutates *Ns in
place, with nsOp, which performs copy-on-write for *Ns.

As a result, the "eval" command no longer mutates the passed namespace. The
default namespace it uses is also changed to match the default of "-source" (an
amalgamated namespace from the local and upvalue scopes), making "-source $file"
equivalent to "eval (slurp <$file)", and formally deprecated.

Another result is that (*Evaler).Eval can now guard the mutation of the global
namespace with the mutex, making it concurrency-safe to execute multiple sources
that touch the global namespace.

This fixes #1137.
2021-01-09 15:02:15 +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
2033600881 pkg/eval: Clean up Port related code. 2021-01-05 05:23:17 +00:00
Qi Xiao
a2790af67a pkg/eval: Clean up the structure and methods of Evaler and Frame.
- Make Evaler mostly thread-safe. The only remaining thread-unsafe part is the
  modules field, which is more tricky than other fields.

- Remove the state and evalerScopes type, and move their fields into Evaler.

- Expose valuePrefix via a get method, and change PortsFromFiles to take the
  prefix instead of a *Evaler. Also expose a PortsFromStdFiles.

- Make Evaler a normal field of Frame, instead of an embedded field. This makes
  access to global states more explicit.
2021-01-05 00:22:09 +00:00
Qi Xiao
6c764d31d5 pkg/eval: Add mutex to Evaler, and remove that of deprecationRegistry.
The Evaler keeps global states and needs to be accessed concurrently. Mutations
to global states have fairly low throughput, so it makes sense to use a single
mutex.

On the other hand, the compiler is always used on a single thread, so it does
not need any mutex protection, so there is no need to put the mutex inside
deprecationRegistry.
2021-01-04 15:55:26 +00:00
Qi Xiao
5fbeb781ff pkg/eval: Remove (*Frame).Eval. 2021-01-03 20:54:35 +00:00
Qi Xiao
7932f58201 pkg/eval: Add a (*Evaler).Call method for calling a function.
Most of the places that need to directly call a function is in the edit package,
which need to call user-defined callbacks.

This change eliminates most call sites of NewTopFrame (including all call sites
outside the eval package). Remove the function and inline it in the remaining
few call sites.

Remove NewTopFrame means that the eval package no longer offers other packages
a way to construct Frame instances. This is intended: Frame is a relatively
low-level concept, and all code outside the eval package now uses the more
high-level Eval, Call, Check/CheckTree methods of *Evaler. The most notable
exception is packages that implement modules; they may still use Frame to access
the information kept in it, but they never construct Frame instances.

In future, the Frame type can be changed to an interface.
2021-01-03 18:57:11 +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
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
Kurtis Rader
4df5e8e015 Use exported methods to access ports
Commit 734eb95 changed most uses of `fm.ports[x].` to a public method
that makes the intent clearer. This changes a couple of uses that were
overlooked by that prior change.
2020-12-25 01:11:33 +00:00
Kurtis Rader
9c7c9cf7d9 [cleanup] trivial golint suggested changes
As with commit #eb2a792 I acknowledge that `golint` recommendations are
controversial and should not automatically be acted on. Nonetheless,
this change fixes legitimate lint issues such as copy/paste cleanups,
style problems I introduced (`i += 1` versus `i++`) or method/var comments
that are not in the preferred form.
2020-12-25 01:11:33 +00:00
Qi Xiao
734eb955e2 pkg/eval: Use exported methods to access ports from builtin functions. 2020-10-10 22:28:13 +01:00
Kurtis Rader
10085080f2 Fix typos and clarify wording 2020-10-10 22:27:45 +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
fca1621294 pkg/eval: Export the StackTrace type. 2020-09-03 05:54:32 +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
Qi Xiao
eb37f92300 pkg/eval: Use eval.ChopLineEnding everywhere for removing line ending. 2020-05-06 23:10:57 +01:00
Qi Xiao
5a09222cf7 pkg/eval: Implement read-line.
This fixes #975.
2020-05-06 23:03:49 +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
663b10d8e2 Suppress deprecations by default.
The behavior is controlled by a global flag that will be flipped for the release
branch. A flag is available to force deprecations to be shown or hidden.
2020-04-26 21:26:53 +01:00
Qi Xiao
cf6e048e58 pkg/eval: Support eval-time deprecation warning.
This addresses #898.
2020-04-26 01:13:05 +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