Search in sources :

Example 26 with ArrayMemory

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

the class Environment method __tick.

/***** UTILS *****/
public void __tick(TraceInfo trace, ArrayMemory locals) {
    TickHandler tickHandler = scope.getTickHandler();
    if (tickHandler != null) {
        IObject $this = this.getLateObject();
        if ($this != null) {
            Memory value = ObjectMemory.valueOf($this);
            if ($this instanceof Closure) {
                value = ((Closure) $this).getSelf();
            }
            if (value.isObject()) {
                locals.putAsKeyString("this", value);
            }
        }
        tickHandler.onTick(this, trace, locals);
    }
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Memory(php.runtime.Memory) ReferenceMemory(php.runtime.memory.ReferenceMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory)

Example 27 with ArrayMemory

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

the class ArrayFunctions method recursive_count.

private static int recursive_count(Environment env, TraceInfo trace, ArrayMemory array, Set<Integer> used) {
    ForeachIterator iterator = array.foreachIterator(false, false);
    int size = array.size();
    while (iterator.next()) {
        Memory el = iterator.getValue();
        if (el.isArray()) {
            if (used == null)
                used = new HashSet<>();
            int pointer = el.getPointer();
            if (!used.add(pointer)) {
                env.warning(trace, "recursion detected");
            } else {
                size += recursive_count(env, trace, array, used);
            }
            used.remove(pointer);
        }
    }
    return size;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) ObjectMemory(php.runtime.memory.ObjectMemory) HashSet(java.util.HashSet)

Example 28 with ArrayMemory

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

the class InfoFunctions method get_defined_functions.

public static Memory get_defined_functions(Environment env) {
    ArrayMemory array = new ArrayMemory();
    ArrayMemory item = (ArrayMemory) array.refOfIndex("internal").assign(new ArrayMemory());
    for (FunctionEntity entity : env.getFunctions()) {
        if (entity.isInternal())
            item.add(new StringMemory(entity.getName()));
    }
    item = (ArrayMemory) array.refOfIndex("user").assign(new ArrayMemory());
    for (FunctionEntity entity : env.getLoadedFunctions().values()) {
        if (!entity.isInternal())
            item.add(new StringMemory(entity.getName()));
    }
    return array.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) FunctionEntity(php.runtime.reflection.FunctionEntity) StringMemory(php.runtime.memory.StringMemory)

Example 29 with ArrayMemory

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

the class LangFunctions method property_exists.

public static Memory property_exists(Environment env, Memory clazz, String property) throws Throwable {
    ClassEntity classEntity;
    IObject object = null;
    boolean isMagic = false;
    if (clazz.isObject()) {
        ObjectMemory tmp = clazz.toValue(ObjectMemory.class);
        classEntity = tmp.getReflection();
        object = tmp.value;
    } else {
        String name = clazz.toString();
        String nameL = name.toLowerCase();
        classEntity = env.fetchClass(name, nameL, true);
        if (classEntity == null) {
            classEntity = env.fetchMagicClass(name, nameL);
            isMagic = true;
        }
    }
    if (classEntity == null) {
        return Memory.FALSE;
    }
    if (object != null) {
        ArrayMemory props = object.getProperties();
        ClassEntity context = env.getLastClassOnStack();
        PropertyEntity entity = classEntity.isInstanceOf(context) ? context.properties.get(property) : classEntity.properties.get(property);
        int accessFlags = entity == null ? 0 : entity.canAccess(env);
        if (accessFlags != 0)
            return Memory.FALSE;
        return (props != null && props.getByScalar(entity == null ? property : entity.getSpecificName()) != null) ? Memory.TRUE : Memory.FALSE;
    } else {
        PropertyEntity entity = classEntity.properties.get(property);
        if (isMagic) {
            int accessFlags = entity == null ? 0 : entity.canAccess(env);
            if (accessFlags != 0)
                return Memory.FALSE;
        }
        return entity != null ? Memory.TRUE : Memory.FALSE;
    }
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) IObject(php.runtime.lang.IObject) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 30 with ArrayMemory

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

the class LangFunctions method debug_backtrace.

public static Memory debug_backtrace(Environment env, TraceInfo trace, int options, int limit) {
    boolean provideObject = (options & LangConstants.DEBUG_BACKTRACE_PROVIDE_OBJECT) == LangConstants.DEBUG_BACKTRACE_PROVIDE_OBJECT;
    boolean ignoreArgs = (options & LangConstants.DEBUG_BACKTRACE_IGNORE_ARGS) == LangConstants.DEBUG_BACKTRACE_IGNORE_ARGS;
    ArrayMemory result = new ArrayMemory();
    for (int i = 0; i < env.getCallStackTop(); i++) {
        if (limit != 0 && i >= limit)
            break;
        CallStackItem item = env.peekCall(i);
        ArrayMemory el = item.toArray(provideObject, ignoreArgs);
        result.add(el);
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) CallStackItem(php.runtime.env.CallStackItem)

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