op,internal/ops: support CallOps without macros

A recorded macro is prefixed with an internal macro op that stores
the end of the macro. The end is used to efficiently skip the macro
when not calling it. The call a macro, the CallOp stores the start
position of the macro.

To support seamless wrapping of Ops lists, this change removes the
dependency on the macro op prefix from CallOp. Internal code can
now call an Ops like this:

    var ops op.Ops
    var wrapper op.Ops

    ops.AddCall(&wrapper.Internal, &ops.Internal, ops.PC{}, ops.PCFor(&ops.Internal))

References: https://todo.sr.ht/~eliasnaur/gio/318
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-01-20 09:50:25 +01:00
parent c0f3ec88e9
commit 65199a2274
3 changed files with 32 additions and 25 deletions
+4 -2
View File
@@ -119,7 +119,7 @@ const (
const (
TypeMacroLen = 1 + 4 + 4
TypeCallLen = 1 + 4 + 4
TypeCallLen = 1 + 4 + 4 + 4 + 4
TypeDeferLen = 1
TypePushTransformLen = 1 + 4*6
TypeTransformLen = 1 + 1 + 4*6
@@ -240,12 +240,14 @@ func FillMacro(o *Ops, startPC PC) {
bo.PutUint32(data[5:], uint32(pc.refs))
}
func AddCall(o *Ops, callOps *Ops, pc PC) {
func AddCall(o *Ops, callOps *Ops, pc PC, end PC) {
data := Write1(o, TypeCallLen, callOps)
data[0] = byte(TypeCall)
bo := binary.LittleEndian
bo.PutUint32(data[1:], uint32(pc.data))
bo.PutUint32(data[5:], uint32(pc.refs))
bo.PutUint32(data[9:], uint32(end.data))
bo.PutUint32(data[13:], uint32(end.refs))
}
func PushOp(o *Ops, kind StackKind) (StackID, int) {