DRY level reset in state

This commit is contained in:
lash 2023-03-31 21:18:54 +01:00
parent 5c5e36cdfa
commit b0a3324409
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 28 additions and 24 deletions

View File

@ -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) 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. 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> LOAD <symbol> <size>
RELOAD <symbol> 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. 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: Compiler must croak if:
@ -137,9 +137,7 @@ Compiler must croak if:
should generate warnings if sink cannot render a single enrry (of list) should generate warnings if sink cannot render a single enrry (of list)
MAP <symbol> <maxsize> <minsize> MAP <symbol>
SINK <symbol> <maxsize>
--- ---

View File

@ -64,10 +64,28 @@ func(st *State) PopArg() (string, error) {
func(st *State) Down(input string) { func(st *State) Down(input string) {
m := make(map[string]string) m := make(map[string]string)
st.Cache = append(st.Cache, m) st.Cache = append(st.Cache, m)
st.CacheMap = make(map[string]string)
st.sizes = make(map[string]uint16) st.sizes = make(map[string]uint16)
st.ExecPath = append(st.ExecPath, input) 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 { 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 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() { func(st *State) Reset() {
if len(st.Cache) == 0 { if len(st.Cache) == 0 {
@ -224,3 +225,8 @@ func(st *State) checkCapacity(v string) uint32 {
} }
return sz return sz
} }
func(st *State) resetCurrent() {
st.sink = nil
st.CacheMap = make(map[string]string)
}