Search in sources :

Example 21 with Invoker

use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.

the class JsonProcessor method onClassSerialize.

@Signature({ @Arg("className"), @Arg(value = "callback", type = HintType.CALLABLE, optional = @Optional("null")) })
public Memory onClassSerialize(Environment env, Memory... args) {
    ClassEntity entity = env.fetchClass(args[0].toString(), true);
    if (entity == null)
        throw new IllegalArgumentException("Class not found - " + args[0]);
    MemorySerializer.Handler handler = null;
    if (!args[1].isNull()) {
        final Invoker invoker = Invoker.valueOf(env, env.trace(), args[1]);
        handler = new MemorySerializer.Handler() {

            @Override
            public Memory call(Environment env, Memory value) {
                return invoker.callNoThrow(value);
            }
        };
    }
    memorySerializer.setClassHandler(entity.getName(), handler);
    return Memory.NULL;
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) MemorySerializer(org.develnext.jphp.json.gson.MemorySerializer) Invoker(php.runtime.invoke.Invoker) Memory(php.runtime.Memory) Environment(php.runtime.env.Environment)

Example 22 with Invoker

use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.

the class RunnableMemoryOperation method convert.

@Override
public Runnable convert(final Environment env, final TraceInfo trace, final Memory arg) throws Throwable {
    return new Runnable() {

        @Override
        public void run() {
            Invoker invoker = Invoker.valueOf(env, trace, arg);
            invoker.callAny();
        }
    };
}
Also used : Invoker(php.runtime.invoke.Invoker)

Example 23 with Invoker

use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.

the class WrapFlow method eachSlice.

@Signature({ @Arg(value = "sliceSize"), @Arg(value = "callback", type = HintType.CALLABLE) })
public Memory eachSlice(Environment env, Memory... args) {
    Invoker invoker = Invoker.valueOf(env, null, args[1]);
    ArrayMemory tmp = new ArrayMemory();
    int cnt = 0, r = 0, n = args[0].toInteger();
    while (iterator.next()) {
        cnt++;
        if (withKeys)
            tmp.refOfIndex(iterator.getMemoryKey()).assign(iterator.getValue());
        else
            tmp.add(iterator.getValue());
        if (cnt >= n) {
            r++;
            Memory ret = invoker.callNoThrow(tmp);
            tmp = new ArrayMemory();
            if (ret.toValue() == Memory.FALSE)
                break;
            cnt = 0;
        }
    }
    if (tmp.size() > 0) {
        r++;
        invoker.callNoThrow(tmp);
    }
    return LongMemory.valueOf(r);
}
Also used : Invoker(php.runtime.invoke.Invoker) Memory(php.runtime.Memory)

Example 24 with Invoker

use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.

the class WrapFlow method group.

@Signature({ @Arg(value = "callback", type = HintType.CALLABLE) })
public Memory group(Environment env, Memory... args) {
    final Invoker invoker = Invoker.valueOf(env, null, args[0]);
    final ForeachIterator iterator = getSelfIterator(env);
    return new ObjectMemory(new WrapFlow(env, new ForeachIterator(false, false, false) {

        protected Memory key;

        @Override
        protected boolean init() {
            key = Memory.CONST_INT_M1;
            return true;
        }

        @Override
        protected boolean nextValue() {
            Memory r = new ArrayMemory();
            boolean done = false;
            while (iterator.next()) {
                done = true;
                if (withKeys)
                    r.refOfIndex(iterator.getMemoryKey()).assign(iterator.getValue());
                else
                    r.refOfPush().assign(iterator.getValue());
                if (call(iterator, invoker).toBoolean())
                    break;
            }
            if (done) {
                currentKeyMemory = key.inc();
                currentKey = currentKeyMemory;
                currentValue = r;
            }
            return done;
        }

        @Override
        protected boolean prevValue() {
            return false;
        }

        @Override
        public void reset() {
            iterator.reset();
            key = Memory.CONST_INT_M1;
        }
    }));
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Invoker(php.runtime.invoke.Invoker) Memory(php.runtime.Memory)

Example 25 with Invoker

use of php.runtime.invoke.Invoker in project jphp by jphp-compiler.

the class WrapFlow method findOne.

@Signature(@Arg(value = "filter", type = HintType.CALLABLE, optional = @Optional("NULL")))
public Memory findOne(Environment env, Memory... args) {
    final Invoker invoker = Invoker.valueOf(env, null, args[0]);
    ForeachIterator iterator = getSelfIterator(env);
    while (iterator.next()) {
        if (call(iterator, invoker).toBoolean())
            return iterator.getValue();
    }
    return Memory.NULL;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) 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