Package org.openquark.cal.services

Examples of org.openquark.cal.services.WorkspaceManager


        //How many more primes would you like? (enter q to quit)
        //q       

        CompilerMessageLogger messageLogger = new MessageLogger();
       
        WorkspaceManager workspaceManager = calServices.getWorkspaceManager();
        Compiler compiler = calServices.getCompiler();   
      
        CALExecutor executor = workspaceManager.makeExecutor(executionContext)
       
        //the below function represent a model of what is created when using EntryPointSpec classes i.e.
        //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);
       
        if (messageLogger.getNMessages() > 0) {
            System.err.println(messageLogger.toString());
        }
 
        try {
            Iterator<?> primesIterator = (Iterator<?>)executor.exec(allPrimesEntryPoint, null);
           
            BufferedReader inBuff = new BufferedReader(new BufferedReader(new java.io.InputStreamReader(System.in)));
                              
            while (true) {
               
                System.out.println("How many more primes would you like? (enter q to quit)");
                String command = inBuff.readLine().trim();
                              
                if (command.startsWith("q")) {
                    break;
                   
                } else {
                    int nPrimesMore = 1;
                    try {
                        nPrimesMore = Integer.parseInt(command);                      
                    } catch (NumberFormatException nfe) {
                        System.out.println("I'm extremely sorry, but I did not understand you. I'll assume one more prime.");
                    }                   
                   
                    List<Object> nextNPrimes = new ArrayList<Object>(nPrimesMore);
                    for (int i = 0; i < nPrimesMore; ++i) {
                        nextNPrimes.add(primesIterator.next());
                    }
                                             
                    System.out.println("the next " + nPrimesMore + " primes are " + nextNPrimes);
                   
                    //we can reset cached CAFs here if we like. (Works without this as well. The point here is to not hold onto
                    //the allPrimes CAF).
                    workspaceManager.resetCachedResults(executionContext);                                                      
                }                                                                                              
            }
           
        } catch (IOException ioe) {
            System.out.println(ioe);
View Full Code Here


        //  How many more primes would you like? (enter q to quit)
        //  q
                       
        CompilerMessageLogger messageLogger = new MessageLogger();
       
        WorkspaceManager workspaceManager = calServices.getWorkspaceManager();
        Compiler compiler = calServices.getCompiler();           
       
        CALExecutor executor = workspaceManager.makeExecutor(executionContext);               
       
        List<EntryPointSpec> entryPointSpecs = new ArrayList<EntryPointSpec>(); //list of EntryPointSpec
       
        //the below function represent a model of what is created when using EntryPointSpec classes i.e.
        //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);
        EntryPointSpec stringListEntryPointSpec =
            EntryPointSpec.make(QualifiedName.make(CALPlatformTestModuleNames.M2, "stringList"), null, OutputPolicy.ITERATOR_OUTPUT_POLICY);      
                     
        entryPointSpecs.add(allPrimesEntryPointSpec);
        entryPointSpecs.add(stringListEntryPointSpec);       
        compiler.getEntryPoints(entryPointSpecs, CALPlatformTestModuleNames.M2, messageLogger);
                      
        List<EntryPoint> entryPoints =
            compiler.getEntryPoints(entryPointSpecs, CALPlatformTestModuleNames.M2, messageLogger);
        if (messageLogger.getNMessages() > 0) {
            System.err.println(messageLogger.toString());
        }       
        EntryPoint allPrimesEntryPoint = entryPoints.get(0);
        EntryPoint stringListEntryPoint = entryPoints.get(1);       
       
        try {
            Iterator<?> primesIterator = (Iterator<?>)executor.exec(allPrimesEntryPoint, null);
            Iterator<?> namesIterator = (Iterator<?>)executor.exec(stringListEntryPoint, null);    
                          
            BufferedReader inBuff = new BufferedReader(new BufferedReader(new java.io.InputStreamReader(System.in)));
                              
            while (true) {
               
                System.out.println("How many more primes would you like? (enter q to quit)");
                String command = inBuff.readLine().trim();
                              
                if (command.startsWith("q")) {
                    break;
                   
                } else {
                    int nPrimesMore = 1;
                    try {
                        nPrimesMore = Integer.parseInt(command);                      
                    } catch (NumberFormatException nfe) {
                        System.out.println("I'm extremely sorry, but I did not understand you. I'll assume one more prime.");
                    }                   
                   
                    List<Object> nextNPrimes = new ArrayList<Object>(nPrimesMore);
                    for (int i = 0; i < nPrimesMore; ++i) {
                        nextNPrimes.add(primesIterator.next());
                    }
                                             
                    System.out.println("the next " + nPrimesMore + " primes are " + nextNPrimes);
                   
                    //we can reset cached CAFs here if we like. (Works without this as well. The point here is to not hold onto
                    //the allPrimes CAF).
                    workspaceManager.resetCachedResults(executionContext);                                                      
                }
               
                System.out.println("How many more names would you like? (enter q to quit)");
                command = inBuff.readLine().trim();
                              
                if (command.startsWith("q")) {
                    break;
                   
                } else {
                    int nNamesMore = 1;
                    try {
                        nNamesMore = Integer.parseInt(command);                      
                    } catch (NumberFormatException nfe) {
                        System.out.println("I'm surpassingly sorry, but I did not understand you. I'll assume one more name.");
                    }
                                                         
                    List<Object> nextNNames = new ArrayList<Object>(nNamesMore);
                    for (int i = 0; i < nNamesMore; ++i) {
                        nextNNames.add(namesIterator.next());
                    }                  
                    System.out.println("the next " + nNamesMore + " names are " + nextNNames);
                   
                    //we can reset cached CAFs here if we like. (Works without this as well. The point here is to not hold onto
                    //the Prelude.stringList CAF).
                    workspaceManager.resetCachedResults(executionContext);                     
                }                                               
            }
           
        } catch (IOException ioe) {
            System.out.println(ioe);
View Full Code Here

        //How many more primes would you like? (enter q to quit)
        //q
              
        CompilerMessageLogger messageLogger = new MessageLogger();
       
        WorkspaceManager workspaceManager = calServices.getWorkspaceManager();
        Compiler compiler = calServices.getCompiler();    
       
        CALExecutor executor = workspaceManager.makeExecutor(executionContext);
       
        EntryPoint allPrimesExternalEntryPoint =
            compiler.getEntryPoint(
                EntryPointSpec.make(QualifiedName.make(CALPlatformTestModuleNames.M2, "allPrimesExternal")),
                CALPlatformTestModuleNames.M2, messageLogger);
        if (messageLogger.getNMessages() > 0) {
            System.err.println(messageLogger.toString());
        }
             
        try {
           
            CalValue remainingPrimesCalValue = (CalValue)executor.exec(allPrimesExternalEntryPoint, null);
           
            EntryPoint nextNPrimesExternalEntryPoint =
                compiler.getEntryPoint(
                    EntryPointSpec.make(QualifiedName.make(CALPlatformTestModuleNames.M2, "nextNPrimesExternal")),
                    CALPlatformTestModuleNames.M2, messageLogger);
           
            BufferedReader inBuff = new BufferedReader(new BufferedReader(new java.io.InputStreamReader(System.in)));          

            while (true) {
               
                System.out.println("How many more primes would you like? (enter q to quit)");
                String command = inBuff.readLine().trim();
                              
                if (command.startsWith("q")) {
                    break;
                   
                } else {
                    int nPrimesMore = 1;
                    try {
                        nPrimesMore = Integer.parseInt(command);                      
                    } catch (NumberFormatException nfe) {
                        System.out.println("I'm extremely sorry, but I did not understand you. I'll assume one more prime.");
                    }
                                                            
                    //a java.util.List with 2 elements. The first is a java.util.List of nPrimesMore primes. The second is a CalValue
                    //containing the remaining primes (as a lazy internal CAL list).
                    List<?> result = (List<?>)executor.exec(nextNPrimesExternalEntryPoint, new Object[] {remainingPrimesCalValue, new Integer(nPrimesMore)});
                    List<?> nextNPrimes = (List<?>)result.get(0);
                    remainingPrimesCalValue = (CalValue)result.get(1);
                    System.out.println("the next " + nPrimesMore + " are " + nextNPrimes);
                   
                    //we can reset cached CAFs here if we like. (Works without this as well. The point here is to not hold onto
                    //the allPrimes CAF).
                    workspaceManager.resetCachedResults(executionContext);                                                           
                }               
            }
       
        } catch (IOException ioe) {
            System.out.println(ioe);
View Full Code Here

        //How many more primes would you like? (enter q to quit)
        //q      
       
        CompilerMessageLogger messageLogger = new MessageLogger();
       
        WorkspaceManager workspaceManager = calServices.getWorkspaceManager();
        Compiler compiler = calServices.getCompiler();    
       
        CALExecutor executor = workspaceManager.makeExecutor(executionContext);               
       
        List<QualifiedName> entryPointNames = new ArrayList<QualifiedName>(); //list of QualifiedName
        entryPointNames.add(QualifiedName.make(CALPlatformTestModuleNames.M2, "allPrimesExternal"));
        entryPointNames.add(QualifiedName.make(CALPlatformTestModuleNames.M2, "stringListExternal"));
        entryPointNames.add(QualifiedName.make(CALPlatformTestModuleNames.M2, "takeNExternal_ListOfInt"));
        entryPointNames.add(QualifiedName.make(CALPlatformTestModuleNames.M2, "takeNExternal_ListOfString"));                      
       
        List<EntryPoint> entryPoints =
            compiler.getEntryPoints(
                EntryPointSpec.buildListFromQualifiedNames(entryPointNames),
                CALPlatformTestModuleNames.M2,
                messageLogger);
       
        if (messageLogger.getNMessages() > 0) {
            System.err.println(messageLogger.toString());
        }
        EntryPoint allPrimesExternal = entryPoints.get(0);
        EntryPoint stringListExternal = entryPoints.get(1);
        EntryPoint takeNExternal_ListOfInt = entryPoints.get(2);
        EntryPoint takeNExternal_ListOfString = entryPoints.get(3);
       
        try {
            CalValue remainingPrimesCalValue = (CalValue)executor.exec(allPrimesExternal, null);
            CalValue remainingNamesCalValue = (CalValue)executor.exec(stringListExternal, null);    
                          
            BufferedReader inBuff = new BufferedReader(new BufferedReader(new java.io.InputStreamReader(System.in)));
                              
            while (true) {
               
                System.out.println("How many more primes would you like? (enter q to quit)");
                String command = inBuff.readLine().trim();
                              
                if (command.startsWith("q")) {
                    break;
                   
                } else {
                    int nPrimesMore = 1;
                    try {
                        nPrimesMore = Integer.parseInt(command);                      
                    } catch (NumberFormatException nfe) {
                        System.out.println("I'm extremely sorry, but I did not understand you. I'll assume one more prime.");
                    }                   
                    
                    List<?> result = (List<?>)executor.exec(takeNExternal_ListOfInt,
                            new Object[] {remainingPrimesCalValue, new Integer(nPrimesMore)});
                  
                    //a java.util.List with 2 elements. The first is a java.util.List of nPrimesMore primes. The second is a CalValue
                    //containing the remaining primes (as a lazy internal CAL list).                     
                    List<?> nextNPrimes = (List<?>)result.get(0);
                    remainingPrimesCalValue = (CalValue)result.get(1);                     
                    System.out.println("the next " + nPrimesMore + " primes are " + nextNPrimes);
                   
                    //we can reset cached CAFs here if we like. (Works without this as well. The point here is to not hold onto
                    //the allPrimes CAF).
                    workspaceManager.resetCachedResults(executionContext);                                                      
                }
               
                System.out.println("How many more names would you like? (enter q to quit)");
                command = inBuff.readLine().trim();
                              
                if (command.startsWith("q")) {
                    break;
                   
                } else {
                    int nNamesMore = 1;
                    try {
                        nNamesMore = Integer.parseInt(command);                      
                    } catch (NumberFormatException nfe) {
                        System.out.println("I'm surpassingly sorry, but I did not understand you. I'll assume one more name.");
                    }
                                     
                    List<?> result = (List<?>)executor.exec(takeNExternal_ListOfString,
                            new Object[] {remainingNamesCalValue, new Integer(nNamesMore)});
                  
                    //a java.util.List with 2 elements. The first is a java.util.List of nNamesMore names. The second is a CalValue
                    //containing the remaining names (as a CAL list).                     
                    List<?> nextNNames = (List<?>)result.get(0);
                    remainingNamesCalValue = (CalValue)result.get(1);                     
                    System.out.println("the next " + nNamesMore + " names are " + nextNNames);
                   
                    //we can reset cached CAFs here if we like. (Works without this as well. The point here is to not hold onto
                    //the Prelude.stringList CAF).
                    workspaceManager.resetCachedResults(executionContext);                     
                }                               
               
            }
       
        } catch (IOException ioe) {
View Full Code Here

        //  How many more primes would you like? (enter q to quit)
        //  q
                       
        CompilerMessageLogger messageLogger = new MessageLogger();
       
        WorkspaceManager workspaceManager = calServices.getWorkspaceManager();
        Compiler compiler = calServices.getCompiler();          
       
        CALExecutor executor = workspaceManager.makeExecutor(executionContext);               
       
        List<EntryPointSpec> entryPointSpecs = new ArrayList<EntryPointSpec>(); //list of EntryPointSpec
       
        //the below 2 functions represent a model of what is created when using EntryPointSpec classes i.e.
        //explicit input and output policies.
       
        //allPrimesAdjunct :: Prelude.JObject;
        //allPrimesAdjunct = (\x -> Prelude.output ((Prelude.unsafeCoerce x) ::  Prelude.CalValue)) M1.allPrimes;
        //
        //takeNIntAdjunct :: Prelude.JObject -> Prelude.JObject -> Prelude.JObject;
        //takeNIntAdjunct list nToTake =
        //    (\x -> Prelude.output ((Prelude.unsafeCoerce x) :: ([Int], CalValue)))
        //        (takeN
        //            ((\x -> (Prelude.unsafeCoerce ((Prelude.input x) :: Prelude.CalValue)) :: [Prelude.Int]) list)
        //            ((Prelude.input :: Prelude.JObject -> Prelude.Int) nToTake)
        //         );
       
        EntryPointSpec allPrimesEntryPointSpec =
            EntryPointSpec.make(QualifiedName.make(CALPlatformTestModuleNames.M1, "allPrimes"), new InputPolicy[] {}, OutputPolicy.CAL_VALUE_OUTPUT_POLICY);
        EntryPointSpec stringListEntryPointSpec =
            EntryPointSpec.make(QualifiedName.make(CALPlatformTestModuleNames.M2, "stringList"), new InputPolicy[] {}, OutputPolicy.CAL_VALUE_OUTPUT_POLICY);
       
        String Prelude_Int = CAL_Prelude.TypeConstructors.Int.getQualifiedName();
        String Prelude_CalValue = CAL_Prelude.TypeConstructors.CalValue.getQualifiedName();
        String Prelude_String = CAL_Prelude.TypeConstructors.String.getQualifiedName();
        String Prelude_unsafeCoerce = CAL_Prelude.Functions.unsafeCoerce.getQualifiedName();
        String Prelude_output = CAL_Prelude.Functions.output.getQualifiedName();
       
        SourceModel.TypeExprDefn listOfIntType = SourceModel.TypeExprDefn.List.make(SourceModel.TypeExprDefn.TypeCons.make(CAL_Prelude.TypeConstructors.Int));
        EntryPointSpec takeNListOfInt =
            EntryPointSpec.make(QualifiedName.make(CALPlatformTestModuleNames.M2, "takeN"), new InputPolicy[] {
            InputPolicy.makeTypedCalValueInputPolicy(listOfIntType),
            InputPolicy.DEFAULT_INPUT_POLICY
            }, OutputPolicy.make("(\\x -> " + Prelude_output + " ((" + Prelude_unsafeCoerce + " x) :: ([" + Prelude_Int + "], " + Prelude_CalValue + ")))"));

       
        SourceModel.TypeExprDefn listOfStringType = SourceModel.TypeExprDefn.List.make(SourceModel.TypeExprDefn.TypeCons.make(CAL_Prelude.TypeConstructors.String));
        EntryPointSpec takeNListOfString =
            EntryPointSpec.make(QualifiedName.make(CALPlatformTestModuleNames.M2, "takeN"), new InputPolicy[] {
            InputPolicy.makeTypedCalValueInputPolicy(listOfStringType),
            InputPolicy.DEFAULT_INPUT_POLICY
        }, OutputPolicy.make("(\\x -> " + Prelude_output + " ((" + Prelude_unsafeCoerce + " x) :: ([" + Prelude_String + "], " + Prelude_CalValue + ")))"));       
                     
        entryPointSpecs.add(allPrimesEntryPointSpec);
        entryPointSpecs.add(stringListEntryPointSpec);
        entryPointSpecs.add(takeNListOfInt);
        entryPointSpecs.add(takeNListOfString);       
                      
        List<EntryPoint> entryPoints =
            compiler.getEntryPoints(entryPointSpecs, CALPlatformTestModuleNames.M2, messageLogger);
        if (messageLogger.getNMessages() > 0) {
            System.err.println(messageLogger.toString());
        }
        EntryPoint allPrimesEntryPoint = entryPoints.get(0);
        EntryPoint stringListEntryPoint = entryPoints.get(1);
        EntryPoint takeNListOfIntEntryPoint = entryPoints.get(2);
        EntryPoint takeNListOfStringEntryPoint = entryPoints.get(3);
       
        try {
            CalValue remainingPrimesCalValue = (CalValue)executor.exec(allPrimesEntryPoint, null);
            CalValue remainingNamesCalValue = (CalValue)executor.exec(stringListEntryPoint, null);    
                          
            BufferedReader inBuff = new BufferedReader(new BufferedReader(new java.io.InputStreamReader(System.in)));
                              
            while (true) {
               
                System.out.println("How many more primes would you like? (enter q to quit)");
                String command = inBuff.readLine().trim();
                              
                if (command.startsWith("q")) {
                    break;
                   
                } else {
                    int nPrimesMore = 1;
                    try {
                        nPrimesMore = Integer.parseInt(command);                      
                    } catch (NumberFormatException nfe) {
                        System.out.println("I'm extremely sorry, but I did not understand you. I'll assume one more prime.");
                    }                   
                    
                    List<?> result = (List<?>)executor.exec(takeNListOfIntEntryPoint,
                            new Object[] {remainingPrimesCalValue, new Integer(nPrimesMore)});
                  
                    //a java.util.List with 2 elements. The first is a java.util.List of nPrimesMore primes. The second is a CalValue
                    //containing the remaining primes (as a lazy internal CAL list).                     
                    List<?> nextNPrimes = (List<?>)result.get(0);
                    remainingPrimesCalValue = (CalValue)result.get(1);                     
                    System.out.println("the next " + nPrimesMore + " primes are " + nextNPrimes);
                   
                    //we can reset cached CAFs here if we like. (Works without this as well. The point here is to not hold onto
                    //the allPrimes CAF).
                    workspaceManager.resetCachedResults(executionContext);                                                      
                }
               
                System.out.println("How many more names would you like? (enter q to quit)");
                command = inBuff.readLine().trim();
                              
                if (command.startsWith("q")) {
                    break;
                   
                } else {
                    int nNamesMore = 1;
                    try {
                        nNamesMore = Integer.parseInt(command);                      
                    } catch (NumberFormatException nfe) {
                        System.out.println("I'm surpassingly sorry, but I did not understand you. I'll assume one more name.");
                    }
                                     
                    List<?> result = (List<?>)executor.exec(takeNListOfStringEntryPoint,
                            new Object[] {remainingNamesCalValue, new Integer(nNamesMore)});
                  
                    //a java.util.List with 2 elements. The first is a java.util.List of nNamesMore names. The second is a CalValue
                    //containing the remaining names (as a lazy internal CAL list).                     
                    List<?> nextNNames = (List<?>)result.get(0);
                    remainingNamesCalValue = (CalValue)result.get(1);                     
                    System.out.println("the next " + nNamesMore + " names are " + nextNNames);
                   
                    //we can reset cached CAFs here if we like. (Works without this as well. The point here is to not hold onto
                    //the Prelude.stringList CAF).
                    workspaceManager.resetCachedResults(executionContext);                     
                }                                               
            }
           
        } catch (IOException ioe) {
            System.out.println(ioe);
View Full Code Here

        helpTestUncheckedCALDocReferencesValidity(leccCALServices);
    }
   
    public void helpTestUncheckedCALDocReferencesValidity(final BasicCALServices calServices) {
       
        final WorkspaceManager workspaceManager = calServices.getWorkspaceManager();
       
        final ModuleName[] moduleNames = workspaceManager.getModuleNamesInProgram();
       
        final List<String> brokenReferences = new ArrayList<String>();
       
        for (final ModuleName moduleName : moduleNames) {
            if (moduleName.equals(CALPlatformTestModuleNames.CALDocTest)) {
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.