Variable valueVariable = scope.createTempVariable(valueType); block.append(context.generate(captureExpression, Optional.empty())); block.append(boxPrimitiveIfNecessary(scope, valueType)); block.putVariable(valueVariable); block.append(wasNull.set(constantFalse()));
case USE_BOXED_TYPE: block.append(arguments.get(realParameterIndex)); block.append(boxPrimitiveIfNecessary(scope, type)); block.append(scope.getVariable("wasNull").set(constantFalse())); break;
private static CompiledLambda defineLambdaMethod( RowExpressionCompiler innerExpressionCompiler, ClassDefinition classDefinition, String methodName, List<Parameter> inputParameters, LambdaDefinitionExpression lambda) { checkCondition(inputParameters.size() <= 254, NOT_SUPPORTED, "Too many arguments for lambda expression"); Class<?> returnType = Primitives.wrap(lambda.getBody().getType().getJavaType()); MethodDefinition method = classDefinition.declareMethod(a(PUBLIC), methodName, type(returnType), inputParameters); Scope scope = method.getScope(); Variable wasNull = scope.declareVariable(boolean.class, "wasNull"); BytecodeNode compiledBody = innerExpressionCompiler.compile(lambda.getBody(), scope, Optional.empty()); method.getBody() .putVariable(wasNull, false) .append(compiledBody) .append(boxPrimitiveIfNecessary(scope, returnType)) .ret(returnType); Handle lambdaAsmHandle = new Handle( Opcodes.H_INVOKEVIRTUAL, method.getThis().getType().getClassName(), method.getName(), method.getMethodDescriptor(), false); return new CompiledLambda( lambdaAsmHandle, method.getReturnType(), method.getParameterTypes()); }
block.append(boxPrimitiveIfNecessary(scope, type)); block.append(scope.getVariable("wasNull").set(constantFalse()));
public static MethodDefinition defineTryMethod( BytecodeExpressionVisitor innerExpressionVisitor, ClassDefinition classDefinition, String methodName, List<Parameter> inputParameters, Class<?> returnType, RowExpression innerRowExpression, CallSiteBinder callSiteBinder) { MethodDefinition method = classDefinition.declareMethod(a(PUBLIC), methodName, type(returnType), inputParameters); Scope calleeMethodScope = method.getScope(); BytecodeNode innerExpression = innerRowExpression.accept(innerExpressionVisitor, calleeMethodScope); MethodType exceptionHandlerType = methodType(returnType, PrestoException.class); MethodHandle exceptionHandler = methodHandle(TryCodeGenerator.class, EXCEPTION_HANDLER_NAME, PrestoException.class).asType(exceptionHandlerType); Binding binding = callSiteBinder.bind(exceptionHandler); method.comment("Try projection: %s", innerRowExpression.toString()); method.getBody() .append(new TryCatch( new BytecodeBlock() .append(innerExpression) .append(boxPrimitiveIfNecessary(calleeMethodScope, returnType)), new BytecodeBlock() .append(invoke(binding, EXCEPTION_HANDLER_NAME)), ParameterizedType.type(PrestoException.class))) .ret(returnType); return method; }