public static BytecodeExpression loadConstant(CallSiteBinder callSiteBinder, Object constant, Class<?> type) { Binding binding = callSiteBinder.bind(MethodHandles.constant(type, constant)); return loadConstant(binding); }
newInstance( VarArgsToArrayAdapterState.class, loadConstant(callSiteBinder, userStateFactory, MethodHandle.class).invoke("invokeExact", Object.class), newArray(type(javaArrayType), argsLength).cast(Object.class)).ret()); loadConstant(callSiteBinder, function, MethodHandle.class) .invoke("invokeExact", returnType, userState, args) .ret());
loadConstant(callSiteBinder, function, Function.class) .invoke("apply", Object.class, map.cast(Object.class)) .cast(returnType)
.comment("%s.%s(output, %s)", type.getTypeSignature(), methodName, valueJavaType.getSimpleName()) .putVariable(tempValue) .append(loadConstant(callSiteBinder.bind(type, Type.class))) .getVariable(outputBlockVariable) .getVariable(tempValue)
.getVariable(value) .comment("set") .append(loadConstant(constant))
.setDescription("constant " + constant.getType()) .comment(constant.toString()) .append(loadConstant(binding));
private void generateCombineMethod(ClassDefinition definition, CallSiteBinder binder, MethodHandle compareMethod, Type keyType, Type valueType, Class<?> stateClass) { Parameter state = arg("state", stateClass); Parameter otherState = arg("otherState", stateClass); MethodDefinition method = definition.declareMethod(a(PUBLIC, STATIC), "combine", type(void.class), state, otherState); Class<?> keyJavaType = keyType.getJavaType(); BytecodeBlock ifBlock = new BytecodeBlock() .append(state.invoke("setFirst", void.class, otherState.invoke("getFirst", keyJavaType))) .append(state.invoke("setFirstNull", void.class, otherState.invoke("isFirstNull", boolean.class))) .append(state.invoke("setSecondNull", void.class, otherState.invoke("isSecondNull", boolean.class))); if (valueType.getJavaType().isPrimitive()) { ifBlock.append(state.invoke("setSecond", void.class, otherState.invoke("getSecond", valueType.getJavaType()))); } else { ifBlock.append(new BytecodeBlock() .append(state.invoke("setSecondBlock", void.class, otherState.invoke("getSecondBlock", Block.class))) .append(state.invoke("setSecondPosition", void.class, otherState.invoke("getSecondPosition", int.class)))); } method.getBody() .append(new IfStatement() .condition(or( state.invoke("isFirstNull", boolean.class), and( not(otherState.invoke("isFirstNull", boolean.class)), loadConstant(binder, compareMethod, MethodHandle.class).invoke("invokeExact", boolean.class, otherState.invoke("getFirst", keyJavaType), state.invoke("getFirst", keyJavaType))))) .ifTrue(ifBlock)) .ret(); }
and( not(key.invoke("isNull", boolean.class, position)), loadConstant(binder, compareMethod, MethodHandle.class).invoke("invokeExact", boolean.class, keySqlType.getValue(key, position), state.invoke("getFirst", keyType.getJavaType()))))) .ifTrue(ifBlock)) .ret();
public static BytecodeExpression loadConstant(CallSiteBinder callSiteBinder, Object constant, Class<?> type) { Binding binding = callSiteBinder.bind(MethodHandles.constant(type, constant)); return loadConstant(binding); }
@Override public BytecodeNode visitInputReference(InputReferenceExpression node, Scope scope) { int field = node.getField(); Type type = node.getType(); Variable block = scope.getVariable("block_" + field); Class<?> javaType = type.getJavaType(); if (!javaType.isPrimitive() && javaType != Slice.class) { javaType = Object.class; } IfStatement ifStatement = new IfStatement(); ifStatement.condition() .setDescription(format("block_%d.get%s()", field, type)) .append(block) .getVariable(positionVariable) .invokeInterface(Block.class, "isNull", boolean.class, int.class); ifStatement.ifTrue() .putVariable(wasNullVariable, true) .pushJavaDefault(javaType); String methodName = "get" + Primitives.wrap(javaType).getSimpleName(); ifStatement.ifFalse() .append(loadConstant(callSiteBinder.bind(type, Type.class))) .append(block) .getVariable(positionVariable) .invokeInterface(Type.class, methodName, javaType, Block.class, int.class); return ifStatement; }
.dup(javaType) .comment("set") .append(loadConstant(constant))
BytecodeExpression value = loadConstant(callSiteBinder, constantExpression.getValue(), Object.class); body.append(outputBlock.set(invokeStatic(RunLengthEncodedBlock.class, "create", Block.class, type, value, cardinality)));
.putVariable(tempValue) .putVariable(tempOutput) .append(loadConstant(callSiteBinder.bind(type, Type.class))) .getVariable(tempOutput) .getVariable(tempValue)
.setDescription("constant " + constant.getType()) .comment(constant.toString()) .append(loadConstant(binding));