commit b0a3324409eee2a8c52093cb397a6f02790f90ef
parent 5c5e36cdfafa75e56adcc397daa9f8aaefc1b427
Author: lash <dev@holbrook.no>
Date: Fri, 31 Mar 2023 21:18:54 +0100
DRY level reset in state
Diffstat:
2 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/draft.txt b/draft.txt
@@ -68,7 +68,7 @@ include command to refresh (for example reload list render)
parameter symbol may only appear once for all branches (when jumping, a parameter require must originate in same place in tree)
load symbol -> load symbol from this point on up to size.
-reload symbol -> flush symbol before rendering, will fail of not previously required
+reload symbol -> flush symbol before rendering, will fail of not previously required. Will use size from preceding LOAD instruction.
LOAD <symbol> <size>
RELOAD <symbol>
@@ -128,7 +128,7 @@ For symbols having data larger than maxsize, data should be lazily split up to e
Total capacity for mapping is cumulative maxsize. Next param in execution has available up to net capacity after consume.
-May define ONE sink, which consumes all remaining data.
+May define ONE sink, which consumes all remaining data. A sink is a LOAd with size 0
Compiler must croak if:
@@ -137,9 +137,7 @@ Compiler must croak if:
should generate warnings if sink cannot render a single enrry (of list)
-MAP <symbol> <maxsize> <minsize>
-SINK <symbol> <maxsize>
-
+MAP <symbol>
---
diff --git a/go/state/state.go b/go/state/state.go
@@ -64,10 +64,28 @@ func(st *State) PopArg() (string, error) {
func(st *State) Down(input string) {
m := make(map[string]string)
st.Cache = append(st.Cache, m)
- st.CacheMap = make(map[string]string)
st.sizes = make(map[string]uint16)
st.ExecPath = append(st.ExecPath, input)
- st.sink = nil
+ st.resetCurrent()
+}
+
+
+func(st *State) Up() error {
+ l := len(st.Cache)
+ if l == 0 {
+ return fmt.Errorf("exit called beyond top frame")
+ }
+ l -= 1
+ m := st.Cache[l]
+ for k, v := range m {
+ sz := len(v)
+ st.CacheUseSize -= uint32(sz)
+ log.Printf("free frame %v key %v value size %v", l, k, sz)
+ }
+ st.Cache = st.Cache[:l]
+ st.ExecPath = st.ExecPath[:l]
+ st.resetCurrent()
+ return nil
}
func(st *State) Add(key string, value string, sizeHint uint16) error {
@@ -156,23 +174,6 @@ func(st *State) Val(key string) (string, error) {
return r, nil
}
-func(st *State) Up() error {
- l := len(st.Cache)
- if l == 0 {
- return fmt.Errorf("exit called beyond top frame")
- }
- l -= 1
- m := st.Cache[l]
- for k, v := range m {
- sz := len(v)
- st.CacheUseSize -= uint32(sz)
- log.Printf("free frame %v key %v value size %v", l, k, sz)
- }
- st.Cache = st.Cache[:l]
- st.ExecPath = st.ExecPath[:l]
- st.sink = nil
- return nil
-}
func(st *State) Reset() {
if len(st.Cache) == 0 {
@@ -224,3 +225,8 @@ func(st *State) checkCapacity(v string) uint32 {
}
return sz
}
+
+func(st *State) resetCurrent() {
+ st.sink = nil
+ st.CacheMap = make(map[string]string)
+}