From bacbfcc517c73202ef54f1d855793af38bfcfa02 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Thu, 9 Nov 2023 18:47:31 +0100 Subject: [PATCH] added debug output to Backup() --- calc.go | 4 ++++ calc_test.go | 5 +++++ stack.go | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/calc.go b/calc.go index 7177a2e..82bda08 100644 --- a/calc.go +++ b/calc.go @@ -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() diff --git a/calc_test.go b/calc_test.go index 9ffe0cd..a5e0958 100644 --- a/calc_test.go +++ b/calc_test.go @@ -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 { diff --git a/stack.go b/stack.go index 3d73fd3..c853db0 100644 --- a/stack.go +++ b/stack.go @@ -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 }