Evaler.Eval now also takes a name.

This commit is contained in:
Qi Xiao 2016-10-13 21:45:50 +08:00
parent 1e6ee5c290
commit 0c3995f8c0
2 changed files with 10 additions and 10 deletions

View File

@ -153,9 +153,9 @@ func (ec *EvalCtx) Interrupts() <-chan struct{} {
return ec.intCh return ec.intCh
} }
// Eval sets up the Evaler and evaluates a chunk. The supplied text is used in // Eval sets up the Evaler and evaluates a chunk. The supplied name and text are
// diagnostic messages. // used in diagnostic messages.
func (ev *Evaler) Eval(text string, n *parse.Chunk) error { func (ev *Evaler) Eval(name, text string, n *parse.Chunk) error {
inCh := make(chan Value) inCh := make(chan Value)
close(inCh) close(inCh)
@ -216,7 +216,7 @@ func (ev *Evaler) Eval(text string, n *parse.Chunk) error {
close(sigGoRoutineDone) close(sigGoRoutineDone)
} }
ret, err := ev.eval("[interactive]", text, n, ports) ret, err := ev.eval(name, text, n, ports)
close(outCh) close(outCh)
<-outDone <-outDone
close(stopSigGoroutine) close(stopSigGoroutine)
@ -317,12 +317,12 @@ func (ec *EvalCtx) errorpf(begin, end int, format string, args ...interface{}) {
} }
// SourceText evaluates a chunk of elvish source. // SourceText evaluates a chunk of elvish source.
func (ev *Evaler) SourceText(src string) error { func (ev *Evaler) SourceText(name, src string) error {
n, err := parse.Parse(src) n, err := parse.Parse(src)
if err != nil { if err != nil {
return err return err
} }
return ev.Eval(src, n) return ev.Eval(name, src, n)
} }
func readFileUTF8(fname string) (string, error) { func readFileUTF8(fname string) (string, error) {
@ -342,7 +342,7 @@ func (ev *Evaler) Source(fname string) error {
if err != nil { if err != nil {
return err return err
} }
return ev.SourceText(src) return ev.SourceText(fname, src)
} }
// Builtin returns the builtin namespace. // Builtin returns the builtin namespace.

View File

@ -96,7 +96,7 @@ func Main() {
if len(args) == 1 { if len(args) == 1 {
if *cmd { if *cmd {
ev.SourceText(args[0]) ev.SourceText("code from -c", args[0])
} else { } else {
script(ev, args[0]) script(ev, args[0])
} }
@ -134,7 +134,7 @@ func source(ev *eval.Evaler, fname string, notexistok bool) error {
return err return err
} }
err = ev.SourceText(src) err = ev.SourceText(fname, src)
if err != nil { if err != nil {
printError(err, fname, "Error", src) printError(err, fname, "Error", src)
} }
@ -207,7 +207,7 @@ func interact(ev *eval.Evaler, st *store.Store) {
printError(err, "[interactive]", "Parse error", line) printError(err, "[interactive]", "Parse error", line)
if err == nil { if err == nil {
err := ev.Eval(line, n) err := ev.Eval("[interactive]", line, n)
printError(err, "[interactive]", "Exception", line) printError(err, "[interactive]", "Exception", line)
} }
} }