2020-11-14 21:09:54 +00:00
|
|
|
/*
|
|
|
|
Serene --- Yet an other Lisp
|
|
|
|
|
|
|
|
Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-11-15 22:16:48 +00:00
|
|
|
package core
|
2020-11-14 21:09:54 +00:00
|
|
|
|
|
|
|
type INamespace interface {
|
|
|
|
DefineGlobal()
|
|
|
|
LookupGlobal()
|
2020-11-15 22:16:48 +00:00
|
|
|
GetRootScope() IScope
|
2020-11-14 21:09:54 +00:00
|
|
|
// return the fully qualified name of the namespace
|
|
|
|
GetName() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Namespace struct {
|
|
|
|
name string
|
2020-11-15 22:16:48 +00:00
|
|
|
rootScope Scope
|
2020-11-14 21:09:54 +00:00
|
|
|
source string
|
|
|
|
externals map[string]Namespace
|
|
|
|
}
|
|
|
|
|
2020-11-15 22:16:48 +00:00
|
|
|
func (n *Namespace) DefineGlobal(k string, v IExpr, public bool) {
|
2020-11-15 21:38:09 +00:00
|
|
|
n.rootScope.Insert(k, v, public)
|
|
|
|
}
|
2020-11-14 21:09:54 +00:00
|
|
|
|
|
|
|
func (n *Namespace) LookupGlobal() {}
|
|
|
|
|
2020-11-15 22:16:48 +00:00
|
|
|
func (n *Namespace) GetRootScope() IScope {
|
2020-11-14 21:09:54 +00:00
|
|
|
return &n.rootScope
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Namespace) GetName() string {
|
|
|
|
return n.name
|
|
|
|
}
|
|
|
|
|
|
|
|
func MakeNS(name string, source string) Namespace {
|
|
|
|
return Namespace{
|
|
|
|
name: name,
|
2020-11-15 22:16:48 +00:00
|
|
|
rootScope: MakeScope(nil),
|
2020-11-14 21:09:54 +00:00
|
|
|
source: source,
|
|
|
|
externals: map[string]Namespace{},
|
|
|
|
}
|
|
|
|
}
|