Ejemplo n.º 1
0
// Float64bits returns the IEEE 754 binary representation of f.
//func Float64bits(f float64) uint64 { return *(*uint64)(unsafe.Pointer(&f)) }
func Float64bits(f float64) uint64 {

	if hx.GetBool("", "Object.nativeFloats") {
		var t float64 = f
		return *(*uint64)(unsafe.Pointer(&t))
	}

	switch runtime.GOARCH {
	case "cs":
		return uint64(hx.Int64(hx.CallDynamic("", "Force.Float64bits", 1, f)))
		// TODO js/cpp/neko short-cut - using Force.f64byts
		//case "js", "cpp", "neko":
		//	return uint64(hx.Int64(hx.CallDynamic("", "Force.Float64bits", 1, f)))
	}

	// below from math.IsInf
	if f > MaxFloat64 {
		return uvinf
	}
	if f < -MaxFloat64 {
		return uvneginf
	}
	if f != f { // NaN
		if f < 0 { // -NaN ?
			return uvnan | uint64(1)<<63
		}
		//return 9221120237041090561
		return uvnan
	}
	if f == 0 {
		if 1/f < -MaxFloat64 { // dividing by -0 gives -Inf
			return uint64(1) << 63
		}
		return 0
	}

	s := uint64(0)
	if f < hx.GetFloat("", "0") {
		s = 1 << 63
		f = -f
	}

	e := uint32(1023 + 52)
	for f >= float64(int64(1<<53)) {
		f /= hx.GetFloat("", "2")
		e++
		if e == uint32((1<<11)-1) {
			break
		}
	}
	for f < float64(int64(1<<52)) {
		e--
		if e == 0 {
			break
		}
		f *= hx.GetFloat("", "2")
	}

	return s | uint64(e)<<52 | (uint64(f) &^ (1 << 52))
}
Ejemplo n.º 2
0
// Float64bits returns the IEEE 754 binary representation of f.
//func Float64bits(f float64) uint64 { return *(*uint64)(unsafe.Pointer(&f)) }
func Float64bits(f float64) uint64 {
	return uint64(hx.Int64(hx.CodeDynamic("",
		"Go_haxegoruntime_FFloat64bits.callFromRT(this._goroutine,_a.itemAddr(0).load().val);", f)))
}
Ejemplo n.º 3
0
func haxe2go(ret *emptyInterface, i interface{}) {
	if ret == nil {
		i = interface{}(nil)
		return
	}
	/*
		if ret.typ == nil { // HELP! assume dynamic?
			panic("DEBUG reflect.haxe2go() nil Go type")
			//println("DEBUG reflect.haxe2go() nil Go type, using uintptr")
			//uip := hx.CodeIface("", "uintptr", "null;")
			//ret.typ = createHaxeType(hx.CodeInt("", "_a.param(0).typ;", uip))
		}
	*/
	ret.word = hx.Malloc(ret.typ.size)

	switch ret.typ.Kind() & kindMask {
	case Bool:
		*(*bool)(ret.word) = hx.CodeBool("", "_a.param(0).val;", i)
	case Int:
		*(*int)(ret.word) = hx.CodeInt("", "_a.param(0).val;", i)
	case Int8:
		*(*int8)(ret.word) = int8(hx.CodeInt("", "_a.param(0).val;", i))
	case Int16:
		*(*int16)(ret.word) = int16(hx.CodeInt("", "_a.param(0).val;", i))
	case Int32:
		*(*int32)(ret.word) = int32(hx.CodeInt("", "_a.param(0).val;", i))
	case Int64:
		*(*int64)(ret.word) = hx.Int64(hx.CodeDynamic("", "_a.param(0).val;", i))
	case Uint:
		*(*uint)(ret.word) = uint(hx.CodeInt("", "_a.param(0).val;", i))
	case Uint8:
		*(*uint8)(ret.word) = uint8(hx.CodeInt("", "_a.param(0).val;", i))
	case Uint16:
		*(*uint16)(ret.word) = uint16(hx.CodeInt("", "_a.param(0).val;", i))
	case Uint32:
		*(*uint32)(ret.word) = uint32(hx.CodeInt("", "_a.param(0).val;", i))
	case Uint64:
		*(*uint64)(ret.word) = uint64(hx.Int64(hx.CodeDynamic("", "_a.param(0).val;", i)))
	case Uintptr:
		*(*uintptr)(ret.word) = uintptr(hx.CodeDynamic("", "_a.param(0).val;", i))
	case Float32:
		*(*float32)(ret.word) = float32(hx.CodeFloat("", "_a.param(0).val;", i))
	case Float64:
		*(*float64)(ret.word) = float64(hx.CodeFloat("", "_a.param(0).val;", i))
	case Complex64:
		*(*complex64)(ret.word) = complex64(hx.Complex(hx.CodeDynamic("", "_a.param(0).val;", i)))
	case Complex128:
		*(*complex128)(ret.word) = hx.Complex(hx.CodeDynamic("", "_a.param(0).val;", i))
	case UnsafePointer, Ptr:
		//*(*unsafe.Pointer)(ret.word) = unsafe.Pointer(hx.CodeDynamic("", "_a.param(0).val;", i))
		ret.word = unsafe.Pointer(hx.CodeDynamic("", "_a.param(0).val;", i))

	case String:
		*(*string)(ret.word) = hx.CodeString("", "_a.param(0).val;", i)

	case Array, Struct:
		hx.Code("",
			"_a.param(1).val.store_object(_a.param(2).val,_a.param(0).val);",
			i, ret.word, ret.typ.size)

	case Slice, Interface, Map, Func, Chan:
		val := hx.CodeDynamic("", "_a.param(0).val;", i)
		*(*uintptr)(ret.word) = val

		/*
			htyp := "null"
			if !hx.IsNull(val) {
				htyp = hx.CallString("", "Type.getClassName", 1, val)
			}
			println("DEBUG unpack haxe type=", htyp, " Go type=", ret.typ.Kind().String(), "val=", val, "encoded=", ret)
		*/
	}

}