use of php.runtime.lang.Closure in project jphp by jphp-compiler.
the class PrintR method printClosure.
@Override
protected void printClosure(Closure closure, int level, Set<Integer> used) {
ClassEntity classEntity = closure.getReflection();
writeObjectHeader(Closure.class.getSimpleName());
if (used.contains(closure.getPointer())) {
printer.write(" *RECURSION*");
} else {
printer.write(StringUtils.repeat(' ', level));
writeOpen();
level += PRINT_INDENT;
used.add(closure.getPointer());
level -= PRINT_INDENT;
printer.write(StringUtils.repeat(' ', level));
writeClose();
used.remove(closure.getPointer());
}
}
use of php.runtime.lang.Closure in project jphp by jphp-compiler.
the class VarDump method printClosure.
@Override
protected void printClosure(Closure closure, int level, Set<Integer> used) {
ClassEntity classEntity = closure.getReflection();
if (used.contains(closure.getPointer())) {
printer.write("*RECURSION*\n");
} else {
printer.write("object(");
printer.write(Closure.class.getSimpleName());
printer.write(")#" + closure.getPointer());
printer.write(" (" + closure.getUses().length + ") {\n");
level += PRINT_INDENT;
used.add(closure.getPointer());
level -= PRINT_INDENT;
printer.write(StringUtils.repeat(' ', level));
printer.write("}\n");
used.remove(closure.getPointer());
}
}
use of php.runtime.lang.Closure in project jphp by jphp-compiler.
the class ObjectInvokeHelper method invokeMethod.
public static Memory invokeMethod(IObject iObject, MethodEntity method, Environment env, TraceInfo trace, Memory[] args, boolean checkAccess) throws Throwable {
ClassEntity clazz = iObject.getReflection();
if (method == null)
method = clazz.methodMagicInvoke;
String className = clazz.getName();
if (method == null) {
env.error(trace, Messages.ERR_CALL_TO_UNDEFINED_METHOD.fetch(className + "::__invoke"));
return Memory.NULL;
}
if (checkAccess)
InvokeHelper.checkAccess(env, trace, method);
Memory[] passed = InvokeArgumentHelper.makeArguments(env, args, method.getParameters(args == null ? 0 : args.length), className, method.getName(), className, trace);
Memory result = method.getImmutableResultTyped(env, trace);
if (result != null) {
return result;
}
if (trace != null) {
String staticClass = className;
if (iObject instanceof Closure) {
staticClass = ((Closure) iObject).getScope();
}
if (clazz.isHiddenInCallStack()) {
env.pushCall(trace, iObject, args, method.getName(), staticClass, staticClass);
} else {
env.pushCallEx(trace, iObject, args, method.getName(), method.getClazz(), staticClass);
}
}
try {
result = method.invokeDynamic(iObject, env, trace, passed);
} finally {
if (trace != null)
env.popCall();
}
return result;
}
use of php.runtime.lang.Closure 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.lang.Closure in project jphp by jphp-compiler.
the class FunctionEntity method getClosure.
@Override
public Closure getClosure(Environment env) {
if (cachedClosure != null)
return cachedClosure;
final FunctionEntity bind = this;
final ClosureEntity closureEntity1 = new ClosureEntity(this.getContext());
closureEntity1.setParent(env.scope.fetchUserClass(Closure.class));
closureEntity1.parameters = this.parameters;
closureEntity1.setReturnReference(this.isReturnReference());
MethodEntity m = new MethodEntity(this);
m.setUsesStackTrace(true);
m.setClazz(closureEntity1);
m.setName("__invoke");
closureEntity1.addMethod(m, null);
closureEntity1.doneDeclare();
Closure tmp = new Closure(env, closureEntity1, new ObjectMemory(env.getLateObject()), null, Memory.CONST_EMPTY_ARRAY) {
@Override
public Memory __invoke(Environment e, Memory... args) {
try {
return bind.invoke(e, e.peekCall(0).trace, args);
} catch (RuntimeException e1) {
throw e1;
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
}
@Override
public Memory getOrCreateStatic(String name) {
return Memory.NULL;
}
@Override
public ClassEntity getReflection() {
return closureEntity1;
}
};
try {
m.setNativeMethod(tmp.getClass().getDeclaredMethod("__invoke", Environment.class, Memory[].class));
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
return cachedClosure = tmp;
}
Aggregations