Commit Graph

53 Commits

Author SHA1 Message Date
Qi Xiao
5a237d7888 pkg/eval: When compiling, emit autofixes for using unimported builtin modules. 2022-12-11 14:21:09 +00:00
Qi Xiao
78862465a4 pkg/diag: Include line:col of start position in Error and Show methods.
The Error methods used to show the start and end indices, while the Show methods
used to show line ranges.

Showing line:col of the start position seems to be pretty standard; both Go and
Rust do that.

I tried including the line:col of the end position too, but can't find a good
enough format.
2022-12-08 19:07:18 +00:00
Qi Xiao
121509d8d2 pkg/eval: Preserve all compilation errors.
Multiple compilation errors are packed using diag.PackCognateErrors, like parse errors.
2022-11-30 01:40:03 +00:00
Qi Xiao
69715b05fe pkg/eval: Don't use panics for propagating compilation errors.
This also enables saving multiple compilation errors.
2022-11-29 21:17:13 +00:00
Qi Xiao
f8f60953ad Properly deprecate float64.
- Replace its use with "num" in documentation and test code.

- Add a new "inexact-num" for explicitly converting a number to inexact.

This fixes #1513.
2022-04-09 11:45:15 +01:00
Qi Xiao
51e4d97568 interface{} -> any now that Elvish requires Go 1.18. 2022-03-20 16:17:19 +00:00
Qi Xiao
653c9f9d0f Remove dir-history, deprecated since 0.17.0. 2022-01-03 00:47:41 +00:00
Qi Xiao
6a92571a23 Check assignments to read-only variable during compilation. 2021-10-13 23:57:14 +01:00
Qi Xiao
862cf5619d Support turning off implicit external command resolution.
See documentation in website/ref/language.html.

This fixes #978.
2021-10-07 01:21:28 +01:00
Qi Xiao
0571db69e2 Remove commands deprecated in 0.16.0, and deprecate dir-history. 2021-10-03 16:47:51 +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
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
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
b53a92b964 Remove all builtin commands deprecated since 0.15.0. 2021-04-08 23:07:50 +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
196eea21d4 Change module import path to src.elv.sh 2021-01-27 01:30:25 +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
fbfbef8531 pkg/eval: Move implementation of compile-time deprecation to compiler.go. 2021-01-19 23:20:23 +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
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
Qi Xiao
56ceeedd21 pkg/eval: Store variable deletion information in *Ns.
This fixes #1213.
2021-01-10 00:54:02 +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
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
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
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
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
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
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
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
ff7c500506 Deprecate the -source command. 2020-08-16 23:07:30 +01:00
Qi Xiao
d5df47f986 Deprecate has-{prefix suffix}. 2020-08-16 16:27: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
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
720181be03 Fix two typos 2020-05-26 21:24:57 +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
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
c767f92d01 Support compile-time deprecation.
This fixes #898.
2020-04-26 13:14:51 +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
b8505c7065 pkg/eval/source.go -> pkg/parse/source.go. 2020-04-25 18:26:17 +01:00
Qi Xiao
8c71635ca3 pkg/eval: Move all assignments to the start of the pipeline they belong in.
This avoids race conditions of accessing the local scope. The test case
"x = 1", "put $x | y = (all)" used to contain a race condition but no longer
does.

This addresses #73.
2020-03-28 23:49:30 +00:00
Qi Xiao
9bebf49b40 pkg/diag: Let NewContext accept a Ranging. 2020-03-28 22:12:42 +00:00
Qi Xiao
3abfc42a8e [cleanup] pkg/eval: Remove boilerplate.go. 2020-03-28 21:33:55 +00:00
Qi Xiao
e6b7d06e80 [cleanup] pkg/eval: Remove compiler.errorf and compiler.compiling.
All errors are now written using compiler.errorpf.
2020-03-28 21:33:55 +00:00
Qi Xiao
d306f33af6 [cleanup] pkg/eval: Let compiler.errorpf accept a single diag.Ranger. 2020-03-28 21:33:55 +00:00