From 86d7bb439b72c10a2c1c7b031df6575a47327420 Mon Sep 17 00:00:00 2001 From: Randy Reddig Date: Sun, 23 Jun 2024 08:57:48 -0700 Subject: [PATCH 1/3] src/vendor/github.com/ydnar/wasm-tools-go: update to HEAD of branch main --- src/vendor/github.com/ydnar/wasm-tools-go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vendor/github.com/ydnar/wasm-tools-go b/src/vendor/github.com/ydnar/wasm-tools-go index 478042fc23..ca8d06b46f 160000 --- a/src/vendor/github.com/ydnar/wasm-tools-go +++ b/src/vendor/github.com/ydnar/wasm-tools-go @@ -1 +1 @@ -Subproject commit 478042fc23c1ccb9837b2b280a098d6cee4cb955 +Subproject commit ca8d06b46fa45bdc90b76060fc9bbf7ab9af5eed From 3bca53b7e1cf3e06602a2322061be85ebc7afc23 Mon Sep 17 00:00:00 2001 From: Randy Reddig Date: Sun, 23 Jun 2024 11:07:08 -0700 Subject: [PATCH 2/3] internal/wasi: regenerate WASI 0.2 bindings with explicit lifting and lowering code --- .../wasi/cli/v0.2.0/command/command.wit.go | 6 + .../cli/v0.2.0/environment/environment.wit.go | 49 +- src/internal/wasi/cli/v0.2.0/exit/exit.wit.go | 10 +- .../wasi/cli/v0.2.0/run/run.exports.go | 19 + src/internal/wasi/cli/v0.2.0/run/run.wit.go | 21 +- .../wasi/cli/v0.2.0/stderr/stderr.wit.go | 18 +- .../wasi/cli/v0.2.0/stdin/stdin.wit.go | 18 +- .../wasi/cli/v0.2.0/stdout/stdout.wit.go | 18 +- .../terminal-input/terminal-input.wit.go | 12 +- .../terminal-output/terminal-output.wit.go | 12 +- .../terminal-stderr/terminal-stderr.wit.go | 16 +- .../terminal-stdin/terminal-stdin.wit.go | 16 +- .../terminal-stdout/terminal-stdout.wit.go | 16 +- .../monotonic-clock/monotonic-clock.wit.go | 76 +- .../v0.2.0/wall-clock/wall-clock.wit.go | 16 +- .../v0.2.0/preopens/preopens.wit.go | 16 +- .../wasi/filesystem/v0.2.0/types/abi.go | 27 + .../wasi/filesystem/v0.2.0/types/types.wit.go | 1951 +++++++++-------- .../wasi/io/v0.2.0/error/error.wit.go | 24 +- src/internal/wasi/io/v0.2.0/poll/poll.wit.go | 43 +- .../wasi/io/v0.2.0/streams/streams.wit.go | 296 +-- .../v0.2.0/insecure-seed/insecure-seed.wit.go | 9 +- .../random/v0.2.0/insecure/insecure.wit.go | 24 +- .../wasi/random/v0.2.0/random/random.wit.go | 24 +- .../instance-network/instance-network.wit.go | 18 +- .../ip-name-lookup/ip-name-lookup.wit.go | 68 +- .../sockets/v0.2.0/network/network.wit.go | 146 +- .../tcp-create-socket.wit.go | 34 +- src/internal/wasi/sockets/v0.2.0/tcp/abi.go | 71 + .../wasi/sockets/v0.2.0/tcp/tcp.wit.go | 398 ++-- .../udp-create-socket.wit.go | 34 +- src/internal/wasi/sockets/v0.2.0/udp/abi.go | 92 + .../wasi/sockets/v0.2.0/udp/udp.wit.go | 623 +++--- 33 files changed, 2193 insertions(+), 2028 deletions(-) create mode 100644 src/internal/wasi/cli/v0.2.0/command/command.wit.go create mode 100644 src/internal/wasi/cli/v0.2.0/run/run.exports.go create mode 100644 src/internal/wasi/filesystem/v0.2.0/types/abi.go create mode 100644 src/internal/wasi/sockets/v0.2.0/tcp/abi.go create mode 100644 src/internal/wasi/sockets/v0.2.0/udp/abi.go diff --git a/src/internal/wasi/cli/v0.2.0/command/command.wit.go b/src/internal/wasi/cli/v0.2.0/command/command.wit.go new file mode 100644 index 0000000000..be6dd30450 --- /dev/null +++ b/src/internal/wasi/cli/v0.2.0/command/command.wit.go @@ -0,0 +1,6 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +//go:build !wasip1 + +// Package command represents the world "wasi:cli/command@0.2.0". +package command 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 d2d41dcb28..b75e74b185 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 @@ -2,31 +2,14 @@ //go:build !wasip1 -// Package environment represents the interface "wasi:cli/environment@0.2.0". +// Package environment represents the imported interface "wasi:cli/environment@0.2.0". package environment import ( "github.com/ydnar/wasm-tools-go/cm" ) -// GetArguments represents function "wasi:cli/environment@0.2.0#get-arguments". -// -// Get the POSIX-style arguments to the program. -// -// get-arguments: func() -> list -// -//go:nosplit -func GetArguments() cm.List[string] { - var result cm.List[string] - wasmimport_GetArguments(&result) - return result -} - -//go:wasmimport wasi:cli/environment@0.2.0 get-arguments -//go:noescape -func wasmimport_GetArguments(result *cm.List[string]) - -// GetEnvironment represents function "wasi:cli/environment@0.2.0#get-environment". +// GetEnvironment represents the imported function "get-environment". // // Get the POSIX-style environment variables. // @@ -40,17 +23,32 @@ func wasmimport_GetArguments(result *cm.List[string]) // get-environment: func() -> list> // //go:nosplit -func GetEnvironment() cm.List[[2]string] { - var result cm.List[[2]string] +func GetEnvironment() (result cm.List[[2]string]) { wasmimport_GetEnvironment(&result) - return result + return } //go:wasmimport wasi:cli/environment@0.2.0 get-environment //go:noescape func wasmimport_GetEnvironment(result *cm.List[[2]string]) -// InitialCWD represents function "wasi:cli/environment@0.2.0#initial-cwd". +// GetArguments represents the imported function "get-arguments". +// +// Get the POSIX-style arguments to the program. +// +// get-arguments: func() -> list +// +//go:nosplit +func GetArguments() (result cm.List[string]) { + wasmimport_GetArguments(&result) + return +} + +//go:wasmimport wasi:cli/environment@0.2.0 get-arguments +//go:noescape +func wasmimport_GetArguments(result *cm.List[string]) + +// InitialCWD represents the imported function "initial-cwd". // // Return a path that programs should use as their initial current working // directory, interpreting `.` as shorthand for this. @@ -58,10 +56,9 @@ func wasmimport_GetEnvironment(result *cm.List[[2]string]) // initial-cwd: func() -> option // //go:nosplit -func InitialCWD() cm.Option[string] { - var result cm.Option[string] +func InitialCWD() (result cm.Option[string]) { wasmimport_InitialCWD(&result) - return result + return } //go:wasmimport wasi:cli/environment@0.2.0 initial-cwd 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 7f6ab0ac2e..36af67d244 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 @@ -2,14 +2,14 @@ //go:build !wasip1 -// Package exit represents the interface "wasi:cli/exit@0.2.0". +// Package exit represents the imported interface "wasi:cli/exit@0.2.0". package exit import ( "github.com/ydnar/wasm-tools-go/cm" ) -// Exit represents function "wasi:cli/exit@0.2.0#exit". +// Exit represents the imported function "exit". // // Exit the current instance and any linked instances. // @@ -17,9 +17,11 @@ import ( // //go:nosplit func Exit(status cm.Result) { - wasmimport_Exit(status) + status0 := cm.LowerResult(status) + wasmimport_Exit((uint32)(status0)) + return } //go:wasmimport wasi:cli/exit@0.2.0 exit //go:noescape -func wasmimport_Exit(status cm.Result) +func wasmimport_Exit(status0 uint32) 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 new file mode 100644 index 0000000000..267e75a081 --- /dev/null +++ b/src/internal/wasi/cli/v0.2.0/run/run.exports.go @@ -0,0 +1,19 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +//go:build !wasip1 + +package run + +import ( + "github.com/ydnar/wasm-tools-go/cm" +) + +// Exports represents the caller-defined exports from "wasi:cli/run@0.2.0". +var Exports struct { + // Run represents the caller-defined, exported function "run". + // + // Run the program. + // + // run: func() -> result + Run func() (result cm.Result) +} 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 865cef98bd..728d0292ad 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 @@ -2,24 +2,17 @@ //go:build !wasip1 -// Package run represents the interface "wasi:cli/run@0.2.0". +// Package run represents the exported interface "wasi:cli/run@0.2.0". package run import ( "github.com/ydnar/wasm-tools-go/cm" ) -// Run represents function "wasi:cli/run@0.2.0#run". -// -// Run the program. -// -// run: func() -> result -// -//go:nosplit -func Run() cm.Result { - return wasmimport_Run() +//go:wasmexport wasi:cli/run@0.2.0#run +//export wasi:cli/run@0.2.0#run +func wasmexport_Run() (result0 uint32) { + result := Exports.Run() + result0 = cm.LowerResult(result) + return } - -//go:wasmimport wasi:cli/run@0.2.0 run -//go:noescape -func wasmimport_Run() cm.Result 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 21b7c49556..fd2b7517c2 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 @@ -2,27 +2,25 @@ //go:build !wasip1 -// Package stderr represents the interface "wasi:cli/stderr@0.2.0". +// Package stderr represents the imported interface "wasi:cli/stderr@0.2.0". package stderr import ( + "github.com/ydnar/wasm-tools-go/cm" "internal/wasi/io/v0.2.0/streams" ) -// OutputStream represents the resource "wasi:io/streams@0.2.0#output-stream". -// -// See [streams.OutputStream] for more information. -type OutputStream = streams.OutputStream - -// GetStderr represents function "wasi:cli/stderr@0.2.0#get-stderr". +// GetStderr represents the imported function "get-stderr". // // get-stderr: func() -> output-stream // //go:nosplit -func GetStderr() OutputStream { - return wasmimport_GetStderr() +func GetStderr() (result streams.OutputStream) { + result0 := wasmimport_GetStderr() + result = cm.Reinterpret[streams.OutputStream]((uint32)(result0)) + return } //go:wasmimport wasi:cli/stderr@0.2.0 get-stderr //go:noescape -func wasmimport_GetStderr() OutputStream +func wasmimport_GetStderr() (result0 uint32) 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 deb634f341..abe35cbbb0 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 @@ -2,27 +2,25 @@ //go:build !wasip1 -// Package stdin represents the interface "wasi:cli/stdin@0.2.0". +// Package stdin represents the imported interface "wasi:cli/stdin@0.2.0". package stdin import ( + "github.com/ydnar/wasm-tools-go/cm" "internal/wasi/io/v0.2.0/streams" ) -// InputStream represents the resource "wasi:io/streams@0.2.0#input-stream". -// -// See [streams.InputStream] for more information. -type InputStream = streams.InputStream - -// GetStdin represents function "wasi:cli/stdin@0.2.0#get-stdin". +// GetStdin represents the imported function "get-stdin". // // get-stdin: func() -> input-stream // //go:nosplit -func GetStdin() InputStream { - return wasmimport_GetStdin() +func GetStdin() (result streams.InputStream) { + result0 := wasmimport_GetStdin() + result = cm.Reinterpret[streams.InputStream]((uint32)(result0)) + return } //go:wasmimport wasi:cli/stdin@0.2.0 get-stdin //go:noescape -func wasmimport_GetStdin() InputStream +func wasmimport_GetStdin() (result0 uint32) 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 921c0f6bcd..2f56b19ec4 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 @@ -2,27 +2,25 @@ //go:build !wasip1 -// Package stdout represents the interface "wasi:cli/stdout@0.2.0". +// Package stdout represents the imported interface "wasi:cli/stdout@0.2.0". package stdout import ( + "github.com/ydnar/wasm-tools-go/cm" "internal/wasi/io/v0.2.0/streams" ) -// OutputStream represents the resource "wasi:io/streams@0.2.0#output-stream". -// -// See [streams.OutputStream] for more information. -type OutputStream = streams.OutputStream - -// GetStdout represents function "wasi:cli/stdout@0.2.0#get-stdout". +// GetStdout represents the imported function "get-stdout". // // get-stdout: func() -> output-stream // //go:nosplit -func GetStdout() OutputStream { - return wasmimport_GetStdout() +func GetStdout() (result streams.OutputStream) { + result0 := wasmimport_GetStdout() + result = cm.Reinterpret[streams.OutputStream]((uint32)(result0)) + return } //go:wasmimport wasi:cli/stdout@0.2.0 get-stdout //go:noescape -func wasmimport_GetStdout() OutputStream +func wasmimport_GetStdout() (result0 uint32) 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 209f5d6ec9..4788644280 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package terminalinput represents the interface "wasi:cli/terminal-input@0.2.0". +// Package terminalinput represents the imported interface "wasi:cli/terminal-input@0.2.0". // // Terminal input. // @@ -15,22 +15,24 @@ import ( "github.com/ydnar/wasm-tools-go/cm" ) -// TerminalInput represents the resource "wasi:cli/terminal-input@0.2.0#terminal-input". +// TerminalInput represents the imported resource "wasi:cli/terminal-input@0.2.0#terminal-input". // // The input side of a terminal. // // resource terminal-input type TerminalInput cm.Resource -// ResourceDrop represents the Canonical ABI function "resource-drop". +// ResourceDrop represents the imported resource-drop for resource "terminal-input". // // Drops a resource handle. // //go:nosplit func (self TerminalInput) ResourceDrop() { - self.wasmimport_ResourceDrop() + self0 := cm.Reinterpret[uint32](self) + wasmimport_TerminalInputResourceDrop((uint32)(self0)) + return } //go:wasmimport wasi:cli/terminal-input@0.2.0 [resource-drop]terminal-input //go:noescape -func (self TerminalInput) wasmimport_ResourceDrop() +func wasmimport_TerminalInputResourceDrop(self0 uint32) 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 1380721dac..759348b85e 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package terminaloutput represents the interface "wasi:cli/terminal-output@0.2.0". +// Package terminaloutput represents the imported interface "wasi:cli/terminal-output@0.2.0". // // Terminal output. // @@ -15,22 +15,24 @@ import ( "github.com/ydnar/wasm-tools-go/cm" ) -// TerminalOutput represents the resource "wasi:cli/terminal-output@0.2.0#terminal-output". +// TerminalOutput represents the imported resource "wasi:cli/terminal-output@0.2.0#terminal-output". // // The output side of a terminal. // // resource terminal-output type TerminalOutput cm.Resource -// ResourceDrop represents the Canonical ABI function "resource-drop". +// ResourceDrop represents the imported resource-drop for resource "terminal-output". // // Drops a resource handle. // //go:nosplit func (self TerminalOutput) ResourceDrop() { - self.wasmimport_ResourceDrop() + self0 := cm.Reinterpret[uint32](self) + wasmimport_TerminalOutputResourceDrop((uint32)(self0)) + return } //go:wasmimport wasi:cli/terminal-output@0.2.0 [resource-drop]terminal-output //go:noescape -func (self TerminalOutput) wasmimport_ResourceDrop() +func wasmimport_TerminalOutputResourceDrop(self0 uint32) 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 c501ec4e5b..db720e1511 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package terminalstderr represents the interface "wasi:cli/terminal-stderr@0.2.0". +// Package terminalstderr represents the imported interface "wasi:cli/terminal-stderr@0.2.0". // // An interface providing an optional `terminal-output` for stderr as a // link-time authority. @@ -13,12 +13,7 @@ import ( terminaloutput "internal/wasi/cli/v0.2.0/terminal-output" ) -// TerminalOutput represents the resource "wasi:cli/terminal-output@0.2.0#terminal-output". -// -// See [terminaloutput.TerminalOutput] for more information. -type TerminalOutput = terminaloutput.TerminalOutput - -// GetTerminalStderr represents function "wasi:cli/terminal-stderr@0.2.0#get-terminal-stderr". +// GetTerminalStderr represents the imported function "get-terminal-stderr". // // If stderr is connected to a terminal, return a `terminal-output` handle // allowing further interaction with it. @@ -26,12 +21,11 @@ type TerminalOutput = terminaloutput.TerminalOutput // get-terminal-stderr: func() -> option // //go:nosplit -func GetTerminalStderr() cm.Option[TerminalOutput] { - var result cm.Option[TerminalOutput] +func GetTerminalStderr() (result cm.Option[terminaloutput.TerminalOutput]) { wasmimport_GetTerminalStderr(&result) - return result + return } //go:wasmimport wasi:cli/terminal-stderr@0.2.0 get-terminal-stderr //go:noescape -func wasmimport_GetTerminalStderr(result *cm.Option[TerminalOutput]) +func wasmimport_GetTerminalStderr(result *cm.Option[terminaloutput.TerminalOutput]) 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 fd4d9216b6..091d8e8c5f 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package terminalstdin represents the interface "wasi:cli/terminal-stdin@0.2.0". +// Package terminalstdin represents the imported interface "wasi:cli/terminal-stdin@0.2.0". // // An interface providing an optional `terminal-input` for stdin as a // link-time authority. @@ -13,12 +13,7 @@ import ( terminalinput "internal/wasi/cli/v0.2.0/terminal-input" ) -// TerminalInput represents the resource "wasi:cli/terminal-input@0.2.0#terminal-input". -// -// See [terminalinput.TerminalInput] for more information. -type TerminalInput = terminalinput.TerminalInput - -// GetTerminalStdin represents function "wasi:cli/terminal-stdin@0.2.0#get-terminal-stdin". +// GetTerminalStdin represents the imported function "get-terminal-stdin". // // If stdin is connected to a terminal, return a `terminal-input` handle // allowing further interaction with it. @@ -26,12 +21,11 @@ type TerminalInput = terminalinput.TerminalInput // get-terminal-stdin: func() -> option // //go:nosplit -func GetTerminalStdin() cm.Option[TerminalInput] { - var result cm.Option[TerminalInput] +func GetTerminalStdin() (result cm.Option[terminalinput.TerminalInput]) { wasmimport_GetTerminalStdin(&result) - return result + return } //go:wasmimport wasi:cli/terminal-stdin@0.2.0 get-terminal-stdin //go:noescape -func wasmimport_GetTerminalStdin(result *cm.Option[TerminalInput]) +func wasmimport_GetTerminalStdin(result *cm.Option[terminalinput.TerminalInput]) 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 7bd09809a8..d0d9bfe485 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package terminalstdout represents the interface "wasi:cli/terminal-stdout@0.2.0". +// Package terminalstdout represents the imported interface "wasi:cli/terminal-stdout@0.2.0". // // An interface providing an optional `terminal-output` for stdout as a // link-time authority. @@ -13,12 +13,7 @@ import ( terminaloutput "internal/wasi/cli/v0.2.0/terminal-output" ) -// TerminalOutput represents the resource "wasi:cli/terminal-output@0.2.0#terminal-output". -// -// See [terminaloutput.TerminalOutput] for more information. -type TerminalOutput = terminaloutput.TerminalOutput - -// GetTerminalStdout represents function "wasi:cli/terminal-stdout@0.2.0#get-terminal-stdout". +// GetTerminalStdout represents the imported function "get-terminal-stdout". // // If stdout is connected to a terminal, return a `terminal-output` handle // allowing further interaction with it. @@ -26,12 +21,11 @@ type TerminalOutput = terminaloutput.TerminalOutput // get-terminal-stdout: func() -> option // //go:nosplit -func GetTerminalStdout() cm.Option[TerminalOutput] { - var result cm.Option[TerminalOutput] +func GetTerminalStdout() (result cm.Option[terminaloutput.TerminalOutput]) { wasmimport_GetTerminalStdout(&result) - return result + return } //go:wasmimport wasi:cli/terminal-stdout@0.2.0 get-terminal-stdout //go:noescape -func wasmimport_GetTerminalStdout(result *cm.Option[TerminalOutput]) +func wasmimport_GetTerminalStdout(result *cm.Option[terminaloutput.TerminalOutput]) 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 f483ba5dbc..4c68033654 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package monotonicclock represents the interface "wasi:clocks/monotonic-clock@0.2.0". +// Package monotonicclock represents the imported interface "wasi:clocks/monotonic-clock@0.2.0". // // WASI Monotonic Clock is a clock API intended to let users measure elapsed // time. @@ -17,17 +17,11 @@ package monotonicclock import ( + "github.com/ydnar/wasm-tools-go/cm" "internal/wasi/io/v0.2.0/poll" ) -// Duration represents the type "wasi:clocks/monotonic-clock@0.2.0#duration". -// -// A duration of time, in nanoseconds. -// -// type duration = u64 -type Duration uint64 - -// Instant represents the type "wasi:clocks/monotonic-clock@0.2.0#instant". +// Instant represents the u64 "wasi:clocks/monotonic-clock@0.2.0#instant". // // An instant in time, in nanoseconds. An instant is relative to an // unspecified initial value, and can only be compared to instances from @@ -36,12 +30,14 @@ type Duration uint64 // type instant = u64 type Instant uint64 -// Pollable represents the resource "wasi:io/poll@0.2.0#pollable". +// Duration represents the u64 "wasi:clocks/monotonic-clock@0.2.0#duration". // -// See [poll.Pollable] for more information. -type Pollable = poll.Pollable +// A duration of time, in nanoseconds. +// +// type duration = u64 +type Duration uint64 -// Now represents function "wasi:clocks/monotonic-clock@0.2.0#now". +// Now represents the imported function "now". // // Read the current value of the clock. // @@ -51,15 +47,17 @@ type Pollable = poll.Pollable // now: func() -> instant // //go:nosplit -func Now() Instant { - return wasmimport_Now() +func Now() (result Instant) { + result0 := wasmimport_Now() + result = (Instant)((uint64)(result0)) + return } //go:wasmimport wasi:clocks/monotonic-clock@0.2.0 now //go:noescape -func wasmimport_Now() Instant +func wasmimport_Now() (result0 uint64) -// Resolution represents function "wasi:clocks/monotonic-clock@0.2.0#resolution". +// Resolution represents the imported function "resolution". // // Query the resolution of the clock. Returns the duration of time // corresponding to a clock tick. @@ -67,43 +65,51 @@ func wasmimport_Now() Instant // resolution: func() -> duration // //go:nosplit -func Resolution() Duration { - return wasmimport_Resolution() +func Resolution() (result Duration) { + result0 := wasmimport_Resolution() + result = (Duration)((uint64)(result0)) + return } //go:wasmimport wasi:clocks/monotonic-clock@0.2.0 resolution //go:noescape -func wasmimport_Resolution() Duration +func wasmimport_Resolution() (result0 uint64) -// SubscribeDuration represents function "wasi:clocks/monotonic-clock@0.2.0#subscribe-duration". +// SubscribeInstant represents the imported function "subscribe-instant". // -// Create a `pollable` which will resolve once the given duration has -// elapsed, starting at the time at which this function was called. +// Create a `pollable` which will resolve once the specified instant // occured. // -// subscribe-duration: func(when: duration) -> pollable +// subscribe-instant: func(when: instant) -> pollable // //go:nosplit -func SubscribeDuration(when Duration) Pollable { - return wasmimport_SubscribeDuration(when) +func SubscribeInstant(when Instant) (result poll.Pollable) { + when0 := (uint64)(when) + result0 := wasmimport_SubscribeInstant((uint64)(when0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return } -//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-duration +//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-instant //go:noescape -func wasmimport_SubscribeDuration(when Duration) Pollable +func wasmimport_SubscribeInstant(when0 uint64) (result0 uint32) -// SubscribeInstant represents function "wasi:clocks/monotonic-clock@0.2.0#subscribe-instant". +// SubscribeDuration represents the imported function "subscribe-duration". // -// Create a `pollable` which will resolve once the specified instant +// Create a `pollable` which will resolve once the given duration has +// elapsed, starting at the time at which this function was called. // occured. // -// subscribe-instant: func(when: instant) -> pollable +// subscribe-duration: func(when: duration) -> pollable // //go:nosplit -func SubscribeInstant(when Instant) Pollable { - return wasmimport_SubscribeInstant(when) +func SubscribeDuration(when Duration) (result poll.Pollable) { + when0 := (uint64)(when) + result0 := wasmimport_SubscribeDuration((uint64)(when0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return } -//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-instant +//go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-duration //go:noescape -func wasmimport_SubscribeInstant(when Instant) Pollable +func wasmimport_SubscribeDuration(when0 uint64) (result0 uint32) diff --git a/src/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go b/src/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go index 90a966555a..a270f78d6d 100644 --- a/src/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go +++ b/src/internal/wasi/clocks/v0.2.0/wall-clock/wall-clock.wit.go @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package wallclock represents the interface "wasi:clocks/wall-clock@0.2.0". +// Package wallclock represents the imported interface "wasi:clocks/wall-clock@0.2.0". // // WASI Wall Clock is a clock API intended to let users query the current // time. The name "wall" makes an analogy to a "clock on the wall", which @@ -33,7 +33,7 @@ type DateTime struct { Nanoseconds uint32 } -// Now represents function "wasi:clocks/wall-clock@0.2.0#now". +// Now represents the imported function "now". // // Read the current value of the clock. // @@ -52,17 +52,16 @@ type DateTime struct { // [Unix Time]: https://en.wikipedia.org/wiki/Unix_time // //go:nosplit -func Now() DateTime { - var result DateTime +func Now() (result DateTime) { wasmimport_Now(&result) - return result + return } //go:wasmimport wasi:clocks/wall-clock@0.2.0 now //go:noescape func wasmimport_Now(result *DateTime) -// Resolution represents function "wasi:clocks/wall-clock@0.2.0#resolution". +// Resolution represents the imported function "resolution". // // Query the resolution of the clock. // @@ -71,10 +70,9 @@ func wasmimport_Now(result *DateTime) // resolution: func() -> datetime // //go:nosplit -func Resolution() DateTime { - var result DateTime +func Resolution() (result DateTime) { wasmimport_Resolution(&result) - return result + return } //go:wasmimport wasi:clocks/wall-clock@0.2.0 resolution 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 8acb164435..d0b71bf110 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package preopens represents the interface "wasi:filesystem/preopens@0.2.0". +// Package preopens represents the imported interface "wasi:filesystem/preopens@0.2.0". package preopens import ( @@ -10,24 +10,18 @@ import ( "internal/wasi/filesystem/v0.2.0/types" ) -// Descriptor represents the resource "wasi:filesystem/types@0.2.0#descriptor". -// -// See [types.Descriptor] for more information. -type Descriptor = types.Descriptor - -// GetDirectories represents function "wasi:filesystem/preopens@0.2.0#get-directories". +// GetDirectories represents the imported function "get-directories". // // Return the set of preopened directories, and their path. // // get-directories: func() -> list> // //go:nosplit -func GetDirectories() cm.List[cm.Tuple[Descriptor, string]] { - var result cm.List[cm.Tuple[Descriptor, string]] +func GetDirectories() (result cm.List[cm.Tuple[types.Descriptor, string]]) { wasmimport_GetDirectories(&result) - return result + return } //go:wasmimport wasi:filesystem/preopens@0.2.0 get-directories //go:noescape -func wasmimport_GetDirectories(result *cm.List[cm.Tuple[Descriptor, string]]) +func wasmimport_GetDirectories(result *cm.List[cm.Tuple[types.Descriptor, string]]) diff --git a/src/internal/wasi/filesystem/v0.2.0/types/abi.go b/src/internal/wasi/filesystem/v0.2.0/types/abi.go new file mode 100644 index 0000000000..288ef2e227 --- /dev/null +++ b/src/internal/wasi/filesystem/v0.2.0/types/abi.go @@ -0,0 +1,27 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +//go:build !wasip1 + +package types + +import ( + "github.com/ydnar/wasm-tools-go/cm" + wallclock "internal/wasi/clocks/v0.2.0/wall-clock" +) + +func lower_DateTime(v wallclock.DateTime) (f0 uint64, f1 uint32) { + f0 = (uint64)(v.Seconds) + f1 = (uint32)(v.Nanoseconds) + return +} + +func lower_NewTimestamp(v NewTimestamp) (f0 uint32, f1 uint64, f2 uint32) { + f0 = (uint32)(cm.Tag(&v)) + switch f0 { + case 2: // timestamp + v1, v2 := lower_DateTime(*v.Timestamp()) + f1 = (uint64)(v1) + f2 = (uint32)(v2) + } + return +} 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 571ceddd73..387426d1b6 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package types represents the interface "wasi:filesystem/types@0.2.0". +// Package types represents the imported interface "wasi:filesystem/types@0.2.0". // // WASI filesystem is a filesystem API primarily intended to let users run WASI // programs that access their files on their existing filesystems, without @@ -37,1202 +37,1227 @@ import ( "internal/wasi/io/v0.2.0/streams" ) -// Advice represents the enum "wasi:filesystem/types@0.2.0#advice". +// FileSize represents the u64 "wasi:filesystem/types@0.2.0#filesize". // -// File or memory access pattern advisory information. +// File size or length of a region within a file. // -// enum advice { -// normal, -// sequential, -// random, -// will-need, -// dont-need, -// no-reuse +// type filesize = u64 +type FileSize uint64 + +// DescriptorType represents the enum "wasi:filesystem/types@0.2.0#descriptor-type". +// +// The type of a filesystem object referenced by a descriptor. +// +// Note: This was called `filetype` in earlier versions of WASI. +// +// enum descriptor-type { +// unknown, +// block-device, +// character-device, +// directory, +// fifo, +// symbolic-link, +// regular-file, +// socket // } -type Advice uint8 +type DescriptorType uint8 const ( - // The application has no advice to give on its behavior with respect - // to the specified data. - AdviceNormal Advice = iota + // The type of the descriptor or file is unknown or is different from + // any of the other types specified. + DescriptorTypeUnknown DescriptorType = iota - // The application expects to access the specified data sequentially - // from lower offsets to higher offsets. - AdviceSequential + // The descriptor refers to a block device inode. + DescriptorTypeBlockDevice - // The application expects to access the specified data in a random - // order. - AdviceRandom + // The descriptor refers to a character device inode. + DescriptorTypeCharacterDevice - // The application expects to access the specified data in the near - // future. - AdviceWillNeed + // The descriptor refers to a directory inode. + DescriptorTypeDirectory - // The application expects that it will not access the specified data - // in the near future. - AdviceDontNeed + // The descriptor refers to a named pipe. + DescriptorTypeFIFO - // The application expects to access the specified data once and then - // not reuse it thereafter. - AdviceNoReuse + // The file refers to a symbolic link inode. + DescriptorTypeSymbolicLink + + // The descriptor refers to a regular file inode. + DescriptorTypeRegularFile + + // The descriptor refers to a socket. + DescriptorTypeSocket ) -// DateTime represents the record "wasi:clocks/wall-clock@0.2.0#datetime". +// DescriptorFlags represents the flags "wasi:filesystem/types@0.2.0#descriptor-flags". // -// See [wallclock.DateTime] for more information. -type DateTime = wallclock.DateTime - -// Descriptor represents the resource "wasi:filesystem/types@0.2.0#descriptor". +// Descriptor flags. // -// A descriptor is a reference to a filesystem object, which may be a file, -// directory, named pipe, special file, or other object on which filesystem -// calls may be made. +// Note: This was called `fdflags` in earlier versions of WASI. // -// resource descriptor -type Descriptor cm.Resource +// flags descriptor-flags { +// read, +// write, +// file-integrity-sync, +// data-integrity-sync, +// requested-write-sync, +// mutate-directory, +// } +type DescriptorFlags uint8 -// ResourceDrop represents the Canonical ABI function "resource-drop". -// -// Drops a resource handle. -// -//go:nosplit -func (self Descriptor) ResourceDrop() { - self.wasmimport_ResourceDrop() -} +const ( + // Read mode: Data can be read. + DescriptorFlagsRead DescriptorFlags = 1 << iota -//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]descriptor -//go:noescape -func (self Descriptor) wasmimport_ResourceDrop() + // Write mode: Data can be written to. + DescriptorFlagsWrite -// Advise represents method "advise". -// -// Provide file advisory information on a descriptor. -// -// This is similar to `posix_fadvise` in POSIX. -// -// advise: func(offset: filesize, length: filesize, advice: advice) -> result<_, error-code> -// -//go:nosplit -func (self Descriptor) Advise(offset FileSize, length FileSize, advice Advice) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_Advise(offset, length, advice, &result) - return result -} + // Request that writes be performed according to synchronized I/O file + // integrity completion. The data stored in the file and the file's + // metadata are synchronized. This is similar to `O_SYNC` in POSIX. + // + // The precise semantics of this operation have not yet been defined for + // WASI. At this time, it should be interpreted as a request, and not a + // requirement. + DescriptorFlagsFileIntegritySync -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.advise -//go:noescape -func (self Descriptor) wasmimport_Advise(offset FileSize, length FileSize, advice Advice, result *cm.ErrResult[struct{}, ErrorCode]) + // Request that writes be performed according to synchronized I/O data + // integrity completion. Only the data stored in the file is + // synchronized. This is similar to `O_DSYNC` in POSIX. + // + // The precise semantics of this operation have not yet been defined for + // WASI. At this time, it should be interpreted as a request, and not a + // requirement. + DescriptorFlagsDataIntegritySync -// AppendViaStream represents method "append-via-stream". -// -// Return a stream for appending to a file, if available. -// -// May fail with an error-code describing why the file cannot be appended. -// -// Note: This allows using `write-stream`, which is similar to `write` with -// `O_APPEND` in in POSIX. -// -// append-via-stream: func() -> result -// -//go:nosplit -func (self Descriptor) AppendViaStream() cm.OKResult[OutputStream, ErrorCode] { - var result cm.OKResult[OutputStream, ErrorCode] - self.wasmimport_AppendViaStream(&result) - return result -} + // Requests that reads be performed at the same level of integrety + // requested for writes. This is similar to `O_RSYNC` in POSIX. + // + // The precise semantics of this operation have not yet been defined for + // WASI. At this time, it should be interpreted as a request, and not a + // requirement. + DescriptorFlagsRequestedWriteSync -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.append-via-stream -//go:noescape -func (self Descriptor) wasmimport_AppendViaStream(result *cm.OKResult[OutputStream, ErrorCode]) + // Mutating directories mode: Directory contents may be mutated. + // + // When this flag is unset on a descriptor, operations using the + // descriptor which would create, rename, delete, modify the data or + // metadata of filesystem objects, or obtain another handle which + // would permit any of those, shall fail with `error-code::read-only` if + // they would otherwise succeed. + // + // This may only be set on directories. + DescriptorFlagsMutateDirectory +) -// CreateDirectoryAt represents method "create-directory-at". -// -// Create a directory. -// -// Note: This is similar to `mkdirat` in POSIX. +// PathFlags represents the flags "wasi:filesystem/types@0.2.0#path-flags". // -// create-directory-at: func(path: string) -> result<_, error-code> +// Flags determining the method of how paths are resolved. // -//go:nosplit -func (self Descriptor) CreateDirectoryAt(path string) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_CreateDirectoryAt(path, &result) - return result -} +// flags path-flags { +// symlink-follow, +// } +type PathFlags uint8 -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.create-directory-at -//go:noescape -func (self Descriptor) wasmimport_CreateDirectoryAt(path string, result *cm.ErrResult[struct{}, ErrorCode]) +const ( + // As long as the resolved path corresponds to a symbolic link, it is + // expanded. + PathFlagsSymlinkFollow PathFlags = 1 << iota +) -// GetFlags represents method "get-flags". -// -// Get flags associated with a descriptor. -// -// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. -// -// Note: This returns the value that was the `fs_flags` value returned -// from `fdstat_get` in earlier versions of WASI. +// OpenFlags represents the flags "wasi:filesystem/types@0.2.0#open-flags". // -// get-flags: func() -> result +// Open flags used by `open-at`. // -//go:nosplit -func (self Descriptor) GetFlags() cm.OKResult[DescriptorFlags, ErrorCode] { - var result cm.OKResult[DescriptorFlags, ErrorCode] - self.wasmimport_GetFlags(&result) - return result -} +// flags open-flags { +// create, +// directory, +// exclusive, +// truncate, +// } +type OpenFlags uint8 -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-flags -//go:noescape -func (self Descriptor) wasmimport_GetFlags(result *cm.OKResult[DescriptorFlags, ErrorCode]) +const ( + // Create file if it does not exist, similar to `O_CREAT` in POSIX. + OpenFlagsCreate OpenFlags = 1 << iota -// GetType represents method "get-type". -// -// Get the dynamic type of a descriptor. -// -// Note: This returns the same value as the `type` field of the `fd-stat` -// returned by `stat`, `stat-at` and similar. -// -// Note: This returns similar flags to the `st_mode & S_IFMT` value provided -// by `fstat` in POSIX. -// -// Note: This returns the value that was the `fs_filetype` value returned -// from `fdstat_get` in earlier versions of WASI. -// -// get-type: func() -> result -// -//go:nosplit -func (self Descriptor) GetType() cm.OKResult[DescriptorType, ErrorCode] { - var result cm.OKResult[DescriptorType, ErrorCode] - self.wasmimport_GetType(&result) - return result -} + // Fail if not a directory, similar to `O_DIRECTORY` in POSIX. + OpenFlagsDirectory -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-type -//go:noescape -func (self Descriptor) wasmimport_GetType(result *cm.OKResult[DescriptorType, ErrorCode]) + // Fail if file already exists, similar to `O_EXCL` in POSIX. + OpenFlagsExclusive -// IsSameObject represents method "is-same-object". -// -// Test whether two descriptors refer to the same filesystem object. -// -// In POSIX, this corresponds to testing whether the two descriptors have the -// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers. -// wasi-filesystem does not expose device and inode numbers, so this function -// may be used instead. + // Truncate file to size 0, similar to `O_TRUNC` in POSIX. + OpenFlagsTruncate +) + +// LinkCount represents the u64 "wasi:filesystem/types@0.2.0#link-count". // -// is-same-object: func(other: borrow) -> bool +// Number of hard links to an inode. // -//go:nosplit -func (self Descriptor) IsSameObject(other Descriptor) bool { - return self.wasmimport_IsSameObject(other) -} - -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.is-same-object -//go:noescape -func (self Descriptor) wasmimport_IsSameObject(other Descriptor) bool +// type link-count = u64 +type LinkCount uint64 -// LinkAt represents method "link-at". -// -// Create a hard link. +// DescriptorStat represents the record "wasi:filesystem/types@0.2.0#descriptor-stat". // -// Note: This is similar to `linkat` in POSIX. +// File attributes. // -// link-at: func(old-path-flags: path-flags, old-path: string, new-descriptor: borrow, -// new-path: string) -> result<_, error-code> +// Note: This was called `filestat` in earlier versions of WASI. // -//go:nosplit -func (self Descriptor) LinkAt(oldPathFlags PathFlags, oldPath string, newDescriptor Descriptor, newPath string) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_LinkAt(oldPathFlags, oldPath, newDescriptor, newPath, &result) - return result -} - -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.link-at -//go:noescape -func (self Descriptor) wasmimport_LinkAt(oldPathFlags PathFlags, oldPath string, newDescriptor Descriptor, newPath string, result *cm.ErrResult[struct{}, ErrorCode]) +// record descriptor-stat { +// %type: descriptor-type, +// link-count: link-count, +// size: filesize, +// data-access-timestamp: option, +// data-modification-timestamp: option, +// status-change-timestamp: option, +// } +type DescriptorStat struct { + // File type. + Type DescriptorType -// MetadataHash represents method "metadata-hash". -// -// Return a hash of the metadata associated with a filesystem object referred -// to by a descriptor. -// -// This returns a hash of the last-modification timestamp and file size, and -// may also include the inode number, device number, birth timestamp, and -// other metadata fields that may change when the file is modified or -// replaced. It may also include a secret value chosen by the -// implementation and not otherwise exposed. -// -// Implementations are encourated to provide the following properties: -// -// - If the file is not modified or replaced, the computed hash value should -// usually not change. -// - If the object is modified or replaced, the computed hash value should -// usually change. -// - The inputs to the hash should not be easily computable from the -// computed hash. -// -// However, none of these is required. -// -// metadata-hash: func() -> result -// -//go:nosplit -func (self Descriptor) MetadataHash() cm.OKResult[MetadataHashValue, ErrorCode] { - var result cm.OKResult[MetadataHashValue, ErrorCode] - self.wasmimport_MetadataHash(&result) - return result -} + // Number of hard links to the file. + LinkCount LinkCount -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash -//go:noescape -func (self Descriptor) wasmimport_MetadataHash(result *cm.OKResult[MetadataHashValue, ErrorCode]) + // For regular files, the file size in bytes. For symbolic links, the + // length in bytes of the pathname contained in the symbolic link. + Size FileSize -// MetadataHashAt represents method "metadata-hash-at". -// -// Return a hash of the metadata associated with a filesystem object referred -// to by a directory descriptor and a relative path. -// -// This performs the same hash computation as `metadata-hash`. -// -// metadata-hash-at: func(path-flags: path-flags, path: string) -> result -// -//go:nosplit -func (self Descriptor) MetadataHashAt(pathFlags PathFlags, path string) cm.OKResult[MetadataHashValue, ErrorCode] { - var result cm.OKResult[MetadataHashValue, ErrorCode] - self.wasmimport_MetadataHashAt(pathFlags, path, &result) - return result -} + // Last data access timestamp. + // + // If the `option` is none, the platform doesn't maintain an access + // timestamp for this file. + DataAccessTimestamp cm.Option[wallclock.DateTime] -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash-at -//go:noescape -func (self Descriptor) wasmimport_MetadataHashAt(pathFlags PathFlags, path string, result *cm.OKResult[MetadataHashValue, ErrorCode]) + // Last data modification timestamp. + // + // If the `option` is none, the platform doesn't maintain a + // modification timestamp for this file. + DataModificationTimestamp cm.Option[wallclock.DateTime] -// OpenAt represents method "open-at". -// -// Open a file or directory. -// -// The returned descriptor is not guaranteed to be the lowest-numbered -// descriptor not currently open/ it is randomized to prevent applications -// from depending on making assumptions about indexes, since this is -// error-prone in multi-threaded contexts. The returned descriptor is -// guaranteed to be less than 2**31. -// -// If `flags` contains `descriptor-flags::mutate-directory`, and the base -// descriptor doesn't have `descriptor-flags::mutate-directory` set, -// `open-at` fails with `error-code::read-only`. -// -// If `flags` contains `write` or `mutate-directory`, or `open-flags` -// contains `truncate` or `create`, and the base descriptor doesn't have -// `descriptor-flags::mutate-directory` set, `open-at` fails with -// `error-code::read-only`. -// -// Note: This is similar to `openat` in POSIX. -// -// open-at: func(path-flags: path-flags, path: string, open-flags: open-flags, flags: -// descriptor-flags) -> result -// -//go:nosplit -func (self Descriptor) OpenAt(pathFlags PathFlags, path string, openFlags OpenFlags, flags DescriptorFlags) cm.OKResult[Descriptor, ErrorCode] { - var result cm.OKResult[Descriptor, ErrorCode] - self.wasmimport_OpenAt(pathFlags, path, openFlags, flags, &result) - return result + // Last file status-change timestamp. + // + // If the `option` is none, the platform doesn't maintain a + // status-change timestamp for this file. + StatusChangeTimestamp cm.Option[wallclock.DateTime] } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.open-at -//go:noescape -func (self Descriptor) wasmimport_OpenAt(pathFlags PathFlags, path string, openFlags OpenFlags, flags DescriptorFlags, result *cm.OKResult[Descriptor, ErrorCode]) - -// Read represents method "read". -// -// Read from a descriptor, without using and updating the descriptor's offset. -// -// This function returns a list of bytes containing the data that was -// read, along with a bool which, when true, indicates that the end of the -// file was reached. The returned list will contain up to `length` bytes; it -// may return fewer than requested, if the end of the file is reached or -// if the I/O operation is interrupted. -// -// In the future, this may change to return a `stream`. +// NewTimestamp represents the variant "wasi:filesystem/types@0.2.0#new-timestamp". // -// Note: This is similar to `pread` in POSIX. +// When setting a timestamp, this gives the value to set it to. // -// read: func(length: filesize, offset: filesize) -> result, bool>, -// error-code> +// variant new-timestamp { +// no-change, +// now, +// timestamp(datetime), +// } +type NewTimestamp cm.Variant[uint8, wallclock.DateTime, wallclock.DateTime] + +// NewTimestampNoChange returns a [NewTimestamp] of case "no-change". // -//go:nosplit -func (self Descriptor) Read(length FileSize, offset FileSize) cm.OKResult[cm.Tuple[cm.List[uint8], bool], ErrorCode] { - var result cm.OKResult[cm.Tuple[cm.List[uint8], bool], ErrorCode] - self.wasmimport_Read(length, offset, &result) - return result +// Leave the timestamp set to its previous value. +func NewTimestampNoChange() NewTimestamp { + var data struct{} + return cm.New[NewTimestamp](0, data) } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read -//go:noescape -func (self Descriptor) wasmimport_Read(length FileSize, offset FileSize, result *cm.OKResult[cm.Tuple[cm.List[uint8], bool], ErrorCode]) +// NoChange returns true if [NewTimestamp] represents the variant case "no-change". +func (self *NewTimestamp) NoChange() bool { + return cm.Tag(self) == 0 +} -// ReadDirectory represents method "read-directory". -// -// Read directory entries from a directory. -// -// On filesystems where directories contain entries referring to themselves -// and their parents, often named `.` and `..` respectively, these entries -// are omitted. -// -// This always returns a new stream which starts at the beginning of the -// directory. Multiple streams may be active on the same directory, and they -// do not interfere with each other. -// -// read-directory: func() -> result +// NewTimestampNow returns a [NewTimestamp] of case "now". // -//go:nosplit -func (self Descriptor) ReadDirectory() cm.OKResult[DirectoryEntryStream, ErrorCode] { - var result cm.OKResult[DirectoryEntryStream, ErrorCode] - self.wasmimport_ReadDirectory(&result) - return result +// Set the timestamp to the current time of the system clock associated +// with the filesystem. +func NewTimestampNow() NewTimestamp { + var data struct{} + return cm.New[NewTimestamp](1, data) } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-directory -//go:noescape -func (self Descriptor) wasmimport_ReadDirectory(result *cm.OKResult[DirectoryEntryStream, ErrorCode]) +// Now returns true if [NewTimestamp] represents the variant case "now". +func (self *NewTimestamp) Now() bool { + return cm.Tag(self) == 1 +} -// ReadViaStream represents method "read-via-stream". -// -// Return a stream for reading from a file, if available. -// -// May fail with an error-code describing why the file cannot be read. -// -// Multiple read, write, and append streams may be active on the same open -// file and they do not interfere with each other. -// -// Note: This allows using `read-stream`, which is similar to `read` in POSIX. -// -// read-via-stream: func(offset: filesize) -> result +// NewTimestampTimestamp returns a [NewTimestamp] of case "timestamp". // -//go:nosplit -func (self Descriptor) ReadViaStream(offset FileSize) cm.OKResult[InputStream, ErrorCode] { - var result cm.OKResult[InputStream, ErrorCode] - self.wasmimport_ReadViaStream(offset, &result) - return result +// Set the timestamp to the given value. +func NewTimestampTimestamp(data wallclock.DateTime) NewTimestamp { + return cm.New[NewTimestamp](2, data) } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-via-stream -//go:noescape -func (self Descriptor) wasmimport_ReadViaStream(offset FileSize, result *cm.OKResult[InputStream, ErrorCode]) +// Timestamp returns a non-nil *[wallclock.DateTime] if [NewTimestamp] represents the variant case "timestamp". +func (self *NewTimestamp) Timestamp() *wallclock.DateTime { + return cm.Case[wallclock.DateTime](self, 2) +} -// ReadLinkAt represents method "readlink-at". -// -// Read the contents of a symbolic link. -// -// If the contents contain an absolute or rooted path in the underlying -// filesystem, this function fails with `error-code::not-permitted`. -// -// Note: This is similar to `readlinkat` in POSIX. +// DirectoryEntry represents the record "wasi:filesystem/types@0.2.0#directory-entry". // -// readlink-at: func(path: string) -> result +// A directory entry. // -//go:nosplit -func (self Descriptor) ReadLinkAt(path string) cm.OKResult[string, ErrorCode] { - var result cm.OKResult[string, ErrorCode] - self.wasmimport_ReadLinkAt(path, &result) - return result -} +// record directory-entry { +// %type: descriptor-type, +// name: string, +// } +type DirectoryEntry struct { + // The type of the file referred to by this directory entry. + Type DescriptorType -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.readlink-at -//go:noescape -func (self Descriptor) wasmimport_ReadLinkAt(path string, result *cm.OKResult[string, ErrorCode]) + // The name of the object. + Name string +} -// RemoveDirectoryAt represents method "remove-directory-at". -// -// Remove a directory. -// -// Return `error-code::not-empty` if the directory is not empty. -// -// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. +// ErrorCode represents the enum "wasi:filesystem/types@0.2.0#error-code". // -// remove-directory-at: func(path: string) -> result<_, error-code> +// Error codes returned by functions, similar to `errno` in POSIX. +// Not all of these error codes are returned by the functions provided by this +// API; some are used in higher-level library layers, and others are provided +// merely for alignment with POSIX. // -//go:nosplit -func (self Descriptor) RemoveDirectoryAt(path string) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_RemoveDirectoryAt(path, &result) - return result -} +// enum error-code { +// access, +// would-block, +// already, +// bad-descriptor, +// busy, +// deadlock, +// quota, +// exist, +// file-too-large, +// illegal-byte-sequence, +// in-progress, +// interrupted, +// invalid, +// io, +// is-directory, +// loop, +// too-many-links, +// message-size, +// name-too-long, +// no-device, +// no-entry, +// no-lock, +// insufficient-memory, +// insufficient-space, +// not-directory, +// not-empty, +// not-recoverable, +// unsupported, +// no-tty, +// no-such-device, +// overflow, +// not-permitted, +// pipe, +// read-only, +// invalid-seek, +// text-file-busy, +// cross-device +// } +type ErrorCode uint8 -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.remove-directory-at -//go:noescape -func (self Descriptor) wasmimport_RemoveDirectoryAt(path string, result *cm.ErrResult[struct{}, ErrorCode]) +const ( + // Permission denied, similar to `EACCES` in POSIX. + ErrorCodeAccess ErrorCode = iota -// RenameAt represents method "rename-at". -// -// Rename a filesystem object. -// -// Note: This is similar to `renameat` in POSIX. -// -// rename-at: func(old-path: string, new-descriptor: borrow, new-path: -// string) -> result<_, error-code> -// -//go:nosplit -func (self Descriptor) RenameAt(oldPath string, newDescriptor Descriptor, newPath string) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_RenameAt(oldPath, newDescriptor, newPath, &result) - return result -} + // Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` + // in POSIX. + ErrorCodeWouldBlock -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.rename-at -//go:noescape -func (self Descriptor) wasmimport_RenameAt(oldPath string, newDescriptor Descriptor, newPath string, result *cm.ErrResult[struct{}, ErrorCode]) + // Connection already in progress, similar to `EALREADY` in POSIX. + ErrorCodeAlready -// SetSize represents method "set-size". -// -// Adjust the size of an open file. If this increases the file's size, the -// extra bytes are filled with zeros. -// -// Note: This was called `fd_filestat_set_size` in earlier versions of WASI. -// -// set-size: func(size: filesize) -> result<_, error-code> -// -//go:nosplit -func (self Descriptor) SetSize(size FileSize) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SetSize(size, &result) - return result -} + // Bad descriptor, similar to `EBADF` in POSIX. + ErrorCodeBadDescriptor -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-size -//go:noescape -func (self Descriptor) wasmimport_SetSize(size FileSize, result *cm.ErrResult[struct{}, ErrorCode]) + // Device or resource busy, similar to `EBUSY` in POSIX. + ErrorCodeBusy -// SetTimes represents method "set-times". -// -// Adjust the timestamps of an open file or directory. -// -// Note: This is similar to `futimens` in POSIX. -// -// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. -// -// set-times: func(data-access-timestamp: new-timestamp, data-modification-timestamp: -// new-timestamp) -> result<_, error-code> -// -//go:nosplit -func (self Descriptor) SetTimes(dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SetTimes(dataAccessTimestamp, dataModificationTimestamp, &result) - return result -} + // Resource deadlock would occur, similar to `EDEADLK` in POSIX. + ErrorCodeDeadlock -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times -//go:noescape -func (self Descriptor) wasmimport_SetTimes(dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp, result *cm.ErrResult[struct{}, ErrorCode]) + // Storage quota exceeded, similar to `EDQUOT` in POSIX. + ErrorCodeQuota -// SetTimesAt represents method "set-times-at". -// -// Adjust the timestamps of a file or directory. -// -// Note: This is similar to `utimensat` in POSIX. -// -// Note: This was called `path_filestat_set_times` in earlier versions of -// WASI. -// -// set-times-at: func(path-flags: path-flags, path: string, data-access-timestamp: -// new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code> -// -//go:nosplit -func (self Descriptor) SetTimesAt(pathFlags PathFlags, path string, dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SetTimesAt(pathFlags, path, dataAccessTimestamp, dataModificationTimestamp, &result) - return result -} + // File exists, similar to `EEXIST` in POSIX. + ErrorCodeExist -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times-at -//go:noescape -func (self Descriptor) wasmimport_SetTimesAt(pathFlags PathFlags, path string, dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp, result *cm.ErrResult[struct{}, ErrorCode]) + // File too large, similar to `EFBIG` in POSIX. + ErrorCodeFileTooLarge -// Stat represents method "stat". -// -// Return the attributes of an open file or directory. + // Illegal byte sequence, similar to `EILSEQ` in POSIX. + ErrorCodeIllegalByteSequence + + // Operation in progress, similar to `EINPROGRESS` in POSIX. + ErrorCodeInProgress + + // Interrupted function, similar to `EINTR` in POSIX. + ErrorCodeInterrupted + + // Invalid argument, similar to `EINVAL` in POSIX. + ErrorCodeInvalid + + // I/O error, similar to `EIO` in POSIX. + ErrorCodeIO + + // Is a directory, similar to `EISDIR` in POSIX. + ErrorCodeIsDirectory + + // Too many levels of symbolic links, similar to `ELOOP` in POSIX. + ErrorCodeLoop + + // Too many links, similar to `EMLINK` in POSIX. + ErrorCodeTooManyLinks + + // Message too large, similar to `EMSGSIZE` in POSIX. + ErrorCodeMessageSize + + // Filename too long, similar to `ENAMETOOLONG` in POSIX. + ErrorCodeNameTooLong + + // No such device, similar to `ENODEV` in POSIX. + ErrorCodeNoDevice + + // No such file or directory, similar to `ENOENT` in POSIX. + ErrorCodeNoEntry + + // No locks available, similar to `ENOLCK` in POSIX. + ErrorCodeNoLock + + // Not enough space, similar to `ENOMEM` in POSIX. + ErrorCodeInsufficientMemory + + // No space left on device, similar to `ENOSPC` in POSIX. + ErrorCodeInsufficientSpace + + // Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. + ErrorCodeNotDirectory + + // Directory not empty, similar to `ENOTEMPTY` in POSIX. + ErrorCodeNotEmpty + + // State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. + ErrorCodeNotRecoverable + + // Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. + ErrorCodeUnsupported + + // Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. + ErrorCodeNoTTY + + // No such device or address, similar to `ENXIO` in POSIX. + ErrorCodeNoSuchDevice + + // Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. + ErrorCodeOverflow + + // Operation not permitted, similar to `EPERM` in POSIX. + ErrorCodeNotPermitted + + // Broken pipe, similar to `EPIPE` in POSIX. + ErrorCodePipe + + // Read-only file system, similar to `EROFS` in POSIX. + ErrorCodeReadOnly + + // Invalid seek, similar to `ESPIPE` in POSIX. + ErrorCodeInvalidSeek + + // Text file busy, similar to `ETXTBSY` in POSIX. + ErrorCodeTextFileBusy + + // Cross-device link, similar to `EXDEV` in POSIX. + ErrorCodeCrossDevice +) + +// Advice represents the enum "wasi:filesystem/types@0.2.0#advice". // -// Note: This is similar to `fstat` in POSIX, except that it does not return -// device and inode information. For testing whether two descriptors refer to -// the same underlying filesystem object, use `is-same-object`. To obtain -// additional data that can be used do determine whether a file has been -// modified, use `metadata-hash`. +// File or memory access pattern advisory information. // -// Note: This was called `fd_filestat_get` in earlier versions of WASI. +// enum advice { +// normal, +// sequential, +// random, +// will-need, +// dont-need, +// no-reuse +// } +type Advice uint8 + +const ( + // The application has no advice to give on its behavior with respect + // to the specified data. + AdviceNormal Advice = iota + + // The application expects to access the specified data sequentially + // from lower offsets to higher offsets. + AdviceSequential + + // The application expects to access the specified data in a random + // order. + AdviceRandom + + // The application expects to access the specified data in the near + // future. + AdviceWillNeed + + // The application expects that it will not access the specified data + // in the near future. + AdviceDontNeed + + // The application expects to access the specified data once and then + // not reuse it thereafter. + AdviceNoReuse +) + +// MetadataHashValue represents the record "wasi:filesystem/types@0.2.0#metadata-hash-value". // -// stat: func() -> result +// A 128-bit hash value, split into parts because wasm doesn't have a +// 128-bit integer type. // -//go:nosplit -func (self Descriptor) Stat() cm.OKResult[DescriptorStat, ErrorCode] { - var result cm.OKResult[DescriptorStat, ErrorCode] - self.wasmimport_Stat(&result) - return result -} +// record metadata-hash-value { +// lower: u64, +// upper: u64, +// } +type MetadataHashValue struct { + // 64 bits of a 128-bit hash value. + Lower uint64 -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat -//go:noescape -func (self Descriptor) wasmimport_Stat(result *cm.OKResult[DescriptorStat, ErrorCode]) + // Another 64 bits of a 128-bit hash value. + Upper uint64 +} -// StatAt represents method "stat-at". -// -// Return the attributes of a file or directory. +// Descriptor represents the imported resource "wasi:filesystem/types@0.2.0#descriptor". // -// Note: This is similar to `fstatat` in POSIX, except that it does not -// return device and inode information. See the `stat` description for a -// discussion of alternatives. +// A descriptor is a reference to a filesystem object, which may be a file, +// directory, named pipe, special file, or other object on which filesystem +// calls may be made. // -// Note: This was called `path_filestat_get` in earlier versions of WASI. +// resource descriptor +type Descriptor cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "descriptor". // -// stat-at: func(path-flags: path-flags, path: string) -> result +// Drops a resource handle. // //go:nosplit -func (self Descriptor) StatAt(pathFlags PathFlags, path string) cm.OKResult[DescriptorStat, ErrorCode] { - var result cm.OKResult[DescriptorStat, ErrorCode] - self.wasmimport_StatAt(pathFlags, path, &result) - return result +func (self Descriptor) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorResourceDrop((uint32)(self0)) + return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat-at +//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]descriptor //go:noescape -func (self Descriptor) wasmimport_StatAt(pathFlags PathFlags, path string, result *cm.OKResult[DescriptorStat, ErrorCode]) +func wasmimport_DescriptorResourceDrop(self0 uint32) -// SymlinkAt represents method "symlink-at". +// Advise represents the imported method "advise". // -// Create a symbolic link (also known as a "symlink"). -// -// If `old-path` starts with `/`, the function fails with -// `error-code::not-permitted`. +// Provide file advisory information on a descriptor. // -// Note: This is similar to `symlinkat` in POSIX. +// This is similar to `posix_fadvise` in POSIX. // -// symlink-at: func(old-path: string, new-path: string) -> result<_, error-code> +// advise: func(offset: filesize, length: filesize, advice: advice) -> result<_, error-code> // //go:nosplit -func (self Descriptor) SymlinkAt(oldPath string, newPath string) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SymlinkAt(oldPath, newPath, &result) - return result +func (self Descriptor) Advise(offset FileSize, length FileSize, advice Advice) (result cm.ErrResult[struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + offset0 := (uint64)(offset) + length0 := (uint64)(length) + advice0 := (uint32)(advice) + wasmimport_DescriptorAdvise((uint32)(self0), (uint64)(offset0), (uint64)(length0), (uint32)(advice0), &result) + return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.symlink-at +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.advise //go:noescape -func (self Descriptor) wasmimport_SymlinkAt(oldPath string, newPath string, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_DescriptorAdvise(self0 uint32, offset0 uint64, length0 uint64, advice0 uint32, result *cm.ErrResult[struct{}, ErrorCode]) -// Sync represents method "sync". +// AppendViaStream represents the imported method "append-via-stream". // -// Synchronize the data and metadata of a file to disk. +// Return a stream for appending to a file, if available. // -// This function succeeds with no effect if the file descriptor is not -// opened for writing. +// May fail with an error-code describing why the file cannot be appended. // -// Note: This is similar to `fsync` in POSIX. +// Note: This allows using `write-stream`, which is similar to `write` with +// `O_APPEND` in in POSIX. // -// sync: func() -> result<_, error-code> +// append-via-stream: func() -> result // //go:nosplit -func (self Descriptor) Sync() cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_Sync(&result) - return result +func (self Descriptor) AppendViaStream() (result cm.OKResult[streams.OutputStream, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorAppendViaStream((uint32)(self0), &result) + return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.append-via-stream //go:noescape -func (self Descriptor) wasmimport_Sync(result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_DescriptorAppendViaStream(self0 uint32, result *cm.OKResult[streams.OutputStream, ErrorCode]) -// SyncData represents method "sync-data". -// -// Synchronize the data of a file to disk. +// CreateDirectoryAt represents the imported method "create-directory-at". // -// This function succeeds with no effect if the file descriptor is not -// opened for writing. +// Create a directory. // -// Note: This is similar to `fdatasync` in POSIX. +// Note: This is similar to `mkdirat` in POSIX. // -// sync-data: func() -> result<_, error-code> +// create-directory-at: func(path: string) -> result<_, error-code> // //go:nosplit -func (self Descriptor) SyncData() cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SyncData(&result) - return result +func (self Descriptor) CreateDirectoryAt(path string) (result cm.ErrResult[struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorCreateDirectoryAt((uint32)(self0), (*uint8)(path0), (uint32)(path1), &result) + return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync-data +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.create-directory-at //go:noescape -func (self Descriptor) wasmimport_SyncData(result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_DescriptorCreateDirectoryAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.ErrResult[struct{}, ErrorCode]) -// UnlinkFileAt represents method "unlink-file-at". +// GetFlags represents the imported method "get-flags". // -// Unlink a filesystem object that is not a directory. +// Get flags associated with a descriptor. // -// Return `error-code::is-directory` if the path refers to a directory. -// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. +// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. // -// unlink-file-at: func(path: string) -> result<_, error-code> +// Note: This returns the value that was the `fs_flags` value returned +// from `fdstat_get` in earlier versions of WASI. +// +// get-flags: func() -> result // //go:nosplit -func (self Descriptor) UnlinkFileAt(path string) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_UnlinkFileAt(path, &result) - return result +func (self Descriptor) GetFlags() (result cm.OKResult[DescriptorFlags, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorGetFlags((uint32)(self0), &result) + return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.unlink-file-at +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-flags //go:noescape -func (self Descriptor) wasmimport_UnlinkFileAt(path string, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_DescriptorGetFlags(self0 uint32, result *cm.OKResult[DescriptorFlags, ErrorCode]) -// Write represents method "write". +// GetType represents the imported method "get-type". // -// Write to a descriptor, without using and updating the descriptor's offset. +// Get the dynamic type of a descriptor. // -// It is valid to write past the end of a file; the file is extended to the -// extent of the write, with bytes between the previous end and the start of -// the write set to zero. +// Note: This returns the same value as the `type` field of the `fd-stat` +// returned by `stat`, `stat-at` and similar. // -// In the future, this may change to take a `stream`. +// Note: This returns similar flags to the `st_mode & S_IFMT` value provided +// by `fstat` in POSIX. // -// Note: This is similar to `pwrite` in POSIX. +// Note: This returns the value that was the `fs_filetype` value returned +// from `fdstat_get` in earlier versions of WASI. // -// write: func(buffer: list, offset: filesize) -> result +// get-type: func() -> result // //go:nosplit -func (self Descriptor) Write(buffer cm.List[uint8], offset FileSize) cm.OKResult[FileSize, ErrorCode] { - var result cm.OKResult[FileSize, ErrorCode] - self.wasmimport_Write(buffer, offset, &result) - return result +func (self Descriptor) GetType() (result cm.OKResult[DescriptorType, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorGetType((uint32)(self0), &result) + return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.get-type //go:noescape -func (self Descriptor) wasmimport_Write(buffer cm.List[uint8], offset FileSize, result *cm.OKResult[FileSize, ErrorCode]) +func wasmimport_DescriptorGetType(self0 uint32, result *cm.OKResult[DescriptorType, ErrorCode]) -// WriteViaStream represents method "write-via-stream". -// -// Return a stream for writing to a file, if available. +// IsSameObject represents the imported method "is-same-object". // -// May fail with an error-code describing why the file cannot be written. +// Test whether two descriptors refer to the same filesystem object. // -// Note: This allows using `write-stream`, which is similar to `write` in -// POSIX. +// In POSIX, this corresponds to testing whether the two descriptors have the +// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers. +// wasi-filesystem does not expose device and inode numbers, so this function +// may be used instead. // -// write-via-stream: func(offset: filesize) -> result +// is-same-object: func(other: borrow) -> bool // //go:nosplit -func (self Descriptor) WriteViaStream(offset FileSize) cm.OKResult[OutputStream, ErrorCode] { - var result cm.OKResult[OutputStream, ErrorCode] - self.wasmimport_WriteViaStream(offset, &result) - return result +func (self Descriptor) IsSameObject(other Descriptor) (result bool) { + self0 := cm.Reinterpret[uint32](self) + other0 := cm.Reinterpret[uint32](other) + result0 := wasmimport_DescriptorIsSameObject((uint32)(self0), (uint32)(other0)) + result = cm.U32ToBool((uint32)(result0)) + return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write-via-stream +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.is-same-object //go:noescape -func (self Descriptor) wasmimport_WriteViaStream(offset FileSize, result *cm.OKResult[OutputStream, ErrorCode]) +func wasmimport_DescriptorIsSameObject(self0 uint32, other0 uint32) (result0 uint32) -// DescriptorFlags represents the flags "wasi:filesystem/types@0.2.0#descriptor-flags". +// LinkAt represents the imported method "link-at". // -// Descriptor flags. +// Create a hard link. // -// Note: This was called `fdflags` in earlier versions of WASI. +// Note: This is similar to `linkat` in POSIX. // -// flags descriptor-flags { -// read, -// write, -// file-integrity-sync, -// data-integrity-sync, -// requested-write-sync, -// mutate-directory, -// } -type DescriptorFlags uint8 - -const ( - // Read mode: Data can be read. - DescriptorFlagsRead DescriptorFlags = 1 << iota - - // Write mode: Data can be written to. - DescriptorFlagsWrite - - // Request that writes be performed according to synchronized I/O file - // integrity completion. The data stored in the file and the file's - // metadata are synchronized. This is similar to `O_SYNC` in POSIX. - // - // The precise semantics of this operation have not yet been defined for - // WASI. At this time, it should be interpreted as a request, and not a - // requirement. - DescriptorFlagsFileIntegritySync - - // Request that writes be performed according to synchronized I/O data - // integrity completion. Only the data stored in the file is - // synchronized. This is similar to `O_DSYNC` in POSIX. - // - // The precise semantics of this operation have not yet been defined for - // WASI. At this time, it should be interpreted as a request, and not a - // requirement. - DescriptorFlagsDataIntegritySync - - // Requests that reads be performed at the same level of integrety - // requested for writes. This is similar to `O_RSYNC` in POSIX. - // - // The precise semantics of this operation have not yet been defined for - // WASI. At this time, it should be interpreted as a request, and not a - // requirement. - DescriptorFlagsRequestedWriteSync +// link-at: func(old-path-flags: path-flags, old-path: string, new-descriptor: borrow, +// new-path: string) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) LinkAt(oldPathFlags PathFlags, oldPath string, newDescriptor Descriptor, newPath string) (result cm.ErrResult[struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + oldPathFlags0 := (uint32)(oldPathFlags) + oldPath0, oldPath1 := cm.LowerString(oldPath) + newDescriptor0 := cm.Reinterpret[uint32](newDescriptor) + newPath0, newPath1 := cm.LowerString(newPath) + wasmimport_DescriptorLinkAt((uint32)(self0), (uint32)(oldPathFlags0), (*uint8)(oldPath0), (uint32)(oldPath1), (uint32)(newDescriptor0), (*uint8)(newPath0), (uint32)(newPath1), &result) + return +} - // Mutating directories mode: Directory contents may be mutated. - // - // When this flag is unset on a descriptor, operations using the - // descriptor which would create, rename, delete, modify the data or - // metadata of filesystem objects, or obtain another handle which - // would permit any of those, shall fail with `error-code::read-only` if - // they would otherwise succeed. - // - // This may only be set on directories. - DescriptorFlagsMutateDirectory -) +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.link-at +//go:noescape +func wasmimport_DescriptorLinkAt(self0 uint32, oldPathFlags0 uint32, oldPath0 *uint8, oldPath1 uint32, newDescriptor0 uint32, newPath0 *uint8, newPath1 uint32, result *cm.ErrResult[struct{}, ErrorCode]) -// DescriptorStat represents the record "wasi:filesystem/types@0.2.0#descriptor-stat". -// -// File attributes. +// MetadataHash represents the imported method "metadata-hash". // -// Note: This was called `filestat` in earlier versions of WASI. +// Return a hash of the metadata associated with a filesystem object referred +// to by a descriptor. // -// record descriptor-stat { -// %type: descriptor-type, -// link-count: link-count, -// size: filesize, -// data-access-timestamp: option, -// data-modification-timestamp: option, -// status-change-timestamp: option, -// } -type DescriptorStat struct { - // File type. - Type DescriptorType - - // Number of hard links to the file. - LinkCount LinkCount - - // For regular files, the file size in bytes. For symbolic links, the - // length in bytes of the pathname contained in the symbolic link. - Size FileSize - - // Last data access timestamp. - // - // If the `option` is none, the platform doesn't maintain an access - // timestamp for this file. - DataAccessTimestamp cm.Option[DateTime] - - // Last data modification timestamp. - // - // If the `option` is none, the platform doesn't maintain a - // modification timestamp for this file. - DataModificationTimestamp cm.Option[DateTime] - - // Last file status-change timestamp. - // - // If the `option` is none, the platform doesn't maintain a - // status-change timestamp for this file. - StatusChangeTimestamp cm.Option[DateTime] -} - -// DescriptorType represents the enum "wasi:filesystem/types@0.2.0#descriptor-type". +// This returns a hash of the last-modification timestamp and file size, and +// may also include the inode number, device number, birth timestamp, and +// other metadata fields that may change when the file is modified or +// replaced. It may also include a secret value chosen by the +// implementation and not otherwise exposed. // -// The type of a filesystem object referenced by a descriptor. +// Implementations are encourated to provide the following properties: // -// Note: This was called `filetype` in earlier versions of WASI. +// - If the file is not modified or replaced, the computed hash value should +// usually not change. +// - If the object is modified or replaced, the computed hash value should +// usually change. +// - The inputs to the hash should not be easily computable from the +// computed hash. // -// enum descriptor-type { -// unknown, -// block-device, -// character-device, -// directory, -// fifo, -// symbolic-link, -// regular-file, -// socket -// } -type DescriptorType uint8 - -const ( - // The type of the descriptor or file is unknown or is different from - // any of the other types specified. - DescriptorTypeUnknown DescriptorType = iota - - // The descriptor refers to a block device inode. - DescriptorTypeBlockDevice - - // The descriptor refers to a character device inode. - DescriptorTypeCharacterDevice - - // The descriptor refers to a directory inode. - DescriptorTypeDirectory - - // The descriptor refers to a named pipe. - DescriptorTypeFIFO - - // The file refers to a symbolic link inode. - DescriptorTypeSymbolicLink - - // The descriptor refers to a regular file inode. - DescriptorTypeRegularFile - - // The descriptor refers to a socket. - DescriptorTypeSocket -) - -// DirectoryEntry represents the record "wasi:filesystem/types@0.2.0#directory-entry". +// However, none of these is required. // -// A directory entry. +// metadata-hash: func() -> result // -// record directory-entry { -// %type: descriptor-type, -// name: string, -// } -type DirectoryEntry struct { - // The type of the file referred to by this directory entry. - Type DescriptorType - - // The name of the object. - Name string +//go:nosplit +func (self Descriptor) MetadataHash() (result cm.OKResult[MetadataHashValue, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorMetadataHash((uint32)(self0), &result) + return } -// DirectoryEntryStream represents the resource "wasi:filesystem/types@0.2.0#directory-entry-stream". +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash +//go:noescape +func wasmimport_DescriptorMetadataHash(self0 uint32, result *cm.OKResult[MetadataHashValue, ErrorCode]) + +// MetadataHashAt represents the imported method "metadata-hash-at". // -// A stream of directory entries. +// Return a hash of the metadata associated with a filesystem object referred +// to by a directory descriptor and a relative path. // -// resource directory-entry-stream -type DirectoryEntryStream cm.Resource - -// ResourceDrop represents the Canonical ABI function "resource-drop". +// This performs the same hash computation as `metadata-hash`. // -// Drops a resource handle. +// metadata-hash-at: func(path-flags: path-flags, path: string) -> result // //go:nosplit -func (self DirectoryEntryStream) ResourceDrop() { - self.wasmimport_ResourceDrop() +func (self Descriptor) MetadataHashAt(pathFlags PathFlags, path string) (result cm.OKResult[MetadataHashValue, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + pathFlags0 := (uint32)(pathFlags) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorMetadataHashAt((uint32)(self0), (uint32)(pathFlags0), (*uint8)(path0), (uint32)(path1), &result) + return } -//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]directory-entry-stream +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.metadata-hash-at //go:noescape -func (self DirectoryEntryStream) wasmimport_ResourceDrop() +func wasmimport_DescriptorMetadataHashAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, result *cm.OKResult[MetadataHashValue, ErrorCode]) -// ReadDirectoryEntry represents method "read-directory-entry". +// OpenAt represents the imported method "open-at". // -// Read a single directory entry from a `directory-entry-stream`. +// Open a file or directory. // -// read-directory-entry: func() -> result, error-code> +// The returned descriptor is not guaranteed to be the lowest-numbered +// descriptor not currently open/ it is randomized to prevent applications +// from depending on making assumptions about indexes, since this is +// error-prone in multi-threaded contexts. The returned descriptor is +// guaranteed to be less than 2**31. +// +// If `flags` contains `descriptor-flags::mutate-directory`, and the base +// descriptor doesn't have `descriptor-flags::mutate-directory` set, +// `open-at` fails with `error-code::read-only`. +// +// If `flags` contains `write` or `mutate-directory`, or `open-flags` +// contains `truncate` or `create`, and the base descriptor doesn't have +// `descriptor-flags::mutate-directory` set, `open-at` fails with +// `error-code::read-only`. +// +// Note: This is similar to `openat` in POSIX. +// +// open-at: func(path-flags: path-flags, path: string, open-flags: open-flags, %flags: +// descriptor-flags) -> result // //go:nosplit -func (self DirectoryEntryStream) ReadDirectoryEntry() cm.OKResult[cm.Option[DirectoryEntry], ErrorCode] { - var result cm.OKResult[cm.Option[DirectoryEntry], ErrorCode] - self.wasmimport_ReadDirectoryEntry(&result) - return result +func (self Descriptor) OpenAt(pathFlags PathFlags, path string, openFlags OpenFlags, flags DescriptorFlags) (result cm.OKResult[Descriptor, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + pathFlags0 := (uint32)(pathFlags) + path0, path1 := cm.LowerString(path) + openFlags0 := (uint32)(openFlags) + flags0 := (uint32)(flags) + wasmimport_DescriptorOpenAt((uint32)(self0), (uint32)(pathFlags0), (*uint8)(path0), (uint32)(path1), (uint32)(openFlags0), (uint32)(flags0), &result) + return } -//go:wasmimport wasi:filesystem/types@0.2.0 [method]directory-entry-stream.read-directory-entry +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.open-at //go:noescape -func (self DirectoryEntryStream) wasmimport_ReadDirectoryEntry(result *cm.OKResult[cm.Option[DirectoryEntry], ErrorCode]) +func wasmimport_DescriptorOpenAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, openFlags0 uint32, flags0 uint32, result *cm.OKResult[Descriptor, ErrorCode]) -// Error represents the resource "wasi:io/error@0.2.0#error". +// Read represents the imported method "read". // -// See [ioerror.Error] for more information. -type Error = ioerror.Error - -// ErrorCode represents the enum "wasi:filesystem/types@0.2.0#error-code". +// Read from a descriptor, without using and updating the descriptor's offset. // -// Error codes returned by functions, similar to `errno` in POSIX. -// Not all of these error codes are returned by the functions provided by this -// API; some are used in higher-level library layers, and others are provided -// merely for alignment with POSIX. +// This function returns a list of bytes containing the data that was +// read, along with a bool which, when true, indicates that the end of the +// file was reached. The returned list will contain up to `length` bytes; it +// may return fewer than requested, if the end of the file is reached or +// if the I/O operation is interrupted. // -// enum error-code { -// access, -// would-block, -// already, -// bad-descriptor, -// busy, -// deadlock, -// quota, -// exist, -// file-too-large, -// illegal-byte-sequence, -// in-progress, -// interrupted, -// invalid, -// io, -// is-directory, -// loop, -// too-many-links, -// message-size, -// name-too-long, -// no-device, -// no-entry, -// no-lock, -// insufficient-memory, -// insufficient-space, -// not-directory, -// not-empty, -// not-recoverable, -// unsupported, -// no-tty, -// no-such-device, -// overflow, -// not-permitted, -// pipe, -// read-only, -// invalid-seek, -// text-file-busy, -// cross-device -// } -type ErrorCode uint8 - -const ( - // Permission denied, similar to `EACCES` in POSIX. - ErrorCodeAccess ErrorCode = iota - - // Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` - // in POSIX. - ErrorCodeWouldBlock - - // Connection already in progress, similar to `EALREADY` in POSIX. - ErrorCodeAlready - - // Bad descriptor, similar to `EBADF` in POSIX. - ErrorCodeBadDescriptor - - // Device or resource busy, similar to `EBUSY` in POSIX. - ErrorCodeBusy - - // Resource deadlock would occur, similar to `EDEADLK` in POSIX. - ErrorCodeDeadlock - - // Storage quota exceeded, similar to `EDQUOT` in POSIX. - ErrorCodeQuota - - // File exists, similar to `EEXIST` in POSIX. - ErrorCodeExist - - // File too large, similar to `EFBIG` in POSIX. - ErrorCodeFileTooLarge - - // Illegal byte sequence, similar to `EILSEQ` in POSIX. - ErrorCodeIllegalByteSequence - - // Operation in progress, similar to `EINPROGRESS` in POSIX. - ErrorCodeInProgress - - // Interrupted function, similar to `EINTR` in POSIX. - ErrorCodeInterrupted - - // Invalid argument, similar to `EINVAL` in POSIX. - ErrorCodeInvalid - - // I/O error, similar to `EIO` in POSIX. - ErrorCodeIO - - // Is a directory, similar to `EISDIR` in POSIX. - ErrorCodeIsDirectory - - // Too many levels of symbolic links, similar to `ELOOP` in POSIX. - ErrorCodeLoop +// In the future, this may change to return a `stream`. +// +// Note: This is similar to `pread` in POSIX. +// +// read: func(length: filesize, offset: filesize) -> result, bool>, +// error-code> +// +//go:nosplit +func (self Descriptor) Read(length FileSize, offset FileSize) (result cm.OKResult[cm.Tuple[cm.List[uint8], bool], ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + length0 := (uint64)(length) + offset0 := (uint64)(offset) + wasmimport_DescriptorRead((uint32)(self0), (uint64)(length0), (uint64)(offset0), &result) + return +} - // Too many links, similar to `EMLINK` in POSIX. - ErrorCodeTooManyLinks +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read +//go:noescape +func wasmimport_DescriptorRead(self0 uint32, length0 uint64, offset0 uint64, result *cm.OKResult[cm.Tuple[cm.List[uint8], bool], ErrorCode]) - // Message too large, similar to `EMSGSIZE` in POSIX. - ErrorCodeMessageSize +// ReadDirectory represents the imported method "read-directory". +// +// Read directory entries from a directory. +// +// On filesystems where directories contain entries referring to themselves +// and their parents, often named `.` and `..` respectively, these entries +// are omitted. +// +// This always returns a new stream which starts at the beginning of the +// directory. Multiple streams may be active on the same directory, and they +// do not interfere with each other. +// +// read-directory: func() -> result +// +//go:nosplit +func (self Descriptor) ReadDirectory() (result cm.OKResult[DirectoryEntryStream, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorReadDirectory((uint32)(self0), &result) + return +} - // Filename too long, similar to `ENAMETOOLONG` in POSIX. - ErrorCodeNameTooLong +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-directory +//go:noescape +func wasmimport_DescriptorReadDirectory(self0 uint32, result *cm.OKResult[DirectoryEntryStream, ErrorCode]) - // No such device, similar to `ENODEV` in POSIX. - ErrorCodeNoDevice +// ReadViaStream represents the imported method "read-via-stream". +// +// Return a stream for reading from a file, if available. +// +// May fail with an error-code describing why the file cannot be read. +// +// Multiple read, write, and append streams may be active on the same open +// file and they do not interfere with each other. +// +// Note: This allows using `read-stream`, which is similar to `read` in POSIX. +// +// read-via-stream: func(offset: filesize) -> result +// +//go:nosplit +func (self Descriptor) ReadViaStream(offset FileSize) (result cm.OKResult[streams.InputStream, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + offset0 := (uint64)(offset) + wasmimport_DescriptorReadViaStream((uint32)(self0), (uint64)(offset0), &result) + return +} - // No such file or directory, similar to `ENOENT` in POSIX. - ErrorCodeNoEntry +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.read-via-stream +//go:noescape +func wasmimport_DescriptorReadViaStream(self0 uint32, offset0 uint64, result *cm.OKResult[streams.InputStream, ErrorCode]) - // No locks available, similar to `ENOLCK` in POSIX. - ErrorCodeNoLock +// ReadLinkAt represents the imported method "readlink-at". +// +// Read the contents of a symbolic link. +// +// If the contents contain an absolute or rooted path in the underlying +// filesystem, this function fails with `error-code::not-permitted`. +// +// Note: This is similar to `readlinkat` in POSIX. +// +// readlink-at: func(path: string) -> result +// +//go:nosplit +func (self Descriptor) ReadLinkAt(path string) (result cm.OKResult[string, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorReadLinkAt((uint32)(self0), (*uint8)(path0), (uint32)(path1), &result) + return +} - // Not enough space, similar to `ENOMEM` in POSIX. - ErrorCodeInsufficientMemory +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.readlink-at +//go:noescape +func wasmimport_DescriptorReadLinkAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.OKResult[string, ErrorCode]) - // No space left on device, similar to `ENOSPC` in POSIX. - ErrorCodeInsufficientSpace +// RemoveDirectoryAt represents the imported method "remove-directory-at". +// +// Remove a directory. +// +// Return `error-code::not-empty` if the directory is not empty. +// +// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. +// +// remove-directory-at: func(path: string) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) RemoveDirectoryAt(path string) (result cm.ErrResult[struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorRemoveDirectoryAt((uint32)(self0), (*uint8)(path0), (uint32)(path1), &result) + return +} - // Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. - ErrorCodeNotDirectory +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.remove-directory-at +//go:noescape +func wasmimport_DescriptorRemoveDirectoryAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.ErrResult[struct{}, ErrorCode]) - // Directory not empty, similar to `ENOTEMPTY` in POSIX. - ErrorCodeNotEmpty +// RenameAt represents the imported method "rename-at". +// +// Rename a filesystem object. +// +// Note: This is similar to `renameat` in POSIX. +// +// rename-at: func(old-path: string, new-descriptor: borrow, new-path: +// string) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) RenameAt(oldPath string, newDescriptor Descriptor, newPath string) (result cm.ErrResult[struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + oldPath0, oldPath1 := cm.LowerString(oldPath) + newDescriptor0 := cm.Reinterpret[uint32](newDescriptor) + newPath0, newPath1 := cm.LowerString(newPath) + wasmimport_DescriptorRenameAt((uint32)(self0), (*uint8)(oldPath0), (uint32)(oldPath1), (uint32)(newDescriptor0), (*uint8)(newPath0), (uint32)(newPath1), &result) + return +} - // State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. - ErrorCodeNotRecoverable +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.rename-at +//go:noescape +func wasmimport_DescriptorRenameAt(self0 uint32, oldPath0 *uint8, oldPath1 uint32, newDescriptor0 uint32, newPath0 *uint8, newPath1 uint32, result *cm.ErrResult[struct{}, ErrorCode]) - // Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. - ErrorCodeUnsupported +// SetSize represents the imported method "set-size". +// +// Adjust the size of an open file. If this increases the file's size, the +// extra bytes are filled with zeros. +// +// Note: This was called `fd_filestat_set_size` in earlier versions of WASI. +// +// set-size: func(size: filesize) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) SetSize(size FileSize) (result cm.ErrResult[struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + size0 := (uint64)(size) + wasmimport_DescriptorSetSize((uint32)(self0), (uint64)(size0), &result) + return +} - // Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. - ErrorCodeNoTTY +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-size +//go:noescape +func wasmimport_DescriptorSetSize(self0 uint32, size0 uint64, result *cm.ErrResult[struct{}, ErrorCode]) - // No such device or address, similar to `ENXIO` in POSIX. - ErrorCodeNoSuchDevice +// SetTimes represents the imported method "set-times". +// +// Adjust the timestamps of an open file or directory. +// +// Note: This is similar to `futimens` in POSIX. +// +// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. +// +// set-times: func(data-access-timestamp: new-timestamp, data-modification-timestamp: +// new-timestamp) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) SetTimes(dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) (result cm.ErrResult[struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + dataAccessTimestamp0, dataAccessTimestamp1, dataAccessTimestamp2 := lower_NewTimestamp(dataAccessTimestamp) + dataModificationTimestamp0, dataModificationTimestamp1, dataModificationTimestamp2 := lower_NewTimestamp(dataModificationTimestamp) + wasmimport_DescriptorSetTimes((uint32)(self0), (uint32)(dataAccessTimestamp0), (uint64)(dataAccessTimestamp1), (uint32)(dataAccessTimestamp2), (uint32)(dataModificationTimestamp0), (uint64)(dataModificationTimestamp1), (uint32)(dataModificationTimestamp2), &result) + return +} - // Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. - ErrorCodeOverflow +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times +//go:noescape +func wasmimport_DescriptorSetTimes(self0 uint32, dataAccessTimestamp0 uint32, dataAccessTimestamp1 uint64, dataAccessTimestamp2 uint32, dataModificationTimestamp0 uint32, dataModificationTimestamp1 uint64, dataModificationTimestamp2 uint32, result *cm.ErrResult[struct{}, ErrorCode]) - // Operation not permitted, similar to `EPERM` in POSIX. - ErrorCodeNotPermitted +// SetTimesAt represents the imported method "set-times-at". +// +// Adjust the timestamps of a file or directory. +// +// Note: This is similar to `utimensat` in POSIX. +// +// Note: This was called `path_filestat_set_times` in earlier versions of +// WASI. +// +// set-times-at: func(path-flags: path-flags, path: string, data-access-timestamp: +// new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) SetTimesAt(pathFlags PathFlags, path string, dataAccessTimestamp NewTimestamp, dataModificationTimestamp NewTimestamp) (result cm.ErrResult[struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + pathFlags0 := (uint32)(pathFlags) + path0, path1 := cm.LowerString(path) + dataAccessTimestamp0, dataAccessTimestamp1, dataAccessTimestamp2 := lower_NewTimestamp(dataAccessTimestamp) + dataModificationTimestamp0, dataModificationTimestamp1, dataModificationTimestamp2 := lower_NewTimestamp(dataModificationTimestamp) + wasmimport_DescriptorSetTimesAt((uint32)(self0), (uint32)(pathFlags0), (*uint8)(path0), (uint32)(path1), (uint32)(dataAccessTimestamp0), (uint64)(dataAccessTimestamp1), (uint32)(dataAccessTimestamp2), (uint32)(dataModificationTimestamp0), (uint64)(dataModificationTimestamp1), (uint32)(dataModificationTimestamp2), &result) + return +} - // Broken pipe, similar to `EPIPE` in POSIX. - ErrorCodePipe +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.set-times-at +//go:noescape +func wasmimport_DescriptorSetTimesAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, dataAccessTimestamp0 uint32, dataAccessTimestamp1 uint64, dataAccessTimestamp2 uint32, dataModificationTimestamp0 uint32, dataModificationTimestamp1 uint64, dataModificationTimestamp2 uint32, result *cm.ErrResult[struct{}, ErrorCode]) - // Read-only file system, similar to `EROFS` in POSIX. - ErrorCodeReadOnly +// Stat represents the imported method "stat". +// +// Return the attributes of an open file or directory. +// +// Note: This is similar to `fstat` in POSIX, except that it does not return +// device and inode information. For testing whether two descriptors refer to +// the same underlying filesystem object, use `is-same-object`. To obtain +// additional data that can be used do determine whether a file has been +// modified, use `metadata-hash`. +// +// Note: This was called `fd_filestat_get` in earlier versions of WASI. +// +// stat: func() -> result +// +//go:nosplit +func (self Descriptor) Stat() (result cm.OKResult[DescriptorStat, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorStat((uint32)(self0), &result) + return +} - // Invalid seek, similar to `ESPIPE` in POSIX. - ErrorCodeInvalidSeek +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat +//go:noescape +func wasmimport_DescriptorStat(self0 uint32, result *cm.OKResult[DescriptorStat, ErrorCode]) - // Text file busy, similar to `ETXTBSY` in POSIX. - ErrorCodeTextFileBusy +// StatAt represents the imported method "stat-at". +// +// Return the attributes of a file or directory. +// +// Note: This is similar to `fstatat` in POSIX, except that it does not +// return device and inode information. See the `stat` description for a +// discussion of alternatives. +// +// Note: This was called `path_filestat_get` in earlier versions of WASI. +// +// stat-at: func(path-flags: path-flags, path: string) -> result +// +//go:nosplit +func (self Descriptor) StatAt(pathFlags PathFlags, path string) (result cm.OKResult[DescriptorStat, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + pathFlags0 := (uint32)(pathFlags) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorStatAt((uint32)(self0), (uint32)(pathFlags0), (*uint8)(path0), (uint32)(path1), &result) + return +} - // Cross-device link, similar to `EXDEV` in POSIX. - ErrorCodeCrossDevice -) +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.stat-at +//go:noescape +func wasmimport_DescriptorStatAt(self0 uint32, pathFlags0 uint32, path0 *uint8, path1 uint32, result *cm.OKResult[DescriptorStat, ErrorCode]) -// FileSize represents the type "wasi:filesystem/types@0.2.0#filesize". +// SymlinkAt represents the imported method "symlink-at". // -// File size or length of a region within a file. +// Create a symbolic link (also known as a "symlink"). // -// type filesize = u64 -type FileSize uint64 - -// InputStream represents the resource "wasi:io/streams@0.2.0#input-stream". +// If `old-path` starts with `/`, the function fails with +// `error-code::not-permitted`. // -// See [streams.InputStream] for more information. -type InputStream = streams.InputStream - -// LinkCount represents the type "wasi:filesystem/types@0.2.0#link-count". +// Note: This is similar to `symlinkat` in POSIX. // -// Number of hard links to an inode. +// symlink-at: func(old-path: string, new-path: string) -> result<_, error-code> // -// type link-count = u64 -type LinkCount uint64 +//go:nosplit +func (self Descriptor) SymlinkAt(oldPath string, newPath string) (result cm.ErrResult[struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + oldPath0, oldPath1 := cm.LowerString(oldPath) + newPath0, newPath1 := cm.LowerString(newPath) + wasmimport_DescriptorSymlinkAt((uint32)(self0), (*uint8)(oldPath0), (uint32)(oldPath1), (*uint8)(newPath0), (uint32)(newPath1), &result) + return +} -// MetadataHashValue represents the record "wasi:filesystem/types@0.2.0#metadata-hash-value". +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.symlink-at +//go:noescape +func wasmimport_DescriptorSymlinkAt(self0 uint32, oldPath0 *uint8, oldPath1 uint32, newPath0 *uint8, newPath1 uint32, result *cm.ErrResult[struct{}, ErrorCode]) + +// Sync represents the imported method "sync". // -// A 128-bit hash value, split into parts because wasm doesn't have a -// 128-bit integer type. +// Synchronize the data and metadata of a file to disk. // -// record metadata-hash-value { -// lower: u64, -// upper: u64, -// } -type MetadataHashValue struct { - // 64 bits of a 128-bit hash value. - Lower uint64 - - // Another 64 bits of a 128-bit hash value. - Upper uint64 +// This function succeeds with no effect if the file descriptor is not +// opened for writing. +// +// Note: This is similar to `fsync` in POSIX. +// +// sync: func() -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) Sync() (result cm.ErrResult[struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorSync((uint32)(self0), &result) + return } -// NewTimestamp represents the variant "wasi:filesystem/types@0.2.0#new-timestamp". +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync +//go:noescape +func wasmimport_DescriptorSync(self0 uint32, result *cm.ErrResult[struct{}, ErrorCode]) + +// SyncData represents the imported method "sync-data". // -// When setting a timestamp, this gives the value to set it to. +// Synchronize the data of a file to disk. // -// variant new-timestamp { -// no-change, -// now, -// timestamp(datetime), -// } -type NewTimestamp cm.Variant[uint8, DateTime, DateTime] - -// NewTimestampNoChange returns a [NewTimestamp] of case "no-change". +// This function succeeds with no effect if the file descriptor is not +// opened for writing. // -// Leave the timestamp set to its previous value. -func NewTimestampNoChange() NewTimestamp { - var data struct{} - return cm.New[NewTimestamp](0, data) +// Note: This is similar to `fdatasync` in POSIX. +// +// sync-data: func() -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) SyncData() (result cm.ErrResult[struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DescriptorSyncData((uint32)(self0), &result) + return } -// NoChange returns true if [NewTimestamp] represents the variant case "no-change". -func (self *NewTimestamp) NoChange() bool { - return cm.Tag(self) == 0 -} +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.sync-data +//go:noescape +func wasmimport_DescriptorSyncData(self0 uint32, result *cm.ErrResult[struct{}, ErrorCode]) -// NewTimestampNow returns a [NewTimestamp] of case "now". +// UnlinkFileAt represents the imported method "unlink-file-at". // -// Set the timestamp to the current time of the system clock associated -// with the filesystem. -func NewTimestampNow() NewTimestamp { - var data struct{} - return cm.New[NewTimestamp](1, data) +// Unlink a filesystem object that is not a directory. +// +// Return `error-code::is-directory` if the path refers to a directory. +// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. +// +// unlink-file-at: func(path: string) -> result<_, error-code> +// +//go:nosplit +func (self Descriptor) UnlinkFileAt(path string) (result cm.ErrResult[struct{}, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + path0, path1 := cm.LowerString(path) + wasmimport_DescriptorUnlinkFileAt((uint32)(self0), (*uint8)(path0), (uint32)(path1), &result) + return } -// Now returns true if [NewTimestamp] represents the variant case "now". -func (self *NewTimestamp) Now() bool { - return cm.Tag(self) == 1 -} +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.unlink-file-at +//go:noescape +func wasmimport_DescriptorUnlinkFileAt(self0 uint32, path0 *uint8, path1 uint32, result *cm.ErrResult[struct{}, ErrorCode]) -// NewTimestampTimestamp returns a [NewTimestamp] of case "timestamp". +// Write represents the imported method "write". // -// Set the timestamp to the given value. -func NewTimestampTimestamp(data DateTime) NewTimestamp { - return cm.New[NewTimestamp](2, data) +// Write to a descriptor, without using and updating the descriptor's offset. +// +// It is valid to write past the end of a file; the file is extended to the +// extent of the write, with bytes between the previous end and the start of +// the write set to zero. +// +// In the future, this may change to take a `stream`. +// +// Note: This is similar to `pwrite` in POSIX. +// +// write: func(buffer: list, offset: filesize) -> result +// +//go:nosplit +func (self Descriptor) Write(buffer cm.List[uint8], offset FileSize) (result cm.OKResult[FileSize, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + buffer0, buffer1 := cm.LowerList(buffer) + offset0 := (uint64)(offset) + wasmimport_DescriptorWrite((uint32)(self0), (*uint8)(buffer0), (uint32)(buffer1), (uint64)(offset0), &result) + return } -// Timestamp returns a non-nil *[DateTime] if [NewTimestamp] represents the variant case "timestamp". -func (self *NewTimestamp) Timestamp() *DateTime { - return cm.Case[DateTime](self, 2) -} +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write +//go:noescape +func wasmimport_DescriptorWrite(self0 uint32, buffer0 *uint8, buffer1 uint32, offset0 uint64, result *cm.OKResult[FileSize, ErrorCode]) -// OpenFlags represents the flags "wasi:filesystem/types@0.2.0#open-flags". +// WriteViaStream represents the imported method "write-via-stream". // -// Open flags used by `open-at`. +// Return a stream for writing to a file, if available. // -// flags open-flags { -// create, -// directory, -// exclusive, -// truncate, -// } -type OpenFlags uint8 +// May fail with an error-code describing why the file cannot be written. +// +// Note: This allows using `write-stream`, which is similar to `write` in +// POSIX. +// +// write-via-stream: func(offset: filesize) -> result +// +//go:nosplit +func (self Descriptor) WriteViaStream(offset FileSize) (result cm.OKResult[streams.OutputStream, ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + offset0 := (uint64)(offset) + wasmimport_DescriptorWriteViaStream((uint32)(self0), (uint64)(offset0), &result) + return +} -const ( - // Create file if it does not exist, similar to `O_CREAT` in POSIX. - OpenFlagsCreate OpenFlags = 1 << iota +//go:wasmimport wasi:filesystem/types@0.2.0 [method]descriptor.write-via-stream +//go:noescape +func wasmimport_DescriptorWriteViaStream(self0 uint32, offset0 uint64, result *cm.OKResult[streams.OutputStream, ErrorCode]) - // Fail if not a directory, similar to `O_DIRECTORY` in POSIX. - OpenFlagsDirectory +// DirectoryEntryStream represents the imported resource "wasi:filesystem/types@0.2.0#directory-entry-stream". +// +// A stream of directory entries. +// +// resource directory-entry-stream +type DirectoryEntryStream cm.Resource - // Fail if file already exists, similar to `O_EXCL` in POSIX. - OpenFlagsExclusive +// ResourceDrop represents the imported resource-drop for resource "directory-entry-stream". +// +// Drops a resource handle. +// +//go:nosplit +func (self DirectoryEntryStream) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DirectoryEntryStreamResourceDrop((uint32)(self0)) + return +} - // Truncate file to size 0, similar to `O_TRUNC` in POSIX. - OpenFlagsTruncate -) +//go:wasmimport wasi:filesystem/types@0.2.0 [resource-drop]directory-entry-stream +//go:noescape +func wasmimport_DirectoryEntryStreamResourceDrop(self0 uint32) -// OutputStream represents the resource "wasi:io/streams@0.2.0#output-stream". +// ReadDirectoryEntry represents the imported method "read-directory-entry". // -// See [streams.OutputStream] for more information. -type OutputStream = streams.OutputStream - -// PathFlags represents the flags "wasi:filesystem/types@0.2.0#path-flags". +// Read a single directory entry from a `directory-entry-stream`. // -// Flags determining the method of how paths are resolved. +// read-directory-entry: func() -> result, error-code> // -// flags path-flags { -// symlink-follow, -// } -type PathFlags uint8 +//go:nosplit +func (self DirectoryEntryStream) ReadDirectoryEntry() (result cm.OKResult[cm.Option[DirectoryEntry], ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_DirectoryEntryStreamReadDirectoryEntry((uint32)(self0), &result) + return +} -const ( - // As long as the resolved path corresponds to a symbolic link, it is - // expanded. - PathFlagsSymlinkFollow PathFlags = 1 << iota -) +//go:wasmimport wasi:filesystem/types@0.2.0 [method]directory-entry-stream.read-directory-entry +//go:noescape +func wasmimport_DirectoryEntryStreamReadDirectoryEntry(self0 uint32, result *cm.OKResult[cm.Option[DirectoryEntry], ErrorCode]) -// FilesystemErrorCode represents function "wasi:filesystem/types@0.2.0#filesystem-error-code". +// FilesystemErrorCode represents the imported function "filesystem-error-code". // // Attempts to extract a filesystem-related `error-code` from the stream // `error` provided. @@ -1248,12 +1273,12 @@ const ( // filesystem-error-code: func(err: borrow) -> option // //go:nosplit -func FilesystemErrorCode(err Error) cm.Option[ErrorCode] { - var result cm.Option[ErrorCode] - wasmimport_FilesystemErrorCode(err, &result) - return result +func FilesystemErrorCode(err ioerror.Error) (result cm.Option[ErrorCode]) { + err0 := cm.Reinterpret[uint32](err) + wasmimport_FilesystemErrorCode((uint32)(err0), &result) + return } //go:wasmimport wasi:filesystem/types@0.2.0 filesystem-error-code //go:noescape -func wasmimport_FilesystemErrorCode(err Error, result *cm.Option[ErrorCode]) +func wasmimport_FilesystemErrorCode(err0 uint32, result *cm.Option[ErrorCode]) 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 e2d6cf76e6..f962f22ea3 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 @@ -2,14 +2,14 @@ //go:build !wasip1 -// Package ioerror represents the interface "wasi:io/error@0.2.0". +// Package ioerror represents the imported interface "wasi:io/error@0.2.0". package ioerror import ( "github.com/ydnar/wasm-tools-go/cm" ) -// Error represents the resource "wasi:io/error@0.2.0#error". +// Error represents the imported resource "wasi:io/error@0.2.0#error". // // A resource which represents some error information. // @@ -34,20 +34,22 @@ import ( // resource error type Error cm.Resource -// ResourceDrop represents the Canonical ABI function "resource-drop". +// ResourceDrop represents the imported resource-drop for resource "error". // // Drops a resource handle. // //go:nosplit func (self Error) ResourceDrop() { - self.wasmimport_ResourceDrop() + self0 := cm.Reinterpret[uint32](self) + wasmimport_ErrorResourceDrop((uint32)(self0)) + return } //go:wasmimport wasi:io/error@0.2.0 [resource-drop]error //go:noescape -func (self Error) wasmimport_ResourceDrop() +func wasmimport_ErrorResourceDrop(self0 uint32) -// ToDebugString represents method "to-debug-string". +// ToDebugString represents the imported method "to-debug-string". // // Returns a string that is suitable to assist humans in debugging // this error. @@ -60,12 +62,12 @@ func (self Error) wasmimport_ResourceDrop() // to-debug-string: func() -> string // //go:nosplit -func (self Error) ToDebugString() string { - var result string - self.wasmimport_ToDebugString(&result) - return result +func (self Error) ToDebugString() (result string) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ErrorToDebugString((uint32)(self0), &result) + return } //go:wasmimport wasi:io/error@0.2.0 [method]error.to-debug-string //go:noescape -func (self Error) wasmimport_ToDebugString(result *string) +func wasmimport_ErrorToDebugString(self0 uint32, result *string) 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 61eb2db5c9..0c362c0791 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package poll represents the interface "wasi:io/poll@0.2.0". +// Package poll represents the imported interface "wasi:io/poll@0.2.0". // // A poll API intended to let users wait for I/O events on multiple handles // at once. @@ -12,27 +12,29 @@ import ( "github.com/ydnar/wasm-tools-go/cm" ) -// Pollable represents the resource "wasi:io/poll@0.2.0#pollable". +// Pollable represents the imported resource "wasi:io/poll@0.2.0#pollable". // // `pollable` represents a single I/O event which may be ready, or not. // // resource pollable type Pollable cm.Resource -// ResourceDrop represents the Canonical ABI function "resource-drop". +// ResourceDrop represents the imported resource-drop for resource "pollable". // // Drops a resource handle. // //go:nosplit func (self Pollable) ResourceDrop() { - self.wasmimport_ResourceDrop() + self0 := cm.Reinterpret[uint32](self) + wasmimport_PollableResourceDrop((uint32)(self0)) + return } //go:wasmimport wasi:io/poll@0.2.0 [resource-drop]pollable //go:noescape -func (self Pollable) wasmimport_ResourceDrop() +func wasmimport_PollableResourceDrop(self0 uint32) -// Block represents method "block". +// Block represents the imported method "block". // // `block` returns immediately if the pollable is ready, and otherwise // blocks until ready. @@ -44,14 +46,16 @@ func (self Pollable) wasmimport_ResourceDrop() // //go:nosplit func (self Pollable) Block() { - self.wasmimport_Block() + self0 := cm.Reinterpret[uint32](self) + wasmimport_PollableBlock((uint32)(self0)) + return } //go:wasmimport wasi:io/poll@0.2.0 [method]pollable.block //go:noescape -func (self Pollable) wasmimport_Block() +func wasmimport_PollableBlock(self0 uint32) -// Ready represents method "ready". +// Ready represents the imported method "ready". // // Return the readiness of a pollable. This function never blocks. // @@ -60,15 +64,18 @@ func (self Pollable) wasmimport_Block() // ready: func() -> bool // //go:nosplit -func (self Pollable) Ready() bool { - return self.wasmimport_Ready() +func (self Pollable) Ready() (result bool) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_PollableReady((uint32)(self0)) + result = cm.U32ToBool((uint32)(result0)) + return } //go:wasmimport wasi:io/poll@0.2.0 [method]pollable.ready //go:noescape -func (self Pollable) wasmimport_Ready() bool +func wasmimport_PollableReady(self0 uint32) (result0 uint32) -// Poll represents function "wasi:io/poll@0.2.0#poll". +// Poll represents the imported function "poll". // // Poll for completion on a set of pollables. // @@ -92,12 +99,12 @@ func (self Pollable) wasmimport_Ready() bool // poll: func(in: list>) -> list // //go:nosplit -func Poll(in cm.List[Pollable]) cm.List[uint32] { - var result cm.List[uint32] - wasmimport_Poll(in, &result) - return result +func Poll(in cm.List[Pollable]) (result cm.List[uint32]) { + in0, in1 := cm.LowerList(in) + wasmimport_Poll((*Pollable)(in0), (uint32)(in1), &result) + return } //go:wasmimport wasi:io/poll@0.2.0 poll //go:noescape -func wasmimport_Poll(in cm.List[Pollable], result *cm.List[uint32]) +func wasmimport_Poll(in0 *Pollable, in1 uint32, result *cm.List[uint32]) 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 f10fe5907f..8983d5ac0c 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package streams represents the interface "wasi:io/streams@0.2.0". +// Package streams represents the imported interface "wasi:io/streams@0.2.0". // // WASI I/O is an I/O abstraction API which is currently focused on providing // stream types. @@ -17,12 +17,46 @@ import ( "internal/wasi/io/v0.2.0/poll" ) -// Error represents the resource "wasi:io/error@0.2.0#error". +// StreamError represents the imported variant "wasi:io/streams@0.2.0#stream-error". // -// See [ioerror.Error] for more information. -type Error = ioerror.Error +// An error for input-stream and output-stream operations. +// +// variant stream-error { +// last-operation-failed(error), +// closed, +// } +type StreamError cm.Variant[uint8, ioerror.Error, ioerror.Error] -// InputStream represents the resource "wasi:io/streams@0.2.0#input-stream". +// StreamErrorLastOperationFailed returns a [StreamError] of case "last-operation-failed". +// +// The last operation (a write or flush) failed before completion. +// +// More information is available in the `error` payload. +func StreamErrorLastOperationFailed(data ioerror.Error) StreamError { + return cm.New[StreamError](0, data) +} + +// LastOperationFailed returns a non-nil *[ioerror.Error] if [StreamError] represents the variant case "last-operation-failed". +func (self *StreamError) LastOperationFailed() *ioerror.Error { + return cm.Case[ioerror.Error](self, 0) +} + +// StreamErrorClosed returns a [StreamError] of case "closed". +// +// The stream is closed: no more input will be accepted by the +// stream. A closed output-stream will return this error on all +// future operations. +func StreamErrorClosed() StreamError { + var data struct{} + return cm.New[StreamError](1, data) +} + +// Closed returns true if [StreamError] represents the variant case "closed". +func (self *StreamError) Closed() bool { + return cm.Tag(self) == 1 +} + +// InputStream represents the imported resource "wasi:io/streams@0.2.0#input-stream". // // An input bytestream. // @@ -36,20 +70,22 @@ type Error = ioerror.Error // resource input-stream type InputStream cm.Resource -// ResourceDrop represents the Canonical ABI function "resource-drop". +// ResourceDrop represents the imported resource-drop for resource "input-stream". // // Drops a resource handle. // //go:nosplit func (self InputStream) ResourceDrop() { - self.wasmimport_ResourceDrop() + self0 := cm.Reinterpret[uint32](self) + wasmimport_InputStreamResourceDrop((uint32)(self0)) + return } //go:wasmimport wasi:io/streams@0.2.0 [resource-drop]input-stream //go:noescape -func (self InputStream) wasmimport_ResourceDrop() +func wasmimport_InputStreamResourceDrop(self0 uint32) -// BlockingRead represents method "blocking-read". +// BlockingRead represents the imported method "blocking-read". // // Read bytes from a stream, after blocking until at least one byte can // be read. Except for blocking, behavior is identical to `read`. @@ -57,17 +93,18 @@ func (self InputStream) wasmimport_ResourceDrop() // blocking-read: func(len: u64) -> result, stream-error> // //go:nosplit -func (self InputStream) BlockingRead(len_ uint64) cm.OKResult[cm.List[uint8], StreamError] { - var result cm.OKResult[cm.List[uint8], StreamError] - self.wasmimport_BlockingRead(len_, &result) - return result +func (self InputStream) BlockingRead(len_ uint64) (result cm.OKResult[cm.List[uint8], StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_InputStreamBlockingRead((uint32)(self0), (uint64)(len0), &result) + return } //go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-read //go:noescape -func (self InputStream) wasmimport_BlockingRead(len_ uint64, result *cm.OKResult[cm.List[uint8], StreamError]) +func wasmimport_InputStreamBlockingRead(self0 uint32, len0 uint64, result *cm.OKResult[cm.List[uint8], StreamError]) -// BlockingSkip represents method "blocking-skip". +// BlockingSkip represents the imported method "blocking-skip". // // Skip bytes from a stream, after blocking until at least one byte // can be skipped. Except for blocking behavior, identical to `skip`. @@ -75,17 +112,18 @@ func (self InputStream) wasmimport_BlockingRead(len_ uint64, result *cm.OKResult // blocking-skip: func(len: u64) -> result // //go:nosplit -func (self InputStream) BlockingSkip(len_ uint64) cm.OKResult[uint64, StreamError] { - var result cm.OKResult[uint64, StreamError] - self.wasmimport_BlockingSkip(len_, &result) - return result +func (self InputStream) BlockingSkip(len_ uint64) (result cm.OKResult[uint64, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_InputStreamBlockingSkip((uint32)(self0), (uint64)(len0), &result) + return } //go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-skip //go:noescape -func (self InputStream) wasmimport_BlockingSkip(len_ uint64, result *cm.OKResult[uint64, StreamError]) +func wasmimport_InputStreamBlockingSkip(self0 uint32, len0 uint64, result *cm.OKResult[uint64, StreamError]) -// Read represents method "read". +// Read represents the imported method "read". // // Perform a non-blocking read from the stream. // @@ -117,17 +155,18 @@ func (self InputStream) wasmimport_BlockingSkip(len_ uint64, result *cm.OKResult // read: func(len: u64) -> result, stream-error> // //go:nosplit -func (self InputStream) Read(len_ uint64) cm.OKResult[cm.List[uint8], StreamError] { - var result cm.OKResult[cm.List[uint8], StreamError] - self.wasmimport_Read(len_, &result) - return result +func (self InputStream) Read(len_ uint64) (result cm.OKResult[cm.List[uint8], StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_InputStreamRead((uint32)(self0), (uint64)(len0), &result) + return } //go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.read //go:noescape -func (self InputStream) wasmimport_Read(len_ uint64, result *cm.OKResult[cm.List[uint8], StreamError]) +func wasmimport_InputStreamRead(self0 uint32, len0 uint64, result *cm.OKResult[cm.List[uint8], StreamError]) -// Skip represents method "skip". +// Skip represents the imported method "skip". // // Skip bytes from a stream. Returns number of bytes skipped. // @@ -137,17 +176,18 @@ func (self InputStream) wasmimport_Read(len_ uint64, result *cm.OKResult[cm.List // skip: func(len: u64) -> result // //go:nosplit -func (self InputStream) Skip(len_ uint64) cm.OKResult[uint64, StreamError] { - var result cm.OKResult[uint64, StreamError] - self.wasmimport_Skip(len_, &result) - return result +func (self InputStream) Skip(len_ uint64) (result cm.OKResult[uint64, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_InputStreamSkip((uint32)(self0), (uint64)(len0), &result) + return } //go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.skip //go:noescape -func (self InputStream) wasmimport_Skip(len_ uint64, result *cm.OKResult[uint64, StreamError]) +func wasmimport_InputStreamSkip(self0 uint32, len0 uint64, result *cm.OKResult[uint64, StreamError]) -// Subscribe represents method "subscribe". +// Subscribe represents the imported method "subscribe". // // Create a `pollable` which will resolve once either the specified stream // has bytes available to read or the other end of the stream has been @@ -159,15 +199,18 @@ func (self InputStream) wasmimport_Skip(len_ uint64, result *cm.OKResult[uint64, // subscribe: func() -> pollable // //go:nosplit -func (self InputStream) Subscribe() Pollable { - return self.wasmimport_Subscribe() +func (self InputStream) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_InputStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return } //go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.subscribe //go:noescape -func (self InputStream) wasmimport_Subscribe() Pollable +func wasmimport_InputStreamSubscribe(self0 uint32) (result0 uint32) -// OutputStream represents the resource "wasi:io/streams@0.2.0#output-stream". +// OutputStream represents the imported resource "wasi:io/streams@0.2.0#output-stream". // // An output bytestream. // @@ -181,20 +224,22 @@ func (self InputStream) wasmimport_Subscribe() Pollable // resource output-stream type OutputStream cm.Resource -// ResourceDrop represents the Canonical ABI function "resource-drop". +// ResourceDrop represents the imported resource-drop for resource "output-stream". // // Drops a resource handle. // //go:nosplit func (self OutputStream) ResourceDrop() { - self.wasmimport_ResourceDrop() + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutputStreamResourceDrop((uint32)(self0)) + return } //go:wasmimport wasi:io/streams@0.2.0 [resource-drop]output-stream //go:noescape -func (self OutputStream) wasmimport_ResourceDrop() +func wasmimport_OutputStreamResourceDrop(self0 uint32) -// BlockingFlush represents method "blocking-flush". +// BlockingFlush represents the imported method "blocking-flush". // // Request to flush buffered output, and block until flush completes // and stream is ready for writing again. @@ -202,17 +247,17 @@ func (self OutputStream) wasmimport_ResourceDrop() // blocking-flush: func() -> result<_, stream-error> // //go:nosplit -func (self OutputStream) BlockingFlush() cm.ErrResult[struct{}, StreamError] { - var result cm.ErrResult[struct{}, StreamError] - self.wasmimport_BlockingFlush(&result) - return result +func (self OutputStream) BlockingFlush() (result cm.ErrResult[struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutputStreamBlockingFlush((uint32)(self0), &result) + return } //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-flush //go:noescape -func (self OutputStream) wasmimport_BlockingFlush(result *cm.ErrResult[struct{}, StreamError]) +func wasmimport_OutputStreamBlockingFlush(self0 uint32, result *cm.ErrResult[struct{}, StreamError]) -// BlockingSplice represents method "blocking-splice". +// BlockingSplice represents the imported method "blocking-splice". // // Read from one stream and write to another, with blocking. // @@ -223,17 +268,19 @@ func (self OutputStream) wasmimport_BlockingFlush(result *cm.ErrResult[struct{}, // blocking-splice: func(src: borrow, len: u64) -> result // //go:nosplit -func (self OutputStream) BlockingSplice(src InputStream, len_ uint64) cm.OKResult[uint64, StreamError] { - var result cm.OKResult[uint64, StreamError] - self.wasmimport_BlockingSplice(src, len_, &result) - return result +func (self OutputStream) BlockingSplice(src InputStream, len_ uint64) (result cm.OKResult[uint64, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + src0 := cm.Reinterpret[uint32](src) + len0 := (uint64)(len_) + wasmimport_OutputStreamBlockingSplice((uint32)(self0), (uint32)(src0), (uint64)(len0), &result) + return } //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-splice //go:noescape -func (self OutputStream) wasmimport_BlockingSplice(src InputStream, len_ uint64, result *cm.OKResult[uint64, StreamError]) +func wasmimport_OutputStreamBlockingSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.OKResult[uint64, StreamError]) -// BlockingWriteAndFlush represents method "blocking-write-and-flush". +// BlockingWriteAndFlush represents the imported method "blocking-write-and-flush". // // Perform a write of up to 4096 bytes, and then flush the stream. Block // until all of these operations are complete, or an error occurs. @@ -261,17 +308,18 @@ func (self OutputStream) wasmimport_BlockingSplice(src InputStream, len_ uint64, // blocking-write-and-flush: func(contents: list) -> result<_, stream-error> // //go:nosplit -func (self OutputStream) BlockingWriteAndFlush(contents cm.List[uint8]) cm.ErrResult[struct{}, StreamError] { - var result cm.ErrResult[struct{}, StreamError] - self.wasmimport_BlockingWriteAndFlush(contents, &result) - return result +func (self OutputStream) BlockingWriteAndFlush(contents cm.List[uint8]) (result cm.ErrResult[struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + contents0, contents1 := cm.LowerList(contents) + wasmimport_OutputStreamBlockingWriteAndFlush((uint32)(self0), (*uint8)(contents0), (uint32)(contents1), &result) + return } //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-and-flush //go:noescape -func (self OutputStream) wasmimport_BlockingWriteAndFlush(contents cm.List[uint8], result *cm.ErrResult[struct{}, StreamError]) +func wasmimport_OutputStreamBlockingWriteAndFlush(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.ErrResult[struct{}, StreamError]) -// BlockingWriteZeroesAndFlush represents method "blocking-write-zeroes-and-flush". +// BlockingWriteZeroesAndFlush represents the imported method "blocking-write-zeroes-and-flush". // // Perform a write of up to 4096 zeroes, and then flush the stream. // Block until all of these operations are complete, or an error @@ -299,17 +347,18 @@ func (self OutputStream) wasmimport_BlockingWriteAndFlush(contents cm.List[uint8 // blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error> // //go:nosplit -func (self OutputStream) BlockingWriteZeroesAndFlush(len_ uint64) cm.ErrResult[struct{}, StreamError] { - var result cm.ErrResult[struct{}, StreamError] - self.wasmimport_BlockingWriteZeroesAndFlush(len_, &result) - return result +func (self OutputStream) BlockingWriteZeroesAndFlush(len_ uint64) (result cm.ErrResult[struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_OutputStreamBlockingWriteZeroesAndFlush((uint32)(self0), (uint64)(len0), &result) + return } //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-zeroes-and-flush //go:noescape -func (self OutputStream) wasmimport_BlockingWriteZeroesAndFlush(len_ uint64, result *cm.ErrResult[struct{}, StreamError]) +func wasmimport_OutputStreamBlockingWriteZeroesAndFlush(self0 uint32, len0 uint64, result *cm.ErrResult[struct{}, StreamError]) -// CheckWrite represents method "check-write". +// CheckWrite represents the imported method "check-write". // // Check readiness for writing. This function never blocks. // @@ -324,17 +373,17 @@ func (self OutputStream) wasmimport_BlockingWriteZeroesAndFlush(len_ uint64, res // check-write: func() -> result // //go:nosplit -func (self OutputStream) CheckWrite() cm.OKResult[uint64, StreamError] { - var result cm.OKResult[uint64, StreamError] - self.wasmimport_CheckWrite(&result) - return result +func (self OutputStream) CheckWrite() (result cm.OKResult[uint64, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutputStreamCheckWrite((uint32)(self0), &result) + return } //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.check-write //go:noescape -func (self OutputStream) wasmimport_CheckWrite(result *cm.OKResult[uint64, StreamError]) +func wasmimport_OutputStreamCheckWrite(self0 uint32, result *cm.OKResult[uint64, StreamError]) -// Flush represents method "flush". +// Flush represents the imported method "flush". // // Request to flush buffered output. This function never blocks. // @@ -350,17 +399,17 @@ func (self OutputStream) wasmimport_CheckWrite(result *cm.OKResult[uint64, Strea // flush: func() -> result<_, stream-error> // //go:nosplit -func (self OutputStream) Flush() cm.ErrResult[struct{}, StreamError] { - var result cm.ErrResult[struct{}, StreamError] - self.wasmimport_Flush(&result) - return result +func (self OutputStream) Flush() (result cm.ErrResult[struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutputStreamFlush((uint32)(self0), &result) + return } //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.flush //go:noescape -func (self OutputStream) wasmimport_Flush(result *cm.ErrResult[struct{}, StreamError]) +func wasmimport_OutputStreamFlush(self0 uint32, result *cm.ErrResult[struct{}, StreamError]) -// Splice represents method "splice". +// Splice represents the imported method "splice". // // Read from one stream and write to another. // @@ -379,17 +428,19 @@ func (self OutputStream) wasmimport_Flush(result *cm.ErrResult[struct{}, StreamE // splice: func(src: borrow, len: u64) -> result // //go:nosplit -func (self OutputStream) Splice(src InputStream, len_ uint64) cm.OKResult[uint64, StreamError] { - var result cm.OKResult[uint64, StreamError] - self.wasmimport_Splice(src, len_, &result) - return result +func (self OutputStream) Splice(src InputStream, len_ uint64) (result cm.OKResult[uint64, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + src0 := cm.Reinterpret[uint32](src) + len0 := (uint64)(len_) + wasmimport_OutputStreamSplice((uint32)(self0), (uint32)(src0), (uint64)(len0), &result) + return } //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.splice //go:noescape -func (self OutputStream) wasmimport_Splice(src InputStream, len_ uint64, result *cm.OKResult[uint64, StreamError]) +func wasmimport_OutputStreamSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.OKResult[uint64, StreamError]) -// Subscribe represents method "subscribe". +// Subscribe represents the imported method "subscribe". // // Create a `pollable` which will resolve once the output-stream // is ready for more writing, or an error has occured. When this @@ -405,15 +456,18 @@ func (self OutputStream) wasmimport_Splice(src InputStream, len_ uint64, result // subscribe: func() -> pollable // //go:nosplit -func (self OutputStream) Subscribe() Pollable { - return self.wasmimport_Subscribe() +func (self OutputStream) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutputStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return } //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.subscribe //go:noescape -func (self OutputStream) wasmimport_Subscribe() Pollable +func wasmimport_OutputStreamSubscribe(self0 uint32) (result0 uint32) -// Write represents method "write". +// Write represents the imported method "write". // // Perform a write. This function never blocks. // @@ -432,17 +486,18 @@ func (self OutputStream) wasmimport_Subscribe() Pollable // write: func(contents: list) -> result<_, stream-error> // //go:nosplit -func (self OutputStream) Write(contents cm.List[uint8]) cm.ErrResult[struct{}, StreamError] { - var result cm.ErrResult[struct{}, StreamError] - self.wasmimport_Write(contents, &result) - return result +func (self OutputStream) Write(contents cm.List[uint8]) (result cm.ErrResult[struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + contents0, contents1 := cm.LowerList(contents) + wasmimport_OutputStreamWrite((uint32)(self0), (*uint8)(contents0), (uint32)(contents1), &result) + return } //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write //go:noescape -func (self OutputStream) wasmimport_Write(contents cm.List[uint8], result *cm.ErrResult[struct{}, StreamError]) +func wasmimport_OutputStreamWrite(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.ErrResult[struct{}, StreamError]) -// WriteZeroes represents method "write-zeroes". +// WriteZeroes represents the imported method "write-zeroes". // // Write zeroes to a stream. // @@ -454,56 +509,13 @@ func (self OutputStream) wasmimport_Write(contents cm.List[uint8], result *cm.Er // write-zeroes: func(len: u64) -> result<_, stream-error> // //go:nosplit -func (self OutputStream) WriteZeroes(len_ uint64) cm.ErrResult[struct{}, StreamError] { - var result cm.ErrResult[struct{}, StreamError] - self.wasmimport_WriteZeroes(len_, &result) - return result +func (self OutputStream) WriteZeroes(len_ uint64) (result cm.ErrResult[struct{}, StreamError]) { + self0 := cm.Reinterpret[uint32](self) + len0 := (uint64)(len_) + wasmimport_OutputStreamWriteZeroes((uint32)(self0), (uint64)(len0), &result) + return } //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write-zeroes //go:noescape -func (self OutputStream) wasmimport_WriteZeroes(len_ uint64, result *cm.ErrResult[struct{}, StreamError]) - -// Pollable represents the resource "wasi:io/poll@0.2.0#pollable". -// -// See [poll.Pollable] for more information. -type Pollable = poll.Pollable - -// StreamError represents the variant "wasi:io/streams@0.2.0#stream-error". -// -// An error for input-stream and output-stream operations. -// -// variant stream-error { -// last-operation-failed(error), -// closed, -// } -type StreamError cm.Variant[uint8, Error, Error] - -// StreamErrorLastOperationFailed returns a [StreamError] of case "last-operation-failed". -// -// The last operation (a write or flush) failed before completion. -// -// More information is available in the `error` payload. -func StreamErrorLastOperationFailed(data Error) StreamError { - return cm.New[StreamError](0, data) -} - -// LastOperationFailed returns a non-nil *[Error] if [StreamError] represents the variant case "last-operation-failed". -func (self *StreamError) LastOperationFailed() *Error { - return cm.Case[Error](self, 0) -} - -// StreamErrorClosed returns a [StreamError] of case "closed". -// -// The stream is closed: no more input will be accepted by the -// stream. A closed output-stream will return this error on all -// future operations. -func StreamErrorClosed() StreamError { - var data struct{} - return cm.New[StreamError](1, data) -} - -// Closed returns true if [StreamError] represents the variant case "closed". -func (self *StreamError) Closed() bool { - return cm.Tag(self) == 1 -} +func wasmimport_OutputStreamWriteZeroes(self0 uint32, len0 uint64, result *cm.ErrResult[struct{}, StreamError]) diff --git a/src/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go b/src/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go index 05c0a84e36..e9ac780821 100644 --- a/src/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go +++ b/src/internal/wasi/random/v0.2.0/insecure-seed/insecure-seed.wit.go @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package insecureseed represents the interface "wasi:random/insecure-seed@0.2.0". +// Package insecureseed represents the imported interface "wasi:random/insecure-seed@0.2.0". // // The insecure-seed interface for seeding hash-map DoS resistance. // @@ -10,7 +10,7 @@ // Windows. package insecureseed -// InsecureSeed represents function "wasi:random/insecure-seed@0.2.0#insecure-seed". +// InsecureSeed represents the imported function "insecure-seed". // // Return a 128-bit value that may contain a pseudo-random value. // @@ -33,10 +33,9 @@ package insecureseed // insecure-seed: func() -> tuple // //go:nosplit -func InsecureSeed() [2]uint64 { - var result [2]uint64 +func InsecureSeed() (result [2]uint64) { wasmimport_InsecureSeed(&result) - return result + return } //go:wasmimport wasi:random/insecure-seed@0.2.0 insecure-seed 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 f5d7c32526..fbea789b5d 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package insecure represents the interface "wasi:random/insecure@0.2.0". +// Package insecure represents the imported interface "wasi:random/insecure@0.2.0". // // The insecure interface for insecure pseudo-random numbers. // @@ -14,7 +14,7 @@ import ( "github.com/ydnar/wasm-tools-go/cm" ) -// GetInsecureRandomBytes represents function "wasi:random/insecure@0.2.0#get-insecure-random-bytes". +// GetInsecureRandomBytes represents the imported function "get-insecure-random-bytes". // // Return `len` insecure pseudo-random bytes. // @@ -28,17 +28,17 @@ import ( // get-insecure-random-bytes: func(len: u64) -> list // //go:nosplit -func GetInsecureRandomBytes(len_ uint64) cm.List[uint8] { - var result cm.List[uint8] - wasmimport_GetInsecureRandomBytes(len_, &result) - return result +func GetInsecureRandomBytes(len_ uint64) (result cm.List[uint8]) { + len0 := (uint64)(len_) + wasmimport_GetInsecureRandomBytes((uint64)(len0), &result) + return } //go:wasmimport wasi:random/insecure@0.2.0 get-insecure-random-bytes //go:noescape -func wasmimport_GetInsecureRandomBytes(len_ uint64, result *cm.List[uint8]) +func wasmimport_GetInsecureRandomBytes(len0 uint64, result *cm.List[uint8]) -// GetInsecureRandomU64 represents function "wasi:random/insecure@0.2.0#get-insecure-random-u64". +// GetInsecureRandomU64 represents the imported function "get-insecure-random-u64". // // Return an insecure pseudo-random `u64` value. // @@ -48,10 +48,12 @@ func wasmimport_GetInsecureRandomBytes(len_ uint64, result *cm.List[uint8]) // get-insecure-random-u64: func() -> u64 // //go:nosplit -func GetInsecureRandomU64() uint64 { - return wasmimport_GetInsecureRandomU64() +func GetInsecureRandomU64() (result uint64) { + result0 := wasmimport_GetInsecureRandomU64() + result = (uint64)((uint64)(result0)) + return } //go:wasmimport wasi:random/insecure@0.2.0 get-insecure-random-u64 //go:noescape -func wasmimport_GetInsecureRandomU64() uint64 +func wasmimport_GetInsecureRandomU64() (result0 uint64) 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 700af66be1..f60d468e19 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package random represents the interface "wasi:random/random@0.2.0". +// Package random represents the imported interface "wasi:random/random@0.2.0". // // WASI Random is a random data API. // @@ -14,7 +14,7 @@ import ( "github.com/ydnar/wasm-tools-go/cm" ) -// GetRandomBytes represents function "wasi:random/random@0.2.0#get-random-bytes". +// GetRandomBytes represents the imported function "get-random-bytes". // // Return `len` cryptographically-secure random or pseudo-random bytes. // @@ -32,17 +32,17 @@ import ( // get-random-bytes: func(len: u64) -> list // //go:nosplit -func GetRandomBytes(len_ uint64) cm.List[uint8] { - var result cm.List[uint8] - wasmimport_GetRandomBytes(len_, &result) - return result +func GetRandomBytes(len_ uint64) (result cm.List[uint8]) { + len0 := (uint64)(len_) + wasmimport_GetRandomBytes((uint64)(len0), &result) + return } //go:wasmimport wasi:random/random@0.2.0 get-random-bytes //go:noescape -func wasmimport_GetRandomBytes(len_ uint64, result *cm.List[uint8]) +func wasmimport_GetRandomBytes(len0 uint64, result *cm.List[uint8]) -// GetRandomU64 represents function "wasi:random/random@0.2.0#get-random-u64". +// GetRandomU64 represents the imported function "get-random-u64". // // Return a cryptographically-secure random or pseudo-random `u64` value. // @@ -52,10 +52,12 @@ func wasmimport_GetRandomBytes(len_ uint64, result *cm.List[uint8]) // get-random-u64: func() -> u64 // //go:nosplit -func GetRandomU64() uint64 { - return wasmimport_GetRandomU64() +func GetRandomU64() (result uint64) { + result0 := wasmimport_GetRandomU64() + result = (uint64)((uint64)(result0)) + return } //go:wasmimport wasi:random/random@0.2.0 get-random-u64 //go:noescape -func wasmimport_GetRandomU64() uint64 +func wasmimport_GetRandomU64() (result0 uint64) 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 defa8261b3..fbd9dc8ad4 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 @@ -2,31 +2,29 @@ //go:build !wasip1 -// Package instancenetwork represents the interface "wasi:sockets/instance-network@0.2.0". +// Package instancenetwork represents the imported interface "wasi:sockets/instance-network@0.2.0". // // This interface provides a value-export of the default network handle.. package instancenetwork import ( + "github.com/ydnar/wasm-tools-go/cm" "internal/wasi/sockets/v0.2.0/network" ) -// Network represents the resource "wasi:sockets/network@0.2.0#network". -// -// See [network.Network] for more information. -type Network = network.Network - -// InstanceNetwork represents function "wasi:sockets/instance-network@0.2.0#instance-network". +// InstanceNetwork represents the imported function "instance-network". // // Get a handle to the default network. // // instance-network: func() -> network // //go:nosplit -func InstanceNetwork() Network { - return wasmimport_InstanceNetwork() +func InstanceNetwork() (result network.Network) { + result0 := wasmimport_InstanceNetwork() + result = cm.Reinterpret[network.Network]((uint32)(result0)) + return } //go:wasmimport wasi:sockets/instance-network@0.2.0 instance-network //go:noescape -func wasmimport_InstanceNetwork() Network +func wasmimport_InstanceNetwork() (result0 uint32) 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 21f04a9ef1..fc81b36ac8 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package ipnamelookup represents the interface "wasi:sockets/ip-name-lookup@0.2.0". +// Package ipnamelookup represents the imported interface "wasi:sockets/ip-name-lookup@0.2.0". package ipnamelookup import ( @@ -11,45 +11,27 @@ import ( "internal/wasi/sockets/v0.2.0/network" ) -// ErrorCode represents the enum "wasi:sockets/network@0.2.0#error-code". -// -// See [network.ErrorCode] for more information. -type ErrorCode = network.ErrorCode - -// IPAddress represents the variant "wasi:sockets/network@0.2.0#ip-address". -// -// See [network.IPAddress] for more information. -type IPAddress = network.IPAddress - -// Network represents the resource "wasi:sockets/network@0.2.0#network". -// -// See [network.Network] for more information. -type Network = network.Network - -// Pollable represents the resource "wasi:io/poll@0.2.0#pollable". -// -// See [poll.Pollable] for more information. -type Pollable = poll.Pollable - -// ResolveAddressStream represents the resource "wasi:sockets/ip-name-lookup@0.2.0#resolve-address-stream". +// ResolveAddressStream represents the imported resource "wasi:sockets/ip-name-lookup@0.2.0#resolve-address-stream". // // resource resolve-address-stream type ResolveAddressStream cm.Resource -// ResourceDrop represents the Canonical ABI function "resource-drop". +// ResourceDrop represents the imported resource-drop for resource "resolve-address-stream". // // Drops a resource handle. // //go:nosplit func (self ResolveAddressStream) ResourceDrop() { - self.wasmimport_ResourceDrop() + self0 := cm.Reinterpret[uint32](self) + wasmimport_ResolveAddressStreamResourceDrop((uint32)(self0)) + return } //go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [resource-drop]resolve-address-stream //go:noescape -func (self ResolveAddressStream) wasmimport_ResourceDrop() +func wasmimport_ResolveAddressStreamResourceDrop(self0 uint32) -// ResolveNextAddress represents method "resolve-next-address". +// ResolveNextAddress represents the imported method "resolve-next-address". // // Returns the next address from the resolver. // @@ -71,17 +53,17 @@ func (self ResolveAddressStream) wasmimport_ResourceDrop() // resolve-next-address: func() -> result, error-code> // //go:nosplit -func (self ResolveAddressStream) ResolveNextAddress() cm.OKResult[cm.Option[IPAddress], ErrorCode] { - var result cm.OKResult[cm.Option[IPAddress], ErrorCode] - self.wasmimport_ResolveNextAddress(&result) - return result +func (self ResolveAddressStream) ResolveNextAddress() (result cm.OKResult[cm.Option[network.IPAddress], network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_ResolveAddressStreamResolveNextAddress((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [method]resolve-address-stream.resolve-next-address //go:noescape -func (self ResolveAddressStream) wasmimport_ResolveNextAddress(result *cm.OKResult[cm.Option[IPAddress], ErrorCode]) +func wasmimport_ResolveAddressStreamResolveNextAddress(self0 uint32, result *cm.OKResult[cm.Option[network.IPAddress], network.ErrorCode]) -// Subscribe represents method "subscribe". +// Subscribe represents the imported method "subscribe". // // Create a `pollable` which will resolve once the stream is ready for I/O. // @@ -91,15 +73,18 @@ func (self ResolveAddressStream) wasmimport_ResolveNextAddress(result *cm.OKResu // subscribe: func() -> pollable // //go:nosplit -func (self ResolveAddressStream) Subscribe() Pollable { - return self.wasmimport_Subscribe() +func (self ResolveAddressStream) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_ResolveAddressStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return } //go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 [method]resolve-address-stream.subscribe //go:noescape -func (self ResolveAddressStream) wasmimport_Subscribe() Pollable +func wasmimport_ResolveAddressStreamSubscribe(self0 uint32) (result0 uint32) -// ResolveAddresses represents function "wasi:sockets/ip-name-lookup@0.2.0#resolve-addresses". +// ResolveAddresses represents the imported function "resolve-addresses". // // Resolve an internet host name to a list of IP addresses. // @@ -126,12 +111,13 @@ func (self ResolveAddressStream) wasmimport_Subscribe() Pollable // error-code> // //go:nosplit -func ResolveAddresses(network_ Network, name string) cm.OKResult[ResolveAddressStream, ErrorCode] { - var result cm.OKResult[ResolveAddressStream, ErrorCode] - wasmimport_ResolveAddresses(network_, name, &result) - return result +func ResolveAddresses(network_ network.Network, name string) (result cm.OKResult[ResolveAddressStream, network.ErrorCode]) { + network0 := cm.Reinterpret[uint32](network_) + name0, name1 := cm.LowerString(name) + wasmimport_ResolveAddresses((uint32)(network0), (*uint8)(name0), (uint32)(name1), &result) + return } //go:wasmimport wasi:sockets/ip-name-lookup@0.2.0 resolve-addresses //go:noescape -func wasmimport_ResolveAddresses(network_ Network, name string, result *cm.OKResult[ResolveAddressStream, ErrorCode]) +func wasmimport_ResolveAddresses(network0 uint32, name0 *uint8, name1 uint32, result *cm.OKResult[ResolveAddressStream, network.ErrorCode]) 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 43aa8e79cf..4cca93aca0 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 @@ -2,13 +2,37 @@ //go:build !wasip1 -// Package network represents the interface "wasi:sockets/network@0.2.0". +// Package network represents the imported interface "wasi:sockets/network@0.2.0". package network import ( "github.com/ydnar/wasm-tools-go/cm" ) +// Network represents the imported resource "wasi:sockets/network@0.2.0#network". +// +// An opaque resource that represents access to (a subset of) the network. +// This enables context-based security for networking. +// There is no need for this to map 1:1 to a physical network interface. +// +// resource network +type Network cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "network". +// +// Drops a resource handle. +// +//go:nosplit +func (self Network) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_NetworkResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:sockets/network@0.2.0 [resource-drop]network +//go:noescape +func wasmimport_NetworkResourceDrop(self0 uint32) + // ErrorCode represents the enum "wasi:sockets/network@0.2.0#error-code". // // Error codes. @@ -135,6 +159,32 @@ const ( ErrorCodePermanentResolverFailure ) +// IPAddressFamily represents the enum "wasi:sockets/network@0.2.0#ip-address-family". +// +// enum ip-address-family { +// ipv4, +// ipv6 +// } +type IPAddressFamily uint8 + +const ( + // Similar to `AF_INET` in POSIX. + IPAddressFamilyIPv4 IPAddressFamily = iota + + // Similar to `AF_INET6` in POSIX. + IPAddressFamilyIPv6 +) + +// IPv4Address represents the tuple "wasi:sockets/network@0.2.0#ipv4-address". +// +// type ipv4-address = tuple +type IPv4Address [4]uint8 + +// IPv6Address represents the tuple "wasi:sockets/network@0.2.0#ipv6-address". +// +// type ipv6-address = tuple +type IPv6Address [8]uint16 + // IPAddress represents the variant "wasi:sockets/network@0.2.0#ip-address". // // variant ip-address { @@ -163,55 +213,6 @@ func (self *IPAddress) IPv6() *IPv6Address { return cm.Case[IPv6Address](self, 1) } -// IPAddressFamily represents the enum "wasi:sockets/network@0.2.0#ip-address-family". -// -// enum ip-address-family { -// ipv4, -// ipv6 -// } -type IPAddressFamily uint8 - -const ( - // Similar to `AF_INET` in POSIX. - IPAddressFamilyIPv4 IPAddressFamily = iota - - // Similar to `AF_INET6` in POSIX. - IPAddressFamilyIPv6 -) - -// IPSocketAddress represents the variant "wasi:sockets/network@0.2.0#ip-socket-address". -// -// variant ip-socket-address { -// ipv4(ipv4-socket-address), -// ipv6(ipv6-socket-address), -// } -type IPSocketAddress cm.Variant[uint8, IPv6SocketAddress, IPv6SocketAddress] - -// IPSocketAddressIPv4 returns a [IPSocketAddress] of case "ipv4". -func IPSocketAddressIPv4(data IPv4SocketAddress) IPSocketAddress { - return cm.New[IPSocketAddress](0, data) -} - -// IPv4 returns a non-nil *[IPv4SocketAddress] if [IPSocketAddress] represents the variant case "ipv4". -func (self *IPSocketAddress) IPv4() *IPv4SocketAddress { - return cm.Case[IPv4SocketAddress](self, 0) -} - -// IPSocketAddressIPv6 returns a [IPSocketAddress] of case "ipv6". -func IPSocketAddressIPv6(data IPv6SocketAddress) IPSocketAddress { - return cm.New[IPSocketAddress](1, data) -} - -// IPv6 returns a non-nil *[IPv6SocketAddress] if [IPSocketAddress] represents the variant case "ipv6". -func (self *IPSocketAddress) IPv6() *IPv6SocketAddress { - return cm.Case[IPv6SocketAddress](self, 1) -} - -// IPv4Address represents the tuple "wasi:sockets/network@0.2.0#ipv4-address". -// -// type ipv4-address = tuple -type IPv4Address [4]uint8 - // IPv4SocketAddress represents the record "wasi:sockets/network@0.2.0#ipv4-socket-address". // // record ipv4-socket-address { @@ -226,11 +227,6 @@ type IPv4SocketAddress struct { Address IPv4Address } -// IPv6Address represents the tuple "wasi:sockets/network@0.2.0#ipv6-address". -// -// type ipv6-address = tuple -type IPv6Address [8]uint16 - // IPv6SocketAddress represents the record "wasi:sockets/network@0.2.0#ipv6-socket-address". // // record ipv6-socket-address { @@ -253,24 +249,30 @@ type IPv6SocketAddress struct { ScopeID uint32 } -// Network represents the resource "wasi:sockets/network@0.2.0#network". -// -// An opaque resource that represents access to (a subset of) the network. -// This enables context-based security for networking. -// There is no need for this to map 1:1 to a physical network interface. +// IPSocketAddress represents the variant "wasi:sockets/network@0.2.0#ip-socket-address". // -// resource network -type Network cm.Resource +// variant ip-socket-address { +// ipv4(ipv4-socket-address), +// ipv6(ipv6-socket-address), +// } +type IPSocketAddress cm.Variant[uint8, IPv6SocketAddress, IPv6SocketAddress] -// ResourceDrop represents the Canonical ABI function "resource-drop". -// -// Drops a resource handle. -// -//go:nosplit -func (self Network) ResourceDrop() { - self.wasmimport_ResourceDrop() +// IPSocketAddressIPv4 returns a [IPSocketAddress] of case "ipv4". +func IPSocketAddressIPv4(data IPv4SocketAddress) IPSocketAddress { + return cm.New[IPSocketAddress](0, data) } -//go:wasmimport wasi:sockets/network@0.2.0 [resource-drop]network -//go:noescape -func (self Network) wasmimport_ResourceDrop() +// IPv4 returns a non-nil *[IPv4SocketAddress] if [IPSocketAddress] represents the variant case "ipv4". +func (self *IPSocketAddress) IPv4() *IPv4SocketAddress { + return cm.Case[IPv4SocketAddress](self, 0) +} + +// IPSocketAddressIPv6 returns a [IPSocketAddress] of case "ipv6". +func IPSocketAddressIPv6(data IPv6SocketAddress) IPSocketAddress { + return cm.New[IPSocketAddress](1, data) +} + +// IPv6 returns a non-nil *[IPv6SocketAddress] if [IPSocketAddress] represents the variant case "ipv6". +func (self *IPSocketAddress) IPv6() *IPv6SocketAddress { + return cm.Case[IPv6SocketAddress](self, 1) +} 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 cf0ec64e7c..906128abea 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package tcpcreatesocket represents the interface "wasi:sockets/tcp-create-socket@0.2.0". +// Package tcpcreatesocket represents the imported interface "wasi:sockets/tcp-create-socket@0.2.0". package tcpcreatesocket import ( @@ -11,27 +11,7 @@ import ( "internal/wasi/sockets/v0.2.0/tcp" ) -// ErrorCode represents the enum "wasi:sockets/network@0.2.0#error-code". -// -// See [network.ErrorCode] for more information. -type ErrorCode = network.ErrorCode - -// IPAddressFamily represents the enum "wasi:sockets/network@0.2.0#ip-address-family". -// -// See [network.IPAddressFamily] for more information. -type IPAddressFamily = network.IPAddressFamily - -// Network represents the resource "wasi:sockets/network@0.2.0#network". -// -// See [network.Network] for more information. -type Network = network.Network - -// TCPSocket represents the resource "wasi:sockets/tcp@0.2.0#tcp-socket". -// -// See [tcp.TCPSocket] for more information. -type TCPSocket = tcp.TCPSocket - -// CreateTCPSocket represents function "wasi:sockets/tcp-create-socket@0.2.0#create-tcp-socket". +// CreateTCPSocket represents the imported function "create-tcp-socket". // // Create a new TCP socket. // @@ -63,12 +43,12 @@ type TCPSocket = tcp.TCPSocket // error-code> // //go:nosplit -func CreateTCPSocket(addressFamily IPAddressFamily) cm.OKResult[TCPSocket, ErrorCode] { - var result cm.OKResult[TCPSocket, ErrorCode] - wasmimport_CreateTCPSocket(addressFamily, &result) - return result +func CreateTCPSocket(addressFamily network.IPAddressFamily) (result cm.OKResult[tcp.TCPSocket, network.ErrorCode]) { + addressFamily0 := (uint32)(addressFamily) + wasmimport_CreateTCPSocket((uint32)(addressFamily0), &result) + return } //go:wasmimport wasi:sockets/tcp-create-socket@0.2.0 create-tcp-socket //go:noescape -func wasmimport_CreateTCPSocket(addressFamily IPAddressFamily, result *cm.OKResult[TCPSocket, ErrorCode]) +func wasmimport_CreateTCPSocket(addressFamily0 uint32, result *cm.OKResult[tcp.TCPSocket, network.ErrorCode]) diff --git a/src/internal/wasi/sockets/v0.2.0/tcp/abi.go b/src/internal/wasi/sockets/v0.2.0/tcp/abi.go new file mode 100644 index 0000000000..fecab79fdf --- /dev/null +++ b/src/internal/wasi/sockets/v0.2.0/tcp/abi.go @@ -0,0 +1,71 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +//go:build !wasip1 + +package tcp + +import ( + "github.com/ydnar/wasm-tools-go/cm" + "internal/wasi/sockets/v0.2.0/network" +) + +func lower_IPv4Address(v network.IPv4Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32) { + f0 = (uint32)(v[0]) + f1 = (uint32)(v[1]) + f2 = (uint32)(v[2]) + f3 = (uint32)(v[3]) + return +} + +func lower_IPv4SocketAddress(v network.IPv4SocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32) { + f0 = (uint32)(v.Port) + f1, f2, f3, f4 = lower_IPv4Address(v.Address) + return +} + +func lower_IPv6Address(v network.IPv6Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32) { + f0 = (uint32)(v[0]) + f1 = (uint32)(v[1]) + f2 = (uint32)(v[2]) + f3 = (uint32)(v[3]) + f4 = (uint32)(v[4]) + f5 = (uint32)(v[5]) + f6 = (uint32)(v[6]) + f7 = (uint32)(v[7]) + return +} + +func lower_IPv6SocketAddress(v network.IPv6SocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32) { + f0 = (uint32)(v.Port) + f1 = (uint32)(v.FlowInfo) + f2, f3, f4, f5, f6, f7, f8, f9 = lower_IPv6Address(v.Address) + f10 = (uint32)(v.ScopeID) + return +} + +func lower_IPSocketAddress(v network.IPSocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32, f11 uint32) { + f0 = (uint32)(cm.Tag(&v)) + switch f0 { + case 0: // ipv4 + v1, v2, v3, v4, v5 := lower_IPv4SocketAddress(*v.IPv4()) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + case 1: // ipv6 + v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 := lower_IPv6SocketAddress(*v.IPv6()) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + f6 = (uint32)(v6) + f7 = (uint32)(v7) + f8 = (uint32)(v8) + f9 = (uint32)(v9) + f10 = (uint32)(v10) + f11 = (uint32)(v11) + } + return +} 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 623b641c93..f390849cba 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package tcp represents the interface "wasi:sockets/tcp@0.2.0". +// Package tcp represents the imported interface "wasi:sockets/tcp@0.2.0". package tcp import ( @@ -13,46 +13,6 @@ import ( "internal/wasi/sockets/v0.2.0/network" ) -// Duration represents the type "wasi:clocks/monotonic-clock@0.2.0#duration". -// -// See [monotonicclock.Duration] for more information. -type Duration = monotonicclock.Duration - -// ErrorCode represents the enum "wasi:sockets/network@0.2.0#error-code". -// -// See [network.ErrorCode] for more information. -type ErrorCode = network.ErrorCode - -// InputStream represents the resource "wasi:io/streams@0.2.0#input-stream". -// -// See [streams.InputStream] for more information. -type InputStream = streams.InputStream - -// IPAddressFamily represents the enum "wasi:sockets/network@0.2.0#ip-address-family". -// -// See [network.IPAddressFamily] for more information. -type IPAddressFamily = network.IPAddressFamily - -// IPSocketAddress represents the variant "wasi:sockets/network@0.2.0#ip-socket-address". -// -// See [network.IPSocketAddress] for more information. -type IPSocketAddress = network.IPSocketAddress - -// Network represents the resource "wasi:sockets/network@0.2.0#network". -// -// See [network.Network] for more information. -type Network = network.Network - -// OutputStream represents the resource "wasi:io/streams@0.2.0#output-stream". -// -// See [streams.OutputStream] for more information. -type OutputStream = streams.OutputStream - -// Pollable represents the resource "wasi:io/poll@0.2.0#pollable". -// -// See [poll.Pollable] for more information. -type Pollable = poll.Pollable - // ShutdownType represents the enum "wasi:sockets/tcp@0.2.0#shutdown-type". // // enum shutdown-type { @@ -73,7 +33,7 @@ const ( ShutdownTypeBoth ) -// TCPSocket represents the resource "wasi:sockets/tcp@0.2.0#tcp-socket". +// TCPSocket represents the imported resource "wasi:sockets/tcp@0.2.0#tcp-socket". // // A TCP socket resource. // @@ -101,20 +61,22 @@ const ( // resource tcp-socket type TCPSocket cm.Resource -// ResourceDrop represents the Canonical ABI function "resource-drop". +// ResourceDrop represents the imported resource-drop for resource "tcp-socket". // // Drops a resource handle. // //go:nosplit func (self TCPSocket) ResourceDrop() { - self.wasmimport_ResourceDrop() + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketResourceDrop((uint32)(self0)) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [resource-drop]tcp-socket //go:noescape -func (self TCPSocket) wasmimport_ResourceDrop() +func wasmimport_TCPSocketResourceDrop(self0 uint32) -// Accept represents method "accept". +// Accept represents the imported method "accept". // // Accept a new client socket. // @@ -149,17 +111,17 @@ func (self TCPSocket) wasmimport_ResourceDrop() // accept: func() -> result, error-code> // //go:nosplit -func (self TCPSocket) Accept() cm.OKResult[cm.Tuple3[TCPSocket, InputStream, OutputStream], ErrorCode] { - var result cm.OKResult[cm.Tuple3[TCPSocket, InputStream, OutputStream], ErrorCode] - self.wasmimport_Accept(&result) - return result +func (self TCPSocket) Accept() (result cm.OKResult[cm.Tuple3[TCPSocket, streams.InputStream, streams.OutputStream], network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketAccept((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.accept //go:noescape -func (self TCPSocket) wasmimport_Accept(result *cm.OKResult[cm.Tuple3[TCPSocket, InputStream, OutputStream], ErrorCode]) +func wasmimport_TCPSocketAccept(self0 uint32, result *cm.OKResult[cm.Tuple3[TCPSocket, streams.InputStream, streams.OutputStream], network.ErrorCode]) -// AddressFamily represents method "address-family". +// AddressFamily represents the imported method "address-family". // // Whether this is a IPv4 or IPv6 socket. // @@ -168,60 +130,63 @@ func (self TCPSocket) wasmimport_Accept(result *cm.OKResult[cm.Tuple3[TCPSocket, // address-family: func() -> ip-address-family // //go:nosplit -func (self TCPSocket) AddressFamily() IPAddressFamily { - return self.wasmimport_AddressFamily() +func (self TCPSocket) AddressFamily() (result network.IPAddressFamily) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_TCPSocketAddressFamily((uint32)(self0)) + result = (network.IPAddressFamily)((uint32)(result0)) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.address-family //go:noescape -func (self TCPSocket) wasmimport_AddressFamily() IPAddressFamily +func wasmimport_TCPSocketAddressFamily(self0 uint32) (result0 uint32) -// FinishBind represents method "finish-bind". +// FinishBind represents the imported method "finish-bind". // // finish-bind: func() -> result<_, error-code> // //go:nosplit -func (self TCPSocket) FinishBind() cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_FinishBind(&result) - return result +func (self TCPSocket) FinishBind() (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketFinishBind((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-bind //go:noescape -func (self TCPSocket) wasmimport_FinishBind(result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_TCPSocketFinishBind(self0 uint32, result *cm.ErrResult[struct{}, network.ErrorCode]) -// FinishConnect represents method "finish-connect". +// FinishConnect represents the imported method "finish-connect". // // finish-connect: func() -> result, error-code> // //go:nosplit -func (self TCPSocket) FinishConnect() cm.OKResult[cm.Tuple[InputStream, OutputStream], ErrorCode] { - var result cm.OKResult[cm.Tuple[InputStream, OutputStream], ErrorCode] - self.wasmimport_FinishConnect(&result) - return result +func (self TCPSocket) FinishConnect() (result cm.OKResult[cm.Tuple[streams.InputStream, streams.OutputStream], network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketFinishConnect((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-connect //go:noescape -func (self TCPSocket) wasmimport_FinishConnect(result *cm.OKResult[cm.Tuple[InputStream, OutputStream], ErrorCode]) +func wasmimport_TCPSocketFinishConnect(self0 uint32, result *cm.OKResult[cm.Tuple[streams.InputStream, streams.OutputStream], network.ErrorCode]) -// FinishListen represents method "finish-listen". +// FinishListen represents the imported method "finish-listen". // // finish-listen: func() -> result<_, error-code> // //go:nosplit -func (self TCPSocket) FinishListen() cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_FinishListen(&result) - return result +func (self TCPSocket) FinishListen() (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketFinishListen((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.finish-listen //go:noescape -func (self TCPSocket) wasmimport_FinishListen(result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_TCPSocketFinishListen(self0 uint32, result *cm.ErrResult[struct{}, network.ErrorCode]) -// HopLimit represents method "hop-limit". +// HopLimit represents the imported method "hop-limit". // // Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. // @@ -233,17 +198,17 @@ func (self TCPSocket) wasmimport_FinishListen(result *cm.ErrResult[struct{}, Err // hop-limit: func() -> result // //go:nosplit -func (self TCPSocket) HopLimit() cm.OKResult[uint8, ErrorCode] { - var result cm.OKResult[uint8, ErrorCode] - self.wasmimport_HopLimit(&result) - return result +func (self TCPSocket) HopLimit() (result cm.OKResult[uint8, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketHopLimit((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.hop-limit //go:noescape -func (self TCPSocket) wasmimport_HopLimit(result *cm.OKResult[uint8, ErrorCode]) +func wasmimport_TCPSocketHopLimit(self0 uint32, result *cm.OKResult[uint8, network.ErrorCode]) -// IsListening represents method "is-listening". +// IsListening represents the imported method "is-listening". // // Whether the socket is in the `listening` state. // @@ -252,15 +217,18 @@ func (self TCPSocket) wasmimport_HopLimit(result *cm.OKResult[uint8, ErrorCode]) // is-listening: func() -> bool // //go:nosplit -func (self TCPSocket) IsListening() bool { - return self.wasmimport_IsListening() +func (self TCPSocket) IsListening() (result bool) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_TCPSocketIsListening((uint32)(self0)) + result = cm.U32ToBool((uint32)(result0)) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.is-listening //go:noescape -func (self TCPSocket) wasmimport_IsListening() bool +func wasmimport_TCPSocketIsListening(self0 uint32) (result0 uint32) -// KeepAliveCount represents method "keep-alive-count". +// KeepAliveCount represents the imported method "keep-alive-count". // // The maximum amount of keepalive packets TCP should send before aborting the connection. // @@ -278,17 +246,17 @@ func (self TCPSocket) wasmimport_IsListening() bool // keep-alive-count: func() -> result // //go:nosplit -func (self TCPSocket) KeepAliveCount() cm.OKResult[uint32, ErrorCode] { - var result cm.OKResult[uint32, ErrorCode] - self.wasmimport_KeepAliveCount(&result) - return result +func (self TCPSocket) KeepAliveCount() (result cm.OKResult[uint32, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveCount((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-count //go:noescape -func (self TCPSocket) wasmimport_KeepAliveCount(result *cm.OKResult[uint32, ErrorCode]) +func wasmimport_TCPSocketKeepAliveCount(self0 uint32, result *cm.OKResult[uint32, network.ErrorCode]) -// KeepAliveEnabled represents method "keep-alive-enabled". +// KeepAliveEnabled represents the imported method "keep-alive-enabled". // // Enables or disables keepalive. // @@ -304,17 +272,17 @@ func (self TCPSocket) wasmimport_KeepAliveCount(result *cm.OKResult[uint32, Erro // keep-alive-enabled: func() -> result // //go:nosplit -func (self TCPSocket) KeepAliveEnabled() cm.OKResult[bool, ErrorCode] { - var result cm.OKResult[bool, ErrorCode] - self.wasmimport_KeepAliveEnabled(&result) - return result +func (self TCPSocket) KeepAliveEnabled() (result cm.OKResult[bool, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveEnabled((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-enabled //go:noescape -func (self TCPSocket) wasmimport_KeepAliveEnabled(result *cm.OKResult[bool, ErrorCode]) +func wasmimport_TCPSocketKeepAliveEnabled(self0 uint32, result *cm.OKResult[bool, network.ErrorCode]) -// KeepAliveIdleTime represents method "keep-alive-idle-time". +// KeepAliveIdleTime represents the imported method "keep-alive-idle-time". // // Amount of time the connection has to be idle before TCP starts sending keepalive // packets. @@ -333,17 +301,17 @@ func (self TCPSocket) wasmimport_KeepAliveEnabled(result *cm.OKResult[bool, Erro // keep-alive-idle-time: func() -> result // //go:nosplit -func (self TCPSocket) KeepAliveIdleTime() cm.OKResult[Duration, ErrorCode] { - var result cm.OKResult[Duration, ErrorCode] - self.wasmimport_KeepAliveIdleTime(&result) - return result +func (self TCPSocket) KeepAliveIdleTime() (result cm.OKResult[monotonicclock.Duration, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveIdleTime((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-idle-time //go:noescape -func (self TCPSocket) wasmimport_KeepAliveIdleTime(result *cm.OKResult[Duration, ErrorCode]) +func wasmimport_TCPSocketKeepAliveIdleTime(self0 uint32, result *cm.OKResult[monotonicclock.Duration, network.ErrorCode]) -// KeepAliveInterval represents method "keep-alive-interval". +// KeepAliveInterval represents the imported method "keep-alive-interval". // // The time between keepalive packets. // @@ -361,17 +329,17 @@ func (self TCPSocket) wasmimport_KeepAliveIdleTime(result *cm.OKResult[Duration, // keep-alive-interval: func() -> result // //go:nosplit -func (self TCPSocket) KeepAliveInterval() cm.OKResult[Duration, ErrorCode] { - var result cm.OKResult[Duration, ErrorCode] - self.wasmimport_KeepAliveInterval(&result) - return result +func (self TCPSocket) KeepAliveInterval() (result cm.OKResult[monotonicclock.Duration, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketKeepAliveInterval((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-interval //go:noescape -func (self TCPSocket) wasmimport_KeepAliveInterval(result *cm.OKResult[Duration, ErrorCode]) +func wasmimport_TCPSocketKeepAliveInterval(self0 uint32, result *cm.OKResult[monotonicclock.Duration, network.ErrorCode]) -// LocalAddress represents method "local-address". +// LocalAddress represents the imported method "local-address". // // Get the bound local address. // @@ -394,17 +362,17 @@ func (self TCPSocket) wasmimport_KeepAliveInterval(result *cm.OKResult[Duration, // local-address: func() -> result // //go:nosplit -func (self TCPSocket) LocalAddress() cm.OKResult[IPSocketAddress, ErrorCode] { - var result cm.OKResult[IPSocketAddress, ErrorCode] - self.wasmimport_LocalAddress(&result) - return result +func (self TCPSocket) LocalAddress() (result cm.OKResult[network.IPSocketAddress, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketLocalAddress((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.local-address //go:noescape -func (self TCPSocket) wasmimport_LocalAddress(result *cm.OKResult[IPSocketAddress, ErrorCode]) +func wasmimport_TCPSocketLocalAddress(self0 uint32, result *cm.OKResult[network.IPSocketAddress, network.ErrorCode]) -// ReceiveBufferSize represents method "receive-buffer-size". +// ReceiveBufferSize represents the imported method "receive-buffer-size". // // The kernel buffer space reserved for sends/receives on this socket. // @@ -422,17 +390,17 @@ func (self TCPSocket) wasmimport_LocalAddress(result *cm.OKResult[IPSocketAddres // receive-buffer-size: func() -> result // //go:nosplit -func (self TCPSocket) ReceiveBufferSize() cm.OKResult[uint64, ErrorCode] { - var result cm.OKResult[uint64, ErrorCode] - self.wasmimport_ReceiveBufferSize(&result) - return result +func (self TCPSocket) ReceiveBufferSize() (result cm.OKResult[uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketReceiveBufferSize((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.receive-buffer-size //go:noescape -func (self TCPSocket) wasmimport_ReceiveBufferSize(result *cm.OKResult[uint64, ErrorCode]) +func wasmimport_TCPSocketReceiveBufferSize(self0 uint32, result *cm.OKResult[uint64, network.ErrorCode]) -// RemoteAddress represents method "remote-address". +// RemoteAddress represents the imported method "remote-address". // // Get the remote address. // @@ -448,107 +416,112 @@ func (self TCPSocket) wasmimport_ReceiveBufferSize(result *cm.OKResult[uint64, E // remote-address: func() -> result // //go:nosplit -func (self TCPSocket) RemoteAddress() cm.OKResult[IPSocketAddress, ErrorCode] { - var result cm.OKResult[IPSocketAddress, ErrorCode] - self.wasmimport_RemoteAddress(&result) - return result +func (self TCPSocket) RemoteAddress() (result cm.OKResult[network.IPSocketAddress, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketRemoteAddress((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.remote-address //go:noescape -func (self TCPSocket) wasmimport_RemoteAddress(result *cm.OKResult[IPSocketAddress, ErrorCode]) +func wasmimport_TCPSocketRemoteAddress(self0 uint32, result *cm.OKResult[network.IPSocketAddress, network.ErrorCode]) -// SendBufferSize represents method "send-buffer-size". +// SendBufferSize represents the imported method "send-buffer-size". // // send-buffer-size: func() -> result // //go:nosplit -func (self TCPSocket) SendBufferSize() cm.OKResult[uint64, ErrorCode] { - var result cm.OKResult[uint64, ErrorCode] - self.wasmimport_SendBufferSize(&result) - return result +func (self TCPSocket) SendBufferSize() (result cm.OKResult[uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketSendBufferSize((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.send-buffer-size //go:noescape -func (self TCPSocket) wasmimport_SendBufferSize(result *cm.OKResult[uint64, ErrorCode]) +func wasmimport_TCPSocketSendBufferSize(self0 uint32, result *cm.OKResult[uint64, network.ErrorCode]) -// SetHopLimit represents method "set-hop-limit". +// SetHopLimit represents the imported method "set-hop-limit". // // set-hop-limit: func(value: u8) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetHopLimit(value uint8) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SetHopLimit(value, &result) - return result +func (self TCPSocket) SetHopLimit(value uint8) (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint32)(value) + wasmimport_TCPSocketSetHopLimit((uint32)(self0), (uint32)(value0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-hop-limit //go:noescape -func (self TCPSocket) wasmimport_SetHopLimit(value uint8, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_TCPSocketSetHopLimit(self0 uint32, value0 uint32, result *cm.ErrResult[struct{}, network.ErrorCode]) -// SetKeepAliveCount represents method "set-keep-alive-count". +// SetKeepAliveCount represents the imported method "set-keep-alive-count". // // set-keep-alive-count: func(value: u32) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetKeepAliveCount(value uint32) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SetKeepAliveCount(value, &result) - return result +func (self TCPSocket) SetKeepAliveCount(value uint32) (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint32)(value) + wasmimport_TCPSocketSetKeepAliveCount((uint32)(self0), (uint32)(value0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-count //go:noescape -func (self TCPSocket) wasmimport_SetKeepAliveCount(value uint32, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_TCPSocketSetKeepAliveCount(self0 uint32, value0 uint32, result *cm.ErrResult[struct{}, network.ErrorCode]) -// SetKeepAliveEnabled represents method "set-keep-alive-enabled". +// SetKeepAliveEnabled represents the imported method "set-keep-alive-enabled". // // set-keep-alive-enabled: func(value: bool) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetKeepAliveEnabled(value bool) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SetKeepAliveEnabled(value, &result) - return result +func (self TCPSocket) SetKeepAliveEnabled(value bool) (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := cm.BoolToU32(value) + wasmimport_TCPSocketSetKeepAliveEnabled((uint32)(self0), (uint32)(value0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-enabled //go:noescape -func (self TCPSocket) wasmimport_SetKeepAliveEnabled(value bool, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_TCPSocketSetKeepAliveEnabled(self0 uint32, value0 uint32, result *cm.ErrResult[struct{}, network.ErrorCode]) -// SetKeepAliveIdleTime represents method "set-keep-alive-idle-time". +// SetKeepAliveIdleTime represents the imported method "set-keep-alive-idle-time". // // set-keep-alive-idle-time: func(value: duration) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetKeepAliveIdleTime(value Duration) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SetKeepAliveIdleTime(value, &result) - return result +func (self TCPSocket) SetKeepAliveIdleTime(value monotonicclock.Duration) (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetKeepAliveIdleTime((uint32)(self0), (uint64)(value0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-idle-time //go:noescape -func (self TCPSocket) wasmimport_SetKeepAliveIdleTime(value Duration, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_TCPSocketSetKeepAliveIdleTime(self0 uint32, value0 uint64, result *cm.ErrResult[struct{}, network.ErrorCode]) -// SetKeepAliveInterval represents method "set-keep-alive-interval". +// SetKeepAliveInterval represents the imported method "set-keep-alive-interval". // // set-keep-alive-interval: func(value: duration) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetKeepAliveInterval(value Duration) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SetKeepAliveInterval(value, &result) - return result +func (self TCPSocket) SetKeepAliveInterval(value monotonicclock.Duration) (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetKeepAliveInterval((uint32)(self0), (uint64)(value0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-keep-alive-interval //go:noescape -func (self TCPSocket) wasmimport_SetKeepAliveInterval(value Duration, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_TCPSocketSetKeepAliveInterval(self0 uint32, value0 uint64, result *cm.ErrResult[struct{}, network.ErrorCode]) -// SetListenBacklogSize represents method "set-listen-backlog-size". +// SetListenBacklogSize represents the imported method "set-listen-backlog-size". // // Hints the desired listen queue size. Implementations are free to ignore this. // @@ -566,47 +539,50 @@ func (self TCPSocket) wasmimport_SetKeepAliveInterval(value Duration, result *cm // set-listen-backlog-size: func(value: u64) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetListenBacklogSize(value uint64) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SetListenBacklogSize(value, &result) - return result +func (self TCPSocket) SetListenBacklogSize(value uint64) (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetListenBacklogSize((uint32)(self0), (uint64)(value0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-listen-backlog-size //go:noescape -func (self TCPSocket) wasmimport_SetListenBacklogSize(value uint64, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_TCPSocketSetListenBacklogSize(self0 uint32, value0 uint64, result *cm.ErrResult[struct{}, network.ErrorCode]) -// SetReceiveBufferSize represents method "set-receive-buffer-size". +// SetReceiveBufferSize represents the imported method "set-receive-buffer-size". // // set-receive-buffer-size: func(value: u64) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetReceiveBufferSize(value uint64) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SetReceiveBufferSize(value, &result) - return result +func (self TCPSocket) SetReceiveBufferSize(value uint64) (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetReceiveBufferSize((uint32)(self0), (uint64)(value0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-receive-buffer-size //go:noescape -func (self TCPSocket) wasmimport_SetReceiveBufferSize(value uint64, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_TCPSocketSetReceiveBufferSize(self0 uint32, value0 uint64, result *cm.ErrResult[struct{}, network.ErrorCode]) -// SetSendBufferSize represents method "set-send-buffer-size". +// SetSendBufferSize represents the imported method "set-send-buffer-size". // // set-send-buffer-size: func(value: u64) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) SetSendBufferSize(value uint64) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SetSendBufferSize(value, &result) - return result +func (self TCPSocket) SetSendBufferSize(value uint64) (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_TCPSocketSetSendBufferSize((uint32)(self0), (uint64)(value0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.set-send-buffer-size //go:noescape -func (self TCPSocket) wasmimport_SetSendBufferSize(value uint64, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_TCPSocketSetSendBufferSize(self0 uint32, value0 uint64, result *cm.ErrResult[struct{}, network.ErrorCode]) -// Shutdown represents method "shutdown". +// Shutdown represents the imported method "shutdown". // // Initiate a graceful shutdown. // @@ -635,17 +611,18 @@ func (self TCPSocket) wasmimport_SetSendBufferSize(value uint64, result *cm.ErrR // shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code> // //go:nosplit -func (self TCPSocket) Shutdown(shutdownType ShutdownType) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_Shutdown(shutdownType, &result) - return result +func (self TCPSocket) Shutdown(shutdownType ShutdownType) (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + shutdownType0 := (uint32)(shutdownType) + wasmimport_TCPSocketShutdown((uint32)(self0), (uint32)(shutdownType0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.shutdown //go:noescape -func (self TCPSocket) wasmimport_Shutdown(shutdownType ShutdownType, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_TCPSocketShutdown(self0 uint32, shutdownType0 uint32, result *cm.ErrResult[struct{}, network.ErrorCode]) -// StartBind represents method "start-bind". +// StartBind represents the imported method "start-bind". // // Bind the socket to a specific network on the provided IP address and port. // @@ -699,17 +676,19 @@ func (self TCPSocket) wasmimport_Shutdown(shutdownType ShutdownType, result *cm. // result<_, error-code> // //go:nosplit -func (self TCPSocket) StartBind(network_ Network, localAddress IPSocketAddress) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_StartBind(network_, localAddress, &result) - return result +func (self TCPSocket) StartBind(network_ network.Network, localAddress network.IPSocketAddress) (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + network0 := cm.Reinterpret[uint32](network_) + localAddress0, localAddress1, localAddress2, localAddress3, localAddress4, localAddress5, localAddress6, localAddress7, localAddress8, localAddress9, localAddress10, localAddress11 := lower_IPSocketAddress(localAddress) + wasmimport_TCPSocketStartBind((uint32)(self0), (uint32)(network0), (uint32)(localAddress0), (uint32)(localAddress1), (uint32)(localAddress2), (uint32)(localAddress3), (uint32)(localAddress4), (uint32)(localAddress5), (uint32)(localAddress6), (uint32)(localAddress7), (uint32)(localAddress8), (uint32)(localAddress9), (uint32)(localAddress10), (uint32)(localAddress11), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-bind //go:noescape -func (self TCPSocket) wasmimport_StartBind(network_ Network, localAddress IPSocketAddress, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_TCPSocketStartBind(self0 uint32, network0 uint32, localAddress0 uint32, localAddress1 uint32, localAddress2 uint32, localAddress3 uint32, localAddress4 uint32, localAddress5 uint32, localAddress6 uint32, localAddress7 uint32, localAddress8 uint32, localAddress9 uint32, localAddress10 uint32, localAddress11 uint32, result *cm.ErrResult[struct{}, network.ErrorCode]) -// StartConnect represents method "start-connect". +// StartConnect represents the imported method "start-connect". // // Connect to a remote endpoint. // @@ -769,17 +748,19 @@ func (self TCPSocket) wasmimport_StartBind(network_ Network, localAddress IPSock // -> result<_, error-code> // //go:nosplit -func (self TCPSocket) StartConnect(network_ Network, remoteAddress IPSocketAddress) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_StartConnect(network_, remoteAddress, &result) - return result +func (self TCPSocket) StartConnect(network_ network.Network, remoteAddress network.IPSocketAddress) (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + network0 := cm.Reinterpret[uint32](network_) + remoteAddress0, remoteAddress1, remoteAddress2, remoteAddress3, remoteAddress4, remoteAddress5, remoteAddress6, remoteAddress7, remoteAddress8, remoteAddress9, remoteAddress10, remoteAddress11 := lower_IPSocketAddress(remoteAddress) + wasmimport_TCPSocketStartConnect((uint32)(self0), (uint32)(network0), (uint32)(remoteAddress0), (uint32)(remoteAddress1), (uint32)(remoteAddress2), (uint32)(remoteAddress3), (uint32)(remoteAddress4), (uint32)(remoteAddress5), (uint32)(remoteAddress6), (uint32)(remoteAddress7), (uint32)(remoteAddress8), (uint32)(remoteAddress9), (uint32)(remoteAddress10), (uint32)(remoteAddress11), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-connect //go:noescape -func (self TCPSocket) wasmimport_StartConnect(network_ Network, remoteAddress IPSocketAddress, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_TCPSocketStartConnect(self0 uint32, network0 uint32, remoteAddress0 uint32, remoteAddress1 uint32, remoteAddress2 uint32, remoteAddress3 uint32, remoteAddress4 uint32, remoteAddress5 uint32, remoteAddress6 uint32, remoteAddress7 uint32, remoteAddress8 uint32, remoteAddress9 uint32, remoteAddress10 uint32, remoteAddress11 uint32, result *cm.ErrResult[struct{}, network.ErrorCode]) -// StartListen represents method "start-listen". +// StartListen represents the imported method "start-listen". // // Start listening for new connections. // @@ -813,17 +794,17 @@ func (self TCPSocket) wasmimport_StartConnect(network_ Network, remoteAddress IP // start-listen: func() -> result<_, error-code> // //go:nosplit -func (self TCPSocket) StartListen() cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_StartListen(&result) - return result +func (self TCPSocket) StartListen() (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_TCPSocketStartListen((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.start-listen //go:noescape -func (self TCPSocket) wasmimport_StartListen(result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_TCPSocketStartListen(self0 uint32, result *cm.ErrResult[struct{}, network.ErrorCode]) -// Subscribe represents method "subscribe". +// Subscribe represents the imported method "subscribe". // // Create a `pollable` which can be used to poll for, or block on, // completion of any of the asynchronous operations of this socket. @@ -846,10 +827,13 @@ func (self TCPSocket) wasmimport_StartListen(result *cm.ErrResult[struct{}, Erro // subscribe: func() -> pollable // //go:nosplit -func (self TCPSocket) Subscribe() Pollable { - return self.wasmimport_Subscribe() +func (self TCPSocket) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_TCPSocketSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return } //go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.subscribe //go:noescape -func (self TCPSocket) wasmimport_Subscribe() Pollable +func wasmimport_TCPSocketSubscribe(self0 uint32) (result0 uint32) 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 285c85f2a5..a73695a9c4 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package udpcreatesocket represents the interface "wasi:sockets/udp-create-socket@0.2.0". +// Package udpcreatesocket represents the imported interface "wasi:sockets/udp-create-socket@0.2.0". package udpcreatesocket import ( @@ -11,27 +11,7 @@ import ( "internal/wasi/sockets/v0.2.0/udp" ) -// ErrorCode represents the enum "wasi:sockets/network@0.2.0#error-code". -// -// See [network.ErrorCode] for more information. -type ErrorCode = network.ErrorCode - -// IPAddressFamily represents the enum "wasi:sockets/network@0.2.0#ip-address-family". -// -// See [network.IPAddressFamily] for more information. -type IPAddressFamily = network.IPAddressFamily - -// Network represents the resource "wasi:sockets/network@0.2.0#network". -// -// See [network.Network] for more information. -type Network = network.Network - -// UDPSocket represents the resource "wasi:sockets/udp@0.2.0#udp-socket". -// -// See [udp.UDPSocket] for more information. -type UDPSocket = udp.UDPSocket - -// CreateUDPSocket represents function "wasi:sockets/udp-create-socket@0.2.0#create-udp-socket". +// CreateUDPSocket represents the imported function "create-udp-socket". // // Create a new UDP socket. // @@ -63,12 +43,12 @@ type UDPSocket = udp.UDPSocket // error-code> // //go:nosplit -func CreateUDPSocket(addressFamily IPAddressFamily) cm.OKResult[UDPSocket, ErrorCode] { - var result cm.OKResult[UDPSocket, ErrorCode] - wasmimport_CreateUDPSocket(addressFamily, &result) - return result +func CreateUDPSocket(addressFamily network.IPAddressFamily) (result cm.OKResult[udp.UDPSocket, network.ErrorCode]) { + addressFamily0 := (uint32)(addressFamily) + wasmimport_CreateUDPSocket((uint32)(addressFamily0), &result) + return } //go:wasmimport wasi:sockets/udp-create-socket@0.2.0 create-udp-socket //go:noescape -func wasmimport_CreateUDPSocket(addressFamily IPAddressFamily, result *cm.OKResult[UDPSocket, ErrorCode]) +func wasmimport_CreateUDPSocket(addressFamily0 uint32, result *cm.OKResult[udp.UDPSocket, network.ErrorCode]) diff --git a/src/internal/wasi/sockets/v0.2.0/udp/abi.go b/src/internal/wasi/sockets/v0.2.0/udp/abi.go new file mode 100644 index 0000000000..c62d3322dd --- /dev/null +++ b/src/internal/wasi/sockets/v0.2.0/udp/abi.go @@ -0,0 +1,92 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +//go:build !wasip1 + +package udp + +import ( + "github.com/ydnar/wasm-tools-go/cm" + "internal/wasi/sockets/v0.2.0/network" +) + +func lower_IPv4Address(v network.IPv4Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32) { + f0 = (uint32)(v[0]) + f1 = (uint32)(v[1]) + f2 = (uint32)(v[2]) + f3 = (uint32)(v[3]) + return +} + +func lower_IPv4SocketAddress(v network.IPv4SocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32) { + f0 = (uint32)(v.Port) + f1, f2, f3, f4 = lower_IPv4Address(v.Address) + return +} + +func lower_IPv6Address(v network.IPv6Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32) { + f0 = (uint32)(v[0]) + f1 = (uint32)(v[1]) + f2 = (uint32)(v[2]) + f3 = (uint32)(v[3]) + f4 = (uint32)(v[4]) + f5 = (uint32)(v[5]) + f6 = (uint32)(v[6]) + f7 = (uint32)(v[7]) + return +} + +func lower_IPv6SocketAddress(v network.IPv6SocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32) { + f0 = (uint32)(v.Port) + f1 = (uint32)(v.FlowInfo) + f2, f3, f4, f5, f6, f7, f8, f9 = lower_IPv6Address(v.Address) + f10 = (uint32)(v.ScopeID) + return +} + +func lower_IPSocketAddress(v network.IPSocketAddress) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32, f11 uint32) { + f0 = (uint32)(cm.Tag(&v)) + switch f0 { + case 0: // ipv4 + v1, v2, v3, v4, v5 := lower_IPv4SocketAddress(*v.IPv4()) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + case 1: // ipv6 + v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 := lower_IPv6SocketAddress(*v.IPv6()) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + f6 = (uint32)(v6) + f7 = (uint32)(v7) + f8 = (uint32)(v8) + f9 = (uint32)(v9) + f10 = (uint32)(v10) + f11 = (uint32)(v11) + } + return +} + +func lower_OptionIPSocketAddress(v cm.Option[network.IPSocketAddress]) (f0 uint32, f1 uint32, f2 uint32, f3 uint32, f4 uint32, f5 uint32, f6 uint32, f7 uint32, f8 uint32, f9 uint32, f10 uint32, f11 uint32, f12 uint32) { + some := v.Some() + if some != nil { + f0 = 1 + v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12 := lower_IPSocketAddress(*some) + f1 = (uint32)(v1) + f2 = (uint32)(v2) + f3 = (uint32)(v3) + f4 = (uint32)(v4) + f5 = (uint32)(v5) + f6 = (uint32)(v6) + f7 = (uint32)(v7) + f8 = (uint32)(v8) + f9 = (uint32)(v9) + f10 = (uint32)(v10) + f11 = (uint32)(v11) + f12 = (uint32)(v12) + } + return +} 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 ceaf1dd593..41b3b9ac0c 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 @@ -2,7 +2,7 @@ //go:build !wasip1 -// Package udp represents the interface "wasi:sockets/udp@0.2.0". +// Package udp represents the imported interface "wasi:sockets/udp@0.2.0". package udp import ( @@ -11,11 +11,6 @@ import ( "internal/wasi/sockets/v0.2.0/network" ) -// ErrorCode represents the enum "wasi:sockets/network@0.2.0#error-code". -// -// See [network.ErrorCode] for more information. -type ErrorCode = network.ErrorCode - // IncomingDatagram represents the record "wasi:sockets/udp@0.2.0#incoming-datagram". // // A received datagram. @@ -36,101 +31,9 @@ type IncomingDatagram struct { // with, if any. // // Equivalent to the `src_addr` out parameter of `recvfrom`. - RemoteAddress IPSocketAddress -} - -// IncomingDatagramStream represents the resource "wasi:sockets/udp@0.2.0#incoming-datagram-stream". -// -// resource incoming-datagram-stream -type IncomingDatagramStream cm.Resource - -// ResourceDrop represents the Canonical ABI function "resource-drop". -// -// Drops a resource handle. -// -//go:nosplit -func (self IncomingDatagramStream) ResourceDrop() { - self.wasmimport_ResourceDrop() -} - -//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]incoming-datagram-stream -//go:noescape -func (self IncomingDatagramStream) wasmimport_ResourceDrop() - -// Receive represents method "receive". -// -// Receive messages on the socket. -// -// This function attempts to receive up to `max-results` datagrams on the socket without -// blocking. -// The returned list may contain fewer elements than requested, but never more. -// -// This function returns successfully with an empty list when either: -// - `max-results` is 0, or: -// - `max-results` is greater than 0, but no results are immediately available. -// This function never returns `error(would-block)`. -// -// # Typical errors -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET -// on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// -// # References -// - -// - -// - -// - -// - -// - -// - -// - -// -// receive: func(max-results: u64) -> result, error-code> -// -//go:nosplit -func (self IncomingDatagramStream) Receive(maxResults uint64) cm.OKResult[cm.List[IncomingDatagram], ErrorCode] { - var result cm.OKResult[cm.List[IncomingDatagram], ErrorCode] - self.wasmimport_Receive(maxResults, &result) - return result -} - -//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.receive -//go:noescape -func (self IncomingDatagramStream) wasmimport_Receive(maxResults uint64, result *cm.OKResult[cm.List[IncomingDatagram], ErrorCode]) - -// Subscribe represents method "subscribe". -// -// Create a `pollable` which will resolve once the stream is ready to receive again. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// -// subscribe: func() -> pollable -// -//go:nosplit -func (self IncomingDatagramStream) Subscribe() Pollable { - return self.wasmimport_Subscribe() + RemoteAddress network.IPSocketAddress } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.subscribe -//go:noescape -func (self IncomingDatagramStream) wasmimport_Subscribe() Pollable - -// IPAddressFamily represents the enum "wasi:sockets/network@0.2.0#ip-address-family". -// -// See [network.IPAddressFamily] for more information. -type IPAddressFamily = network.IPAddressFamily - -// IPSocketAddress represents the variant "wasi:sockets/network@0.2.0#ip-socket-address". -// -// See [network.IPSocketAddress] for more information. -type IPSocketAddress = network.IPSocketAddress - -// Network represents the resource "wasi:sockets/network@0.2.0#network". -// -// See [network.Network] for more information. -type Network = network.Network - // OutgoingDatagram represents the record "wasi:sockets/udp@0.2.0#outgoing-datagram". // // A datagram to be sent out. @@ -152,162 +55,32 @@ type OutgoingDatagram struct { // // If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise // it is equivalent to `sendto`. - RemoteAddress cm.Option[IPSocketAddress] -} - -// OutgoingDatagramStream represents the resource "wasi:sockets/udp@0.2.0#outgoing-datagram-stream". -// -// resource outgoing-datagram-stream -type OutgoingDatagramStream cm.Resource - -// ResourceDrop represents the Canonical ABI function "resource-drop". -// -// Drops a resource handle. -// -//go:nosplit -func (self OutgoingDatagramStream) ResourceDrop() { - self.wasmimport_ResourceDrop() -} - -//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]outgoing-datagram-stream -//go:noescape -func (self OutgoingDatagramStream) wasmimport_ResourceDrop() - -// CheckSend represents method "check-send". -// -// Check readiness for sending. This function never blocks. -// -// Returns the number of datagrams permitted for the next call to `send`, -// or an error. Calling `send` with more datagrams than this function has -// permitted will trap. -// -// When this function returns ok(0), the `subscribe` pollable will -// become ready when this function will report at least ok(1), or an -// error. -// -// Never returns `would-block`. -// -// check-send: func() -> result -// -//go:nosplit -func (self OutgoingDatagramStream) CheckSend() cm.OKResult[uint64, ErrorCode] { - var result cm.OKResult[uint64, ErrorCode] - self.wasmimport_CheckSend(&result) - return result -} - -//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.check-send -//go:noescape -func (self OutgoingDatagramStream) wasmimport_CheckSend(result *cm.OKResult[uint64, ErrorCode]) - -// Send represents method "send". -// -// Send messages on the socket. -// -// This function attempts to send all provided `datagrams` on the socket without blocking -// and -// returns how many messages were actually sent (or queued for sending). This function -// never -// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` -// is returned. -// -// This function semantically behaves the same as iterating the `datagrams` list and -// sequentially -// sending each individual datagram until either the end of the list has been reached -// or the first error occurred. -// If at least one datagram has been sent successfully, this function never returns -// an error. -// -// If the input list is empty, the function returns `ok(0)`. -// -// Each call to `send` must be permitted by a preceding `check-send`. Implementations -// must trap if -// either `check-send` was not called or `datagrams` contains more items than `check-send` -// permitted. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. -// (EAFNOSUPPORT) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY -// (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, -// EADDRNOTAVAIL) -// - `invalid-argument`: The socket is in "connected" mode and `remote-address` -// is `some` value that does not match the address passed to `stream`. (EISCONN) -// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` -// was provided. (EDESTADDRREQ) -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, -// ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) -// -// # References -// - -// - -// - -// - -// - -// - -// - -// - -// -// send: func(datagrams: list) -> result -// -//go:nosplit -func (self OutgoingDatagramStream) Send(datagrams cm.List[OutgoingDatagram]) cm.OKResult[uint64, ErrorCode] { - var result cm.OKResult[uint64, ErrorCode] - self.wasmimport_Send(datagrams, &result) - return result -} - -//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.send -//go:noescape -func (self OutgoingDatagramStream) wasmimport_Send(datagrams cm.List[OutgoingDatagram], result *cm.OKResult[uint64, ErrorCode]) - -// Subscribe represents method "subscribe". -// -// Create a `pollable` which will resolve once the stream is ready to send again. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -// -// subscribe: func() -> pollable -// -//go:nosplit -func (self OutgoingDatagramStream) Subscribe() Pollable { - return self.wasmimport_Subscribe() + RemoteAddress cm.Option[network.IPSocketAddress] } -//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.subscribe -//go:noescape -func (self OutgoingDatagramStream) wasmimport_Subscribe() Pollable - -// Pollable represents the resource "wasi:io/poll@0.2.0#pollable". -// -// See [poll.Pollable] for more information. -type Pollable = poll.Pollable - -// UDPSocket represents the resource "wasi:sockets/udp@0.2.0#udp-socket". +// UDPSocket represents the imported resource "wasi:sockets/udp@0.2.0#udp-socket". // // A UDP socket handle. // // resource udp-socket type UDPSocket cm.Resource -// ResourceDrop represents the Canonical ABI function "resource-drop". +// ResourceDrop represents the imported resource-drop for resource "udp-socket". // // Drops a resource handle. // //go:nosplit func (self UDPSocket) ResourceDrop() { - self.wasmimport_ResourceDrop() + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketResourceDrop((uint32)(self0)) + return } //go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]udp-socket //go:noescape -func (self UDPSocket) wasmimport_ResourceDrop() +func wasmimport_UDPSocketResourceDrop(self0 uint32) -// AddressFamily represents method "address-family". +// AddressFamily represents the imported method "address-family". // // Whether this is a IPv4 or IPv6 socket. // @@ -316,30 +89,33 @@ func (self UDPSocket) wasmimport_ResourceDrop() // address-family: func() -> ip-address-family // //go:nosplit -func (self UDPSocket) AddressFamily() IPAddressFamily { - return self.wasmimport_AddressFamily() +func (self UDPSocket) AddressFamily() (result network.IPAddressFamily) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_UDPSocketAddressFamily((uint32)(self0)) + result = (network.IPAddressFamily)((uint32)(result0)) + return } //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.address-family //go:noescape -func (self UDPSocket) wasmimport_AddressFamily() IPAddressFamily +func wasmimport_UDPSocketAddressFamily(self0 uint32) (result0 uint32) -// FinishBind represents method "finish-bind". +// FinishBind represents the imported method "finish-bind". // // finish-bind: func() -> result<_, error-code> // //go:nosplit -func (self UDPSocket) FinishBind() cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_FinishBind(&result) - return result +func (self UDPSocket) FinishBind() (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketFinishBind((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.finish-bind //go:noescape -func (self UDPSocket) wasmimport_FinishBind(result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_UDPSocketFinishBind(self0 uint32, result *cm.ErrResult[struct{}, network.ErrorCode]) -// LocalAddress represents method "local-address". +// LocalAddress represents the imported method "local-address". // // Get the current bound address. // @@ -362,17 +138,17 @@ func (self UDPSocket) wasmimport_FinishBind(result *cm.ErrResult[struct{}, Error // local-address: func() -> result // //go:nosplit -func (self UDPSocket) LocalAddress() cm.OKResult[IPSocketAddress, ErrorCode] { - var result cm.OKResult[IPSocketAddress, ErrorCode] - self.wasmimport_LocalAddress(&result) - return result +func (self UDPSocket) LocalAddress() (result cm.OKResult[network.IPSocketAddress, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketLocalAddress((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.local-address //go:noescape -func (self UDPSocket) wasmimport_LocalAddress(result *cm.OKResult[IPSocketAddress, ErrorCode]) +func wasmimport_UDPSocketLocalAddress(self0 uint32, result *cm.OKResult[network.IPSocketAddress, network.ErrorCode]) -// ReceiveBufferSize represents method "receive-buffer-size". +// ReceiveBufferSize represents the imported method "receive-buffer-size". // // The kernel buffer space reserved for sends/receives on this socket. // @@ -390,17 +166,17 @@ func (self UDPSocket) wasmimport_LocalAddress(result *cm.OKResult[IPSocketAddres // receive-buffer-size: func() -> result // //go:nosplit -func (self UDPSocket) ReceiveBufferSize() cm.OKResult[uint64, ErrorCode] { - var result cm.OKResult[uint64, ErrorCode] - self.wasmimport_ReceiveBufferSize(&result) - return result +func (self UDPSocket) ReceiveBufferSize() (result cm.OKResult[uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketReceiveBufferSize((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.receive-buffer-size //go:noescape -func (self UDPSocket) wasmimport_ReceiveBufferSize(result *cm.OKResult[uint64, ErrorCode]) +func wasmimport_UDPSocketReceiveBufferSize(self0 uint32, result *cm.OKResult[uint64, network.ErrorCode]) -// RemoteAddress represents method "remote-address". +// RemoteAddress represents the imported method "remote-address". // // Get the address the socket is currently streaming to. // @@ -416,77 +192,80 @@ func (self UDPSocket) wasmimport_ReceiveBufferSize(result *cm.OKResult[uint64, E // remote-address: func() -> result // //go:nosplit -func (self UDPSocket) RemoteAddress() cm.OKResult[IPSocketAddress, ErrorCode] { - var result cm.OKResult[IPSocketAddress, ErrorCode] - self.wasmimport_RemoteAddress(&result) - return result +func (self UDPSocket) RemoteAddress() (result cm.OKResult[network.IPSocketAddress, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketRemoteAddress((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.remote-address //go:noescape -func (self UDPSocket) wasmimport_RemoteAddress(result *cm.OKResult[IPSocketAddress, ErrorCode]) +func wasmimport_UDPSocketRemoteAddress(self0 uint32, result *cm.OKResult[network.IPSocketAddress, network.ErrorCode]) -// SendBufferSize represents method "send-buffer-size". +// SendBufferSize represents the imported method "send-buffer-size". // // send-buffer-size: func() -> result // //go:nosplit -func (self UDPSocket) SendBufferSize() cm.OKResult[uint64, ErrorCode] { - var result cm.OKResult[uint64, ErrorCode] - self.wasmimport_SendBufferSize(&result) - return result +func (self UDPSocket) SendBufferSize() (result cm.OKResult[uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketSendBufferSize((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.send-buffer-size //go:noescape -func (self UDPSocket) wasmimport_SendBufferSize(result *cm.OKResult[uint64, ErrorCode]) +func wasmimport_UDPSocketSendBufferSize(self0 uint32, result *cm.OKResult[uint64, network.ErrorCode]) -// SetReceiveBufferSize represents method "set-receive-buffer-size". +// SetReceiveBufferSize represents the imported method "set-receive-buffer-size". // // set-receive-buffer-size: func(value: u64) -> result<_, error-code> // //go:nosplit -func (self UDPSocket) SetReceiveBufferSize(value uint64) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SetReceiveBufferSize(value, &result) - return result +func (self UDPSocket) SetReceiveBufferSize(value uint64) (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_UDPSocketSetReceiveBufferSize((uint32)(self0), (uint64)(value0), &result) + return } //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-receive-buffer-size //go:noescape -func (self UDPSocket) wasmimport_SetReceiveBufferSize(value uint64, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_UDPSocketSetReceiveBufferSize(self0 uint32, value0 uint64, result *cm.ErrResult[struct{}, network.ErrorCode]) -// SetSendBufferSize represents method "set-send-buffer-size". +// SetSendBufferSize represents the imported method "set-send-buffer-size". // // set-send-buffer-size: func(value: u64) -> result<_, error-code> // //go:nosplit -func (self UDPSocket) SetSendBufferSize(value uint64) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SetSendBufferSize(value, &result) - return result +func (self UDPSocket) SetSendBufferSize(value uint64) (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint64)(value) + wasmimport_UDPSocketSetSendBufferSize((uint32)(self0), (uint64)(value0), &result) + return } //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-send-buffer-size //go:noescape -func (self UDPSocket) wasmimport_SetSendBufferSize(value uint64, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_UDPSocketSetSendBufferSize(self0 uint32, value0 uint64, result *cm.ErrResult[struct{}, network.ErrorCode]) -// SetUnicastHopLimit represents method "set-unicast-hop-limit". +// SetUnicastHopLimit represents the imported method "set-unicast-hop-limit". // // set-unicast-hop-limit: func(value: u8) -> result<_, error-code> // //go:nosplit -func (self UDPSocket) SetUnicastHopLimit(value uint8) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_SetUnicastHopLimit(value, &result) - return result +func (self UDPSocket) SetUnicastHopLimit(value uint8) (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + value0 := (uint32)(value) + wasmimport_UDPSocketSetUnicastHopLimit((uint32)(self0), (uint32)(value0), &result) + return } //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.set-unicast-hop-limit //go:noescape -func (self UDPSocket) wasmimport_SetUnicastHopLimit(value uint8, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_UDPSocketSetUnicastHopLimit(self0 uint32, value0 uint32, result *cm.ErrResult[struct{}, network.ErrorCode]) -// StartBind represents method "start-bind". +// StartBind represents the imported method "start-bind". // // Bind the socket to a specific network on the provided IP address and port. // @@ -524,17 +303,19 @@ func (self UDPSocket) wasmimport_SetUnicastHopLimit(value uint8, result *cm.ErrR // result<_, error-code> // //go:nosplit -func (self UDPSocket) StartBind(network_ Network, localAddress IPSocketAddress) cm.ErrResult[struct{}, ErrorCode] { - var result cm.ErrResult[struct{}, ErrorCode] - self.wasmimport_StartBind(network_, localAddress, &result) - return result +func (self UDPSocket) StartBind(network_ network.Network, localAddress network.IPSocketAddress) (result cm.ErrResult[struct{}, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + network0 := cm.Reinterpret[uint32](network_) + localAddress0, localAddress1, localAddress2, localAddress3, localAddress4, localAddress5, localAddress6, localAddress7, localAddress8, localAddress9, localAddress10, localAddress11 := lower_IPSocketAddress(localAddress) + wasmimport_UDPSocketStartBind((uint32)(self0), (uint32)(network0), (uint32)(localAddress0), (uint32)(localAddress1), (uint32)(localAddress2), (uint32)(localAddress3), (uint32)(localAddress4), (uint32)(localAddress5), (uint32)(localAddress6), (uint32)(localAddress7), (uint32)(localAddress8), (uint32)(localAddress9), (uint32)(localAddress10), (uint32)(localAddress11), &result) + return } //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.start-bind //go:noescape -func (self UDPSocket) wasmimport_StartBind(network_ Network, localAddress IPSocketAddress, result *cm.ErrResult[struct{}, ErrorCode]) +func wasmimport_UDPSocketStartBind(self0 uint32, network0 uint32, localAddress0 uint32, localAddress1 uint32, localAddress2 uint32, localAddress3 uint32, localAddress4 uint32, localAddress5 uint32, localAddress6 uint32, localAddress7 uint32, localAddress8 uint32, localAddress9 uint32, localAddress10 uint32, localAddress11 uint32, result *cm.ErrResult[struct{}, network.ErrorCode]) -// Stream represents method "stream". +// Stream represents the imported method "stream". // // Set up inbound & outbound communication channels, optionally to a specific peer. // @@ -587,21 +368,22 @@ func (self UDPSocket) wasmimport_StartBind(network_ Network, localAddress IPSock // - // - // -// stream: func(remote-address: option) -> result) -> result, error-code> // //go:nosplit -func (self UDPSocket) Stream(remoteAddress cm.Option[IPSocketAddress]) cm.OKResult[cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], ErrorCode] { - var result cm.OKResult[cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], ErrorCode] - self.wasmimport_Stream(remoteAddress, &result) - return result +func (self UDPSocket) Stream(remoteAddress cm.Option[network.IPSocketAddress]) (result cm.OKResult[cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + remoteAddress0, remoteAddress1, remoteAddress2, remoteAddress3, remoteAddress4, remoteAddress5, remoteAddress6, remoteAddress7, remoteAddress8, remoteAddress9, remoteAddress10, remoteAddress11, remoteAddress12 := lower_OptionIPSocketAddress(remoteAddress) + wasmimport_UDPSocketStream((uint32)(self0), (uint32)(remoteAddress0), (uint32)(remoteAddress1), (uint32)(remoteAddress2), (uint32)(remoteAddress3), (uint32)(remoteAddress4), (uint32)(remoteAddress5), (uint32)(remoteAddress6), (uint32)(remoteAddress7), (uint32)(remoteAddress8), (uint32)(remoteAddress9), (uint32)(remoteAddress10), (uint32)(remoteAddress11), (uint32)(remoteAddress12), &result) + return } //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.stream //go:noescape -func (self UDPSocket) wasmimport_Stream(remoteAddress cm.Option[IPSocketAddress], result *cm.OKResult[cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], ErrorCode]) +func wasmimport_UDPSocketStream(self0 uint32, remoteAddress0 uint32, remoteAddress1 uint32, remoteAddress2 uint32, remoteAddress3 uint32, remoteAddress4 uint32, remoteAddress5 uint32, remoteAddress6 uint32, remoteAddress7 uint32, remoteAddress8 uint32, remoteAddress9 uint32, remoteAddress10 uint32, remoteAddress11 uint32, remoteAddress12 uint32, result *cm.OKResult[cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], network.ErrorCode]) -// Subscribe represents method "subscribe". +// Subscribe represents the imported method "subscribe". // // Create a `pollable` which will resolve once the socket is ready for I/O. // @@ -611,15 +393,18 @@ func (self UDPSocket) wasmimport_Stream(remoteAddress cm.Option[IPSocketAddress] // subscribe: func() -> pollable // //go:nosplit -func (self UDPSocket) Subscribe() Pollable { - return self.wasmimport_Subscribe() +func (self UDPSocket) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_UDPSocketSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return } //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.subscribe //go:noescape -func (self UDPSocket) wasmimport_Subscribe() Pollable +func wasmimport_UDPSocketSubscribe(self0 uint32) (result0 uint32) -// UnicastHopLimit represents method "unicast-hop-limit". +// UnicastHopLimit represents the imported method "unicast-hop-limit". // // Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. // @@ -631,12 +416,228 @@ func (self UDPSocket) wasmimport_Subscribe() Pollable // unicast-hop-limit: func() -> result // //go:nosplit -func (self UDPSocket) UnicastHopLimit() cm.OKResult[uint8, ErrorCode] { - var result cm.OKResult[uint8, ErrorCode] - self.wasmimport_UnicastHopLimit(&result) - return result +func (self UDPSocket) UnicastHopLimit() (result cm.OKResult[uint8, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_UDPSocketUnicastHopLimit((uint32)(self0), &result) + return } //go:wasmimport wasi:sockets/udp@0.2.0 [method]udp-socket.unicast-hop-limit //go:noescape -func (self UDPSocket) wasmimport_UnicastHopLimit(result *cm.OKResult[uint8, ErrorCode]) +func wasmimport_UDPSocketUnicastHopLimit(self0 uint32, result *cm.OKResult[uint8, network.ErrorCode]) + +// IncomingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.0#incoming-datagram-stream". +// +// resource incoming-datagram-stream +type IncomingDatagramStream cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "incoming-datagram-stream". +// +// Drops a resource handle. +// +//go:nosplit +func (self IncomingDatagramStream) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_IncomingDatagramStreamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]incoming-datagram-stream +//go:noescape +func wasmimport_IncomingDatagramStreamResourceDrop(self0 uint32) + +// Receive represents the imported method "receive". +// +// Receive messages on the socket. +// +// This function attempts to receive up to `max-results` datagrams on the socket without +// blocking. +// The returned list may contain fewer elements than requested, but never more. +// +// This function returns successfully with an empty list when either: +// - `max-results` is 0, or: +// - `max-results` is greater than 0, but no results are immediately available. +// This function never returns `error(would-block)`. +// +// # Typical errors +// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET +// on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `connection-refused`: The connection was refused. (ECONNREFUSED) +// +// # References +// - +// - +// - +// - +// - +// - +// - +// - +// +// receive: func(max-results: u64) -> result, error-code> +// +//go:nosplit +func (self IncomingDatagramStream) Receive(maxResults uint64) (result cm.OKResult[cm.List[IncomingDatagram], network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + maxResults0 := (uint64)(maxResults) + wasmimport_IncomingDatagramStreamReceive((uint32)(self0), (uint64)(maxResults0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.receive +//go:noescape +func wasmimport_IncomingDatagramStreamReceive(self0 uint32, maxResults0 uint64, result *cm.OKResult[cm.List[IncomingDatagram], network.ErrorCode]) + +// Subscribe represents the imported method "subscribe". +// +// Create a `pollable` which will resolve once the stream is ready to receive again. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. +// +// subscribe: func() -> pollable +// +//go:nosplit +func (self IncomingDatagramStream) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_IncomingDatagramStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]incoming-datagram-stream.subscribe +//go:noescape +func wasmimport_IncomingDatagramStreamSubscribe(self0 uint32) (result0 uint32) + +// OutgoingDatagramStream represents the imported resource "wasi:sockets/udp@0.2.0#outgoing-datagram-stream". +// +// resource outgoing-datagram-stream +type OutgoingDatagramStream cm.Resource + +// ResourceDrop represents the imported resource-drop for resource "outgoing-datagram-stream". +// +// Drops a resource handle. +// +//go:nosplit +func (self OutgoingDatagramStream) ResourceDrop() { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingDatagramStreamResourceDrop((uint32)(self0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [resource-drop]outgoing-datagram-stream +//go:noescape +func wasmimport_OutgoingDatagramStreamResourceDrop(self0 uint32) + +// CheckSend represents the imported method "check-send". +// +// Check readiness for sending. This function never blocks. +// +// Returns the number of datagrams permitted for the next call to `send`, +// or an error. Calling `send` with more datagrams than this function has +// permitted will trap. +// +// When this function returns ok(0), the `subscribe` pollable will +// become ready when this function will report at least ok(1), or an +// error. +// +// Never returns `would-block`. +// +// check-send: func() -> result +// +//go:nosplit +func (self OutgoingDatagramStream) CheckSend() (result cm.OKResult[uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + wasmimport_OutgoingDatagramStreamCheckSend((uint32)(self0), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.check-send +//go:noescape +func wasmimport_OutgoingDatagramStreamCheckSend(self0 uint32, result *cm.OKResult[uint64, network.ErrorCode]) + +// Send represents the imported method "send". +// +// Send messages on the socket. +// +// This function attempts to send all provided `datagrams` on the socket without blocking +// and +// returns how many messages were actually sent (or queued for sending). This function +// never +// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` +// is returned. +// +// This function semantically behaves the same as iterating the `datagrams` list and +// sequentially +// sending each individual datagram until either the end of the list has been reached +// or the first error occurred. +// If at least one datagram has been sent successfully, this function never returns +// an error. +// +// If the input list is empty, the function returns `ok(0)`. +// +// Each call to `send` must be permitted by a preceding `check-send`. Implementations +// must trap if +// either `check-send` was not called or `datagrams` contains more items than `check-send` +// permitted. +// +// # Typical errors +// - `invalid-argument`: The `remote-address` has the wrong address family. +// (EAFNOSUPPORT) +// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY +// (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, +// EADDRNOTAVAIL) +// - `invalid-argument`: The socket is in "connected" mode and `remote-address` +// is `some` value that does not match the address passed to `stream`. (EISCONN) +// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` +// was provided. (EDESTADDRREQ) +// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, +// ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `connection-refused`: The connection was refused. (ECONNREFUSED) +// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) +// +// # References +// - +// - +// - +// - +// - +// - +// - +// - +// +// send: func(datagrams: list) -> result +// +//go:nosplit +func (self OutgoingDatagramStream) Send(datagrams cm.List[OutgoingDatagram]) (result cm.OKResult[uint64, network.ErrorCode]) { + self0 := cm.Reinterpret[uint32](self) + datagrams0, datagrams1 := cm.LowerList(datagrams) + wasmimport_OutgoingDatagramStreamSend((uint32)(self0), (*OutgoingDatagram)(datagrams0), (uint32)(datagrams1), &result) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.send +//go:noescape +func wasmimport_OutgoingDatagramStreamSend(self0 uint32, datagrams0 *OutgoingDatagram, datagrams1 uint32, result *cm.OKResult[uint64, network.ErrorCode]) + +// Subscribe represents the imported method "subscribe". +// +// Create a `pollable` which will resolve once the stream is ready to send again. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. +// +// subscribe: func() -> pollable +// +//go:nosplit +func (self OutgoingDatagramStream) Subscribe() (result poll.Pollable) { + self0 := cm.Reinterpret[uint32](self) + result0 := wasmimport_OutgoingDatagramStreamSubscribe((uint32)(self0)) + result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) + return +} + +//go:wasmimport wasi:sockets/udp@0.2.0 [method]outgoing-datagram-stream.subscribe +//go:noescape +func wasmimport_OutgoingDatagramStreamSubscribe(self0 uint32) (result0 uint32) From 6921ce6520f8dc6247ccccfa9d094820df33174b Mon Sep 17 00:00:00 2001 From: Randy Reddig Date: Sun, 23 Jun 2024 12:07:28 -0700 Subject: [PATCH 3/3] compiler: update isValidWasmType to reflect the current Go proposal This reflects the relaxed type restrictions proposed here (except for structs.HostLayout): https://github.com/golang/go/issues/66984 --- compiler/symbol.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/compiler/symbol.go b/compiler/symbol.go index 540c32e685..c48082fa5f 100644 --- a/compiler/symbol.go +++ b/compiler/symbol.go @@ -360,7 +360,7 @@ func (c *compilerContext) checkWasmImport(f *ssa.Function, pragma string) { c.addError(f.Signature.Results().At(1).Pos(), fmt.Sprintf("%s: too many return values", pragma)) } else if f.Signature.Results().Len() == 1 { result := f.Signature.Results().At(0) - if !isValidWasmType(result.Type(), true) { + if !isValidWasmType(result.Type(), false) { c.addError(result.Pos(), fmt.Sprintf("%s: unsupported result type %s", pragma, result.Type().String())) } } @@ -373,30 +373,42 @@ func (c *compilerContext) checkWasmImport(f *ssa.Function, pragma string) { } } -// Check whether the type maps directly to a WebAssembly type, according to: -// https://github.com/golang/go/issues/59149 +// Check whether the type maps directly to a WebAssembly type. // -// Update: this reflects the relaxed type restrictions proposed here: +// This reflects the relaxed type restrictions proposed here (except for structs.HostLayout): // https://github.com/golang/go/issues/66984 -func isValidWasmType(typ types.Type, isReturn bool) bool { +// +// This previously reflected the additional restrictions documented here: +// https://github.com/golang/go/issues/59149 +func isValidWasmType(typ types.Type, isPointerOrField bool) bool { switch typ := typ.Underlying().(type) { case *types.Basic: switch typ.Kind() { case types.Bool: return true - case types.Int8, types.Uint8, types.Int16, types.Uint16, types.Int32, types.Uint32, types.Int64, types.Uint64: + case types.Int, types.Uint, types.Int8, types.Uint8, types.Int16, types.Uint16, types.Int32, types.Uint32, types.Int64, types.Uint64: return true case types.Float32, types.Float64: return true case types.Uintptr, types.UnsafePointer: return true case types.String: - return true + return isPointerOrField } + case *types.Array: + return isPointerOrField && isValidWasmType(typ.Elem(), true) case *types.Struct: + if !isPointerOrField { + return false + } + for i := 0; i < typ.NumFields(); i++ { + if !isValidWasmType(typ.Field(i).Type(), true) { + return false + } + } return true case *types.Pointer: - return isValidWasmType(typ.Elem(), isReturn) + return isValidWasmType(typ.Elem(), true) } return false }