<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main/main.go')
-rw-r--r--main/main.go20
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
}