From 87a8aafc4fc84ca0a2b5e68f9e0b425e4fac4878 Mon Sep 17 00:00:00 2001 From: Randy Reddig Date: Tue, 16 Jul 2024 11:18:46 -0700 Subject: all: simplify wasm-tools-go dependency - add internal/wasm-tools/go.mod file to depend on wasm-tools-go - copy package cm into src/internal/cm - remove wasm-tools-go "vendor" submodule internal/tools: fix typo go.{mod,sum}, internal/tools: add wit-bindgen-go to tools GNUmakefile: use go run for wit-bindgen-go GNUmakefile: add tools target to go:generate tools binaries in internal/tools GNUmakefile: add .PHONY for lint and spell GNUmakefile, internal/cm: vendor package cm into internal/cm go.{mod,sum}: update wasm-tools-go to v0.1.4 internal/wasi: use internal/cm package remove submodule src/vendor/github.com/ydnar/wasm-tools-go GNUmakefile: add comment documenting what wasi-cm target does go.{mod,sum}: remove toolchain; go mod tidy go.mod: revert to Go 1.19 go.mod: go 1.19 go.{mod,sum}, internal/{tools,wasm-tools}: revert root go.mod file to go1.19 Create a wasm-tools specific module that can require go1.22 for wasm-tools-go. --- .gitmodules | 3 - GNUmakefile | 19 +- internal/tools/tools.go | 7 +- internal/wasm-tools/README.md | 5 + internal/wasm-tools/go.mod | 12 ++ internal/wasm-tools/go.sum | 25 +++ internal/wasm-tools/tools.go | 11 + loader/goroot.go | 3 +- src/internal/cm/abi.go | 118 +++++++++++ src/internal/cm/docs.go | 8 + src/internal/cm/list.go | 48 +++++ src/internal/cm/option.go | 44 ++++ src/internal/cm/resource.go | 21 ++ src/internal/cm/result.go | 107 ++++++++++ src/internal/cm/tuple.go | 230 +++++++++++++++++++++ src/internal/cm/variant.go | 74 +++++++ .../wasi/cli/v0.2.0/environment/environment.wit.go | 2 +- src/internal/wasi/cli/v0.2.0/exit/exit.wit.go | 2 +- src/internal/wasi/cli/v0.2.0/run/run.exports.go | 2 +- src/internal/wasi/cli/v0.2.0/run/run.wit.go | 2 +- src/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go | 2 +- src/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go | 2 +- src/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go | 2 +- .../v0.2.0/terminal-input/terminal-input.wit.go | 2 +- .../v0.2.0/terminal-output/terminal-output.wit.go | 2 +- .../v0.2.0/terminal-stderr/terminal-stderr.wit.go | 2 +- .../v0.2.0/terminal-stdin/terminal-stdin.wit.go | 2 +- .../v0.2.0/terminal-stdout/terminal-stdout.wit.go | 2 +- .../v0.2.0/monotonic-clock/monotonic-clock.wit.go | 2 +- .../filesystem/v0.2.0/preopens/preopens.wit.go | 2 +- src/internal/wasi/filesystem/v0.2.0/types/abi.go | 2 +- .../wasi/filesystem/v0.2.0/types/types.wit.go | 2 +- src/internal/wasi/io/v0.2.0/error/error.wit.go | 2 +- src/internal/wasi/io/v0.2.0/poll/poll.wit.go | 2 +- src/internal/wasi/io/v0.2.0/streams/streams.wit.go | 2 +- .../wasi/random/v0.2.0/insecure/insecure.wit.go | 2 +- .../wasi/random/v0.2.0/random/random.wit.go | 2 +- .../instance-network/instance-network.wit.go | 2 +- .../wasi/sockets/v0.2.0/ip-name-lookup/abi.go | 2 +- .../v0.2.0/ip-name-lookup/ip-name-lookup.wit.go | 2 +- .../wasi/sockets/v0.2.0/network/network.wit.go | 2 +- .../tcp-create-socket/tcp-create-socket.wit.go | 2 +- src/internal/wasi/sockets/v0.2.0/tcp/abi.go | 2 +- src/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go | 2 +- .../udp-create-socket/udp-create-socket.wit.go | 2 +- src/internal/wasi/sockets/v0.2.0/udp/abi.go | 2 +- src/internal/wasi/sockets/v0.2.0/udp/udp.wit.go | 2 +- src/runtime/runtime_tinygowasmp2.go | 4 +- src/syscall/libc_wasip2.go | 4 +- src/vendor/github.com/ydnar/wasm-tools-go | 1 - 50 files changed, 760 insertions(+), 46 deletions(-) create mode 100644 internal/wasm-tools/README.md create mode 100644 internal/wasm-tools/go.mod create mode 100644 internal/wasm-tools/go.sum create mode 100644 internal/wasm-tools/tools.go create mode 100644 src/internal/cm/abi.go create mode 100644 src/internal/cm/docs.go create mode 100644 src/internal/cm/list.go create mode 100644 src/internal/cm/option.go create mode 100644 src/internal/cm/resource.go create mode 100644 src/internal/cm/result.go create mode 100644 src/internal/cm/tuple.go create mode 100644 src/internal/cm/variant.go delete mode 160000 src/vendor/github.com/ydnar/wasm-tools-go diff --git a/.gitmodules b/.gitmodules index edd7b215c..4a8820e3a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -42,6 +42,3 @@ [submodule "lib/wasi-cli"] path = lib/wasi-cli url = https://github.com/WebAssembly/wasi-cli -[submodule "src/vendor/github.com/ydnar/wasm-tools-go"] - path = src/vendor/github.com/ydnar/wasm-tools-go - url = https://github.com/ydnar/wasm-tools-go.git diff --git a/GNUmakefile b/GNUmakefile index 3fc7275db..f2f5e2f53 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -269,9 +269,16 @@ lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a: cd lib/wasi-libc && $(MAKE) -j4 EXTRA_CFLAGS="-O2 -g -DNDEBUG -mnontrapping-fptoint -msign-ext" MALLOC_IMPL=none CC="$(CLANG)" AR=$(LLVM_AR) NM=$(LLVM_NM) # Generate WASI syscall bindings +WASM_TOOLS_MODULE=github.com/ydnar/wasm-tools-go .PHONY: wasi-syscall -wasi-syscall: - wit-bindgen-go generate -o ./src/internal -p internal --versioned ./lib/wasi-cli/wit +wasi-syscall: wasi-cm + go run -modfile ./internal/wasm-tools/go.mod $(WASM_TOOLS_MODULE)/cmd/wit-bindgen-go generate --versioned -o ./src/internal -p internal --cm internal/cm ./lib/wasi-cli/wit + +# Copy package cm into src/internal/cm +.PHONY: wasi-cm +wasi-cm: + # rm -rf ./src/internal/cm + rsync -rv --delete --exclude '*_test.go' $(shell go list -modfile ./internal/wasm-tools/go.mod -m -f {{.Dir}} $(WASM_TOOLS_MODULE))/cm ./src/internal/ # Check for Node.js used during WASM tests. NODEJS_VERSION := $(word 1,$(subst ., ,$(shell node -v | cut -c 2-))) @@ -946,6 +953,11 @@ release: build/release deb: build/release endif +.PHONY: tools +tools: + go generate -C ./internal/tools -tags tools ./ + +.PHONY: lint lint: go run github.com/mgechev/revive -version # TODO: lint more directories! @@ -954,6 +966,7 @@ lint: # Use 'grep .' to get rid of stray blank line go run github.com/mgechev/revive -config revive.toml compiler/... src/{os,reflect}/*.go | grep -v "should have comment or be unexported" | grep '.' | awk '{print}; END {exit NR>0}' +.PHONY: spell spell: - # Check for typos in comments. Skip git submodules etc. + # Check for typos in comments. Skip git submodules etc. go run github.com/client9/misspell/cmd/misspell -i 'ackward,devided,extint,inbetween,programmmer,rela' $$( find . -depth 1 -type d | egrep -w -v 'lib|llvm|src/net' ) diff --git a/internal/tools/tools.go b/internal/tools/tools.go index cda689101..d592921a5 100644 --- a/internal/tools/tools.go +++ b/internal/tools/tools.go @@ -1,10 +1,13 @@ //go:build tools -// Install linter versions specified in go.mod -// See https://marcofranssen.nl/manage-go-tools-via-go-modules for idom +// Install tools specified in go.mod. +// See https://marcofranssen.nl/manage-go-tools-via-go-modules for idiom. package tools import ( _ "github.com/client9/misspell" _ "github.com/mgechev/revive" ) + +//go:generate go install github.com/client9/misspell/cmd/misspell +//go:generate go install github.com/mgechev/revive diff --git a/internal/wasm-tools/README.md b/internal/wasm-tools/README.md new file mode 100644 index 000000000..5e3a94ec6 --- /dev/null +++ b/internal/wasm-tools/README.md @@ -0,0 +1,5 @@ +# wasm-tools directory + +This directory has a separate `go.mod` file because the `wasm-tools-go` module requires Go 1.22, while TinyGo itself supports Go 1.19. + +When the minimum Go version for TinyGo is 1.22, this directory can be folded into `internal/tools` and the `go.mod` and `go.sum` files deleted. diff --git a/internal/wasm-tools/go.mod b/internal/wasm-tools/go.mod new file mode 100644 index 000000000..8a0e49351 --- /dev/null +++ b/internal/wasm-tools/go.mod @@ -0,0 +1,12 @@ +module github.com/tinygo-org/tinygo/internal/tools + +go 1.22.4 + +require github.com/ydnar/wasm-tools-go v0.1.4 + +require ( + github.com/coreos/go-semver v0.3.1 // indirect + github.com/urfave/cli/v3 v3.0.0-alpha9 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + golang.org/x/mod v0.19.0 // indirect +) diff --git a/internal/wasm-tools/go.sum b/internal/wasm-tools/go.sum new file mode 100644 index 000000000..b2d0b1e3a --- /dev/null +++ b/internal/wasm-tools/go.sum @@ -0,0 +1,25 @@ +github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= +github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= +github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/urfave/cli/v3 v3.0.0-alpha9 h1:P0RMy5fQm1AslQS+XCmy9UknDXctOmG/q/FZkUFnJSo= +github.com/urfave/cli/v3 v3.0.0-alpha9/go.mod h1:0kK/RUFHyh+yIKSfWxwheGndfnrvYSmYFVeKCh03ZUc= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/ydnar/wasm-tools-go v0.1.4 h1:+25WqBj0AhLx8OFvZvrs7bQO6L3WtQ7t6JzQEYsXQb8= +github.com/ydnar/wasm-tools-go v0.1.4/go.mod h1:lQfv2Tde3tRgZDSYriro0EmdSHzP1mrHPMmYNahSS/g= +golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= +golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg= +golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/wasm-tools/tools.go b/internal/wasm-tools/tools.go new file mode 100644 index 000000000..c8eb42fde --- /dev/null +++ b/internal/wasm-tools/tools.go @@ -0,0 +1,11 @@ +//go:build tools + +// Install tools specified in go.mod. +// See https://marcofranssen.nl/manage-go-tools-via-go-modules for idiom. +package tools + +import ( + _ "github.com/ydnar/wasm-tools-go/cmd/wit-bindgen-go" +) + +//go:generate go install github.com/ydnar/wasm-tools-go/cmd/wit-bindgen-go diff --git a/loader/goroot.go b/loader/goroot.go index 72b2f3335..8661bf67e 100644 --- a/loader/goroot.go +++ b/loader/goroot.go @@ -238,6 +238,7 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool { "internal/": true, "internal/binary/": false, "internal/bytealg/": false, + "internal/cm/": false, "internal/fuzz/": false, "internal/reflectlite/": false, "internal/task/": false, @@ -251,8 +252,6 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool { "runtime/": false, "sync/": true, "testing/": true, - "vendor/": true, - "vendor/github.com/": false, } if goMinor >= 19 { diff --git a/src/internal/cm/abi.go b/src/internal/cm/abi.go new file mode 100644 index 000000000..91ca1be32 --- /dev/null +++ b/src/internal/cm/abi.go @@ -0,0 +1,118 @@ +package cm + +import "unsafe" + +// Reinterpret reinterprets the bits of type From into type T. +// Will panic if the size of From is smaller than the size of To. +func Reinterpret[T, From any](from From) (to T) { + if unsafe.Sizeof(to) > unsafe.Sizeof(from) { + panic("reinterpret: size of to > from") + } + return *(*T)(unsafe.Pointer(&from)) +} + +// LowerString lowers a [string] into a pair of Core WebAssembly types. +// +// [string]: https://pkg.go.dev/builtin#string +func LowerString[S ~string](s S) (*byte, uint32) { + return unsafe.StringData(string(s)), uint32(len(s)) +} + +// LiftString lifts Core WebAssembly types into a [string]. +func LiftString[T ~string, Data unsafe.Pointer | uintptr | *uint8, Len uint | uintptr | uint32 | uint64](data Data, len Len) T { + return T(unsafe.String((*uint8)(unsafe.Pointer(data)), int(len))) +} + +// LowerList lowers a [List] into a pair of Core WebAssembly types. +func LowerList[L ~struct{ list[T] }, T any](list L) (*T, uint32) { + l := (*List[T])(unsafe.Pointer(&list)) + return l.data, uint32(l.len) +} + +// LiftList lifts Core WebAssembly types into a [List]. +func LiftList[L List[T], T any, Data unsafe.Pointer | uintptr | *T, Len uint | uintptr | uint32 | uint64](data Data, len Len) L { + return L(NewList((*T)(unsafe.Pointer(data)), uint(len))) +} + +// BoolToU32 converts a value whose underlying type is [bool] into a [uint32]. +// Used to lower a [bool] into a Core WebAssembly i32 as specified in the [Canonical ABI]. +// +// [bool]: https://pkg.go.dev/builtin#bool +// [uint32]: https://pkg.go.dev/builtin#uint32 +// [Canonical ABI]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md +func BoolToU32[B ~bool](v B) uint32 { return uint32(*(*uint8)(unsafe.Pointer(&v))) } + +// U32ToBool converts a [uint32] into a [bool]. +// Used to lift a Core WebAssembly i32 into a [bool] as specified in the [Canonical ABI]. +// +// [uint32]: https://pkg.go.dev/builtin#uint32 +// [bool]: https://pkg.go.dev/builtin#bool +// [Canonical ABI]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md +func U32ToBool(v uint32) bool { tmp := uint8(v); return *(*bool)(unsafe.Pointer(&tmp)) } + +// F32ToU32 maps the bits of a [float32] into a [uint32]. +// Used to lower a [float32] into a Core WebAssembly i32 as specified in the [Canonical ABI]. +// +// [Canonical ABI]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md +// [float32]: https://pkg.go.dev/builtin#float32 +// [uint32]: https://pkg.go.dev/builtin#uint32 +func F32ToU32(v float32) uint32 { return *(*uint32)(unsafe.Pointer(&v)) } + +// U32ToF32 maps the bits of a [uint32] into a [float32]. +// Used to lift a Core WebAssembly i32 into a [float32] as specified in the [Canonical ABI]. +// +// [uint32]: https://pkg.go.dev/builtin#uint32 +// [float32]: https://pkg.go.dev/builtin#float32 +// [Canonical ABI]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md +func U32ToF32(v uint32) float32 { return *(*float32)(unsafe.Pointer(&v)) } + +// F64ToU64 maps the bits of a [float64] into a [uint64]. +// Used to lower a [float64] into a Core WebAssembly i64 as specified in the [Canonical ABI]. +// +// [float64]: https://pkg.go.dev/builtin#float64 +// [uint64]: https://pkg.go.dev/builtin#uint64 +// [Canonical ABI]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md +// +// [uint32]: https://pkg.go.dev/builtin#uint32 +func F64ToU64(v float64) uint64 { return *(*uint64)(unsafe.Pointer(&v)) } + +// U64ToF64 maps the bits of a [uint64] into a [float64]. +// Used to lift a Core WebAssembly i64 into a [float64] as specified in the [Canonical ABI]. +// +// [uint64]: https://pkg.go.dev/builtin#uint64 +// [float64]: https://pkg.go.dev/builtin#float64 +// [Canonical ABI]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md +func U64ToF64(v uint64) float64 { return *(*float64)(unsafe.Pointer(&v)) } + +// PointerToU32 converts a pointer of type *T into a [uint32]. +// Used to lower a pointer into a Core WebAssembly i32 as specified in the [Canonical ABI]. +// +// [uint32]: https://pkg.go.dev/builtin#uint32 +// [Canonical ABI]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md +func PointerToU32[T any](v *T) uint32 { return uint32(uintptr(unsafe.Pointer(v))) } + +// U32ToPointer converts a [uint32] into a pointer of type *T. +// Used to lift a Core WebAssembly i32 into a pointer as specified in the [Canonical ABI]. +// +// [uint32]: https://pkg.go.dev/builtin#uint32 +// [Canonical ABI]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md +func U32ToPointer[T any](v uint32) *T { return (*T)(unsafePointer(uintptr(v))) } + +// PointerToU64 converts a pointer of type *T into a [uint64]. +// Used to lower a pointer into a Core WebAssembly i64 as specified in the [Canonical ABI]. +// +// [uint64]: https://pkg.go.dev/builtin#uint64 +// [Canonical ABI]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md +func PointerToU64[T any](v *T) uint64 { return uint64(uintptr(unsafe.Pointer(v))) } + +// U64ToPointer converts a [uint64] into a pointer of type *T. +// Used to lift a Core WebAssembly i64 into a pointer as specified in the [Canonical ABI]. +// +// [uint64]: https://pkg.go.dev/builtin#uint64 +// [Canonical ABI]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md +func U64ToPointer[T any](v uint64) *T { return (*T)(unsafePointer(uintptr(v))) } + +// Appease vet, see https://github.com/golang/go/issues/58625 +func unsafePointer(p uintptr) unsafe.Pointer { + return *(*unsafe.Pointer)(unsafe.Pointer(&p)) +} diff --git a/src/internal/cm/docs.go b/src/internal/cm/docs.go new file mode 100644 index 000000000..5fc48fb75 --- /dev/null +++ b/src/internal/cm/docs.go @@ -0,0 +1,8 @@ +// Package cm contains types and functions for interfacing with the WebAssembly Component Model. +// +// The types in this package (such as [List], [Option], [Result], and [Variant]) are designed to match the memory layout +// of [Component Model] types as specified in the [Canonical ABI]. +// +// [Component Model]: https://component-model.bytecodealliance.org/introduction.html +// [Canonical ABI]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md#alignment +package cm diff --git a/src/internal/cm/list.go b/src/internal/cm/list.go new file mode 100644 index 000000000..e170efbed --- /dev/null +++ b/src/internal/cm/list.go @@ -0,0 +1,48 @@ +package cm + +import "unsafe" + +// List represents a Component Model list. +// The binary representation of list is similar to a Go slice minus the cap field. +type List[T any] struct{ list[T] } + +// NewList returns a List[T] from data and len. +func NewList[T any](data *T, len uint) List[T] { + return List[T]{ + list[T]{ + data: data, + len: len, + }, + } +} + +// ToList returns a List[T] equivalent to the Go slice s. +// The underlying slice data is not copied, and the resulting List points at the +// same array storage as the slice. +func ToList[S ~[]T, T any](s S) List[T] { + return NewList[T](unsafe.SliceData([]T(s)), uint(len(s))) +} + +// list represents the internal representation of a Component Model list. +// It is intended to be embedded in a [List], so embedding types maintain +// the methods defined on this type. +type list[T any] struct { + data *T + len uint +} + +// Slice returns a Go slice representing the List. +func (l list[T]) Slice() []T { + return unsafe.Slice(l.data, l.len) +} + +// Data returns the data pointer for the list. +func (l list[T]) Data() *T { + return l.data +} + +// Len returns the length of the list. +// TODO: should this return an int instead of a uint? +func (l list[T]) Len() uint { + return l.len +} diff --git a/src/internal/cm/option.go b/src/internal/cm/option.go new file mode 100644 index 000000000..edc288b4c --- /dev/null +++ b/src/internal/cm/option.go @@ -0,0 +1,44 @@ +package cm + +// Option represents a Component Model [option] type. +// +// [option]: https://component-model.bytecodealliance.org/design/wit.html#options +type Option[T any] struct{ option[T] } + +// None returns an [Option] representing the none case, +// equivalent to the zero value. +func None[T any]() Option[T] { + return Option[T]{} +} + +// Some returns an [Option] representing the some case. +func Some[T any](v T) Option[T] { + return Option[T]{ + option[T]{ + isSome: true, + some: v, + }, + } +} + +// option represents the internal representation of a Component Model option type. +// The first byte is a bool representing none or some, +// followed by storage for the associated type T. +type option[T any] struct { + isSome bool + some T +} + +// None returns true if o represents the none case. +func (o *option[T]) None() bool { + return !o.isSome +} + +// Some returns a non-nil *T if o represents the some case, +// or nil if o represents the none case. +func (o *option[T]) Some() *T { + if o.isSome { + return &o.some + } + return nil +} diff --git a/src/internal/cm/resource.go b/src/internal/cm/resource.go new file mode 100644 index 000000000..830d76591 --- /dev/null +++ b/src/internal/cm/resource.go @@ -0,0 +1,21 @@ +package cm + +// Resource represents an opaque Component Model [resource handle]. +// It is represented in the [Canonical ABI] as an 32-bit integer. +// +// [resource handle]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#handle-types +// [Canonical ABI]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md +type Resource uint32 + +// Rep represents a Component Model [resource rep], the core representation type of a resource. +// It is represented in the [Canonical ABI] as an 32-bit integer. +// +// [resource rep]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md#canon-resourcerep +// [Canonical ABI]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md +type Rep uint32 + +// ResourceNone is a sentinel value indicating a null or uninitialized resource. +// This is a reserved value specified in the [Canonical ABI runtime state]. +// +// [Canonical ABI runtime state]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md#runtime-state +const ResourceNone = 0 diff --git a/src/internal/cm/result.go b/src/internal/cm/result.go new file mode 100644 index 000000000..d21275612 --- /dev/null +++ b/src/internal/cm/result.go @@ -0,0 +1,107 @@ +package cm + +import "unsafe" + +const ( + // ResultOK represents the OK case of a result. + ResultOK = false + + // ResultErr represents the error case of a result. + ResultErr = true +) + +// BoolResult represents a result with no OK or error type. +// False represents the OK case and true represents the error case. +type BoolResult bool + +// Result represents a result sized to hold the Shape type. +// The size of the Shape type must be greater than or equal to the size of OK and Err types. +// For results with two zero-length types, use [BoolResult]. +type Result[Shape, OK, Err any] struct{ result[Shape, OK, Err] } + +// result represents the internal representation of a Component Model result type. +type result[Shape, OK, Err any] struct { + isErr bool + _ [0]OK + _ [0]Err + data Shape // [unsafe.Sizeof(*(*Shape)(unsafe.Pointer(nil)))]byte +} + +// IsOK returns true if r represents the OK case. +func (r *result[Shape, OK, Err]) IsOK() bool { + r.validate() + return !r.isErr +} + +// IsErr returns true if r represents the error case. +func (r *result[Shape, OK, Err]) IsErr() bool { + r.validate() + return r.isErr +} + +// OK returns a non-nil *OK pointer if r represents the OK case. +// If r represents an error, then it returns nil. +func (r *result[Shape, OK, Err]) OK() *OK { + r.validate() + if r.isErr { + return nil + } + return (*OK)(unsafe.Pointer(&r.data)) +} + +// Err returns a non-nil *Err pointer if r represents the error case. +// If r represents the OK case, then it returns nil. +func (r *result[Shape, OK, Err]) Err() *Err { + r.validate() + if !r.isErr { + return nil + } + return (*Err)(unsafe.Pointer(&r.data)) +} + +// This function is sized so it can be inlined and optimized away. +func (r *result[Shape, OK, Err]) validate() { + var shape Shape + var ok OK + var err Err + + // Check if size of Shape is greater than both OK and Err + if unsafe.Sizeof(shape) > unsafe.Sizeof(ok) && unsafe.Sizeof(shape) > unsafe.Sizeof(err) { + panic("result: size of data type > OK and Err types") + } + + // Check if size of OK is greater than Shape + if unsafe.Sizeof(ok) > unsafe.Sizeof(shape) { + panic("result: size of OK type > data type") + } + + // Check if size of Err is greater than Shape + if unsafe.Sizeof(err) > unsafe.Sizeof(shape) { + panic("result: size of Err type > data type") + } + + // Check if Shape is zero-sized, but size of result != 1 + if unsafe.Sizeof(shape) == 0 && unsafe.Sizeof(*r) != 1 { + panic("result: size of data type == 0, but result size != 1") + } +} + +// OK returns an OK result with shape Shape and type OK and Err. +// Pass Result[OK, OK, Err] or Result[Err, OK, Err] as the first type argument. +func OK[R ~struct{ result[Shape, OK, Err] }, Shape, OK, Err any](ok OK) R { + var r struct{ result[Shape, OK, Err] } + r.validate() + r.isErr = ResultOK + *((*OK)(unsafe.Pointer(&r.data))) = ok + return R(r) +} + +// Err returns an error result with shape Shape and type OK and Err. +// Pass Result[OK, OK, Err] or Result[Err, OK, Err] as the first type argument. +func Err[R ~struct{ result[Shape, OK, Err] }, Shape, OK, Err any](err Err) R { + var r struct{ result[Shape, OK, Err] } + r.validate() + r.isErr = ResultErr + *((*Err)(unsafe.Pointer(&r.data))) = err + return R(r) +} diff --git a/src/internal/cm/tuple.go b/src/internal/cm/tuple.go new file mode 100644 index 000000000..7b0e535c0 --- /dev/null +++ b/src/internal/cm/tuple.go @@ -0,0 +1,230 @@ +package cm + +// Tuple represents a [Component Model tuple] with 2 fields. +// +// [Component Model tuple]: https://component-model.bytecodealliance.org/design/wit.html#tuples +type Tuple[T0, T1 any] struct { + F0 T0 + F1 T1 +} + +// Tuple3 represents a [Component Model tuple] with 3 fields. +// +// [Component Model tuple]: https://component-model.bytecodealliance.org/design/wit.html#tuples +type Tuple3[T0, T1, T2 any] struct { + F0 T0 + F1 T1 + F2 T2 +} + +// Tuple4 represents a [Component Model tuple] with 4 fields. +// +// [Component Model tuple]: https://component-model.bytecodealliance.org/design/wit.html#tuples +type Tuple4[T0, T1, T2, T3 any] struct { + F0 T0 + F1 T1 + F2 T2 + F3 T3 +} + +// Tuple5 represents a [Component Model tuple] with 5 fields. +// +// [Component Model tuple]: https://component-model.bytecodealliance.org/design/wit.html#tuples +type Tuple5[T0, T1, T2, T3, T4 any] struct { + F0 T0 + F1 T1 + F2 T2 + F3 T3 + F4 T4 +} + +// Tuple6 represents a [Component Model tuple] with 6 fields. +// +// [Component Model tuple]: https://component-model.bytecodealliance.org/design/wit.html#tuples +type Tuple6[T0, T1, T2, T3, T4, T5 any] struct { + F0 T0 + F1 T1 + F2 T2 + F3 T3 + F4 T4 + F5 T5 +} + +// Tuple7 represents a [Component Model tuple] with 7 fields. +// +// [Component Model tuple]: https://component-model.bytecodealliance.org/design/wit.html#tuples +type Tuple7[T0, T1, T2, T3, T4, T5, T6 any] struct { + F0 T0 + F1 T1 + F2 T2 + F3 T3 + F4 T4 + F5 T5 + F6 T6 +} + +// Tuple8 represents a [Component Model tuple] with 8 fields. +// +// [Component Model tuple]: https://component-model.bytecodealliance.org/design/wit.html#tuples +type Tuple8[T0, T1, T2, T3, T4, T5, T6, T7 any] struct { + F0 T0 + F1 T1 + F2 T2 + F3 T3 + F4 T4 + F5 T5 + F6 T6 + F7 T7 +} + +// Tuple9 represents a [Component Model tuple] with 9 fields. +// +// [Component Model tuple]: https://component-model.bytecodealliance.org/design/wit.html#tuples +type Tuple9[T0, T1, T2, T3, T4, T5, T6, T7, T8 any] struct { + F0 T0 + F1 T1 + F2 T2 + F3 T3 + F4 T4 + F5 T5 + F6 T6 + F7 T7 + F8 T8 +} + +// Tuple10 represents a [Component Model tuple] with 10 fields. +// +// [Component Model tuple]: https://component-model.bytecodealliance.org/design/wit.html#tuples +type Tuple10[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9 any] struct { + F0 T0 + F1 T1 + F2 T2 + F3 T3 + F4 T4 + F5 T5 + F6 T6 + F7 T7 + F8 T8 + F9 T9 +} + +// Tuple11 represents a [Component Model tuple] with 11 fields. +// +// [Component Model tuple]: https://component-model.bytecodealliance.org/design/wit.html#tuples +type Tuple11[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 any] struct { + F0 T0 + F1 T1 + F2 T2 + F3 T3 + F4 T4 + F5 T5 + F6 T6 + F7 T7 + F8 T8 + F9 T9 + F10 T10 +} + +// Tuple12 represents a [Component Model tuple] with 12 fields. +// +// [Component Model tuple]: https://component-model.bytecodealliance.org/design/wit.html#tuples +type Tuple12[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 any] struct { + F0 T0 + F1 T1 + F2 T2 + F3 T3 + F4 T4 + F5 T5 + F6 T6 + F7 T7 + F8 T8 + F9 T9 + F10 T10 + F11 T11 +} + +// Tuple13 represents a [Component Model tuple] with 13 fields. +// +// [Component Model tuple]: https://component-model.bytecodealliance.org/design/wit.html#tuples +type Tuple13[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 any] struct { + F0 T0 + F1 T1 + F2 T2 + F3 T3 + F4 T4 + F5 T5 + F6 T6 + F7 T7 + F8 T8 + F9 T9 + F10 T10 + F11 T11 + F12 T12 +} + +// Tuple14 represents a [Component Model tuple] with 14 fields. +// +// [Component Model tuple]: https://component-model.bytecodealliance.org/design/wit.html#tuples +type Tuple14[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 any] struct { + F0 T0 + F1 T1 + F2 T2 + F3 T3 + F4 T4 + F5 T5 + F6 T6 + F7 T7 + F8 T8 + F9 T9 + F10 T10 + F11 T11 + F12 T12 + F13 T13 +} + +// Tuple15 represents a [Component Model tuple] with 15 fields. +// +// [Component Model tuple]: https://component-model.bytecodealliance.org/design/wit.html#tuples +type Tuple15[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 any] struct { + F0 T0 + F1 T1 + F2 T2 + F3 T3 + F4 T4 + F5 T5 + F6 T6 + F7 T7 + F8 T8 + F9 T9 + F10 T10 + F11 T11 + F12 T12 + F13 T13 + F14 T14 +} + +// Tuple16 represents a [Component Model tuple] with 16 fields. +// +// [Component Model tuple]: https://component-model.bytecodealliance.org/design/wit.html#tuples +type Tuple16[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 any] struct { + F0 T0 + F1 T1 + F2 T2 + F3 T3 + F4 T4 + F5 T5 + F6 T6 + F7 T7 + F8 T8 + F9 T9 + F10 T10 + F11 T11 + F12 T12 + F13 T13 + F14 T14 + F15 T15 +} + +// MaxTuple specifies the maximum number of fields in a Tuple* type, currently [Tuple16]. +// See https://github.com/WebAssembly/component-model/issues/373 for more information. +const MaxTuple = 16 diff --git a/src/internal/cm/variant.go b/src/internal/cm/variant.go new file mode 100644 index 000000000..5ae5cf381 --- /dev/null +++ b/src/internal/cm/variant.go @@ -0,0 +1,74 @@ +package cm + +import "unsafe" + +// Discriminant is the set of types that can represent the tag or discriminator of a variant. +// Use bool for 2-case variant types, result, or option types, uint8 where there are 256 or +// fewer cases, uint16 for up to 65,536 cases, or uint32 for anything greater. +type Discriminant interface { + bool | uint8 | uint16 | uint32 +} + +// Variant represents a loosely-typed Component Model variant. +// Shape and Align must be non-zero sized types. To create a variant with no associated +// types, use an enum. +type Variant[Tag Discriminant, Shape, Align any] struct{ variant[Tag, Shape, Align] } + +// NewVariant returns a [Variant] with tag of type Disc, storage and GC shape of type Shape, +// aligned to type Align, with a value of type T. +func NewVariant[Tag Discriminant, Shape, Align any, T any](tag Tag, data T) Variant[Tag, Shape, Align] { + validateVariant[Tag, Shape, Align, T]() + var v Variant[Tag, Shape, Align] + v.tag = tag + *(*T)(unsafe.Pointer(&v.data)) = data + return v +} + +// New returns a [Variant] with tag of type Disc, storage and GC shape of type Shape, +// aligned to type Align, with a value of type T. +func New[V ~struct{ variant[Tag, Shape, Align] }, Tag Discriminant, Shape, Align any, T any](tag Tag, data T) V { + validateVariant[Tag, Shape, Align, T]() + var v variant[Tag, Shape, Align] + v.tag = tag + *(*T)(unsafe.Pointer(&v.data)) = data + return *(*V)(unsafe.Pointer(&v)) +} + +// Case returns a non-nil *T if the [Variant] case is equal to tag, otherwise it returns nil. +func Case[T any, V ~struct{ variant[Tag, Shape, Align] }, Tag Discriminant, Shape, Align any](v *V, tag Tag) *T { + validateVariant[Tag, Shape, Align, T]() + v2 := (*variant[Tag, Shape, Align])(unsafe.Pointer(v)) + if v2.tag == tag { + return (*T)(unsafe.Pointer(&v2.data)) + } + return nil +} + +// variant is the internal representation of a Component Model variant. +// Shape and Align must be non-zero sized types. +type variant[Tag Discriminant, Shape, Align any] struct { + tag Tag + _ [0]Align + data Shape // [unsafe.Sizeof(*(*Shape)(unsafe.Pointer(nil)))]byte +} + +// Tag returns the tag (discriminant) of variant v. +func (v *variant[Tag, Shape, Align]) Tag() Tag { + return v.tag +} + +// This function is sized so it can be inlined and optimized away. +func validateVariant[Disc Discriminant, Shape, Align any, T any]() { + var v variant[Disc, Shape, Align] + var t T + + // Check if size of T is greater than Shape + if unsafe.Sizeof(t) > unsafe.Sizeof(v.data) { + panic("variant: size of requested type > data type") + } + + // Check if Shape is zero-sized, but size of result != 1 + if unsafe.Sizeof(v.data) == 0 && unsafe.Sizeof(v) != 1 { + panic("variant: size of data type == 0, but variant size != 1") + } +} diff --git a/src/internal/wasi/cli/v0.2.0/environment/environment.wit.go b/src/internal/wasi/cli/v0.2.0/environment/environment.wit.go index b75e74b18..81fec996a 100644 --- a/src/internal/wasi/cli/v0.2.0/environment/environment.wit.go +++ b/src/internal/wasi/cli/v0.2.0/environment/environment.wit.go @@ -6,7 +6,7 @@ package environment import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" ) // GetEnvironment represents the imported function "get-environment". diff --git a/src/internal/wasi/cli/v0.2.0/exit/exit.wit.go b/src/internal/wasi/cli/v0.2.0/exit/exit.wit.go index d10b734c6..24aa1b561 100644 --- a/src/internal/wasi/cli/v0.2.0/exit/exit.wit.go +++ b/src/internal/wasi/cli/v0.2.0/exit/exit.wit.go @@ -6,7 +6,7 @@ package exit import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" ) // Exit represents the imported function "exit". diff --git a/src/internal/wasi/cli/v0.2.0/run/run.exports.go b/src/internal/wasi/cli/v0.2.0/run/run.exports.go index 3d0edcc80..8dfaedec2 100644 --- a/src/internal/wasi/cli/v0.2.0/run/run.exports.go +++ b/src/internal/wasi/cli/v0.2.0/run/run.exports.go @@ -5,7 +5,7 @@ package run import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" ) // Exports represents the caller-defined exports from "wasi:cli/run@0.2.0". diff --git a/src/internal/wasi/cli/v0.2.0/run/run.wit.go b/src/internal/wasi/cli/v0.2.0/run/run.wit.go index 47e00180c..22e7fc432 100644 --- a/src/internal/wasi/cli/v0.2.0/run/run.wit.go +++ b/src/internal/wasi/cli/v0.2.0/run/run.wit.go @@ -6,7 +6,7 @@ package run import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" ) //go:wasmexport wasi:cli/run@0.2.0#run diff --git a/src/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go b/src/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go index fd2b7517c..b57323715 100644 --- a/src/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go +++ b/src/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go @@ -6,7 +6,7 @@ package stderr import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" "internal/wasi/io/v0.2.0/streams" ) diff --git a/src/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go b/src/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go index abe35cbbb..664ca14be 100644 --- a/src/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go +++ b/src/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go @@ -6,7 +6,7 @@ package stdin import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" "internal/wasi/io/v0.2.0/streams" ) diff --git a/src/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go b/src/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go index 2f56b19ec..6b2b28aac 100644 --- a/src/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go +++ b/src/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go @@ -6,7 +6,7 @@ package stdout import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" "internal/wasi/io/v0.2.0/streams" ) diff --git a/src/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go b/src/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go index 478864428..318a91ac7 100644 --- a/src/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go +++ b/src/internal/wasi/cli/v0.2.0/terminal-input/terminal-input.wit.go @@ -12,7 +12,7 @@ package terminalinput import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" ) // TerminalInput represents the imported resource "wasi:cli/terminal-input@0.2.0#terminal-input". diff --git a/src/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go b/src/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go index 759348b85..6e56faf40 100644 --- a/src/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go +++ b/src/internal/wasi/cli/v0.2.0/terminal-output/terminal-output.wit.go @@ -12,7 +12,7 @@ package terminaloutput import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" ) // TerminalOutput represents the imported resource "wasi:cli/terminal-output@0.2.0#terminal-output". diff --git a/src/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go b/src/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go index db720e151..d9e32838c 100644 --- a/src/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go +++ b/src/internal/wasi/cli/v0.2.0/terminal-stderr/terminal-stderr.wit.go @@ -9,7 +9,7 @@ package terminalstderr import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" terminaloutput "internal/wasi/cli/v0.2.0/terminal-output" ) diff --git a/src/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go b/src/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go index 091d8e8c5..834864f8e 100644 --- a/src/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go +++ b/src/internal/wasi/cli/v0.2.0/terminal-stdin/terminal-stdin.wit.go @@ -9,7 +9,7 @@ package terminalstdin import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" terminalinput "internal/wasi/cli/v0.2.0/terminal-input" ) diff --git a/src/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go b/src/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go index d0d9bfe48..7dbb2cab1 100644 --- a/src/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go +++ b/src/internal/wasi/cli/v0.2.0/terminal-stdout/terminal-stdout.wit.go @@ -9,7 +9,7 @@ package terminalstdout import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" terminaloutput "internal/wasi/cli/v0.2.0/terminal-output" ) diff --git a/src/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go b/src/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go index 4c6803365..1b1ae5358 100644 --- a/src/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go +++ b/src/internal/wasi/clocks/v0.2.0/monotonic-clock/monotonic-clock.wit.go @@ -17,7 +17,7 @@ package monotonicclock import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" "internal/wasi/io/v0.2.0/poll" ) diff --git a/src/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go b/src/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go index d0b71bf11..4638a9a39 100644 --- a/src/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go +++ b/src/internal/wasi/filesystem/v0.2.0/preopens/preopens.wit.go @@ -6,7 +6,7 @@ package preopens import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" "internal/wasi/filesystem/v0.2.0/types" ) diff --git a/src/internal/wasi/filesystem/v0.2.0/types/abi.go b/src/internal/wasi/filesystem/v0.2.0/types/abi.go index 41f6848ec..136fb06c2 100644 --- a/src/internal/wasi/filesystem/v0.2.0/types/abi.go +++ b/src/internal/wasi/filesystem/v0.2.0/types/abi.go @@ -5,7 +5,7 @@ package types import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" wallclock "internal/wasi/clocks/v0.2.0/wall-clock" "unsafe" ) diff --git a/src/internal/wasi/filesystem/v0.2.0/types/types.wit.go b/src/internal/wasi/filesystem/v0.2.0/types/types.wit.go index 226edabd7..f1f139ed1 100644 --- a/src/internal/wasi/filesystem/v0.2.0/types/types.wit.go +++ b/src/internal/wasi/filesystem/v0.2.0/types/types.wit.go @@ -31,7 +31,7 @@ package types import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" wallclock "internal/wasi/clocks/v0.2.0/wall-clock" ioerror "internal/wasi/io/v0.2.0/error" "internal/wasi/io/v0.2.0/streams" diff --git a/src/internal/wasi/io/v0.2.0/error/error.wit.go b/src/internal/wasi/io/v0.2.0/error/error.wit.go index f962f22ea..aae635062 100644 --- a/src/internal/wasi/io/v0.2.0/error/error.wit.go +++ b/src/internal/wasi/io/v0.2.0/error/error.wit.go @@ -6,7 +6,7 @@ package ioerror import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" ) // Error represents the imported resource "wasi:io/error@0.2.0#error". diff --git a/src/internal/wasi/io/v0.2.0/poll/poll.wit.go b/src/internal/wasi/io/v0.2.0/poll/poll.wit.go index 0c362c079..274a8e8a4 100644 --- a/src/internal/wasi/io/v0.2.0/poll/poll.wit.go +++ b/src/internal/wasi/io/v0.2.0/poll/poll.wit.go @@ -9,7 +9,7 @@ package poll import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" ) // Pollable represents the imported resource "wasi:io/poll@0.2.0#pollable". diff --git a/src/internal/wasi/io/v0.2.0/streams/streams.wit.go b/src/internal/wasi/io/v0.2.0/streams/streams.wit.go index f3c1e3c35..317fdc882 100644 --- a/src/internal/wasi/io/v0.2.0/streams/streams.wit.go +++ b/src/internal/wasi/io/v0.2.0/streams/streams.wit.go @@ -12,7 +12,7 @@ package streams import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" ioerror "internal/wasi/io/v0.2.0/error" "internal/wasi/io/v0.2.0/poll" ) diff --git a/src/internal/wasi/random/v0.2.0/insecure/insecure.wit.go b/src/internal/wasi/random/v0.2.0/insecure/insecure.wit.go index fbea789b5..7b38f0118 100644 --- a/src/internal/wasi/random/v0.2.0/insecure/insecure.wit.go +++ b/src/internal/wasi/random/v0.2.0/insecure/insecure.wit.go @@ -11,7 +11,7 @@ package insecure import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" ) // GetInsecureRandomBytes represents the imported function "get-insecure-random-bytes". diff --git a/src/internal/wasi/random/v0.2.0/random/random.wit.go b/src/internal/wasi/random/v0.2.0/random/random.wit.go index f60d468e1..05b755623 100644 --- a/src/internal/wasi/random/v0.2.0/random/random.wit.go +++ b/src/internal/wasi/random/v0.2.0/random/random.wit.go @@ -11,7 +11,7 @@ package random import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" ) // GetRandomBytes represents the imported function "get-random-bytes". diff --git a/src/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go b/src/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go index fbd9dc8ad..e7d5f0ea7 100644 --- a/src/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go +++ b/src/internal/wasi/sockets/v0.2.0/instance-network/instance-network.wit.go @@ -8,7 +8,7 @@ package instancenetwork import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" "internal/wasi/sockets/v0.2.0/network" ) diff --git a/src/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go b/src/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go index 065c935e1..41714d9ec 100644 --- a/src/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go +++ b/src/internal/wasi/sockets/v0.2.0/ip-name-lookup/abi.go @@ -5,7 +5,7 @@ package ipnamelookup import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" "internal/wasi/sockets/v0.2.0/network" "unsafe" ) diff --git a/src/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go b/src/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go index 34ca3a6a0..dcd1fd9d9 100644 --- a/src/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go +++ b/src/internal/wasi/sockets/v0.2.0/ip-name-lookup/ip-name-lookup.wit.go @@ -6,7 +6,7 @@ package ipnamelookup import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" "internal/wasi/io/v0.2.0/poll" "internal/wasi/sockets/v0.2.0/network" ) diff --git a/src/internal/wasi/sockets/v0.2.0/network/network.wit.go b/src/internal/wasi/sockets/v0.2.0/network/network.wit.go index 7108f6d97..5f2403c43 100644 --- a/src/internal/wasi/sockets/v0.2.0/network/network.wit.go +++ b/src/internal/wasi/sockets/v0.2.0/network/network.wit.go @@ -6,7 +6,7 @@ package network import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" ) // Network represents the imported resource "wasi:sockets/network@0.2.0#network". diff --git a/src/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go b/src/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go index 06de81f96..20478aaae 100644 --- a/src/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go +++ b/src/internal/wasi/sockets/v0.2.0/tcp-create-socket/tcp-create-socket.wit.go @@ -6,7 +6,7 @@ package tcpcreatesocket import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" "internal/wasi/sockets/v0.2.0/network" "internal/wasi/sockets/v0.2.0/tcp" ) diff --git a/src/internal/wasi/sockets/v0.2.0/tcp/abi.go b/src/internal/wasi/sockets/v0.2.0/tcp/abi.go index 39ccd2f62..f986948e3 100644 --- a/src/internal/wasi/sockets/v0.2.0/tcp/abi.go +++ b/src/internal/wasi/sockets/v0.2.0/tcp/abi.go @@ -5,7 +5,7 @@ package tcp import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" "internal/wasi/io/v0.2.0/streams" "internal/wasi/sockets/v0.2.0/network" "unsafe" diff --git a/src/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go b/src/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go index c306afef9..e27871310 100644 --- a/src/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go +++ b/src/internal/wasi/sockets/v0.2.0/tcp/tcp.wit.go @@ -6,7 +6,7 @@ package tcp import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" monotonicclock "internal/wasi/clocks/v0.2.0/monotonic-clock" "internal/wasi/io/v0.2.0/poll" "internal/wasi/io/v0.2.0/streams" diff --git a/src/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go b/src/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go index b30bafaad..c06bc96c5 100644 --- a/src/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go +++ b/src/internal/wasi/sockets/v0.2.0/udp-create-socket/udp-create-socket.wit.go @@ -6,7 +6,7 @@ package udpcreatesocket import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" "internal/wasi/sockets/v0.2.0/network" "internal/wasi/sockets/v0.2.0/udp" ) diff --git a/src/internal/wasi/sockets/v0.2.0/udp/abi.go b/src/internal/wasi/sockets/v0.2.0/udp/abi.go index 47954d872..3783acdac 100644 --- a/src/internal/wasi/sockets/v0.2.0/udp/abi.go +++ b/src/internal/wasi/sockets/v0.2.0/udp/abi.go @@ -5,7 +5,7 @@ package udp import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" "internal/wasi/sockets/v0.2.0/network" "unsafe" ) diff --git a/src/internal/wasi/sockets/v0.2.0/udp/udp.wit.go b/src/internal/wasi/sockets/v0.2.0/udp/udp.wit.go index 075739876..41b8491c0 100644 --- a/src/internal/wasi/sockets/v0.2.0/udp/udp.wit.go +++ b/src/internal/wasi/sockets/v0.2.0/udp/udp.wit.go @@ -6,7 +6,7 @@ package udp import ( - "github.com/ydnar/wasm-tools-go/cm" + "internal/cm" "internal/wasi/io/v0.2.0/poll" "internal/wasi/sockets/v0.2.0/network" ) diff --git a/src/runtime/runtime_tinygowasmp2.go b/src/runtime/runtime_tinygowasmp2.go index 96d7db0ff..eb3c507fd 100644 --- a/src/runtime/runtime_tinygowasmp2.go +++ b/src/runtime/runtime_tinygowasmp2.go @@ -3,13 +3,13 @@ package runtime import ( + "internal/cm" + exit "internal/wasi/cli/v0.2.0/exit" stdout "internal/wasi/cli/v0.2.0/stdout" monotonicclock "internal/wasi/clocks/v0.2.0/monotonic-clock" wallclock "internal/wasi/clocks/v0.2.0/wall-clock" random "internal/wasi/random/v0.2.0/random" - - "github.com/ydnar/wasm-tools-go/cm" ) const putcharBufferSize = 120 diff --git a/src/syscall/libc_wasip2.go b/src/syscall/libc_wasip2.go index ea3d3327d..1e985c1da 100644 --- a/src/syscall/libc_wasip2.go +++ b/src/syscall/libc_wasip2.go @@ -7,6 +7,8 @@ package syscall import ( "unsafe" + "internal/cm" + "internal/wasi/cli/v0.2.0/environment" "internal/wasi/cli/v0.2.0/stderr" "internal/wasi/cli/v0.2.0/stdin" @@ -17,8 +19,6 @@ import ( ioerror "internal/wasi/io/v0.2.0/error" "internal/wasi/io/v0.2.0/streams" "internal/wasi/random/v0.2.0/random" - - "github.com/ydnar/wasm-tools-go/cm" ) func goString(cstr *byte) string { diff --git a/src/vendor/github.com/ydnar/wasm-tools-go b/src/vendor/github.com/ydnar/wasm-tools-go deleted file mode 160000 index 49f7d9208..000000000 --- a/src/vendor/github.com/ydnar/wasm-tools-go +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 49f7d9208ece21e46a1232189d664d649524b8cc -- cgit v1.2.3