<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/subexstate.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-07-21 16:42:49 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-07-21 16:42:49 +0100
commitbed0e712deda5038f52e495bacae003098df7a55 (patch)
tree09f3b86927efc6a0cef4f7fdf509c1731cc4b86d /subex/subexstate.go
parentc52794f9d420e319900f27e9f16c8444e8842e92 (diff)
downloadstred-go-bed0e712deda5038f52e495bacae003098df7a55.tar
Reimplements inserting basic values using subexes
Diffstat (limited to 'subex/subexstate.go')
-rw-r--r--subex/subexstate.go43
1 files changed, 34 insertions, 9 deletions
diff --git a/subex/subexstate.go b/subex/subexstate.go
index 7ffd592..0b21c93 100644
--- a/subex/subexstate.go
+++ b/subex/subexstate.go
@@ -121,29 +121,54 @@ func (state SubexStoreEndState) accepting(aux auxiliaryState) []OutputStack {
// A part of an output literal, either an Atom or a slot from which to load
type OutputContent interface {
- // Given the current store, return the []Atom produced by the TransducerOutput
- build(Store) walk.ValueList
+ // Given the current store, return the ValueList produced by the TransducerOutput
+ buildValues(Store) walk.ValueList
+ // Given the current store, return the RuneList produced by the TransducerOutput
+ buildRunes(Store) walk.RuneList
}
-// An OutputContent which is just an Atom literal
-type OutputAtomLiteral struct {
- atom walk.Value
+// An OutputContent which is just a Value literal
+type OutputValueLiteral struct {
+ value walk.Value
}
-func (replacement OutputAtomLiteral) build(store Store) walk.ValueList {
- return walk.ValueList{replacement.atom}
+func (replacement OutputValueLiteral) buildValues(store Store) walk.ValueList {
+ return walk.ValueList{replacement.value}
+}
+func (replacement OutputValueLiteral) buildRunes(store Store) walk.RuneList {
+ // TODO: serialise to JSON
+ panic("Unimplemented!")
+}
+
+// An OutputContent which is just a rune literal
+type OutputRuneLiteral struct {
+ rune walk.StringRuneAtom
+}
+func (replacement OutputRuneLiteral) buildValues(store Store) walk.ValueList {
+ // TODO: Try to deserialise
+ panic("Unimplemented!")
+}
+func (replacement OutputRuneLiteral) buildRunes(store Store) walk.RuneList {
+ return walk.RuneList {replacement.rune}
}
// An OutputContent which is a slot that is loaded from
type OutputLoad struct {
slot int
}
-func (replacement OutputLoad) build(store Store) walk.ValueList {
+func (replacement OutputLoad) buildValues(store Store) walk.ValueList {
values, isValues := store[replacement.slot].(walk.ValueList)
if !isValues {
panic("Tried to output non-values list")
}
return values
}
+func (replacement OutputLoad) buildRunes(store Store) walk.RuneList {
+ runes, isRunes := store[replacement.slot].(walk.RuneList)
+ if !isRunes {
+ panic("Tried to output non-runes as runes")
+ }
+ return runes
+}
// Don't read in anything, just output the series of data and slots specified
type SubexOutputState struct {
@@ -155,7 +180,7 @@ type SubexOutputState struct {
func (state SubexOutputState) build(store Store) walk.ValueList {
var result walk.ValueList
for _, part := range state.content {
- result = append(result, part.build(store)...)
+ result = append(result, part.buildValues(store)...)
}
return result
}