Package org.openquark.cal.services

Examples of org.openquark.cal.services.BasicCALServices


        }


        final String defaultWorkspaceFile = "cal.optimizer.cws";

        BasicCALServices calServices = BasicCALServices.make(defaultWorkspaceFile);
        calServices.getWorkspaceManager().useOptimizer(false);
        CompilerMessageLogger messageLogger = new MessageLogger();
        if (!calServices.compileWorkspace(null, messageLogger)) {
            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());
View Full Code Here


    /**
     * get the type info for the BAM run module
     * @return BAm run module type info
     */
    static private ModuleTypeInfo getTargetModuleTypeInfo() {
        BasicCALServices calServices = MonitorApp.getInstance().getCalServices();
        return calServices.getCALWorkspace().getMetaModule(MonitorApp.TARGET_MODULE).getTypeInfo();
    }
View Full Code Here

            }
        }
       
        // compile and start each job
        try {
            BasicCALServices calServices = getCalServices();
            for (int jobN = 0; jobN < document.getJobDescriptionCount (); ++jobN) {
                MonitorJobDescription jobDescription = document.getNthJobDescription (jobN);

                GemGraphGenerator generator = new GemGraphGenerator (calServices, jobDescription);

                //create each new job in separate modules.
                ModuleName jobModuleName = ModuleName.make(jobDescription.getJobId().toUpperCase());

                EntryPointSpec entry = calServices.addNewModuleWithFunction(jobModuleName, generator.getCalSource());

                MessageSource messageSource = MessageSourceFactory.createMessageSource (jobDescription);
                MonitorJob job = new MonitorJob (jobDescription, messageSource, entry);

                messageSource.addStatusListener (makeStatusListener (job));
View Full Code Here

    public static void initOptimizer(){

        final ModuleName targetModule = CAL_Optimizer.MODULE_NAME;
        final String defaultWorkspaceFile = "cal.optimizer.cws";
       
        BasicCALServices calServices = CALServicesTestUtilities.makeUnsharedUnitTestCALServices(null, defaultWorkspaceFile, null, false);
        calServices.getWorkspaceManager().useOptimizer(false);
        CompilerMessageLogger messageLogger = new MessageLogger();       
        if (!calServices.compileWorkspace(null, messageLogger)) {
            System.err.println(messageLogger.toString());
        }
              
        final ExecutionContext executionContext = calServices.getWorkspaceManager().makeExecutionContextWithDefaultProperties();       

        workspaceManager = calServices.getWorkspaceManager();
        Compiler compiler = calServices.getCompiler();  
       
        optimizer_entryPoint = compiler.getEntryPoint(
            EntryPointSpec.make(QualifiedName.make(ModuleName.make("Cal.Test.Internal.Optimizer_Test"), "unitTests")),
            ModuleName.make("Cal.Test.Internal.Optimizer_Test"), messageLogger);
        if (messageLogger.getNMessages() > 0) {
            System.err.println(messageLogger.toString());
        }
        optimizer_executor = workspaceManager.makeExecutor(executionContext);

        {
            ModuleTypeInfo moduleTypeInfo = workspaceManager.getModuleTypeInfo(CAL_Prelude.MODULE_NAME);
            preludeTypeConstants = new PreludeTypeConstants(moduleTypeInfo);
        }

        currentModuleTypeInfo = calServices.getCALWorkspace().getMetaModule(targetModule).getTypeInfo();
        nilDataCons = currentModuleTypeInfo.getVisibleDataConstructor(CAL_Prelude.DataConstructors.Nil);
        consDataCons = currentModuleTypeInfo.getVisibleDataConstructor(CAL_Prelude.DataConstructors.Cons);
    }
View Full Code Here

        InputListItem inputItem = getSelectedInputListItem ();

        metricCombo.removeAllItems ();

        if (inputItem != null) {          
            BasicCALServices calServices = MonitorApp.getInstance().getCalServices();
            //for all message properties consider which metrics are suitable
            Collection<MessagePropertyDescription> msgProperties = jobDescription.getMessagePropertyDescriptions();
            for (final MessagePropertyDescription propertyInfo : msgProperties) {
                TypeExpr propertyType = propertyInfo.getCalType(calServices);
View Full Code Here

               
                argumentNameToBindingMap.put(info.name, new PropertyBinding (info));
            }

            //add all metrics/properties combinations that produce printable outputs
            BasicCALServices calServices = MonitorApp.getInstance().getCalServices();
            for (final MessagePropertyDescription propertyInfo : messagePropertyDescriptions) {
                TypeExpr propertyType = propertyInfo.getCalType(calServices);
                TypeExpr printableType = calServices.getTypeFromString(MonitorApp.TARGET_MODULE, "Cal.Samples.BusinessActivityMonitor.BAM.Printable a => a");

                Set<GemEntity> gemEntities = new MetricGemFilter(propertyType, printableType ).getMatchingGems();
                for (final GemEntity gemEntity : gemEntities) {
                    MetricDescription metricDescription=new MetricDescription(gemEntity.getName(), propertyInfo );
                    model.addElement(new MetricItem (metricDescription));                       
View Full Code Here

    /**
     * @see org.openquark.util.ui.WizardCardDialog#makeCard()
     */
    @Override
    protected WizardCard makeCard () {
        BasicCALServices calServices = app.getCalServices();
       
        GemEntity gemEntity = calServices.getGemEntity(boundGemDescription.getQualifiedName());
       
        bindInputsCard = new BindInputsCard (app, jobDescription, gemEntity, boundGemDescription.getInputBindings (), usage);
       
        return bindInputsCard;
    }
View Full Code Here

       
        // 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(false);
       
        BasicCALServices privateCopyLeccServices = BasicCALServices.make(
            "org.openquark.cal.test.workspace",
            "ice.default.cws",
            null);
       
        ((EntryPointGenerator)privateCopyLeccServices.getWorkspaceManager().getCompiler()).setForceCodeRegen(true);       

        try {           
            MessageLogger logger = new MessageLogger();
            privateCopyLeccServices.compileWorkspace(null, logger);
            assertEquals(logger.getNErrors(), 0);

            addSourceModelCode( privateCopyLeccServices );
           
            // Run tests and make sure that it still returns true even after all the source model
            // transformations
            runCode_test(privateCopyLeccServices);
           
        } finally {
            // Restore the workspace by compiling the original module definitions
            // without the source model transformations
           
            // Turn off the debugging flag before recompilation
            CALCompiler.setInUnitTestDebugSourceModelMode(false);
           
            ((EntryPointGenerator)privateCopyLeccServices.getWorkspaceManager().getCompiler()).setForceCodeRegen(true);       

            privateCopyLeccServices.compileWorkspace(null, new MessageLogger());
        }
       
    }
View Full Code Here

    /**
     * Runs the platform function using the g machine.
     */
    public void testErrorMessage_gMachine() throws GemCompilationException, CALExecutorException {
        // Not working yet
        BasicCALServices bcs = CALServicesTestUtilities.getCommonCALServices(MachineType.G, "cal.platform.test.cws");
        addSourceModelCode( bcs );
        runCode_test( bcs );
    }
View Full Code Here

     * @param expectedReturnVal
     */
    private void renameAllSymbolsInModule(final ModuleName moduleName, final String workspaceFile, final String targetMethod, boolean renameModule, final Object expectedReturnVal) {
        try {
            String renamedTargetMethod = targetMethod;
            BasicCALServices privateCopyLeccServices = CALServicesTestUtilities.makeUnsharedUnitTestCALServices(
                MachineType.LECC,
                "org.openquark.cal.test.workspace.CALRenaming_DeepTest.renameAllSymbolsInModule",
                workspaceFile,
                null, "CALRenaming_DeepTest.renameAllSymbolsInModule", false);
           
            try {
                privateCopyLeccServices.compileWorkspace(null, new MessageLogger());
               
                ModuleSourceDefinition sourceDef = makeSourceDefFromBuiltIn(moduleName, privateCopyLeccServices.getCALWorkspace());
                String moduleString = getSourceString(sourceDef);
                List <Renaming> renamings = new ArrayList<Renaming>();
               
                // Convert the source into a source model representation, then use this model to obtain a list of symbols to rename.
                SourceModel.ModuleDefn moduleDefn = SourceModelUtilities.TextParsing.parseModuleDefnIntoSourceModel(moduleString);
                SourceModel.TopLevelSourceElement[] sourceElements = moduleDefn.getTopLevelDefns();
                for (int i = 0, n = sourceElements.length; i < n; i++) {
                    if (sourceElements[i] instanceof SourceModel.TypeConstructorDefn) {
                        SourceModel.TypeConstructorDefn typeConstructorDefn = (SourceModel.TypeConstructorDefn)sourceElements[i];
                        renamings.add(new Renaming(typeConstructorDefn.getTypeConsName(), "RenamedTypeCons" + i, SourceIdentifier.Category.TYPE_CONSTRUCTOR));
                        if (typeConstructorDefn instanceof SourceModel.TypeConstructorDefn.AlgebraicType) {
                            SourceModel.TypeConstructorDefn.AlgebraicType algebraicType = (SourceModel.TypeConstructorDefn.AlgebraicType) typeConstructorDefn;
                            SourceModel.TypeConstructorDefn.AlgebraicType.DataConsDefn[] dataConsDefns = algebraicType.getDataConstructors();
                            for (int j = 0, m = dataConsDefns.length; j < m; j++) {
                                renamings.add(new Renaming(dataConsDefns[j].getDataConsName(), ("RenamedDataCons" + i + "_" + j), SourceIdentifier.Category.DATA_CONSTRUCTOR));
                            }
                        }
                    } else if (sourceElements[i] instanceof SourceModel.TypeClassDefn) {
                        SourceModel.TypeClassDefn typeClassDefn = (SourceModel.TypeClassDefn)sourceElements[i];
                        renamings.add(new Renaming(typeClassDefn.getTypeClassName(), "RenamedTypeClass" + i, SourceIdentifier.Category.TYPE_CLASS));
                        SourceModel.TypeClassDefn.ClassMethodDefn[] classMethodDefns = typeClassDefn.getClassMethodDefns();
                        for (int j = 0, m = classMethodDefns.length; j < m; j++) {
                            renamings.add(new Renaming(classMethodDefns[j].getMethodName(), ("renamedClassMethod" + i + "_" + j), SourceIdentifier.Category.TOP_LEVEL_FUNCTION_OR_CLASS_METHOD));
                        }
                    } else if (sourceElements[i] instanceof SourceModel.FunctionDefn) {
                        SourceModel.FunctionDefn functionDefn = (SourceModel.FunctionDefn)sourceElements[i];
                        if (functionDefn.getName().equals(targetMethod)) {
                            renamedTargetMethod = "renamedFunction" + i;
                        }
                        renamings.add(new Renaming(functionDefn.getName(), "renamedFunction" + i, SourceIdentifier.Category.TOP_LEVEL_FUNCTION_OR_CLASS_METHOD));
                    } else if (sourceElements[i] instanceof SourceModel.InstanceDefn) {                   
                    } else if (sourceElements[i] instanceof SourceModel.FunctionTypeDeclaration) {                   
                    } else {
                        fail("Invalid top level source element type.");
                    }
                }
               
                if(renameModule) {
                    renamings.add(new Renaming(moduleName.toSourceText(), ("ModuleMangledByRenaming_" + moduleName), SourceIdentifier.Category.MODULE_NAME));
                }
               
                ModuleTypeInfo moduleTypeInfo = privateCopyLeccServices.getWorkspaceManager().getModuleTypeInfo(moduleName);
               
                // Now run through the list and perform all the renamings.
                ModuleName recompiledModuleName = moduleName;
                for (int n = renamings.size(), i = 0; i < n; i++) {               
                    Renaming renaming = renamings.get(i);
                   
                    QualifiedName oldQualifiedName;
                    QualifiedName newQualifiedName;
                   
                    if (renaming.category == SourceIdentifier.Category.MODULE_NAME) {
                        oldQualifiedName = QualifiedName.make(ModuleName.make(renaming.oldName), Refactorer.Rename.UNQUALIFIED_NAME_FOR_MODULE_RENAMING);
                        newQualifiedName = QualifiedName.make(ModuleName.make(renaming.newName), Refactorer.Rename.UNQUALIFIED_NAME_FOR_MODULE_RENAMING);
                    } else {
                        oldQualifiedName = QualifiedName.make(moduleName, renaming.oldName);
                        newQualifiedName = QualifiedName.make(moduleName, renaming.newName);
                    }
                   
                    CompilerMessageLogger logger = new MessageLogger();
                    SourceModifier renamer = IdentifierRenamer.getSourceModifier(moduleTypeInfo, moduleString, oldQualifiedName, newQualifiedName, renaming.category, logger);
                    assertTrue(logger.getMaxSeverity().compareTo(Severity.ERROR) < 0);
                   
                    moduleString = renamer.apply(moduleString);
                    if (renaming.category == SourceIdentifier.Category.MODULE_NAME && recompiledModuleName.equals(ModuleName.make(renaming.oldName))) {
                        recompiledModuleName = ModuleName.make(renaming.newName);
                    }
                }
               
                sourceDef = new StringModuleSourceDefinition(recompiledModuleName, moduleString);
               
                // Remove the old module from the workspace and add the new one. This will also force a recompilation of the relevant modules.
                CompilerMessageLogger logger = new MessageLogger();
                privateCopyLeccServices.getWorkspaceManager().removeModule(moduleName, new Status(""));    
                privateCopyLeccServices.getWorkspaceManager().makeModule(sourceDef, logger);
                if (logger.getMaxSeverity().compareTo(CompilerMessage.Severity.ERROR) >= 0) {
                    List<CompilerMessage> errors = logger.getCompilerMessages(CompilerMessage.Severity.ERROR);
                    for (int i = 0, n = errors.size(); i < n; i++) {
                        System.out.println(errors.get(i).toString());
                    }
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.