llgo/ssa,runtime: Slice

This commit is contained in:
xushiwei
2024-04-30 08:23:55 +08:00
parent 91401c4571
commit 0bfc269652
12 changed files with 109 additions and 16 deletions

View File

@@ -23,8 +23,8 @@ const (
LLGoPackage = "decl"
)
//go:linkname String llgo.cstr
func String(string) *int8
//go:linkname Str llgo.cstr
func Str(string) *int8
//go:linkname Alloca llgo.alloca
func Alloca(size uintptr) unsafe.Pointer

View File

@@ -24,9 +24,9 @@ import (
// Slice is the runtime representation of a slice.
type Slice struct {
array unsafe.Pointer
len int
cap int
data unsafe.Pointer
len int
cap int
}
// NilSlice returns a nil slice.
@@ -34,4 +34,14 @@ func NilSlice() Slice {
return Slice{nil, 0, 0}
}
// NewSlice creates a new slice.
func NewSlice(data unsafe.Pointer, len, cap int) Slice {
return Slice{data, len, cap}
}
// SliceLen returns the length of a slice.
func SliceLen(s Slice) int {
return s.len
}
// -----------------------------------------------------------------------------