Package org.openquark.cal.services

Examples of org.openquark.cal.services.BasicCALServices


     * Tests the source model debugging code in the CALCompiler class by compiling the workspace
     * with the debugging code turned on, and running  CAL_Platform_TestSuite.testModule.
     */
    public void testSourceModelDebuggingCode() throws GemCompilationException, CALExecutorException {
       
        BasicCALServices  privateCopyLeccServices = CALServicesTestUtilities.makeUnsharedUnitTestCALServices(
            MachineType.LECC,
            "org.openquark.cal.test.workspace.CALCompiler_DeepTest.testSourceModelDebuggingCode",
            "ice.default.cws",
            null, "CALCompiler_DeepTest.testSourceModelDebuggingCode", false);
       
        try {
            ((EntryPointGenerator)privateCopyLeccServices.getWorkspaceManager().getCompiler()).setForceCodeRegen(true);       
           
            // Turn on the debugging flag in the compiler, so that each module being compiled will
            // go through a set of semantics-preserving text-to-source-model-to-text transformations
            CALCompiler.setInUnitTestDebugSourceModelMode(true);
           
            MessageLogger logger = new MessageLogger();
            privateCopyLeccServices.compileWorkspace(null, logger);
           
            if (logger.getNErrors() > 0) {
                String message = "Compilation of the workspace (with source model debugging turned on) failed with these errors:\n" + logger.toString();
               
                if (SHOW_DEBUGGING_OUTPUT) {
View Full Code Here


     * @throws CALExecutorException
     * @throws GemCompilationException
     */
    public void testMakeAlgebraicTypeInstanceFunctions() throws GemCompilationException, CALExecutorException {
       
        BasicCALServices privateCopyLeccServices = CALServicesTestUtilities.makeUnsharedUnitTestCALServices(
            MachineType.LECC,
            "org.openquark.cal.test.workspace.DerivedInstanceFunctionGenerator_Test.testMakeAlgebraicTypeInstanceFunctions",
            "ice.default.cws",
            null, "DIFG_Test", false); // we use an abbreviated name here so that the path names are not too long (for running in lecc java source mode)
       
        try {
            MessageLogger logger = new MessageLogger();
           
            privateCopyLeccServices.compileWorkspace(null, logger);
            if (logger.getNErrors() > 0) {
                Assert.fail("Compilation of workspace failed: " + logger.getCompilerMessages());
            }
           
            final ModuleName moduleName = ModuleName.make("Test_MakeAlgebraicTypeInstanceFunctions");
           
            SourceModel.ModuleDefn moduleDefn =
                SourceModelUtilities.TextParsing.parseModuleDefnIntoSourceModel(
                    "module " + moduleName + ";\n" +
                    "import " + CAL_Prelude.MODULE_NAME + ";\n" +
                    "import " + CAL_Debug.MODULE_NAME + ";\n" +
                    "import " + CALPlatformTestModuleNames.DerivedInstanceFunctionGenerator_Test_Support + ";\n" +
                    "data Unary = U1;\n" +
                    "data Binary = B1 | B2;\n" +
                    "data Ternary = T1 | T2 | T3;\n" +
                    "data MyWrap = MyWrap #1 :: " + CAL_Prelude.MODULE_NAME + ".Char;\n" +
                    "data MyBottomMiddleTop a = Bottom | Middle arg :: a | Top;\n" +
                    "data MyFooBarBaz a b = MyFoo arg :: a | MyBar | MyBaz arg:: b;\n" +
                    "data MyTuple3B a b c = MyTuple3B\n" +
                    "        #1       :: a\n" +
                    "        field1   :: b\n" +
                    "        field1_1 :: c;\n",
                    logger);
           
            if (logger.getNErrors() > 0) {
                Assert.fail("Parsing of module definition failed: " + logger.getCompilerMessages());
            }
           
            WorkspaceManager workspaceManager = privateCopyLeccServices.getWorkspaceManager();
           
            workspaceManager.makeModule(new SourceModelModuleSource(moduleDefn), logger);
            if (logger.getNErrors() > 0) {
                Assert.fail("Compilation of test module (before adding instances) failed: " + logger.getCompilerMessages());
            }
View Full Code Here

          
            ////
            /// Create and compile a workspace through a BasicCALServices
            //
           
            BasicCALServices calServices = BasicCALServices.make(workspaceName);
            WorkspaceManager workspaceManager = calServices.getWorkspaceManager();
           
            try {
                HTMLDocumentationGeneratorConfiguration config = CALDocTool.makeConfiguration(workspaceManager, args, logger);
               
                MessageLogger msgLogger = new MessageLogger();
               
                StatusListener.StatusListenerAdapter statusListener = new StatusListener.StatusListenerAdapter() {
                    /**
                     * {@inheritDoc}
                     */
                    @Override
                    public void setModuleStatus(StatusListener.Status.Module moduleStatus, ModuleName moduleName) {
                        if (moduleStatus == StatusListener.SM_GENCODE) {
                            logger.fine("Compiling " + moduleName);
                        }
                    }
                };
               
                logger.info("Compiling CAL workspace..");
                calServices.compileWorkspace(statusListener, msgLogger);
               
                if (msgLogger.getNErrors() == 0) {
                    logger.info("Compilation successful");
                   
                    ////
View Full Code Here

        public CALServicesHelper() throws BusinessObjectsException {
            boolean compilationSuccessful = false;
           
            CompilerMessageLogger messageLogger = new MessageLogger();
           
            BasicCALServices newCalServices = null;
            try {
                newCalServices = BasicCALServices.make (WORKSPACE_FILE_PROPERTY,
                        DEFAULT_WORKSPACE_FILE, DEFAULT_WORKSPACE_CLIENT_ID);
               
                if (newCalServices != null) {
                    // If there's a local cache, the workspace will use it, rather than the modules in the repo
                    // ...so if the cache is out of date, now's the time to synch
                    compilationSuccessful = newCalServices.compileWorkspace(null, messageLogger);
                }
            }
            catch (Throwable t) {
                t.printStackTrace();
               
View Full Code Here

            assert false;
        }
    }
   
    private static boolean isWellFormed(String path) throws Exception {
        BasicCALServices cal = getCALServices();

        EntryPointSpec isWellFormedEntrySpec =
            EntryPointSpec.make(QualifiedName.make(ModuleName.make("Cal.Test.Experimental.Utilities.XmlParserEngine_Tests"),
                    "isWellFormed"));
       
        Object result = cal.runFunction(isWellFormedEntrySpec, new Object[] { path });
       
        assert result instanceof Boolean;
        return ((Boolean)result).booleanValue();
   }
View Full Code Here

        assert result instanceof Boolean;
        return ((Boolean)result).booleanValue();
   }
   
    private static void parseAndWriteSecondXmlCanonicalForm(String inPath, String outPath) throws Exception {
        BasicCALServices cal = getCALServices();
       
        EntryPointSpec parseAndWriteSecondXmlCanonicalFormEntrySpec =
            EntryPointSpec.make(QualifiedName.make(ModuleName.make("Cal.Test.Experimental.Utilities.XmlParserEngine_Tests"),
                    "parseAndWriteSecondXmlCanonicalForm"));
       
        cal.runFunction(parseAndWriteSecondXmlCanonicalFormEntrySpec, new Object[] { inPath, outPath });
    }
View Full Code Here

       
        // We need to set up the BasicCALServices instance that is required for the demo.
        // We get an instance through the getInstance() method, and compile the modules in the workspace via
        // the compileWorkspace() method.
       
        BasicCALServices calServices = BasicCALServices.make(
            WORKSPACE_FILE_NAME);
       
        if (!calServices.compileWorkspace(null, messageLogger)) {
            System.err.println(messageLogger.toString());
        }
       
        System.out.println();
        System.out.println("The CAL source of the demo gems defined using the source model:");
View Full Code Here

        System.out.println("-------------------------------------------------------------------------------------");
       
        MessageLogger messageLogger = new MessageLogger();       
       
        // We need to set up the calServices instance that is required for the demo.
        BasicCALServices calServices =
            BasicCALServices.makeCompiled(WORKSPACE_FILE_NAME, messageLogger);
       
        if (calServices == null) {
            System.err.println(messageLogger.toString());
            System.exit(1);
View Full Code Here

   
    public static void main(String[] args) {
        CompilerMessageLogger messageLogger = new MessageLogger();
        BasicCALServices calServices = BasicCALServices.makeCompiled(WORKSPACE_FILE_NAME, messageLogger);       

        try {

            {
                //Example 1: Inferring output type
                //This example shows how to use the Prelude.add function
                //Prelude.add is a polymorphic function - it works for all types of numbers
                //Therefore we must provide some type information to make it concrete
                //We provide a typed (Int) input policy for the first input. This will
                //allow CAL to infer the types of the second input and the output, so default
                //policies can be used there.
               
                //Note 1. If add was not a polymorphic function it would be possible to use just
                //default input and output policies as the types would not be ambiguous
               
                //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});

                System.out.println("Example 3 output: " + primesList.toString());
            }
           
           
View Full Code Here

     * @param args
     */
    public static void main(String[] args) {
       
        String workspaceFileName = "gemcutter.default.cws";
        BasicCALServices services = BasicCALServices.make(workspaceFileName);
       
        // A simple status listener which provides feedback with dots.
        StatusListener statusListener = new StatusListener() {

            private int nDotsInLine = 0;
            private static final int DOTS_PER_LINE = 120;
           
            public void setModuleStatus(StatusListener.Status.Module moduleStatus, ModuleName moduleName) {
                dumpDot();
            }
           
            public void setEntityStatus(StatusListener.Status.Entity entityStatus, String entityName) {
                dumpDot();
            }
           
            public void incrementCompleted(double d) {
                dumpDot();
            }

            private void dumpDot() {
                System.out.print('.');
                nDotsInLine++;
                if (nDotsInLine >= DOTS_PER_LINE) {
                    nDotsInLine = 0;
                    System.out.println();
                }
            }
        };
       
        System.out.println("Compiling...");
       
        CompilerMessageLogger logger = new MessageLogger();
        services.compileWorkspace(statusListener, logger);
       
        System.out.println();
       
        // Just dump messages to the console.
        if (logger.getNMessages() > 0) {
View Full Code Here

TOP

Related Classes of org.openquark.cal.services.BasicCALServices

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.