Search in sources :

Example 1 with GetVarExprToken

use of org.develnext.jphp.core.tokenizer.token.expr.value.GetVarExprToken in project jphp by jphp-compiler.

the class UnsetCompiler method write.

@Override
public void write(UnsetExprToken token, boolean returnValue) {
    method.getEntity().setImmutable(false);
    for (ExprStmtToken param : token.getParameters()) {
        if (param.isSingle() && param.getSingle() instanceof VariableExprToken) {
            VariableExprToken variable = (VariableExprToken) param.getSingle();
            expr.checkAssignableVar(variable);
            LocalVariable local = method.getLocalVariable(variable.getName());
            expr.writeVarLoad(local);
            expr.writePushEnv();
            expr.writeSysDynamicCall(Memory.class, "manualUnset", void.class, Environment.class);
            if (!local.isReference()) {
                expr.writePushNull();
                expr.writeVarAssign(local, null, false, false);
            }
            local.setValue(null);
        } else if (param.isSingle() && param.getSingle() instanceof GetVarExprToken) {
            expr.writeValue((ValueExprToken) param.getSingle(), true);
            expr.writePushEnv();
            expr.writeSysDynamicCall(Memory.class, "manualUnset", void.class, Environment.class);
        } else {
            expr.writeExpression(param, false, false, true);
        }
    }
    if (returnValue)
        expr.writePushNull();
}
Also used : ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) Memory(php.runtime.Memory) LocalVariable(org.develnext.jphp.core.compiler.jvm.misc.LocalVariable) Environment(php.runtime.env.Environment) VariableExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.VariableExprToken) GetVarExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.GetVarExprToken) ValueExprToken(org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)

Example 2 with GetVarExprToken

use of org.develnext.jphp.core.tokenizer.token.expr.value.GetVarExprToken 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);
        }
    }
}
Also used : Memory(php.runtime.Memory) LocalVariable(org.develnext.jphp.core.compiler.jvm.misc.LocalVariable) Environment(php.runtime.env.Environment) VariableExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.VariableExprToken) GetVarExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.GetVarExprToken) CriticalException(php.runtime.exceptions.CriticalException) ValueExprToken(org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)

Aggregations

LocalVariable (org.develnext.jphp.core.compiler.jvm.misc.LocalVariable)2 ValueExprToken (org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)2 GetVarExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.GetVarExprToken)2 VariableExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.VariableExprToken)2 Memory (php.runtime.Memory)2 Environment (php.runtime.env.Environment)2 ExprStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken)1 CriticalException (php.runtime.exceptions.CriticalException)1