Examples of MachineFunction


Examples of org.openquark.cal.machine.MachineFunction

        if (!entryPoint.getQualifiedName().equals(idName)) {
           
            LECCModule startModule =
                (LECCModule) program.getModule(idName.getModuleName());
           
            MachineFunction mf = startModule.getFunction(idName);
            idFunction = getInstanceOfGeneratedClass(mf);
        }
       
        RTValue startPoint = getInstanceOfGeneratedClass(entryPoint);
       
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

     * @param functionName
     * @return the MachineFunction instance for the named function.  Null if it doesn't exist.    
     */
    @Override
    public MachineFunction getFunction (String functionName) {
        MachineFunction mf = super.getFunction(functionName);
       
        // Check to see if the function is a lifted let variable function.
        if (mf == null) {
            mf = liftedFunctionMap.get(functionName);
        }
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

     * @param functionName - the qualified name of a function
     * @return the MachineFunction instance for the named function.  Null if it doesn't exist.
     */
    @Override
    public MachineFunction getFunction (QualifiedName functionName) {
        MachineFunction mf = super.getFunction(functionName);
       
        // Check to see if the function is a lifted let variable function.
        if (mf == null && functionName.getModuleName().equals(getName())) {
            mf = liftedFunctionMap.get(functionName.getUnqualifiedName());
        }
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

     * be passed to the appropriate module..
     * @param functionName
     * @return FunctionGroupInfo if successful, null otherwise.
     */
    FunctionGroupInfo getFunctionGroupInfo (QualifiedName functionName) {
        MachineFunction mf = getFunction(functionName);
        if (mf != null) {
            return getFunctionGroupInfo(mf);
        }
       
        if (functionName.getModuleName().equals(getName())) {
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

                    }
                } else {
                    List<MachineFunction> machineFunctions = new ArrayList<MachineFunction>();
                    Set<String> connectedComponents = mf.getStronglyConnectedComponents();
                    for (final String functionName : connectedComponents) {
                        MachineFunction mf2 = getFunction(functionName);
                        machineFunctions.add(mf2);
                    }
                   
                    fgi = new LECCModule.FunctionGroupInfo(this, machineFunctions);
                    for (final MachineFunction mf2 : machineFunctions) {                      
                        functionNameToFunctionGroup.put(mf2.getName(), fgi);
                    }
                }
            }
           
            return fgi;
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

        Collection<MachineFunction> getLiftedLetVarDefFunctions () {
            return Collections.unmodifiableCollection(liftedLetVarMachineFunctions.values());
        }
       
        MachineFunction getMachineFunction (String name) {
            MachineFunction mf =  machineFunctions.get(name);
            if (mf == null) {
                mf = liftedLetVarMachineFunctions.get(name);
            }
            return mf;
        }
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

        //
        // {EntryPointClass's instance}
        //     .apply(Input_String_List.$instance.apply(new RTData.CAL_Opaque(args))
        //     .evaluate(executionContext);
        //
        final MachineFunction entryPointMachineFunction = module.getFunction(entryPointName);
       
        final MachineFunction inputStringListMachineFunction = module.getFunction(CAL_Prelude_internal.Functions.inputStringList);
       
        final JavaExpression runExpr =
            makeEvaluateInvocationExpr(
                makeApplyInvocationExpr(
                    getInstanceOfGeneratedClassJavaExpression(entryPointMachineFunction, module, executionContextLocalVar),
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

        /// Build up the chain of .apply(...) calls, with each argument marshalled properly
        /// We use the multi-argument apply() variants as much as possible
        /// Then build up the evaluation of the application chain.
        //
       
        final MachineFunction functionalAgentMachineFunction = module.getFunction(functionalAgent.getName());
       
        final JavaExpression executionContextArg = new JavaExpression.CastExpression(
            JavaTypeNames.RTEXECUTION_CONTEXT,
            new JavaExpression.MethodVariable(executionContextArgName));
       
        final List<JavaExpression> marshalledArgs = new ArrayList<JavaExpression>();
        for (int i = 0; i < nFunctionalAgentArgs; i++) {
            marshalledArgs.add(makeRTValueMarshallingExpr(
                argTypes.get(i), new JavaExpression.MethodVariable(methodArgNames.get(i))));
        }
       
        final JavaExpression resultExpr;
        final boolean isLiteralResult;
       
        // Special handling for literal value is required, because it may represent either an actual literal value
        // or an enum data cons, or an alias to an enum data cons
        final Object literalValue = functionalAgentMachineFunction.getLiteralValue();
        if (literalValue != null) {
           
            final Class<?> unboxedLiteralType = supportedLiteralTypesBoxedToUnboxedClassMap.get(literalValue.getClass());
            if (unboxedLiteralType == null) {
                throw new IllegalStateException("Unsupported literal type in machine function: " + literalValue.getClass());
            }
           
            isLiteralResult = true;
           
            if (returnType.getExposedTypeName().equals(JavaTypeName.CAL_VALUE)) {
                // an alias of a data constructor, which should be in an enumeration algebraic type
                // so we just marshall the literal as the opaque representation of the enum value
                if (unboxedLiteralType != int.class) {
                    throw new IllegalStateException("Unboxed literal type " + unboxedLiteralType + " is not the primitive type int.");
                }
               
                if (!LECCMachineConfiguration.TREAT_ENUMS_AS_INTS) {
                    throw new IllegalStateException("Enums are not treated as ints, but there is a MachineFunction with a literal value whose return type is CalValue");
                }
               
                resultExpr = makeRTValueMarshallingExpr(ClassTypeInfo.make(unboxedLiteralType), JavaExpression.LiteralWrapper.make(literalValue));
               
            } else {
                // not an aliased data constructor
                if (!returnType.getExposedTypeName().equals(JavaTypeName.make(unboxedLiteralType))) {
                    throw new IllegalStateException("Unboxed literal type " + unboxedLiteralType + " does not match return type " + returnType.getExposedTypeName());
                }

                // emit a literal value directly
                resultExpr = JavaExpression.LiteralWrapper.make(literalValue);
            }
           
        } else if (functionalAgentMachineFunction.isDataConstructor() && isEnumDataConsRepresentedAsPrimitiveInt((DataConstructor)functionalAgent)) {
            // ***Optional optimization***
            // a data constructor in an enumeration algebraic type
            // so we just marshall the literal as the opaque representation of the enum value
           
            if (!returnType.getExposedTypeName().equals(JavaTypeName.CAL_VALUE)) {
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

            entryPointSCName = mf.getQualifiedName();
        }
   
        final LECCModule startModule = (LECCModule)module.findModule(entryPointSCName.getModuleName());
   
        final MachineFunction actualMachineFunction = startModule.getFunction(entryPointSCName);
   
        // Munge the qualified name into a class name.
        // Get local name and capitalised local name
        if (actualMachineFunction.isDataConstructor()) {
   
            // this is a DataConstructor
            final String className = CALToJavaNames.createFullClassNameFromDC(entryPointSCName, startModule);
           
            final DataConstructor dc = startModule.getModuleTypeInfo().getDataConstructor(entryPointSCName.getUnqualifiedName());
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

            return null;
        }

        // Try to collect information about the called function.
        // This is used to decide how to encode the function call.
        MachineFunction mf = module.getFunction(var.getName());
        if (mf == null) {
            return null;
        }

        // Only functions with an unboxable return type implement an
        // fUnboxed method.
        if (!SCJavaDefn.canTypeBeUnboxed(mf.getResultType())) {
            return null;
        }

        // We only generate fUnboxed methods under the same conditions we generate the fNL and fNS methods.
        boolean generateFnMethods = mf.getArity() > 0
        && (mf.getArity() <= LECCMachineConfiguration.OPTIMIZED_APP_CHAIN_LENGTH
                || mf.isTailRecursive() || hasStrictUnboxableArguments(mf));

        if (!generateFnMethods) {
            return null;
        }

        // It must be a fully saturated application.
        if (mf.getArity() != chain.length -1 || mf.getArity() == 0) {
            return null;
        }

        // We don't 'unbox' our internal type.
        JavaTypeName calledReturnType = SCJavaDefn.typeExprToTypeName(mf.getResultType());
        if (calledReturnType.equals(JavaTypeNames.RTVALUE) ||
            calledReturnType.equals(JavaTypeName.CAL_VALUE)) {
            return null;
        }

        // If the primitiveness of the called function result type is not the same
        // as the primitiveness of the desired unboxed type we can't do a direct call.
        verifyUnboxType(unboxedType, calledReturnType);

        //  Get information about the arguments of the called function.
        boolean[] calledArgStrictness = mf.getParameterStrictness();
        TypeExpr[] calledArgTypes = mf.getParameterTypes();
        int calledArity = mf.getArity();

        if (!canCallDirectlyOnJavaStack (chain[0].asVar(), calledArgTypes, scheme)) {
            return null;
        }
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.