// initialize name to type map
while (varsUsed.size() > 0) {
QualifiedName var = (QualifiedName) varsUsed.removeFirst();
CoreFunction iBody = null;
// Look for the function the the previously compiled modules.
MachineFunction iMF = program == null ? workspace.getMachineFunction(var) : program.getCodeLabel(var);
if (iMF != null){
iBody = ((MachineFunctionImpl)iMF).getCoreFunction();
}
if (iBody == null){
// Look for the function in the module currently being compiled.
iBody = inlinableFunctions.get(var);
}
// if iBody is still null then the symbol found was perhaps an argument and not a function name.
if (iBody != null) {
if (
iBody.isCALFunction() &&
!iBody.getHadUnsafeCoerce() &&
// iBody.getFormalParameters().length > 0 &&
// if the function calls itself don't include itself in the helper functions
// since we are optimizing that function already.
iBody.getName() != name &&
iBody.getExpression() != null){
getCALTypes(iBody, nameToTypeExpr, alreadyGotTypes);
AlgebraicValue coreFunction = OptimizerHelper.getAlgebraicValue(iBody);
if (coreFunction == null){
continue;
}
if (iBody.getName().getQualifiedName().startsWith("$dict")){
continue;
}
/*
* What I really want to do is not use functions that call unsafe coerce in the body
* this is just temporary so I can get some timings
*/
if (iBody.getName().getQualifiedName().equals(CAL_Array.Functions.subscript.getQualifiedName())){
continue;
}
helperFunctions.addFirst(coreFunction);
// add the functions used by this body to the
// inlined list iff the function is defined
// in this module since the functions in this
// module are not optimized yet. The hard coded
// names are here because the optimizer currently
// does not optimize these functions.
if (iBody.getName().getModuleName().equals(name.getModuleName()) ||
iBody.getName().getModuleName().equals(CAL_Prelude.MODULE_NAME) ||
iBody.getName().getModuleName().equals(CAL_List.MODULE_NAME) ||
iBody.getName().getModuleName().equals(CAL_String.MODULE_NAME) ||
iBody.getName().getModuleName().equals(CAL_Dynamic.MODULE_NAME) ||
iBody.getName().getModuleName().equals(CAL_Debug.MODULE_NAME)
){
Set<Object> moreVars = variables(iBody.getExpression());
for (final Object mv : moreVars) {
if (varsDone.contains(mv)) {
continue; // already done
} else {
varsDone.add(mv);
varsUsed.add(mv);
}
}
}
else{
{
// Add type information for any variables used by this function.
Set<Object> moreVars = variables(iBody.getExpression());
for (final Object object : moreVars) {
QualifiedName mv = (QualifiedName) object;
if (varsDone.contains(mv) || varsUsed.contains(mv)) {
continue; // already done or is going to be done
} else {
CoreFunction mvBody = null;
// Look for the function the the previously compiled modules.
MachineFunction mvMF = program == null ? workspace.getMachineFunction(mv) : program.getCodeLabel(mv);
if (mvMF != null){
mvBody = ((MachineFunctionImpl)mvMF).getCoreFunction();
}
if (mvBody == null){