Changeset 3078
- Timestamp:
- 11/18/08 12:54:36 (12 months ago)
- Location:
- trunk
- Files:
-
- 19 modified
-
Library/FortressSyntax.fsi (modified) (1 diff)
-
ProjectFortress/astgen/Fortress.ast (modified) (3 diffs)
-
ProjectFortress/src/com/sun/fortress/compiler/desugarer/ObjectExpressionVisitor.java (modified) (1 diff)
-
ProjectFortress/src/com/sun/fortress/compiler/disambiguator/TopLevelEnv.java (modified) (31 diffs)
-
ProjectFortress/src/com/sun/fortress/compiler/environments/TopLevelEnvGen.java (modified) (29 diffs)
-
ProjectFortress/src/com/sun/fortress/compiler/index/ComponentIndex.java (modified) (3 diffs)
-
ProjectFortress/src/com/sun/fortress/compiler/typechecker/SubtypeCheckerJUTest.java (modified) (1 diff)
-
ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeAnalyzerJUTest.java (modified) (3 diffs)
-
ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeChecker.java (modified) (2 diffs)
-
ProjectFortress/src/com/sun/fortress/interpreter/Driver.java (modified) (2 diffs)
-
ProjectFortress/src/com/sun/fortress/interpreter/env/CUWrapper.java (modified) (13 diffs)
-
ProjectFortress/src/com/sun/fortress/interpreter/env/ComponentWrapper.java (modified) (9 diffs)
-
ProjectFortress/src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java (modified) (2 diffs)
-
ProjectFortress/src/com/sun/fortress/nodes_util/NodeUtil.java (modified) (2 diffs)
-
ProjectFortress/src/com/sun/fortress/parser/Compilation.rats (modified) (1 diff)
-
ProjectFortress/src/com/sun/fortress/parser/preparser/PreCompilation.rats (modified) (2 diffs)
-
ProjectFortress/src/com/sun/fortress/syntax_abstractions/parser/PreParser.java (modified) (1 diff)
-
ProjectFortress/src/com/sun/fortress/tests/unit_tests/ConstructorsJUTest.java (modified) (2 diffs)
-
ProjectFortress/src/com/sun/fortress/tools/FortressAstToConcrete.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Library/FortressSyntax.fsi
r3077 r3078 29 29 Component : Component 30 30 Api : Api 31 Exports : List[\Export\] 32 Export : Export 31 Exports : List[\APIName\] 33 32 Imports : List[\Import\] 34 33 Import : Import -
trunk/ProjectFortress/astgen/Fortress.ast
r3077 r3078 162 162 * component declaration 163 163 * Component ::= native? component APIName Imports? Exports Decls? end 164 * Export ::= export APINames 164 165 * e.g.) component Hello 165 166 * export Executable … … 168 169 */ 169 170 Component(boolean _native = false, APIName name, List<Import> imports, 170 List< Export> exports, List<Decl> decls,171 List<APIName> exports, List<Decl> decls, 171 172 List<_RewriteObjectExpr> objectExprs = 172 173 Collections.<_RewriteObjectExpr>emptyList(), … … 226 227 AliasedAPIName(APIName api, 227 228 Option<Id> alias = Option.<Id>none()); 228 /**229 * export statement230 * Export ::= export APINames231 * e.g.) export Executable232 */233 Export(List<APIName> apis);234 229 /** 235 230 * trait or object declaration in components or APIs -
trunk/ProjectFortress/src/com/sun/fortress/compiler/desugarer/ObjectExpressionVisitor.java
r3077 r3078 170 170 public Node forComponentOnly(Component that, APIName name_result, 171 171 List<Import> imports_result, 172 List< Export> exports_result,172 List<APIName> exports_result, 173 173 List<Decl> decls_result, 174 174 List<_RewriteObjectExpr> objectExprs) { -
trunk/ProjectFortress/src/com/sun/fortress/compiler/disambiguator/TopLevelEnv.java
r3071 r3078 46 46 import com.sun.fortress.nodes.Component; 47 47 import com.sun.fortress.nodes.Enclosing; 48 import com.sun.fortress.nodes.Export;49 48 import com.sun.fortress.nodes.Id; 50 49 import com.sun.fortress.nodes.IdOrOpName; … … 76 75 public class TopLevelEnv extends NameEnv { 77 76 private static final Set<String> WELL_KNOWN_APIS = Useful.set(WellKnownNames.fortressLibrary, WellKnownNames.fortressBuiltin, WellKnownNames.anyTypeName); 78 77 79 78 private final GlobalEnvironment _originalGlobalEnv; // environment as it is created by the compiler 80 79 private final GlobalEnvironment _filteredGlobalEnv; // environment that only includes "imported" names … … 95 94 _current = current; 96 95 _errors = errors; 97 96 98 97 GlobalEnvironment filtered_global_env; 99 98 if( current instanceof ApiIndex ) { … … 105 104 // Filter env based on what this component imports 106 105 Map<APIName,ApiIndex> filtered = filterApis(globalEnv.apis(), ((Component)current.ast())); 107 filtered_global_env = new GlobalEnvironment.FromMap(filtered); 106 filtered_global_env = new GlobalEnvironment.FromMap(filtered); 108 107 } 109 108 else { … … 111 110 } 112 111 _filteredGlobalEnv = filtered_global_env; 113 112 114 113 _onDemandImportedApis = Collections.unmodifiableMap(initializeOnDemandImportedApis(filtered_global_env, current)); 115 114 _onDemandTypeConsNames = Collections.unmodifiableMap(initializeOnDemandTypeConsNames(_onDemandImportedApis)); … … 123 122 124 123 /** 125 * Initializes the map of imported API names to ApiIndices. 124 * Initializes the map of imported API names to ApiIndices. 126 125 * Adds all imported and implicitly imported 127 126 * Apis to a map that it returns. … … 131 130 // TODO: Fix to support other kinds of imports. 132 131 Set<APIName> imports = current.imports(); 133 Map<APIName, ApiIndex> result = new HashMap<APIName, ApiIndex>(); 132 Map<APIName, ApiIndex> result = new HashMap<APIName, ApiIndex>(); 134 133 135 134 // The following APIs are always imported, provided they exist. … … 184 183 // TODO: Fix to support explicit imports and api imports. I don't think this is still a 'to-do' 185 184 Map<Id, Set<Id>> result = new HashMap<Id, Set<Id>>(); 186 185 187 186 for (Map.Entry<APIName, ApiIndex> apiEntry: imported_apis.entrySet()) { 188 187 for (Map.Entry<Id, TypeConsIndex> typeEntry: apiEntry.getValue().typeConses().entrySet()) { … … 216 215 217 216 private static OpName copyOpNameWithNewAPIName(OpName op, final APIName api) { 218 OpName result = 217 OpName result = 219 218 op.accept(new NodeDepthFirstVisitor<OpName>(){ 220 219 @Override … … 232 231 return result; 233 232 } 234 233 235 234 private static Pair<Map<Id, Set<Id>>, Map<OpName, Set<OpName>>> initializeOnDemandFunctionNames(Map<APIName, ApiIndex> imported_apis) { 236 235 Map<Id, Set<Id>> fun_result = new HashMap<Id, Set<Id>>(); 237 236 Map<OpName, Set<OpName>> ops_result = new HashMap<OpName, Set<OpName>>(); 238 237 239 238 for (Map.Entry<APIName, ApiIndex> apiEntry: imported_apis.entrySet()) { 240 239 for (IdOrOpOrAnonymousName fnName: apiEntry.getValue().functions().firstSet()) { … … 253 252 fun_result.put(_fnName, matches); 254 253 } 255 } 254 } 256 255 else { // fnName instanceof OpName 257 256 OpName _opName = (OpName)fnName; … … 299 298 } 300 299 } 301 300 302 301 @Override 303 302 public Option<StaticParam> hasTypeParam(IdOrOpName name) { … … 321 320 _current.units().containsKey(name)) { 322 321 323 // A name defined in this CU should only be qualified if this is an API 322 // A name defined in this CU should only be qualified if this is an API 324 323 Id result_id; 325 324 if( _current instanceof ApiIndex ) … … 327 326 else if( _current instanceof ComponentIndex ) 328 327 result_id = apiQualifyIfComponentExports(((ComponentIndex)_current), name); 329 else 328 else 330 329 result_id = name; 331 330 … … 345 344 private Id apiQualifyIfComponentExports(ComponentIndex comp, Id name) { 346 345 Option<Id> result_ = Option.none(); 347 346 348 347 for( APIName api_name : comp.exports() ) { 349 348 350 349 // TODO: We don't really need this, but for now since there is no Executable... 351 350 if( !_originalGlobalEnv.definesApi(api_name) ) continue; 352 351 353 352 ApiIndex api = _originalGlobalEnv.api(api_name); 354 353 355 354 if( api.typeConses().containsKey(name) ) { 356 if( result_.isSome() ) 355 if( result_.isSome() ) 357 356 return NI.nyi("Disambiguator cannot yet handle the same Component providing the implementation for multiple APIs: " + name); 358 357 359 358 result_ = Option.some(NodeFactory.makeId(api_name, name, name.getSpan())); 360 359 } 361 360 } 362 361 363 362 if( result_.isNone() ) 364 363 return name; … … 367 366 } 368 367 369 public Set<Id> explicitVariableNames(Id name) { 368 public Set<Id> explicitVariableNames(Id name) { 370 369 Set<Id> result = Collections.emptySet(); 371 370 if (_current.variables().containsKey(name) || 372 371 _current.units().containsKey(name)) { 373 372 374 373 // A name defined in this CU should only be qualified if this is an API 375 374 Id result_id; … … 394 393 public Set<Id> explicitFunctionNames(Id name) { 395 394 Set<Id> result = Collections.emptySet(); 396 395 397 396 // Add fns from this component 398 397 if (_current.functions().containsFirst(name)) { … … 403 402 else 404 403 result_id = name; 405 404 406 405 result = CollectUtil.union(result, Collections.singleton(result_id)); 407 406 } 408 407 409 408 // Also add imports 410 409 result = CollectUtil.union(result, this.onDemandFunctionNames(name)); … … 424 423 else 425 424 result_id = name; 426 425 427 426 result = CollectUtil.union(result, Collections.singleton(result_id)); 428 427 } … … 584 583 } 585 584 } 586 585 587 586 /** 588 587 * Returns API names in the given list of exports that can be imported implicitly. 589 588 * This helps, for example, when compiling FortressLibrary, since that is one API that 590 * is normally imported implicitly. 589 * is normally imported implicitly. 591 590 */ 592 private static Set<APIName> findWellKnownExports(List<Export> exports) { 593 return IterUtil.fold(exports, new HashSet<APIName>(),new Lambda2<HashSet<APIName>,Export, HashSet<APIName>>(){ 594 public HashSet<APIName> value(HashSet<APIName> arg0, Export arg1) { 595 for( APIName api : arg1.getApis() ) { 596 if( WELL_KNOWN_APIS.contains(api.getText()) ) { 597 arg0.add(api); 598 } 591 private static Set<APIName> findWellKnownExports(List<APIName> exports) { 592 return IterUtil.fold(exports, new HashSet<APIName>(),new Lambda2<HashSet<APIName>,APIName, HashSet<APIName>>(){ 593 public HashSet<APIName> value(HashSet<APIName> arg0, APIName api) { 594 if( WELL_KNOWN_APIS.contains(api.getText()) ) { 595 arg0.add(api); 599 596 } 600 597 return arg0; 601 598 }}); 602 599 } 603 600 604 601 private static Map<APIName, ApiIndex> filterApis(Map<APIName,ApiIndex> apis, Component comp) { 605 602 Set<APIName> dont_import = findWellKnownExports(comp.getExports()); … … 611 608 // need them at a minimum. 612 609 Import this_api_import = new ImportStar(NodeFactory.makeSpan("implicit import, TopLevelEnv"), api.getName(), Collections.<IdOrOpOrAnonymousName>emptyList()); 613 return filterApis(Collections.unmodifiableMap(apis), 614 Useful.concat(Collections.singletonList(this_api_import), 610 return filterApis(Collections.unmodifiableMap(apis), 611 Useful.concat(Collections.singletonList(this_api_import), 615 612 api.getImports() 616 613 ) … … 618 615 } 619 616 620 private static <K, T> Map<K,T> filterMap(Map<K,T> map, Set<? super K> set, 617 private static <K, T> Map<K,T> filterMap(Map<K,T> map, Set<? super K> set, 621 618 Predicate<K> pred) { 622 619 623 620 Map<K,T> result = new HashMap<K,T>(); 624 621 for( Map.Entry<K, T> entry : map.entrySet() ) { … … 629 626 return result; 630 627 } 631 628 632 629 private static <K, T> Map<K,T> removeHelper(Map<K,T> map, final Set<? super K> set) { 633 630 Predicate<K> pred = new Predicate<K>() { … … 635 632 return !set.contains(arg1); 636 633 }}; 637 634 638 635 return filterMap(map, set, pred); 639 636 } 640 637 641 638 private static ApiIndex remove(ApiIndex index, 642 639 final Set<IdOrOpOrAnonymousName> exceptions_) { 643 640 644 641 Predicate2<IdOrOpOrAnonymousName,Function> pred = new Predicate2<IdOrOpOrAnonymousName,Function>(){ 645 642 … … 647 644 return !exceptions_.contains(arg0); 648 645 } 649 646 650 647 }; 651 648 652 649 return new ApiIndex((Api)index.ast(), 653 650 removeHelper(index.variables(), exceptions_), … … 659 656 index.modifiedDate()); 660 657 } 661 658 662 659 private static <K, T> Map<K,T> keepHelper(Map<K,T> map, final Set<? super K> set) { 663 660 Predicate<K> pred = new Predicate<K>() { … … 665 662 return set.contains(arg1); 666 663 }}; 667 664 668 665 return filterMap(map, set, pred); 669 666 } 670 667 671 668 private static ApiIndex keep(ApiIndex index, 672 669 final Set<IdOrOpOrAnonymousName> allowed_) { 673 670 674 671 Predicate2<IdOrOpOrAnonymousName,Function> pred = new Predicate2<IdOrOpOrAnonymousName,Function>(){ 675 672 … … 677 674 return allowed_.contains(arg0); 678 675 } 679 676 680 677 }; 681 678 682 679 return new ApiIndex((Api)index.ast(), 683 680 keepHelper(index.variables(), allowed_), … … 689 686 index.modifiedDate()); 690 687 } 691 688 692 689 /** 693 690 * Filter out whole apis or parts of apis based on the imports of a component or 694 * api. FortressBuiltin and AnyType are always imported, and FortressLibrary is only 691 * api. FortressBuiltin and AnyType are always imported, and FortressLibrary is only 695 692 * imported implicitly if it is not imported explicitly. If {@code do_not_import} contains 696 693 * api names, those apis will not beimported no matter what. 697 694 */ 698 private static Map<APIName,ApiIndex> filterApis(Map<APIName, ApiIndex> apis, List<Import> imports, Set<APIName> do_not_import) { 695 private static Map<APIName,ApiIndex> filterApis(Map<APIName, ApiIndex> apis, List<Import> imports, Set<APIName> do_not_import) { 699 696 final Map<APIName, Set<IdOrOpOrAnonymousName>> exceptions = new HashMap<APIName, Set<IdOrOpOrAnonymousName>>(); 700 697 final Map<APIName, Set<IdOrOpOrAnonymousName>> allowed = new HashMap<APIName, Set<IdOrOpOrAnonymousName>>(); … … 722 719 723 720 // TODO Handle these aliased names more thoroughly 724 List<IdOrOpOrAnonymousName> names = CollectUtil.makeList(IterUtil.map(that.getAliasedNames(), 721 List<IdOrOpOrAnonymousName> names = CollectUtil.makeList(IterUtil.map(that.getAliasedNames(), 725 722 new Lambda<AliasedSimpleName,IdOrOpOrAnonymousName>(){ 726 723 public IdOrOpOrAnonymousName value( … … 772 769 Set<IdOrOpOrAnonymousName> allowed_ = allowed.get(name); 773 770 result.put(name, keep(index, allowed_)); 774 } 771 } 775 772 else if( name.getText().equals(WellKnownNames.fortressBuiltin) ) { 776 773 // Fortress builtin is always implicitly imported -
trunk/ProjectFortress/src/com/sun/fortress/compiler/environments/TopLevelEnvGen.java
r2773 r3078 78 78 79 79 public static String mangleClassIdentifier(String identifier) { 80 String mangledString = identifier.replaceAll("\\.", "\\$"); 81 return mangledString; 82 } 83 80 String mangledString = identifier.replaceAll("\\.", "\\$"); 81 return mangledString; 82 } 83 84 84 /** 85 85 * http://blogs.sun.com/jrose/entry/symbolic_freedom_in_the_vm … … 115 115 mangledString = "\\=" + mangledString; 116 116 } 117 return mangledString; 117 return mangledString; 118 118 } 119 119 … … 146 146 return new CompilationUnitResult(compiledApis, errors); 147 147 } 148 148 149 149 /** 150 150 * Given a list of components, generate a Java bytecode compiled environment … … 232 232 ImportApi importApi = (ImportApi) imports; 233 233 for (AliasedAPIName api : importApi.getApis()) { 234 importedApiNames.add(NodeUtil.nameString(api.getApi())); 234 importedApiNames.add(NodeUtil.nameString(api.getApi())); 235 235 } 236 236 } else if (imports instanceof ImportedNames) { … … 241 241 } 242 242 } 243 243 244 244 // XXX: SUPER DUPER HACKY 245 245 // Rewrite the AST to include these builtin imports! 246 246 for(String builtinLib : WellKnownNames.defaultLibrary) { 247 importedApiNames.add(builtinLib); 248 } 249 247 importedApiNames.add(builtinLib); 248 } 249 250 250 // Any names that are exported, are also "imported", which is to say, 251 251 // the disambiguator will generate references to them, so we had better … … 253 253 if (comp instanceof Component) { 254 254 Component ccomp = (Component) comp; 255 for (Export e : ccomp.getExports()) { 256 for (APIName api : e.getApis()) { 257 importedApiNames.add(NodeUtil.nameString(api)); 258 } 259 } 260 } 261 262 namesToFields(EnvironmentClass.ENVIRONMENT, cw, symbolNames, importedApiNames); 255 for (APIName api : ccomp.getExports()) { 256 importedApiNames.add(NodeUtil.nameString(api)); 257 } 258 } 259 260 namesToFields(EnvironmentClass.ENVIRONMENT, cw, symbolNames, importedApiNames); 263 261 } 264 262 … … 271 269 // Create all variables as fields in the environment 272 270 Set<String> idStringSet = new HashSet<String>(); 273 for(Id id : compUnitIndex.variables().keySet()) { 271 for(Id id : compUnitIndex.variables().keySet()) { 274 272 String idString = NodeUtil.nameString(id); 275 273 if (idString.equals("_")) { … … 285 283 // apply further mangling. 286 284 } 287 idStringSet.add(idString); 288 } 289 namesToFields(EnvironmentClass.FVALUE, cw, symbolNames, idStringSet); 285 idStringSet.add(idString); 286 } 287 namesToFields(EnvironmentClass.FVALUE, cw, symbolNames, idStringSet); 290 288 291 289 // Create all functions as fields in the environment … … 293 291 for(IdOrOpOrAnonymousName id : compUnitIndex.functions().firstSet()) { 294 292 String idString = NodeUtil.nameString(id); 295 idStringSet.add(idString); 296 } 297 namesToFields(EnvironmentClass.FVALUE, cw, symbolNames, idStringSet); 293 idStringSet.add(idString); 294 } 295 namesToFields(EnvironmentClass.FVALUE, cw, symbolNames, idStringSet); 298 296 299 297 // Create all types as fields in the environment … … 303 301 idStringSet.add(idString); 304 302 } 305 namesToFields(EnvironmentClass.FTYPE, cw, symbolNames, idStringSet); 303 namesToFields(EnvironmentClass.FTYPE, cw, symbolNames, idStringSet); 306 304 307 305 // Special case for singleton objects; get to the object through … … 314 312 if (oti.constructor().isNone()) { 315 313 String idString = WellKnownNames.obfuscatedSingletonConstructorName(NodeUtil.nameString(id), id); 316 idStringSet.add(idString); 314 idStringSet.add(idString); 317 315 } 318 316 } 319 317 } 320 namesToFields(EnvironmentClass.FVALUE, cw, symbolNames, idStringSet); 321 318 namesToFields(EnvironmentClass.FVALUE, cw, symbolNames, idStringSet); 319 322 320 handleWeirdToplevelDecls(cw, compUnitIndex, symbolNames); 323 321 324 322 writeImportFields(cw, compUnitIndex, symbolNames); 325 323 } 326 324 327 325 /** 328 326 * Emits additional names for overloaded functions, 329 327 * for temporaries generated by multiple assignment/init, 330 328 * and for object expressions. 331 * 329 * 332 330 * @param cw 333 331 * @param compUnitIndex … … 355 353 } 356 354 } 357 355 358 356 // Scan for all object exprs in a component; the interpreter will 359 357 // promote those to top level. … … 373 371 compUnit.accept(visitor); 374 372 } 375 } 376 373 } 374 377 375 private static void namesToFields(EnvironmentClass nameSpace, 378 376 ClassWriter cw, EnvSymbolNames symbolNames, Set<String> idStringSet) { … … 388 386 cw.visitField(Opcodes.ACC_PUBLIC, mangleIdentifier(idString), nameSpace.descriptor(), null, null).visitEnd(); 389 387 return; 390 } 388 } 391 389 392 390 /** … … 394 392 * This constructors calls the method setToplevel(). 395 393 * If this environment is not a top-level environment, then a default 396 * constructor does not need to be created. (ASM will generate a 394 * constructor does not need to be created. (ASM will generate a 397 395 * default constructor). 398 396 */ … … 414 412 /** 415 413 * Implementing "static reflection" for the method getFooRaw so the 416 * interpreter uses a switch instruction for ***GetRaw 414 * interpreter uses a switch instruction for ***GetRaw 417 415 * based on the hash values of String names in this namespace. 418 416 */ … … 439 437 Collections.sort(sortedCodes); 440 438 Label returnNull = new Label(); 441 439 442 440 getRawHelper(mv, className, hashCodeRelation, environmentClass, sortedCodes, returnNull); 443 441 444 442 mv.visitLabel(returnNull); 445 443 mv.visitInsn(Opcodes.ACONST_NULL); 446 mv.visitInsn(Opcodes.ARETURN); 447 444 mv.visitInsn(Opcodes.ARETURN); 445 448 446 Label endFunction = new Label(); 449 447 mv.visitLabel(endFunction); … … 451 449 mv.visitLocalVariable("queryString", "Ljava/lang/String;", null, beginFunction, endFunction, 1); 452 450 mv.visitLocalVariable("queryHashCode", "I", null, beginLoop, endFunction, 2); 453 // See comment above on ClassWriter.COMPUTE_FRAMES 451 // See comment above on ClassWriter.COMPUTE_FRAMES 454 452 mv.visitMaxs(2, 3); 455 453 mv.visitEnd(); … … 505 503 /** 506 504 * Implementing "static reflection" for the method putRaw so the 507 * interpreter uses a switch instruction for ***PutRaw 505 * interpreter uses a switch instruction for ***PutRaw 508 506 * based on the hash values of String names in this namespace. 509 507 */ … … 524 522 mv.visitLabel(beginLoop); 525 523 526 Relation<String, Integer> hashCodeRelation = symbolNames.makeHashCodeRelation(environmentClass); 524 Relation<String, Integer> hashCodeRelation = symbolNames.makeHashCodeRelation(environmentClass); 527 525 ArrayList<Integer> sortedCodes = new ArrayList<Integer>(hashCodeRelation.secondSet()); 528 526 Collections.sort(sortedCodes); … … 530 528 putRawHelper(mv, className, environmentClass, hashCodeRelation, sortedCodes, notFound); 531 529 mv.visitLabel(notFound); 532 mv.visitInsn(Opcodes.RETURN); 533 Label endFunction = new Label(); 530 mv.visitInsn(Opcodes.RETURN); 531 Label endFunction = new Label(); 534 532 mv.visitLabel(endFunction); 535 533 mv.visitLocalVariable("this", "L" + className + ";", null, … … 539 537 mv.visitLocalVariable("value", environmentClass.descriptor(), null, beginFunction, endFunction, 2); 540 538 mv.visitLocalVariable("queryHashCode", "I", null, beginLoop, endFunction, 3); 541 // See comment above on ClassWriter.COMPUTE_FRAMES 539 // See comment above on ClassWriter.COMPUTE_FRAMES 542 540 mv.visitMaxs(2, 4); 543 541 mv.visitEnd(); … … 560 558 mv.visitLabel(labels[i]); 561 559 putRawBaseCase(mv, className, hashCodeRelation, environmentClass, codes[i], notFound); 562 } 563 560 } 561 564 562 } 565 563 566 564 private static void putRawBaseCase(MethodVisitor mv, String className, 567 Relation<String, Integer> hashCodeRelation, EnvironmentClass environmentClass, 565 Relation<String, Integer> hashCodeRelation, EnvironmentClass environmentClass, 568 566 int code, Label notFound ) { 569 567 … … 603 601 mv.visitLocalVariable("this", "L" + className + ";", null, l0, l1, 0); 604 602 mv.visitLocalVariable("str", "Ljava/lang/String;", null, l0, l1, 1); 605 // See comment above on ClassWriter.COMPUTE_FRAMES 603 // See comment above on ClassWriter.COMPUTE_FRAMES 606 604 mv.visitMaxs(1, 2); 607 605 mv.visitEnd(); … … 619 617 mv.visitLocalVariable("str", "Ljava/lang/String;", null, l0, l1, 1); 620 618 mv.visitLocalVariable("f2", "Ljava/lang/Number;", null, l0, l1, 2); 621 // See comment above on ClassWriter.COMPUTE_FRAMES 619 // See comment above on ClassWriter.COMPUTE_FRAMES 622 620 mv.visitMaxs(0, 3); 623 621 mv.visitEnd(); … … 642 640 mv.visitLocalVariable("this", "L" + className + ";", null, l0, l2, 0); 643 641 mv.visitLocalVariable("name", "Ljava/lang/String;", null, l0, l2, 1); 644 // See comment above on ClassWriter.COMPUTE_FRAMES 642 // See comment above on ClassWriter.COMPUTE_FRAMES 645 643 mv.visitMaxs(3, 2); 646 644 mv.visitEnd(); … … 714 712 mv.visitLocalVariable("this", "L" + className + ";", null, l0, l9, 0); 715 713 mv.visitLocalVariable("a", "Ljava/lang/Appendable;", null, l0, l9, 1); 716 // See comment above on ClassWriter.COMPUTE_FRAMES 714 // See comment above on ClassWriter.COMPUTE_FRAMES 717 715 mv.visitMaxs(2, 2); 718 716 mv.visitEnd(); … … 783 781 Pair<String,byte[]> compOutput = compiledCompUnits.get(componentName); 784 782 String fileName = ProjectProperties.BYTECODE_CACHE_DIR + File.separator + compOutput.getA() + ".class"; 785 outputClassFile(compOutput.getB(), fileName, errors); 783 outputClassFile(compOutput.getB(), fileName, errors); 786 784 } 787 785 } … … 811 809 812 810 } 813 814 -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/ComponentIndex.java
r2699 r3078 26 26 import com.sun.fortress.nodes.APIName; 27 27 import com.sun.fortress.nodes.Component; 28 import com.sun.fortress.nodes.Export;29 28 import com.sun.fortress.nodes.Id; 30 29 import com.sun.fortress.nodes.IdOrOpOrAnonymousName; … … 45 44 Map<Id, Unit> units, 46 45 long modifiedDate) { 47 super(ast, variables, functions, typeConses, 46 super(ast, variables, functions, typeConses, 48 47 dimensions, units, modifiedDate); 49 48 _initializers = initializers; … … 55 54 56 55 @Override 57 public Set<APIName> exports() { 58 List< Export> exports = ((Component)ast()).getExports();56 public Set<APIName> exports() { 57 List<APIName> exports = ((Component)ast()).getExports(); 59 58 Set<APIName> result = new HashSet<APIName>(); 60 59 61 for( Export export : exports ) { 62 result.addAll(export.getApis()); 63 } 60 result.addAll(exports); 64 61 return result; 65 62 } -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/SubtypeCheckerJUTest.java
r3071 r3078 356 356 Component ast = new Component(span, NodeFactory.makeAPIName(span, name), 357 357 Collections.<Import>emptyList(), 358 Collections.< Export>emptyList(),358 Collections.<APIName>emptyList(), 359 359 traitDecls); 360 360 return new ComponentIndex(ast, -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeAnalyzerJUTest.java
r3071 r3078 41 41 42 42 static Span span = NodeFactory.makeSpan("TypeAnalyzerJUTest"); 43 43 44 44 public static void main(String... args) { 45 45 junit.textui.TestRunner.run(TypeAnalyzerJUTest.class); … … 429 429 Component ast = new Component(span, NodeFactory.makeAPIName(name), 430 430 Collections.<Import>emptyList(), 431 Collections.< Export>emptyList(),431 Collections.<APIName>emptyList(), 432 432 traitDecls); 433 433 return new ComponentIndex(ast, … … 514 514 s = s.trim(); 515 515 int opIndex; 516 516 517 517 opIndex = findAtTop(s, "->"); 518 518 if (opIndex >= 0) { -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeChecker.java
r3077 r3078 2042 2042 (APIName)name_result.ast(), 2043 2043 (List<Import>)TypeCheckerResult.astFromResults(imports_result), 2044 (List< Export>)TypeCheckerResult.astFromResults(exports_result),2044 (List<APIName>)TypeCheckerResult.astFromResults(exports_result), 2045 2045 (List<Decl>)TypeCheckerResult.astFromResults(decls_result)); 2046 2046 … … 2209 2209 2210 2210 return TypeCheckerResult.compose(new_node, Types.BOTTOM, subtypeChecker, withResult); 2211 }2212 2213 @Override2214 public TypeCheckerResult forExportOnly(Export that, List<TypeCheckerResult> apis_result) {2215 return new TypeCheckerResult(that);2216 2211 } 2217 2212 -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/Driver.java
r3077 r3078 70 70 import com.sun.fortress.nodes.Component; 71 71 import com.sun.fortress.nodes.Decl; 72 import com.sun.fortress.nodes.Export;73 72 import com.sun.fortress.nodes.FnAbsDeclOrDecl; 74 73 import com.sun.fortress.nodes.FnDecl; … … 510 509 511 510 List<APIWrapper> exports_list = new ArrayList<APIWrapper>(1); 512 for (Export ex : comp.getExports()) 513 for (APIName ex_apiname : ex.getApis()) { 514 String ex_name = NodeUtil.nameString(ex_apiname); 515 Api newapi = readTreeOrSourceApi(ex_name, ex_name, fr); 516 exports_list.add( new APIWrapper(newapi, linker, WellKnownNames.defaultLibrary) ); 517 } 511 for (APIName ex_apiname : comp.getExports()) { 512 String ex_name = NodeUtil.nameString(ex_apiname); 513 Api newapi = readTreeOrSourceApi(ex_name, ex_name, fr); 514 exports_list.add( new APIWrapper(newapi, linker, WellKnownNames.defaultLibrary) ); 515 } 518 516 519 517 comp_wrapper = new ComponentWrapper(comp_index, exports_list, linker, WellKnownNames.defaultLibrary); -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/env/CUWrapper.java
r2994 r3078 42 42 import com.sun.fortress.nodes.CompilationUnit; 43 43 import com.sun.fortress.nodes.Component; 44 import com.sun.fortress.nodes.Export;45 44 import com.sun.fortress.nodes.Import; 46 45 import com.sun.fortress.nodes_util.NodeUtil; … … 53 52 54 53 public class CUWrapper { 55 54 56 55 private final static boolean loadCompiledEnvs = 57 56 ProjectProperties.getBoolean("fortress.test.compiled.environments", true); 58 57 59 58 CompilationUnit comp_unit; 60 59 … … 68 67 */ 69 68 protected String[] implicitLibs; 70 69 71 70 public BASet<String> ownNames = new BASet<String>(com.sun.fortress.useful.StringHashComparer.V); 72 71 public BASet<String> excludedImportNames = new BASet<String>(com.sun.fortress.useful.StringHashComparer.V); 73 72 74 73 /** 75 * If a variable/value/function name is missing when an API is initialized, 76 * store it here, in case it is found later (that is, imported into the 74 * If a variable/value/function name is missing when an API is initialized, 75 * store it here, in case it is found later (that is, imported into the 77 76 * component through some other API). 78 77 */ … … 89 88 */ 90 89 //public BASet<String> missingExportedTypes = new BASet<String>(com.sun.fortress.useful.StringHashComparer.V); 91 90 92 91 public Set<AbstractNode> unresolvedExports = new HashSet<AbstractNode>(); 93 92 94 93 protected DesugarerVisitor desugarer; 95 94 … … 105 104 } 106 105 this.exports = null; 107 108 } 109 106 107 } 108 110 109 Visitor2<String, Object> nameCollector = new Visitor2<String, Object>() { 111 110 112 111 @Override 113 112 public void visit(String t, Object u) { 114 113 115 114 ownNames.add(t); 116 115 } … … 122 121 if (comp == null) 123 122 throw new NullPointerException("Null component (1st parameter to constructor) not allowed"); 124 123 125 124 comp_unit = comp; 126 125 127 126 String fortressFileName = comp_unit.getName().getText(); 128 127 129 128 try { 130 129 131 130 Environment e = loadCompiledEnvs ? 132 131 SimpleClassLoader.loadEnvironment(fortressFileName, false) : … … 136 135 new BuildNativeEnvironment(e, linker) : 137 136 new BuildTopLevelEnvironments(e, linker)); 138 List< Export> component_exports = comp.getExports();139 for ( Exportexp : component_exports) {137 List<APIName> component_exports = comp.getExports(); 138 for (APIName exp : component_exports) { 140 139 // TODO work in progress, this might not be the best place 141 140 } 142 141 143 142 } catch (IOException ex) { 144 143 bug("Failed to load class (" + ex + ") for " + comp); … … 154 153 if (api == null) 155 154 throw new NullPointerException("Null api (1st parameter to constructor) not allowed"); 156 155 157 156 //comp_unit = (Api) RewriteInPresenceOfTypeInfoVisitor.Only.visit(api); 158 157 comp_unit = api; // do nothing? 159 158 160 159 String fortressFileName = comp_unit.getName().getText(); 161 160 162 161 try { 163 162 Environment e = loadCompiledEnvs ? … … 166 165 e.setTopLevel(); 167 166 be = new BuildApiEnvironment(e, linker); 168 167 169 168 } catch (IOException ex) { 170 169 bug("Failed to load class (" + ex + ") for " + api); … … 189 188 public CUWrapper(Component comp, List<APIWrapper> api_list, HashMap<String, ComponentWrapper> linker, String[] implicitLibs) { 190 189 this(comp, linker, implicitLibs); 191 for (APIWrapper api : api_list) 190 for (APIWrapper api : api_list) 192 191 exports.put(NodeUtil.nameString(api.getCompilationUnit().getName()), api); 193 192 } 194 193 195 194 196 195 … … 219 218 return exports.values(); 220 219 } 221 220 222 221 public void touchExports(boolean suppressDebugDump) { 223 222 if (visitState != UNVISITED) … … 258 257 return desugarer.injectAtTopLevel(putName, getName, getFrom.desugarer, excluded); 259 258 } 260 261 262 263 259 260 261 262 264 263 public void initTypes() { 265 264 if (visitState == POPULATED) { … … 303 302 304 303 protected void registerObjectExprs(Environment environment) { 305 304 306 305 } 307 306 -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/env/ComponentWrapper.java
r3047 r3078 35 35 import com.sun.fortress.nodes.CompilationUnit; 36 36 import com.sun.fortress.nodes.Component; 37 import com.sun.fortress.nodes.Export;38 37 import com.sun.fortress.nodes.Param; 39 38 import com.sun.fortress.nodes.StaticParam; … … 53 52 public class ComponentWrapper extends CUWrapper { 54 53 55 /* 54 /* 56 55 * Next three lines are for the "cache" of rewritten ASTs 57 56 */ … … 60 59 public String apply(APIName x) { 61 60 return ProjectProperties.compFileName(ProjectProperties.INTERPRETER_CACHE_DIR, CacheBasedRepository.deCaseName(x)); 62 } 61 } 63 62 }; 64 63 private static IOAst componentReaderWriter = new IOAst(toCompFileName); 65 private static DerivedFiles<CompilationUnit> componentCache = 64 private static DerivedFiles<CompilationUnit> componentCache = 66 65 new DerivedFiles<CompilationUnit>(componentReaderWriter); 67 66 68 67 public static boolean noCache; 69 68 70 69 Component transformed; 71 70 boolean cacheDisabled; 72 73 71 72 74 73 private Component getCached(ComponentIndex comp) { 75 74 if (cacheDisabled) … … 78 77 return (Component) componentCache.get(comp.ast().getName(), comp.modifiedDate()); 79 78 } 80 79 81 80 public ComponentWrapper(ComponentIndex comp, HashMap<String, ComponentWrapper> linker, 82 81 String[] implicitLibs) { 83 82 super((Component) comp.ast(), linker, implicitLibs); 84 83 cacheDisabled = noCache; 85 84 86 85 transformed = getCached(comp); 87 86 // TODO Auto-generated constructor stub … … 125 124 } 126 125 } 127 126 128 127 if (!cacheDisabled && exportsMain(transformed)) { 129 128 // It's not a library, no point keeping this copy in memory. … … 136 135 be.getEnvironment().visit(nameCollector); 137 136 comp_unit = cu; 138 137 139 138 for (String implicitLibraryName : implicitLibs) { 140 139 be.importAPIName(implicitLibraryName); 141 140 } 142 141 143 142 for (CUWrapper api: exports.values()) { 144 143 be.importAPIName(api.name()); 145 144 } 146 145 147 146 for (APIWrapper api: exports.values()) { 148 147 api.populateOne(this); … … 151 150 return cu; 152 151 } 153 152 154 153 private boolean exportsMain(Component transformed2) { 155 List<Export> exports = transformed2.getExports(); 156 for (Export e : exports) { 157 List<APIName> apis = e.getApis(); 158 for (APIName a : apis) 159 if (a.getText().equals("Executable")) 160 return true; 154 List<APIName> exports = transformed2.getExports(); 155 for (APIName a : exports) { 156 if (a.getText().equals("Executable")) 157 return true; 161 158 } 162 159 return false; … … 170 167 protected void registerObjectExprs(Environment env) { 171 168 Component comp = (Component) comp_unit; 172 169 173 170 for (_RewriteObjectExpr oe : comp.getObjectExprs()) { 174 171 String name = oe.getGenSymName(); … … 196 193 } 197 194 } 198 195 199 196 } 200 197 public Set<String> getTopLevelRewriteNames() { -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java
r3077 r3078 66 66 import com.sun.fortress.nodes.DoFront; 67 67 import com.sun.fortress.nodes.EnsuresClause; 68 import com.sun.fortress.nodes.Export;69 68 import com.sun.fortress.nodes.Expr; 70 69 import com.sun.fortress.nodes.ExprMI; … … 655 654 APIName name_result = (APIName) recur(com.getName()); 656 655 List<Import> imports_result = recurOnListOfImport(com.getImports()); 657 List< Export> exports_result = recurOnListOfExport(com.getExports());656 List<APIName> exports_result = recurOnListOfAPIName(com.getExports()); 658 657 List<Decl> decls_result = recurOnListOfDecl(com.getDecls()); 659 658 -
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeUtil.java
r3077 r3078 93 93 94 94 @Override 95 public void forExport(Export that){96 Debug.debug(Debug.Type.SYNTAX, 2, "Add export api ", that.getApis());97 all.addAll(that.getApis());98 }99 100 @Override101 95 public void forImportApi(ImportApi that){ 102 96 for (AliasedAPIName api : that.getApis()){ … … 106 100 } 107 101 }); 102 for (APIName api : comp.getExports()) { 103 all.add(api); 104 } 108 105 return removeExecutableApi(all); 109 106 } -
trunk/ProjectFortress/src/com/sun/fortress/parser/Compilation.rats
r3019 r3078 296 296 297 297 /* Exports ::= Export (br Export)* */ 298 private List<Export> Exports = a1:Export a2s:(br Export)* 299 { yyValue = FortressUtil.mkList(a1, a2s.list()); }; 298 private List<APIName> Exports = a1:Export a2s:(br Export)* 299 { yyValue = a1; 300 for (List<APIName> export : a2s.list()) { 301 a1.addAll(export); 302 } 303 }; 300 304 301 305 /* Export ::= export w APINames */ 302 private Export Export = export w a1:APINames 303 { yyValue = new Export(createSpan(yyStart,yyCount), a1); }; 306 private List<APIName> Export = export w APINames ; 304 307 305 308 /* APINames ::= -
trunk/ProjectFortress/src/com/sun/fortress/parser/preparser/PreCompilation.rats
r2249 r3078 93 93 / a1:(native w)? component w a2:APIName a3:(w yyValue:Imports w semicolon?)? w a4:Exports w (_)* 94 94 { if (a3 == null) a3 = Collections.<Import>emptyList(); 95 // List<Export> a4 = Collections.<Export>emptyList();96 95 List<Decl> a5 = Collections.<Decl>emptyList(); 97 96 Span span = createSpan(yyStart,yyCount); … … 263 262 264 263 /* Exports ::= Export (br Export)* */ 265 private List<Export> Exports = a1:Export a2s:(br Export)* 266 { yyValue = FortressUtil.mkList(a1, a2s.list()); }; 264 private List<APIName> Exports = a1:Export a2s:(br Export)* 265 { yyValue = a1; 266 for (List<APIName> export : a2s.list()) { 267 a1.addAll(export); 268 } 269 }; 267 270 268 271 /* Export ::= export w APINames */ 269 private Export Export = export w a1:APINames 270 { yyValue = new Export(createSpan(yyStart,yyCount), a1); }; 272 private List<APIName> Export = export w APINames; 271 273 272 274 /* APINames ::= -
trunk/ProjectFortress/src/com/sun/fortress/syntax_abstractions/parser/PreParser.java
r3073 r3078 34 34 import com.sun.fortress.nodes.CompilationUnit; 35 35 import com.sun.fortress.nodes.Component; 36 import com.sun.fortress.nodes.Export;37 36 import com.sun.fortress.nodes.Id; 38 37 import com.sun.fortress.nodes.Import; -
trunk/ProjectFortress/src/com/sun/fortress/tests/unit_tests/ConstructorsJUTest.java
r2650 r3078 24 24 25 25 import com.sun.fortress.nodes.APIName; 26 import com.sun.fortress.nodes.Export;27 26 import com.sun.fortress.nodes.Expr; 28 27 import com.sun.fortress.nodes.FloatLiteralExpr; … … 126 125 } 127 126 128 public void testExport() {129 Span span1 = newSpan("cat", 1, 2, 3);130 Export e1 = new Export(span1, FortressUtil.mkList(newAPIName("some", "exported", "apiname")));131 Export e2 = new Export(span1, FortressUtil.mkList(newAPIName("some", "exported", "apiname")));132 Export e3 = new Export(span1, FortressUtil.mkList(newAPIName("an", "exported", "apiname")));133 134 een(e1, e2, e3);135 }136 137 127 /** 138 128 * @param e1 -
trunk/ProjectFortress/src/com/sun/fortress/tools/FortressAstToConcrete.java
r3077 r3078 287 287 s.append( import_ ).append( "\n" ); 288 288 } 289 for ( String export_ : exports_result ){ 290 s.append( export_ ).append( "\n" ); 291 } 289 if (exports_result.size() == 0) 290 return bug(that, "A component should have at least one export statement."); 291 else 292 s = optCurlyBraces(s,"export ", exports_result, ""); 293 s.append( "\n" ); 292 294 for ( String decl_ : decls_result ){ 293 295 s.append( decl_ ).append( "\n\n" ); … … 373 375 } 374 376 return s.toString(); 375 }376 377 @Override public String forExportOnly(Export that, List<String> apis_result) {378 StringBuilder s = new StringBuilder();379 if (apis_result.size() == 0)380 return bug(that, "An export statement should have at least one API name.");381 else382 return optCurlyBraces(s,"export ", apis_result, "").toString();383 377 } 384 378

