private void emitStringTrieSwitch(final String[] keys, final StringSwitchCallback callback) throws Exception { final Label defaultLabel = defineLabel(); final Label breakTarget = defineLabel(); final Map<Integer, List<String>> buckets = getStringSwitchBuckets( Arrays.asList(keys), new Func1<String, Integer>() { dup(); call(StringLengthMethod); emitSwitch( intKeys, new SwitchCallback() { markLabel(defaultLabel); pop(); callback.emitDefault(breakTarget); markLabel(breakTarget);
final LocalBuilder sourceLocal = declareLocal(sourceType); final LocalBuilder targetLocal = declareLocal(targetType); final Label ifNull = defineLabel(); final Label end = defineLabel(); emitStore(sourceLocal); emitStore(targetLocal); emitLoad(sourceLocal); emit(OpCode.IFNULL, ifNull); emitLoad(sourceLocal); emitUnbox(sourceType); emitConversion(unboxedSourceType, unboxedTargetType); emitBox(targetType); emitStore(targetLocal); emitGoto(end); markLabel(ifNull); emitNull(); emitStore(targetLocal); markLabel(end); emitLoad(targetLocal);
protected void emitLoadConstant(final int token) { if (token < MIN_BYTE || token > MAX_BYTE) { emit(OpCode.LDC_W); emitShortOperand(token); } else { emit(OpCode.LDC); emitByteOperand(token); } }
public void emit(final OpCode opCode, final short arg) { emit(opCode); emitShortOperand(arg); }
public void emit(final OpCode opCode, final long arg) { emit(opCode); emitLongOperand(arg); }
emitBoolean((Boolean)value); return true; emitByte((Byte)value); return true; emitShort((Short)value); return true; emitInteger((Integer)value); return true; emitLong((Long)value); return true; emitCharacter((Character)value); return true; emitFloat((Float)value); return true; emitDouble((Double)value); return true; emitString((String)value); return true; getField(unboxedType.getField(value.toString())); return true;
final Label breakTarget = defineLabel(); final Label defaultLabel = defineLabel(); final int start = offset(); final SwitchOptions resolvedOptions = resolveSwitchOptions(keys, options); labels[key - minimum] = defineLabel(); emit(OpCode.TABLESWITCH); for (int i = 0, padding = (4 - offset() % 4) % 4; i < padding; i++) { emitByteOperand(0); addFixup(defaultLabel, start, offset(), 4); emitIntOperand(0); emitIntOperand(minimum); emitIntOperand(maximum); addFixup(label, start, offset(), 4); emitIntOperand(0); markLabel(label); callback.emitCase(i + minimum, breakTarget); labels[i] = defineLabel(); emit(OpCode.LOOKUPSWITCH); for (int i = 0, padding = (4 - offset() % 4) % 4; i < padding; i++) {
public void emitConstantArray(final Object array) { VerifyArgument.notNull(array, "array"); final int length = Array.getLength(array); final Type<?> arrayType = Type.getType(array); final Type<?> elementType = arrayType.getElementType(); emitInteger(length); emitNewArray(arrayType); for (int i = 0; i < length; i++) { dup(); emitInteger(i); emitConstant(Array.get(array, i)); emitStoreElement(elementType); } }
code.emitThis(); final Type<?> t = override.parameterBuilders[i].getParameterType().getErasedType(); code.emitLoadArgument(i); code.emitConversion(s, t); code.call(override); code.emitConversion(override.getReturnType().getErasedType(), returnType); code.emitReturn(returnType);
@Override public void emitCase(final int key, final Label ignore) throws Exception { final List<String> bucket = buckets.get(key); Label next = null; for (Iterator<String> it = bucket.iterator(); it.hasNext(); ) { final String string = it.next(); if (next != null) { markLabel(next); } if (it.hasNext()) { dup(); } emitString(string); call(ObjectEqualsMethod); if (it.hasNext()) { emit(OpCode.IFEQ, next = defineLabel()); pop(); } else { emit(OpCode.IFEQ, defaultLabel); } callback.emitCase(string, breakTarget); } }
final Map<Integer, List<String>> buckets = getStringSwitchBuckets( bucket, new Func1<String, Integer> dup(); emitInteger(index); call(StringCharAtMethod); emitSwitch( intKeys, new SwitchCallback() {
public void beginFinallyBlock() { if (_currentExceptionStackCount == 0) { throw Error.notInExceptionBlock(); } final __ExceptionInfo current = _currentExceptionStack[_currentExceptionStackCount - 1]; final int state = current.getCurrentState(); int catchEndAddress = 0; if (state != __ExceptionInfo.State_Try) { catchEndAddress = offset(); } final Label finallyEndLabel = defineLabel(); current.setFinallyEndLabel(finallyEndLabel); final Label endLabel = current.getEndLabel(); markLabel(endLabel); // // Insert a branch to jump past the finally block. With the // JVM, the finally block contents are inlined in the try and // catch blocks. What will actually be emitted next is the // finally block as executed only when an unhandled exception // occurs, so we want the preceding try/catch block past the // unhandled exception code path (again, as they've already // run the inlined finally block). // emit(OpCode.GOTO, current.getFinallyEndLabel()); if (catchEndAddress == 0) { catchEndAddress = offset(); } current.markFinallyAddress(offset(), catchEndAddress); }
private void emitUnboxedToBoxedConversion(final Type<?> sourceType, final Type<?> targetType) { assert sourceType.isPrimitive() && TypeUtils.isAutoUnboxed(targetType) : "sourceType.isPrimitive() && TypeUtils.isAutoUnboxed(targetType)"; final Type<?> unboxedTargetType = TypeUtils.getUnderlyingPrimitive(targetType); final LocalBuilder targetLocal = declareLocal(targetType); emitConversion(sourceType, unboxedTargetType); emitBox(targetType); }
private void emitBoxedToUnboxedNumericConversion(final Type<?> sourceType, final Type<?> targetType) { assert TypeUtils.isAutoUnboxed(sourceType) && !TypeUtils.isAutoUnboxed(targetType) : "TypeUtils.isAutoUnboxed(sourceType) && !TypeUtils.isAutoUnboxed(targetType)"; final MethodInfo coercionMethod = TypeUtils.getCoercionMethod(sourceType, targetType); if (coercionMethod != null) { call(coercionMethod); } else { final Type<?> unboxedSourceType = TypeUtils.getUnderlyingPrimitive(sourceType); emitUnbox(sourceType); emitConversion(unboxedSourceType, targetType); } }
public Label beginExceptionBlock() { if (_exceptions == null) { _exceptions = new __ExceptionInfo[DefaultExceptionArraySize]; } if (_currentExceptionStack == null) { _currentExceptionStack = new __ExceptionInfo[DefaultExceptionArraySize]; } if (_exceptionCount >= _exceptions.length) { _exceptions = enlargeArray(_exceptions); } if (_currentExceptionStackCount >= _currentExceptionStack.length) { _currentExceptionStack = enlargeArray(_currentExceptionStack); } final Label endLabel = defineLabel(); final __ExceptionInfo exceptionInfo = new __ExceptionInfo(offset(), endLabel); _exceptions[_exceptionCount++] = exceptionInfo; _currentExceptionStack[_currentExceptionStackCount++] = exceptionInfo; return endLabel; }
public void emitNew(final Type<?> type) { VerifyArgument.notNull(type, "type"); if (type.containsGenericParameters()) { throw Error.cannotInstantiateUnboundGenericType(type); } if (type.isPrimitive()) { emitDefaultValue(type); return; } emit(OpCode.NEW, type); }
_body = code.bakeByteArray(); exceptions = code.getExceptions();
public void emit(final OpCode opCode, final byte arg) { emit(opCode); emitByteOperand(arg); }