mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
reflect: add converting complex
This commit is contained in:
committed by
Damian Gryski
parent
a93640662e
commit
d29e8e5f22
@@ -1485,13 +1485,11 @@ func convertOp(src Value, typ Type) (Value, bool) {
|
||||
return cvtFloat(src, rtype), true
|
||||
}
|
||||
|
||||
/*
|
||||
case Complex64, Complex128:
|
||||
switch src.Kind() {
|
||||
case Complex64, Complex128:
|
||||
return cvtComplex
|
||||
}
|
||||
*/
|
||||
case Complex64, Complex128:
|
||||
switch src.Kind() {
|
||||
case Complex64, Complex128:
|
||||
return cvtComplex(src, typ.(*RawType)), true
|
||||
}
|
||||
|
||||
case Slice:
|
||||
switch rtype := typ.(*RawType); rtype.Kind() {
|
||||
@@ -1578,6 +1576,10 @@ func cvtFloat(v Value, t *RawType) Value {
|
||||
return makeFloat(v.flags, v.Float(), t)
|
||||
}
|
||||
|
||||
func cvtComplex(v Value, t *RawType) Value {
|
||||
return makeComplex(v.flags, v.Complex(), t)
|
||||
}
|
||||
|
||||
//go:linkname stringToBytes runtime.stringToBytes
|
||||
func stringToBytes(x string) []byte
|
||||
|
||||
@@ -1661,6 +1663,29 @@ func makeFloat32(flags valueFlags, f float32, t *RawType) Value {
|
||||
return v
|
||||
}
|
||||
|
||||
func makeComplex(flags valueFlags, f complex128, t *RawType) Value {
|
||||
size := t.Size()
|
||||
|
||||
v := Value{
|
||||
typecode: t,
|
||||
flags: flags,
|
||||
}
|
||||
|
||||
ptr := unsafe.Pointer(&v.value)
|
||||
if size > unsafe.Sizeof(uintptr(0)) {
|
||||
ptr = alloc(size, nil)
|
||||
v.value = ptr
|
||||
}
|
||||
|
||||
switch size {
|
||||
case 8:
|
||||
*(*complex64)(ptr) = complex64(f)
|
||||
case 16:
|
||||
*(*complex128)(ptr) = f
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func cvtIntString(src Value, t *RawType) Value {
|
||||
panic("cvtUintString: unimplemented")
|
||||
}
|
||||
|
||||
+1
-1
@@ -402,7 +402,7 @@ func (t *rawType) CanSeq2() bool {
|
||||
}
|
||||
|
||||
func (t *rawType) ConvertibleTo(u Type) bool {
|
||||
return t.RawType.Convertibleto(u.(*rawType).RawType)
|
||||
return t.RawType.ConvertibleTo(&(u.(*rawType).RawType))
|
||||
}
|
||||
|
||||
func (t *rawType) Elem() Type {
|
||||
|
||||
Reference in New Issue
Block a user