Skip to content

Commit

Permalink
move messages to msg package
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-mcgann committed Sep 19, 2024
1 parent 7d04a0c commit babc953
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (c *Calc) Reset() {
c.temp.Clear()
clear(c.mem)
clear(c.state)
c.Notify("reset")
c.Notify(msg.Reset())
}

func (c *Calc) Eval(line string) error {
Expand Down
8 changes: 4 additions & 4 deletions app/funcs/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ func DivModBigInt(c zc.Calc) {
}
x.DivMod(x, y, m)
zc.BigInt.Push(c, x)
c.SetLabel("quo")
c.SetLabel(msg.Quo)
zc.BigInt.Push(c, m)
c.SetLabel("mod")
c.SetLabel(msg.Mod)
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -505,7 +505,7 @@ func QuoRemBigInt(c zc.Calc) {
}
x.QuoRem(x, y, r)
zc.BigInt.Push(c, x)
c.SetLabel("quo")
c.SetLabel(msg.Quo)
zc.BigInt.Push(c, r)
c.SetLabel("rem")
c.SetLabel(msg.Rem)
}
2 changes: 1 addition & 1 deletion app/funcs/dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func RoundingModeSet(c zc.Calc) {
c.Raise(msg.ErrInvalidArg(err.Error()))
return
}
c.Notify("rounding mode set to %v", mode)
c.Notify(msg.RoundingModeSet(mode))
}

func RoundingModeGet(c zc.Calc) {
Expand Down
2 changes: 1 addition & 1 deletion app/funcs/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func PrecFloat(c zc.Calc) {
func PrecFloatGet(c zc.Calc) {
v := vars.ForFloat(c)
zc.Uint.Push(c, v.Prec)
c.SetLabel(msg.Precision())
c.SetLabel(msg.Precision)
}

func SignBigFloat(c zc.Calc) {
Expand Down
3 changes: 2 additions & 1 deletion app/funcs/geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/blackchip-org/zc/v6"
"github.com/blackchip-org/zc/v6/ext"
"github.com/blackchip-org/zc/v6/msg"
)

const EarthRadius = 6371000
Expand Down Expand Up @@ -47,7 +48,7 @@ func Haversine(c zc.Calc) {
r0 := EarthRadius * c0

zc.Float64.Push(c, r0)
c.SetUnit("m")
c.SetUnit(msg.Meters)
}

func Proj(c zc.Calc) {
Expand Down
2 changes: 1 addition & 1 deletion app/funcs/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func RandSeed(c zc.Calc) {
v.Seed = zc.BigInt.Pop(c)
lo, hi := v.SplitSeed()
v.Source.Seed(lo, hi)
c.Notify("seed set to %v", v.Seed)
c.Notify(msg.SeedSet(v.Seed))
}

func RandSeedGet(c zc.Calc) {
Expand Down
4 changes: 2 additions & 2 deletions app/funcs/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Copy(c zc.Calc) {
t := c.Temp()
t = append(t, s...)
c.SetTemp(t)
c.Notify("copied")
c.Notify(msg.Copied())
}

func Down(c zc.Calc) {
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("stored")
c.Notify(msg.Stored())
}

func Swap(c zc.Calc) {
Expand Down
14 changes: 7 additions & 7 deletions app/funcs/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ func DayYear(c zc.Calc) {
func Hours(c zc.Calc) {
x := zc.Duration.Pop(c)
zc.Float64.Push(c, x.Hours())
c.SetUnit("h")
c.SetUnit(msg.Hours)
}

func LocalZone(c zc.Calc) {
v := vars.ForTime(c)
zc.String.Push(c, v.ZoneName)
c.SetLabel("time zone")
c.SetLabel(msg.TimeZone)
}

func LocalZoneSet(c zc.Calc) {
Expand All @@ -85,13 +85,13 @@ func LocalZoneSet(c zc.Calc) {
}
v.Zone = loc
v.ZoneName = zone
c.Notify("local time zone is now %v", msg.Quote(v.ZoneName))
c.Notify(msg.LocalTimeZoneSet(zone))
}

func MinutesTime(c zc.Calc) {
x := zc.Duration.Pop(c)
zc.Float64.Push(c, x.Minutes())
c.SetUnit("m")
c.SetUnit(msg.Meters)
}

func Now(c zc.Calc) {
Expand All @@ -103,19 +103,19 @@ func NowSet(c zc.Calc) {
v := vars.ForTime(c)
x := zc.DateTime.Pop(c)
v.Now = func() time.Time { return x.In(v.Zone) }
c.Notify("now set to %v", msg.Quote(zc.DateTime.Format(c, x)))
c.Notify(msg.NowSet(zc.DateTime.Format(c, x)))
}

func NowReset(c zc.Calc) {
v := vars.ForTime(c)
v.Now = func() time.Time { return time.Now() }
c.Notify("now reset")
c.Notify(msg.Reset())
}

func SecondsTime(c zc.Calc) {
x := zc.Duration.Pop(c)
zc.Float64.Push(c, x.Seconds())
c.SetUnit("s")
c.SetUnit(msg.Seconds)
}

func SubDuration(c zc.Calc) {
Expand Down
3 changes: 2 additions & 1 deletion app/repl/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/blackchip-org/scan"
"github.com/blackchip-org/zc/v6"
"github.com/blackchip-org/zc/v6/msg"
)

type Cmd func(*Repl, []scan.Token) error
Expand Down Expand Up @@ -77,7 +78,7 @@ func redo(r *Repl, _ []scan.Token) error {

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

Expand Down
15 changes: 8 additions & 7 deletions msg/label.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package msg

func Data() string {
return "data"
}

func Precision() string {
return "precision"
}
var (
Data = "data"
Mod = "mod"
Precision = "precision"
Quo = "quo"
Rem = "rem"
TimeZone = "time zone"
)
37 changes: 34 additions & 3 deletions msg/notice.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
package msg

import "fmt"
import (
"fmt"
"math/big"
)

func PrecisionSet(p uint) string {
return fmt.Sprintf("precision set to %v", p)
func Copied() string {
return "copied"
}

func Inexact() string {
return "inexact"
}

func LocalTimeZoneSet(z string) string {
return fmt.Sprintf("local time zone is now %v", z)
}

func NowSet(dt string) string {
return fmt.Sprintf("now set to %v", Quote(dt))
}

func PrecisionSet(p uint) string {
return fmt.Sprintf("precision set to %v", p)
}

func RoundingModeSet(m string) string {
return fmt.Sprintf("rounding mode set to %v", m)
}

func Reset() string {
return "reset"
}

func SeedSet(s *big.Int) string {
return fmt.Sprintf("seed set to %v", s)
}

func Stored() string {
return "stored"
}
8 changes: 8 additions & 0 deletions msg/unit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package msg

var (
Hours = "h"
Meters = "m"
Minutes = "m"
Seconds = "s"
)
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func (t DataType) As(a any) *bytes.Buffer {

func (t DataType) Push(c Calc, val *bytes.Buffer) {
c.Push(Item{TypeVal: val, Type: t})
c.SetLabel(msg.Data())
c.SetLabel(msg.Data)
}

func (t DataType) Pop(c Calc) *bytes.Buffer {
Expand Down

0 comments on commit babc953

Please sign in to comment.