mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-09-11 23:19:30 +00:00
reflect: implement MakeChan
TinyGo had MakeMap/MakeSlice but not MakeChan. Implement it via the runtime chanMake primitive (mirroring MakeMap), so packages that call reflect.MakeChan (e.g. github.com/ugorji/go/codec used by gin) compile and work.
This commit is contained in:
committed by
Damian Gryski
parent
af429a597b
commit
1579b235e8
@@ -2208,6 +2208,9 @@ func hashmapMake(keySize, valueSize uintptr, sizeHint uintptr, alg uint8) unsafe
|
||||
//go:linkname hashmapMakeReflect runtime.hashmapMakeReflect
|
||||
func hashmapMakeReflect(keySize, valueSize, sizeHint uintptr, keyType unsafe.Pointer) unsafe.Pointer
|
||||
|
||||
//go:linkname chanMake runtime.chanMake
|
||||
func chanMake(elementSize uintptr, bufSize uintptr) unsafe.Pointer
|
||||
|
||||
// MakeMapWithSize creates a new map with the specified type and initial space
|
||||
// for approximately n elements.
|
||||
func MakeMapWithSize(typ Type, n int) Value {
|
||||
@@ -2254,6 +2257,26 @@ func MakeMap(typ Type) Value {
|
||||
return MakeMapWithSize(typ, 8)
|
||||
}
|
||||
|
||||
// MakeChan creates a new channel with the specified type and buffer size.
|
||||
func MakeChan(typ Type, size int) Value {
|
||||
if typ.Kind() != Chan {
|
||||
panic(&ValueError{Method: "MakeChan", Kind: typ.Kind()})
|
||||
}
|
||||
if size < 0 {
|
||||
panic("reflect.MakeChan: negative buffer size")
|
||||
}
|
||||
if typ.(*RawType).ChanDir() != BothDir {
|
||||
panic("reflect.MakeChan: unidirectional channel type")
|
||||
}
|
||||
elem := typ.Elem().(*RawType)
|
||||
ch := chanMake(elem.Size(), uintptr(size))
|
||||
return Value{
|
||||
typecode: typ.(*RawType),
|
||||
value: ch,
|
||||
flags: valueFlagExported,
|
||||
}
|
||||
}
|
||||
|
||||
func (v Value) Call(in []Value) []Value {
|
||||
panic("unimplemented: (reflect.Value).Call()")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user