Skip to content

Commit

Permalink
rename unary + (Gop_Pos => Gop_Dup)
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Apr 23, 2022
1 parent 237212e commit 8a91b24
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
21 changes: 6 additions & 15 deletions builtin/ng/big.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ func (a Bigint) IsNil() bool {
return a.Int == nil
}

// Gop_Assign: func (a bigint) = (b bigint)
func (a Bigint) Gop_Assign(b Bigint) {
if Gop_istmp(b) {
*a.Int = *b.Int
} else {
a.Int.Set(b.Int)
}
}

// Gop_Add: func (a bigint) + (b bigint) bigint
func (a Bigint) Gop_Add(b Bigint) Bigint {
return Bigint{tmpint(a, b).Add(a.Int, b.Int)}
Expand Down Expand Up @@ -179,9 +170,9 @@ func (a Bigint) Gop_Neg() Bigint {
return Bigint{tmpint1(a).Neg(a.Int)}
}

// Gop_Pos: func +(a bigint) bigint
func (a Bigint) Gop_Pos() Bigint {
return a
// Gop_Dup: func +(a bigint) bigint
func (a Bigint) Gop_Dup() Bigint {
return Bigint{new(big.Int).Set(a.Int)}
}

// Gop_Not: func ^(a bigint) bigint
Expand Down Expand Up @@ -397,9 +388,9 @@ func (a Bigrat) Gop_Neg() Bigrat {
return Bigrat{tmprat1(a).Neg(a.Rat)}
}

// Gop_Pos: func +(a bigrat) bigrat
func (a Bigrat) Gop_Pos() Bigrat {
return a
// Gop_Dup: func +(a bigrat) bigrat
func (a Bigrat) Gop_Dup() Bigrat {
return Bigrat{new(big.Rat).Set(a.Rat)}
}

// Gop_Inv: func /(a bigrat) bigrat
Expand Down
4 changes: 4 additions & 0 deletions builtin/ng/int128.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ func (i Int128) Gop_Neg() (v Int128) {
return v
}

func (i Int128) Gop_Dup() (v Int128) {
return i
}

// Abs returns the absolute value of i as a signed integer.
func (i Int128) Abs__0() Int128 {
if i.hi&signBit != 0 {
Expand Down
4 changes: 4 additions & 0 deletions builtin/ng/uint128.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ func (u Uint128) Cmp__0(n uint64) int {
return 0
}

func (u Uint128) Gop_Dup() (v Uint128) {
return u
}

func (u Uint128) Gop_Inc() (v Uint128) {
var carry uint64
v.lo, carry = bits.Add64(u.lo, 1, 0)
Expand Down
3 changes: 1 addition & 2 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,6 @@ var binaryGopNames = map[string]string{
"<<=": "Gop_LshAssign",
">>=": "Gop_RshAssign",
"&^=": "Gop_AndNotAssign",
"=": "Gop_Assign",

"==": "Gop_EQ",
"!=": "Gop_NE",
Expand All @@ -798,7 +797,7 @@ var unaryGopNames = map[string]string{
"++": "Gop_Inc",
"--": "Gop_Dec",
"-": "Gop_Neg",
"+": "Gop_Pos",
"+": "Gop_Dup",
"^": "Gop_Not",
"!": "Gop_LNot",
"<-": "Gop_Recv",
Expand Down
6 changes: 3 additions & 3 deletions cl/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ const (
testType_println_code, testType_println_ret = `
{
var x $(type) = 1
println x
println x, +x
}
`, `1
`, `1 1
`
testType_init_code, testType_init_ret = `
{
Expand Down Expand Up @@ -168,7 +168,7 @@ const (
)

func TestUint128_run(t *testing.T) {
testRunType(t, "uint128", testType_all_code, testType_all_ret)
testRunType(t, "uint128", testType_println_code, testType_println_ret)
}

func TestInt128_run(t *testing.T) {
Expand Down

0 comments on commit 8a91b24

Please sign in to comment.