added debug output to Backup()

This commit is contained in:
2023-11-09 18:47:31 +01:00
parent b91e024569
commit bacbfcc517
3 changed files with 13 additions and 0 deletions

View File

@@ -393,6 +393,10 @@ func (c *Calc) DoFuncall(funcname string) error {
return R.Err
}
// don't forget to backup!
c.stack.Backup()
// "pop"
if batch {
// get rid of stack
c.stack.Clear()

View File

@@ -236,6 +236,11 @@ func TestCalc(t *testing.T) {
exp: 2,
batch: true,
},
{
name: "undo",
cmd: `4 4 + undo *`,
exp: 16,
},
}
for _, tt := range tests {

View File

@@ -198,10 +198,14 @@ func (s *Stack) Backup() {
s.mutex.Lock()
defer s.mutex.Unlock()
s.Debug(fmt.Sprintf("backing up %d items from rev %d",
s.linklist.Len(), s.rev))
s.backup = list.List{}
for e := s.linklist.Front(); e != nil; e = e.Next() {
s.backup.PushBack(e.Value.(float64))
}
s.backuprev = s.rev
}