From 8e80185508a697ddfcfed4a04d3f4e1ac5a330a9 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Mon, 24 Apr 2023 13:16:06 +0100 Subject: WalkItems are now made of Atoms instead of WalkValues, and I have rolled my own JSON parser and serialiser These changes improve performance --- main/command.go | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'main/command.go') diff --git a/main/command.go b/main/command.go index a0ac35e..c7b1aa9 100644 --- a/main/command.go +++ b/main/command.go @@ -16,16 +16,7 @@ func (cmd PrintValueCommand) exec(state *ProgramState) { panic("Tried to convert invalid atoms to values") } path := walk.PathFromWalkValues(pathValues) - values, err := walk.Compound(state.value) - if err != nil { - panic("Tried to convert invalid atoms to values") - } - for _, value := range values { - state.out <- walk.WalkItem { - Value: value, - Path: path, - } - } + state.out.Print(path, state.value) } type SequenceCommand struct { @@ -39,16 +30,22 @@ func (cmd SequenceCommand) exec(state *ProgramState) { type NextCommand struct {} func (cmd NextCommand) exec(state *ProgramState) { - nextItem := <- state.in - state.value = walk.Atomise([]walk.WalkValue{nextItem.Value}) - state.path = walk.Atomise(nextItem.Path.ToWalkValues()) + nextItem, err := state.in.Read() + if err != nil { + panic("Missing next value") + } + state.value = nextItem.Value + state.path = nextItem.Path } type AppendNextCommand struct {} func (cmd AppendNextCommand) exec(state *ProgramState) { - nextItem := <- state.in - state.value = append(state.value, walk.Atomise([]walk.WalkValue{nextItem.Value})...) - state.path = walk.Atomise(nextItem.Path.ToWalkValues()) + nextItem, err := state.in.Read() + if err != nil { + panic("Missing next value") + } + state.value = append(state.value, nextItem.Value...) + state.path = nextItem.Path } type DeleteValueCommand struct {} -- cgit v1.2.3