Search in sources :

Example 81 with ArrayMemory

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

the class ReflectionClass method getStaticProperties.

@Signature
public Memory getStaticProperties(Environment env, Memory... args) {
    ArrayMemory result = new ArrayMemory();
    ClassEntity classEntity = env.fetchClass("ReflectionProperty");
    for (PropertyEntity e : entity.getStaticProperties()) {
        ReflectionProperty prop = new ReflectionProperty(env, classEntity);
        prop.setEntity(e);
        result.add(new ObjectMemory(prop));
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ClassEntity(php.runtime.reflection.ClassEntity) PropertyEntity(php.runtime.reflection.PropertyEntity) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 82 with ArrayMemory

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

the class ReflectionClass method getInterfaces.

@Signature
public Memory getInterfaces(Environment env, Memory... args) {
    ArrayMemory result = new ArrayMemory();
    ClassEntity classEntity = env.fetchClass("ReflectionClass");
    for (ClassEntity e : entity.getInterfaces().values()) {
        ReflectionClass cls = new ReflectionClass(env, classEntity);
        cls.setEntity(e);
        result.add(new ObjectMemory(cls));
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ClassEntity(php.runtime.reflection.ClassEntity) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 83 with ArrayMemory

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

the class ItemsUtils method combine.

@Signature({ @Arg(value = "keys", type = HintType.TRAVERSABLE), @Arg(value = "values", type = HintType.TRAVERSABLE) })
public static Memory combine(Environment env, Memory... args) {
    ForeachIterator keyIterator = args[0].getNewIterator(env);
    ForeachIterator valueIterator = args[1].getNewIterator(env);
    ArrayMemory r = new ArrayMemory();
    while (keyIterator.next()) {
        if (valueIterator.next()) {
            r.refOfIndex(keyIterator.getValue()).assign(valueIterator.getValue().toImmutable());
        } else {
            return Memory.NULL;
        }
    }
    return r.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ForeachIterator(php.runtime.lang.ForeachIterator)

Example 84 with ArrayMemory

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

the class ItemsUtils method map.

@Signature({ @Arg(value = "collection", type = HintType.TRAVERSABLE), @Arg(value = "callback", type = HintType.CALLABLE) })
public static Memory map(Environment env, Memory... args) throws Throwable {
    ForeachIterator iterator = args[0].getNewIterator(env);
    if (iterator == null) {
        return Memory.NULL;
    }
    Invoker callback = Invoker.valueOf(env, null, args[1]);
    if (callback == null) {
        return Memory.NULL;
    }
    ArrayMemory r = new ArrayMemory();
    while (iterator.next()) {
        r.refOfIndex(iterator.getMemoryKey()).assign(callback.call(iterator.getValue()));
    }
    return r.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ForeachIterator(php.runtime.lang.ForeachIterator) Invoker(php.runtime.invoke.Invoker)

Example 85 with ArrayMemory

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

the class ItemsUtils method flatten.

@Signature({ @Arg(value = "collection", type = HintType.TRAVERSABLE), @Arg(value = "level", optional = @Optional("-1")) })
public static Memory flatten(Environment env, Memory... args) {
    ArrayMemory r = new ArrayMemory();
    int level = args[1].toInteger();
    ForeachIterator iterator = args[0].getNewIterator(env);
    if (iterator == null) {
        return Memory.NULL;
    }
    Set<Integer> used = new HashSet<Integer>();
    used.add(args[0].getPointer());
    flatten(env, iterator, used, r, 0, level);
    return r.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ForeachIterator(php.runtime.lang.ForeachIterator)

Aggregations

ArrayMemory (php.runtime.memory.ArrayMemory)148 Memory (php.runtime.Memory)60 ForeachIterator (php.runtime.lang.ForeachIterator)41 ObjectMemory (php.runtime.memory.ObjectMemory)35 LongMemory (php.runtime.memory.LongMemory)31 StringMemory (php.runtime.memory.StringMemory)29 ReferenceMemory (php.runtime.memory.ReferenceMemory)25 KeyValueMemory (php.runtime.memory.KeyValueMemory)17 Invoker (php.runtime.invoke.Invoker)9 ClassEntity (php.runtime.reflection.ClassEntity)9 Signature (php.runtime.annotation.Reflection.Signature)6 IObject (php.runtime.lang.IObject)6 Map (java.util.Map)4 Test (org.junit.Test)4 DoubleMemory (php.runtime.memory.DoubleMemory)4 ConcurrentEnvironment (php.runtime.env.ConcurrentEnvironment)3 TraceInfo (php.runtime.env.TraceInfo)3 ModuleEntity (php.runtime.reflection.ModuleEntity)3 ParameterEntity (php.runtime.reflection.ParameterEntity)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2