internal/wasm-tools, internal/cm: udpate to go.bytecodealliance.org@v0.6.1 and cm@v0.2.1

This commit is contained in:
Randy Reddig
2025-03-16 13:35:44 -07:00
committed by Ron Evans
parent 8e009de8a8
commit d63d8e0899
5 changed files with 18 additions and 69 deletions
+1 -1
View File
@@ -277,7 +277,7 @@ wasi-syscall: wasi-cm
.PHONY: wasi-cm
wasi-cm:
rm -rf ./src/internal/cm/*
rsync -rv --delete --exclude go.mod --exclude '*_test.go' --exclude '*.md' --exclude LICENSE $(shell go list -modfile ./internal/wasm-tools/go.mod -m -f {{.Dir}} $(WASM_TOOLS_MODULE)/cm)/ ./src/internal/cm
rsync -rv --delete --exclude go.mod --exclude '*_test.go' --exclude '*_json.go' --exclude '*.md' --exclude LICENSE $(shell go list -modfile ./internal/wasm-tools/go.mod -m -f {{.Dir}} $(WASM_TOOLS_MODULE)/cm)/ ./src/internal/cm
# Check for Node.js used during WASM tests.
NODEJS_VERSION := $(word 1,$(subst ., ,$(shell node -v | cut -c 2-)))
+2 -2
View File
@@ -3,8 +3,8 @@ module github.com/tinygo-org/tinygo/internal/wasm-tools
go 1.23.0
require (
go.bytecodealliance.org v0.6.0
go.bytecodealliance.org/cm v0.2.0
go.bytecodealliance.org v0.6.1
go.bytecodealliance.org/cm v0.2.1
)
require (
+4 -4
View File
@@ -29,10 +29,10 @@ github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjcw9Zg=
github.com/urfave/cli/v3 v3.0.0-beta1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
go.bytecodealliance.org v0.6.0 h1:9ziqj963aEKqOiu5cl87Hb78KImNP4zEABl+OWwBwxk=
go.bytecodealliance.org v0.6.0/go.mod h1:j0lprXhqeVSE8kYN2EjcN9gm+fxUyNWtl//WA+3ypFg=
go.bytecodealliance.org/cm v0.2.0 h1:HMkj1x1LZWU/Ghu2TtUk3VTyS7gyDHLyIfIut0Cpc5M=
go.bytecodealliance.org/cm v0.2.0/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI=
go.bytecodealliance.org v0.6.1 h1:H3vVYeEZa8Gs9t9YyZ4ZjA8sr5c6Xfkz3p+cM3543aA=
go.bytecodealliance.org v0.6.1/go.mod h1:qPL6PksrsjAxl6o23HuX4pGO6n3UxiESPbvRn8ZVot0=
go.bytecodealliance.org/cm v0.2.1 h1:sFUQRPfM+ku7hKgFwxGdwjghv4QtTLukpqsAHgE1Tek=
go.bytecodealliance.org/cm v0.2.1/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI=
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
+11 -6
View File
@@ -1,7 +1,5 @@
package cm
import "errors"
// CaseUnmarshaler returns an function that can unmarshal text into
// [variant] or [enum] case T.
//
@@ -33,8 +31,7 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
if len(text) == 0 {
return errEmpty
}
s := string(text)
c, ok := m[s]
c, ok := m[string(text)]
if !ok {
return errNoMatchingCase
}
@@ -46,6 +43,14 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
const linearScanThreshold = 16
var (
errEmpty = errors.New("empty text")
errNoMatchingCase = errors.New("no matching case")
errEmpty = &stringError{"empty text"}
errNoMatchingCase = &stringError{"no matching case"}
)
type stringError struct {
err string
}
func (err *stringError) Error() string {
return err.err
}
-56
View File
@@ -1,8 +1,6 @@
package cm
import (
"bytes"
"encoding/json"
"unsafe"
)
@@ -62,57 +60,3 @@ func (l list[T]) Data() *T {
func (l list[T]) Len() uintptr {
return l.len
}
// MarshalJSON implements json.Marshaler.
func (l list[T]) MarshalJSON() ([]byte, error) {
if l.len == 0 {
return []byte("[]"), nil
}
s := l.Slice()
var zero T
if unsafe.Sizeof(zero) == 1 {
// The default Go json.Encoder will marshal []byte as base64.
// We override that behavior so all int types have the same serialization format.
// []uint8{1,2,3} -> [1,2,3]
// []uint32{1,2,3} -> [1,2,3]
return json.Marshal(sliceOf(s))
}
return json.Marshal(s)
}
type slice[T any] []entry[T]
func sliceOf[S ~[]E, E any](s S) slice[E] {
return *(*slice[E])(unsafe.Pointer(&s))
}
type entry[T any] [1]T
func (v entry[T]) MarshalJSON() ([]byte, error) {
return json.Marshal(v[0])
}
// UnmarshalJSON implements json.Unmarshaler.
func (l *list[T]) UnmarshalJSON(data []byte) error {
if bytes.Equal(data, nullLiteral) {
return nil
}
var s []T
err := json.Unmarshal(data, &s)
if err != nil {
return err
}
l.data = unsafe.SliceData([]T(s))
l.len = uintptr(len(s))
return nil
}
// nullLiteral is the JSON representation of a null literal.
// By convention, to approximate the behavior of Unmarshal itself,
// Unmarshalers implement UnmarshalJSON([]byte("null")) as a no-op.
// See https://pkg.go.dev/encoding/json#Unmarshaler for more information.
var nullLiteral = []byte("null")