Commit Graph

736 Commits

Author SHA1 Message Date
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
83c81cc5b2 Fix unused symbols found by staticcheck.
Also consolidate pkg/sys/testutil_test.go into pkg/sys/select_test.go.
2021-06-15 17:46:31 +01:00
Qi Xiao
5cbb218dad Merge branch 'docset' 2021-06-14 22:50:00 +01:00
Qi Xiao
7d435154f5 Move doc for the epm module into its source. 2021-06-14 22:48:10 +01:00
Qi Xiao
56ce36f1aa Fix the file module's elvdoc.
- Fix broken anchors.

- Fix broken comment block of the pipe command.
2021-06-14 22:18:32 +01:00
Qi Xiao
162ae65b92 Fix elvdoc for file:close and platform:hostname. 2021-06-14 21:57:57 +01:00
Qi Xiao
3204e700ac Fixup for #1329 2021-06-13 22:54:47 +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
a823eb8fbb Fix a broken link. 2021-06-13 16:27:36 +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
Qi Xiao
3e9e7ce5c8 In elvdoc for to-terminated, use slurp to show byte output that includes NUL. 2021-06-11 14:49:43 +01:00
Qi Xiao
46fa331dca Fixup for #1308. 2021-06-10 09:14:15 +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
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
59e4a7302a Remove outdated TODO on math:round. 2021-06-10 00:11:52 +01:00
Qi Xiao
b7f2457820 Make all rounding functions in math: exactness-preserving.
This fixes #1331.
2021-06-10 00:10:50 +01:00
Qi Xiao
cb15a1e28e Fixup for #1332 2021-06-06 22:46:27 +01:00
Kurtis Rader
b8bc076d07 Increase pkg/eval/vars/env_list.go coverage to 100%
Related #1234
2021-06-06 22:43:45 +01:00
Kurtis Rader
a55b83c6f2 Increase pkg/eval/vars/env.go coverage to 100%
Related #1234
2021-06-06 22:39:09 +01:00
Qi Xiao
59b96f27d8
Merge branch 'master' into testutil-test-coverage 2021-06-06 22:03:34 +01:00
Qi Xiao
675812c608 Fixup for #1321. 2021-06-06 22:01:41 +01:00
Qi Xiao
79b5435f8a
Merge pull request #1321 from krader1961/sleep-values
Fix `sleep` handling of the new `num` type
2021-06-06 22:00:47 +01:00
Qi Xiao
c3594f0670 Fixup for #1322. 2021-06-06 21:59:30 +01:00
Kurtis Rader
3a73babdee Increase eawk test coverage to 100%
Related #1234
2021-06-06 21:56:23 +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
f5d38ab3d7 Eliminate duplicate error definitions
In light of the preceding change to address staticcheck lint warnings I
ran this:

    grep 'errors\.New("' **.go |
        sed -e 's/^.*errors\.New("\([^"]*\)".*/\1/' |
        sort | uniq -c | sort -n

Which caused me to notice two errors associated with the builtin `sleep`
command have multiple definitions. It is questionable whether the negative
duration error is justified. I think it should be replaced by the invalid
duration error but decided not to do that in order to limit the scope of
this change.
2021-06-06 14:54:47 +01:00
Kurtis Rader
9345125bd2 staticcheck lint cleanups
Fix two issues found by `staticcheck -tests=false ./...`:

pkg/eval/go_fn.go:155:5: var errNoOptions is unused (U1000)
pkg/persistent/hashmap/hashmap.go:321:2: only the first constant in this group has an explicit type (SA9004)
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
9361832251 Fixup for #1310 2021-05-31 22:13:24 +01:00
Qi Xiao
641690ed45
Merge branch 'master' into peach-unit-test 2021-05-31 21:33:10 +01:00
Qi Xiao
c39d03e973 Support all number types in the order command.
This fixes #1309.
2021-05-31 21:25:08 +01: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
20decc5976 Implement edit:command-history &dedup
This implements `&dedup` and `&newest-first` options for
`edit:command-history`. This makes it noticably cheaper to feed unique
command history into external commands like `fzf`.

Related #1053
Fixes #568
2021-05-30 23:49:46 +01:00
Kurtis Rader
f67c7ed387 A couple of TODO cleanups 2021-05-30 00:40:42 +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
cc1a07b28b Fixup for file:truncate. 2021-05-30 00:32:30 +01:00
Supreet
fc28dddb38 file:truncate added to file module, with requested changes 2021-05-30 00:15:43 +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
641f0ebf04 Detect and suppress SIGPIPE caused by the next command in a pipeline exiting early.
This addresses #952.
2021-05-20 00:10:17 +01:00
Qi Xiao
fd70a5a274 pkg/eval/errs: Add ReaderGone error type.
Also fix the error message of SetReadOnlyVar.
2021-05-18 20:34:44 +01:00
Kurtis Rader
8a92716bd9 Add test coverage of peach
This also documents the behavior of `break` and `continue` when used in
the function passed to `peach`.

Related #1234
2021-05-17 19:28:45 -07:00
Qi Xiao
f7a82908e2 Reimplement some math functions to be exactness-preserving.
This addresses #1300.
2021-05-09 20:03:21 +01:00
Qi Xiao
79fe6947cf Reorder test cases in math.go and math_test.go. 2021-05-09 14:40:34 +01: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
3d078ec653 pkg/eval/mods/path: Skip symlink tests if unable to create symlinks.
Creating symlinks requires a special permission on Windows, which the
use may not have.

Also remove the support for symlinks in testutil.ApplyDir. Because of
this issue on Windows, any test that requires creating symlinks needs to
be broken out to an individual test case, meaning that symlinks can't be
created alongside other files, so there is less benefit of keeping it
inside the same Dir structure.
2021-05-08 13:22:21 +01:00
Qi Xiao
b80f9ed09e pkg/eval/mods/path: Fix test on Windows. 2021-05-08 02:32:42 +01:00
Qi Xiao
b1d50754e2 Remove the NEXT-RELEASE.md symlink.
GitHub displays symlinks simply as the path of the destination, meaning
that we can't just link to it for the notes of the next release.
2021-05-05 22:26:12 +01:00
Kurtis Rader
e2f810048e Add $edit:after-command and $edit:command-duration
The `edit:after-command` hooks are called with a single argument:
a pseudo-map with these keys:

    "command": the command line that was run
    "duration": the execution duration in seconds
    "error": any error that occurred ($nil if no error occurred)

The `edit:command-duration` variable is the elapsed seconds (as a
float64) of the most recently run interactive command.

Resolves #1029
2021-05-05 22:17:19 +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
2ac9d891ca Improve readability of argument mismatch error message.
* Use 0-based indexing.

* Use more natural-sounding English.

Inspired by #1290.
2021-05-02 00:27:38 +01:00
Qi Xiao
9cd90c49bb Minor fixup for #1274. 2021-05-02 00:22:28 +01:00
Qi Xiao
698d55ef07
Merge branch 'master' into issue-1248 2021-05-01 19:17:17 -04:00
Qi Xiao
7b66e9f104 Minor fixups for #1273.
Also fix a test broken by bad merge.
2021-05-02 00:13:22 +01:00
Qi Xiao
82f1912c5e
Merge branch 'master' into readonly-var-msg 2021-05-01 19:06:39 -04: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
a2ba33f6c5 Remove unneeded tests.
These tests exercise the arity checking logic, which is implemented
generically for every builtin function and does not need to be tested
individually.
2021-04-19 23:49:09 +01:00
Supreet
8f2accb0b9 File module with pipe function. Pipe command marked deprecated in compiler.go and builtin_fn_io.go
Prclose and pwclose with Deprecation marked in specific file. Give
feedback regarding the test cases.

File module now has prclose and pwclose

Wrote test cases for prclose and pwclose, need better test cases

Deprecation for prclose and pwclose marked in respective files.
2021-04-19 18:48:22 -04:00
Qi Xiao
2a1eda6bb0
Fix elvdoc of the src command 2021-04-11 01:17:39 +01:00
Qi Xiao
9b276a3431 Replace references to f{open close} in file module's elvdoc. 2021-04-09 13:03:47 +01:00
Qi Xiao
42d6e94dd7 Remove support for $-exports-. 2021-04-09 00:02:40 +01:00
Qi Xiao
c30a6a2fbe Remove support for using a lone "a=b" for assignment. 2021-04-08 23:57:40 +01:00
Qi Xiao
b53a92b964 Remove all builtin commands deprecated since 0.15.0. 2021-04-08 23:07:50 +01:00
Qi Xiao
318c4c14fd Clean up temporary files properly in the test for the file: module. 2021-04-08 23:07:11 +01:00
Qi Xiao
e1552ab4f5 Minor fixes for the file module:
* Add to release notes.

* Fix the deprecation level of fopen and fclose.

* Fix format of elvdoc and add ref doc.

* Minor style adjustments.
2021-04-08 22:55:33 +01:00
Supreet
77c40b9abb Links file module, marks fopen and fclose deprecation in compiler.go
aand builtin_fn_io.go
2021-04-08 22:45:16 +01:00
Qi Xiao
c2a232a156 Merge branch 'num'
This fixes #241.
2021-04-08 00:43:19 +01:00
Qi Xiao
5eec2c049d Remove special treatment of the builtin: namespace.
This fixes #1227.
2021-04-08 00:42:58 +01:00
Qi Xiao
fd212c1f75 More doc, and add exact-num. 2021-04-07 07:05:08 +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
e2c4030728 pkg/eval: Handle non-positive step and overflow in the range builtin. 2021-04-06 22:33:02 +01:00
Qi Xiao
5c643181a4 Cleanup, docs and tests. 2021-04-05 20:48:22 +01:00
Kurtis Rader
12980c2719 Some golint cleanups 2021-04-05 15:31:53 +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
Kurtis Rader
e2759f777b Initialize a command var to $nop~
You cannot assign $nil to a command var so that should not be the initial
value of `var x~`. Instead, assign $builtin:nop~.

Fixes #1248
2021-03-28 22:51:30 -07:00
Kurtis Rader
ddf9bf040e Correctly highlight read-only except var
Using a read-only variable as the target of an `except` clause should
highlight just the var name rather than the entire `try...except...`
statement.

Resolves #1258
2021-03-28 22:01:31 +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
959120162b pkg/eval: Use cmpd.StringLiteral in one more place.
Also remove an unused method that is now superseded by the cmpd package.
2021-03-19 23:18:42 +00:00
Kurtis Rader
69a8adb2e9 Allow quoted var names in an except... block
Related #1258
2021-03-19 22:59:25 +00:00
Qi Xiao
b2591e95a7 Add new edit:clear command.
This fixes #1238.
2021-02-26 00:36:09 +00: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
a33ecb2da4 When variable cannot set, point to the variable in the stack trace.
This fixes #255.
2021-02-21 11:53:05 +00:00
Qi Xiao
5327ba3521 Make tests compatible with "go test -count n" (n > 1).
The "-count" flag causes the test functions to be invoked multiple times. Since
some tests mutate their test data or some global state, they will fail when
invoked with a count larger than 1.

This commit changes *some* of such tests to either avoid mutating the test data,
or resetting the global state. Some such tests still remain and will be fixed later.
2021-02-17 22:46:32 +00:00
Qi Xiao
ed854fa667 Remove edit:histlist:toggle-case-sensitivity; do smart-case matching. 2021-02-14 15:52:38 +00:00
Qi Xiao
ba7a72631c Fix readline-binding, and add a test. 2021-02-14 14:41:38 +00:00
Qi Xiao
3c4db682e9 Change path:is-{dir regular} to use Lstat.
This matches their behavior with the documentation regarding symlinks; both
should return false for symlinks.
2021-02-10 23:33:31 +00:00
Qi Xiao
c96bfade21 pkg/parse: Small API tweak. 2021-02-01 14:20:56 +00:00
Qi Xiao
e4fa1cf452 Run gofmt -s on pkg/eval/closure.go. 2021-01-27 01:44:28 +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
3bf95ec088 Fix the panic when referencing a module that calls edit:add-var.
This fixes #1225.
2021-01-21 01:05:33 +00:00
Qi Xiao
37c3c0b0de Deprecate the use of "a=b" for non-temporary assignment in 0.15.
It is still the syntax for temporary assignment; only using it as a standalone
command is deprecated.
2021-01-19 23:28:34 +00:00
Qi Xiao
fbfbef8531 pkg/eval: Move implementation of compile-time deprecation to compiler.go. 2021-01-19 23:20:23 +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
Kurtis Rader
87519a9d9c Fix typo in description of path:is-regular 2021-01-17 04:56:59 +00:00
Qi Xiao
d97c989219 Introduce edit:add-var and edit:add-vars.
This addresses #1138.
2021-01-17 01:33:25 +00:00
Qi Xiao
a16cd8dfa6 pkg/eval: Allow "var a:". 2021-01-17 01:17:35 +00:00
Qi Xiao
629144195b pkg/eval: Fix handling of the global scope in (*Evaler).Eval.
- Do not mutate ev.global if cfg.Global is not nil. This fixes #1223.

- Handle concurrent mutations correctly. This addresses #1138.
2021-01-17 00:36:18 +00:00
Kurtis Rader
be712d5405
Introduce the path: module (#1203)
* Introduce the `path:` module

This is based on https://github.com/elves/elvish/pull/1084 by @kolbycrouch
submitted five months ago. It addresses all of the feedback on that
change and includes other documentation and unit test improvements. It
also includes a couple of extensions to the original P.R., such as a
`path:is-abs` command.

I decided to resurrect that change because I want better support for
filesystem path manipulation so that users can replace non-portable
external commands such as `realpath` and `find` with Elvish builtins. This
is a baby step towards that goal.

Related #849

* Add a `path:is-regular` command

This adds a `path:is-regular` command.  This is for symmetry with the
`path:is-dir` command and the glob `[type:regular]` modifier.

It also adds support for symlinks in the `testutil.Applydir` function
and change the path unit test to use it.

* Rename path:real to path:eval-symlinks
2021-01-16 23:21:33 +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
22dc0e6a6b Move parsing of ordinary assignment form to the compile phase.
This will unblock the implementation of the "var" special command.

This addresses #645.
2021-01-16 01:48:51 +00:00
Qi Xiao
5f7bcb91e5 Make the syntax for the argument of "del" consistent with assignment LHS.
This fixes #1218.
2021-01-13 23:27:38 +00:00
Qi Xiao
e833b74aa4 Document %% in the elvdoc of printf. 2021-01-11 21:49:11 +00:00
Qi Xiao
ff69171c9d Fix typo: interprete -> interpret 2021-01-11 12:00:55 +00:00
Qi Xiao
75f10573d4 Address feedback of #1200. 2021-01-10 18:34:34 +00:00
Qi Xiao
f1d1107e33 Fix the elvdoc of -source. 2021-01-10 17:08:59 +00:00
Qi Xiao
50c971e5dd pkg/eval: Split test functions. 2021-01-10 16:43:21 +00:00
Kurtis Rader
c67677fd8f Implement a printf builtin
There is more work to be done but this should address 99.9999% of the
expected uses of a `printf` builtin. Some corner cases which don't have
a POSIX analog, such as support for Elvish bool types will be implemented
in future changes.

Resolves #1132
2021-01-10 16:39:50 +00:00
Qi Xiao
2defb9c53a pkg/eval: Correctly handle variable lookup error during runtime.
This fixes #1214.
2021-01-10 13:30:07 +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
8d1a6b34db pkg/eval/evaltest: Support testing evaluation of multiple code pieces.
Also use this to simplify TestMultipleEval in pkg/eval.
2021-01-10 00:08:58 +00:00
Qi Xiao
402861fcfb eval/evaltest: Simplify EvalAndCollect. 2021-01-10 00:04:07 +00:00
Qi Xiao
d84e9801b5 Don't compile the arguments of special commands twice.
This fixes #1204.
2021-01-09 23:33:24 +00:00
Qi Xiao
28f86fefc6 Fix non-first uses of a module.
The implementation of useOp has not been updated correctly to accomodate the
fact that the namespaces are no longer modified in place.

This fixes #1212.
2021-01-09 23:17:26 +00:00
Qi Xiao
02d9252b5d pkg/eval: Return bool instead error from (*Evaler)'s PurelyEval* methods. 2021-01-09 16:05:04 +00:00
Qi Xiao
9991b08fe0 Fix panic in completion of non-existing namespace variable.
This fixes #1209.
2021-01-09 15:54:12 +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
066b48cfd2 Make all builtin functions and subnamespaces read-only.
This fixes #1211.
2021-01-09 00:41:42 +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
Kurtis Rader
5564c8f754 Fix handling of unexpected errors
Doing something like the following is likely to result in too many open
files (assuming `ulimit -n` == 256) resulting in a panic:

    > fn fact [n]{ if (== $n 0) { put 1 } else { put (* $n (fact (- $n 1))) } }
    > fact 60
    panic: interface conversion: error is *os.SyscallError, not
    *eval.Exception

    goroutine 24161 [running]:
    github.com/elves/elvish/pkg/eval.(*pipelineOp).exec.func1(0x152a5a0,
    0xc000dca210, 0xc000a44e70, 0xc00057b540, 0xc001030590, 0x203000)
        github.com/elves/elvish/pkg/eval/compile_effect.go:153 +0x152
    created by github.com/elves/elvish/pkg/eval.(*pipelineOp).exec
        github.com/elves/elvish/pkg/eval/compile_effect.go:149 +0x225
    Exception: elvish exited with 2

Fixes #1208
2021-01-07 22:34:22 +00:00
Qi Xiao
9af4c83bf6 pkg/eval: Minor cleanups. 2021-01-05 16:05:34 +00:00
Qi Xiao
af0c22c47a Move pkg/eval/resolve.go to pkg/edit, and add more introspection methods on *Ns. 2021-01-05 15:43:26 +00:00
Qi Xiao
5c55e72e78 pkg/eval: Update comments about the Elvish-Go interface. 2021-01-05 05:23:28 +00:00
Qi Xiao
2033600881 pkg/eval: Clean up Port related code. 2021-01-05 05:23:17 +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
75baa0b5a2 pkg/eval: Remove (*Ns).Append.
This change makes Ns immutable from the exposed API. Internally there is exactly
one place that still mutates Ns, in scopeOp; this will be addressed later.
2021-01-05 01:09:04 +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
0a3d7ac02e pkg/eval: Fix $args.
This fixes #1207.
2021-01-04 21:04:17 +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
b44bbd9668 pkg/eval: Remove superfluous tests. 2021-01-04 14:36:53 +00:00
Qi Xiao
1be25a240c pkg/eval: Internal cleanups.
- Remove the Op type; it is no longer used by any code outside the eval package
  and its use within the package is limited.

- Replace (*Evaler).execOp with (*Evaler).prepareFrame.
2021-01-04 14:17:27 +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
685f0a2593 Fix the example in the elvdoc for -source. 2021-01-03 22:59:24 +00:00
Qi Xiao
d844d80ebb Fix format of elvdoc for -source. 2021-01-03 22:36:13 +00:00
Qi Xiao
09b8dcdf2f Handle the global namespace correctly in the -source command.
The -source command now runs with a temporary namespace that is amalgamated
from the local and up namespace of the caller -source; this means that it can
no longer mutate its caller's local scope, which is the only possible sensible
behavior anyway.

This fixes #1202.
2021-01-03 22:31:55 +00:00
Qi Xiao
086038fa0f pkg/eval: Remove (*Evaler).Close. 2021-01-03 20:55:04 +00:00
Qi Xiao
5fbeb781ff pkg/eval: Remove (*Frame).Eval. 2021-01-03 20:54:35 +00:00
Qi Xiao
d140e98f3c Fix definition of recursive functions with fn.
Also document explicitly that the function body may refer to the function being
defined.

This fixes #1206.
2021-01-03 20:44:52 +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
261861888a pkg/eval: Support specifying an alternative global Ns in EvalCfg.
This feature supersedes the CompileWithGlobal method, and simplifies the only
use of that method in pkg/edit, where the default binding is evaluated using the
edit: namespace as the global Ns.
2021-01-03 17:20:56 +00:00
Qi Xiao
9323912c98 pkg/eval: De-export (*Evaler).Compile, and expose a (*Evaler).CheckTree.
The Compile method was used only by the syntax highlighting code to find
compilation errors. Since it only needs the error part but not the Op part,
provide an alternative API that only exposes the error.
2021-01-03 17:05:15 +00:00
Qi Xiao
3f6b5da2b9 pkg/shell: Print both parse and compile errors when using -compileonly -json.
The new (*Evaler).Check method allows the implementation to be simpler.

Also test the JSON format feature in an integration test instead of unit test;
this makes it unnecessary for the eval package to expose NewCompilationError.
2021-01-03 16:32:04 +00:00
Qi Xiao
7663d9a0ce pkg/eval: Replace the NoExecute option of (*Evaler).Eval with a new Check method.
This method has the property that it always tries to compile the code even if
there is a parse failure. This is the more desirable behavior when checking
code: if there is a parse failure near the end of a chunk of code, the user may
like to learn about compile errors earlier in the code.
2021-01-03 16:01:24 +00:00
Qi Xiao
2d971d2cd0 pkg/eval: De-export (*Evaler).ParseAndCompile.
All code outside the eval package now uses (*Evaler).Eval to evaluate code, and
do not need this method anymore.
2021-01-02 02:41:36 +00:00
Qi Xiao
5642dc3756 pkg/eval: Test compile-time deprecations using (*Evaler).Eval. 2021-01-02 02:39:38 +00:00
Qi Xiao
e43492ba17 pkg: Move edit.capturePort to eval.CaptureStringPort. 2021-01-02 02:39:03 +00:00
Qi Xiao
9b5dc09f14 pkg/eval: In (*Evaler).Eval, replace nil ports with placeholder ports.
This allows callers of this method to only supply the ports it is interested in
setting and leave the rest either unspecified or nil.
2021-01-02 02:22:44 +00:00
Qi Xiao
7cd2745c03 Deflake the test against "sleep" by delaying the SIGINT slightly.
The test contained a race condition: when the mock TimeAfter implementation
sends the process a SIGINT, the "sleep" function may not have entered the
"select" block, meaning that the signal will be ignored.

This commit works around this by waiting 1ms (scaled with
$ELVISH_TEST_TIME_SCALE) before sending SIGINT. The test now consistently
succeeds on my local laptop.
2021-01-02 01:49:40 +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
dc59cbfeb4 pkg/eval: Make (*Evaler).Eval accept a Source instead of an Op.
Most callers can now call it with the source to evaluate, without having to call
ParseAndCompile first themselves.
2021-01-02 00:10:26 +00:00
Qi Xiao
5f0e4fc196 pkg/eval: Remove the bool return value of GetCompilationError.
This is done for consistency with parse.GetError.
2021-01-01 23:27:11 +00:00
Qi Xiao
e4cebea152 pkg/eval: Simplify the tests for -source by running them in a temp dir. 2020-12-29 13:46:03 +00:00
Qi Xiao
3615988408 Change signature of "exec" and "fg" on Windows to match that on Unix.
This fixes #1195.
2020-12-26 22:59:18 +00:00
Qi Xiao
3e29266ee0 pkg/eval: Remove unused (*Evaler).InstallBundled. 2020-12-26 03:26:10 +00:00
Qi Xiao
719314c029 pkg/eval: Various cleanups for qname handling code. 2020-12-25 22:31:52 +00:00
Qi Xiao
8613527450 pkg/eval: Deduplicate code for command head resolution. 2020-12-25 21:30:57 +00:00
Qi Xiao
9a6d53e012 Fix Windows build. 2020-12-25 17:58:03 +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
Qi Xiao
09829ae9cd pkg/eval: Update doc of the "not" command. 2020-12-25 17:46:09 +00:00
Kurtis Rader
f94a0ec735 Trivial documentation consistency change
I noticed that most places in the documentation that emit a "note"
about Elvish behavior use `**Note**:`. There were two places that use
all uppercase. Make those consistent with the other uses. Also clarify
the note associated with the `not` builtin.
2020-12-25 17:43:32 +00:00
Kurtis Rader
d52aa03764 In prompts implicitly coerce float64 to string
Including the float64 data type in the prompt value stream causes an error.
This causes those values to be implicitly converted to a string as happens
everywhere else in Elvish.

I initially intended to modify the code to do the implicit string coercion
for any type not otherwise explicitly handled by the pkg/ui `Concat`
methods. I decided against that approach because doing so doesn't make
sense for some types that might appear in the value stream; e.g., Elvish
exceptions.

Fixes #1186
2020-12-25 17:34:49 +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
bd69facfb2 Add benchmarks for variable access.
Also change the benchmarks to only benchmark eval time, excluding parse and compile.
2020-12-25 00:44:26 +00:00
Qi Xiao
6f3b8a787b Minor fixup for last commit. 2020-11-07 19:02:44 +00:00
Kurtis Rader
b58b495d77 Fix hang reading value channel from a redirection
Fixes #600
Fixes #1010
2020-11-07 13:52:29 -05:00
Kurtis Rader
a943dc764a Improve navigation mode corner cases
There are some Navigation mode corner cases whose current behavior is
surprising. Such as inserting a space before the filename when the space
isn't wanted or redundant. Also, selecting an empty directory and pressing
Enter should insert nothing rather than an empty string.

Fixes #1169
2020-11-07 13:17:00 -05:00
Kurtis Rader
f1baa70a78 Fix the $pwd tests
Not sure what happened but my fix for issue #1120 resulted in the core
unit test module not being executed due to a bogus "// +build wtf"
comment. Apparently I was experimenting with "+build" directives and
forgot to remove that line. This also improves the test coverage of the
$pwd code from 44% to 100%.
2020-10-28 19:36:01 -04:00
Kurtis Rader
784c4159d2 Minor documentation improvements
Fixing issue #857 will require some non-trivial work. But I noticed these
documentation cleanups when I started working on the issue so I'm making
them as an independent change.

Related #857
2020-10-22 15:28:06 +01:00
Qi Xiao
318efef553 Remove the "binding" bundled module.
It is some leftover code from the old editor and is no longer used.
2020-10-10 22:47:56 +01:00
Shengjing Zhu
6c08de0ff3 Fix typos found by codespell 2020-10-10 22:47:50 +01:00
Scott Reeves
864097a4ce Update elvdocs referencing deprecated splits 2020-10-10 22:44:00 +01:00
Scott Reeves
3085870115 Try to resolve confusion around Alt-1 vs. Alt-, 2020-10-10 22:38:36 +01:00
Qi Xiao
672f097a2c pkg/eval: Break up value.go. 2020-10-10 22:28:13 +01: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
5ec11cfe2b Update docs for $_ and $nil. 2020-09-04 22:45:04 +01:00
Qi Xiao
a88ac31b39 pkg/eval: De-export PwdVariable. 2020-09-04 22:32:41 +01:00
Qi Xiao
948432e766 pkg/eval: De-export GoFn. 2020-09-04 22:30:42 +01:00
Qi Xiao
f1efae4f5f pkg/eval: De-export EnvList. 2020-09-04 22:24:24 +01:00
Qi Xiao
2af7361bd5 pkg/eval: De-export Closure. 2020-09-04 22:18:50 +01:00
Qi Xiao
ad9c93df9d pkg/eval: Styled -> styled. 2020-09-04 22:15:29 +01:00
Qi Xiao
9df62a6dc9 pkg/eval: Remove unused PurelyEvalCompound. 2020-09-04 22:15:15 +01:00
Qi Xiao
72d7c5c595 pkg/eval: Minor godoc edits. 2020-09-04 22:10:47 +01:00
Qi Xiao
b986d80a49 pkg/eval: Move EachExternal to the fsutil package. 2020-09-04 22:04:20 +01:00
Qi Xiao
f3c2185dae pkg/eval/evaltest: Move Must* functions to the testutil package.
Also exclude those functions from test coverage calculation.
2020-09-04 21:57:20 +01:00
Qi Xiao
03f543a9b9 pkg/eval: Use util.ApplyDir in a test. 2020-09-04 21:50:13 +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
9b9a6de2cd pkg/eval: Cause -> Reason. 2020-09-04 21:04:58 +01:00
Qi Xiao
bd33459eaf pkg/eval/evaltest: Move value and error matching code to separate file. 2020-09-04 20:55:19 +01:00
Qi Xiao
90a99c1792 pkg/eval/evaltest: Consolidate all the Throws* methods into one. 2020-09-04 20:31:47 +01:00
Qi Xiao
b271a85279 pkg/eval/evaltest: Move InTempHome to pkg/testutil. 2020-09-03 06:55:14 +01:00
Qi Xiao
bb122024dd pkg/eval: Move test framework into new evaltest package. 2020-09-03 06:51:21 +01:00
Qi Xiao
fca1621294 pkg/eval: Export the StackTrace type. 2020-09-03 05:54:32 +01:00
Qi Xiao
11898f763a pkg/util: Break into fsutil/ and logutil/. 2020-09-03 05:27:18 +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
6dd122107c pkg: Move multierror.go from util/ to diag/. 2020-09-03 05:12:55 +01:00
Qi Xiao
eae14f91b9 pkg: Move camel_to_dashed from util/ to strutil/. 2020-09-03 05:10:59 +01:00
Qi Xiao
48919bcb24 pkg/: Move test utilities from util/ to testutil/. 2020-09-03 04:55:16 +01:00
Qi Xiao
eb9638fc16 pkg/eval: Move modules into a mods directory. 2020-09-03 04:31:04 +01:00
Kurtis Rader
0f6b4bb737 Test $pwd behavior
Related #1062
Resolves #1120
2020-09-03 04:25:38 +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
e28a7d766b pkg/eval: Small fixup for ExternalCmd tests. 2020-09-03 04:16:29 +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
b1ef4b2c6d pkg/eval: Fixup for the elvdoc of the sleep command. 2020-08-31 20:27:29 +01:00
Kurtis Rader
19e158d08a Document builtin sleep and add tests
I was reviewing test coverage and noticed that the `esleep`
implementation was undocumented and had no tests. This

a) implements `sleep` and deprecates `esleep`,

b) uses the Go time.ParseDuration function rather than assuming a
simple number of seconds,

c) documents the command,

d) adds tests of the function.

Related #1062
2020-08-31 20:22:47 +01:00
Qi Xiao
0bbee3b5f4 pkg/eval: Fix the error message when using dynamic string as head. 2020-08-31 14:01:49 +01:00
Kurtis Rader
e25ee599db Increase options.go coverage to 100%
Related #1062
2020-08-26 20:40:22 +01:00
Kurtis Rader
2bbe6d2212 Add explicit cd unit tests
This is to ensure we have good test coverage of the `cd` implementation.

Related #1062
2020-08-26 20:34:34 +01:00
Qi Xiao
0c00a92839 Fix crash when accessing the body attribute of fn-defined functions.
This fixes #1126.
2020-08-25 20:17:21 +01:00
Qi Xiao
b2c85b7c2f pkg/eval: Add some basic benchmarks for code evaluation. 2020-08-23 17:33:54 +01:00
Qi Xiao
4a130be641 pkg/eval: Move benchmarks to separte file. 2020-08-23 16:07:11 +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
Qi Xiao
821e414fc9 pkg/eval/errs: Change OutOfRange.Valid{Low High} to strings. 2020-08-18 21:23:26 +01:00
Kurtis Rader
da16162cc8 Increase umask code coverage from 62% to 100%
Related #1062
2020-08-18 21:13:27 +01:00
Qi Xiao
4659d9bcc6 Introduce a use-mod command.
This fixes #1113.
2020-08-17 00:11:25 +01:00
Qi Xiao
ea31426a9a pkg/eval: Refactor to reuse code between "use" and "eval". 2020-08-16 23:32:51 +01:00
Qi Xiao
ff7c500506 Deprecate the -source command. 2020-08-16 23:07:30 +01:00
Qi Xiao
735d30c0ff Introduce a new eval command.
This fixes #230.
2020-08-16 23:04:10 +01:00
Qi Xiao
dca782d573 pkg/eval: Document and test the ns builtin.
Also return a structured error with errs.BadValue.
2020-08-16 22:01:03 +01:00
Qi Xiao
9b2b33b429 pkg/eval: Move elvdoc comments before the implementations. 2020-08-16 18:46:29 +01:00
Qi Xiao
d5736120e5 Fixup for removal of "joins" and "splits".
* Migrate epm

* Fix docs
2020-08-16 17:29:09 +01:00
Kurtis Rader
6c07af8dab Add randint command unit tests
This results in pkg/eval/builtin_fn_num.go having only
one untested statement and that is being discussed in
https://github.com/elves/elvish/issues/1099.

Related #1062
2020-08-16 16:57:41 +01:00
Kurtis Rader
5d78bab127 Add basic tests for the *-external builtins
This adds basic tests for three functions in pkg/eval/builtin_fn_cmd.go
that implement the `external`, `has-external`, and `search-external`
builtin commands. TBD is how to test those commands on MS Windows.

Related #1062
2020-08-16 16:54:33 +01:00
Kurtis Rader
1b200c4bd9 Validate a for loop corner case
This exercises the first failure condition in the `evalForVar` function.
Thus bringing coverage of pkg/eval/value_helper.go to 100%.

Related #1062
2020-08-16 16:52:47 +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
d5df47f986 Deprecate has-{prefix suffix}. 2020-08-16 16:27:24 +01:00
Qi Xiao
0c2d05f260 Remove support for using \ for line continuation. 2020-08-16 16:16:24 +01:00
Qi Xiao
bb24b63356 Remove builtin commands deprecated in v0.14.0. 2020-08-16 16:10:58 +01:00
Qi Xiao
2fb2c8e4a3 Fix the deprecation warnings for "ord" and "chr". 2020-08-16 16:02:48 +01:00
Qi Xiao
8f410a24be pkg/util: Move environment variable names to a new package.
Also document that this package should be broken up.
2020-08-16 14:12:48 +01:00
Qi Xiao
8aa9c26ba2 Small fixup for #1092.
* Call decSHLVL from execFn.

* Rephrase doc comment.
2020-08-16 14:08:48 +01:00
Kurtis Rader
b2c7746bf6 Replace "PATH" literals with a constant 2020-08-16 14:05:13 +01:00
Kurtis Rader
19f315e28a Replace "PWD" literals with a constant 2020-08-16 14:05:13 +01:00
Kurtis Rader
f656f9511b Replace "HOME" literals with a constant 2020-08-16 14:05:13 +01:00
Kurtis Rader
ade5fa6c76 Fix exec handling of $E:SHLVL
Fixes #1091
2020-08-16 14:05:13 +01:00
Qi Xiao
239ce3ec0d pkg/eval/testutil.go: Expand the comments on the Throws* methods. 2020-08-16 13:51:48 +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
0c72fcd5b1 Small fixup for #1081. 2020-08-13 22:14:16 +01:00
Gabriel Rauter
1124c10b56
Add str:from-utf8-bytes, str:to-utf8-bytes and move builtin ord and chr to str module (#1081)
* pkg/eval/str: move builtin ord and chr to str

Move builtin string function ord and chr to the str module and rename to
to str:to-codepoints and str:from-codepoints respectively as suggested
in #851.

* pkg/eval/str: add from-utf8-bytes & to-utf8-bytes

Add from-utf8-bytes and to-utf8-bytes functions to the str module. This
functions differ from their *-codepoints in that they handle utf8 bytes
instead of whole codepoints. Closes #851

* pkg/eval/str: range check for codepoint and bytes

str:from-codepoints
Add check if arguments codepoints are within valid unicode range, return
an OutOfRange error otherwise. Return a BadValue error if the codepoint
isn't valid. Add/change testcases.

str:from-utf8-bytes
Add check if byte arguments are within valid range, return an OutOfRange
error otherwise. Return a BadValue error if the byte sequence isn't a
valid UTF-8 sequence. Add/change testcases.

Add additional test if piping from str:to-codepoints/str:to-utf8-bytes
to str:from-codpoints/str:from-utf8-bytes returns the original input.
2020-08-13 21:56:28 +01:00
Kurtis Rader
3300c81c8b Document break, continue, and return
Since `break`, `continue`, and `return` are builtin commands, rather
than language keywords, they should be documented on the builtin module
reference page.
2020-08-04 23:08:41 +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
Kurtis Rader
5f0b72ab4f rephrase float64 description 2020-07-25 16:25:23 +01:00
Kurtis Rader
cff229d9fa Remove two obsolete TODO comments and resolve one 2020-07-25 16:25:23 +01:00
Kurtis Rader
9858d5a545 Add missing deprecation text for explode
Also, fix trivial typo in a comment as reported at
https://goreportcard.com/report/github.com/elves/elvish
2020-07-21 22:51:53 +01:00
Qi Xiao
e5e0446c5a Warn about deprecated syntax features in imported modules.
This fixes #1072.
2020-07-15 00:04:03 +01:00
Shengjing Zhu
45b12127f6 pkg/eval: Don't hardcode signal name in test
On gccgo signal name is capitalized.
2020-07-14 20:49:03 +01:00
Shengjing Zhu
b52ca6b530 pkg/eval/platform: Add workaround for failing test on gccgo 2020-07-14 20:49:03 +01:00
Qi Xiao
853f00c812 pkg/eval: Fix panic on "show $ok".
This fixes #1064.
2020-07-04 19:08:09 +01:00
Qi Xiao
c5c07bbb81 pkg/eval: Do not crash when showing an exception with nil reason.
This fixes #994.
2020-07-01 21:48:03 +01:00
Qi Xiao
06a00f4a5f pkg/parse: Show deprecation warning when using \ for line continuation.
This addresses #979.
2020-07-01 21:39:29 +01:00
Qi Xiao
e9b4035896 pkg/eval: Move the show command into the builtin namespace.
This will likely become a basic operation in future that can support more types
than exceptions, so putting it in the builtin namespace is appropriate.

Also remove the exc: module altogether as it contains nothing now. All the
introspection features are now implemented as fields of the exception values and
the reason values.
2020-06-30 22:36:27 +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
3eda8d2f43 pkg/eval/exc: Make the predicates work on the exception reason.
This brings the Elvish API closer to the Go internal API.
2020-06-29 23:45:54 +01:00
Qi Xiao
7b9f784cd5 pkg/eval: Rename fields of Exception, and expose fields as a pseudomap. 2020-06-29 21:26:10 +01:00
Qi Xiao
5874863991 pkg/eval: Use pseudo-structmap to implement closure introspection. 2020-06-29 00:32:00 +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
088190b4a5 Address remaining feedback of #1018. 2020-06-28 01:33:27 +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
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
ff16eda59f pkg/eval/exc: Add missing unit tests for exc:is-pipeline-exc. 2020-06-24 22:41:59 +01:00
Qi Xiao
df6d741217 pkg/eval/exc: Add exc:is-pipeline-exc. 2020-06-24 22:41:00 +01:00
Qi Xiao
e3387b2be0 pkg/eval/exc: Add missing example for exc:is-fail-exc. 2020-06-24 22:35:44 +01:00
Qi Xiao
abe9fa3aec Fixup for platform:hostname. 2020-06-14 12:24:42 +01:00
Kurtis Rader
90860c1ba2 Implement platform hostname command
Resolves #1028
2020-06-14 12:19:41 +01:00
Qi Xiao
65eeda9ae2 pkg/eval/exc: Rename is-*-error to is-*-exc.
These predicates are for exceptions, not errors. Moreover, Elvish doesn't really
have a concept of errors, only exceptions.

This addresses #208.
2020-05-31 13:59:55 +01:00
Qi Xiao
50d0b33e53 pkg/eval/exc: Add exc:is-fail-error.
This addresses #208.
2020-05-31 13:57:27 +01:00
Qi Xiao
270c7f230e pkg/eval: Support passing any value to "fail". 2020-05-31 13:56:59 +01:00
Qi Xiao
4bf795a08d pkg/eval/exc: Introduce is-{external-cmd-error nonzero-exit killed}.
This addresses #208.
2020-05-30 12:05:07 +01:00
Qi Xiao
e13ee5aba4 pkg/eval: Fix a nil pointer panic.
The preExit function is not checking whether fm.DaemonClient is nil, which
causes "exit" and "exec" to panic in non-interactive mode.
2020-05-29 00:20:12 +01:00
Kurtis Rader
720181be03 Fix two typos 2020-05-26 21:24:57 +01:00
Qi Xiao
ff292d43ce pkg/eval: Make the sorting of "order" always stable. 2020-05-25 21:50:09 +01:00
Qi Xiao
1cd192daaf pkg/eval: Implement "order".
This fixes #651.
2020-05-25 17:45:08 +01:00
Qi Xiao
0724478faf pkg/eval/testutils.go: Print outputs using Repr when they don't match. 2020-05-25 17:44:49 +01:00
Kurtis Rader
2d86a2453d Clarify the rules for using styled #RGB values
Document that an unqouted `#` character has special meaning to the Elvish
parser in the context of passing `#RGB` values to the `styled` command.
Also document the `fg-` color name prefix.
2020-05-18 00:25:05 +01:00
Qi Xiao
a4875de822 pkg/eval: Document {from to}-lines.
This fixes #1023.
2020-05-17 16:35:44 +01:00
Kurtis Rader
83ab9fe9c0 Remove obsolete, broken, "narrow" module
Related #1021
2020-05-17 16:05:43 +01:00
Kurtis Rader
1d85b7fced Cleanups to previous commit 2020-05-14 23:46:24 +01:00
Kurtis Rader
3e4cb1ed6e Implement math:min and math:max
Resolves #727
2020-05-14 23:46:24 +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
05156ea239 Add make-map command.
This fixes #943.
2020-05-05 23:23:23 +01:00
Qi Xiao
92cb80d89a Support rethrowing an exception with "fail".
This fixes #941.
2020-05-05 00:43:50 +01:00
Qi Xiao
e72f7183a0 pkg/eval/go_fn.go: Surface errors in option parsing.
This fixes #958.
2020-05-03 23:39:16 +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
Kurtis Rader
d9ec0447fc Implement math:pow and math:pow10
To facilitate using the `^` character for line continuation we need to
remove its use an an exponentiation function. So introduce `math:pow`
and `math:pow10` as alternatatives and mark `^` as deprecated.

Related #989
2020-05-03 21:40:10 +01:00
Qi Xiao
0bbbd70cf1 pkg/eval/exc: Add newline in the output of exc:show; expand doc. 2020-05-02 23:46:36 +01:00
Qi Xiao
0b5b210d24 Add exc:show for showing exceptions.
This addresses #945.
2020-05-02 23:28:42 +01:00
Kurtis Rader
098e0e6880 Document base command 2020-04-27 10:33:02 +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
90a34f2d19 pkg/eval: Support specifying a callback for the "time" builtin.
This fixes #295.
2020-04-26 21:11:01 +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
3e9d5e9e60 pkg/eval/str: Add join, replace and split.
The implementations are mostly copied from the builtin joins, replaces and
splits, with small changes to the error behavior in the join function.

The versions in the builtin module are now deprecated.
2020-04-26 17:01:10 +01:00
Qi Xiao
43054831e6 pkg/eval/vals: Support float64 in Kind. 2020-04-26 15:38:09 +01:00
Qi Xiao
c767f92d01 Support compile-time deprecation.
This fixes #898.
2020-04-26 13:14:51 +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
3fb0098fed pkg/eval: Support checking stderr in tests. 2020-04-26 00:13:06 +01:00
Qi Xiao
88122a019e pkg: Simplify some APIs by using parse.Tree. 2020-04-25 19:36:35 +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
13f7b29707 pkg/parse: Add a new Parse function and a Tree type.
This replaces the AsChunk function. All current users of parse.AsChunk has been
changed to use parse.Parse instead.
2020-04-25 19:16:22 +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
53a1eca9af pkg/eval: Remove New*Source functions.
All call sites of such functions are replaced with simple &Source{...}
expressions.
2020-04-25 13:22:07 +01:00
Qi Xiao
c112223611 pkg/eval: Simplify API of "src".
Remove the Type and Root fields, and add a new IsFile field.
2020-04-25 12:50:07 +01:00
Qi Xiao
28a7ca5a15 Document read-upto.
This fixes #938.
2020-04-19 14:28:37 +01:00
Qi Xiao
5cdff82883 pkg/eval: Fix stack trace, and add tests. 2020-04-18 00:28:48 +01:00
Kurtis Rader
ab3e7d6169 Implement the three inverse hyperbolic functions
Related #727
2020-04-17 22:08:17 +01:00
Qi Xiao
9869557aee pkg/eval: Add a few tests for builtin string functions.
This addresses #944.
2020-04-17 01:15:45 +01:00
Qi Xiao
e8368127b7 pkg/eval: Add more tests against glob.go.
This addresses #944.
2020-04-17 00:47:00 +01:00
Qi Xiao
fbc18ba55d pkg/eval: Rewrite glob tests. 2020-04-17 00:40:47 +01:00
Qi Xiao
c9458344f1 pkg/eval: Remove unneeded methods of GlobPattern. 2020-04-17 00:20:30 +01:00
Kurtis Rader
094a03ac5b Normalize count implementation arity exception
Add some comments that clarify why the `count` implmentation does not
use the `Inputs` API. Change the mismatched arg count exception to match
that of the `Inputs` API. Add a couple more unit tests.

Resolves #966
2020-04-16 15:56:20 +01:00
Qi Xiao
0c50e93ebd pkg/eval: Remove (*Evaler).EvalInTTY.
This is so that pkg/program/shell can get rid of the dependency on the standard
streams and can dependency-inject the files.
2020-04-16 00:11:23 +01:00
Qi Xiao
b1d9efbe47 pkg/eval: Tighten the type of Frame.intCh. 2020-04-15 23:03:58 +01:00
Qi Xiao
a99d930424 pkg/eval: Add test for source.go.
Also fix a small bug in printing internal Elvish sources.

This addresses #944.
2020-04-15 00:47:35 +01:00
Qi Xiao
8292a5b166 pkg/eval: Remove Evaler.EvalSourceInTTY. 2020-04-15 00:04:23 +01:00
Kurtis Rader
60fa63c383 Implement inverse trigonometric math functions
Related #727
2020-04-14 23:59:11 +01:00
Kurtis Rader
9b1c2783a7 Implement hyperbolic trigonometric math functions
Related #727
2020-04-14 23:58:10 +01:00
Kurtis Rader
2c6a90601c Fix two typos in my previous change 2020-04-14 23:57:33 +01:00
Qi Xiao
d77ad829b6 pkg/eval: Add Evaler.ParseAndCompile.
Also require a name argument in NewInteractiveSource.
2020-04-14 23:54:45 +01:00
Qi Xiao
6597d38834 pkg/eval: Test more error cases. 2020-04-13 16:29:01 +01:00
Qi Xiao
a36a372624 pkg: Fix small issues found by staticcheck. 2020-04-13 13:56:10 +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
Kurtis Rader
f9d90f0225 Fix formatting of the styled documentation 2020-04-13 02:32:08 +01:00
Qi Xiao
887967a7bb pkg/eval: Fix elvdoc for the "all" builtin. 2020-04-13 00:52:21 +01:00
Qi Xiao
7ad3f6aa24 pkg/eval: Test GoFn's Elvish value methods. 2020-04-13 00:50:03 +01:00
Qi Xiao
07a9e781a6 pkg/eval: Report detailed ArityMismatch errors. 2020-04-13 00:47:33 +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
bd2ffa75cc pkg/eval: Make exception matching more explicit.
Don't match implicitly by Cause. Instead, use a new .ThrowsCause method to
explicitly match for the cause.
2020-04-10 20:55:31 +01:00
Qi Xiao
79ed2c5549 pkg/eval: Fix the indentation in the styled doc. 2020-04-10 18:27:37 +01:00
Kurtis Rader
f59e96204e Document and add math functions
In addition to documenting the `math:` module introduced by commit 2d8a045c
two months ago this also:

a) restructures the code to match that of the `re:` and `str:` modules, and

b) adds many more useful constants and functions.

I don't think this completely addresses issue #727 so I'm marking this
as related to, rather than fixing, that issue.

Related #727
2020-04-10 18:15:38 +01:00
Qi Xiao
33da89f34f pkg/eval: Clean up API.
Unexport some of the test utilities, and remove unused AddDirer.
2020-04-10 18:10:42 +01:00