closing.go 1.2 KB

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