Skip to content

Commit

Permalink
update messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-mcgann committed Sep 20, 2024
1 parent babc953 commit d5f4306
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 154 deletions.
12 changes: 6 additions & 6 deletions app/calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,21 @@ func (c *Calc) Raise(err error) {

func (c *Calc) Label() string {
if c.stack.Len() == 0 {
panic(msg.ErrStackEmpty())
panic(msg.ErrStackEmpty)
}
return c.stack.Get(0).Label
}

func (c *Calc) Unit() string {
if c.stack.Len() == 0 {
panic(msg.ErrStackEmpty())
panic(msg.ErrStackEmpty)
}
return c.stack.Get(0).Unit
}

func (c *Calc) SetLabel(label string) {
if c.stack.Len() == 0 {
panic(msg.ErrStackEmpty())
panic(msg.ErrStackEmpty)
}
item := c.stack.Get(0)
item.Label = label
Expand All @@ -119,7 +119,7 @@ func (c *Calc) SetLabel(label string) {

func (c *Calc) SetUnit(unit string) {
if c.stack.Len() == 0 {
panic(msg.ErrStackEmpty())
panic(msg.ErrStackEmpty)
}
item := c.stack.Get(0)
item.Unit = unit
Expand Down Expand Up @@ -150,7 +150,7 @@ func (c *Calc) Reset() {
c.temp.Clear()
clear(c.mem)
clear(c.state)
c.Notify(msg.Reset())
c.Notify(msg.Reset)
}

func (c *Calc) Eval(line string) error {
Expand Down Expand Up @@ -321,5 +321,5 @@ func (c *Calc) errTypeMismatch(op zc.Op) error {
return msg.ErrUnexpectedType(arg.Val())
}
}
return msg.ErrNotEnoughArgs()
return msg.ErrNotEnoughArgs
}
18 changes: 9 additions & 9 deletions app/funcs/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func DivBigInt(c zc.Calc) {
defer zc.BigInt.Recycle(y)

if y.Cmp(&zero) == 0 {
c.Raise(msg.ErrDivisionByZero())
c.Raise(msg.ErrDivisionByZero)
return
}
x.Div(x, y)
Expand All @@ -127,7 +127,7 @@ func DivDecimal(c zc.Calc) {

cond, err := d.Quo(x, x, y)
if cond.DivisionByZero() {
c.Raise(msg.ErrDivisionByZero())
c.Raise(msg.ErrDivisionByZero)
return
}
if err != nil {
Expand All @@ -144,7 +144,7 @@ func DivRat(c zc.Calc) {
defer zc.Rat.Recycle(y)

if y.Cmp(&zero) == 0 {
c.Raise(msg.ErrDivisionByZero())
c.Raise(msg.ErrDivisionByZero)
return
}

Expand All @@ -161,7 +161,7 @@ func DivModBigInt(c zc.Calc) {
defer zc.BigInt.Recycle(y)

if y.Cmp(&zero) == 0 {
c.Raise(msg.ErrDivisionByZero())
c.Raise(msg.ErrDivisionByZero)
return
}
x.DivMod(x, y, m)
Expand Down Expand Up @@ -245,7 +245,7 @@ func ModBigInt(c zc.Calc) {
defer zc.BigInt.Recycle(y)

if y.Cmp(&zero) == 0 {
c.Raise(msg.ErrDivisionByZero())
c.Raise(msg.ErrDivisionByZero)
return
}
x.Mod(x, y)
Expand Down Expand Up @@ -358,7 +358,7 @@ func RemBigInt(c zc.Calc) {
defer zc.BigInt.Recycle(y)

if y.Cmp(&zero) == 0 {
c.Raise(msg.ErrDivisionByZero())
c.Raise(msg.ErrDivisionByZero)
return
}
x.Rem(x, y)
Expand All @@ -372,7 +372,7 @@ func RemDecimal(c zc.Calc) {
defer zc.Decimal.Recycle(y)

if y.IsZero() {
c.Raise(msg.ErrDivisionByZero())
c.Raise(msg.ErrDivisionByZero)
return
}
_, err := d.Rem(x, x, y)
Expand Down Expand Up @@ -484,7 +484,7 @@ func QuoBigInt(c zc.Calc) {
defer zc.BigInt.Recycle(y)

if y.Cmp(&zero) == 0 {
c.Raise(msg.ErrDivisionByZero())
c.Raise(msg.ErrDivisionByZero)
return
}
x.Quo(x, y)
Expand All @@ -500,7 +500,7 @@ func QuoRemBigInt(c zc.Calc) {
defer zc.BigInt.Recycle(y)

if y.Cmp(&zero) == 0 {
c.Raise(msg.ErrDivisionByZero())
c.Raise(msg.ErrDivisionByZero)
return
}
x.QuoRem(x, y, r)
Expand Down
2 changes: 1 addition & 1 deletion app/funcs/dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func DecRat(c zc.Calc) {
d := zc.Decimal.New()
d.SetFloat64(f)
if !exact {
c.Notify(msg.Inexact())
c.Notify(msg.Inexact)
}
zc.Decimal.Push(c, d)
}
Expand Down
6 changes: 3 additions & 3 deletions app/funcs/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func DivBigFloat(c zc.Calc) {
x := zc.BigFloat.Pop(c)

if y.Cmp(&zero) == 0 {
c.Raise(msg.ErrDivisionByZero())
c.Raise(msg.ErrDivisionByZero)
return
}

Expand All @@ -58,7 +58,7 @@ func DivFloat32(c zc.Calc) {
y := zc.Float32.Pop(c)
x := zc.Float32.Pop(c)
if y == 0 {
c.Raise(msg.ErrDivisionByZero())
c.Raise(msg.ErrDivisionByZero)
return
}
zc.Float32.Push(c, x/y)
Expand All @@ -68,7 +68,7 @@ func DivFloat64(c zc.Calc) {
y := zc.Float64.Pop(c)
x := zc.Float64.Pop(c)
if y == 0 {
c.Raise(msg.ErrDivisionByZero())
c.Raise(msg.ErrDivisionByZero)
return
}
zc.Float64.Push(c, x/y)
Expand Down
6 changes: 3 additions & 3 deletions app/funcs/hof.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func Apply(c zc.Calc) {
nArgs := int(zc.Uint32.Pop(c))
opName := zc.String.Pop(c)
if c.Len() < nArgs {
c.Raise(msg.ErrNotEnoughArgs())
c.Raise(msg.ErrNotEnoughArgs)
return
}
var args []string
Expand All @@ -36,7 +36,7 @@ func Filter(c zc.Calc) {
dc.Push(v)
dc.Eval(opName)
if dc.Len() == 0 {
c.Raise(msg.ErrNoReturnValues())
c.Raise(msg.ErrNoReturnValues)
return
}
out := dc.Pop()
Expand All @@ -60,7 +60,7 @@ func Fold(c zc.Calc) {
return
}
if c.Len() >= before {
c.Raise(msg.ErrDoesNotReduce())
c.Raise(msg.ErrDoesNotReduce)
return
}
}
Expand Down
16 changes: 8 additions & 8 deletions app/funcs/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ func Clear(c zc.Calc) {

func Copy(c zc.Calc) {
if c.Len() == 0 {
c.Raise(msg.ErrStackEmpty())
c.Raise(msg.ErrStackEmpty)
return
}
s := zc.DupItems(c.Stack())
t := c.Temp()
t = append(t, s...)
c.SetTemp(t)
c.Notify(msg.Copied())
c.Notify(msg.Copied)
}

func Down(c zc.Calc) {
if c.Len() == 0 {
c.Raise(msg.ErrStackEmpty())
c.Raise(msg.ErrStackEmpty)
return
}
if c.Len() == 1 {
Expand Down Expand Up @@ -67,7 +67,7 @@ func Load(c zc.Calc) {
func Pop(c zc.Calc) {
t := c.Temp()
if len(t) == 0 {
c.Raise(msg.ErrStackEmpty())
c.Raise(msg.ErrStackEmpty)
return
}
l := len(t)
Expand All @@ -80,7 +80,7 @@ func PopAll(c zc.Calc) {
s := c.Stack()
t := c.Temp()
if len(t) == 0 {
c.Raise(msg.ErrStackEmpty())
c.Raise(msg.ErrStackEmpty)
return
}
s = append(s, t...)
Expand All @@ -90,7 +90,7 @@ func PopAll(c zc.Calc) {

func Push(c zc.Calc) {
if c.Len() == 0 {
c.Raise(msg.ErrStackEmpty())
c.Raise(msg.ErrStackEmpty)
return
}
x := c.Pop()
Expand All @@ -101,7 +101,7 @@ func Push(c zc.Calc) {

func PushAll(c zc.Calc) {
if c.Len() == 0 {
c.Raise(msg.ErrStackEmpty())
c.Raise(msg.ErrStackEmpty)
return
}
s := c.Stack()
Expand Down Expand Up @@ -133,7 +133,7 @@ func Size(c zc.Calc) {
func Store(c zc.Calc) {
n := zc.String.Pop(c)
c.Store(n)
c.Notify(msg.Stored())
c.Notify(msg.Stored)
}

func Swap(c zc.Calc) {
Expand Down
2 changes: 1 addition & 1 deletion app/funcs/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func NowSet(c zc.Calc) {
func NowReset(c zc.Calc) {
v := vars.ForTime(c)
v.Now = func() time.Time { return time.Now() }
c.Notify(msg.Reset())
c.Notify(msg.Reset)
}

func SecondsTime(c zc.Calc) {
Expand Down
2 changes: 1 addition & 1 deletion app/repl/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func redo(r *Repl, _ []scan.Token) error {

func reset(r *Repl, _ []scan.Token) error {
r.Calc.Reset()
r.Calc.Notify(msg.Reset())
r.Calc.Notify(msg.Reset)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion math.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func IsFloatErr(c Calc, f float64) bool {
c.Raise(msg.ErrInfinity(1))
return true
case math.IsNaN(f):
c.Raise(msg.ErrNotANumber())
c.Raise(msg.ErrNotANumber)
return true
default:
return false
Expand Down
Loading

0 comments on commit d5f4306

Please sign in to comment.