Commit Graph

21 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
9e6555a4fb pkg/eval: Reorganize benchmarks.
Use b.Run to run benchmarks. Also remove the dedicated tests for output capture.
2021-12-02 00:30:01 +00:00
Kurtis Rader
d4b4edbbbe Replace legacy lambda with new lambda examples
I was surprised to see so many legacy lambda syntax examples in the
documentation. This replaces all of them with the new syntax -- excluding
the handful of cases meant to explicitly verify the legacy form is still
valid. This also adds a link to the issue in the release notes which
documents the change in syntax.

Related #664
2021-11-28 21:30:59 +00:00
Qi Xiao
d8ff3e743e pkg/eval: Fill in default dummy ports in Evaler.prepareFrame.
Also fix the value of Frame.port in a benchmark.

This fixes #1355.
2021-08-01 21:38:30 +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
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
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
b87cc7b5de Add back support for circular module dependency.
This fixes #1226.
2021-01-24 14:10:45 +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
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
086038fa0f pkg/eval: Remove (*Evaler).Close. 2021-01-03 20:55:04 +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
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
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
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
734eb955e2 pkg/eval: Use exported methods to access ports from builtin functions. 2020-10-10 22:28:13 +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