ui: make OpPush and OpPop explicit

We're about to allow OpBlock for invoking ops from multiple (cached)
Ops containers. To allow for drawing state changes to stick after
invoking such a cached block, we can't let OpBlock perform an implicit
save and restore of drawing state.

Instead, introduce OpPush and OpPop for explicit drawing state stack
management.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-06-02 15:10:09 +02:00
parent bf5d083b8a
commit 9142345fd4
7 changed files with 28 additions and 20 deletions
+14 -6
View File
@@ -24,8 +24,6 @@ type OpsReader struct {
pc pc
stack []block
ops opsData
pseudoOp [1]byte
}
type block struct {
@@ -73,6 +71,10 @@ var refLengths = [...]int{
ops.TypePopRefs,
}
type OpPush struct{}
type OpPop struct{}
type OpBlock struct {
ops *Ops
pc pc
@@ -82,6 +84,14 @@ type opBlockDef struct {
endpc pc
}
func (p OpPush) Add(o *Ops) {
o.Write([]byte{byte(ops.TypePush)}, nil)
}
func (p OpPop) Add(o *Ops) {
o.Write([]byte{byte(ops.TypePop)}, nil)
}
// Begin a block of ops.
func (o *Ops) Begin() {
o.stack = append(o.stack, o.ops.pc())
@@ -183,8 +193,7 @@ func (r *OpsReader) Decode() ([]byte, []interface{}, bool) {
r.ops = b.ops
r.pc = b.retPC
r.stack = r.stack[:len(r.stack)-1]
r.pseudoOp[0] = byte(ops.TypePop)
return r.pseudoOp[:], nil, true
continue
}
}
if r.pc.data == len(r.ops.data) {
@@ -217,8 +226,7 @@ func (r *OpsReader) Decode() ([]byte, []interface{}, bool) {
r.pc = op.pc
r.pc.data += ops.TypeBlockDefLen
r.pc.refs += ops.TypeBlockDefRefs
r.pseudoOp[0] = byte(ops.TypePush)
return r.pseudoOp[:], nil, true
continue
case ops.TypeBlockDef:
var op opBlockDef
op.decode(data)