Search in sources :

Example 6 with MemoryOperation

use of php.runtime.memory.support.MemoryOperation in project jphp by jphp-compiler.

the class UXImage method toNative.

@Signature
public Memory toNative(Environment env) throws Throwable {
    MemoryOperation operation = MemoryOperation.get(BufferedImage.class, null);
    if (operation != null) {
        BufferedImage image = SwingFXUtils.fromFXImage(this.getWrappedObject(), null);
        image = convertToCompatible(image);
        return operation.unconvert(env, env.trace(), image);
    } else {
        return Memory.NULL;
    }
}
Also used : MemoryOperation(php.runtime.memory.support.MemoryOperation) BufferedImage(java.awt.image.BufferedImage) Signature(php.runtime.annotation.Reflection.Signature)

Example 7 with MemoryOperation

use of php.runtime.memory.support.MemoryOperation in project jphp by jphp-compiler.

the class CompileMethodEntity method invokeDynamic.

public Memory invokeDynamic(Object _this, Environment env, TraceInfo trace, Memory... arguments) throws Throwable {
    try {
        if (isAbstract) {
            env.error(ErrorType.E_ERROR, "Cannot call abstract method %s", getSignatureString(false));
            return Memory.NULL;
        }
        if (_this == null && !isStatic) {
            _this = clazz.newMock(env);
            if (_this == null)
                env.error(ErrorType.E_ERROR, Messages.ERR_STATIC_METHOD_CALLED_DYNAMICALLY.fetch(getClazz().getName() + "::" + getName()));
        }
        CompileMethod.Method method = function.find(arguments == null ? 0 : arguments.length);
        if (method == null) {
            env.warning(env.trace(), Messages.ERR_EXPECT_LEAST_PARAMS.fetch(name, function.getMinArgs(), arguments == null ? 0 : arguments.length));
            return Memory.NULL;
        } else {
            if (arguments != null && arguments.length > method.argsCount && !method.isVarArg()) {
                env.error(env.trace(), ErrorType.E_ERROR, Messages.ERR_EXPECT_EXACTLY_PARAMS, name, method.argsCount, arguments.length);
                return Memory.NULL;
            }
        }
        Class<?>[] types = method.parameterTypes;
        Object[] passed = new Object[types.length];
        int i = 0;
        int j = 0;
        for (Class<?> clazz : types) {
            boolean isRef = method.references[i];
            boolean mutableValue = method.mutableValues[i];
            MemoryOperation<?> operation = method.argumentOperations[i];
            if (clazz == Memory.class) {
                passed[i] = isRef ? arguments[j] : (mutableValue ? arguments[j].toValue() : arguments[j].fast_toImmutable());
                j++;
            } else if (operation != null) {
                if (operation instanceof InjectMemoryOperation) {
                    passed[i] = operation.convert(env, trace, null);
                } else {
                    passed[i] = operation.convert(env, trace, arguments[j]);
                    j++;
                }
            } else if (i == types.length - 1 && types[i] == Memory[].class) {
                Memory[] arg = new Memory[arguments.length - i + 1];
                if (!isRef) {
                    for (int k = 0; k < arg.length; k++) arg[i] = arguments[i].fast_toImmutable();
                } else {
                    System.arraycopy(arguments, j, arg, 0, arg.length);
                }
                passed[i] = arg;
                break;
            } else {
                env.error(trace, ErrorType.E_CORE_ERROR, name + "(): Cannot call this method dynamically");
                passed[i] = Memory.NULL;
            }
            i++;
        }
        try {
            return method.returnOperation.unconvertNoThow(env, trace, method.method.invoke(_this, passed));
        } finally {
            i = 0;
            if (this != this.getClazz().methodConstruct) {
                for (Object o : passed) {
                    MemoryOperation operation = method.argumentOperations[i];
                    if (operation != null) {
                        operation.releaseConverted(env, trace, o);
                    }
                    i++;
                }
            }
        }
    } catch (InvocationTargetException e) {
        return env.__throwException(e);
    } catch (Throwable e) {
        throw e;
    } finally {
        unsetArguments(arguments);
    }
}
Also used : Memory(php.runtime.Memory) BeanMemoryOperation(php.runtime.memory.support.operation.BeanMemoryOperation) MemoryOperation(php.runtime.memory.support.MemoryOperation) IObject(php.runtime.lang.IObject)

Example 8 with MemoryOperation

use of php.runtime.memory.support.MemoryOperation in project jphp by jphp-compiler.

the class Invoker method callAny.

public final Memory callAny(Object... args) {
    if (args != null && args.length > 0) {
        Memory[] passed = new Memory[args.length];
        for (int i = 0; i < passed.length; i++) {
            if (args[i] == null) {
                passed[i] = Memory.NULL;
                continue;
            }
            MemoryOperation operation = MemoryOperation.get(args[i].getClass(), args[i].getClass().getGenericSuperclass());
            if (operation == null) {
                throw new CriticalException("Unsupported bind type - " + args[i].getClass().toString());
            }
            passed[i] = operation.unconvertNoThow(env, trace, args[i]);
        }
        return callNoThrow(passed);
    } else {
        return callNoThrow();
    }
}
Also used : Memory(php.runtime.Memory) ObjectMemory(php.runtime.memory.ObjectMemory) MemoryOperation(php.runtime.memory.support.MemoryOperation) CriticalException(php.runtime.exceptions.CriticalException)

Aggregations

MemoryOperation (php.runtime.memory.support.MemoryOperation)8 Memory (php.runtime.Memory)4 IObject (php.runtime.lang.IObject)3 BufferedImage (java.awt.image.BufferedImage)2 Signature (php.runtime.annotation.Reflection.Signature)2 CriticalException (php.runtime.exceptions.CriticalException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 WritableImage (javafx.scene.image.WritableImage)1 NativeObject (org.develnext.jphp.ext.pna.classes.NativeObject)1 ObjectMemory (php.runtime.memory.ObjectMemory)1 BeanMemoryOperation (php.runtime.memory.support.operation.BeanMemoryOperation)1