Changeset 879
- Timestamp:
- 10/04/07 16:55:44 (2 years ago)
- Location:
- trunk/ProjectFortress
- Files:
-
- 8 added
- 12 modified
-
quickzip (added)
-
src/com/sun/fortress/interpreter/evaluator/EvalType.java (modified) (1 diff)
-
src/com/sun/fortress/interpreter/evaluator/Init.java (modified) (2 diffs)
-
src/com/sun/fortress/interpreter/evaluator/InstantiationLock.java (added)
-
src/com/sun/fortress/interpreter/evaluator/OverloadJUTest.java (modified) (2 diffs)
-
src/com/sun/fortress/interpreter/evaluator/ScoutVisitor.java (added)
-
src/com/sun/fortress/interpreter/evaluator/types/FTraitOrObjectOrGeneric.java (modified) (2 diffs)
-
src/com/sun/fortress/interpreter/evaluator/types/FType.java (modified) (4 diffs)
-
src/com/sun/fortress/interpreter/evaluator/types/FTypeGeneric.java (modified) (3 diffs)
-
src/com/sun/fortress/interpreter/evaluator/types/FTypeOpr.java (modified) (3 diffs)
-
src/com/sun/fortress/interpreter/evaluator/types/FTypeTuple.java (modified) (1 diff)
-
src/com/sun/fortress/interpreter/evaluator/values/GenericConstructor.java (modified) (3 diffs)
-
src/com/sun/fortress/interpreter/evaluator/values/Overload.java (modified) (3 diffs)
-
src/com/sun/fortress/interpreter/evaluator/values/OverloadedFunction.java (modified) (12 diffs)
-
src/com/sun/fortress/useful/DebugletPrintStream.java (added)
-
src/com/sun/fortress/useful/LazyMemo1PC.java (added)
-
src/com/sun/fortress/useful/LazyMemo1PCL.java (added)
-
src/com/sun/fortress/useful/Memo1PCL.java (added)
-
test (modified) (1 diff)
-
testForDebug (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/EvalType.java
r799 r879 313 313 314 314 public FType forOprArg(OprArg b) { 315 return new FTypeOpr(NodeUtil.nameString(b.getName()));315 return FTypeOpr.make(NodeUtil.nameString(b.getName())); 316 316 } 317 317 -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Init.java
r358 r879 30 30 import com.sun.fortress.interpreter.evaluator.types.FTypeLong; 31 31 import com.sun.fortress.interpreter.evaluator.types.FTypeNumber; 32 import com.sun.fortress.interpreter.evaluator.types.FTypeOpr; 32 33 import com.sun.fortress.interpreter.evaluator.types.FTypeOverloadedArrow; 33 34 import com.sun.fortress.interpreter.evaluator.types.FTypeRange; … … 51 52 FTypeArrow.reset(); 52 53 FTypeTuple.reset(); 54 FTypeOpr.reset(); 53 55 FTypeRest.reset(); 54 56 FTypeOverloadedArrow.reset(); -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/OverloadJUTest.java
r744 r879 43 43 super("OverloadJUTest"); 44 44 } 45 private Overload simple_overload(List<FType> types ) {46 return new Overload(new Dummy_fcn(types) );45 private Overload simple_overload(List<FType> types, OverloadedFunction olf) { 46 return new Overload(new Dummy_fcn(types), olf); 47 47 } 48 48 … … 77 77 NodeFactory.makeIdName("dummyOverloadName"), BetterEnv.primitive("Test overload dispatch")); 78 78 for(List<FType> cl: clauses) { 79 fcn.addOverload(simple_overload(cl ));79 fcn.addOverload(simple_overload(cl, fcn)); 80 80 } 81 81 fcn.finishInitializing(); -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/types/FTraitOrObjectOrGeneric.java
r855 r879 88 88 // if (x.getStaticParams().isPresent()) { 89 89 if (x instanceof FTypeGeneric) { 90 cl = new OverloadedFunction(fndod.getName(), topLevel); 90 91 cl = new OverloadedFunction(fndod.getName(), topLevel); 92 topLevel.putValueNoShadowFn(fndodname, cl); 93 91 94 } else { 92 95 // Note that the instantiation of a generic … … 94 97 // here too 95 98 cl = new FunctionalMethod(topLevel, fndod, spi, x); 99 topLevel.putValueNoShadowFn(fndodname, cl); 96 100 } 97 101 98 102 // TODO test and other modifiers 99 103 100 topLevel.putValueNoShadowFn(fndodname, cl);104 101 105 } 102 106 } -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/types/FType.java
r852 r879 38 38 import com.sun.fortress.useful.EmptyLatticeIntervalError; 39 39 import com.sun.fortress.useful.HasAt; 40 import com.sun.fortress.useful.ListComparer; 40 41 import com.sun.fortress.useful.MagicNumbers; 41 42 import com.sun.fortress.useful.Pair; … … 51 52 protected static final boolean DUMP_UNIFY = false; 52 53 53 static Comparator<FType> comparator = new Comparator<FType>() {54 static public Comparator<FType> comparator = new Comparator<FType>() { 54 55 55 56 public int compare(FType arg0, FType arg1) { … … 59 60 }; 60 61 62 static public ListComparer<FType> listComparer = new ListComparer<FType>(); 63 61 64 // static Random random = new Random(0xd06f00d); 62 65 … … 248 251 } 249 252 250 for (FType t : getTransitiveExtends()) { 253 List<FType> extendsThis = getTransitiveExtends(); 254 for (FType t : extendsThis) { 251 255 BASet t_excludes = t.excludes; 252 for (FType o : other.getTransitiveExtends()) { 256 if (t_excludes.isEmpty()) 257 continue; 258 List<FType> extendsOther = other.getTransitiveExtends(); 259 for (FType o : extendsOther) { 253 260 if ( !(t == this && o == other) && t_excludes.contains(o)) { 254 261 // Short-circuit any future queries -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/types/FTypeGeneric.java
r869 r879 18 18 package com.sun.fortress.interpreter.evaluator.types; 19 19 20 import static com.sun.fortress.interpreter.evaluator.InterpreterBug.bug; 21 import static com.sun.fortress.interpreter.evaluator.ProgramError.error; 22 import static com.sun.fortress.interpreter.evaluator.ProgramError.errorMsg; 23 20 24 import java.util.ArrayList; 21 25 import java.util.HashMap; 22 26 import java.util.List; 23 27 import java.util.Map; 24 import java.util.Set;25 28 26 29 import com.sun.fortress.interpreter.env.BetterEnv; 27 30 import com.sun.fortress.interpreter.evaluator.BuildEnvironments; 28 31 import com.sun.fortress.interpreter.evaluator.EvalType; 32 import com.sun.fortress.interpreter.evaluator.InstantiationLock; 29 33 import com.sun.fortress.interpreter.rewrite.OprInstantiater; 30 34 import com.sun.fortress.nodes.AbsDeclOrDecl; … … 32 36 import com.sun.fortress.nodes.ObjectDecl; 33 37 import com.sun.fortress.nodes.OperatorParam; 34 import com.sun.fortress.nodes.TraitObjectAbsDeclOrDecl;35 import com.sun.fortress.nodes._RewriteObjectExpr;36 38 import com.sun.fortress.nodes.StaticArg; 37 39 import com.sun.fortress.nodes.StaticParam; 38 40 import com.sun.fortress.nodes.TraitAbsDeclOrDecl; 41 import com.sun.fortress.nodes.TraitObjectAbsDeclOrDecl; 42 import com.sun.fortress.nodes._RewriteObjectExpr; 39 43 import com.sun.fortress.nodes_util.NodeUtil; 40 44 import com.sun.fortress.useful.Factory1P; 41 45 import com.sun.fortress.useful.HasAt; 42 46 import com.sun.fortress.useful.LazyFactory1P; 43 import com.sun.fortress.useful.LazyMemo1P ;47 import com.sun.fortress.useful.LazyMemo1PCL; 44 48 import com.sun.fortress.useful.Useful; 45 46 import static com.sun.fortress.interpreter.evaluator.ProgramError.error;47 import static com.sun.fortress.interpreter.evaluator.ProgramError.errorMsg;48 import static com.sun.fortress.interpreter.evaluator.InterpreterBug.bug;49 49 50 50 public class FTypeGeneric extends FTraitOrObjectOrGeneric implements Factory1P<List<FType>, FTraitOrObject, HasAt> { … … 231 231 232 232 233 LazyMemo1P <List<FType>, FTraitOrObject, HasAt> memo =234 new LazyMemo1P <List<FType>, FTraitOrObject, HasAt>(235 new Factory() );233 LazyMemo1PCL<List<FType>, FTraitOrObject, HasAt> memo = 234 new LazyMemo1PCL<List<FType>, FTraitOrObject, HasAt>( 235 new Factory(), FType.listComparer, InstantiationLock.L); 236 236 237 237 public FTraitOrObject make(List<FType> l, HasAt within) { -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/types/FTypeOpr.java
r829 r879 18 18 package com.sun.fortress.interpreter.evaluator.types; 19 19 20 import java.util.List; 20 21 import java.util.Set; 21 22 import com.sun.fortress.interpreter.env.BetterEnv; … … 23 24 import com.sun.fortress.nodes.Type; 24 25 import com.sun.fortress.useful.BoundingMap; 26 import com.sun.fortress.useful.Factory1; 27 import com.sun.fortress.useful.Memo1C; 28 import com.sun.fortress.useful.StringComparer; 25 29 26 30 import static com.sun.fortress.interpreter.evaluator.ProgramError.errorMsg; … … 28 32 29 33 public class FTypeOpr extends FType { 30 p ublicFTypeOpr(String s) {34 private FTypeOpr(String s) { 31 35 super(s); 32 36 } 33 37 38 static Memo1C<String, FType> memo = null; 39 40 private static class Factory implements Factory1<String, FType> { 41 public FType make(String part1) { 42 return new FTypeOpr(part1); 43 } 44 } 45 46 public static void reset() { 47 memo = new Memo1C<String, FType>( new Factory(), StringComparer.V); 48 } 49 50 static public FType make(String s) { 51 return memo.make(s); 52 } 53 34 54 /* 35 55 * @see com.sun.fortress.interpreter.evaluator.types.FType#unifyNonVar(java.util.Set, com.sun.fortress.interpreter.useful.ABoundingMap, -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/types/FTypeTuple.java
r852 r879 46 46 public class FTypeTuple extends FType { 47 47 48 static ListComparer<FType> listComparer = new ListComparer<FType>();49 48 List<FType> l; 50 49 -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/values/GenericConstructor.java
r869 r879 25 25 import com.sun.fortress.interpreter.evaluator.Environment; 26 26 import com.sun.fortress.interpreter.evaluator.EvalType; 27 import com.sun.fortress.interpreter.evaluator.InstantiationLock; 27 28 import com.sun.fortress.interpreter.evaluator.types.FType; 28 29 import com.sun.fortress.interpreter.evaluator.types.FTypeGeneric; … … 36 37 import com.sun.fortress.useful.HasAt; 37 38 import com.sun.fortress.useful.Memo1P; 39 import com.sun.fortress.useful.Memo1PCL; 38 40 import com.sun.fortress.useful.Useful; 39 41 … … 64 66 } 65 67 66 Memo1P <List<FType>, Constructor, HasAt> memo =67 new Memo1P <List<FType>, Constructor, HasAt>(new Factory());68 Memo1PCL<List<FType>, Constructor, HasAt> memo = 69 new Memo1PCL<List<FType>, Constructor, HasAt>(new Factory(), FType.listComparer, InstantiationLock.L); 68 70 69 71 public Constructor make(List<FType> l, HasAt within) { -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/values/Overload.java
r679 r879 22 22 import com.sun.fortress.interpreter.evaluator.InterpreterBug; 23 23 import com.sun.fortress.interpreter.evaluator.types.FType; 24 import com.sun.fortress.useful.DebugletPrintStream; 24 25 import com.sun.fortress.useful.HasAt; 25 26 … … 42 43 } 43 44 44 public Overload(SingleFcn fn ) {45 public Overload(SingleFcn fn, OverloadedFunction olf) { 45 46 this.fn = fn; 46 47 } … … 72 73 73 74 private SingleFcn fn; 75 76 DebugletPrintStream ps; 74 77 75 78 /* (non-Javadoc) -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/values/OverloadedFunction.java
r865 r879 18 18 package com.sun.fortress.interpreter.evaluator.values; 19 19 20 import java.io.PrintStream; 20 21 import java.util.ArrayList; 21 22 import java.util.List; … … 26 27 import com.sun.fortress.interpreter.evaluator.EvaluatorBase; 27 28 import com.sun.fortress.interpreter.evaluator.FortressError; 29 import com.sun.fortress.interpreter.evaluator.InstantiationLock; 28 30 import com.sun.fortress.interpreter.evaluator.ProgramError; 29 31 import com.sun.fortress.interpreter.evaluator.types.FType; … … 39 41 import com.sun.fortress.nodes.FnRef; 40 42 import com.sun.fortress.useful.BATreeEC; 43 import com.sun.fortress.useful.DebugletPrintStream; 41 44 import com.sun.fortress.useful.Factory1P; 42 45 import com.sun.fortress.useful.HasAt; … … 52 55 implements Factory1P<List<FType>, Fcn, HasAt>{ 53 56 57 private final boolean debug = false; 58 /** 59 * Disables ALL consistency checking of overloaded functions. 60 */ 61 private final boolean noCheck = false; 62 54 63 protected volatile List<Overload> overloads = new ArrayList<Overload>(); 55 64 private List<Overload> pendingOverloads = new ArrayList<Overload>(); 56 protected volatile boolean finishedFirst = false;57 protected volatile boolean finishedSecond = false;65 protected volatile boolean finishedFirst = true; // an empty overload is consistent 66 protected volatile boolean finishedSecond = true; 58 67 protected SimpleName fnName; 59 68 60 private Thread currentUpdater;61 62 69 static final boolean DUMP_EXCLUSION = false; 63 70 … … 124 131 ol = pendingOverloads.get(i); 125 132 SingleFcn sfcn = ol.getFn(); 133 134 String ps = ol.ps != null ? String.valueOf(ol.ps) + " " : ""; 135 126 136 if (sfcn instanceof Closure) { 127 137 Closure cl = (Closure) sfcn; 128 138 if (! cl.getFinished()) 129 139 cl.finishInitializing(); 140 141 if (debug) { 142 System.err.println("Overload " + ps + cl); 143 } 130 144 131 145 } else if (sfcn instanceof Dummy_fcn) { 132 // Primitives are all ready 146 if (debug) 147 System.err.println("Overload primitive " + ps + sfcn); 133 148 134 149 } else if (sfcn instanceof FGenericFunction) { 135 // no finishInitializing for these guys, yet 150 if (debug) 151 System.err.println("Overload generic " + ps + sfcn); 136 152 137 153 } else { … … 139 155 sfcn)); 140 156 } 157 158 if (ol.ps != null) 159 ol.ps.close(); 141 160 } 142 161 finishedFirst = true; … … 163 182 ftalist.add(new_overloads.get(i).getFn().type()); 164 183 184 if (!noCheck) { 185 165 186 for (int j = i-1; j >= 0 ; j--) { 166 187 Overload o1 = new_overloads.get(i); … … 320 341 } 321 342 } 343 } 322 344 } 323 345 FType ftoa = FTypeOverloadedArrow.make(ftalist); … … 405 427 // if (finishedFirst && !fn.getFinished()) 406 428 // throw new IllegalStateException("Any functions added after finishedFirst must have types assigned."); 407 addOverload(new Overload(fn ));429 addOverload(new Overload(fn, this)); 408 430 } 409 431 … … 427 449 * @param overload 428 450 */ 429 public synchronizedvoid addOverload(Overload overload) {451 public void addOverload(Overload overload) { 430 452 // if (finishedSecond) 431 453 // throw new IllegalStateException("Cannot add overloads after overloaded function is complete"); 432 454 433 Thread me = Thread.currentThread(); 455 // Thread me = Thread.currentThread(); 456 // 457 // if (currentUpdater == null) { 458 // currentUpdater = me; 459 // } 460 // 461 // while (currentUpdater != me) { 462 // try { 463 // wait(); 464 // } catch (InterruptedException e) { 465 // // TODO Auto-generated catch block 466 // e.printStackTrace(); 467 // } 468 // if (currentUpdater == null) 469 // currentUpdater = me; 470 // } 471 // 434 472 435 if (currentUpdater == null) { 436 currentUpdater = me; 473 if (!finishedSecond) { 474 pendingOverloads.add(overload); 475 // InstantiationLock.lastOverload = this; 476 // InstantiationLock.lastOverloadThrowable = Useful.backtrace(0, 1000); 477 } else { 478 // InstantiationLock.L.lock(); 479 if (debug) 480 System.err.println("Lock " + fnName.stringName()); 481 finishedFirst = false; 482 finishedSecond = false; 483 pendingOverloads.add(overload); 484 // InstantiationLock.lastOverload = this; 485 // InstantiationLock.lastOverloadThrowable = Useful.backtrace(0, 1000); 437 486 } 438 487 439 while (currentUpdater != me) { 440 try { 441 wait(); 442 } catch (InterruptedException e) { 443 // TODO Auto-generated catch block 444 e.printStackTrace(); 445 } 446 if (currentUpdater == null) 447 currentUpdater = me; 448 } 449 450 finishedFirst = false; 451 finishedSecond = false; 452 pendingOverloads.add(overload); 488 if (debug) { 489 DebugletPrintStream ps = DebugletPrintStream.make("OVERLOADS"); 490 overload.ps = ps; 491 System.err.println("add " + ps + " " + overload); 492 ps.backtrace().flush(); 493 } 453 494 454 495 } … … 481 522 */ 482 523 public int bestMatchIndex(List<FValue> args, HasAt loc, BetterEnv envForInference) throws Error { 483 if (!finishedSecond) { 484 synchronized(this) { 485 if (!finishedSecond && 486 (currentUpdater == Thread.currentThread() || 487 currentUpdater == null)) 488 bug(loc,"Cannot call before 'setFinished()'"); 489 } 490 } 524 525 if (!finishedSecond && InstantiationLock.L.isHeldByCurrentThread()) 526 bug(loc, "Cannot call before 'setFinished()'"); 491 527 492 528 int best = -1; … … 567 603 * very exciting overload consistency test. 568 604 */ 569 public synchronized void bless() { 605 public void bless() { 606 if (finishedSecond) 607 return; 570 608 this.overloads = pendingOverloads; 571 609 this.pendingOverloads = new ArrayList<Overload>(); 572 610 finishedSecond = true; 573 611 finishedFirst = true; 574 notifyAll(); 575 currentUpdater = null; 612 if (debug) 613 System.err.println("Unlock " + fnName.stringName()); 614 // InstantiationLock.L.unlock(); 576 615 } 577 616 -
trunk/ProjectFortress/test
r723 r879 24 24 fi 25 25 26 java -cp "$CP" -Xmx320m -Xms192m \ 26 27 28 java -cp "$CP" -Xmx512m -Xms256m \ 27 29 junit.swingui.TestRunner \ 28 30 com.sun.fortress.interpreter.drivers.SystemJUTests >& test.log

