Skip to content

Commit

Permalink
Merge pull request #107 from rokostik/serialize-state-part-1
Browse files Browse the repository at this point in the history
Serialize state part 1
  • Loading branch information
refaktor authored Jan 28, 2024
2 parents f16e51a + 3a49ff8 commit 2043d4f
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 0 deletions.
15 changes: 15 additions & 0 deletions env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ func (i RyeCtx) Equal(o Object) bool {
return false
}

func (i RyeCtx) Serialize(e Idxs) string {
var bu strings.Builder
bu.WriteString(fmt.Sprintf("doc \"%s\"\n", i.Doc))
for j := 0; j < e.GetWordCount(); j++ {
if val, ok := i.state[j]; ok {
bu.WriteString(fmt.Sprintf("%s: %s\n", e.GetWord(j), val.Serialize(e)))
}
}
return bu.String()
}

/*func (e *Env) Get(word int) (*Object, bool) {
obj, exists := e.state[word]
// recursively look at outer Environments ...
Expand Down Expand Up @@ -264,6 +275,10 @@ func NewProgramState(ser TSeries, idx *Idxs) *ProgramState {
return &ps
}

func (ps *ProgramState) Serialize() string {
return ps.Ctx.Serialize(*ps.Idx)
}

func AddToProgramState(ps *ProgramState, ser TSeries, idx *Idxs) *ProgramState {
ps.Ser = ser
ps.Res = nil
Expand Down
Loading

0 comments on commit 2043d4f

Please sign in to comment.