forked from glycerine/zygomys
/
closing.go
45 lines (37 loc) · 1.16 KB
/
closing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package zygo
// where we store our closure-supporing stack pointers
type Closing struct {
Stack *Stack
Name string
env *Zlisp
}
func NewClosing(name string, env *Zlisp) *Closing {
stk := env.linearstack.Clone()
// be super strict: only store up to our
// enclosing function definition, because after
// that, the definition time of that function
// should be what we use.
return &Closing{
Stack: stk,
Name: name,
env: env}
}
func NewEmptyClosing(name string, env *Zlisp) *Closing {
return &Closing{
Stack: env.NewStack(0),
Name: name,
env: env}
}
func (c *Closing) IsStackElem() {}
func (c *Closing) LookupSymbolUntilFunction(sym *SexpSymbol, setVal *Sexp, maximumFuncToSearch int, checkCaptures bool) (Sexp, error, *Scope) {
return c.Stack.LookupSymbolUntilFunction(sym, setVal, maximumFuncToSearch, checkCaptures)
}
func (c *Closing) LookupSymbol(sym *SexpSymbol, setVal *Sexp) (Sexp, error, *Scope) {
return c.Stack.LookupSymbol(sym, setVal)
}
func (c *Closing) Show(env *Zlisp, ps *PrintState, label string) (string, error) {
return c.Stack.Show(env, ps, label)
}
func (c *Closing) TopScope() *Scope {
return c.Stack.GetTop().(*Scope)
}