Changeset 2132
- Timestamp:
- 06/29/08 06:06:23 (3 months ago)
- Files:
-
- trunk/Library/incomplete/SkipTreeTest.fss (modified) (3 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/Shell.java (modified) (12 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/compiler/Fortress.java (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/repository/CacheBasedRepository.java (modified) (3 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/unicode/OperatorStuffGenerator.java (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/useful/ConvenientStrings.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Library/incomplete/SkipTreeTest.fss
r2117 r2132 1 (******************************************************************************* 2 Copyright 2008 Sun Microsystems, Inc., 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 All rights reserved. 5 6 U.S. Government Rights - Commercial software. 7 Government users are subject to the Sun Microsystems, Inc. standard 8 license agreement and applicable provisions of the FAR and its supplements. 9 10 Use is subject to license terms. 11 12 This distribution may include materials developed by third parties. 13 14 Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered 15 trademarks of Sun Microsystems, Inc. in the U.S. and other countries. 16 ******************************************************************************) 17 1 18 component SkipTreeTest 2 19 import SkipTree.{...} … … 8 25 println leaf.toString() 9 26 println leaf.find(3) 10 println leaf.find(7) 27 println leaf.find(7) 11 28 testList = emptyList[\ZZ32\]().addRight(5).addRight(10).addRight(15).addRight(20) 12 29 assert(binarySearch[\ZZ32\](testList, 2), -1) … … 20 37 assert(binarySearch[\ZZ32\](testList, 23), -5) 21 38 22 println leaf.insert(5,2,4).toString() 39 println leaf.insert(5,2,4).toString() 23 40 (** tree = SkipTree[\ZZ32,ZZ32\](Just[\Node[\ZZ32,ZZ32\]\](leaf)) *) 24 25 26 27 41 42 43 44 28 45 end (* run(args:String...):() *) 29 46 trunk/ProjectFortress/src/com/sun/fortress/Shell.java
r2128 r2132 43 43 44 44 public final class Shell { 45 // public static boolean debug;46 45 static boolean test; 47 private static String COMPONENT_SUFFIX = ".fss";48 private static String API_SUFFIX = ".fsi";49 50 public static String fortressLocation() {51 return ProjectProperties.ANALYZED_CACHE_DIR;52 }53 46 54 47 /* Helper method to print usage message.*/ 55 48 private static void printUsageMessage() { 56 49 System.err.println("Usage:"); 57 System.err.println(" compile [-out file] [-debug [#]] somefile.fs{s,i}");50 System.err.println(" compile [-out file] [-debug [#]] somefile.fs{s,i}"); 58 51 System.err.println(" [run] [-test] [-debug [#]] somefile.fss arg..."); 59 52 System.err.println(" parse [-out file] [-debug [#]] somefile.fs{s,i}..."); … … 65 58 System.err.println 66 59 ("Invoked as script: fortress args\n"+ 67 "Invoked by java: java ... com.sun.fortress.shell.Shell args\n"+ 60 "Invoked by java: java ... com.sun.fortress.Shell args\n"+ 61 "fortress compile [-out file] [-debug [#]] somefile.fs{s,i}\n"+ 62 " Compile somefile. If compilation succeeds no message will be printed.\n"+ 63 " -out file : dumps the processed abstract syntax tree to a file.\n" + 64 " -debug : enables debugging to the maximum level and prints java stack traces.\n"+ 65 " -debug # : sets debugging to the specified level, where # is a number.\n"+ 66 "\n"+ 68 67 "fortress [run] [-test] [-debug [#]] somefile.fss arg ...\n"+ 69 68 " Runs somefile.fss through the Fortress interpreter, passing arg ... to the\n"+ 70 69 " run method of somefile.fss.\n"+ 70 " -test : first runs test functions associated with the program.\n"+ 71 71 " -debug : enables debugging to the maximum level and prints java stack traces.\n"+ 72 72 " -debug # : sets debugging to the specified level, where # is a number.\n"+ 73 " -test : first runs test functions associated with the program.\n"+74 73 "\n"+ 75 "fortress compile [-debug [#]] [-out file] somefile.fs{s,i}\n"+ 76 " Compile somefile. If compilation succeeds no message will be printed.\n"+ 74 "fortress parse [-out file] [-debug [#]] somefile.fs{i,s}\n"+ 75 " Parses a file. If parsing succeeds the message \"Ok\" will be printed.\n"+ 76 " If -out file is given, a message about the file being written to will be printed.\n"+ 77 " -out file : dumps the abstract syntax tree to a file.\n"+ 77 78 " -debug : enables debugging to the maximum level and prints java stack traces.\n"+ 78 79 " -debug # : sets debugging to the specified level, where # is a number.\n"+ 79 " -out file : dumps the processed abstract syntax tree to a file.\n" +80 "\n"+81 "fortress parse [-out file] [-debug [#]] somefile.fs{i,s}\n"+82 " Parses a file. If the parse succeeds the message \"Ok\" will be printed.\n"+83 " If -out file is given, a message about the file being written to will be printed.\n"+84 " -debug : enables debugging to the maximum level and prints java stack traces.\n"+85 " -debug # : sets debugging to the specified level, where # is a number.\n"+86 " -out file : dumps the abstract syntax tree to a file.\n"+87 80 "\n"+ 88 81 "fortress typecheck [-out file] [-debug [#]] somefile.fs{i,s}\n"+ 89 " Typechecks a file. If the typecheck succeeds no message will be printed.\n"+ 82 " Typechecks a file. If type checking succeeds no message will be printed.\n"+ 83 " -out file : dumps the processed abstract syntax tree to a file.\n"+ 90 84 " -debug : enables debugging to the maximum level and prints java stack traces.\n"+ 91 " -debug # : sets debugging to the specified level, where # is a number.\n"+ 92 " -out file : dumps the processed abstract syntax tree to a file\n" 85 " -debug # : sets debugging to the specified level, where # is a number.\n" 93 86 ); 94 87 } … … 108 101 try { 109 102 String what = tokens[0]; 110 if (what.equals("run")) { 111 run(Arrays.asList(tokens).subList(1, tokens.length)); 112 } else if (what.equals("compile")) { 113 compile(false, Arrays.asList(tokens).subList(1, tokens.length), Option.<String>none()); 103 List<String> args = Arrays.asList(tokens).subList(1, tokens.length); 104 if (what.equals("compile")) { 105 compile(args, Option.<String>none()); 106 } else if (what.equals("run")) { 107 run(args); 108 } else if ( what.equals("parse" ) ){ 109 parse(args, Option.<String>none()); 114 110 } else if (what.equals("typecheck")) { 115 111 turnOnTypeChecking(); 116 compile(false, Arrays.asList(tokens).subList(1, tokens.length), Option.<String>none()); 117 } else if (what.contains(COMPONENT_SUFFIX) || (what.startsWith("-") && tokens.length > 1)) { 112 compile(args, Option.<String>none()); 113 } else if (what.contains(ProjectProperties.COMP_SOURCE_SUFFIX) 114 || (what.startsWith("-") && tokens.length > 1)) { 118 115 // no "run" command. 119 116 run(Arrays.asList(tokens)); 120 } else if ( what.equals("parse" ) ){121 parse(Arrays.asList(tokens).subList(1, tokens.length), Option.<String>none());122 117 } else if (what.equals("help")) { 123 118 printHelpMessage(); … … 134 129 135 130 /** 136 * Parse a file. If the file parses ok it will say "Ok". If you want a dump then give137 * -out somefile.131 * Parse a file. If the file parses ok it will say "Ok". 132 * If you want a dump then give -out somefile. 138 133 */ 139 private static void parse(List<String> args, Option<String> out){ 134 private static void parse(List<String> args, Option<String> out) 135 throws UserError, InterruptedException, IOException { 136 if (args.size() == 0) { 137 throw new UserError("Need a file to compile"); 138 } 140 139 String s = args.get(0); 141 140 List<String> rest = args.subList(1, args.size()); … … 155 154 rest = rest.subList( 1, rest.size() ); 156 155 } 157 if (s.equals("-test")) test = true;158 156 if (s.equals("-noPreparse")) ProjectProperties.noPreparse = true; 159 157 … … 166 164 private static void parse( String file, Option<String> out){ 167 165 try{ 168 CompilationUnit unit = Parser.parseFile(apiName(file), new File(file)); 169 if ( ! out.isSome() ){ 170 System.out.println( "Ok" ); 171 } else { 166 CompilationUnit unit = Parser.parseFile(cuName(file), new File(file)); 167 System.out.println( "Ok" ); 168 if ( out.isSome() ){ 172 169 try{ 173 170 ASTIO.writeJavaAst(unit, out.unwrap()); … … 186 183 } 187 184 185 private static boolean isInteger( String s ){ 186 try{ 187 int i = Integer.valueOf(s); 188 return i == i; 189 } catch ( NumberFormatException n ){ 190 return false; 191 } 192 } 193 188 194 private static boolean isApi(String file){ 189 return file.endsWith( API_SUFFIX);195 return file.endsWith(ProjectProperties.API_SOURCE_SUFFIX); 190 196 } 191 197 192 198 private static boolean isComponent(String file){ 193 return file.endsWith(COMPONENT_SUFFIX); 194 } 195 196 private static APIName apiName( String file ){ 197 if ( file.endsWith( COMPONENT_SUFFIX ) || file.endsWith( API_SUFFIX ) ){ 199 return file.endsWith(ProjectProperties.COMP_SOURCE_SUFFIX); 200 } 201 202 private static APIName cuName( String file ){ 203 if ( file.endsWith( ProjectProperties.COMP_SOURCE_SUFFIX ) || 204 file.endsWith( ProjectProperties.API_SOURCE_SUFFIX ) ){ 198 205 return NodeFactory.makeAPIName(file.substring( 0, file.lastIndexOf(".") )); 199 206 } 200 207 return NodeFactory.makeAPIName(file); 208 } 209 210 /** 211 * Compile a file. 212 * If you want a dump then give -out somefile. 213 */ 214 static void compile(List<String> args, Option<String> out) 215 throws UserError, InterruptedException, IOException { 216 if (args.size() == 0) { 217 throw new UserError("Need a file to compile"); 218 } 219 String s = args.get(0); 220 List<String> rest = args.subList(1, args.size()); 221 222 if (s.startsWith("-")) { 223 if (s.equals("-debug")){ 224 Debug.setDebug( 99 ); 225 if ( ! rest.isEmpty() && isInteger( rest.get( 0 ) ) ){ 226 Debug.setDebug( Integer.valueOf( rest.get( 0 ) ) ); 227 rest = rest.subList( 1, rest.size() ); 228 } else { 229 ProjectProperties.debug = true; 230 } 231 } 232 if (s.equals("-out") && ! rest.isEmpty() ){ 233 out = Option.<String>some(rest.get(0)); 234 rest = rest.subList(1, rest.size()); 235 } 236 if (s.equals("-noPreparse")) ProjectProperties.noPreparse = true; 237 compile(rest, out); 238 } else { 239 compile(s, out ); 240 } 201 241 } 202 242 … … 211 251 * @throws IOException 212 252 */ 213 static void compile(boolean doLink, String s, Option<String> out) throws UserError, InterruptedException, IOException { 253 static void compile(String s, Option<String> out) 254 throws UserError, InterruptedException { 214 255 try { 215 //FortressRepository fileBasedRepository = new FileBasedRepository(shell.getPwd()); 216 FortressRepository repository = new CacheBasedRepository(fortressLocation()); 256 FortressRepository repository = new CacheBasedRepository(ProjectProperties.ANALYZED_CACHE_DIR); 217 257 Fortress fortress = new Fortress(repository); 218 258 219 259 Path path = ProjectProperties.SOURCE_PATH; 220 260 261 /* 1) Not for parse 262 2) What if there are multiple "/"s 263 */ 221 264 if (s.contains("/")) { 222 265 String head = s.substring(0, s.lastIndexOf("/")); … … 231 274 System.err.println(error); 232 275 } 276 // If there are no errors, all components will have been written to disk by the CacheBasedRepository. 233 277 } else if ( out.isSome() ){ 234 278 try{ 235 279 if ( isApi(s) ){ 236 ASTIO.writeJavaAst(repository.getApi( apiName(s)).ast(), out.unwrap());280 ASTIO.writeJavaAst(repository.getApi(cuName(s)).ast(), out.unwrap()); 237 281 } else if ( isComponent(s) ){ 238 ASTIO.writeJavaAst(repository.getComponent( apiName(s)).ast(), out.unwrap());282 ASTIO.writeJavaAst(repository.getComponent(cuName(s)).ast(), out.unwrap()); 239 283 } else { 240 284 System.out.println( "Don't know what kind of file " + s + " is. Append .fsi or .fss." ); 241 285 } 242 } catch ( FileNotFoundException e ){243 System.out.println( "Could not find file " + s );244 286 } catch ( IOException e ){ 245 System.out.println( "Error while writing " + out.unwrap() ); 246 } 247 } 248 // If there are no errors, all components will have been written to disk by the FileBasedRepository. 249 } 250 catch (RepositoryError error) { 287 System.err.println( "Error while writing " + out.unwrap() ); 288 } 289 } 290 } catch (RepositoryError error) { 251 291 System.err.println(error); 252 292 } 253 293 } 254 294 255 static void compile(boolean doLink, List<String> args, Option<String> out) throws UserError, InterruptedException, IOException { 295 /** 296 * Run a file. 297 */ 298 static void run(List<String> args) 299 throws UserError, IOException, Throwable { 256 300 if (args.size() == 0) { 257 throw new UserError("Need a file to compile");301 throw new UserError("Need a file to run"); 258 302 } 259 303 String s = args.get(0); … … 270 314 } 271 315 } 272 if (s.equals("-out") && ! rest.isEmpty() ){273 out = Option.wrap(rest.get(0));274 rest = rest.subList(1, rest.size());275 }276 316 if (s.equals("-test")) test = true; 277 if (s.equals("-noPreparse")) ProjectProperties.noPreparse = true;278 compile( doLink, rest, out);279 } else {280 compile( doLink, s, out );281 }282 }283 284 private static boolean isInteger( String s ){285 try{286 int i = Integer.valueOf(s);287 return i == i;288 } catch ( NumberFormatException n ){289 return false;290 }291 }292 293 static void run(List<String> args) throws UserError, IOException, Throwable {294 if (args.size() == 0) {295 throw new UserError("Need a file to run");296 }297 String s = args.get(0);298 List<String> rest = args.subList(1, args.size());299 300 if (s.startsWith("-")) {301 if (s.equals("-debug")){302 Debug.setDebug( 99 );303 if ( ! rest.isEmpty() && isInteger( rest.get( 0 ) ) ){304 Debug.setDebug( Integer.valueOf( rest.get( 0 ) ) );305 rest = rest.subList( 1, rest.size() );306 } else {307 ProjectProperties.debug = true;308 }309 }310 if (s.equals("-test")) test= true;311 317 if (s.equals("-noPreparse")) ProjectProperties.noPreparse = true; 312 318 run(rest); … … 315 321 } 316 322 } 317 static void run(String fileName, List<String> args) throws UserError, IOException, Throwable { 323 324 static void run(String fileName, List<String> args) 325 throws UserError, Throwable { 318 326 try { 319 //FortressRepository fileBasedRepository = new FileBasedRepository(shell.getPwd());320 327 Fortress fortress = new Fortress(new CacheBasedRepository(ProjectProperties.ANALYZED_CACHE_DIR)); 321 328 … … 328 335 } 329 336 330 /* 331 * Strip suffix to get a bare component name. 332 */ 333 if (fileName.endsWith("." + ProjectProperties.COMP_SOURCE_SUFFIX)) { 334 fileName = fileName.substring(0, fileName.length() - ProjectProperties.COMP_SOURCE_SUFFIX.length()); 335 } 336 337 Iterable<? extends StaticError> errors = fortress.run(path, fileName, test, args); 337 Iterable<? extends StaticError> errors = fortress.run(path, cuName(fileName), test, args); 338 338 339 339 for (StaticError error: errors) { 340 340 System.err.println(error); 341 341 } 342 // If there are no errors, all components will have been written to disk by the FileBasedRepository.342 // If there are no errors, all components will have been written to disk by the CacheBasedRepository. 343 343 } catch ( StaticError e ){ 344 344 System.err.println(e); trunk/ProjectFortress/src/com/sun/fortress/compiler/Fortress.java
r2125 r2132 316 316 } 317 317 318 public Iterable<? extends StaticError> run(Path path, StringcomponentName, boolean test, List<String> args) {318 public Iterable<? extends StaticError> run(Path path, APIName componentName, boolean test, List<String> args) { 319 319 FortressRepository bcr = Driver.specificRepository(path); 320 320 321 /*322 if (! (_bcr instanceof BatchCachingAnalyzingRepository) ) {323 throw new ProgramError("Please set property fortress.static.analysis=1.");324 }325 */326 327 // BatchCachingAnalyzingRepository bcr = (BatchCachingAnalyzingRepository) _bcr;328 /*329 bcr.setVerbose(ProjectProperties.debug);330 Parser.Result result = compileInner(bcr, componentName);331 if (!result.isSuccessful()) { return result.errors(); }332 333 if (bcr.verbose())334 System.err.println("Parsing done.");335 */336 337 321 try { 338 CompilationUnit cu = bcr.getLinkedComponent( NodeFactory.makeAPIName(componentName)).ast();322 CompilationUnit cu = bcr.getLinkedComponent(componentName).ast(); 339 323 Driver.runProgram(bcr, cu, test, args); 340 324 } catch (Throwable th) { trunk/ProjectFortress/src/com/sun/fortress/repository/CacheBasedRepository.java
r2127 r2132 108 108 109 109 try { 110 111 if (ast instanceof Component) { 112 ASTIO.writeJavaAst(ast, compFileName(ast.getName() )); 113 } 114 else { // ast instanceof Api 115 ASTIO.writeJavaAst(ast, apiFileName(ast.getName() )); 116 } 110 ASTIO.writeJavaAst(ast, apiFileName(ast.getName() )); 117 111 } catch (IOException e) { 118 112 throw new ShellException(e); … … 125 119 if (! actual.equals(name)) { 126 120 boolean flag = actual.equals(name); 127 throw new RepositoryError(a st.getName()+ " cannot be cached under name " + name);121 throw new RepositoryError(actual + " cannot be cached under name " + name); 128 122 } 129 123 } … … 143 137 144 138 try { 145 name = ast.getName(); 146 ASTIO.writeJavaAst(ast, compFileName(name)); 139 ASTIO.writeJavaAst(ast, compFileName(ast.getName())); 147 140 } catch (IOException e) { 148 141 throw new ShellException(e); trunk/ProjectFortress/src/com/sun/fortress/unicode/OperatorStuffGenerator.java
r2119 r2132 1 1 /******************************************************************************* 2 Copyright 200 7Sun Microsystems, Inc.,2 Copyright 2008 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. trunk/ProjectFortress/src/com/sun/fortress/useful/ConvenientStrings.java
r2127 r2132 1 1 /******************************************************************************* 2 Copyright 200 7Sun Microsystems, Inc.,2 Copyright 2008 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved.
