}
// Get supercombinator defined at the current target and its name
ModuleTypeInfo currentModuleTypeInfo = getWorkspaceManager().getWorkspace().getMetaModule(getTargetModule()).getTypeInfo();
AdjunctSource scDef = target.getTargetDef(null, currentModuleTypeInfo);
CompilerMessageLogger logger = new MessageLogger ();
TypeExpr targetTypeExpr = getTypeChecker().checkFunction(scDef, targetModule, logger);
if (targetTypeExpr == null) {
VALUENODE_LOGGER.log(Level.SEVERE, "Error determining gem execution type. Text: \n" + scDef);
throw new ProgramCompileException(CompilerMessage.Severity.ERROR, logger.getFirstError());
}
// Determine the overall output TypeExpr of the target.
int numArgs = inputPolicies.length;
TypeExpr[] targetTypePieces = targetTypeExpr.getTypePieces(numArgs);
TypeExpr outputTypeExpr;
try {
TypeExpr[] specializedTargetTypePieces =
TypeExpr.patternMatchPieces(argTypes, targetTypePieces, currentModuleTypeInfo);
outputTypeExpr = specializedTargetTypePieces[numArgs];
} catch (TypeException e) {
// What to do? You really don't want to be throwing an uncaught exception here.
VALUENODE_LOGGER.log(Level.WARNING, "Error determining gem execution output type.");
e.printStackTrace();
outputTypeExpr = targetTypePieces[numArgs];
}
TypeExpr declaredType = outputTypeExpr;
for (int i = numArgs - 1; i >= 0 ; i--) {
declaredType = TypeExpr.makeFunType(argTypes[i], declaredType);
}
// Update the scDef with the type declaration.
scDef = target.getTargetDef(declaredType, currentModuleTypeInfo);
outputValueNode = valueNodeBuilderHelper.getValueNodeForTypeExpr(outputTypeExpr);
if (outputValueNode == null) {
// Unable to create an output value node for type: {declaredType}
throw new ProgramCompileException(CompilerMessage.Severity.ERROR,
new CompilerMessage(new MessageKind.Error.UnableToCreateOutputValueNode(declaredType.toString())));
}
OutputPolicy outputPolicy = null;
outputPolicy = outputValueNode.getOutputPolicy();
if (outputPolicy == null) {
// Unable to retrieve an output policy for type: {declaredType}
throw new ProgramCompileException(CompilerMessage.Severity.ERROR,
new CompilerMessage(new MessageKind.Error.UnableToRetrieveAnOutputPolicy(declaredType.toString())));
}
if (getShowConsoleInfo()) {
System.out.println("Executing:\n" + scDef);
}
// Compile the definition, indicating that this is an adjunct
QualifiedName targetName = QualifiedName.make(getTargetModule(), getTarget().getTargetName(currentModuleTypeInfo));
entryPoint = getWorkspaceManager().getCompiler().getEntryPoint(scDef, EntryPointSpec.make(targetName, inputPolicies, outputPolicy), targetName.getModuleName(), logger);
if (entryPoint == null) {
throw new ProgramCompileException(CompilerMessage.Severity.ERROR, logger.getFirstError());
}
}