| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | package com.sun.fortress.interpreter.evaluator.values; |
|---|
| 19 | |
|---|
| 20 | import static com.sun.fortress.exceptions.InterpreterBug.bug; |
|---|
| 21 | import static com.sun.fortress.exceptions.ProgramError.errorMsg; |
|---|
| 22 | import com.sun.fortress.interpreter.evaluator.Environment; |
|---|
| 23 | import com.sun.fortress.interpreter.evaluator.types.BottomType; |
|---|
| 24 | import com.sun.fortress.interpreter.evaluator.types.FType; |
|---|
| 25 | import com.sun.fortress.interpreter.evaluator.types.FTypeArrow; |
|---|
| 26 | import com.sun.fortress.useful.Hasher; |
|---|
| 27 | import com.sun.fortress.useful.MagicNumbers; |
|---|
| 28 | import com.sun.fortress.useful.Useful; |
|---|
| 29 | |
|---|
| 30 | import java.util.List; |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | abstract public class Simple_fcn extends SingleFcn { |
|---|
| 34 | Simple_fcn(Environment within) { |
|---|
| 35 | super(within); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | FType ret_type; |
|---|
| 39 | |
|---|
| 40 | public void setFtypeUnconditionally(FType ftype) { |
|---|
| 41 | super.setFtypeUnconditionally(ftype); |
|---|
| 42 | FType t = ((FTypeArrow) ftype).getRange(); |
|---|
| 43 | |
|---|
| 44 | if (t == BottomType.ONLY) t = com.sun.fortress.interpreter.evaluator.types.FTypeTop.ONLY; |
|---|
| 45 | ret_type = t; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | protected FValue check(FValue x) { |
|---|
| 49 | FType t = ret_type; |
|---|
| 50 | |
|---|
| 51 | if (true || t.typeMatch(x)) return x; |
|---|
| 52 | return bug(errorMsg("Function ", |
|---|
| 53 | this, |
|---|
| 54 | " returned ", |
|---|
| 55 | x, |
|---|
| 56 | " but signature required ", |
|---|
| 57 | t, |
|---|
| 58 | ", supers are ", |
|---|
| 59 | x.type().getTransitiveExtends())); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | public String getString() { |
|---|
| 63 | return at() + ": " + getFnName().toString() + Useful.listInParens(getDomain()) + ":" + getRange(); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | public FType getRange() { |
|---|
| 67 | return ret_type; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | abstract boolean getFinished(); |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | abstract public String at(); |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | static class SignatureEquivalence extends Hasher<Simple_fcn> { |
|---|
| 87 | @Override |
|---|
| 88 | public long hash(Simple_fcn x) { |
|---|
| 89 | long a = (long) x.getFnName().hashCode() * MagicNumbers.s; |
|---|
| 90 | long b = (long) x.getDomain().hashCode() * MagicNumbers.l; |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | return a + b; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | @Override |
|---|
| 97 | public boolean equiv(Simple_fcn x, Simple_fcn y) { |
|---|
| 98 | List<FType> dx = x.getDomain(); |
|---|
| 99 | List<FType> dy = y.getDomain(); |
|---|
| 100 | if (dx.size() != dy.size()) return false; |
|---|
| 101 | if (!x.getFnName().equals(y.getFnName())) return false; |
|---|
| 102 | for (int i = 0; i < dx.size(); i++) { |
|---|
| 103 | if (!dx.get(i).equals(dy.get(i))) return false; |
|---|
| 104 | } |
|---|
| 105 | return true; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | public static Hasher<Simple_fcn> signatureEquivalence = new SignatureEquivalence(); |
|---|
| 111 | |
|---|
| 112 | static class NameEquivalence extends Hasher<Simple_fcn> { |
|---|
| 113 | @Override |
|---|
| 114 | public long hash(Simple_fcn x) { |
|---|
| 115 | long a = (long) x.getFnName().hashCode() * MagicNumbers.N; |
|---|
| 116 | return a; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | @Override |
|---|
| 120 | public boolean equiv(Simple_fcn x, Simple_fcn y) { |
|---|
| 121 | return x.getFnName().equals(y.getFnName()); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | public static Hasher<Simple_fcn> nameEquivalence = new NameEquivalence(); |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | } |
|---|