<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-04-21 15:17:52 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-04-21 15:17:52 +0100
commit45b6fb61a00d7b8ce0a79479329e6817367d97ea (patch)
treeedef8e54f327107d8196b33a23cd7b3b6676e335 /main
parent4b7f7b349e906e4760279273f1c03ad5fa802e25 (diff)
downloadstred-go-45b6fb61a00d7b8ce0a79479329e6817367d97ea.tar
All registers are now lists of atoms instead of lists of values
This is to reduce the amount of translating between them that needs to be done
Diffstat (limited to 'main')
-rw-r--r--main/command.go31
-rw-r--r--main/main.go18
2 files changed, 30 insertions, 19 deletions
diff --git a/main/command.go b/main/command.go
index 136fb26..a0ac35e 100644
--- a/main/command.go
+++ b/main/command.go
@@ -11,8 +11,16 @@ type Command interface {
type PrintValueCommand struct {}
func (cmd PrintValueCommand) exec(state *ProgramState) {
- path := walk.PathFromWalkValues(state.path)
- for _, value := range state.value {
+ pathValues, err := walk.Compound(state.path)
+ if err != nil {
+ 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,
@@ -32,15 +40,15 @@ func (cmd SequenceCommand) exec(state *ProgramState) {
type NextCommand struct {}
func (cmd NextCommand) exec(state *ProgramState) {
nextItem := <- state.in
- state.value = []walk.WalkValue{nextItem.Value}
- state.path = nextItem.Path.ToWalkValues()
+ state.value = walk.Atomise([]walk.WalkValue{nextItem.Value})
+ state.path = walk.Atomise(nextItem.Path.ToWalkValues())
}
type AppendNextCommand struct {}
func (cmd AppendNextCommand) exec(state *ProgramState) {
nextItem := <- state.in
- state.value = append(state.value, nextItem.Value)
- state.path = nextItem.Path.ToWalkValues()
+ state.value = append(state.value, walk.Atomise([]walk.WalkValue{nextItem.Value})...)
+ state.path = walk.Atomise(nextItem.Path.ToWalkValues())
}
type DeleteValueCommand struct {}
@@ -53,17 +61,12 @@ func (cmd DeletePathCommand) exec(state *ProgramState) {
state.path = nil
}
-func runSubex(state subex.SubexState, in []walk.WalkValue) (out []walk.WalkValue, error bool) {
- atomsIn := walk.Atomise(in)
- atomsOut, error := subex.RunTransducer(state, atomsIn)
+func runSubex(state subex.SubexState, in []walk.Atom) (out []walk.Atom, error bool) {
+ atomsOut, error := subex.RunTransducer(state, in)
if error {
return nil, true
}
- valuesOut, err := walk.Compound(atomsOut)
- if err != nil {
- return nil, true
- }
- return valuesOut, false
+ return atomsOut, false
}
type SubstituteValueCommand struct {
diff --git a/main/main.go b/main/main.go
index 923ffa6..564d14a 100644
--- a/main/main.go
+++ b/main/main.go
@@ -9,7 +9,7 @@ import (
type Program []Command
type ProgramState struct {
- path, value, xreg []walk.WalkValue
+ path, value, xreg []walk.Atom
in chan walk.WalkItem
out chan walk.WalkItem
program []Command
@@ -50,14 +50,22 @@ func main() {
go func () {
for walkItem := range dataStream {
- state.value = []walk.WalkValue{walkItem.Value}
- state.path = walkItem.Path.ToWalkValues()
+ state.value = walk.Atomise([]walk.WalkValue{walkItem.Value})
+ state.path = walk.Atomise(walkItem.Path.ToWalkValues())
for _, cmd := range state.program {
cmd.exec(&state)
}
if !quiet {
- path := walk.PathFromWalkValues(state.path)
- for _, value := range state.value {
+ pathValues, err := walk.Compound(state.path)
+ if err != nil {
+ 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,