diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2024-03-29 09:49:26 +0000 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2024-03-29 09:49:26 +0000 |
commit | 080a24e894f125d4f1741cfdcba7cb722304d209 (patch) | |
tree | 78c12af110a8a239b6a3b1f828e4f193fcb8cd32 /main/command.go | |
parent | 510a8c95ce112617c33f8dfb865e752db0716cb1 (diff) | |
download | stred-go-080a24e894f125d4f1741cfdcba7cb722304d209.tar |
Completely remove the path space
The new design uses deeply nested values in the value space instead.
Diffstat (limited to 'main/command.go')
-rw-r--r-- | main/command.go | 66 |
1 files changed, 9 insertions, 57 deletions
diff --git a/main/command.go b/main/command.go index 5a898e2..1d089ee 100644 --- a/main/command.go +++ b/main/command.go @@ -13,12 +13,11 @@ type Command interface { type PrintValueCommand struct {} func (cmd PrintValueCommand) exec(state *ProgramState) { - err := state.out.Write(walk.WalkItem { - Path: state.path, - Value: state.value, - }) - if err != nil { - panic("Error while outputting") + for _, value := range state.value { + err := state.out.Write(value) + if err != nil { + panic("Error while outputting") + } } state.pc++ } @@ -32,8 +31,7 @@ func (cmd NextCommand) exec(state *ProgramState) { if err != nil { panic("Missing next value") } - state.value = nextItem.Value - state.path = nextItem.Path + state.value = []walk.Value{nextItem.Value} state.pc++ } func (cmd NextCommand) String() string { @@ -46,8 +44,7 @@ func (cmd AppendNextCommand) exec(state *ProgramState) { if err != nil { panic("Missing next value") } - state.value = append(state.value, nextItem.Value...) - state.path = nextItem.Path + state.value = append(state.value, nextItem.Value) state.pc++ } func (cmd AppendNextCommand) String() string { @@ -63,16 +60,7 @@ func (cmd DeleteValueCommand) String() string { return "d" } -type DeletePathCommand struct {} -func (cmd DeletePathCommand) exec(state *ProgramState) { - state.path = nil - state.pc++ -} -func (cmd DeletePathCommand) String() string { - return "D" -} - -func runSubex(state subex.Transducer, in walk.ValueList) (walk.ValueList, bool) { +func runSubex(state subex.Transducer, in []walk.Value) ([]walk.Value, bool) { out, error := subex.RunTransducer(state, in) if error { return nil, true @@ -96,22 +84,6 @@ func (cmd SubstituteValueCommand) String() string { return "s/.../" } -type SubstitutePathCommand struct { - subex subex.Transducer -} -func (cmd SubstitutePathCommand) exec(state *ProgramState) { - newPath, err := runSubex(cmd.subex, state.path) - if err { - state.pc++ - } else { - state.pc += 2 - state.path = newPath - } -} -func (cmd SubstitutePathCommand) String() string { - return "S/.../" -} - type NoopCommand struct {} func (cmd NoopCommand) exec(state *ProgramState) { state.pc++ @@ -180,26 +152,6 @@ func (cmd AppendZRegCommand) String() string { return "Z" } -type SwapPathCommand struct {} -func (cmd SwapPathCommand) exec(state *ProgramState) { - v := state.value - state.value = state.path - state.path = v - state.pc++ -} -func (cmd SwapPathCommand) String() string { - return "k" -} - -type AppendPathCommand struct {} -func (cmd AppendPathCommand) exec(state *ProgramState) { - state.path = append(state.path, state.value...) - state.pc++ -} -func (cmd AppendPathCommand) String() string { - return "K" -} - type JumpCommand struct { destination int } @@ -220,4 +172,4 @@ func (cmd BranchPlaceholderCommand) exec(state *ProgramState) { } func (cmd BranchPlaceholderCommand) String() string { return fmt.Sprintf("b%c", cmd.label) -}
\ No newline at end of file +} |