From 4cde5179f1339c8646cfb8e0b93b82acf0c1baa2 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Thu, 2 Nov 2023 16:55:12 +0100 Subject: [PATCH] Remove NewScope method from vm.Scope --- vm/function.go | 11 +++-------- vm/scope.go | 9 --------- vm/vm.go | 2 +- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/vm/function.go b/vm/function.go index 5c6a4ad..b331d92 100644 --- a/vm/function.go +++ b/vm/function.go @@ -177,11 +177,7 @@ func FunctionFromGraph(g *gg.Graph, scope Scope) (Function, error) { if edgeVal.Graph != nil { - opFromGraph, err := FunctionFromGraph( - edgeVal.Graph, - scope.NewScope(), - ) - + opFromGraph, err := FunctionFromGraph(edgeVal.Graph, scope) if err != nil { return nil, fmt.Errorf("compiling graph to operation: %w", err) } @@ -198,7 +194,7 @@ func FunctionFromGraph(g *gg.Graph, scope Scope) (Function, error) { })), nil } - // the edgeVal is not an Function at compile time, and so + // the edgeVal is not a Function at compile time, and so // it must become one at runtime. We must resolve edgeVal to an // edgeFn as well (edgeEdgeFn), and then at runtime that is // given the inArg and (hopefully) the resultant Function is @@ -217,8 +213,7 @@ func FunctionFromGraph(g *gg.Graph, scope Scope) (Function, error) { if runtimeEdgeVal.Graph != nil { runtimeFn, err := FunctionFromGraph( - runtimeEdgeVal.Graph, - scope.NewScope(), + runtimeEdgeVal.Graph, scope, ) if err != nil { diff --git a/vm/scope.go b/vm/scope.go index 8150638..b71cdc2 100644 --- a/vm/scope.go +++ b/vm/scope.go @@ -9,10 +9,6 @@ type Scope interface { // Resolve accepts a name and returns an Value. Resolve(string) (Value, error) - - // NewScope returns a new Scope which sub-operations within this Scope - // should use for themselves. - NewScope() Scope } // ScopeMap implements the Scope interface. @@ -33,11 +29,6 @@ func (m ScopeMap) Resolve(name string) (Value, error) { return v, nil } -// NewScope returns the ScopeMap as-is. -func (m ScopeMap) NewScope() Scope { - return m -} - type scopeWith struct { Scope // parent name string diff --git a/vm/vm.go b/vm/vm.go index 4bdd4f0..bbe85da 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -114,7 +114,7 @@ func EvaluateSource(opSrc io.Reader, input Value, scope Scope) (Value, error) { return Value{}, errors.New("value must be a graph") } - fn, err := FunctionFromGraph(v.Value.Graph, scope.NewScope()) + fn, err := FunctionFromGraph(v.Value.Graph, scope) if err != nil { return Value{}, err }