Replace direct reference to persistent types with their aliases in eval/vals.

This commit is contained in:
Qi Xiao 2021-12-17 00:21:20 +00:00
parent 82d92ad467
commit 71e5bff8da
8 changed files with 11 additions and 19 deletions

View File

@ -7,7 +7,6 @@ import (
"src.elv.sh/pkg/eval"
"src.elv.sh/pkg/eval/vals"
"src.elv.sh/pkg/parse"
"src.elv.sh/pkg/persistent/hashmap"
"src.elv.sh/pkg/ui"
)
@ -16,7 +15,7 @@ var errValueShouldBeFn = errors.New("value should be function")
// A special Map that converts its key to ui.Key and ensures that its values
// satisfy eval.CallableValue.
type bindingsMap struct {
hashmap.Map
vals.Map
}
var emptyBindingsMap = bindingsMap{vals.EmptyMap}
@ -89,7 +88,7 @@ func (bt bindingsMap) Dissoc(k interface{}) interface{} {
return bindingsMap{bt.Map.Dissoc(key)}
}
func makeBindingMap(raw hashmap.Map) (bindingsMap, error) {
func makeBindingMap(raw vals.Map) (bindingsMap, error) {
converted := vals.EmptyMap
for it := raw.Iterator(); it.HasElem(); it.Next() {
k, v := it.Elem()

View File

@ -10,7 +10,6 @@ import (
"src.elv.sh/pkg/eval/vals"
"src.elv.sh/pkg/getopt"
"src.elv.sh/pkg/parse"
"src.elv.sh/pkg/persistent/hashmap"
)
//elvdoc:fn complete-getopt
@ -236,7 +235,7 @@ func parseGetoptOptSpecs(v interface{}) (parsedOptSpecs, error) {
var err error
errIterate := vals.Iterate(v, func(v interface{}) bool {
m, ok := v.(hashmap.Map)
m, ok := v.(vals.Map)
if !ok {
err = fmt.Errorf("opt should be map, got %s", vals.Kind(v))
return false

View File

@ -5,7 +5,6 @@ import (
"src.elv.sh/pkg/eval"
"src.elv.sh/pkg/eval/vals"
"src.elv.sh/pkg/eval/vars"
"src.elv.sh/pkg/persistent/hashmap"
)
//elvdoc:var abbr
@ -131,7 +130,7 @@ func initInsertAPI(appSpec *cli.AppSpec, nt notifier, ev *eval.Evaler, nb eval.N
func makeMapIterator(mv vars.PtrVar) func(func(a, b string)) {
return func(f func(a, b string)) {
for it := mv.GetRaw().(hashmap.Map).Iterator(); it.HasElem(); it.Next() {
for it := mv.GetRaw().(vals.Map).Iterator(); it.HasElem(); it.Next() {
k, v := it.Elem()
ks, kok := k.(string)
vs, vok := v.(string)

View File

@ -11,7 +11,6 @@ import (
"src.elv.sh/pkg/eval"
"src.elv.sh/pkg/eval/vals"
"src.elv.sh/pkg/eval/vars"
"src.elv.sh/pkg/persistent/hashmap"
"src.elv.sh/pkg/store/storedefs"
)
@ -229,7 +228,7 @@ func adaptToIterateString(variable vars.Var) func(func(string)) {
func adaptToIterateStringPair(variable vars.Var) func(func(string, string) bool) {
return func(f func(a, b string) bool) {
m := variable.Get().(hashmap.Map)
m := variable.Get().(vals.Map)
for it := m.Iterator(); it.HasElem(); it.Next() {
k, v := it.Elem()
ks, kok := k.(string)

View File

@ -10,7 +10,6 @@ import (
"src.elv.sh/pkg/eval/errs"
"src.elv.sh/pkg/eval/vals"
"src.elv.sh/pkg/eval/vars"
"src.elv.sh/pkg/persistent/hashmap"
)
// Sequence, list and maps.
@ -62,7 +61,7 @@ func init() {
// ▶ value
// ```
func nsFn(m hashmap.Map) (*Ns, error) {
func nsFn(m vals.Map) (*Ns, error) {
nb := BuildNs()
for it := m.Iterator(); it.HasElem(); it.Next() {
k, v := it.Elem()
@ -741,7 +740,7 @@ func drop(fm *Frame, n int, inputs Inputs) error {
func hasValue(container, value interface{}) (bool, error) {
switch container := container.(type) {
case hashmap.Map:
case vals.Map:
for it := container.Iterator(); it.HasElem(); it.Next() {
_, v := it.Elem()
if vals.Equal(v, value) {

View File

@ -16,7 +16,6 @@ import (
"src.elv.sh/pkg/eval/vars"
"src.elv.sh/pkg/logutil"
"src.elv.sh/pkg/parse"
"src.elv.sh/pkg/persistent/vector"
)
var logger = logutil.GetLogger("[eval] ")
@ -146,7 +145,7 @@ type Evaler struct {
// NewEvaler creates a new Evaler.
func NewEvaler() *Evaler {
builtin := builtinNs.Ns()
beforeChdirElvish, afterChdirElvish := vector.Empty, vector.Empty
beforeChdirElvish, afterChdirElvish := vals.EmptyList, vals.EmptyList
ev := &Evaler{
global: new(Ns),
@ -186,7 +185,7 @@ func NewEvaler() *Evaler {
return ev
}
func adaptChdirHook(name string, ev *Evaler, pfns *vector.Vector) func(string) {
func adaptChdirHook(name string, ev *Evaler, pfns *vals.List) func(string) {
return func(path string) {
ports, cleanup := PortsFromStdFiles(ev.ValuePrefix())
defer cleanup()

View File

@ -11,7 +11,6 @@ import (
"src.elv.sh/pkg/diag"
"src.elv.sh/pkg/eval/vals"
"src.elv.sh/pkg/persistent/vector"
)
var (
@ -52,7 +51,7 @@ func (envli *envListVar) Get() interface{} {
return envli.cacheValue
}
envli.cacheFor = value
v := vector.Empty
v := vals.EmptyList
for _, path := range strings.Split(value, pathListSeparator) {
v = v.Cons(path)
}

View File

@ -7,7 +7,6 @@ import (
"src.elv.sh/pkg/eval"
"src.elv.sh/pkg/eval/errs"
"src.elv.sh/pkg/eval/vals"
"src.elv.sh/pkg/persistent/vector"
)
// Ns is the namespace for the re: module.
@ -111,7 +110,7 @@ func find(fm *eval.Frame, opts findOpts, argPattern, source string) error {
for _, match := range matches {
start, end := match[0], match[1]
groups := vector.Empty
groups := vals.EmptyList
for i := 0; i < len(match); i += 2 {
start, end := match[i], match[i+1]
text := ""