mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-13 23:43:40 +00:00
all: modernize (#5498)
* modernize string cut usage * modernize string cut prefix usage * modernize slices helper usage * modernize min and max usage * modernize loop variable copies * modernize integer range loops * modernize map copy loops * modernize go types iterator usage * modernize empty interface usage * modernize atomic type usage * modernize string builders * modernize string split iteration * modernize remaining loop variable copies * modernize usb cdc min usage * modernize src integer range loops * modernize example empty interface usage * modernize src min and max usage * modernize src integer range loops * modernize src empty interface usage * modernize src atomic type usage * modernize reflect type lookups * modernize review nits
This commit is contained in:
+1
-1
@@ -151,7 +151,7 @@ func (r *runner) compileFunction(llvmFn llvm.Value) *function {
|
||||
case llvm.PHI:
|
||||
inst.name = llvmInst.Name()
|
||||
incomingCount := inst.llvmInst.IncomingCount()
|
||||
for i := 0; i < incomingCount; i++ {
|
||||
for i := range incomingCount {
|
||||
incomingBB := inst.llvmInst.IncomingBlock(i)
|
||||
incomingValue := inst.llvmInst.IncomingValue(i)
|
||||
inst.operands = append(inst.operands,
|
||||
|
||||
@@ -22,7 +22,6 @@ func TestInterp(t *testing.T) {
|
||||
"alloc",
|
||||
"slicedata",
|
||||
} {
|
||||
name := name // make local to this closure
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
runTest(t, "testdata/"+name)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -470,7 +471,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
// should be returned.
|
||||
numMethods := int(r.builder.CreateExtractValue(methodSet, 0, "").ZExtValue())
|
||||
var method llvm.Value
|
||||
for i := 0; i < numMethods; i++ {
|
||||
for i := range numMethods {
|
||||
methodSignatureAgg := r.builder.CreateExtractValue(methodSet, 1, "")
|
||||
methodSignature := r.builder.CreateExtractValue(methodSignatureAgg, i, "")
|
||||
if methodSignature == signature {
|
||||
@@ -907,7 +908,7 @@ func (r *runner) interpretICmp(lhs, rhs value, predicate llvm.IntPredicate) bool
|
||||
func (r *runner) runAtRuntime(fn *function, inst instruction, locals []value, mem *memoryView, indent string) *Error {
|
||||
numOperands := inst.llvmInst.OperandsCount()
|
||||
operands := make([]llvm.Value, numOperands)
|
||||
for i := 0; i < numOperands; i++ {
|
||||
for i := range numOperands {
|
||||
operand := inst.llvmInst.Operand(i)
|
||||
if !operand.IsAInstruction().IsNil() || !operand.IsAArgument().IsNil() {
|
||||
var err error
|
||||
@@ -985,9 +986,9 @@ func (r *runner) runAtRuntime(fn *function, inst instruction, locals []value, me
|
||||
mem.instructions = append(mem.instructions, agg)
|
||||
}
|
||||
result = operands[1]
|
||||
for i := len(indices) - 1; i >= 0; i-- {
|
||||
for i, indice := range slices.Backward(indices) {
|
||||
agg := aggregates[i]
|
||||
result = r.builder.CreateInsertValue(agg, result, int(indices[i]), inst.name+".insertvalue"+strconv.Itoa(i))
|
||||
result = r.builder.CreateInsertValue(agg, result, int(indice), inst.name+".insertvalue"+strconv.Itoa(i))
|
||||
if i != 0 { // don't add last result to mem.instructions as it will be done at the end already
|
||||
mem.instructions = append(mem.instructions, result)
|
||||
}
|
||||
|
||||
+14
-14
@@ -18,8 +18,10 @@ import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"math"
|
||||
"math/big"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -80,9 +82,7 @@ func (mv *memoryView) extend(sub memoryView) {
|
||||
if mv.objects == nil && len(sub.objects) != 0 {
|
||||
mv.objects = make(map[uint32]object)
|
||||
}
|
||||
for key, value := range sub.objects {
|
||||
mv.objects[key] = value
|
||||
}
|
||||
maps.Copy(mv.objects, sub.objects)
|
||||
mv.instructions = append(mv.instructions, sub.instructions...)
|
||||
}
|
||||
|
||||
@@ -90,8 +90,8 @@ func (mv *memoryView) extend(sub memoryView) {
|
||||
// created in this memoryView. Do not reuse this memoryView.
|
||||
func (mv *memoryView) revert() {
|
||||
// Erase instructions in reverse order.
|
||||
for i := len(mv.instructions) - 1; i >= 0; i-- {
|
||||
llvmInst := mv.instructions[i]
|
||||
for _, llvmInst := range slices.Backward(mv.instructions) {
|
||||
|
||||
if llvmInst.IsAInstruction().IsNil() {
|
||||
// The IR builder will try to create constant versions of
|
||||
// instructions whenever possible. If it does this, it's not an
|
||||
@@ -172,7 +172,7 @@ func (mv *memoryView) markExternal(llvmValue llvm.Value, mark uint8) error {
|
||||
continue
|
||||
}
|
||||
numOperands := inst.OperandsCount()
|
||||
for i := 0; i < numOperands; i++ {
|
||||
for i := range numOperands {
|
||||
// Using mark '2' (which means read/write access)
|
||||
// because this might be a store instruction.
|
||||
err := mv.markExternal(inst.Operand(i), 2)
|
||||
@@ -215,7 +215,7 @@ func (mv *memoryView) markExternal(llvmValue llvm.Value, mark uint8) error {
|
||||
// need any marking.
|
||||
case llvm.StructTypeKind:
|
||||
numElements := llvmType.StructElementTypesCount()
|
||||
for i := 0; i < numElements; i++ {
|
||||
for i := range numElements {
|
||||
element := mv.r.builder.CreateExtractValue(llvmValue, i, "")
|
||||
err := mv.markExternal(element, mark)
|
||||
if err != nil {
|
||||
@@ -224,7 +224,7 @@ func (mv *memoryView) markExternal(llvmValue llvm.Value, mark uint8) error {
|
||||
}
|
||||
case llvm.ArrayTypeKind:
|
||||
numElements := llvmType.ArrayLength()
|
||||
for i := 0; i < numElements; i++ {
|
||||
for i := range numElements {
|
||||
element := mv.r.builder.CreateExtractValue(llvmValue, i, "")
|
||||
err := mv.markExternal(element, mark)
|
||||
if err != nil {
|
||||
@@ -366,7 +366,7 @@ func (mv *memoryView) store(v value, p pointerValue) bool {
|
||||
buffer := obj.buffer.asRawValue(mv.r)
|
||||
obj.buffer = buffer
|
||||
v := v.asRawValue(mv.r)
|
||||
for i := uint32(0); i < valueLen; i++ {
|
||||
for i := range valueLen {
|
||||
buffer.buf[p.offset()+i] = v.buf[i]
|
||||
}
|
||||
}
|
||||
@@ -392,7 +392,7 @@ type value interface {
|
||||
// literalValue contains simple integer values that don't need to be stored in a
|
||||
// buffer.
|
||||
type literalValue struct {
|
||||
value interface{}
|
||||
value any
|
||||
}
|
||||
|
||||
// Make a literalValue given the number of bits.
|
||||
@@ -1015,7 +1015,7 @@ func (v *rawValue) set(llvmValue llvm.Value, r *runner) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for i := uint32(0); i < ptrSize; i++ {
|
||||
for i := range ptrSize {
|
||||
v.buf[i] = ptr.pointer
|
||||
}
|
||||
} else if !llvmValue.IsAConstantExpr().IsNil() {
|
||||
@@ -1056,7 +1056,7 @@ func (v *rawValue) set(llvmValue llvm.Value, r *runner) {
|
||||
panic(err)
|
||||
}
|
||||
ptrValue.pointer += totalOffset
|
||||
for i := uint32(0); i < ptrSize; i++ {
|
||||
for i := range ptrSize {
|
||||
v.buf[i] = ptrValue.pointer
|
||||
}
|
||||
case llvm.ICmp:
|
||||
@@ -1113,7 +1113,7 @@ func (v *rawValue) set(llvmValue llvm.Value, r *runner) {
|
||||
}
|
||||
case llvm.StructTypeKind:
|
||||
numElements := llvmType.StructElementTypesCount()
|
||||
for i := 0; i < numElements; i++ {
|
||||
for i := range numElements {
|
||||
offset := r.targetData.ElementOffset(llvmType, i)
|
||||
field := rawValue{
|
||||
buf: v.buf[offset:],
|
||||
@@ -1124,7 +1124,7 @@ func (v *rawValue) set(llvmValue llvm.Value, r *runner) {
|
||||
numElements := llvmType.ArrayLength()
|
||||
childType := llvmType.ElementType()
|
||||
childTypeSize := r.targetData.TypeAllocSize(childType)
|
||||
for i := 0; i < numElements; i++ {
|
||||
for i := range numElements {
|
||||
offset := i * int(childTypeSize)
|
||||
field := rawValue{
|
||||
buf: v.buf[offset:],
|
||||
|
||||
Reference in New Issue
Block a user