3e8c502550bc87762753ecb03ebaea460fb5e852 — Elias Naur a month ago ae8a377
op: return value StackOp from Push and make Pop use a value receiver

To match Record, we'd like Push to return a value. To do that and
support the one-line

	defer op.Push(ops).Pop()

Pop needs to use a value receiver as well. Drop the active field
and make it so. The field was only a sanity check, a check which is
already done by Ops.stackStack, albeit with a less specific panic.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
1 files changed, 7 insertions(+), 19 deletions(-)

M op/op.go
M op/op.go => op/op.go +7 -19
@@ 100,7 100,6 @@ type Ops struct {
type StackOp struct {
	id      stackID
	macroID int
	active  bool
	ops     *Ops

@@ 158,34 157,23 @@ func (c CallOp) Add(o *Ops) {

// Push (save) the current operations state.
func Push(o *Ops) *StackOp {
	var s StackOp
	return &s

func (s *StackOp) push(o *Ops) {
	if s.active {
		panic("unbalanced push")
func Push(o *Ops) StackOp {
	s := StackOp{
		ops:     o,
		id:      o.stackStack.push(),
		macroID: o.macroStack.currentID,
	s.active = true
	s.ops = o
	s.id = o.stackStack.push()
	s.macroID = o.macroStack.currentID
	data := o.Write(opconst.TypePushLen)
	data[0] = byte(opconst.TypePush)
	return s

// Pop (restore) a previously Pushed operations state.
func (s *StackOp) Pop() {
	if !s.active {
		panic("unbalanced pop")
func (s StackOp) Pop() {
	if s.ops.macroStack.currentID != s.macroID {
		panic("pop in a different macro than push")
	s.active = false
	data := s.ops.Write(opconst.TypePopLen)
	data[0] = byte(opconst.TypePop)