mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
op: assume aux ops are always wrapped by a macro
Shaves off a length, and prepares for further simplification. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -44,7 +44,7 @@ const (
|
|||||||
TypeHideInputLen = 1
|
TypeHideInputLen = 1
|
||||||
TypePushLen = 1
|
TypePushLen = 1
|
||||||
TypePopLen = 1
|
TypePopLen = 1
|
||||||
TypeAuxLen = 1 + 4
|
TypeAuxLen = 1
|
||||||
TypeClipLen = 1 + 4*4
|
TypeClipLen = 1 + 4*4
|
||||||
TypeProfileLen = 1
|
TypeProfileLen = 1
|
||||||
)
|
)
|
||||||
|
|||||||
+4
-17
@@ -53,10 +53,6 @@ type opMacroDef struct {
|
|||||||
endpc pc
|
endpc pc
|
||||||
}
|
}
|
||||||
|
|
||||||
type opAux struct {
|
|
||||||
len int
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset start reading from the op list.
|
// Reset start reading from the op list.
|
||||||
func (r *Reader) Reset(ops *op.Ops) {
|
func (r *Reader) Reset(ops *op.Ops) {
|
||||||
r.stack = r.stack[:0]
|
r.stack = r.stack[:0]
|
||||||
@@ -93,9 +89,10 @@ func (r *Reader) Decode() (EncodedOp, bool) {
|
|||||||
refs = refs[:nrefs]
|
refs = refs[:nrefs]
|
||||||
switch t {
|
switch t {
|
||||||
case opconst.TypeAux:
|
case opconst.TypeAux:
|
||||||
var op opAux
|
// An Aux operations is always wrapped in a macro, and
|
||||||
op.decode(data)
|
// its length is the remaining space.
|
||||||
n += op.len
|
block := r.stack[len(r.stack)-1]
|
||||||
|
n += block.endPC.data - r.pc.data - opconst.TypeAuxLen
|
||||||
data = data[:n]
|
data = data[:n]
|
||||||
case opconst.TypeMacro:
|
case opconst.TypeMacro:
|
||||||
var op macroOp
|
var op macroOp
|
||||||
@@ -151,16 +148,6 @@ func (op *opMacroDef) decode(data []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (op *opAux) decode(data []byte) {
|
|
||||||
if opconst.OpType(data[0]) != opconst.TypeAux {
|
|
||||||
panic("invalid op")
|
|
||||||
}
|
|
||||||
bo := binary.LittleEndian
|
|
||||||
*op = opAux{
|
|
||||||
len: int(int32(bo.Uint32(data[1:]))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *macroOp) decode(data []byte, refs []interface{}) {
|
func (m *macroOp) decode(data []byte, refs []interface{}) {
|
||||||
if opconst.OpType(data[0]) != opconst.TypeMacro {
|
if opconst.OpType(data[0]) != opconst.TypeMacro {
|
||||||
panic("invalid op")
|
panic("invalid op")
|
||||||
|
|||||||
@@ -216,12 +216,7 @@ func (o *Ops) Write(op []byte, refs ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *Ops) endAux() {
|
func (o *Ops) endAux() {
|
||||||
if !o.inAux {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
o.inAux = false
|
o.inAux = false
|
||||||
bo := binary.LittleEndian
|
|
||||||
bo.PutUint32(o.data[o.auxOff+1:], uint32(o.auxLen))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Ops) pc() pc {
|
func (o *Ops) pc() pc {
|
||||||
|
|||||||
Reference in New Issue
Block a user