use of php.runtime.Memory in project jphp by jphp-compiler.
the class ArraysTest method testArrayPushRefAssign.
@Test
public void testArrayPushRefAssign() {
Memory memory = includeResource("arrays/array_push_ref_assign.php");
Assert.assertEquals("success", memory.toString());
}
use of php.runtime.Memory in project jphp by jphp-compiler.
the class ClosureValueCompiler method write.
@Override
public void write(ClosureStmtToken closure, boolean returnValue) {
if (returnValue) {
ClosureEntity entity = compiler.getModule().findClosure(closure.getId());
boolean thisExists = closure.getFunction().isThisExists();
boolean staticExists = closure.getFunction().isStaticExists();
if (closure.getFunction().getUses().isEmpty() && !thisExists && !staticExists && closure.getFunction().getStaticLocal().isEmpty()) {
expr.writePushEnv();
expr.writePushConstString(compiler.getModule().getInternalName());
expr.writePushConstInt((int) entity.getId());
expr.writeSysDynamicCall(Environment.class, "__getSingletonClosure", Memory.class, String.class, Integer.TYPE);
} else {
add(new TypeInsnNode(NEW, entity.getInternalName()));
expr.stackPush(Memory.Type.REFERENCE);
expr.writePushDup();
expr.writePushEnv();
expr.writePushEnv();
expr.writePushConstString(compiler.getModule().getInternalName());
expr.writePushConstInt((int) entity.getId());
expr.writeSysDynamicCall(Environment.class, "__getClosure", ClassEntity.class, String.class, Integer.TYPE);
if (thisExists)
expr.writePushThis();
else
expr.writePushNull();
writeContext();
writePushUses(closure.getFunction().getUses());
add(new MethodInsnNode(INVOKESPECIAL, entity.getInternalName(), Constants.INIT_METHOD, Type.getMethodDescriptor(Type.getType(void.class), Type.getType(Environment.class), Type.getType(ClassEntity.class), Type.getType(Memory.class), Type.getType(String.class), Type.getType(Memory[].class)), false));
expr.stackPop();
expr.stackPop();
expr.stackPop();
expr.stackPop();
expr.stackPop();
expr.stackPop();
expr.writeSysStaticCall(ObjectMemory.class, "valueOf", Memory.class, IObject.class);
}
expr.setStackPeekAsImmutable();
}
}
use of php.runtime.Memory in project jphp by jphp-compiler.
the class GlobalDefinitionCompiler method write.
@Override
public void write(GlobalStmtToken token) {
for (ValueExprToken variable : token.getVariables()) {
if (variable instanceof VariableExprToken) {
LocalVariable local = method.getLocalVariable(((VariableExprToken) variable).getName());
assert local != null;
expr.writePushEnv();
expr.writePushConstString(local.name);
expr.writeSysDynamicCall(Environment.class, "getOrCreateGlobal", Memory.class, String.class);
expr.writeVarStore(local, false, false);
} else if (variable instanceof GetVarExprToken) {
BaseExprCompiler<GetVarExprToken> compiler = (BaseExprCompiler<GetVarExprToken>) expr.getCompiler(GetVarExprToken.class);
if (compiler == null)
throw new CriticalException("Cannot find a valid compiler for " + GetVarExprToken.class.getName());
compiler.write((GetVarExprToken) variable, true);
expr.writePushEnv();
Memory name = expr.writeExpression(((GetVarExprToken) variable).getName(), true, true, true);
if (name != null) {
expr.writePushConstString(name.toString());
} else {
expr.writePopString();
}
expr.writeSysDynamicCall(Environment.class, "getOrCreateGlobal", Memory.class, String.class);
expr.writeSysDynamicCall(Memory.class, "assign", Memory.class, Memory.class);
expr.writePopAll(1);
}
}
}
use of php.runtime.Memory in project jphp by jphp-compiler.
the class ReturnCompiler method write.
@Override
public void write(ReturnStmtToken token) {
if (token.getValue() != null && method.getGeneratorEntity() != null) {
env.error(token.toTraceInfo(compiler.getContext()), ErrorType.E_ERROR, "Generators cannot return values using \"return\"");
}
Memory result = Memory.NULL;
boolean isImmutable = method.getEntity().isImmutable();
if (token.getValue() != null)
result = expr.writeExpression(token.getValue(), true, true);
if (result != null) {
if (isImmutable) {
if (method.getEntity().getResult() == null)
method.getEntity().setResult(result);
}
expr.writePushMemory(result);
} else {
method.getEntity().setImmutable(false);
}
if (expr.stackEmpty(false))
expr.writePushNull();
else
expr.writePopBoxing(false);
if (method.getEntity().isReturnReference()) {
expr.writePushDup();
expr.writePushEnv();
expr.writePushTraceInfo(token);
expr.writeSysStaticCall(InvokeHelper.class, "checkReturnReference", void.class, Memory.class, Environment.class, TraceInfo.class);
} else
expr.writePopImmutable();
if (!method.getTryStack().empty()) {
LocalVariable variable = method.getLocalVariable("~result~");
if (variable == null)
variable = method.addLocalVariable("~result~", null, Memory.class);
expr.writeVarStore(variable, false, false);
add(new JumpInsnNode(GOTO, method.getTryStack().peek().getReturnLabel()));
} else {
add(new InsnNode(ARETURN));
//removeStackFrame();
expr.stackPop();
}
}
use of php.runtime.Memory in project jphp by jphp-compiler.
the class CastTest method testObject.
@Test
public void testObject() {
Memory memory = includeResource("cast/object.php");
Assert.assertEquals("success", memory.toString());
}
Aggregations