Skip to content

Commit

Permalink
add equal function to object
Browse files Browse the repository at this point in the history
  • Loading branch information
rokostik committed Dec 22, 2023
1 parent 0b0147f commit 77d1236
Show file tree
Hide file tree
Showing 8 changed files with 501 additions and 34 deletions.
25 changes: 25 additions & 0 deletions env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,31 @@ func (e RyeCtx) GetWords(idxs Idxs) Block {
return *NewBlock(*NewTSeries(objs))
}

func (i RyeCtx) Equal(o Object) bool {
if i.Type() != o.Type() {
return false
}
oCtx := o.(RyeCtx)
if len(i.state) != len(oCtx.state) {
return false
}
for k, v := range i.state {
if !v.Equal(oCtx.state[k]) {
return false
}
}
if i.Parent != oCtx.Parent {
return false
}
if i.Kind != oCtx.Kind {
return false
}
if i.locked != oCtx.locked {
return false
}
return false
}

/*func (e *Env) Get(word int) (*Object, bool) {
obj, exists := e.state[word]
// recursively look at outer Environments ...
Expand Down
7 changes: 0 additions & 7 deletions env/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,3 @@ func (e *Gen) Set(kind int, word int, val Object) Object {
e.dict[kind][word] = val
return val
}

func (i Builtin) GetKind() int {
return int(BuiltinType)
}

// TODO: Builtin is just temporary ... we need to make something else, that holds natives and user functions. Interface should be the same ...
// would it be better (faster) to have concrete type probably.
Loading

0 comments on commit 77d1236

Please sign in to comment.