Package org.openquark.cal.compiler.io

Examples of org.openquark.cal.compiler.io.EntryPointSpec


        try {
            GemFactory gemFactory = new GemFactory(calServices);

            SourceModel.FunctionDefn.Algebraic gemSource = positiveOutlierDetectorGemGraph(gemFactory, calServices).getCALSource();
            EntryPointSpec entryPointSpec = calServices.addNewModuleWithFunction(RUN_MODULE, gemSource);

            List<?> result;

            ////
            /// A Java java.util.List can be passed in as an argument to a CAL function that expects a
View Full Code Here


               
                //Note 2. If the input was of a type for which there was no special typed policy
                //we could use InputPolicy.makeTypedDefaultInputPolicy to create one, e.g.
                //InputPolicy.makeTypedDefaultInputPolicy(SourceModel.TypeExprDefn.TypeCons.make(CAL_Prelude.TypeConstructors.Int))

                EntryPointSpec addSpec = EntryPointSpec.make(QualifiedName.make(CAL_Prelude.MODULE_NAME, "add"), new InputPolicy[] {
                    InputPolicy.INT_INPUT_POLICY,
                    InputPolicy.DEFAULT_INPUT_POLICY
                }, OutputPolicy.DEFAULT_OUTPUT_POLICY);
               
                Object addResult = calServices.runFunction(addSpec, new Object[] { new Integer(1), new Integer(2) });
                System.out.println("Example 1 output: " + addResult.toString());
            }

            {
                //Example 2: Inferring input types
                //This example again shows how the Prelude.add function
                //can be invoked. We provide a type (Int) for the output. This will
                //allow CAL to infer the types of the inputs, so default input
                //policies can be used.
                EntryPointSpec addSpec = EntryPointSpec.make(QualifiedName.make(CAL_Prelude.MODULE_NAME, "add"), new InputPolicy[] {
                    InputPolicy.DEFAULT_INPUT_POLICY,
                    InputPolicy.DEFAULT_INPUT_POLICY
                }, OutputPolicy.INT_OUTPUT_POLICY);
               
                Object addResult = calServices.runFunction(addSpec, new Object[] { new Integer(3), new Integer(4) });
                System.out.println("Example 2 output: " + addResult.toString());
            }

            {
                //Example 3: CAL Value Output
                //This example shows the use of CAL_VALUE_OUTPUT to output a CAL value as an opaque type in Java.
                //the opaque output is then used as an input to another CAL function.
              
                //Call the allPrimes and get the resulting infinite list as an opaque CAL Value
                EntryPointSpec allPrimesSpec = EntryPointSpec.make(QualifiedName.make(CALPlatformTestModuleNames.M1, "allPrimes"), new InputPolicy[0], OutputPolicy.CAL_VALUE_OUTPUT_POLICY);

                Object allPrimesResult = calServices.runFunction(allPrimesSpec, new Object[0]);

                //Use List.Take to get 5 values from the primes list.
                //As List.take is a polymorphic function we must specify the type of the CAL input
                EntryPointSpec primesSpec = EntryPointSpec.make(QualifiedName.make(CAL_List.MODULE_NAME, "take"), new InputPolicy[] {
                    InputPolicy.DEFAULT_INPUT_POLICY,
                    InputPolicy.makeTypedCalValueInputPolicy(SourceModel.TypeExprDefn.List.make(SourceModel.TypeExprDefn.TypeCons.make(CAL_Prelude.TypeConstructors.Int)))}, OutputPolicy.DEFAULT_OUTPUT_POLICY);

                List<?> primesList = (List<?>) calServices.runFunction(primesSpec, new Object[] { new Integer(5), allPrimesResult});
View Full Code Here

        //explicit input and output policies.
       
        //allPrimesAdjunct :: Prelude.JObject;
        //allPrimesAdjunct = (Prelude.output # List.toJIterator) M1.allPrimes;           

        EntryPointSpec allPrimesEntryPointSpec =
            EntryPointSpec.make(QualifiedName.make(CALPlatformTestModuleNames.M1, "allPrimes"), null, OutputPolicy.ITERATOR_OUTPUT_POLICY);       
       
        EntryPoint allPrimesEntryPoint =
            compiler.getEntryPoint(allPrimesEntryPointSpec, CALPlatformTestModuleNames.M1, messageLogger);
       
View Full Code Here

TOP

Related Classes of org.openquark.cal.compiler.io.EntryPointSpec

Copyright © 2018 www.massapicom. 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.