EvalCtx.context -> .name

This commit is contained in:
Qi Xiao 2016-10-13 21:51:51 +08:00
parent 0c3995f8c0
commit db1c12cb48
3 changed files with 12 additions and 12 deletions

View File

@ -197,8 +197,8 @@ func use(ec *EvalCtx, modname string, pfilename *string) {
// TODO(xiaq): Should handle failures when evaluting the module // TODO(xiaq): Should handle failures when evaluting the module
newEc := &EvalCtx{ newEc := &EvalCtx{
ec.Evaler, ec.Evaler, "module " + modname,
filename, source, "module " + modname, filename, source,
local, Namespace{}, local, Namespace{},
ec.ports, nil, true, ec.ports, nil, true,
0, len(source), ec.addTraceback(), 0, len(source), ec.addTraceback(),

View File

@ -74,6 +74,6 @@ func (c *Closure) Call(ec *EvalCtx, args []Value, opts map[string]Value) {
ec.traceback = ec.addTraceback() ec.traceback = ec.addTraceback()
ec.name, ec.text = c.SourceName, c.Source ec.srcName, ec.src = c.SourceName, c.Source
c.Op.Exec(ec) c.Op.Exec(ec)
} }

View File

@ -45,10 +45,10 @@ type Evaler struct {
} }
// EvalCtx maintains an Evaler along with its runtime context. After creation // EvalCtx maintains an Evaler along with its runtime context. After creation
// an EvalCtx is not modified, and new instances are created when needed. // an EvalCtx is seldom modified, and new instances are created when needed.
type EvalCtx struct { type EvalCtx struct {
*Evaler *Evaler
name, text, context string name, srcName, src string
local, up Namespace local, up Namespace
ports []*Port ports []*Port
@ -86,24 +86,24 @@ const (
// NewTopEvalCtx creates a top-level evalCtx. // NewTopEvalCtx creates a top-level evalCtx.
func NewTopEvalCtx(ev *Evaler, name, text string, ports []*Port) *EvalCtx { func NewTopEvalCtx(ev *Evaler, name, text string, ports []*Port) *EvalCtx {
return &EvalCtx{ return &EvalCtx{
ev, ev, "top",
name, text, "top", name, text,
ev.Global, Namespace{}, ev.Global, Namespace{},
ports, nil, true, ports, nil, true,
0, len(text), nil, 0, len(text), nil,
} }
} }
// fork returns a modified copy of ec. The ports are forked, and the context is // fork returns a modified copy of ec. The ports are forked, and the name is
// changed to the given value. Other fields are copied shallowly. // changed to the given value. Other fields are copied shallowly.
func (ec *EvalCtx) fork(newContext string) *EvalCtx { func (ec *EvalCtx) fork(name string) *EvalCtx {
newPorts := make([]*Port, len(ec.ports)) newPorts := make([]*Port, len(ec.ports))
for i, p := range ec.ports { for i, p := range ec.ports {
newPorts[i] = p.Fork() newPorts[i] = p.Fork()
} }
return &EvalCtx{ return &EvalCtx{
ec.Evaler, ec.Evaler, name,
ec.name, ec.text, newContext, ec.srcName, ec.src,
ec.local, ec.up, ec.local, ec.up,
newPorts, ec.positionals, true, newPorts, ec.positionals, true,
ec.begin, ec.end, ec.traceback, ec.begin, ec.end, ec.traceback,
@ -305,7 +305,7 @@ func (ec *EvalCtx) makeTracebackError(e error) *util.TracebackError {
func (ec *EvalCtx) addTraceback() *util.Traceback { func (ec *EvalCtx) addTraceback() *util.Traceback {
return &util.Traceback{ return &util.Traceback{
Name: ec.name, Source: ec.text, Name: ec.srcName, Source: ec.src,
Begin: ec.begin, End: ec.end, Next: ec.traceback, Begin: ec.begin, End: ec.end, Next: ec.traceback,
} }
} }