From 6ddc71c0ba77217b518c586dc8589d627c92ebfb Mon Sep 17 00:00:00 2001 From: alandonovan Date: Tue, 4 Jun 2019 09:08:55 -0400 Subject: resolve: move resolver types to resolver package (#211) The job of the resolver is to compute a binding for each identifer, the local and free variables for each function, and the locals and globals for each module. As a space optimization and for convenience, this information is saved in the syntax tree rather than in a side table. We have a choice between declaring these resolver data structures in the syntax package or the resolve package. Putting them in the syntax package, as we did prior to this change, allowed each Identifier, File, DefStmt, and LambdaExpr to depend directly on the resolver types, even though those types didn't really belong there. This change moves these types to the resolver package where they belong. The dependencies on the types are broken by using an interface{} in each case. (The values are are all pointers, so this does not induce new allocation.) Also, this change eliminates syntax.Function, which was a false abstraction of DefStmt and LambdaExpr. The two syntax nodes are now fully concrete; it is in the resolver that their shared concept of Function belongs. This is a breaking API change, but it should affect very few clients and be trivial to fix. --- starlarkstruct/struct_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'starlarkstruct') diff --git a/starlarkstruct/struct_test.go b/starlarkstruct/struct_test.go index 81936a9..8e6a93d 100644 --- a/starlarkstruct/struct_test.go +++ b/starlarkstruct/struct_test.go @@ -9,8 +9,8 @@ import ( "path/filepath" "testing" - "go.starlark.net/starlark" "go.starlark.net/resolve" + "go.starlark.net/starlark" "go.starlark.net/starlarkstruct" "go.starlark.net/starlarktest" ) @@ -67,7 +67,7 @@ func (sym *symbol) Name() string { return sym.name } func (sym *symbol) String() string { return sym.name } func (sym *symbol) Type() string { return "symbol" } func (sym *symbol) Freeze() {} // immutable -func (sym *symbol) Truth() starlark.Bool { return starlark.True } +func (sym *symbol) Truth() starlark.Bool { return starlark.True } func (sym *symbol) Hash() (uint32, error) { return 0, fmt.Errorf("unhashable: %s", sym.Type()) } func (sym *symbol) CallInternal(thread *starlark.Thread, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) { -- cgit v1.2.3