Search in sources :

Example 1 with InstructionBuilder

use of org.apache.tapestry5.plastic.InstructionBuilder in project tapestry-5 by apache.

the class PlasticFieldImpl method replaceFieldWriteAccess.

private void replaceFieldWriteAccess(String conduitFieldName) {
    ensureNotPublic();
    String setAccessName = plasticClass.makeUnique(plasticClass.methodNames, "conduit_set_" + node.name);
    setAccess = new MethodNode(accessForMethod(), setAccessName, "(" + node.desc + ")V", null, null);
    InstructionBuilder builder = plasticClass.newBuilder(setAccess);
    pushFieldConduitOntoStack(conduitFieldName, builder);
    builder.loadThis();
    plasticClass.pushInstanceContextFieldOntoStack(builder);
    // Take the value passed to this method and push it onto the stack.
    builder.loadArgument(0);
    builder.boxPrimitive(typeName);
    builder.invoke(FieldConduit.class, void.class, "set", Object.class, InstanceContext.class, Object.class);
    if (isWriteBehindEnabled()) {
        builder.loadThis().loadArgument(0).putField(plasticClass.className, node.name, typeName);
    }
    builder.returnResult();
    plasticClass.addMethod(setAccess);
    plasticClass.redirectFieldWrite(node.name, isPrivate(), setAccess);
}
Also used : MethodNode(org.apache.tapestry5.internal.plastic.asm.tree.MethodNode)

Example 2 with InstructionBuilder

use of org.apache.tapestry5.plastic.InstructionBuilder in project tapestry-5 by apache.

the class PlasticFieldImpl method replaceFieldReadAccess.

private void replaceFieldReadAccess(String conduitFieldName) {
    ensureNotPublic();
    boolean writeBehindEnabled = isWriteBehindEnabled();
    String getAccessName = plasticClass.makeUnique(plasticClass.methodNames, "conduit_get_" + node.name);
    getAccess = new MethodNode(accessForMethod(), getAccessName, "()" + node.desc, null, null);
    InstructionBuilder builder = plasticClass.newBuilder(getAccess);
    // Get the correct FieldConduit object on the stack
    pushFieldConduitOntoStack(conduitFieldName, builder);
    builder.loadThis();
    // Now push the instance context on the stack
    plasticClass.pushInstanceContextFieldOntoStack(builder);
    builder.invoke(FieldConduit.class, Object.class, "get", Object.class, InstanceContext.class).castOrUnbox(typeName);
    if (writeBehindEnabled) {
        if (isWide()) {
            // Dupe this under the wide value, then pop the wide value
            builder.dupeWide().loadThis().dupe(2).pop();
        } else {
            builder.dupe().loadThis().swap();
        }
        // At which point the stack is the result value, this, the result value
        builder.putField(plasticClass.className, node.name, typeName);
    // And now it is just the result value
    }
    builder.returnResult();
    plasticClass.addMethod(getAccess);
    plasticClass.redirectFieldRead(node.name, isPrivate(), getAccess);
}
Also used : MethodNode(org.apache.tapestry5.internal.plastic.asm.tree.MethodNode)

Example 3 with InstructionBuilder

use of org.apache.tapestry5.plastic.InstructionBuilder in project tapestry-5 by apache.

the class InstructionBuilderImpl method increment.

@Override
public InstructionBuilder increment(LocalVariable variable) {
    check();
    LVInfo info = state.locals.get(variable);
    v.visitIincInsn(info.offset, 1);
    return this;
}
Also used : LVInfo(org.apache.tapestry5.internal.plastic.InstructionBuilderState.LVInfo)

Example 4 with InstructionBuilder

use of org.apache.tapestry5.plastic.InstructionBuilder in project tapestry-5 by apache.

the class InstructionBuilderImpl method doWhile.

@Override
public InstructionBuilder doWhile(Condition condition, final WhileCallback callback) {
    check();
    assert condition != null;
    assert callback != null;
    Label doCheck = state.newLabel();
    Label exitLoop = new Label();
    callback.buildTest(this);
    v.visitJumpInsn(conditionToOpcode.get(condition), exitLoop);
    callback.buildBody(this);
    v.visitJumpInsn(GOTO, doCheck);
    v.visitLabel(exitLoop);
    return this;
}
Also used : Label(org.apache.tapestry5.internal.plastic.asm.Label)

Example 5 with InstructionBuilder

use of org.apache.tapestry5.plastic.InstructionBuilder in project tapestry-5 by apache.

the class InstructionBuilderImpl method loadTypeConstant.

@Override
public InstructionBuilder loadTypeConstant(Class clazz) {
    check();
    Type type = Type.getType(clazz);
    v.visitLdcInsn(type);
    return this;
}
Also used : Type(org.apache.tapestry5.internal.plastic.asm.Type)

Aggregations

MethodNode (org.apache.tapestry5.internal.plastic.asm.tree.MethodNode)7 InstructionBuilder (org.apache.tapestry5.plastic.InstructionBuilder)6 InstructionBuilderCallback (org.apache.tapestry5.plastic.InstructionBuilderCallback)6 Method (java.lang.reflect.Method)3 PlasticClass (org.apache.tapestry5.plastic.PlasticClass)3 PlasticField (org.apache.tapestry5.plastic.PlasticField)3 Label (org.apache.tapestry5.internal.plastic.asm.Label)2 Type (org.apache.tapestry5.internal.plastic.asm.Type)2 PlasticClassTransformer (org.apache.tapestry5.plastic.PlasticClassTransformer)2 IFn (clojure.lang.IFn)1 Symbol (clojure.lang.Symbol)1 OnEvent (org.apache.tapestry5.annotations.OnEvent)1 Namespace (org.apache.tapestry5.clojure.Namespace)1 StrategyRegistry (org.apache.tapestry5.commons.util.StrategyRegistry)1 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)1 LVInfo (org.apache.tapestry5.internal.plastic.InstructionBuilderState.LVInfo)1 JSONArray (org.apache.tapestry5.json.JSONArray)1 JSONObject (org.apache.tapestry5.json.JSONObject)1 ClassInstantiator (org.apache.tapestry5.plastic.ClassInstantiator)1 Condition (org.apache.tapestry5.plastic.Condition)1