コード例 #1
0
ファイル: environ.c.go プロジェクト: timob/gojvm
func (self *Environment) setDoubleField(z interface{}, static bool, name string, val float64) (err error) {
	jval, field, err := self.getField(z, static, name, types.Basic(types.IntKind))
	if err != nil {
		return
	}
	if static {
		C.envSetStaticDoubleField(self.env, C.valObject(jval), field.field, C.jdouble(val))
	} else {
		C.envSetDoubleField(self.env, C.valObject(jval), field.field, C.jdouble(val))
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	return
}
コード例 #2
0
ファイル: environ.c.go プロジェクト: timob/gojvm
func (self *Environment) setObjField(z interface{}, static bool, name string, rval types.Typed, val *Object) (err error) {
	jval, field, err := self.getField(z, static, name, rval)
	if err != nil {
		return
	}
	if static {
		C.envSetStaticObjectField(self.env, C.valObject(jval), field.field, val.object)
	} else {
		C.envSetObjectField(self.env, C.valObject(jval), field.field, val.object)
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	return
}
コード例 #3
0
ファイル: environ.c.go プロジェクト: timob/gojvm
func (self *Environment) callVoid(z interface{}, static bool, name string, params ...interface{}) (err error) {
	jval, meth, args, localStack, err := self.getMethod(z, static, name, types.Basic(types.VoidKind), params...)
	if err != nil {
		return
	}
	defer blowStack(self, localStack)
	if static {
		C.envCallStaticVoidMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	} else {
		C.envCallVoidMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	return
}
コード例 #4
0
ファイル: environ.c.go プロジェクト: timob/gojvm
func (self *Environment) callFloat(z interface{}, static bool, name string, params ...interface{}) (v float32, err error) {
	jval, meth, args, localStack, err := self.getMethod(z, static, name, types.Basic(types.FloatKind), params...)
	if err != nil {
		return
	}
	defer blowStack(self, localStack)
	var ji C.jfloat
	if static {
		ji = C.envCallStaticFloatMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	} else {
		ji = C.envCallFloatMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	v = float32(ji)
	return
}
コード例 #5
0
ファイル: environ.c.go プロジェクト: timob/gojvm
func (self *Environment) getShortField(z interface{}, static bool, name string) (v int16, err error) {
	jval, field, err := self.getField(z, static, name, types.Basic(types.ShortKind))
	if err != nil {
		return
	}
	var oval C.jshort
	if static {
		oval = C.envGetStaticShortField(self.env, C.valObject(jval), field.field)
	} else {
		oval = C.envGetShortField(self.env, C.valObject(jval), field.field)
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	if err == nil {
		v = int16(oval)
	}
	return
}
コード例 #6
0
ファイル: environ.c.go プロジェクト: timob/gojvm
func (self *Environment) getObjField(z interface{}, static bool, name string, rval types.Typed) (v *Object, err error) {
	jval, field, err := self.getField(z, static, name, rval)
	if err != nil {
		return
	}
	var oval C.jobject
	if static {
		oval = C.envGetStaticObjectField(self.env, C.valObject(jval), field.field)
	} else {
		oval = C.envGetObjectField(self.env, C.valObject(jval), field.field)
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	if err == nil {
		v = &Object{oval}
	}
	return
}
コード例 #7
0
ファイル: environ.c.go プロジェクト: timob/gojvm
func (self *Environment) setBoolField(z interface{}, static bool, name string, gval bool) (err error) {
	jval, field, err := self.getField(z, static, name, types.Basic(types.BoolKind))
	if err != nil {
		return
	}
	val := C.jboolean(C.JNI_FALSE)
	if gval {
		val = C.JNI_TRUE
	}
	if static {
		C.envSetStaticBooleanField(self.env, C.valObject(jval), field.field, val)
	} else {
		C.envSetBooleanField(self.env, C.valObject(jval), field.field, val)
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	return
}
コード例 #8
0
ファイル: environ.c.go プロジェクト: timob/gojvm
func (self *Environment) getDobuleField(z interface{}, static bool, name string) (v float64, err error) {
	jval, field, err := self.getField(z, static, name, types.Basic(types.IntKind))
	if err != nil {
		return
	}
	var oval C.jdouble
	if static {
		oval = C.envGetStaticDoubleField(self.env, C.valObject(jval), field.field)
	} else {
		oval = C.envGetDoubleField(self.env, C.valObject(jval), field.field)
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	if err == nil {
		v = float64(oval)
	}
	return
}
コード例 #9
0
ファイル: environ.c.go プロジェクト: timob/gojvm
func (self *Environment) callIntArray(z interface{}, static bool, name string, params ...interface{}) (v []int, err error) {
	jval, meth, args, localStack, err := self.getMethod(z, static, name, types.Array{types.Basic(types.IntKind)}, params...)
	if err != nil {
		return
	}
	defer blowStack(self, localStack)
	var oval C.jobject
	if static {
		oval = C.envCallStaticObjectMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	} else {
		oval = C.envCallObjectMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	}
	if oval == nil {
		err = self.ExceptionOccurred()
	}
	if err == nil {
		v = self.ToIntArray(newObject(oval))
	}
	return
}
コード例 #10
0
ファイル: environ.c.go プロジェクト: timob/gojvm
func (self *Environment) callShort(z interface{}, static bool, name string, params ...interface{}) (v int16, err error) {
	jval, meth, args, localStack, err := self.getMethod(z, static, name, types.Basic(types.ShortKind), params...)
	if err != nil {
		return
	}
	defer blowStack(self, localStack)
	var oval C.jshort
	if static {
		oval = C.envCallStaticShortMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	} else {
		oval = C.envCallShortMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	if err == nil {
		v = int16(oval)
	}
	return
}
コード例 #11
0
ファイル: environ.c.go プロジェクト: timob/gojvm
func (self *Environment) callObj(z interface{}, static bool, name string, rval types.Typed, params ...interface{}) (vObj *Object, err error) {
	jval, meth, args, localStack, err := self.getMethod(z, static, name, rval, params...)
	if err != nil {
		return
	}
	defer blowStack(self, localStack)
	var oval C.jobject
	if static {
		oval = C.envCallStaticObjectMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	} else {
		oval = C.envCallObjectMethodA(self.env, C.valObject(jval), meth.method, args.Ptr())
	}
	if self.ExceptionCheck() {
		err = self.ExceptionOccurred()
	}
	if err == nil {
		vObj = newObject(oval)
	}
	return
}
コード例 #12
0
ファイル: environ.c.go プロジェクト: timob/gojvm
func (self *Environment) getIntArrayField(z interface{}, static bool, name string) (v []int, err error) {
	jval, field, err := self.getField(z, static, name, types.Array{types.Basic(types.IntKind)})
	if err != nil {
		return
	}
	var oval C.jobject
	if static {
		oval = C.envGetStaticObjectField(self.env, C.valObject(jval), field.field)
	} else {
		oval = C.envGetObjectField(self.env, C.valObject(jval), field.field)
	}
	if oval == nil {
		err = self.ExceptionOccurred()
	}
	if err == nil {
		v = self.ToIntArray(newObject(oval))
	}

	return
}
コード例 #13
0
ファイル: globals.c.go プロジェクト: timob/gojvm
// C callbacks actually start in the 'generifiedX' calls (see the .c files)
// Next, goCallbackNArgs is used to determine the number of variadic paramers to expect (
// java doesn't inform us of this, and we can't force any of the callback parameters.
//
// Finally, goCallback looks up the 'fId' - our internal function reference ID (the X in generified),
// un(re) marshalls all the parameters appropriately, calls our function, and returns
// any underlying value back to generified who will return it to the JVM.
// The initial jbool indicates success, and any failure should check for exceptions.
//
//export goCallback
func goCallback(envp, obj uintptr, fId int, nargs int, argp uintptr) (ok C.jboolean, val interface{}) {
	args := C.ArgListPtr(unsafe.Pointer(argp))
	env := AllEnvs.Find(envp)
	if env == nil {
		panic("Got a nil environment")
	}
	if env.jvm == nil {
		panic("Environment pointer has no JVM")
	}
	var cd callbackDescriptor
	var _ok bool
	if cd, _ok = env.jvm.registered[fId]; !_ok {
		print("Unknown callbackId: \t", fId, "\n")
		return
	}
	// TODO: pack argp somehow...
	if nargs != len(cd.Signature.Params) {
		panic("callback/signature length mismatch")
	}
	inCall := []reflect.Value{reflect.ValueOf(env), reflect.ValueOf(newObject(C.jobject(unsafe.Pointer(obj))))}
	var err error
	for i := 0; i < nargs; i++ {
		switch cd.Signature.Params[i].Kind() {
		case types.BoolKind:
			inCall = append(inCall, reflect.ValueOf(bool(0 != C.valBool(C.getArg(args, C.int(i))))))
		case types.LongKind:
			inCall = append(inCall, reflect.ValueOf(int64(C.valLong(C.getArg(args, C.int(i))))))
		case types.IntKind:
			inCall = append(inCall, reflect.ValueOf(int(C.valInt(C.getArg(args, C.int(i))))))
		case types.ShortKind:
			inCall = append(inCall, reflect.ValueOf(int16(C.valShort(C.getArg(args, C.int(i))))))
		case types.FloatKind:
			inCall = append(inCall, reflect.ValueOf(float32(C.valFloat(C.getArg(args, C.int(i))))))
		case types.DoubleKind:
			inCall = append(inCall, reflect.ValueOf(float64(C.valDouble(C.getArg(args, C.int(i))))))
		case types.ClassKind:
			inCall = append(inCall, reflect.ValueOf(newObject(C.valObject(C.getArg(args, C.int(i))))))
		default:
			err = errors.New("Couldn't reflect kind " + cd.Signature.Params[i].Kind().TypeString())
		}
		if err != nil {
			break
		}
	}
	if err != nil {
		return
	}
	outCall := reflect.ValueOf(cd.F).Call(inCall)
	switch cd.Signature.Return.Kind() {
	case types.VoidKind:
		return 1, nil
	}
	switch cd.Signature.Return.Kind() {
	case types.BoolKind:
		if outCall[0].Interface().(bool) {
			return 1, C.jboolean(C.JNI_TRUE)
		} else {
			return 1, C.jboolean(C.JNI_FALSE)
		}
	case types.ByteKind:
		return 1, C.jbyte(outCall[0].Interface().(byte))
	case types.CharKind:
		return 1, C.jchar(outCall[0].Interface().(int))
	case types.IntKind:
		return 1, C.jint(outCall[0].Interface().(int))
	case types.ShortKind:
		return 1, C.jshort(outCall[0].Interface().(int16))
	case types.LongKind:
		return 1, C.jint(outCall[0].Interface().(int64))
	case types.FloatKind:
		return 1, C.jfloat(outCall[0].Interface().(float32))
	case types.DoubleKind:
		return 1, C.jdouble(outCall[0].Interface().(float64))
	case types.ClassKind:
		klass := cd.Signature.Return.(types.Class).Klass
		if klass.Cmp(types.JavaLangString) == 0 {
			var obj *Object
			str := outCall[0].Interface().(string)
			obj, err = env.NewStringObject(str)
			if err == nil {
				return 1, C.jstring(obj.object)
			} // else, exception occurred
			// not needed as callbacks will reap their own refs.
			// env.DeleteLocalRef(obj)
			print("String Error\t", err.Error())
			return 0, nil
		}
		return 1, C.jobject(outCall[0].Interface().(*Object).object)
	default:
		panic("array return type not yet supported")
	}

	panic("not reached")
}