Search in sources :

Example 6 with StackItem

use of org.develnext.jphp.core.compiler.common.misc.StackItem in project jphp by jphp-compiler.

the class ExpressionStmtCompiler method writePushDup.

public void writePushDup() {
    StackItem item = method.peek();
    stackPush(item);
    if (item.type.size() == 2)
        code.add(new InsnNode(DUP2));
    else
        code.add(new InsnNode(DUP));
}
Also used : StackItem(org.develnext.jphp.core.compiler.common.misc.StackItem)

Example 7 with StackItem

use of org.develnext.jphp.core.compiler.common.misc.StackItem in project jphp by jphp-compiler.

the class MethodStmtCompiler method pop.

StackItem pop() {
    StackItem item = stack.pop();
    stackSize -= item.size;
    return item;
}
Also used : StackItem(org.develnext.jphp.core.compiler.common.misc.StackItem)

Example 8 with StackItem

use of org.develnext.jphp.core.compiler.common.misc.StackItem in project jphp by jphp-compiler.

the class ExpressionStmtCompiler method writeDynamicAccessPrepare.

public void writeDynamicAccessPrepare(DynamicAccessExprToken dynamic, boolean addLowerName) {
    if (stackEmpty(true))
        unexpectedToken(dynamic);
    StackItem o = stackPop();
    writePush(o);
    if (stackPeek().isConstant())
        unexpectedToken(dynamic);
    writePopBoxing();
    if (dynamic instanceof DynamicAccessAssignExprToken) {
        if (((DynamicAccessAssignExprToken) dynamic).getValue() != null) {
            writeExpression(((DynamicAccessAssignExprToken) dynamic).getValue(), true, false);
            writePopBoxing(true);
        }
    }
    writeDynamicAccessInfo(dynamic, addLowerName);
}
Also used : StackItem(org.develnext.jphp.core.compiler.common.misc.StackItem)

Example 9 with StackItem

use of org.develnext.jphp.core.compiler.common.misc.StackItem in project jphp by jphp-compiler.

the class ExpressionStmtCompiler method writeArrayGet.

void writeArrayGet(ArrayGetExprToken operator, boolean returnValue) {
    StackItem o = stackPeek();
    ValueExprToken L = null;
    if (o.getToken() != null) {
        stackPop();
        writePush(L = o.getToken(), true, false);
        writePopBoxing();
    }
    String methodName = operator instanceof ArrayGetRefExprToken ? "refOfIndex" : "valueOfIndex";
    boolean isShortcut = operator instanceof ArrayGetRefExprToken && ((ArrayGetRefExprToken) operator).isShortcut();
    int i = 0;
    int size = operator.getParameters().size();
    int traceIndex = createTraceInfo(operator);
    for (ExprStmtToken param : operator.getParameters()) {
        // push dup trace
        writePushTraceInfo(traceIndex);
        writeExpression(param, true, false);
        if (operator instanceof ArrayGetUnsetExprToken && i == size - 1) {
            writePopBoxing();
            writeSysDynamicCall(Memory.class, "unsetOfIndex", void.class, TraceInfo.class, stackPeek().type.toClass());
            if (returnValue)
                writePushNull();
        } else if (operator instanceof ArrayGetIssetExprToken && i == size - 1) {
            writePopBoxing();
            writeSysDynamicCall(Memory.class, "issetOfIndex", Memory.class, TraceInfo.class, stackPeek().type.toClass());
        } else if (operator instanceof ArrayGetEmptyExprToken && i == size - 1) {
            writePopBoxing();
            writeSysDynamicCall(Memory.class, "emptyOfIndex", Memory.class, TraceInfo.class, stackPeek().type.toClass());
        } else {
            // TODO: Remove.
            // PHP CMP: $hack = &$arr[0];
            // boolean isMemory = stackPeek().type.toClass() == Memory.class;
            // if (isMemory)
            /*if (compiler.isPhpMode()){
                    if (i == size - 1 && isShortcut){
                        writePopBoxing();
                        writeSysDynamicCall(Memory.class, methodName + "AsShortcut", Memory.class, TraceInfo.class, Memory.class);
                        continue;
                    }
                }*/
            writeSysDynamicCall(Memory.class, methodName, Memory.class, TraceInfo.class, stackPeek().type.toClass());
            i++;
        }
    }
}
Also used : StackItem(org.develnext.jphp.core.compiler.common.misc.StackItem) UndefinedMemory(php.runtime.memory.helper.UndefinedMemory) Memory(php.runtime.Memory) TraceInfo(php.runtime.env.TraceInfo) ValueExprToken(org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)

Aggregations

StackItem (org.develnext.jphp.core.compiler.common.misc.StackItem)9 ValueExprToken (org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)4 Memory (php.runtime.Memory)4 UndefinedMemory (php.runtime.memory.helper.UndefinedMemory)4 LocalVariable (org.develnext.jphp.core.compiler.jvm.misc.LocalVariable)2 TraceInfo (php.runtime.env.TraceInfo)2 CompileClass (php.runtime.ext.support.compile.CompileClass)2 OpenEchoTagToken (org.develnext.jphp.core.tokenizer.token.OpenEchoTagToken)1 Token (org.develnext.jphp.core.tokenizer.token.Token)1 ClassExprToken (org.develnext.jphp.core.tokenizer.token.expr.ClassExprToken)1 OperatorExprToken (org.develnext.jphp.core.tokenizer.token.expr.OperatorExprToken)1 Type (org.objectweb.asm.Type)1 Environment (php.runtime.env.Environment)1 InvokeHelper (php.runtime.invoke.InvokeHelper)1 ObjectInvokeHelper (php.runtime.invoke.ObjectInvokeHelper)1