diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2024-04-21 17:16:01 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2024-04-21 17:16:01 +0100 |
commit | 1e66aaece6ea7cd3c705ca56ce5558e8f87681b8 (patch) | |
tree | 2fff87e4abfb0727e028854c006577eccfeee370 /main/main.go | |
parent | 7162ae8c641314846f0b565d7614ac8d71dbd628 (diff) | |
download | stred-go-1e66aaece6ea7cd3c705ca56ce5558e8f87681b8.tar |
Add substitute next commands
Diffstat (limited to 'main/main.go')
-rw-r--r-- | main/main.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/main/main.go b/main/main.go index 3fb1cbf..47bcddb 100644 --- a/main/main.go +++ b/main/main.go @@ -11,11 +11,29 @@ import ( type ProgramState struct { value, xreg, yreg, zreg []walk.Value start, prevStart, end, nextEnd bool + // TODO: This will only ever have 0 or 1 values, it is a slice out of laziness + peekStack []walk.WalkItem in walk.StredReader out walk.StredWriter program []Command pc int } +func (state *ProgramState) Read() (walk.WalkItem, error) { + if len(state.peekStack) > 0 { + item := state.peekStack[len(state.peekStack) - 1] + state.peekStack = state.peekStack[:len(state.peekStack) - 1] + return item, nil + } + return state.in.Read() +} +func (state *ProgramState) Peek() (walk.WalkItem, error) { + item, err := state.Read() + if err != nil { + return walk.WalkItem{}, err + } + state.peekStack = append(state.peekStack, item) + return item, nil +} type config struct { quiet bool @@ -38,7 +56,7 @@ func run(config config) { } for { - walkItem, err := state.in.Read() + walkItem, err := state.Read() if err != nil { break } |