use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class WrapFlow method reduce.
@Signature(@Arg(value = "callback", type = HintType.CALLABLE))
public Memory reduce(Environment env, Memory... args) {
Invoker invoker = Invoker.valueOf(env, null, args[0]);
ForeachIterator iterator = getSelfIterator(env);
Memory r = Memory.NULL;
int argCount = invoker.getArgumentCount();
while (iterator.next()) {
if (argCount < 3)
r = invoker.callNoThrow(r, iterator.getValue());
else
r = invoker.callNoThrow(r, iterator.getValue(), iterator.getMemoryKey());
}
return r;
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class WrapEnvironment method onOutput.
@Signature(@Arg("callback"))
public Memory onOutput(Environment env, Memory... args) {
if (args[0].isNull()) {
Invoker invoker = Invoker.valueOf(this.environment, null, args[0]);
if (invoker == null) {
env.exception("Argument 1 must be callable in environment");
return Memory.NULL;
}
invoker.setTrace(env.trace());
this.environment.getDefaultBuffer().setCallback(args[0], invoker);
} else {
this.environment.getDefaultBuffer().setCallback(null);
}
return Memory.NULL;
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class WrapThreadPool method submit.
@Signature({ @Arg(value = "runnable", type = HintType.CALLABLE), @Arg(value = "env", typeClass = "php\\lang\\Environment", optional = @Optional("NULL")) })
public Memory submit(Environment env, Memory... args) {
final Environment _env = args[1].isNull() ? env : args[1].toObject(WrapEnvironment.class).getWrapEnvironment();
final Invoker invoker = Invoker.valueOf(_env, null, args[0]);
Future<Memory> future = service.submit(new Callable<Memory>() {
@Override
public Memory call() throws Exception {
return invoker.callNoThrow();
}
});
return new ObjectMemory(new WrapFuture(env, future));
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class WrapThreadPool method execute.
@Signature({ @Arg(value = "runnable", type = HintType.CALLABLE), @Arg(value = "env", nativeType = WrapEnvironment.class, optional = @Optional("NULL")) })
public Memory execute(final Environment env, Memory... args) {
Environment _env = env;
if (!args[1].isNull()) {
_env = args[1].toObject(WrapEnvironment.class).getWrapEnvironment();
}
final Invoker invoker = Invoker.valueOf(_env, null, args[0]);
invoker.setTrace(env.trace());
final Environment final_env = _env;
service.execute(new Runnable() {
@Override
public void run() {
Environment.addThreadSupport(final_env);
invoker.callNoThrow();
}
});
return Memory.NULL;
}
use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.
the class WrapEnvironment method onMessage.
@Signature(@Arg("callback"))
public Memory onMessage(Environment env, Memory... args) {
Invoker invoker = Invoker.valueOf(this.environment, null, args[0]);
if (invoker == null) {
env.exception("Argument 1 must be callable in environment");
return Memory.NULL;
}
onMessage = invoker;
return Memory.NULL;
}
Aggregations