Examples of MachineFunction


Examples of org.openquark.cal.machine.MachineFunction

     * @param var The name of the function to look for.
     * @return An algebraic value for the core function that is usable by the optimizer.
     */
   
    public static AlgebraicValue getCoreFunction(WorkspaceManager workspaceManager, QualifiedName var){
        MachineFunction mf = null;
        try {
            mf = workspaceManager.getMachineFunction(var);
        } catch (ProgramException e) {
            // TODO FIX THIS
            e.printStackTrace();
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

     * @param var The name of the function to look for.
     * @return An algebraic value for the core function that is usable by the optimizer.
     */
   
    public static AlgebraicValue getTestInput(WorkspaceManager workspaceManager, QualifiedName var){
        MachineFunction mf = null;
        try {
            mf = workspaceManager.getMachineFunction(var);
        } catch (ProgramException e) {
            // TODO FIX THIS
            e.printStackTrace();
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

        // 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){
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

         // Save code objects (currently only one for a supercombinator - labels may refer to offsets)
         try {
             coreFunction.setForAdjunct(codeGenerator.isForAdjunct());
             // At this point we want to package the expression form of the super combinator, along
             // with a description of the initial environment (i.e. parameters).
             MachineFunction machineFunction = getMachineFunction(coreFunction);
             getCurrentModule().addFunction (machineFunction);

             for (final StatusListener l : getStatusListeners()) {
                 l.setEntityStatus(StatusListener.SM_COMPILED, machineFunction.getName());
             }
           
         } catch (NullPointerException e) {
             // No module to copy into (or something worse)
             throw new Packager.PackagerException("No active module in which to store the core function " + coreFunction);
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

       // caused by argument strictness.
      
       // Step 1.  Set aliasOf members based on function definitions.
       Iterator<MachineFunction> functions = functionsList.iterator();
       while (functions.hasNext()) {
           MachineFunction mf = functions.next();
           // Get the name of the aliased function. (may be null)
           QualifiedName aliasOf = aliasOf (mf);
           mf.setAliasOf(aliasOf);
       }

       // Steps 2 and 3.  Do deep resolution of aliases and
       // check strictness compatability.
       functions = functionsList.iterator();
       while (functions.hasNext()) {
           MachineFunction mf = functions.next();

           // Get the name of the aliased function. (may be null)
           QualifiedName aliasOf = compatibleStrictnessWithAliasedFunction(mf);
          
           if (aliasOf != null) {
               // Follow any alias chains to the end.
               MachineFunction aliasFunction = getCurrentModule().getFunction(aliasOf);
               while (aliasFunction != null && aliasFunction.getAliasOf() != null) {
                   aliasOf = aliasFunction.getAliasOf();
                   aliasFunction = getCurrentModule().getFunction(aliasOf);
               }
   
               // The function which is being aliased may represent a literal value
               if (aliasFunction != null && aliasFunction.getLiteralValue() != null) {
                   // Set the expression of the current function to be the literal.
                   mf.setExpression(new Expression.Literal(aliasFunction.getLiteralValue()));
               } else {
                   // Mark the current function as being an alias.
                   mf.setAliasOf(aliasOf);
               }
           } else {
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

                // Left hand side of chain must be a function.
                if (node.asVar() == null) {
                    return null;
                }
               
                MachineFunction aliasFunction = getCurrentModule().getFunction(node.asVar().getName());
                if (aliasFunction == null) {
                    return null;
                }
               
                // The aliased function must have the same arity and be fully saturated.
                if (arity != aliasFunction.getArity() || arity != nodes.size()) {
                    return null;
                }
               
                // The arguments to the aliased function must consist soley of the arguments to
                // this function, in the same order.
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

        if (aliasOf == null) {
            return null;
        }
       
        // Follow any alias chains to the end.
        MachineFunction aliasFunction = getCurrentModule().getFunction(aliasOf);
        while (aliasFunction != null && aliasFunction.getAliasOf() != null) {
            aliasOf = aliasFunction.getAliasOf();
            aliasFunction = getCurrentModule().getFunction(aliasOf);
        }
       
//        System.out.println ("second stage alias " + cl.getQualifiedName() + " -> " + aliasOf);
       
        if (aliasFunction == null || aliasOf == null) {
            return null;
        } else {
            // Get the strictness of the two functions.
            boolean thisStrictness[] = mf.getParameterStrictness();
            boolean aliasStrictness[] = aliasFunction.getParameterStrictness();
           
            // If the current function is a CAF.
            if (mf.getArity() == 0) {
                if (aliasFunction.getArity() == 0) {
                    // Check for a CAF which is defined as a zero arity foreign function.
                    // This is not an alias as a CAF has different behaviour than
                    // a zero arity foreign function.
                    if (aliasFunction.isForeignFunction()) {
                        return null;
                    }
                   
                    // If the aliasFunction is a CAF defined as a literal value
                    // set the current function to be defined as a literal.
                    Expression expressionForm = aliasFunction.getExpressionForm();
                    if (expressionForm != null && expressionForm.asLiteral() != null) {
                        mf.setExpression(expressionForm);
                        return null;
                    }
                }
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

                                formalParameters, argStrictness, argTypes, resultType,
                                timeStamp);

                        newCF.setExpression(newFunctionBody);

                        MachineFunction mf = getMachineFunction(newCF);
                        moreFunctions.add(mf);
                       
                        // in case functions in the same module use the definition.
                        inlinableFunctions.put(newCF.getName(), newCF);
                    }
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

        }
       
        Iterator<MachineFunction> functions = functionsList.iterator();
        Map<String, Expression> nameToExpressionMap = new HashMap<String, Expression>();
        while (functions.hasNext()) {
            MachineFunction cl = functions.next ();
            nameToExpressionMap.put (cl.getName(), cl.getExpressionForm());
        }
       
        // Determine the strongly connected components and put the information into the code labels.
        List<Set<String>> sets = ExpressionAnalyzer.determineStronglyConnectedComponents(m.getName(), nameToExpressionMap);
        for (int i = 0; i < sets.size(); ++i) {
            Set<String> set = sets.get(i);
            Iterator<String> items = set.iterator();
            while (items.hasNext()) {
                String name = items.next();
                MachineFunctionImpl mf = (MachineFunctionImpl)m.getFunction(name);
                if (mf != null) {
                    mf.setStronglyConnectedComponents(set);
                }
            }
        }

        // Now that we've determined the closely connected components we can use
        // an ExpressionAnalyzer to do optimizing transformations to the expression.
        functions = functionsList.iterator();
        while (functions.hasNext()) {
           
            MachineFunction cl = functions.next ();
            ExpressionAnalyzer ea = new ExpressionAnalyzer (m.getModuleTypeInfo(), cl);
           
            cl.setExpression(ea.transformExpression(cl.getExpressionForm()));
            if (ea.getHadUnsafeCoerce()){
                cl.setHadUnsafeCoerce();
            }
            cl.setIsTailRecursive(ExpressionAnalyzer.isTailRecursive(cl.getExpressionForm()));
        }       
       
       
        // At this point we want to figure out whether any functions are
        // simply an alias for another function and put the name of the aliased function
        //in the MachineFunction.
        determineFunctionAliases(functionsList);
       
        functions = functionsList.iterator();
        while (functions.hasNext ()) {
            MachineFunction mf = functions.next ();
            ExpressionAnalyzer.antiAlias (mf, m, logger);
            mf.setOptimized();
        }
       
    }
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

        if (function == null ||
            function.length() == 0) {
            return;
        }
       
        MachineFunction cl;
        try {
            cl = getWorkspaceManager().getMachineFunction(EntryPointImpl.makeEntryPointName(function));
        } catch (Exception e) {
            logInfo(function + " is not a valid function name.");
            return;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.