Java Code Examples for org.objectweb.asm.commons.GeneratorAdapter#ifZCmp()

The following examples show how to use org.objectweb.asm.commons.GeneratorAdapter#ifZCmp() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpressionBooleanOr.java    From datakernel with Apache License 2.0 6 votes vote down vote up
@Override
public Type load(Context ctx) {
	GeneratorAdapter g = ctx.getGeneratorAdapter();
	Label exit = new Label();
	Label labelTrue = new Label();
	for (Expression predicate : expressions) {
		Type type = predicate.load(ctx);
		checkArgument(type == BOOLEAN_TYPE);
		g.ifZCmp(GeneratorAdapter.NE, labelTrue);
	}
	g.push(false);
	g.goTo(exit);

	g.mark(labelTrue);
	g.push(true);

	g.mark(exit);
	return BOOLEAN_TYPE;
}
 
Example 2
Source File: ExpressionBooleanAnd.java    From datakernel with Apache License 2.0 6 votes vote down vote up
@Override
public Type load(Context ctx) {
	GeneratorAdapter g = ctx.getGeneratorAdapter();
	Label exit = new Label();
	Label labelFalse = new Label();
	for (Expression predicate : expressions) {
		Type type = predicate.load(ctx);
		checkArgument(type == BOOLEAN_TYPE);
		g.ifZCmp(GeneratorAdapter.EQ, labelFalse);
	}
	g.push(true);
	g.goTo(exit);

	g.mark(labelFalse);
	g.push(false);

	g.mark(exit);
	return BOOLEAN_TYPE;
}
 
Example 3
Source File: ExpressionBooleanNot.java    From datakernel with Apache License 2.0 5 votes vote down vote up
@Override
public Type load(Context ctx) {
	GeneratorAdapter g = ctx.getGeneratorAdapter();
	Label labelFalse = g.newLabel();
	Label labelExit = g.newLabel();
	expression.load(ctx);
	g.ifZCmp(GeneratorAdapter.EQ, labelFalse);
	g.push(false);
	g.goTo(labelExit);
	g.visitLabel(labelFalse);
	g.push(true);
	g.visitLabel(labelExit);
	return Type.BOOLEAN_TYPE;
}
 
Example 4
Source File: ExpressionComparator.java    From datakernel with Apache License 2.0 4 votes vote down vote up
@Override
public Type load(Context ctx) {
	GeneratorAdapter g = ctx.getGeneratorAdapter();

	Label labelReturn = new Label();

	for (ComparablePair pair : pairs) {
		Type leftPropertyType = pair.left.load(ctx);
		Type rightPropertyType = pair.right.load(ctx);

		checkArgument(leftPropertyType.equals(rightPropertyType), "Types of compared values should match");
		if (isPrimitiveType(leftPropertyType)) {
			g.invokeStatic(wrap(leftPropertyType), new Method("compare", INT_TYPE, new Type[]{leftPropertyType, leftPropertyType}));
			g.dup();
			g.ifZCmp(NE, labelReturn);
			g.pop();
		} else if (!pair.nullable) {
			g.invokeVirtual(leftPropertyType, new Method("compareTo", INT_TYPE, new Type[]{Type.getType(Object.class)}));
			g.dup();
			g.ifZCmp(NE, labelReturn);
			g.pop();
		} else {
			VarLocal varRight = ctx.newLocal(rightPropertyType);
			varRight.store(ctx);

			VarLocal varLeft = ctx.newLocal(leftPropertyType);
			varLeft.store(ctx);

			Label continueLabel = new Label();
			Label nonNulls = new Label();
			Label leftNonNull = new Label();

			varLeft.load(ctx);
			g.ifNonNull(leftNonNull);

			varRight.load(ctx);
			g.ifNull(continueLabel);
			g.push(-1);
			g.returnValue();

			g.mark(leftNonNull);

			varRight.load(ctx);
			g.ifNonNull(nonNulls);
			g.push(1);
			g.returnValue();

			g.mark(nonNulls);

			varLeft.load(ctx);
			varRight.load(ctx);

			g.invokeVirtual(leftPropertyType, new Method("compareTo", INT_TYPE, new Type[]{Type.getType(Object.class)}));
			g.dup();
			g.ifZCmp(NE, labelReturn);
			g.pop();

			g.mark(continueLabel);
		}
	}

	g.push(0);

	g.mark(labelReturn);

	return INT_TYPE;
}
 
Example 5
Source File: ExpressionCmp.java    From datakernel with Apache License 2.0 4 votes vote down vote up
@Override
public Type load(Context ctx) {
	GeneratorAdapter g = ctx.getGeneratorAdapter();
	Label labelTrue = new Label();
	Label labelExit = new Label();

	Type leftType = left.load(ctx);
	Type rightType = right.load(ctx);
	checkArgument(Objects.equals(leftType, rightType), "Types of compared values should match");

	if (isPrimitiveType(leftType)) {
		g.ifCmp(leftType, operation.opCode, labelTrue);
	} else {
		if (operation == EQ || operation == NE) {
			g.invokeVirtual(leftType, new Method("equals", BOOLEAN_TYPE, new Type[]{Type.getType(Object.class)}));
			g.push(operation == EQ);
			g.ifCmp(BOOLEAN_TYPE, GeneratorAdapter.EQ, labelTrue);
		} else {
			g.invokeVirtual(leftType, new Method("compareTo", INT_TYPE, new Type[]{Type.getType(Object.class)}));
			if (operation == LT) {
				g.ifZCmp(GeneratorAdapter.LT, labelTrue);
			} else if (operation == GT) {
				g.ifZCmp(GeneratorAdapter.GT, labelTrue);
			} else if (operation == LE) {
				g.ifZCmp(GeneratorAdapter.LE, labelTrue);
			} else if (operation == GE) {
				g.ifZCmp(GeneratorAdapter.GE, labelTrue);
			}
		}
	}

	g.push(false);
	g.goTo(labelExit);

	g.mark(labelTrue);
	g.push(true);

	g.mark(labelExit);

	return BOOLEAN_TYPE;
}