Search in sources :

Example 11 with ArrayMemory

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

the class MultipleIterator method current.

@Override
@Signature
public Memory current(Environment env, Memory... args) {
    if (iterators.size() == 0) {
        return Memory.FALSE;
    }
    ArrayMemory result = new ArrayMemory();
    ForeachIterator iterator = iterators.getNewIterator(env);
    while (iterator.next()) {
        Iterator el = iterator.getValue().toObject(Iterator.class);
        if (env.invokeMethodNoThrow(el, "valid").toBoolean()) {
            Memory current = env.invokeMethodNoThrow(el, "current");
            if ((flags & MIT_KEYS_ASSOC) == MIT_KEYS_ASSOC) {
                result.put(iterator.getKey(), current);
            } else {
                result.add(current);
            }
        } else {
            if ((flags & MIT_NEED_ALL) == MIT_NEED_ALL) {
                env.exception(InvalidArgumentException.class, "One of iterators is not valid");
            }
        }
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) ObjectMemory(php.runtime.memory.ObjectMemory) ForeachIterator(php.runtime.lang.ForeachIterator)

Example 12 with ArrayMemory

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

the class ReflectionClass method getMethods.

@Signature(@Arg(value = "filter", optional = @Optional("NULL")))
public Memory getMethods(Environment env, Memory... args) {
    int mod = args[0].isNull() ? -1 : args[0].toInteger();
    ArrayMemory result = new ArrayMemory();
    ClassEntity classEntity = env.fetchClass("ReflectionMethod");
    for (MethodEntity e : entity.getMethods().values()) {
        if (checkModifiers(e, mod)) {
            ReflectionMethod method = new ReflectionMethod(env, classEntity);
            method.setEntity(e);
            result.add(new ObjectMemory(method));
        }
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ClassEntity(php.runtime.reflection.ClassEntity) ObjectMemory(php.runtime.memory.ObjectMemory) MethodEntity(php.runtime.reflection.MethodEntity)

Example 13 with ArrayMemory

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

the class CharArrayMemoryOperation method convert.

@Override
public char[] convert(Environment env, TraceInfo trace, Memory arg) throws Throwable {
    char[] result = new char[((ArrayMemory) arg).size()];
    int i = 0;
    for (Memory el : (ArrayMemory) arg) {
        result[i++] = el.toChar();
    }
    return result;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory)

Example 14 with ArrayMemory

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

the class ShortArrayMemoryOperation method convert.

@Override
public short[] convert(Environment env, TraceInfo trace, Memory arg) throws Throwable {
    short[] result = new short[((ArrayMemory) arg).size()];
    int i = 0;
    for (Memory el : (ArrayMemory) arg) {
        result[i++] = (short) el.toInteger();
    }
    return result;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory)

Example 15 with ArrayMemory

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

the class ClassEntity method issetProperty.

public Memory issetProperty(Environment env, TraceInfo trace, IObject object, String property, PropertyCallCache callCache, int cacheIndex) throws Throwable {
    PropertyEntity entity = callCache == null || env instanceof ConcurrentEnvironment ? null : callCache.get(env, cacheIndex);
    if (entity == null) {
        ClassEntity contex = env.getLastClassOnStack();
        entity = isInstanceOf(contex) ? contex.properties.get(property) : properties.get(property);
        if (entity != null && callCache != null) {
            callCache.put(env, cacheIndex, entity);
        }
    }
    int accessFlag = entity == null ? 0 : entity.canAccess(env);
    ArrayMemory props = object.getProperties();
    Memory tmp = props == null || accessFlag != 0 ? null : props.getByScalar(entity == null ? property : entity.specificName);
    if (tmp != null)
        return tmp.isNull() ? tmp : Memory.TRUE;
    if (methodMagicIsset != null) {
        Memory result;
        ClassEntity contex = env.getLastClassOnStack();
        if (contex != null && contex.getId() == methodMagicIsset.getClazz().getId())
            if (env.peekCall(0).flags == FLAG_ISSET) {
                return object.getProperties().getByScalar(property) != null ? Memory.TRUE : Memory.NULL;
            }
        try {
            Memory[] args = new Memory[] { new StringMemory(property) };
            env.pushCall(trace, object, args, methodMagicIsset.getName(), methodMagicIsset.getClazz().getName(), name);
            env.peekCall(0).flags = FLAG_ISSET;
            InvokeArgumentHelper.checkType(env, trace, methodMagicIsset, new StringMemory(property));
            result = methodMagicIsset.invokeDynamic(object, env, new StringMemory(property)).toBoolean() ? Memory.TRUE : Memory.NULL;
        } finally {
            env.popCall();
        }
        return result;
    }
    return Memory.NULL;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ConcurrentEnvironment(php.runtime.env.ConcurrentEnvironment) ArrayMemory(php.runtime.memory.ArrayMemory) Memory(php.runtime.Memory) ReferenceMemory(php.runtime.memory.ReferenceMemory) StringMemory(php.runtime.memory.StringMemory) StringMemory(php.runtime.memory.StringMemory)

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