Source:
private Class<?> generate(List<Class<?>> javaTypes, Type type, MethodHandle compareMethod) { Failures.checkCondition( javaTypes.size() <= 127, StandardErrorCode.NOT_SUPPORTED, "Too many arguments for function call %s()", getSignature().getName()); String javaTypeName = javaTypes.stream() .map(Class::getSimpleName) .collect(joining()); ClassDefinition definition = new ClassDefinition( a(PUBLIC, FINAL), CompilerUtils.makeClassName(javaTypeName + "$" + getSignature().getName()), type(Object.class)); definition.declareDefaultConstructor(a(PRIVATE)); List<Parameter> parameters = IntStream.range(0, javaTypes.size()) .mapToObj(i -> arg("arg" + i, javaTypes.get(i))) .collect(toImmutableList()); MethodDefinition method = definition.declareMethod( a(PUBLIC, STATIC), getSignature().getName(), type(javaTypes.get(0)), parameters); Scope scope = method.getScope(); BytecodeBlock body = method.getBody(); CallSiteBinder binder = new CallSiteBinder(); if (type.getTypeSignature().getBase().equals(StandardTypes.DOUBLE)) { for (Parameter parameter : parameters) { body.append(parameter); body.append(invoke(binder.bind(CHECK_NOT_NAN.bindTo(getSignature().getName())), "checkNotNaN")); } } Variable value = scope.declareVariable(javaTypes.get(0), "value"); body.append(value.set(parameters.get(0))); for (int i = 1; i < javaTypes.size(); i++) { body.append(new IfStatement() .condition(new BytecodeBlock() .append(parameters.get(i)) .append(value) .append(invoke(binder.bind(compareMethod), "compare"))) .ifTrue(value.set(parameters.get(i)))); } body.append(value.ret()); return defineClass(definition, Object.class, binder.getBindings(), new DynamicClassLoader(getClass().getClassLoader())); }

Target:
private Class<?> generate(List<Class<?>> javaTypes, Type type, MethodHandle compareMethod) { checkCondition(javaTypes.size() <= 127, NOT_SUPPORTED, "Too many arguments for function call %s()", getSignature().getName()); String javaTypeName = javaTypes.stream() .map(Class::getSimpleName) .collect(joining()); ClassDefinition definition = new ClassDefinition( a(PUBLIC, FINAL), CompilerUtils.makeClassName(javaTypeName + "$" + getSignature().getName()), type(Object.class)); definition.declareDefaultConstructor(a(PRIVATE)); List<Parameter> parameters = IntStream.range(0, javaTypes.size()) .mapToObj(i -> arg("arg" + i, javaTypes.get(i))) .collect(toImmutableList()); MethodDefinition method = definition.declareMethod( a(PUBLIC, STATIC), getSignature().getName(), type(javaTypes.get(0)), parameters); Scope scope = method.getScope(); BytecodeBlock body = method.getBody(); CallSiteBinder binder = new CallSiteBinder(); if (type.getTypeSignature().getBase().equals(StandardTypes.DOUBLE)) { for (Parameter parameter : parameters) { body.append(parameter); body.append(invoke(binder.bind(CHECK_NOT_NAN.bindTo(getSignature().getName())), "checkNotNaN")); } } Variable value = scope.declareVariable(javaTypes.get(0), "value"); body.append(value.set(parameters.get(0))); for (int i = 1; i < javaTypes.size(); i++) { body.append(new IfStatement() .condition(new BytecodeBlock() .append(parameters.get(i)) .append(value) .append(invoke(binder.bind(compareMethod), "compare"))) .ifTrue(value.set(parameters.get(i)))); } body.append(value.ret()); return defineClass(definition, Object.class, binder.getBindings(), new DynamicClassLoader(getClass().getClassLoader())); }