Changeset 1048
- Timestamp:
- 12/04/07 10:00:12 (1 year ago)
- Files:
-
- trunk/ProjectFortress/astgen/Fortress.ast (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/compiler/CompilerTopLevelJUTest.java (modified) (7 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/compiler/Fortress.java (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/EmptyTypeEnv.java (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/NonEmptyTypeEnv.java (modified) (2 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeEnv.java (modified) (2 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeEnvJUTest.java (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/shell/FileBasedRepository.java (modified) (3 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/syntaxabstractions/parser/FortressParser.java (modified) (2 diffs)
- trunk/ProjectFortress/static_tests/LocalVarRef.fss (modified) (1 diff)
- trunk/ProjectFortress/static_tests/SimpleApi.fss (modified) (1 diff)
- trunk/ProjectFortress/static_tests/SimpleProgram.fss (modified) (1 diff)
- trunk/ProjectFortress/static_tests/lib (added)
- trunk/ProjectFortress/static_tests/lib/FortressBuiltin.tfs (added)
- trunk/ProjectFortress/static_tests/lib/FortressLibrary.tfs (added)
- trunk/ProjectFortress/static_tests/lib/NativeArray.tfs (added)
- trunk/ProjectFortress/static_tests/lib/NativeThread.tfs (added)
- trunk/ProjectFortress/test_library/FortressBuiltin.fsi (added)
- trunk/ProjectFortress/test_library_native/FortressBuiltin.fss (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ProjectFortress/astgen/Fortress.ast
r1040 r1048 1185 1185 */ 1186 1186 UnitArg(UnitExpr unit); 1187 _RewriteImplicitType(); 1187 1188 /** 1188 1189 * static expression trunk/ProjectFortress/src/com/sun/fortress/compiler/CompilerTopLevelJUTest.java
r922 r1048 20 20 import junit.framework.TestCase; 21 21 import java.io.File; 22 import java.io.IOException; 22 23 import java.util.Map; 23 24 import java.util.List; … … 35 36 import com.sun.fortress.compiler.index.ComponentIndex; 36 37 import com.sun.fortress.nodes.DottedName; 38 import com.sun.fortress.shell.FileBasedRepository; 37 39 38 40 import com.sun.fortress.interpreter.drivers.ProjectProperties; … … 44 46 // relative to the top ProjectFortress directory 45 47 private static String baseDir = ProjectProperties.BASEDIR; 48 private static String staticTests = baseDir + "static_tests/"; 46 49 47 50 private static final List<String> NOT_PASSING = Arrays.asList( 48 baseDir + "static_tests/SimpleProgram.fss", 49 baseDir + "static_tests/SimpleApi.fss", 50 baseDir + "static_tests/LocalFnRef.fss", 51 baseDir + "static_tests/LocalVarRef.fss", 52 baseDir + "static_tests/stub to eliminate comma trouble" 51 staticTests + "XXXMultipleRefErrors.fss", 52 staticTests + "XXXUndefinedArrayRef.fss", 53 staticTests + "XXXUndefinedInitializer.fss", 54 staticTests + "XXXUndefinedNestedRef.fss", 55 staticTests + "XXXUndefinedRefInLoop.fss", 56 staticTests + "XXXUndefinedVar.fss", 57 staticTests + "stub to eliminate comma trouble" 53 58 ); 54 59 … … 58 63 })); 59 64 60 public void testStaticTests() {65 public void testStaticTests() throws IOException { 61 66 boolean foundAFile = false; 62 67 Predicate<File> filter = IOUtil.extensionFilePredicate("fss", IOUtil.IS_FILE); 63 for (File f : IOUtil.listFilesRecursively(new File( baseDir + "static_tests"), filter)) {68 for (File f : IOUtil.listFilesRecursively(new File(staticTests), filter)) { 64 69 foundAFile = true; 65 70 if (SKIP_NOT_PASSING && NOT_PASSING_FILES.contains(f)) { continue; } … … 70 75 } 71 76 72 private void assertMalformedProgram(File f) {77 private void assertMalformedProgram(File f) throws IOException { 73 78 Iterable<? extends StaticError> errors = compile(f); 74 79 assertFalse("Source " + f + " was compiled without error", … … 80 85 } 81 86 82 private void assertWellFormedProgram(File f) {87 private void assertWellFormedProgram(File f) throws IOException { 83 88 Iterable<? extends StaticError> errors = compile(f); 84 89 String message = "Source " + f + " produces static errors:\n" + … … 88 93 } 89 94 90 private Iterable<? extends StaticError> compile(File f) {95 private Iterable<? extends StaticError> compile(File f) throws IOException { 91 96 final Map<DottedName, ApiIndex> apis = new HashMap<DottedName, ApiIndex>(); 92 Fortress fortress = new Fortress(new FortressRepository() { 93 public Map<DottedName, ApiIndex> apis() { 94 return Collections.unmodifiableMap(apis); 95 } 96 public void addApi(DottedName name, ApiIndex def) { 97 apis.put(name, def); 98 } 99 public void addComponent(DottedName name, ComponentIndex def) { 100 /* ignore */ 101 } 102 }); 97 Fortress fortress = new Fortress(new FileBasedRepository(baseDir, staticTests + "lib")); 98 // new FortressRepository() { 99 // public Map<DottedName, ApiIndex> apis() { 100 // return Collections.unmodifiableMap(apis); 101 // } 102 // public void addApi(DottedName name, ApiIndex def) { 103 // apis.put(name, def); 104 // } 105 // public void addComponent(DottedName name, ComponentIndex def) { 106 // /* ignore */ 107 // } 108 // }); 103 109 return fortress.compile(f); 104 110 } trunk/ProjectFortress/src/com/sun/fortress/compiler/Fortress.java
r1043 r1048 50 50 public Iterable<? extends StaticError> compile(Iterable<File> files) { 51 51 GlobalEnvironment env = new GlobalEnvironment(_repository.apis()); 52 52 53 53 FortressParser.Result pr = FortressParser.parse(files, env); 54 54 // Parser.Result pr = Parser.parse(files, env); 55 55 if (!pr.isSuccessful()) { return pr.errors(); } 56 System.out.println(" parsing done.");56 System.out.println("Parsing done."); 57 57 58 58 // Handle APIs first trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/EmptyTypeEnv.java
r1036 r1048 32 32 33 33 public Option<LValueBind> binding(IdName var) { return none(); } 34 public Option< Option<Type>> type(IdName var) { return none(); }34 public Option<Type> type(IdName var) { return none(); } 35 35 public Option<List<Modifier>> mods(IdName var) { return none(); } 36 36 public Option<Boolean> mutable(IdName var) { return none(); } trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/NonEmptyTypeEnv.java
r1034 r1048 19 19 20 20 import com.sun.fortress.nodes.*; 21 import com.sun.fortress.nodes_util.NodeFactory; 21 22 import edu.rice.cs.plt.tuple.Option; 22 23 import java.util.*; … … 42 43 } 43 44 44 public Option<Option<Type>> type(IdName var) { 45 Option<LValueBind> binding = binding(var); 45 public Option<Type> type(IdName var) { 46 for (int i = 0; i < entries.length; i++) { 47 LValueBind entry = entries[i]; 48 49 if (var.equals(entry.getName())) { 50 Option<Type> type = entry.getType(); 51 if (type.isSome()) { 52 return type; 53 } else { 54 Type implicitType = new _RewriteImplicitType(); 55 entries[i] = 56 NodeFactory.makeLValue(entry, implicitType); 57 return wrap(implicitType); 58 } 59 } 60 } 61 return Option.none(); 62 } 46 63 47 if (binding.isSome()) { return wrap(unwrap(binding).getType()); }48 else { return Option.none(); }49 }50 51 52 64 public Option<List<Modifier>> mods(IdName var) { 53 65 Option<LValueBind> binding = binding(var); trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeEnv.java
r1036 r1048 24 24 import static com.sun.fortress.nodes_util.NodeFactory.makeIdName; 25 25 26 26 /** 27 * This class is used by the type checker to represent static type environments, 28 * mapping bound variables to their types. 29 */ 27 30 public abstract class TypeEnv { 28 31 public static TypeEnv make(LValueBind... entries) { … … 31 34 32 35 public abstract Option<LValueBind> binding(IdName var); 33 public abstract Option< Option<Type>> type(IdName var);36 public abstract Option<Type> type(IdName var); 34 37 public abstract Option<List<Modifier>> mods(IdName var); 35 38 public abstract Option<Boolean> mutable(IdName var); 36 39 37 public Option< Option<Type>> type(String var) { return type(makeIdName(var)); }40 public Option<Type> type(String var) { return type(makeIdName(var)); } 38 41 public Option<List<Modifier>> mods(String var) { return mods(makeIdName(var)); } 39 42 public Option<Boolean> mutable(String var) { return mutable(makeIdName(var)); } 40 43 44 /** 45 * Produce a new type environment extending this with the given variable bindings. 46 */ 41 47 public TypeEnv extend(LValueBind... entries) { 42 48 if (entries.length == 0) { return EmptyTypeEnv.ONLY; } trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeEnvJUTest.java
r1036 r1048 54 54 55 55 public void testLookupType() { 56 assertEquals(FOO, unwrap( unwrap(extended.type("x"))));57 assertEquals(BAZ, unwrap( unwrap(extended.type("y"))));58 assertEquals(BAR, unwrap( unwrap(extended.type("z"))));56 assertEquals(FOO, unwrap(extended.type("x"))); 57 assertEquals(BAZ, unwrap(extended.type("y"))); 58 assertEquals(BAR, unwrap(extended.type("z"))); 59 59 60 assert(! (BAR.equals(unwrap( unwrap(extended.type("x"))))));60 assert(! (BAR.equals(unwrap(extended.type("x"))))); 61 61 } 62 62 trunk/ProjectFortress/src/com/sun/fortress/shell/FileBasedRepository.java
r1024 r1048 37 37 new HashMap<DottedName, ComponentIndex>(); 38 38 private final String pwd; 39 private final String path = Shell.fortressLocation();39 private final String path; 40 40 41 41 public FileBasedRepository(String _pwd) throws IOException { 42 this(_pwd, Shell.fortressLocation()); 43 } 44 45 public FileBasedRepository(String _pwd, String _path) throws IOException { 42 46 pwd = _pwd; 47 path = _path; 43 48 initialize(); 44 49 } … … 49 54 50 55 for (File file: files) { 51 System.err.println("Loading " + file); 52 53 Option<CompilationUnit> candidate = 54 Driver.readJavaAst(file.getCanonicalPath()); 55 56 if (candidate.isNone()) { 57 throw new RepositoryError ("Compilation aborted. " + 58 "There were problems reading back the compiled file " + 59 file.getCanonicalPath()); 56 if (! file.isDirectory()) { 57 System.err.println("Loading " + file); 58 59 Option<CompilationUnit> candidate = 60 Driver.readJavaAst(file.getCanonicalPath()); 61 62 if (candidate.isNone()) { 63 throw new RepositoryError ("Compilation aborted. " + 64 "There were problems reading back the compiled file " + 65 file.getCanonicalPath()); 66 } 67 else { 68 CompilationUnit _candidate = Option.unwrap(candidate); 69 70 if (_candidate instanceof Api) { 71 ArrayList<Api> _candidates = new ArrayList<Api>(); 72 _candidates.add((Api)_candidate); 73 apis.putAll(IndexBuilder.buildApis(_candidates).apis()); 74 } else if (_candidate instanceof Component) { 75 ArrayList<Component> _candidates = new ArrayList<Component>(); 76 _candidates.add((Component)_candidate); 77 78 components.putAll(IndexBuilder.buildComponents(_candidates).components()); 79 80 ArrayList<Id> _ids = new ArrayList<Id>(); 81 for (Id id: _candidate.getName().getIds()) { _ids.add(new Id(new String(id.getText()))); } 82 83 84 } else { 85 throw new RuntimeException("The file " + file.getName() + " parsed to something other than a component or API!"); 86 } 87 } 60 88 } 61 else {62 CompilationUnit _candidate = Option.unwrap(candidate);63 64 if (_candidate instanceof Api) {65 ArrayList<Api> _candidates = new ArrayList<Api>();66 _candidates.add((Api)_candidate);67 apis.putAll(IndexBuilder.buildApis(_candidates).apis());68 } else if (_candidate instanceof Component) {69 ArrayList<Component> _candidates = new ArrayList<Component>();70 _candidates.add((Component)_candidate);71 72 components.putAll(IndexBuilder.buildComponents(_candidates).components());73 74 ArrayList<Id> _ids = new ArrayList<Id>();75 for (Id id: _candidate.getName().getIds()) { _ids.add(new Id(new String(id.getText()))); }76 77 78 } else {79 throw new RuntimeException("The file " + file.getName() + " parsed to something other than a component or API!");80 }81 }82 89 } 83 } 84 90 } 85 91 86 92 public Map<DottedName, ApiIndex> apis() { return apis; } … … 96 102 if (ast instanceof Component) { 97 103 Driver.writeJavaAst(ast, pwd + SEP + ast.getName() + 98 DOT + Driver.COMP_TREE_SUFFIX);104 DOT + Driver.COMP_TREE_SUFFIX); 99 105 } 100 106 else { // ast instanceof Api 101 107 Driver.writeJavaAst(ast, pwd + SEP + ast.getName() + 102 DOT + Driver.API_TREE_SUFFIX);108 DOT + Driver.API_TREE_SUFFIX); 103 109 } 104 110 } catch (IOException e) { trunk/ProjectFortress/src/com/sun/fortress/syntaxabstractions/parser/FortressParser.java
r1044 r1048 56 56 57 57 public Result(Iterable<? extends StaticError> errors) { 58 super(errors);59 _apis = IterUtil.empty();60 _components = IterUtil.empty(); 61 }62 63 public Result(Component component) {58 super(errors); 59 _apis = IterUtil.empty(); 60 _components = IterUtil.empty(); 61 } 62 63 public Result(Component component) { 64 64 _components = IterUtil.singleton(component); 65 65 _apis = IterUtil.empty(); … … 144 144 BufferedReader in = Useful.utf8BufferedFileReader(f); 145 145 try { 146 147 PreParser.Result ppr = PreParser.parse(f, env);148 if (!ppr.isSuccessful()) { return new Result(ppr.errors()); }149 150 xtc.parser.Result parseResult = null;151 ParserBase p = null;152 153 System.out.print("Parsing file: "+f.getName());154 if (!ppr.getGrammars().isEmpty()) {155 156 // Compile the macro declarations and create a temporary parser157 MacroCompiler macroCompiler = new FileBasedMacroCompiler();158 MacroCompiler.Result tr = macroCompiler.compile(ppr.getGrammars());159 if (!tr.isSuccessful()) { return new Result(tr.errors()); }160 Class<?> temporaryParserClass = tr.getParserClass();161 162 try {163 p = ParserMediator.getParser(temporaryParserClass, in, f.toString());164 parseResult = ParserMediator.parse();165 } catch (Exception e) {166 String desc = "Error occured while instantiating and executing a temporary parser: "+temporaryParserClass.getCanonicalName();167 if (e.getMessage() != null) { desc += " (" + e.getMessage() + ")"; }168 return new Result(StaticError.make(desc, f.toString()));169 }170 171 }172 else {146 147 PreParser.Result ppr = PreParser.parse(f, env); 148 if (!ppr.isSuccessful()) { return new Result(ppr.errors()); } 149 150 xtc.parser.Result parseResult = null; 151 ParserBase p = null; 152 153 System.out.println("Parsing file: "+f.getName()); 154 if (!ppr.getGrammars().isEmpty()) { 155 156 // Compile the macro declarations and create a temporary parser 157 MacroCompiler macroCompiler = new FileBasedMacroCompiler(); 158 MacroCompiler.Result tr = macroCompiler.compile(ppr.getGrammars()); 159 if (!tr.isSuccessful()) { return new Result(tr.errors()); } 160 Class<?> temporaryParserClass = tr.getParserClass(); 161 162 try { 163 p = ParserMediator.getParser(temporaryParserClass, in, f.toString()); 164 parseResult = ParserMediator.parse(); 165 } catch (Exception e) { 166 String desc = "Error occured while instantiating and executing a temporary parser: "+temporaryParserClass.getCanonicalName(); 167 if (e.getMessage() != null) { desc += " (" + e.getMessage() + ")"; } 168 return new Result(StaticError.make(desc, f.toString())); 169 } 170 171 } 172 else { 173 173 p = new com.sun.fortress.parser.Fortress(in, f.toString()); 174 174 parseResult = ((com.sun.fortress.parser.Fortress) p).pFile(0); 175 }176 175 } 176 177 177 178 178 if (parseResult.hasValue()) { trunk/ProjectFortress/static_tests/LocalVarRef.fss
r727 r1048 20 20 21 21 run(args:String...):() = do 22 x:ZZ = 2323 y:ZZ = x22 x:ZZ64 = 23 23 y:ZZ64 = x 24 24 () 25 25 end trunk/ProjectFortress/static_tests/SimpleApi.fss
r709 r1048 18 18 api SimpleApi 19 19 20 x:ZZ 21 f(num:ZZ ):ZZ20 x:ZZ64 21 f(num:ZZ64): ZZ64 22 22 23 23 end trunk/ProjectFortress/static_tests/SimpleProgram.fss
r709 r1048 19 19 export Executable 20 20 21 x:ZZ = 2322 f(num:ZZ ):ZZ= num + 121 x:ZZ64 = 23 22 f(num:ZZ64): ZZ64 = num + 1 23 23 24 24 run(args:String...):() = do 25 z:ZZ = f(x) * f(10)25 z:ZZ64 = f(x) * f(10) 26 26 () 27 27 end
