1// compile
2
3// Copyright 2020 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7package p
8
9type Symbol interface{}
10
11type Value interface {
12	String() string
13}
14
15type Object interface {
16	String() string
17}
18
19type Scope struct {
20	outer *Scope
21	elems map[string]Object
22}
23
24func (s *Scope) findouter(name string) (*Scope, Object) {
25	return s.outer.findouter(name)
26}
27
28func (s *Scope) Resolve(name string) (sym Symbol) {
29	if _, obj := s.findouter(name); obj != nil {
30		sym = obj.(Symbol)
31	}
32	return
33}
34
35type ScopeName struct {
36	scope *Scope
37}
38
39func (n *ScopeName) Get(name string) (Value, error) {
40	return n.scope.Resolve(name).(Value), nil
41}
42