mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-07 04:23:41 +00:00
87a8aafc4f
- add internal/wasm-tools/go.mod file to depend on wasm-tools-go
- copy package cm into src/internal/cm
- remove wasm-tools-go "vendor" submodule
internal/tools: fix typo
go.{mod,sum}, internal/tools: add wit-bindgen-go to tools
GNUmakefile: use go run for wit-bindgen-go
GNUmakefile: add tools target to go:generate tools binaries in internal/tools
GNUmakefile: add .PHONY for lint and spell
GNUmakefile, internal/cm: vendor package cm into internal/cm
go.{mod,sum}: update wasm-tools-go to v0.1.4
internal/wasi: use internal/cm package
remove submodule src/vendor/github.com/ydnar/wasm-tools-go
GNUmakefile: add comment documenting what wasi-cm target does
go.{mod,sum}: remove toolchain; go mod tidy
go.mod: revert to Go 1.19
go.mod: go 1.19
go.{mod,sum}, internal/{tools,wasm-tools}: revert root go.mod file to go1.19
Create a wasm-tools specific module that can require go1.22 for wasm-tools-go.
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package cm
|
|
|
|
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] }
|
|
|
|
// NewList returns a List[T] from data and len.
|
|
func NewList[T any](data *T, len uint) List[T] {
|
|
return List[T]{
|
|
list[T]{
|
|
data: data,
|
|
len: len,
|
|
},
|
|
}
|
|
}
|
|
|
|
// ToList returns a List[T] equivalent to the Go slice s.
|
|
// The underlying slice data is not copied, and the resulting List points at the
|
|
// same array storage as the slice.
|
|
func ToList[S ~[]T, T any](s S) List[T] {
|
|
return NewList[T](unsafe.SliceData([]T(s)), uint(len(s)))
|
|
}
|
|
|
|
// list represents the internal representation of a Component Model list.
|
|
// It is intended to be embedded in a [List], so embedding types maintain
|
|
// the methods defined on this type.
|
|
type list[T any] struct {
|
|
data *T
|
|
len uint
|
|
}
|
|
|
|
// Slice returns a Go slice representing the List.
|
|
func (l list[T]) Slice() []T {
|
|
return unsafe.Slice(l.data, l.len)
|
|
}
|
|
|
|
// Data returns the data pointer for the list.
|
|
func (l list[T]) Data() *T {
|
|
return l.data
|
|
}
|
|
|
|
// Len returns the length of the list.
|
|
// TODO: should this return an int instead of a uint?
|
|
func (l list[T]) Len() uint {
|
|
return l.len
|
|
}
|