mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-17 11:13:27 +00:00
internal/{cm,wasi}: regenerate WASI 0.2 bindings with wasm-tools-go v0.3.0
This commit is contained in:
+20
-8
@@ -4,14 +4,25 @@ import "unsafe"
|
||||
|
||||
// List represents a Component Model list.
|
||||
// The binary representation of list<T> is similar to a Go slice minus the cap field.
|
||||
type List[T any] struct{ list[T] }
|
||||
type List[T any] struct {
|
||||
_ HostLayout
|
||||
list[T]
|
||||
}
|
||||
|
||||
// AnyList is a type constraint for generic functions that accept any [List] type.
|
||||
type AnyList[T any] interface {
|
||||
~struct {
|
||||
_ HostLayout
|
||||
list[T]
|
||||
}
|
||||
}
|
||||
|
||||
// NewList returns a List[T] from data and len.
|
||||
func NewList[T any](data *T, len uint) List[T] {
|
||||
func NewList[T any, Len AnyInteger](data *T, len Len) List[T] {
|
||||
return List[T]{
|
||||
list[T]{
|
||||
list: list[T]{
|
||||
data: data,
|
||||
len: len,
|
||||
len: uintptr(len),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -20,15 +31,16 @@ func NewList[T any](data *T, len uint) List[T] {
|
||||
// The underlying slice data is not copied, and the resulting List points at the
|
||||
// same array storage as the slice.
|
||||
func ToList[S ~[]T, T any](s S) List[T] {
|
||||
return NewList[T](unsafe.SliceData([]T(s)), uint(len(s)))
|
||||
return NewList[T](unsafe.SliceData([]T(s)), uintptr(len(s)))
|
||||
}
|
||||
|
||||
// list represents the internal representation of a Component Model list.
|
||||
// It is intended to be embedded in a [List], so embedding types maintain
|
||||
// the methods defined on this type.
|
||||
type list[T any] struct {
|
||||
_ HostLayout
|
||||
data *T
|
||||
len uint
|
||||
len uintptr
|
||||
}
|
||||
|
||||
// Slice returns a Go slice representing the List.
|
||||
@@ -42,7 +54,7 @@ func (l list[T]) Data() *T {
|
||||
}
|
||||
|
||||
// Len returns the length of the list.
|
||||
// TODO: should this return an int instead of a uint?
|
||||
func (l list[T]) Len() uint {
|
||||
// TODO: should this return an int instead of a uintptr?
|
||||
func (l list[T]) Len() uintptr {
|
||||
return l.len
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user