Skip to content

Commit

Permalink
merge with main online
Browse files Browse the repository at this point in the history
  • Loading branch information
refaktor committed May 15, 2024
2 parents 866ce7e + 48009d9 commit 3f25ac4
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
cache: false

- name: golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v5
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
actions: read # To read the workflow path.
id-token: write # To sign the provenance.
contents: write # To add assets to a release.
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.10.0
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.0.0
with:
base64-subjects: "${{ needs.goreleaser.outputs.hashes }}"
upload-assets: true # upload to a new release
Expand All @@ -84,7 +84,7 @@ jobs:
actions: read
id-token: write
packages: write
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@v1.10.0
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@v2.0.0
with:
image: ${{ needs.goreleaser.outputs.image }}
digest: ${{ needs.goreleaser.outputs.digest }}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ tests/*.html
shell_*.rye
console_*.rye

<<<<<<< HEAD
buildtemp/main.rye
*.bson

=======
buildtemp/main.rye
>>>>>>> 48009d9729854bd7bbbc0a943f839fc579a2943b
26 changes: 24 additions & 2 deletions env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,30 @@ func (e *RyeCtx) Get2(word int) (Object, bool, *RyeCtx) {
}

func (e *RyeCtx) Set(word int, val Object) Object {
e.state[word] = val
return val
if _, exists := e.state[word]; exists {
return NewError("Can't set already set word, try using modword")
} else {
e.state[word] = val
return val
}
}

func (e *RyeCtx) Unset(word int) Object {
if _, exists := e.state[word]; !exists {
return NewError("Can't unset non-existing word in this context")
} else {
delete(e.state, word)
return NewInteger(1)
}
}

func (e *RyeCtx) Mod(word int, val Object) Object {
if _, exists := e.state[word]; exists {
e.state[word] = val
return val
} else {
return NewError("Can't mod an unset word, try using setword")
}
}

func (e *RyeCtx) Unset(word int, idxs *Idxs) Object {

Check failure on line 272 in env/env.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

method RyeCtx.Unset already declared at env/env.go:254:18

Check failure on line 272 in env/env.go

View workflow job for this annotation

GitHub Actions / lint

method RyeCtx.Unset already declared at env/env.go:254:18

Check failure on line 272 in env/env.go

View workflow job for this annotation

GitHub Actions / lint

method RyeCtx.Unset already declared at env/env.go:254:18

Check failure on line 272 in env/env.go

View workflow job for this annotation

GitHub Actions / lint

method RyeCtx.Unset already declared at env/env.go:254:18

Check failure on line 272 in env/env.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

method RyeCtx.Unset already declared at env/env.go:254:18
Expand Down
57 changes: 57 additions & 0 deletions evaldo/builtins_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math"

"github.com/refaktor/rye/env"
"github.com/refaktor/rye/util"
)

// Integer represents an integer.
Expand Down Expand Up @@ -341,6 +342,62 @@ var Builtins_math = map[string]*env.Builtin{
}
},
},
"copysign": {
Argsn: 2,
Doc: "Copysign returns a value with the magnitude of arg1 and the sign of arg2.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch val := arg0.(type) {
case env.Integer:
switch val2 := arg1.(type) {
case env.Integer:
return *env.NewDecimal(math.Copysign(float64(val.Value), float64(val2.Value)))
case env.Decimal:
return *env.NewDecimal(math.Copysign(float64(val.Value), val2.Value))
default:
return MakeArgError(ps, 2, []env.Type{env.IntegerType, env.DecimalType}, "copysign")
}
case env.Decimal:
switch val2 := arg1.(type) {
case env.Integer:
return *env.NewDecimal(math.Copysign(val.Value, float64(val2.Value)))
case env.Decimal:
return *env.NewDecimal(math.Copysign(val.Value, val2.Value))
default:
return MakeArgError(ps, 2, []env.Type{env.IntegerType, env.DecimalType}, "copysign")
}
default:
return MakeArgError(ps, 1, []env.Type{env.IntegerType, env.DecimalType}, "copysign")
}
},
},
"dim": {
Argsn: 2,
Doc: "Dim returns the maximum of arg1-arg2 or 0.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch val := arg0.(type) {
case env.Integer:
switch val2 := arg1.(type) {
case env.Integer:
return *env.NewDecimal(util.GetDimValue(float64(val.Value), float64(val2.Value)))
case env.Decimal:
return *env.NewDecimal(util.GetDimValue(float64(val.Value), val2.Value))
default:
return MakeArgError(ps, 2, []env.Type{env.IntegerType, env.DecimalType}, "dim")
}
case env.Decimal:
switch val2 := arg1.(type) {
case env.Integer:
return *env.NewDecimal(util.GetDimValue(val.Value, float64(val2.Value)))
case env.Decimal:
return *env.NewDecimal(util.GetDimValue(val.Value, val2.Value))
default:
return MakeArgError(ps, 2, []env.Type{env.IntegerType, env.DecimalType}, "dim")
}
default:
return MakeArgError(ps, 1, []env.Type{env.IntegerType, env.DecimalType}, "dim")
}
},
},
"pi": {
Argsn: 0,
Doc: "Return Pi constant.",
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ require (
github.com/shirou/gopsutil/v3 v3.24.3
github.com/thomasberger/parsemail v1.2.6
go.mongodb.org/mongo-driver v1.14.0
golang.org/x/crypto v0.21.0
golang.org/x/net v0.23.0
golang.org/x/crypto v0.22.0
golang.org/x/net v0.24.0
golang.org/x/sync v0.6.0
golang.org/x/term v0.18.0
golang.org/x/term v0.19.0
golang.org/x/text v0.14.0
)

Expand Down Expand Up @@ -103,7 +103,7 @@ require (
github.com/yhirose/go-peg v0.0.0-20210804202551-de25d6753cf1 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/sys v0.19.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
Expand Down
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
goji.io v2.0.2+incompatible h1:uIssv/elbKRLznFUy3Xj4+2Mz/qKhek/9aZQDUMae7c=
goji.io v2.0.2+incompatible/go.mod h1:sbqFwrtqZACxLBTQcdgVjFh54yGVCvwq8+w49MVMMIk=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
Expand All @@ -246,11 +246,12 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
17 changes: 17 additions & 0 deletions tests/misc.rye
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,23 @@ section "Math functions"
equal { do\in math { cbrt 27 } } 3.000000
equal { do\in math { cbrt 12.3 } } 2.308350239753609
}

group "copysign"
mold\nowrap ""
{ { string } }
{
equal { do\in math { copysign 4.9 -1 } } -4.9
equal { do\in math { copysign 4.9 1 } } 4.9
}

group "dim"
mold\nowrap ""
{ { string } }
{
equal { do\in math { dim 2 -3 } } 5.000000
equal { do\in math { dim 8 -1 } } 9.000000
equal { do\in math { dim -4 -2 } } 0.000000
}

}

Expand Down
10 changes: 7 additions & 3 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,13 @@ func ProcessFunctionSpec(args env.Block) (bool, string) {
return true, doc
}

func MakeBuiltinError(env1 *env.ProgramState, msg string, fn string) *env.Error {
env1.FailureFlag = true
return env.NewError(msg + " in builtin " + fn + ".")
// GetDimValue get max x-y or 0 value
func GetDimValue(x, y float64) float64 {
difference := x - y
if difference > 0 {
return difference
}
return 0
}

/*
Expand Down

0 comments on commit 3f25ac4

Please sign in to comment.