Search in sources :

Example 11 with Invoker

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;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Invoker(php.runtime.invoke.Invoker) Memory(php.runtime.Memory)

Example 12 with Invoker

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;
}
Also used : Invoker(php.runtime.invoke.Invoker)

Example 13 with Invoker

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));
}
Also used : Invoker(php.runtime.invoke.Invoker) ObjectMemory(php.runtime.memory.ObjectMemory) Memory(php.runtime.Memory) ObjectMemory(php.runtime.memory.ObjectMemory) Environment(php.runtime.env.Environment)

Example 14 with Invoker

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;
}
Also used : Invoker(php.runtime.invoke.Invoker) Environment(php.runtime.env.Environment)

Example 15 with Invoker

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;
}
Also used : Invoker(php.runtime.invoke.Invoker)

Aggregations

Invoker (php.runtime.invoke.Invoker)50 Memory (php.runtime.Memory)21 ArrayMemory (php.runtime.memory.ArrayMemory)13 ForeachIterator (php.runtime.lang.ForeachIterator)12 LongMemory (php.runtime.memory.LongMemory)9 ObjectMemory (php.runtime.memory.ObjectMemory)9 KeyValueMemory (php.runtime.memory.KeyValueMemory)7 StringMemory (php.runtime.memory.StringMemory)7 Environment (php.runtime.env.Environment)6 ReferenceMemory (php.runtime.memory.ReferenceMemory)5 SplClassLoader (php.runtime.env.SplClassLoader)4 File (java.io.File)2 MemorySerializer (org.develnext.jphp.json.gson.MemorySerializer)2 UIReader (org.develnext.jphp.swing.loader.UIReader)2 TraceInfo (php.runtime.env.TraceInfo)2 FileObject (php.runtime.ext.core.classes.stream.FileObject)2 ActionEvent (java.awt.event.ActionEvent)1 MessageDigest (java.security.MessageDigest)1 Scanner (java.util.Scanner)1 FileFilter (javax.swing.filechooser.FileFilter)1