From 8748a757c94a17c80210dc4c83214a3bb043a6e1 Mon Sep 17 00:00:00 2001 From: Guilherme Puida Date: Sun, 9 Jun 2024 23:32:05 -0300 Subject: [PATCH 1/6] Run tests with GOARCH=386 -race is not supported when running tests on Linux/386. --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dbc679a..e25551d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,6 +29,7 @@ jobs: run: | gawk --version go test -race ./... + GOARCH=386 go test ./... build-windows: runs-on: windows-latest From dab1744f775e42c9143f33a1bbfe31e29f51d8c9 Mon Sep 17 00:00:00 2001 From: Guilherme Puida Date: Sun, 9 Jun 2024 23:37:18 -0300 Subject: [PATCH 2/6] Fix number formatting on non-64bit architectures (#234) --- interp/value.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interp/value.go b/interp/value.go index 7ae95d6..3079568 100644 --- a/interp/value.go +++ b/interp/value.go @@ -141,8 +141,8 @@ func (v value) str(floatFormat string) string { } else { return "inf" } - case v.n == float64(int(v.n)): - return strconv.Itoa(int(v.n)) + case v.n == float64(int64(v.n)): + return strconv.FormatInt(int64(v.n), 10) default: if floatFormat == "%.6g" { return strconv.FormatFloat(v.n, 'g', 6, 64) From 0b1d07eb3f234e612de80182f3eb487fd376610f Mon Sep 17 00:00:00 2001 From: Ben Hoyt Date: Tue, 11 Jun 2024 20:55:42 +1200 Subject: [PATCH 3/6] Fix additional int size issues --- internal/ast/ast.go | 4 ++-- internal/compiler/compiler.go | 4 ++-- internal/compiler/disassembler.go | 4 ++-- interp/functions.go | 4 ++-- interp/vm.go | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/ast/ast.go b/internal/ast/ast.go index 303df70..191974b 100644 --- a/internal/ast/ast.go +++ b/internal/ast/ast.go @@ -285,8 +285,8 @@ type NumExpr struct { } func (e *NumExpr) String() string { - if e.Value == float64(int(e.Value)) { - return strconv.Itoa(int(e.Value)) + if e.Value == float64(int64(e.Value)) { + return strconv.FormatInt(int64(e.Value), 10) } else { return fmt.Sprintf("%.6g", e.Value) } diff --git a/internal/compiler/compiler.go b/internal/compiler/compiler.go index d7beb89..39b718a 100644 --- a/internal/compiler/compiler.go +++ b/internal/compiler/compiler.go @@ -1135,10 +1135,10 @@ func (c *compiler) binaryOp(op lexer.Token) { // Generate an array index, handling multi-indexes properly. func (c *compiler) index(index []ast.Expr) { for _, expr := range index { - if e, ok := expr.(*ast.NumExpr); ok && e.Value == float64(int(e.Value)) { + if e, ok := expr.(*ast.NumExpr); ok && e.Value == float64(int64(e.Value)) { // If index expression is integer constant, optimize to string "n" // to avoid toString() at runtime. - s := strconv.Itoa(int(e.Value)) + s := strconv.FormatInt(int64(e.Value), 10) c.expr(&ast.StrExpr{Value: s}) continue } diff --git a/internal/compiler/disassembler.go b/internal/compiler/disassembler.go index 8f944a3..4dc17a0 100644 --- a/internal/compiler/disassembler.go +++ b/internal/compiler/disassembler.go @@ -134,8 +134,8 @@ func (d *disassembler) disassemble(prefix string) error { case Num: index := d.fetch() num := d.program.Nums[index] - if num == float64(int(num)) { - d.writeOpf("Num %d (%d)", int(num), index) + if num == float64(int64(num)) { + d.writeOpf("Num %d (%d)", int64(num), index) } else { d.writeOpf("Num %.6g (%d)", num, index) } diff --git a/interp/functions.go b/interp/functions.go index 8e12547..a10f6af 100644 --- a/interp/functions.go +++ b/interp/functions.go @@ -405,11 +405,11 @@ func (p *interp) sprintf(format string, args []value) (string, error) { case 's': v = p.toString(a) case 'd': - v = int(a.num()) + v = int64(a.num()) case 'f': v = a.num() case 'u': - v = uint(a.num()) + v = uint64(a.num()) case 'c': var c []byte n, isStr := a.isTrueStr() diff --git a/interp/vm.go b/interp/vm.go index e531afb..57d84f1 100644 --- a/interp/vm.go +++ b/interp/vm.go @@ -980,7 +980,7 @@ func (p *interp) callBuiltin(builtinOp compiler.BuiltinOp) error { p.replaceTop(num(float64(index + 1))) case compiler.BuiltinInt: - p.replaceTop(num(float64(int(p.peekTop().num())))) + p.replaceTop(num(float64(int64(p.peekTop().num())))) case compiler.BuiltinLength: p.push(num(float64(len(p.line)))) From 3c1ab79cd666cf02ac85b1b6d06c4cb709fed1b0 Mon Sep 17 00:00:00 2001 From: Ben Hoyt Date: Tue, 11 Jun 2024 21:29:29 +1200 Subject: [PATCH 4/6] Have separate amd64 and 386 jobs --- .github/workflows/tests.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e25551d..787facf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,6 +29,30 @@ jobs: run: | gawk --version go test -race ./... + go test ./... + + build-linux-386: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + go: ['1.22'] + + name: Go ${{ matrix.go }} on Linux 386 + + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - name: Build and Test + run: | + gawk --version + GOARCH=386 go test -race ./... GOARCH=386 go test ./... build-windows: From 5d93da9ca66e67d725fba2b401c5d477389a7b02 Mon Sep 17 00:00:00 2001 From: Ben Hoyt Date: Tue, 11 Jun 2024 21:30:03 +1200 Subject: [PATCH 5/6] -race is not supported on GOARCH=386 --- .github/workflows/tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 787facf..0127cc8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -52,7 +52,6 @@ jobs: - name: Build and Test run: | gawk --version - GOARCH=386 go test -race ./... GOARCH=386 go test ./... build-windows: From 9c899f6c7ca24908c88e3136552503c782c2c913 Mon Sep 17 00:00:00 2001 From: Ben Hoyt Date: Tue, 11 Jun 2024 21:49:52 +1200 Subject: [PATCH 6/6] Remove redundant go test --- .github/workflows/tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0127cc8..630ffb9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,7 +29,6 @@ jobs: run: | gawk --version go test -race ./... - go test ./... build-linux-386: runs-on: ubuntu-latest