Skip to content

Commit

Permalink
chore: rename max var name to avoid collision with predeclared iden…
Browse files Browse the repository at this point in the history
…tifier

Signed-off-by: gfanton <[email protected]>
  • Loading branch information
gfanton committed Dec 5, 2024
1 parent 5427f26 commit 235a0f3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
26 changes: 13 additions & 13 deletions gnovm/pkg/gnolang/op_expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,20 @@ func (m *Machine) doOpSelector() {

func (m *Machine) doOpSlice() {
sx := m.PopExpr().(*SliceExpr)
var low, high, max int = -1, -1, -1
var lowVal, highVal, maxVal int = -1, -1, -1
// max
if sx.Max != nil {
max = m.PopValue().ConvertGetInt()
maxVal = m.PopValue().ConvertGetInt()
}
// high
if sx.High != nil {
high = m.PopValue().ConvertGetInt()
highVal = m.PopValue().ConvertGetInt()
}
// low
if sx.Low != nil {
low = m.PopValue().ConvertGetInt()
lowVal = m.PopValue().ConvertGetInt()
} else {
low = 0
lowVal = 0
}
// slice base x
xv := m.PopValue()
Expand All @@ -114,14 +114,14 @@ func (m *Machine) doOpSlice() {
}
// fill default based on xv
if sx.High == nil {
high = xv.GetLength()
highVal = xv.GetLength()
}
// all low:high:max cases
if max == -1 {
sv := xv.GetSlice(m.Alloc, low, high)
if maxVal == -1 {
sv := xv.GetSlice(m.Alloc, lowVal, highVal)
m.PushValue(sv)
} else {
sv := xv.GetSlice2(m.Alloc, low, high, max)
sv := xv.GetSlice2(m.Alloc, lowVal, highVal, maxVal)
m.PushValue(sv)
}
}
Expand Down Expand Up @@ -593,16 +593,16 @@ func (m *Machine) doOpSliceLit2() {
// peek slice type.
st := m.PeekValue(1).V.(TypeValue).Type
// calculate maximum index.
max := 0
maxVal := 0
for i := 0; i < el; i++ {
itv := tvs[i*2+0]
idx := itv.ConvertGetInt()
if idx > max {
max = idx
if idx > maxVal {
maxVal = idx
}
}
// construct element buf slice.
es := make([]TypedValue, max+1)
es := make([]TypedValue, maxVal+1)
for i := 0; i < el; i++ {
itv := tvs[i*2+0]
vtv := tvs[i*2+1]
Expand Down
48 changes: 24 additions & 24 deletions gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -2248,41 +2248,41 @@ func (tv *TypedValue) GetSlice(alloc *Allocator, low, high int) TypedValue {
}
}

func (tv *TypedValue) GetSlice2(alloc *Allocator, low, high, max int) TypedValue {
if low < 0 {
func (tv *TypedValue) GetSlice2(alloc *Allocator, lowVal, highVal, maxVal int) TypedValue {
if lowVal < 0 {
panic(fmt.Sprintf(
"invalid slice index %d (index must be non-negative)",
low))
lowVal))

Check warning on line 2255 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2255

Added line #L2255 was not covered by tests
}
if high < 0 {
if highVal < 0 {
panic(fmt.Sprintf(
"invalid slice index %d (index must be non-negative)",
high))
highVal))

Check warning on line 2260 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2260

Added line #L2260 was not covered by tests
}
if max < 0 {
if maxVal < 0 {
panic(fmt.Sprintf(
"invalid slice index %d (index must be non-negative)",
max))
maxVal))

Check warning on line 2265 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2265

Added line #L2265 was not covered by tests
}
if low > high {
if lowVal > highVal {
panic(fmt.Sprintf(
"invalid slice index %d > %d",
low, high))
lowVal, highVal))

Check warning on line 2270 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2270

Added line #L2270 was not covered by tests
}
if high > max {
if highVal > maxVal {
panic(fmt.Sprintf(
"invalid slice index %d > %d",
high, max))
highVal, maxVal))

Check warning on line 2275 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2275

Added line #L2275 was not covered by tests
}
if tv.GetCapacity() < high {
if tv.GetCapacity() < highVal {
panic(fmt.Sprintf(
"slice bounds out of range [%d:%d:%d] with capacity %d",
low, high, max, tv.GetCapacity()))
lowVal, highVal, maxVal, tv.GetCapacity()))

Check warning on line 2280 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2280

Added line #L2280 was not covered by tests
}
if tv.GetCapacity() < max {
if tv.GetCapacity() < maxVal {
panic(fmt.Sprintf(
"slice bounds out of range [%d:%d:%d] with capacity %d",
low, high, max, tv.GetCapacity()))
lowVal, highVal, maxVal, tv.GetCapacity()))

Check warning on line 2285 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2285

Added line #L2285 was not covered by tests
}
switch bt := baseOf(tv.T).(type) {
case *ArrayType:
Expand All @@ -2294,15 +2294,15 @@ func (tv *TypedValue) GetSlice2(alloc *Allocator, low, high, max int) TypedValue
return TypedValue{
T: st,
V: alloc.NewSlice(
av, // base
low, // low
high-low, // length
max-low, // maxcap
av, // base
lowVal, // low
highVal-lowVal, // length
maxVal-lowVal, // maxcap
),
}
case *SliceType:
if tv.V == nil {
if low != 0 || high != 0 || max != 0 {
if lowVal != 0 || highVal != 0 || maxVal != 0 {

Check warning on line 2305 in gnovm/pkg/gnolang/values.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values.go#L2305

Added line #L2305 was not covered by tests
panic("nil slice index out of range")
}
return TypedValue{
Expand All @@ -2314,10 +2314,10 @@ func (tv *TypedValue) GetSlice2(alloc *Allocator, low, high, max int) TypedValue
return TypedValue{
T: tv.T,
V: alloc.NewSlice(
sv.Base, // base
sv.Offset+low, // offset
high-low, // length
max-low, // maxcap
sv.Base, // base
sv.Offset+lowVal, // offset
highVal-lowVal, // length
maxVal-lowVal, // maxcap
),
}
default:
Expand Down

0 comments on commit 235a0f3

Please sign in to comment.