Move renderEnv's methods into env.go, a table's route and draw steps into table.go, and the compiled read into arm.go

This commit is contained in:
2026-10-07 01:06:51 +02:00
committed by Lillem4n
parent d0886e4795
commit 0e3c986801
7 changed files with 320 additions and 306 deletions
+57 -1
View File
@@ -1,6 +1,9 @@
package fejkdata
import "github.com/larvit/fejkdata/internal/invariant"
import (
"github.com/larvit/fejkdata/internal/drawstate"
"github.com/larvit/fejkdata/internal/invariant"
)
// readValue is what one read drew: its text, and whether it landed on a null.
type readValue struct {
@@ -47,3 +50,56 @@ func (env renderEnv) rowOf(t *table) int {
}
return env.row.index
}
// enter starts a read landing on n: the read sees no frame opened before it, and gets a frame for
// each name scope around n, from memo where there is one, so reads sharing memo read one pick of
// each name. It returns the mark that closes those frames.
func (env renderEnv) enter(n node, memo *drawMemo) (renderEnv, int) {
env = env.entering()
for scope := scopeAround(n); scope != nil; scope = scope.up {
if len(scope.order) > 0 {
env.frames.push(memo.enteredFrame(scope))
}
}
return env, env.base
}
// entering is env as a read entering a category sees it: no frame opened before it, and no pick.
func (env renderEnv) entering() renderEnv {
env.base, env.pick = len(env.frames.frames), nil
return env
}
// renderFrame opens a fresh frame of t's scope, where t binds names and no read entering the
// category opened one, returning the mark that closes it, or -1.
func (env renderEnv) renderFrame(t *template) int {
own := t.ownScope()
if own == nil || env.frameOf(own) != nil {
return -1
}
return env.frames.push(newPickFrame(own))
}
// frameOf is the frame of scope rendering since the read entering the category, nil where none is.
func (env renderEnv) frameOf(scope *nameScope) *pickFrame {
for i := len(env.frames.frames) - 1; i >= env.base; i-- {
if f := env.frames.frames[i]; f.scope == scope {
return f
}
}
return nil
}
// drawRowOf draws the row a render of t reads: inside the pick's rows where t renders as part of one.
func (env renderEnv) drawRowOf(s *drawstate.State, t *table) int {
if env.pick != nil {
return t.rows.DrawIn(s, &env.pick.pins)
}
return t.rows.Draw(s)
}
// keeps reports whether a read of env's name addresses the level a starts at.
func (env renderEnv) keeps(a arm) bool {
_, kept := env.pick.named.addressed[env.pickAt.under(a.levels[0])]
return kept
}