Skip to content

Commit d63d8e0

Browse files
ydnardeadprogram
authored andcommitted
internal/wasm-tools, internal/cm: udpate to go.bytecodealliance.org@v0.6.1 and cm@v0.2.1
1 parent 8e009de commit d63d8e0

File tree

5 files changed

+18
-69
lines changed

5 files changed

+18
-69
lines changed

GNUmakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ wasi-syscall: wasi-cm
277277
.PHONY: wasi-cm
278278
wasi-cm:
279279
rm -rf ./src/internal/cm/*
280-
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
280+
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
281281

282282
# Check for Node.js used during WASM tests.
283283
NODEJS_VERSION := $(word 1,$(subst ., ,$(shell node -v | cut -c 2-)))

internal/wasm-tools/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module github.com/tinygo-org/tinygo/internal/wasm-tools
33
go 1.23.0
44

55
require (
6-
go.bytecodealliance.org v0.6.0
7-
go.bytecodealliance.org/cm v0.2.0
6+
go.bytecodealliance.org v0.6.1
7+
go.bytecodealliance.org/cm v0.2.1
88
)
99

1010
require (

internal/wasm-tools/go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
2929
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
3030
github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjcw9Zg=
3131
github.com/urfave/cli/v3 v3.0.0-beta1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
32-
go.bytecodealliance.org v0.6.0 h1:9ziqj963aEKqOiu5cl87Hb78KImNP4zEABl+OWwBwxk=
33-
go.bytecodealliance.org v0.6.0/go.mod h1:j0lprXhqeVSE8kYN2EjcN9gm+fxUyNWtl//WA+3ypFg=
34-
go.bytecodealliance.org/cm v0.2.0 h1:HMkj1x1LZWU/Ghu2TtUk3VTyS7gyDHLyIfIut0Cpc5M=
35-
go.bytecodealliance.org/cm v0.2.0/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI=
32+
go.bytecodealliance.org v0.6.1 h1:H3vVYeEZa8Gs9t9YyZ4ZjA8sr5c6Xfkz3p+cM3543aA=
33+
go.bytecodealliance.org v0.6.1/go.mod h1:qPL6PksrsjAxl6o23HuX4pGO6n3UxiESPbvRn8ZVot0=
34+
go.bytecodealliance.org/cm v0.2.1 h1:sFUQRPfM+ku7hKgFwxGdwjghv4QtTLukpqsAHgE1Tek=
35+
go.bytecodealliance.org/cm v0.2.1/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI=
3636
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
3737
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
3838
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=

src/internal/cm/case.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package cm
22

3-
import "errors"
4-
53
// CaseUnmarshaler returns an function that can unmarshal text into
64
// [variant] or [enum] case T.
75
//
@@ -33,8 +31,7 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
3331
if len(text) == 0 {
3432
return errEmpty
3533
}
36-
s := string(text)
37-
c, ok := m[s]
34+
c, ok := m[string(text)]
3835
if !ok {
3936
return errNoMatchingCase
4037
}
@@ -46,6 +43,14 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te
4643
const linearScanThreshold = 16
4744

4845
var (
49-
errEmpty = errors.New("empty text")
50-
errNoMatchingCase = errors.New("no matching case")
46+
errEmpty = &stringError{"empty text"}
47+
errNoMatchingCase = &stringError{"no matching case"}
5148
)
49+
50+
type stringError struct {
51+
err string
52+
}
53+
54+
func (err *stringError) Error() string {
55+
return err.err
56+
}

src/internal/cm/list.go

-56
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package cm
22

33
import (
4-
"bytes"
5-
"encoding/json"
64
"unsafe"
75
)
86

@@ -62,57 +60,3 @@ func (l list[T]) Data() *T {
6260
func (l list[T]) Len() uintptr {
6361
return l.len
6462
}
65-
66-
// MarshalJSON implements json.Marshaler.
67-
func (l list[T]) MarshalJSON() ([]byte, error) {
68-
if l.len == 0 {
69-
return []byte("[]"), nil
70-
}
71-
72-
s := l.Slice()
73-
var zero T
74-
if unsafe.Sizeof(zero) == 1 {
75-
// The default Go json.Encoder will marshal []byte as base64.
76-
// We override that behavior so all int types have the same serialization format.
77-
// []uint8{1,2,3} -> [1,2,3]
78-
// []uint32{1,2,3} -> [1,2,3]
79-
return json.Marshal(sliceOf(s))
80-
}
81-
return json.Marshal(s)
82-
}
83-
84-
type slice[T any] []entry[T]
85-
86-
func sliceOf[S ~[]E, E any](s S) slice[E] {
87-
return *(*slice[E])(unsafe.Pointer(&s))
88-
}
89-
90-
type entry[T any] [1]T
91-
92-
func (v entry[T]) MarshalJSON() ([]byte, error) {
93-
return json.Marshal(v[0])
94-
}
95-
96-
// UnmarshalJSON implements json.Unmarshaler.
97-
func (l *list[T]) UnmarshalJSON(data []byte) error {
98-
if bytes.Equal(data, nullLiteral) {
99-
return nil
100-
}
101-
102-
var s []T
103-
err := json.Unmarshal(data, &s)
104-
if err != nil {
105-
return err
106-
}
107-
108-
l.data = unsafe.SliceData([]T(s))
109-
l.len = uintptr(len(s))
110-
111-
return nil
112-
}
113-
114-
// nullLiteral is the JSON representation of a null literal.
115-
// By convention, to approximate the behavior of Unmarshal itself,
116-
// Unmarshalers implement UnmarshalJSON([]byte("null")) as a no-op.
117-
// See https://pkg.go.dev/encoding/json#Unmarshaler for more information.
118-
var nullLiteral = []byte("null")

0 commit comments

Comments
 (0)