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;
}
}
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);
}
}
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();
}
}
Aggregations