Skip to content

Commit

Permalink
Merge pull request #122 from Shopify/golang-update
Browse files Browse the repository at this point in the history
Golang update
  • Loading branch information
etiennemartin authored Jan 20, 2022
2 parents d8ac556 + b48f06d commit 9ab7793
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
lua-tests/
.DS_[sS]tore
2 changes: 1 addition & 1 deletion bit32.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func fieldArguments(l *State, fieldIndex int) (uint, uint) {
var bitLibrary = []RegistryFunction{
{"arshift", func(l *State) int {
r, i := CheckUnsigned(l, 1), CheckInteger(l, 2)
if i < 0 || 0 == (r&(1<<(bitCount-1))) {
if i < 0 || (r&(1<<(bitCount-1)) == 0) {
return shift(l, r, -i)
}

Expand Down
8 changes: 4 additions & 4 deletions dev.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: go-lua

up:
- go: 1.7.3
- go: 1.17.5
- custom:
name: Initializing submodules
met?: test -f lua-tests/.git
Expand All @@ -15,9 +15,9 @@ up:
echo "brew install lua"
exit 1
fi
meet: 'true'
meet: "true"

commands:
test:
run: go test ./...
desc: 'run unit tests'
run: go test -v -tags=!skip ./...
desc: "run unit tests"
Binary file added doc/presentations/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/Shopify/go-lua

go 1.17
9 changes: 3 additions & 6 deletions go_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Skip these test since they have different results based on the CPU architecture.
//go:build skip

package lua

// Test assumptions about how Go works
Expand Down Expand Up @@ -62,12 +65,6 @@ func TestPow(t *testing.T) {
}
}

func TestZero(t *testing.T) {
if 0.0 != -0.0 {
t.Error("0.0 == -0.0")
}
}

func TestParseFloat(t *testing.T) {
if f, err := strconv.ParseFloat("inf", 64); err != nil {
t.Error("ParseFloat('inf', 64) == ", f, err)
Expand Down
3 changes: 1 addition & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ func (p *parser) suffixedExpression() exprDesc {
return e
}
}
panic("unreachable")
}

func (p *parser) simpleExpression() (e exprDesc) {
Expand Down Expand Up @@ -682,7 +681,7 @@ func protectedParser(l *State, r io.Reader, name, chunkMode string) error {
} else if c == Signature[0] {
l.checkMode(chunkMode, "binary")
b.UnreadByte()
closure, err = l.undump(b, name) // TODO handle err
closure, _ = l.undump(b, name) // TODO handle err
} else {
l.checkMode(chunkMode, "text")
b.UnreadByte()
Expand Down
1 change: 0 additions & 1 deletion scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ func (s *scanner) scan() token {
return token{t: c}
}
}
panic("unreachable")
}

func (s *scanner) next() {
Expand Down
1 change: 0 additions & 1 deletion stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ func (l *State) preCall(function int, resultCount int) bool {
l.stack[function] = tm
}
}
panic("unreachable")
}

func (l *State) callHook(ci *callInfo) {
Expand Down
12 changes: 7 additions & 5 deletions string.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lua
import (
"bytes"
"fmt"
"math"
"strings"
"unicode"
)
Expand Down Expand Up @@ -91,18 +92,19 @@ func formatHelper(l *State, fs string, argCount int) string {
fallthrough
case 'd':
n := CheckNumber(l, arg)
ArgumentCheck(l, math.Floor(n) == n && -math.Pow(2, 63) <= n && n < math.Pow(2, 63), arg, "number has no integer representation")
ni := int(n)
diff := n - float64(ni)
ArgumentCheck(l, -1 < diff && diff < 1, arg, "not a number in proper range")
fmt.Fprintf(&b, f, ni)
case 'u': // The fmt package doesn't support %u.
f = f[:len(f)-1] + "d"
fallthrough
n := CheckNumber(l, arg)
ArgumentCheck(l, math.Floor(n) == n && 0.0 <= n && n < math.Pow(2, 64), arg, "not a non-negative number in proper range")
ni := uint(n)
fmt.Fprintf(&b, f, ni)
case 'o', 'x', 'X':
n := CheckNumber(l, arg)
ArgumentCheck(l, 0.0 <= n && n < math.Pow(2, 64), arg, "not a non-negative number in proper range")
ni := uint(n)
diff := n - float64(ni)
ArgumentCheck(l, -1 < diff && diff < 1, arg, "not a non-negative number in proper range")
fmt.Fprintf(&b, f, ni)
case 'e', 'E', 'f', 'g', 'G':
fmt.Fprintf(&b, f, CheckNumber(l, arg))
Expand Down
2 changes: 1 addition & 1 deletion undump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestAllHeaderNoFun(t *testing.T) {

func TestWrongEndian(t *testing.T) {
h := header
if 0 == h.Endianness {
if h.Endianness == 0 {
h.Endianness = 1
} else {
h.Endianness = 0
Expand Down
2 changes: 1 addition & 1 deletion vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ type engine struct {
}

func (e *engine) k(field int) value {
if 0 != field&bitRK { // OPT: Inline isConstant(field).
if field&bitRK != 0 { // OPT: Inline isConstant(field).
return e.constants[field & ^bitRK] // OPT: Inline constantIndex(field).
}
return e.frame[field]
Expand Down
7 changes: 5 additions & 2 deletions vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import (
"testing"
)

func testString(t *testing.T, s string) { testStringHelper(t, s, false) }
func traceString(t *testing.T, s string) { testStringHelper(t, s, true) }
func testString(t *testing.T, s string) { testStringHelper(t, s, false) }

// Commented out to avoid a warning relating to the method not being used. Left here since it's useful for debugging.
//func traceString(t *testing.T, s string) { testStringHelper(t, s, true) }

func testNoPanicString(t *testing.T, s string) {
defer func() {
if rc := recover(); rc != nil {
Expand Down

0 comments on commit 9ab7793

Please sign in to comment.