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);
}
}
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;
}
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();
}
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;
}
}
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();
}
Aggregations