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:
@@ -85,25 +85,6 @@ func (st *frameStack) push(f *pickFrame) int {
|
||||
|
||||
func (st *frameStack) pop(mark int) { st.frames = st.frames[:mark] }
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// scopeAround is the innermost name scope a render of n reads names in, short of the frames n
|
||||
// renders itself, one per iteration of a repeat.
|
||||
func scopeAround(n node) *nameScope {
|
||||
@@ -134,26 +115,6 @@ func (m *drawMemo) enteredFrame(scope *nameScope) *pickFrame {
|
||||
return f
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// readName reads the arm a from the pick of its name, held in the frame of the name's scope.
|
||||
// When the pick renders another category, enter takes that category's frames from the pick's
|
||||
// memo, and renderFrame finds them and opens no new one.
|
||||
@@ -179,20 +140,6 @@ func readName(s *drawstate.State, env renderEnv, a arm) readValue {
|
||||
return r
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// readUnder reads a, an arm of t, once per pick: t renders in env.pick at env.pickAt, and a read of
|
||||
// the name addresses the level a starts at. It keys the value by a's key under env.pickAt.
|
||||
func readUnder(s *drawstate.State, t *template, env renderEnv, a arm) readValue {
|
||||
|
||||
Reference in New Issue
Block a user