Package org.openquark.cal.services

Examples of org.openquark.cal.services.WorkspaceManager


            System.err.println(messageLogger.toString());
        }

        final ExecutionContext executionContext = calServices.getWorkspaceManager().makeExecutionContextWithDefaultProperties();

        WorkspaceManager workspaceManager = calServices.getWorkspaceManager();
        Compiler compiler = calServices.getCompiler();
        optimizer_entryPoint = compiler.getEntryPoint(
                EntryPointSpec.make(CAL_Optimizer_internal.Functions.optimize),
                CAL_Optimizer.MODULE_NAME, messageLogger);
        if (messageLogger.getNMessages() > 0) {
            System.err.println(messageLogger.toString());
        }
        optimizer_executor = workspaceManager.makeExecutor(executionContext);
       
        // Initialize preludeTypeConstants
        {
            ModuleTypeInfo moduleTypeInfo = workspaceManager.getModuleTypeInfo(CAL_Prelude.MODULE_NAME);
            preludeTypeConstants = new PreludeTypeConstants(moduleTypeInfo);
            OptimizerHelper.setPreludeTypeConstants(preludeTypeConstants);
        }   
    }
View Full Code Here


    /**
     * Test invoking a non-zero arity run target.
     */
    public void testInvokingNonCAF_lecc () {
        if (test_lecc_machine) {
            WorkspaceManager workspaceManager = leccCALServices.getWorkspaceManager();
            Compiler compiler = leccCALServices.getCompiler();

            CompilerMessageLogger messageLogger = new MessageLogger();
            EntryPoint entryPoint = compiler.getEntryPoint(
                EntryPointSpec.make(QualifiedName.make(CALPlatformTestModuleNames.RuntimeRegression, "nonCAFEntryPoint")),
                CALPlatformTestModuleNames.RuntimeRegression, messageLogger);
            if (messageLogger.getNMessages() > 0) {
                System.err.println(messageLogger.toString());
            }

            final ExecutionContext executionContext = leccCALServices.getWorkspaceManager().makeExecutionContextWithDefaultProperties();

            CALExecutor executor = workspaceManager.makeExecutor(executionContext);
            try {
                Object result = executor.exec(entryPoint, new Object[] { new Integer(1), new Integer(2)});
                assertTrue(((Integer)result).intValue() == 6);
            } catch (CALExecutorException e) {
                fail(e.toString());
View Full Code Here

    /**
     * Test invoking a non-zero arity run target.
     */
    public void testInvokingNonCAF_g () {
        if (test_g_machine) {
            WorkspaceManager workspaceManager = gCALServices.getWorkspaceManager();
            Compiler compiler = gCALServices.getCompiler();

            CompilerMessageLogger messageLogger = new MessageLogger();
            EntryPoint entryPoint = compiler.getEntryPoint(
                EntryPointSpec.make(QualifiedName.make(CALPlatformTestModuleNames.RuntimeRegression, "nonCAFEntryPoint")),
                CALPlatformTestModuleNames.RuntimeRegression, messageLogger);
            if (messageLogger.getNMessages() > 0) {
                System.err.println(messageLogger.toString());
            }

            final ExecutionContext executionContext = gCALServices.getWorkspaceManager().makeExecutionContextWithDefaultProperties();

            CALExecutor executor = workspaceManager.makeExecutor(executionContext);
            try {
                Object result = executor.exec(entryPoint, new Object[] { new Integer(1), new Integer(2)});
                assertTrue(((Integer)result).intValue() == 6);
            } catch (CALExecutorException e) {
                fail(e.toString());
View Full Code Here

        String sourceDefString = comment + " module " + tempModuleName + "; import " + CAL_Prelude.MODULE_NAME + ";";
       
        ModuleSourceDefinition sourceDef = new StringModuleSourceDefinition(tempModuleName, sourceDefString);
       
        // Get the workspace manager and the logger.
        WorkspaceManager workspaceManager = leccCALServices.getWorkspaceManager();
        CompilerMessageLogger logger = new MessageLogger();
       
        // Compile the module.
        workspaceManager.makeModule(sourceDef, logger);
       
        // Remove the module.
        leccCALServices.getWorkspaceManager().removeModule(tempModuleName, new Status("Remove module status."));
       
        // Check that we got an error message of the expected type.
View Full Code Here

       
        AdjunctSource source = new AdjunctSource.FromSourceModel(
                SourceModel.FunctionDefn.Algebraic.make(adjunctUnqualifiedName, Scope.PUBLIC, null, funcExpr));
       

        WorkspaceManager workspaceManager = leccCALServices.getWorkspaceManager();
        CompilerMessageLogger logger = new MessageLogger();
       
       
        // Compile the adjunct definition.       
        EntryPointSpec entryPointSpec = EntryPointSpec.make(qualifiedAdjunctName, new InputPolicy[0], OutputPolicy.DEFAULT_OUTPUT_POLICY);
        workspaceManager.getCompiler().getEntryPoint (source, entryPointSpec, adjunctModuleName,  logger);

        if (logger.getMaxSeverity().compareTo(CompilerMessage.Severity.ERROR) >= 0) {
            fail("Compilation failed: " + logger.getFirstError().getMessage());
        }
       

        // Get the classloader for module with the adjunct we compiled.
        LECCModule module = (LECCModule)workspaceManager.getModuleTypeInfo(adjunctModuleName).getModule();
        CALClassLoader adjunctModuleClassLoader = module.getClassLoader();
       
        // Check that it's an adjunct classloader..
        checkIsAdjunctClassLoader(adjunctModuleClassLoader);
       
View Full Code Here

    private boolean compileWorkspace(boolean dirtyOnly, boolean forceCodeRegen) {

        jfitLogger.info("Compiling CAL workspace..");
       
        String clientID = WorkspaceConfiguration.getDiscreteWorkspaceID(DEFAULT_WORKSPACE_CLIENT_ID);
        WorkspaceManager workspaceManager = WorkspaceManager.getWorkspaceManager(clientID);
       
        // Add a status listener to log when modules are loaded.
        workspaceManager.addStatusListener(new StatusListener.StatusListenerAdapter() {
            public void setModuleStatus(StatusListener.Status.Module moduleStatus, ModuleName moduleName) {
                if (moduleStatus == StatusListener.SM_LOADED) {
                    jfitLogger.fine("  Module loaded: " + moduleName);
                }
            }
        });

       
        CompilerMessageLogger ml = new MessageLogger();
       
        // Init and compile the workspace.
        Status initStatus = new Status("Init status.");
        workspaceManager.initWorkspace(streamProvider, initStatus);
       
        if (initStatus.getSeverity() != Status.Severity.OK) {
            ml.logMessage(initStatus.asCompilerMessage());
        }
       
        long startCompile = System.currentTimeMillis();
       
        // If there are no errors go ahead and compile the workspace.
        if (ml.getMaxSeverity().compareTo(CompilerMessage.Severity.ERROR) < 0) {
            WorkspaceManager.CompilationOptions options = new WorkspaceManager.CompilationOptions();
            options.setForceCodeRegeneration(forceCodeRegen);
            workspaceManager.compile(ml, dirtyOnly, null, options);
        }
       
        long compileTime = System.currentTimeMillis() - startCompile;
       
        boolean compilationSucceeded;
        if (ml.getMaxSeverity().compareTo(CompilerMessage.Severity.ERROR) >= 0) {
            // Errors
            jfitLogger.severe("Compilation unsuccessful because of errors:");
            compilationSucceeded = false;
        } else {
            // Compilation successful
            jfitLogger.fine("Compilation successful");
            compilationSucceeded = true;
        }
       
        // Write out compiler messages
        java.util.List<CompilerMessage> errs = ml.getCompilerMessages();
        int errsSize = errs.size();
        for (int i = 0; i < errsSize; i++) {
            CompilerMessage err = errs.get(i);
            jfitLogger.info("  " + err.toString());
        }
       
        jfitLogger.fine("CAL: Finished compiling in " + compileTime + "ms");
       
        this.calWorkspace = workspaceManager.getWorkspace();
       
        return compilationSucceeded;
    }
View Full Code Here

     * @param topLevelSourceElements the top-level source elements to include.
     * @return a logger which logged the results of the compile.
     */
    private static CompilerMessageLogger compileAndRemoveModuleForTopLevelSourceElements(ModuleName moduleName, SourceModel.TopLevelSourceElement[] topLevelSourceElements) {
        // Get the workspace manager and the logger.
        WorkspaceManager workspaceManager = leccCALServices.getWorkspaceManager();
        CompilerMessageLogger logger = new MessageLogger();

        // Get the module defn.
        SourceModel.ModuleDefn moduleDefnWithoutImports = SourceModel.ModuleDefn.make(moduleName, new SourceModel.Import[0], topLevelSourceElements);
        SourceModel.ModuleDefn moduleDefn = SourceModelUtilities.ImportAugmenter.augmentWithImports(moduleDefnWithoutImports);

        // Compile the module.
        SourceModelModuleSource moduleSource = new SourceModelModuleSource(moduleDefn);
        workspaceManager.makeModule(moduleSource, logger);

        // Remove the module.
        leccCALServices.getWorkspaceManager().removeModule(DEFAULT_TEST_MODULE_NAME, new Status("Remove module status."));

        return logger;
View Full Code Here

    /**
     * Test that a data constructor argument without a field name gives an error.
     */
    public void testUnnamedDCArgError() {
        // Get the workspace manager and the logger.
        WorkspaceManager workspaceManager = leccCALServices.getWorkspaceManager();
        CompilerMessageLogger logger = new MessageLogger();

        ModuleName moduleName = DEFAULT_TEST_MODULE_NAME;
        final String moduleCode =
            "module " + DEFAULT_TEST_MODULE_NAME + ";" +
            "import " + Prelude + ";" +
           
            "data Foo = Foo " + Prelude + ".Int;";

        // Compile the module.
        ModuleSourceDefinition moduleSourceDef = new StringModuleSourceDefinition(moduleName, moduleCode);
        workspaceManager.makeModule(moduleSourceDef, logger);

        // Remove the module.
        leccCALServices.getWorkspaceManager().removeModule(DEFAULT_TEST_MODULE_NAME, new Status("Remove module status."));
       
        // Check that we got an error message of the expected type.
View Full Code Here

           
            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());
            }
           
            String[] typeNames = new String[] {
                "Unary", "Binary", "Ternary", "MyWrap", "MyBottomMiddleTop", "MyFooBarBaz", "MyTuple3B"
            };
           
            SourceModel.Expr[][] correspTestValues = new SourceModel.Expr[][] {
                parseExprs(new String[] {"U1"}),
                parseExprs(new String[] {"B1", "B2"}),
                parseExprs(new String[] {"T1", "T2", "T3"}),
                parseExprs(new String[] {"MyWrap 'a'", "MyWrap 'b'", "MyWrap 'c'"}),
                parseExprs(new String[] {"Bottom", "Middle 'a'", "Middle 'b'", "Middle 'c'", "Top"}),
                parseExprs(new String[] {"MyFoo 'a'", "MyFoo 'b'", "MyFoo 'c'", "MyBar", "MyBaz 'a'", "MyBaz 'b'", "MyBaz 'c'"}),
                parseExprs(new String[] {
                    "MyTuple3B 'a' 'a' 'a'",
                    "MyTuple3B 'a' 'a' 'b'",
                    "MyTuple3B 'a' 'b' 'a'",
                    "MyTuple3B 'a' 'b' 'b'",
                    "MyTuple3B 'b' 'a' 'a'",
                    "MyTuple3B 'b' 'a' 'b'",
                    "MyTuple3B 'b' 'b' 'a'",
                    "MyTuple3B 'b' 'b' 'b'"})
            };
           
            SourceModel.ModuleDefn compactImplModuleDefn = addInstancesAndTests(moduleDefn, workspaceManager, typeNames, correspTestValues, true, "testAllCompact");
           
            if (SHOW_DEBUGGING_OUTPUT) {
                System.out.println("Module with compact instance implementations:");
                System.out.println(compactImplModuleDefn);
            }
           
            workspaceManager.makeModule(new SourceModelModuleSource(compactImplModuleDefn), logger);
            if (logger.getNErrors() > 0) {
                Assert.fail("Compilation of compact instance implementations failed: " + logger.getCompilerMessages());
            }
           
            CALServicesTestUtilities.runNamedFunction(QualifiedName.make(moduleName, "testAllCompact"), privateCopyLeccServices);
           
            SourceModel.ModuleDefn efficientImplModuleDefn = addInstancesAndTests(moduleDefn, workspaceManager, typeNames, correspTestValues, false, "testAllEfficient");
           
            if (SHOW_DEBUGGING_OUTPUT) {
                System.out.println("Module with efficient instance implementations:");
                System.out.println(efficientImplModuleDefn);
            }
           
            workspaceManager.makeModule(new SourceModelModuleSource(efficientImplModuleDefn), logger);
            if (logger.getNErrors() > 0) {
                Assert.fail("Compilation of efficient instance implementations failed: " + logger.getCompilerMessages());
            }

            CALServicesTestUtilities.runNamedFunction(QualifiedName.make(moduleName, "testAllEfficient"), privateCopyLeccServices);
View Full Code Here

            "unqualifiedFooReference = foo;\n" +
            "boundBarReference bar =\n" +
            "   foo bar;\n" +
            "intToOrderingReference = intToOrdering;";
       
        WorkspaceManager workspaceManager = leccServices.getWorkspaceManager();
        CompilerMessageLogger logger = new MessageLogger();
       
        ModuleTypeInfo moduleTypeInfo1 = workspaceManager.getModuleTypeInfo(CALRenaming_Test_Support1);
        ModuleTypeInfo moduleTypeInfo2 = workspaceManager.getModuleTypeInfo(CALRenaming_Test_Support2);
       
        QualifiedName oldName = QualifiedName.make(CALRenaming_Test_Support1, "foo");
        QualifiedName newName = QualifiedName.make(CALRenaming_Test_Support1, "bar");
       
        SourceModifier renamer1 = IdentifierRenamer.getSourceModifier(moduleTypeInfo1, sourceText1, oldName, newName, Category.TOP_LEVEL_FUNCTION_OR_CLASS_METHOD, logger);
View Full Code Here

TOP

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

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.