nice-commit Mailing List for The Nice Programming Language (Page 41)
Brought to you by:
bonniot
You can subscribe to this list here.
2003 |
Jan
|
Feb
(60) |
Mar
(125) |
Apr
(183) |
May
(140) |
Jun
(227) |
Jul
(141) |
Aug
(181) |
Sep
(75) |
Oct
(89) |
Nov
(187) |
Dec
(162) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(69) |
Feb
(197) |
Mar
(98) |
Apr
(26) |
May
(10) |
Jun
(85) |
Jul
(88) |
Aug
(79) |
Sep
(80) |
Oct
(81) |
Nov
(53) |
Dec
(109) |
2005 |
Jan
(68) |
Feb
(77) |
Mar
(232) |
Apr
(79) |
May
(37) |
Jun
(37) |
Jul
(3) |
Aug
(18) |
Sep
|
Oct
|
Nov
|
Dec
|
2006 |
Jan
(10) |
Feb
|
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(1) |
Dec
(9) |
2007 |
Jan
(2) |
Feb
(8) |
Mar
(2) |
Apr
(5) |
May
|
Jun
|
Jul
|
Aug
(4) |
Sep
|
Oct
|
Nov
(17) |
Dec
(6) |
2008 |
Jan
|
Feb
(3) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Arjan B. <ar...@us...> - 2004-08-03 10:16:25
|
Update of /cvsroot/nice/Nice/src/bossa/link In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21010/F:/nice/src/bossa/link Modified Files: Alternative.java Dispatch.java Log Message: Added a fast coverage test that can check the correctness of a part of the methods avoiding the long test. Index: Dispatch.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/Dispatch.java,v retrieving revision 1.68 retrieving revision 1.69 diff -C2 -d -r1.68 -r1.69 *** Dispatch.java 30 Jul 2004 13:06:20 -0000 1.68 --- Dispatch.java 3 Aug 2004 10:16:14 -0000 1.69 *************** *** 86,92 **** { Stack sortedAlternatives = Alternative.sortedAlternatives(m); ! if (! trivialTestOK(sortedAlternatives)) ! test(m, sortedAlternatives, false); if(Debug.codeGeneration) --- 86,93 ---- { Stack sortedAlternatives = Alternative.sortedAlternatives(m); ! if (! trivialTestOK(sortedAlternatives)) ! if (! shortTestOk(m, sortedAlternatives)) ! test(m, sortedAlternatives, false); if(Debug.codeGeneration) *************** *** 99,103 **** { Stack sortedAlternatives = Alternative.sortedAlternatives(m); ! if (! trivialTestJava(m, sortedAlternatives)) test(m, sortedAlternatives, true); --- 100,104 ---- { Stack sortedAlternatives = Alternative.sortedAlternatives(m); ! if (! trivialTestJava(m, sortedAlternatives)) test(m, sortedAlternatives, true); *************** *** 117,124 **** Alternative a = (Alternative) alternatives.peek(); ! for (int i = 0; i<a.patterns.length; i++) ! if (! a.patterns[i].atAny()) ! return false; ! return true; } --- 118,122 ---- Alternative a = (Alternative) alternatives.peek(); ! return a.allAtAny(); } *************** *** 145,148 **** --- 143,173 ---- } + private static boolean shortTestOk(NiceMethod method, Stack alternatives) + { + if (alternatives.size() < 2) + return false; + + //check for default implementation + if (! ((Alternative) alternatives.peek()).allAtAny()) + return false; + + for (int i = 0; i < alternatives.size(); i++) + for (int k = i+1; k < alternatives.size(); k++) + { + Alternative altA = (Alternative)alternatives.get(i); + Alternative altB = (Alternative)alternatives.get(k); + + if (Alternative.leq(altB, altA)) + User.error(method, "ambiguity because of equivalent patterns in:\n" + + altA.printLocated() + "\nand\n" + + altB.printLocated()); + + if (! (Alternative.leq(altA, altB) || Alternative.disjoint(altA, altB))) + return false; + } + + return true; + } + private static boolean[] findUsedPositions(int len, Stack alternatives) { Index: Alternative.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/Alternative.java,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** Alternative.java 30 Jul 2004 13:06:20 -0000 1.50 --- Alternative.java 3 Aug 2004 10:16:14 -0000 1.51 *************** *** 82,85 **** --- 82,94 ---- } + static boolean disjoint(Alternative a, Alternative b) + { + for(int i = 0; i<a.patterns.length; i++) + if (a.patterns[i].disjoint(b.patterns[i])) + return true; + + return false; + } + /** * Tests the matching of tags against a method alternative. *************** *** 121,124 **** --- 130,142 ---- } + boolean allAtAny() + { + for (int i = 0; i<patterns.length; i++) + if (! patterns[i].atAny()) + return false; + + return true; + } + /**************************************************************** * Code generation |
From: Arjan B. <ar...@us...> - 2004-08-03 10:16:25
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21010/F:/nice/src/bossa/syntax Modified Files: Pattern.java Log Message: Added a fast coverage test that can check the correctness of a part of the methods avoiding the long test. Index: Pattern.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Pattern.java,v retrieving revision 1.86 retrieving revision 1.87 diff -C2 -d -r1.86 -r1.87 *** Pattern.java 5 Jul 2004 08:22:25 -0000 1.86 --- Pattern.java 3 Aug 2004 10:16:13 -0000 1.87 *************** *** 448,451 **** --- 448,505 ---- } + /** + returns true when the patterns can't match the same values. + May return false if it can't be determined easily. + */ + public boolean disjoint(Pattern that) + { + if (this.atAny() || that.atAny()) + return false; + + if (this.atNull() ^ that.atNull()) + return true; + + if (this.atBool() && that.atBool()) + return this.atTrue() ^ that.atTrue(); + + if (this.atReference() && that.atReference()) + return ! this.atValue.equals(that.atValue); + + if (this.atString() && that.atString()) + return ! this.atValue.equals(that.atValue); + + if (this.atIntCompare() && that.atIntCompare()) + { + if (this.atLess() == that.atLess()) + return false; + + long val = this.atValue.longValue(); + if (this.compareKind == LT) val--; + if (this.compareKind == GT) val++; + + return ! that.matchesCompareValue(val); + } + + if (this.atIntCompare() && that.atIntValue()) + return ! this.matchesCompareValue(that.atValue.longValue()); + + if (this.atIntValue() && that.atIntCompare()) + return ! that.matchesCompareValue(this.atValue.longValue()); + + if (this.atIntValue() && that.atIntValue()) + return ! this.atValue.equals(that.atValue); + + if (this.exactlyAt && that.exactlyAt) + return this.tc != that.tc; + + if (TypeConstructors.isClass(this.tc) && TypeConstructors.isClass(that.tc)) + return (! Typing.testRigidLeq(this.tc, that.tc)) && + (! Typing.testRigidLeq(that.tc, this.tc)); + + //TODO: check disjoints for all tc's with a <T | T <: TC_PA, T <: TC_PB> constraint + + return false; + } + public boolean matches(TypeConstructor tag) { |
From: Arjan B. <ar...@us...> - 2004-08-02 19:11:08
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9750/F:/nice/src/bossa/syntax Modified Files: CustomConstructor.java dispatch.java.bootstrap tools.nice Log Message: Don't use specific expression/statements in enumdefinition. Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** tools.nice 30 Jul 2004 19:08:45 -0000 1.39 --- tools.nice 2 Aug 2004 19:10:58 -0000 1.40 *************** *** 142,145 **** --- 142,186 ---- } + void resolveCCThis(Statement stmt, Located thisLoc, NiceClass classe) + { + Block block = cast(stmt); + + Statement last = block.last; + if (last instanceof Block) + { + resolveCCThis(last, thisLoc, classe); + return; + } + + void missingThisError() + { + User.error(thisLoc, "The last statement must be a call to 'this' constructor"); + } + + if (! (last instanceof ExpressionStmt)) + missingThisError(); + + ExpressionStmt expstmt = cast(last); + + if (! (expstmt.exp instanceof CallExp)) + missingThisError(); + + CallExp call = cast(expstmt.exp); + + if (! (call.function instanceof IdentExp)) + missingThisError(); + + IdentExp ident = cast(call.function); + + if (! ident.toString().equals("this")) + missingThisError(); + + Location loc = ident.location(); + call.function = createOverloadedSymbolExp(classe.getConstructorCallSymbols(), + FormalParameters.thisName); + notNull(call.function).setLocation(loc); + } + + // For bootstrap void _printStackTraceWithSourceInfo(Throwable t) = *************** *** 168,171 **** --- 209,214 ---- <T> String map(String, String, String, T[]) = native String bossa.util.Util.map(String, String, String, Object[]); Stack<bossa.link.Alternative> sortedAlternatives(MethodDeclaration) = native Stack bossa.link.Alternative.sortedAlternatives(MethodDeclaration); + List<VarSymbol> getConstructorCallSymbols(NiceClass) = native List NiceClass.getConstructorCallSymbols(); + // Retypings needed since java types are not strict. Index: CustomConstructor.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/CustomConstructor.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** CustomConstructor.java 28 Jul 2004 14:40:33 -0000 1.16 --- CustomConstructor.java 2 Aug 2004 19:10:58 -0000 1.17 *************** *** 153,188 **** void resolveBody() { ! resolveThis((Block) body); body = bossa.syntax.dispatch.analyse (body, thisScope, thisTypeScope, false); } - private void resolveThis(Block block) - { - Statement last = block.statements[block.statements.length - 1]; - if (last instanceof Block) - { - resolveThis((Block) last); - return; - } - - try { - CallExp call = (CallExp) ((ExpressionStmt) last).exp; - IdentExp ident = (IdentExp) call.function; - if (! call.function.toString().equals("this")) - User.error(this, - "The last statement must be a call to 'this' constructor"); - - Location loc = ident.location(); - call.function = bossa.syntax.dispatch.createOverloadedSymbolExp - (classe.getConstructorCallSymbols(), FormalParameters.thisName); - call.function.setLocation(loc); - } - catch(ClassCastException ex) { - User.error(this, - "The last statement must be a call to 'this' constructor"); - } - } - void innerTypecheck() throws TypingEx { --- 153,161 ---- void resolveBody() { ! bossa.syntax.dispatch.resolveCCThis(body, this, classe); body = bossa.syntax.dispatch.analyse (body, thisScope, thisTypeScope, false); } void innerTypecheck() throws TypingEx { Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** dispatch.java.bootstrap 30 Jul 2004 13:06:21 -0000 1.14 --- dispatch.java.bootstrap 2 Aug 2004 19:10:58 -0000 1.15 *************** *** 34,37 **** --- 34,39 ---- { return null; } + static void resolveCCThis(Statement stmt, bossa.util.Located thisloc, NiceClass classe) {} + static Statement analyse(Statement s, VarScope v, TypeScope t, boolean r) { return null; } |
From: Francis B. <fb...@us...> - 2004-08-01 04:42:22
|
Update of /cvsroot/nice/Nice/src/nice/tools/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17554/src/nice/tools/doc Modified Files: comment.nice Log Message: Changed sort order so that the general comment appears first. Index: comment.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/doc/comment.nice,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** comment.nice 31 Jul 2004 07:59:35 -0000 1.4 --- comment.nice 1 Aug 2004 04:42:14 -0000 1.5 *************** *** 229,236 **** return 0; else ! return 1; } else if(s2 == null) ! return -1; else return s1.compareTo(s2); --- 229,236 ---- return 0; else ! return -1; } else if(s2 == null) ! return 1; else return s1.compareTo(s2); |
From: Daniel B. <bo...@us...> - 2004-07-31 10:42:13
|
Update of /cvsroot/nice/Nice/src/nice/tools/locator/repository In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32634/src/nice/tools/locator/repository Log Message: Directory /cvsroot/nice/Nice/src/nice/tools/locator/repository added to the repository |
From: Daniel B. <bo...@us...> - 2004-07-31 10:06:06
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28558/stdlib/nice/lang Modified Files: native.nice java.nice Log Message: Cleanup, using the new Class<T> handling since bootstrap. (This means one needs a recent development version to bootstrap) Index: java.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/java.nice,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** java.nice 30 Jul 2004 19:08:43 -0000 1.54 --- java.nice 31 Jul 2004 10:05:56 -0000 1.55 *************** *** 41,56 **** Process exec(Runtime, String[]) = native Process Runtime.exec(String[]); ! // Class classForName(String name) = native Class Class.forName(String); ! // Field[] getFields(Class) = native Field[] Class.getFields(); ! // Method[] getMethods(Class) = native Method[] Class.getMethods(); - /*TBD*/<T> Method getMethod(Class<T>, String, ?(Class<Object>[])) = native Method[] Class.getMethod(String, Class[]); - /*TBD*/<T> String getName(Class<T>) = native String Class.getName(); <T, V> V get(Field, T) = native Object Field.get(Object); <T, V> void set(Field, T, V) = native void Field.set(Object, Object); String getName(Field) = native String Field.getName(); - // Class getType(Field) = native Class Field.getType(); - /*TBD*/<T> java.net.URL getResource(Class<T>, String) = native java.net.URL Class.getResource(String); - <T> T newInstance(Class<T>) = native Object Class.newInstance(); String concat(String, String) = native String String.concat(String); --- 41,53 ---- Process exec(Runtime, String[]) = native Process Runtime.exec(String[]); ! Class classForName(String name) = native Class Class.forName(String); ! Field[] getFields(Class) = native Field[] Class.getFields(); ! Method[] getMethods(Class) = native Method[] Class.getMethods(); ! Class getType(Field) = native Class Field.getType(); ! <T> T newInstance(Class<T>) = native Object Class.newInstance(); <T, V> V get(Field, T) = native Object Field.get(Object); <T, V> void set(Field, T, V) = native void Field.set(Object, Object); String getName(Field) = native String Field.getName(); String concat(String, String) = native String String.concat(String); Index: native.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/native.nice,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** native.nice 30 Jul 2004 19:08:43 -0000 1.8 --- native.nice 31 Jul 2004 10:05:56 -0000 1.9 *************** *** 29,35 **** <T,U> boolean `instanceof`(T value, Class<U>) = inline nice.lang.inline.Instanceof(); - - <T> boolean `instanceof`(T value, Type) = - inline nice.lang.inline.Instanceof(); - - <T> Class<T> `class`(Type) = inline nice.lang.inline.Class(); --- 29,30 ---- |
From: Daniel B. <bo...@us...> - 2004-07-31 10:06:05
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang/inline In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28558/stdlib/nice/lang/inline Removed Files: Class.java Log Message: Cleanup, using the new Class<T> handling since bootstrap. (This means one needs a recent development version to bootstrap) --- Class.java DELETED --- |
From: Francis B. <fb...@us...> - 2004-07-31 08:10:14
|
Update of /cvsroot/nice/Nice/src/nice/tools/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13402/src/nice/tools/doc Modified Files: document.nice htmlwriter.nice Log Message: Removed deprecated syntax. That is, myMethod(t@Type) changed to myMethod(Type t) Index: htmlwriter.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/doc/htmlwriter.nice,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** htmlwriter.nice 31 Jul 2004 07:59:35 -0000 1.11 --- htmlwriter.nice 31 Jul 2004 08:10:05 -0000 1.12 *************** *** 44,48 **** } ! write(c...@Cl...ass, packageName) { // Here we handle classes --- 44,48 ---- } ! write(ClassDefinition.Class c, packageName) { // Here we handle classes *************** *** 127,131 **** } ! write(gv@GlobalVarDeclaration, packageName) { //Handle global variables --- 127,131 ---- } ! write(GlobalVarDeclaration gv, packageName) { //Handle global variables *************** *** 158,162 **** } ! write(m@MethodDeclaration, packageName) { //Handle methods --- 158,162 ---- } ! write(MethodDeclaration m, packageName) { //Handle methods *************** *** 190,194 **** } ! write(m@DefaultMethodImplementation, packageName) { this.write(m.getDeclaration(), packageName); } --- 190,194 ---- } ! write(DefaultMethodImplementation m, packageName) { this.write(m.getDeclaration(), packageName); } Index: document.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/doc/document.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** document.nice 25 Apr 2004 16:21:31 -0000 1.2 --- document.nice 31 Jul 2004 08:10:05 -0000 1.3 *************** *** 37,41 **** } ! document(c...@Cl...ass) { // Here we handle classes --- 37,41 ---- } ! document(ClassDefinition.Class c) { // Here we handle classes *************** *** 53,57 **** } ! document(m@MethodDeclaration) { println("Method " + m.getName); --- 53,57 ---- } ! document(MethodDeclaration m) { println("Method " + m.getName); *************** *** 59,63 **** } ! document(m@MethodImplementation) { // Method implementations can probably be ignored, as they do not --- 59,63 ---- } ! document(MethodImplementation m) { // Method implementations can probably be ignored, as they do not *************** *** 65,69 **** } ! document(m@DefaultMethodImplementation) { // However, for a default implementation, we want to handle the corresponding --- 65,69 ---- } ! document(DefaultMethodImplementation m) { // However, for a default implementation, we want to handle the corresponding |
From: Francis B. <fb...@us...> - 2004-07-31 07:59:44
|
Update of /cvsroot/nice/Nice/src/nice/tools/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11297/src/nice/tools/doc Modified Files: comment.nice htmlwriter.nice Log Message: htmlwriter.nice: now using the Comment class to parse comments. comment.nice: changed dramatically to actually parse comments pretty much correctly. for example, the previous version spat the dummy if an email address was included in the comment because it interpreted the "@" as the start of an "@param". Index: htmlwriter.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/doc/htmlwriter.nice,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** htmlwriter.nice 3 Apr 2004 14:51:41 -0000 1.10 --- htmlwriter.nice 31 Jul 2004 07:59:35 -0000 1.11 *************** *** 1,4 **** --- 1,6 ---- package nice.tools.doc; + //TODO: change illegal windows filename (+ * etc) + /** *************** *** 21,24 **** --- 23,35 ---- import java.io.*; + /** Comment + */ + int testMethod(double testvar) { + return 0; + } + + /** + *Comment + */ class HTMLWriter { //mainPackage = mainPackage.deleteAtEnd("/").replace('/', "."); *************** *** 30,33 **** --- 41,45 ---- */ void write(Definition d, String packageName) { + //System.err.println("Ignoring " + d.getName() + " (class: " + d.getClass().getName() + ") with docString: "+ d.docString()); } *************** *** 91,96 **** writer.write("<p>\n"); String comments; ! if(c.docString() != null) comments = notNull(c.docString()); else comments = "null"; --- 103,121 ---- writer.write("<p>\n"); String comments; ! if(c.docString() != null) { comments = notNull(c.docString()); + + Comment c = new Comment(commentStr: comments); + List<(?String, String)> tags = c.tags; + writer.write("<table>\n"); + for((?String, String) tag : tags) { + writer.write("<tr>\n"); + (?String x, String y) = tag; + writer.write("<td>" x "</td>\n"); + writer.write("<td>" y "</td>\n"); + writer.write("</tr>\n"); + } + writer.write("</table>\n"); + } else comments = "null"; *************** *** 197,201 **** } else { ! System.err.println("Ignoring " d "\n (type " d.getClass() ")"); } } --- 222,226 ---- } else { ! //System.err.println("Ignoring " d "\n (type " d.getClass() ")"); } } Index: comment.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/doc/comment.nice,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** comment.nice 2 Jun 2004 00:19:32 -0000 1.3 --- comment.nice 31 Jul 2004 07:59:35 -0000 1.4 *************** *** 29,32 **** --- 29,33 ---- /*Initialisation*/ { + //println("Comment String = " commentStr); tags = parse(commentStr); } *************** *** 40,101 **** * @return a list of tuples mapping tags to values. */ List<(?String,String)> parse(String comments) { - //an initial capacity of 8 is used becuase I don't expect many values - //ArrayList<(?String,String)> list = new ArrayList(8); - StringBuffer buf = new StringBuffer(comments); //the first and last chars should be '/' ! if(buf.charAt(0) == '/' && buf.charAt(buf.length() - 1) == '/') { ! buf.deleteCharAt(0); ! buf.deleteCharAt(buf.length()-1); } ! //else this is a problem - do something ! for(int i = 0; i < buf.length; /*no increment*/) { ! if(buf.charAt(i) == '*' && (i == 0 || buf.charAt(i-1) == '\n')) { ! buf.deleteCharAt(i); ! } ! else { ! i++; ! } } ! for(int i = 0; i < buf.length; i++) { ! if(buf.charAt(i) == '\n') { ! buf.replace(i, i+1, " "); } } ! StringTokenizer st = new StringTokenizer(buf.toString(), "@", true /*return delimiters*/); ! boolean isParam = false; ! ?Node root = null; ! for(int i = 0; st.hasMoreTokens(); i++) { ! //println("\"Token " i ": " st.nextToken().trim() "\""); ! String token = st.nextToken().trim(); ! if(token.equals("@")) { ! //the next token will be a param string ! isParam = true; ! } ! else if(isParam) { ! /*this token will have the form "<param name> <comment string>" ! *extract the param name and insert it as the key. add the rest as a comment ! */ ! int index = token.indexOf(' '); ! //list.add(("@" token.substring(0, index), token.substring(index+1))); ! if(root == null) ! root = new Node(value: ("@" token.substring(0, index), token.substring(index+1))); ! else ! root.insert(new Node(value: ("@" token.substring(0, index), token.substring(index+1)))); ! isParam = false; ! } ! else { ! //this is a general comment ! //list.add((null, token)); ! if(root == null) ! root = new Node(value: (null, token)); ! else ! root.insert(new Node(value: (null, token))); } } return toList(root); } class Node { (?String,String) value; --- 41,187 ---- * @return a list of tuples mapping tags to values. */ + + /* I am going to make some assumptions here: + * 1) The general comments section precedes any @ tags + * 2) ... + */ List<(?String,String)> parse(String comments) { //the first and last chars should be '/' ! if(comments.charAt(0) == '/' && comments.charAt(comments.length() - 1) == '/') { ! comments = comments.substring(1, comments.length() - 1); } ! //FIXME: else this is a problem - do something ! ! //read one line at a time ! PushBackTokenizer tok = new PushBackTokenizer(comments, "\n", false /*don't return delimiters*/); ! ! //are there any tokens? if not, nothing more to do ! if(!tok.hasMoreTokens()) { ! //return an empty list ! return new LinkedList(); } ! ! String line = ""; //stops the compiler complaining that it's not initialised. ! String generalComment = ""; ! //the nicedoc comment starts with a block of text - the general comment. ! ! while(tok.hasMoreTokens()) { ! line = tok.nextToken().trim(); ! ! //remove the '*' and ' ' if necessary ! line = trimComment(line); ! ! if(line.length() > 0) { ! //if the first character is a '@' then we are into the tags and ! //need to break out of this loop, but replace the token first ! if(line.charAt(0) == '@') { ! tok.pushBack(line); ! break; ! } ! ! //append the current line to the general comment ! generalComment += line + " "; } } ! ! //if the loop finished because there were no more tokens we need to return now ! if(!tok.hasMoreTokens()) { ! List<(?String, String)> l = new LinkedList(); ! l.add((null, generalComment)); ! return l; ! } ! ! //root will contain a sorted list of all the tags ! Node root = new Node(value: (null, generalComment)); ! ?Node lastNode = null; ! ! while(tok.hasMoreTokens()) { ! line = tok.nextToken().trim(); ! ! //remove the '*' and ' ' if necessary ! line = trimComment(line); ! ! if(line.length() > 0) { ! //this is a new tag ! if(line.charAt(0) == '@') { ! //find the first space - this tells us the range of the tag ! int index = line.indexOf(' '); ! String tag = line.substring(1, index); //skip the '@' ! String comment = line.substring(index+1); //+1 because we need to skip the space ! ! Node n = new Node(value: (tag, comment)); ! root.insert(n); ! lastNode = n; ! } ! //this is a continuation of the last tag, append this line to the comment ! else { ! if(lastNode != null) { ! (?String tag, String comment) = lastNode.value; ! lastNode.value = (tag, comment + " " + line); ! } ! else { ! //logically, I don't see how we can get here. ! throw new RuntimeException("Error parsing comment"); ! } ! } } } + /*println("Returing:"); + List<(?String, String)> list = toList(root); + Iterator<(?String, String)> iterator = list.iterator(); + while(iterator.hasNext()) { + (?String x, String y) = iterator.next(); + println("x: " x "\ny: " y); + }*/ return toList(root); } + String trimComment(String s) { + StringBuffer buf = new StringBuffer(s); + while(buf.length() > 0 && (buf.charAt(0) == '*' || buf.charAt(0) == ' ')) + buf.deleteCharAt(0); + return buf.toString(); + } + + class PushBackTokenizer extends StringTokenizer { + List<String> tokens = new ArrayList(); + + countTokens() { + return super + tokens.size(); + } + + hasMoreElements() { + //we need "this" because of a compiler limitation + return this.hasMoreTokens(); + } + + hasMoreTokens() { + if(!tokens.isEmpty()) + return true; + else + return super; + } + + nextElement() { + return this.nextToken(); + } + + nextToken() { + if(!tokens.isEmpty()) + return tokens.removeAt(tokens.size()-1); + else + return super; + } + + nextToken(String delim) { + throw new UnsupportedOperationException("Method not implemented"); + } + + void pushBack(String token) { + tokens.add(token); + } + } + class Node { (?String,String) value; |
From: Daniel B. <bo...@us...> - 2004-07-31 07:53:20
|
Update of /cvsroot/nice/Nice In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10983 Modified Files: Makefile Log Message: Make sure to really compile nice.tools.locator during bootstrap, so that it appears in the classes.old directory. Index: Makefile =================================================================== RCS file: /cvsroot/nice/Nice/Makefile,v retrieving revision 1.150 retrieving revision 1.151 diff -C2 -d -r1.150 -r1.151 *** Makefile 30 Jul 2004 19:47:34 -0000 1.150 --- Makefile 31 Jul 2004 07:53:10 -0000 1.151 *************** *** 161,165 **** -cd src/bossa/syntax && mv -f dispatch.java.bootstrap dispatch.java ${JAVAC} src/nice/tools/util/System.java ! ${NICEC} nice.tools.locator ${JAVAC} \ src/bossa/syntax/dispatch.java \ --- 161,165 ---- -cd src/bossa/syntax && mv -f dispatch.java.bootstrap dispatch.java ${JAVAC} src/nice/tools/util/System.java ! ${NICEC} -r nice.tools.locator ${JAVAC} \ src/bossa/syntax/dispatch.java \ |
From: Daniel B. <bo...@us...> - 2004-07-30 20:05:19
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16577/src/bossa/syntax Modified Files: NiceClass.java Log Message: Really make final fields final in the bytecode. Index: NiceClass.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceClass.java,v retrieving revision 1.82 retrieving revision 1.83 diff -C2 -d -r1.82 -r1.83 *** NiceClass.java 11 Jun 2004 15:53:35 -0000 1.82 --- NiceClass.java 30 Jul 2004 20:05:10 -0000 1.83 *************** *** 244,247 **** --- 244,248 ---- method.fieldDecl = classe.addField (sym.name.toString(), Types.javaType(sym.type)); + method.fieldDecl.setFlag(isFinal, gnu.expr.Declaration.IS_CONSTANT); method.fieldDecl.setFlag(isTransient, gnu.expr.Declaration.TRANSIENT); method.fieldDecl.setFlag(isVolatile , gnu.expr.Declaration.VOLATILE); |
From: Daniel B. <bo...@us...> - 2004-07-30 19:47:43
|
Update of /cvsroot/nice/Nice In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13525 Modified Files: Makefile Log Message: Fix-up bootstrap for super.nice Index: Makefile =================================================================== RCS file: /cvsroot/nice/Nice/Makefile,v retrieving revision 1.149 retrieving revision 1.150 diff -C2 -d -r1.149 -r1.150 *** Makefile 28 Jul 2004 15:58:25 -0000 1.149 --- Makefile 30 Jul 2004 19:47:34 -0000 1.150 *************** *** 164,167 **** --- 164,168 ---- ${JAVAC} \ src/bossa/syntax/dispatch.java \ + src/mlsub/typing/TypeConstructorLeqMonotypeCst.java \ src/gnu/expr/LoopExp.java \ stdlib/nice/lang/{Native,rawArray}.java \ |
From: Daniel B. <bo...@us...> - 2004-07-30 19:09:23
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6432/stdlib/nice/lang Modified Files: prelude.nice native.nice java.nice Log Message: java.lang.Class is now parameterized by the type it represents. Index: java.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/java.nice,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** java.nice 22 Jul 2004 13:50:38 -0000 1.53 --- java.nice 30 Jul 2004 19:08:43 -0000 1.54 *************** *** 34,48 **** // PACKAGE: java.lang // result is non-null Runtime getRuntime() = native Runtime Runtime.getRuntime(); Process exec(Runtime, String[]) = native Process Runtime.exec(String[]); ! Class classForName(String name) = native Class Class.forName(String); ! Field[] getFields(Class) = native Field[] Class.getFields(); ! Method[] getMethods(Class) = native Method[] Class.getMethods(); <T, V> V get(Field, T) = native Object Field.get(Object); <T, V> void set(Field, T, V) = native void Field.set(Object, Object); String getName(Field) = native String Field.getName(); ! Class getType(Field) = native Class Field.getType(); String concat(String, String) = native String String.concat(String); --- 34,56 ---- // PACKAGE: java.lang + class Class<T> = native java.lang.Class; + // result is non-null Runtime getRuntime() = native Runtime Runtime.getRuntime(); Process exec(Runtime, String[]) = native Process Runtime.exec(String[]); ! ! // Class classForName(String name) = native Class Class.forName(String); ! // Field[] getFields(Class) = native Field[] Class.getFields(); ! // Method[] getMethods(Class) = native Method[] Class.getMethods(); ! ! /*TBD*/<T> Method getMethod(Class<T>, String, ?(Class<Object>[])) = native Method[] Class.getMethod(String, Class[]); ! /*TBD*/<T> String getName(Class<T>) = native String Class.getName(); <T, V> V get(Field, T) = native Object Field.get(Object); <T, V> void set(Field, T, V) = native void Field.set(Object, Object); String getName(Field) = native String Field.getName(); ! // Class getType(Field) = native Class Field.getType(); ! /*TBD*/<T> java.net.URL getResource(Class<T>, String) = native java.net.URL Class.getResource(String); ! <T> T newInstance(Class<T>) = native Object Class.newInstance(); String concat(String, String) = native String String.concat(String); Index: native.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/native.nice,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** native.nice 24 Feb 2004 16:04:59 -0000 1.7 --- native.nice 30 Jul 2004 19:08:43 -0000 1.8 *************** *** 27,32 **** void `throw`(java.lang.Throwable exception) = inline nice.lang.inline.Throw(); <T> boolean `instanceof`(T value, Type) = inline nice.lang.inline.Instanceof(); ! Class `class`(Type) = inline nice.lang.inline.Class(); --- 27,35 ---- void `throw`(java.lang.Throwable exception) = inline nice.lang.inline.Throw(); + <T,U> boolean `instanceof`(T value, Class<U>) = + inline nice.lang.inline.Instanceof(); + <T> boolean `instanceof`(T value, Type) = inline nice.lang.inline.Instanceof(); ! <T> Class<T> `class`(Type) = inline nice.lang.inline.Class(); Index: prelude.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/prelude.nice,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** prelude.nice 24 Feb 2004 16:04:59 -0000 1.37 --- prelude.nice 30 Jul 2004 19:08:43 -0000 1.38 *************** *** 75,79 **** class Type = native; ! /* Allows to consider any nice object as an instance of java.lang.Object @deprecated object(...) is not needed any more: any value is an Object. --- 75,79 ---- class Type = native; ! /* Allows to consider any nice object as an instance of java.lang.Object @deprecated object(...) is not needed any more: any value is an Object. *************** *** 108,112 **** <T> String toString(!T) = native String Object.toString(); <T> String valueOf(T) = native String String.valueOf(Object); ! <T> Class getClass(!T) = native Class Object.getClass(); <T> void wait(!T) = native void Object.wait(); --- 108,112 ---- <T> String toString(!T) = native String Object.toString(); <T> String valueOf(T) = native String String.valueOf(Object); ! <T> Class<!T> getClass(!T) = native Class Object.getClass(); <T> void wait(!T) = native void Object.wait(); |
From: Daniel B. <bo...@us...> - 2004-07-30 19:09:23
|
Update of /cvsroot/nice/Nice/src/nice/tools/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6432/src/nice/tools/typing Modified Files: Types.java Log Message: java.lang.Class is now parameterized by the type it represents. Index: Types.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/typing/Types.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Types.java 16 Jun 2004 10:00:34 -0000 1.7 --- Types.java 30 Jul 2004 19:08:43 -0000 1.8 *************** *** 177,181 **** return Typing.lowestInstance(res); } ! /**************************************************************** * Type parameters --- 177,192 ---- return Typing.lowestInstance(res); } ! ! public static Monotype zeroArgMonotype(TypeConstructor tc) ! throws BadSizeEx ! { ! // Handle 'Class' as 'Class<?>' ! if (tc == PrimitiveType.classTC) ! return new MonotypeConstructor ! (tc, new mlsub.typing.Monotype[]{ UnknownMonotype.instance }); ! ! return new MonotypeConstructor(tc, null); ! } ! /**************************************************************** * Type parameters |
From: Daniel B. <bo...@us...> - 2004-07-30 19:09:22
|
Update of /cvsroot/nice/Nice/testsuite/compiler/native In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6432/testsuite/compiler/native Modified Files: instanceof.testsuite class.testsuite Log Message: java.lang.Class is now parameterized by the type it represents. Index: instanceof.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/native/instanceof.testsuite,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** instanceof.testsuite 19 Dec 2003 02:12:34 -0000 1.7 --- instanceof.testsuite 30 Jul 2004 19:08:42 -0000 1.8 *************** *** 38,46 **** /// PASS ! assert [] instanceof Array; int[] i = [0]; ! assert i instanceof Array; ! List<String> l = [""]; ! assert l instanceof Array; --- 38,46 ---- /// PASS ! assert [] instanceof Object[]; int[] i = [0]; ! assert i instanceof int[]; ! Object l = [""]; ! assert l instanceof String[]; Index: class.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/native/class.testsuite,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** class.testsuite 23 Jul 2002 12:44:15 -0000 1.2 --- class.testsuite 30 Jul 2004 19:08:42 -0000 1.3 *************** *** 16,17 **** --- 16,44 ---- /// FAIL Class c = NotExisting.class; + + /// FAIL + Class<NotExisting> c = NotExisting.class; + + /// FAIL + Class<String> c = NotExisting.class; + + /// FAIL + Class<String> c = java.io.File.class; + + /// FAIL + /// Toplevel + Class<String> unsafe(Class c) = c; + + /// PASS + /// Toplevel + boolean isIntClass(Class c) = c == int.class || int.class == c; + + <T> boolean foo(T,T) = false; + + boolean classTest(Class c) = foo(c, String.class) || foo(String.class, c); + + /// PASS + foo(String.class); + /// Toplevel + void foo(Class) {} + <Number T> void foo(Class<T>) {} |
From: Daniel B. <bo...@us...> - 2004-07-30 19:09:21
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang/reflect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6432/stdlib/nice/lang/reflect Modified Files: instances.nice Added Files: promotion-demotion.nice Log Message: java.lang.Class is now parameterized by the type it represents. --- NEW FILE: promotion-demotion.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package nice.lang.reflect; /** @param source an object of type T @param target the Class of type U, a supertype of T @return a new instance of class U, keeping all relevant fields from object <code>source</code> */ public <T, U | T <: U> U demote(T source, Class<U> target) { // Create the new object U res = target.newInstance(); for (field : target.getFields()) println(""field[res]" => "field[source]); // Initialize all fields of the new object by copy from the source for (field : target.getFields()) field[res] = field[source]; return res; } /** @param source an object of non-null type T @param target the Class of type U, a subtype of T @return a new instance of class U, keeping all fields from object <code>source</code> */ public <!T, U | U <: T> U promote(T source, Class<U> target) { Class<T> sourceClass = source.getClass(); U res = target.newInstance(); for (field : target.getFields()) { // Only copy fields that exist in the source class if (field.getDeclaringClass().isAssignableFrom(sourceClass)) field[res] = field[source]; } return res; } // Unit tests class _Dog { String name = ""; } class _Dalmatian extends _Dog { boolean spotted = false; } class _Chihuahua extends _Dog { boolean dancing = false; } void _testDemote() { _Dalmatian dalmatian = new _Dalmatian(name: "Dalmatian", spotted: true); _Dog dog = dalmatian.demote(nice.lang.reflect._Dog); assert dog.getClass() == nice.lang.reflect._Dog; assert dog.name.equals("Dalmatian"); Object o = dog.demote(Object.class); // Error detected at compile time: //String s = dog.demote(java.lang.String); } void _testPromote() { _Dog dog = new _Dog(name: "Simple dog"); _Dalmatian dalmatian = dog.promote(nice.lang.reflect._Dalmatian); assert dalmatian.getClass() == nice.lang.reflect._Dalmatian; assert dalmatian.name.equals("Simple dog"); assert ! dalmatian.spotted; _Chihuahua chihuahua = new _Chihuahua(name: "Chichi", dancing: true); dalmatian = chihuahua.promote(nice.lang.reflect._Dalmatian); assert dalmatian.getClass() == nice.lang.reflect._Dalmatian; assert dalmatian.name.equals("Chichi"); assert ! dalmatian.spotted; } Index: instances.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/reflect/instances.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** instances.nice 12 Dec 2003 12:55:25 -0000 1.2 --- instances.nice 30 Jul 2004 19:08:42 -0000 1.3 *************** *** 52,59 **** ****************************************************************/ - public <T> T newInstance(Class) = native Object Class.newInstance(); - public <T> T newInstance(String className) = ! newInstance(Class.forName(className)); // Testcases --- 52,57 ---- ****************************************************************/ public <T> T newInstance(String className) = ! cast(newInstance(Class.forName(className))); // Testcases |
From: Daniel B. <bo...@us...> - 2004-07-30 19:09:21
|
Update of /cvsroot/nice/Nice/testsuite/compiler/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6432/testsuite/compiler/typing Modified Files: instanceof.testsuite Log Message: java.lang.Class is now parameterized by the type it represents. Index: instanceof.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/typing/instanceof.testsuite,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** instanceof.testsuite 20 Jul 2004 22:37:49 -0000 1.22 --- instanceof.testsuite 30 Jul 2004 19:08:41 -0000 1.23 *************** *** 356,357 **** --- 356,371 ---- /// Toplevel Object foo() = ""; + + /// PASS + Object o = new String[3]; + if (o instanceof String[]) + { + ?String[] s = o; + } + + /// FAIL + Object o = new String[3]; + if (o instanceof String[]) + { + ?java.io.File[] s = o; + } |
From: Daniel B. <bo...@us...> - 2004-07-30 19:08:56
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6432/src/bossa/syntax Modified Files: typecheck.nice tools.nice analyse.nice TypeIdent.java TypeConstantExp.java PrimitiveType.java Monotype.java ConstantExp.java ClassDefinition.java Log Message: java.lang.Class is now parameterized by the type it represents. Index: analyse.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/analyse.nice,v retrieving revision 1.106 retrieving revision 1.107 diff -C2 -d -r1.106 -r1.107 *** analyse.nice 29 Jul 2004 12:11:40 -0000 1.106 --- analyse.nice 30 Jul 2004 19:08:45 -0000 1.107 *************** *** 613,633 **** } ! analyse(TypeConstantExp e, info) { ! LocatedString name = cast(e.value); ! ! ?gnu.bytecode.Type type = nice.tools.code.Types.typeRepresentationToBytecode ! (name.toString(), name.location()); ! ! if (type == null) { ! if (info.lookupType(name) instanceof MonotypeVar) ! throw new bossa.util.UserError(name, "A type variable cannot be used here"); else ! throw new bossa.util.UserError(name, "Class " + name + " is not declared"); } ! e.value = type; ! e.representedType = bossa.syntax.Node.getGlobalTypeScope(). ! globalLookup(name.toString(), name.location()); return e; --- 613,661 ---- } ! mlsub.typing.Polytype typeRepresentationToPolytype(String name, ! ?bossa.util.Location loc, ! Info info, ! boolean sure = true) { ! if (name.charAt(0) == '[') { ! mlsub.typing.Polytype res = ! typeRepresentationToPolytype(name.substring(1), loc, info, sure: false); ! ! let type = new mlsub.typing.MonotypeConstructor ! (PrimitiveType.arrayTC, [res.getMonotype()]); ! ! return new mlsub.typing.Polytype ! (res.getConstraint(), ! sure ? Monotype.sure(type) : Monotype.maybe(type)); ! } ! ! ?TypeConstructor tc = Node.getGlobalTypeScope().globalLookup(name, loc); ! ! if (tc == null) ! { ! if (name.equals("Object") || name.equals("java.lang.Object")) ! return PrimitiveType.objectPolytype(); ! ! if (info.typeVars[name] instanceof MonotypeVar) ! throw new bossa.util.UserError(loc, "A type variable cannot be used here"); else ! throw new bossa.util.UserError(loc, "Class "name" is not declared"); } ! ! return TypeConstantExp.universalPolytype(tc, sure); ! } ! ! analyse(TypeConstantExp e, info) ! { ! LocatedString name = cast(e.value); ! ! mlsub.typing.Polytype type = typeRepresentationToPolytype(name.toString(), name.location(), info); ! ! ?gnu.bytecode.Type bytecodeType = ! nice.tools.code.Types.typeRepresentationToBytecode ! (name.toString(), name.location()); ! ! e.setRepresentedType(type, bytecodeType); return e; *************** *** 892,895 **** // Local Variables: ! // nice-xprogram: "nicec -d \"$HOME/Nice/classes\" --sourcepath=\"$HOME/Nice/src\" --classpath=\"$HOME/Nice/classes\"" // End: --- 920,923 ---- // Local Variables: ! // nice-xprogram: "../bin/nicec -d ../classes --sourcepath=../src" // End: Index: TypeConstantExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/TypeConstantExp.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TypeConstantExp.java 9 Dec 2003 17:20:15 -0000 1.4 --- TypeConstantExp.java 30 Jul 2004 19:08:45 -0000 1.5 *************** *** 13,16 **** --- 13,21 ---- package bossa.syntax; + import mlsub.typing.Polytype; + import mlsub.typing.MonotypeConstructor; + import mlsub.typing.TypeConstructor; + import mlsub.typing.MonotypeVar; + /** A type used as an expression. *************** *** 20,36 **** */ ! class TypeConstantExp extends ConstantExp { ! TypeConstantExp(LocatedString name) { ! super(PrimitiveType.typeTC, name, name.toString(), name.location()); } ! private TypeConstantExp(LocatedString name, gnu.bytecode.Type type) { ! this(name); ! this.value = type; } /** @return an Expression representing ident as a type or package literal. --- 25,101 ---- */ ! public class TypeConstantExp extends ConstantExp { ! public TypeConstantExp(LocatedString name) { ! super(null, null, name, name.toString(), name.location()); } ! gnu.bytecode.ClassType staticClass() { ! // If this is a '<name>.class' expression, do not consider it as a ! // qualified prefix. ! if (isExpression) ! return null; ! ! return (gnu.bytecode.ClassType) value; ! } ! ! void setRepresentedType(Polytype type, gnu.bytecode.Type bytecodeType) ! { ! this.value = bytecodeType; ! ! this.representedType = type.getMonotype(); ! ! this.type = new Polytype ! (type.getConstraint(), ! Monotype.sure ! (new MonotypeConstructor ! (PrimitiveType.classTC, ! new mlsub.typing.Monotype[]{ type.getMonotype() }))); ! } ! ! protected gnu.expr.Expression compile() ! { ! if (isLiteral) ! return super.compile(); ! ! gnu.bytecode.Type type = (gnu.bytecode.Type) value; ! String representation = type instanceof gnu.bytecode.ArrayType ? ! type.getSignature().replace('/', '.') : ! type.getName(); ! ! return new gnu.expr.ApplyExp ! (forName, ! new gnu.expr.Expression[]{ ! new gnu.expr.QuoteExp(representation)}); ! } ! ! static final gnu.bytecode.Method forName = ! gnu.bytecode.ClassType.make("java.lang.Class").getDeclaredMethod("forName", 1); ! ! TypeConstructor getTC() ! { ! return nice.tools.typing.Types.rawType(representedType).head(); } + mlsub.typing.Monotype representedType; + + public boolean isExpression = false; + public boolean isLiteral = false; + + static Polytype universalPolytype(TypeConstructor tc, boolean sure) + { + MonotypeVar[] vars = MonotypeVar.news(tc.arity()); + mlsub.typing.Monotype type = new MonotypeConstructor(tc, vars); + return new Polytype + (vars == null ? null : new mlsub.typing.Constraint(vars, null), + sure ? Monotype.sure(type) : Monotype.maybe(type)); + } + + /**************************************************************** + * Type literals + ****************************************************************/ + /** @return an Expression representing ident as a type or package literal. *************** *** 40,44 **** return create(null, ident); } ! /** @return an Expression representing [root].[name] --- 105,109 ---- return create(null, ident); } ! /** @return an Expression representing [root].[name] *************** *** 49,54 **** if (root != null) fullName = root.name.append(".").append(fullName).toString(); ! ! mlsub.typing.TypeConstructor tc = Node.getGlobalTypeScope().globalLookup(fullName, name.location()); --- 114,119 ---- if (root != null) fullName = root.name.append(".").append(fullName).toString(); ! ! TypeConstructor tc = Node.getGlobalTypeScope().globalLookup(fullName, name.location()); *************** *** 56,64 **** { gnu.bytecode.Type type = nice.tools.code.Types.javaType(tc); // type might not be a class // for instance if the ident was "int" if (type instanceof gnu.bytecode.ClassType) { ! Expression res = new TypeConstantExp(name, type); res.setLocation(root == null ? name.location() : root.location()); return res; --- 121,131 ---- { gnu.bytecode.Type type = nice.tools.code.Types.javaType(tc); + // type might not be a class // for instance if the ident was "int" if (type instanceof gnu.bytecode.ClassType) { ! TypeConstantExp res = new TypeConstantExp(name); ! res.setRepresentedType(universalPolytype(tc, true), type); res.setLocation(root == null ? name.location() : root.location()); return res; *************** *** 74,83 **** return root; } - - gnu.bytecode.ClassType staticClass() - { - return (gnu.bytecode.ClassType) value; - } - - mlsub.typing.TypeConstructor representedType; } --- 141,143 ---- Index: TypeIdent.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/TypeIdent.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** TypeIdent.java 23 Dec 2003 10:20:40 -0000 1.28 --- TypeIdent.java 30 Jul 2004 19:08:45 -0000 1.29 *************** *** 16,19 **** --- 16,20 ---- import java.util.*; import mlsub.typing.TypeConstructor; + import mlsub.typing.MonotypeConstructor; import mlsub.typing.Interface; import mlsub.typing.MonotypeVar; *************** *** 78,82 **** { TypeSymbol res = resolveToTypeSymbol(scope); ! if (res instanceof mlsub.typing.Monotype) return (mlsub.typing.Monotype) res; --- 79,83 ---- { TypeSymbol res = resolveToTypeSymbol(scope); ! if (res instanceof mlsub.typing.Monotype) return (mlsub.typing.Monotype) res; *************** *** 87,94 **** try{ ! return new mlsub.typing.MonotypeConstructor(tc, null); } catch(mlsub.typing.BadSizeEx e){ ! throw User.error(this, name + Util.has(e.expected, "type parameter", e.actual)); } --- 88,95 ---- try{ ! return nice.tools.typing.Types.zeroArgMonotype(tc); } catch(mlsub.typing.BadSizeEx e){ ! throw User.error(this, name + Util.has(e.expected, "type parameter", e.actual)); } Index: ClassDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/ClassDefinition.java,v retrieving revision 1.106 retrieving revision 1.107 diff -C2 -d -r1.106 -r1.107 *** ClassDefinition.java 16 Jun 2004 10:00:38 -0000 1.106 --- ClassDefinition.java 30 Jul 2004 19:08:45 -0000 1.107 *************** *** 395,398 **** --- 395,400 ---- else if (name.equals("nice.lang.Collection")) PrimitiveType.collectionTC = tc; + else if (name.equals("nice.lang.Class")) + PrimitiveType.classTC = tc; } Index: Monotype.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Monotype.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** Monotype.java 16 Jun 2004 10:00:37 -0000 1.35 --- Monotype.java 30 Jul 2004 19:08:45 -0000 1.36 *************** *** 218,222 **** ****************************************************************/ ! static Monotype create(mlsub.typing.Monotype m) { return new Wrapper(m); --- 218,222 ---- ****************************************************************/ ! public static Monotype create(mlsub.typing.Monotype m) { return new Wrapper(m); Index: PrimitiveType.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/PrimitiveType.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** PrimitiveType.java 22 Jul 2004 15:19:19 -0000 1.11 --- PrimitiveType.java 30 Jul 2004 19:08:45 -0000 1.12 *************** *** 154,161 **** return gnu.bytecode.Type.pointer_type; } ! if (name.equals("nice.lang.Type")) { - typeTC = tc; // to differ with the null result, which signals error return gnu.bytecode.Type.pointer_type; --- 154,160 ---- return gnu.bytecode.Type.pointer_type; } ! if (name.equals("nice.lang.Type")) { // to differ with the null result, which signals error return gnu.bytecode.Type.pointer_type; *************** *** 182,185 **** --- 181,186 ---- } + public static void reset() { objectPolytype = null; } + public static TypeConstructor maybeTC, sureTC, nullTC; *************** *** 187,191 **** public static Monotype synVoidType; ! static TypeConstructor typeTC; static TypeConstructor collectionTC; static TypeConstructor throwableTC; --- 188,192 ---- public static Monotype synVoidType; ! public static TypeConstructor classTC; static TypeConstructor collectionTC; static TypeConstructor throwableTC; Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** tools.nice 30 Jul 2004 13:06:21 -0000 1.38 --- tools.nice 30 Jul 2004 19:08:45 -0000 1.39 *************** *** 114,126 **** TypeConstantExp type = cast(arg2); ! if (type.representedType == null) return null; ! TypeConstructor tc = notNull(type.representedType); mlsub.typing.Monotype[?] parameters; if (tc.arity() == 0) parameters = null; ! else { let originalType = nice.tools.typing.Types.rawType(sym.getMonotype()); --- 114,130 ---- TypeConstantExp type = cast(arg2); ! if (type.getTC() == null) return null; ! TypeConstructor tc = notNull(type.getTC()); ! ! if (tc == PrimitiveType.arrayTC) ! return (sym, notNull(type.representedType)); ! mlsub.typing.Monotype[?] parameters; if (tc.arity() == 0) parameters = null; ! else { let originalType = nice.tools.typing.Types.rawType(sym.getMonotype()); *************** *** 173,176 **** // Local Variables: ! // nice-xprogram: "nicec -d \"$HOME/Nice/classes\" --sourcepath=\"$HOME/Nice/src\" --classpath=\"$HOME/Nice/classes\"" // End: --- 177,180 ---- // Local Variables: ! // nice-xprogram: "../bin/nicec -d ../classes --sourcepath=../src" // End: Index: ConstantExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/ConstantExp.java,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** ConstantExp.java 24 Nov 2003 17:27:22 -0000 1.49 --- ConstantExp.java 30 Jul 2004 19:08:45 -0000 1.50 *************** *** 280,288 **** return res; } - - public static ConstantExp makeType(LocatedString representation) - { - return new TypeConstantExp(representation); - } /**************************************************************** --- 280,283 ---- Index: typecheck.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v retrieving revision 1.104 retrieving revision 1.105 diff -C2 -d -r1.104 -r1.105 *** typecheck.nice 29 Jul 2004 12:11:40 -0000 1.104 --- typecheck.nice 30 Jul 2004 19:08:45 -0000 1.105 *************** *** 114,118 **** } ! enterIf(); try { typecheck(args.getExp(0)); --- 114,118 ---- } ! enterBlock(); try { typecheck(args.getExp(0)); *************** *** 156,160 **** } ! enterIf(); try { typecheck(args.getExp(0)); --- 156,160 ---- } ! enterBlock(); try { typecheck(args.getExp(0)); *************** *** 397,401 **** var Stack<(MonoSymbol, mlsub.typing.Monotype)> conditionalTypes = new Stack(); ! void enterIf() { ifLevel++; } void enterElse() --- 397,403 ---- var Stack<(MonoSymbol, mlsub.typing.Monotype)> conditionalTypes = new Stack(); ! void enterBlock() { ifLevel++; } ! ! void exitBlock () { enterElse(); exitIf(); } void enterElse() *************** *** 506,510 **** e.condition = condition; ! enterIf(); try{ --- 508,512 ---- e.condition = condition; ! enterBlock(); try{ *************** *** 717,729 **** typecheck(Block b) { ! b.statements = rewrite(b.statements); ! b.locals.foreach(?Block.LocalDeclaration d => typecheck(d)); ! b.statements.foreach ! (?Statement s => { ! try { typecheck(s); } ! catch (bossa.util.UserError ex) ! { throw ensureLocated(ex, notNull(s)); } ! }); } --- 719,738 ---- typecheck(Block b) { ! enterBlock(); ! try { ! b.statements = rewrite(b.statements); ! ! b.locals.foreach(?Block.LocalDeclaration d => typecheck(d)); ! b.statements.foreach ! (?Statement s => { ! try { typecheck(s); } ! catch (bossa.util.UserError ex) ! { throw ensureLocated(ex, notNull(s)); } ! }); ! } ! finally { ! exitBlock(); ! } } *************** *** 816,820 **** } ! enterIf(); try { --- 825,829 ---- } ! enterBlock(); try { |
From: Daniel B. <bo...@us...> - 2004-07-30 19:08:55
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6432/src/bossa/parser Modified Files: Parser.jj Log Message: java.lang.Class is now parameterized by the type it represents. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.250 retrieving revision 1.251 diff -C2 -d -r1.250 -r1.251 *** Parser.jj 28 Jul 2004 21:23:39 -0000 1.250 --- Parser.jj 30 Jul 2004 19:08:45 -0000 1.251 *************** *** 521,529 **** } ! ConstantExp typeExpression(): { LocatedString name; } { name = doted_array_string() ! { return ConstantExp.makeType(name); } } --- 521,529 ---- } ! TypeConstantExp typeExpression(): { LocatedString name; } { name = doted_array_string() ! { return new TypeConstantExp(name); } } *************** *** 776,780 **** } { ! [ "?" { maybe = true; } | "!" { sure = true; } ] ( --- 776,785 ---- } { ! [ ! // Consume "?" only if it does not appear by itself ! LOOKAHEAD( "?", { getToken(2).kind != COMMA && getToken(2).kind != GT}) ! "?" { maybe = true; } ! | "!" { sure = true; } ! ] ( *************** *** 803,806 **** --- 808,814 ---- } { return res; } + | + "?" + { return Monotype.create(mlsub.typing.UnknownMonotype.instance); } } *************** *** 2055,2062 **** { Expression res; } { ! res=RelationalExpression() ! [ { Token t; ConstantExp type; } ! t="instanceof" type=typeExpression() ! { return CallExp.create(symb(t), res, type); } ] { return res; } --- 2063,2070 ---- { Expression res; } { ! res=RelationalExpression() ! [ { Token t; TypeConstantExp type; } ! t="instanceof" type=typeExpression() ! { type.isLiteral = true; return CallExp.create(symb(t), res, type); } ] { return res; } *************** *** 2213,2219 **** | LOOKAHEAD( doted_array_string() "." "class" ) ! { ConstantExp type; Token t; } type=typeExpression() "." t="class" ! { return CallExp.create(symb(t), type); } | //Name() --- 2221,2227 ---- | LOOKAHEAD( doted_array_string() "." "class" ) ! { TypeConstantExp type; Token t; } type=typeExpression() "." t="class" ! { type.isExpression = true; return type; } | //Name() |
From: Daniel B. <bo...@us...> - 2004-07-30 19:08:55
|
Update of /cvsroot/nice/Nice In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6432 Modified Files: NEWS Log Message: java.lang.Class is now parameterized by the type it represents. Index: NEWS =================================================================== RCS file: /cvsroot/nice/Nice/NEWS,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** NEWS 20 Jul 2004 22:37:50 -0000 1.38 --- NEWS 30 Jul 2004 19:08:46 -0000 1.39 *************** *** 7,11 **** assert o instanceof String; // Here o can be used as a string without cast ! -- --- 7,15 ---- assert o instanceof String; // Here o can be used as a string without cast ! * java.lang.Class is now parameterized by the type it represents. ! In particular, newInstance is now declared in nice.lang with ! <T> T newInstance(Class<T>); ! This make it possible to write type-safe code that uses reflexion, ! in particular when using class literals. -- |
From: Daniel B. <bo...@us...> - 2004-07-30 19:08:55
|
Update of /cvsroot/nice/Nice/src/bossa/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6432/src/bossa/modules Modified Files: Package.java Log Message: java.lang.Class is now parameterized by the type it represents. Index: Package.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Package.java,v retrieving revision 1.117 retrieving revision 1.118 diff -C2 -d -r1.117 -r1.118 *** Package.java 30 Jun 2004 14:12:37 -0000 1.117 --- Package.java 30 Jul 2004 19:08:46 -0000 1.118 *************** *** 289,292 **** --- 289,293 ---- TypeConstructors.reset(); JavaClasses.reset(); + PrimitiveType.reset(); gnu.bytecode.Type.reset(); } |
From: Daniel B. <bo...@us...> - 2004-07-30 19:08:54
|
Update of /cvsroot/nice/Nice/src/mlsub/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6432/src/mlsub/typing Modified Files: Variance.java MonotypeVar.java Monotype.java Added Files: UnknownMonotype.java Log Message: java.lang.Class is now parameterized by the type it represents. Index: Variance.java =================================================================== RCS file: /cvsroot/nice/Nice/src/mlsub/typing/Variance.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Variance.java 17 Mar 2004 16:55:33 -0000 1.16 --- Variance.java 30 Jul 2004 19:08:45 -0000 1.17 *************** *** 242,245 **** --- 242,246 ---- for(int i=0; i<size; i++) switch(signs[i]){ + // TODO: Consider UnknownMonotype in non-invariant cases case COVARIANT: mlsub.typing.lowlevel.Engine.leq(tp1[i],tp2[i]); *************** *** 248,252 **** --- 249,263 ---- mlsub.typing.lowlevel.Engine.leq(tp2[i],tp1[i]); break; + case INVARIANT: + if (tp2[i].isUnknown()) + return; + + if (tp1[i].isUnknown()) + { + tp2[i].setUnknown(); + return; + } + mlsub.typing.lowlevel.Engine.leq(tp1[i],tp2[i]); mlsub.typing.lowlevel.Engine.leq(tp2[i],tp1[i]); Index: MonotypeVar.java =================================================================== RCS file: /cvsroot/nice/Nice/src/mlsub/typing/MonotypeVar.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** MonotypeVar.java 16 Jun 2004 10:00:36 -0000 1.17 --- MonotypeVar.java 30 Jul 2004 19:08:45 -0000 1.18 *************** *** 172,175 **** --- 172,177 ---- void reset() { + unknown = false; + if (persistentKind == null) { *************** *** 199,202 **** --- 201,215 ---- } + private boolean unknown; + + boolean isUnknown() { return unknown; } + + void setUnknown() + throws mlsub.typing.lowlevel.Unsatisfiable + { + super.setUnknown(); + this.unknown = true; + } + /** When this variable is discovered to be of some given kind, an equivalent monotype is created. */ Index: Monotype.java =================================================================== RCS file: /cvsroot/nice/Nice/src/mlsub/typing/Monotype.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Monotype.java 17 Mar 2004 16:55:34 -0000 1.10 --- Monotype.java 30 Jul 2004 19:08:45 -0000 1.11 *************** *** 121,124 **** --- 121,133 ---- } + boolean isUnknown() { return false; } + + void setUnknown() + throws mlsub.typing.lowlevel.Unsatisfiable + { + mlsub.typing.lowlevel.Engine.leq + (TopMonotype.instance, nice.tools.typing.Types.rawType(this)); + } + /**************************************************************** * Simplification --- NEW FILE: UnknownMonotype.java --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package mlsub.typing; import mlsub.typing.lowlevel.Kind; import mlsub.typing.lowlevel.Element; /** An unknown monotype. @author Daniel Bonniot (bo...@us...) */ public class UnknownMonotype extends Monotype implements TypeSymbol { private UnknownMonotype() {} public static final UnknownMonotype instance = new UnknownMonotype(); public TypeSymbol cloneTypeSymbol() { return this; } boolean isUnknown() { return true; } Monotype canonify() { return this; } Monotype substitute(java.util.Map map) { return this; } void tag(int variance) {} public String toString() { return "?"; } /**************************************************************** * low-level interface ****************************************************************/ public int getId() { throw new Error(); } public void setId(int value) { throw new Error(); } public Kind getKind() { return NullnessKind.instance; } public void setKind(Kind value) { throw new Error(); } } |
From: Daniel B. <bo...@us...> - 2004-07-30 19:08:53
|
Update of /cvsroot/nice/Nice/src/nice/tools/code In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6432/src/nice/tools/code Modified Files: Types.java Log Message: java.lang.Class is now parameterized by the type it represents. Index: Types.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/code/Types.java,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** Types.java 2 Jul 2004 12:12:20 -0000 1.58 --- Types.java 30 Jul 2004 19:08:44 -0000 1.59 *************** *** 513,525 **** } - if (tc.variance != null && tc.arity() != 0) - throw new ParametricClassException(tc.toString()); - if (tc.getId() == -1) throw new NotIntroducedClassException(tc); ! ! return new MonotypeConstructor(tc, null); } ! /**************************************************************** * Converting string to gnu.bytecode.Type --- 513,527 ---- } if (tc.getId() == -1) throw new NotIntroducedClassException(tc); ! ! try { ! return nice.tools.typing.Types.zeroArgMonotype(tc); ! } ! catch (BadSizeEx ex) { ! throw new ParametricClassException(tc.toString()); ! } } ! /**************************************************************** * Converting string to gnu.bytecode.Type *************** *** 557,566 **** return TypeImport.lookup(s, loc); } ! /** ! The type is not necessarily fully qulified. */ ! public static final ! gnu.bytecode.Type typeRepresentationToBytecode(String type, bossa.util.Location loc) { --- 559,568 ---- return TypeImport.lookup(s, loc); } ! /** ! The type is not necessarily fully qualified. */ ! public static final ! gnu.bytecode.Type typeRepresentationToBytecode(String type, bossa.util.Location loc) { *************** *** 573,577 **** return SpecialArray.create(res); } ! TypeConstructor sym = bossa.syntax.Node.getGlobalTypeScope(). globalLookup(type, loc); --- 575,582 ---- return SpecialArray.create(res); } ! ! if (type.equals("Object") || type.equals("java.lang.Object")) ! return Type.pointer_type; ! TypeConstructor sym = bossa.syntax.Node.getGlobalTypeScope(). globalLookup(type, loc); |
From: Daniel B. <bo...@us...> - 2004-07-30 18:31:20
|
Update of /cvsroot/nice/Nice/testsuite/compiler/expressions/arrays In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32295/testsuite/compiler/expressions/arrays Modified Files: literal.testsuite Log Message: For literal arrays with a known expected type, perform type-checking on the elements instead of inferring the type of the whole array. Index: literal.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/expressions/arrays/literal.testsuite,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** literal.testsuite 2 Jul 2004 15:14:58 -0000 1.12 --- literal.testsuite 30 Jul 2004 18:31:11 -0000 1.13 *************** *** 54,55 **** --- 54,58 ---- lists.foreach(List<T> list => i = list.size); } + + /// FAIL + int[] i = [1, /*/// FAIL HERE*/ ""]; |
From: Daniel B. <bo...@us...> - 2004-07-30 18:31:19
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32295/src/bossa/syntax Modified Files: literalarray.nice Log Message: For literal arrays with a known expected type, perform type-checking on the elements instead of inferring the type of the whole array. Index: literalarray.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/literalarray.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** literalarray.nice 28 Jul 2004 14:40:33 -0000 1.1 --- literalarray.nice 30 Jul 2004 18:31:10 -0000 1.2 *************** *** 66,71 **** if (elementType != null) ! for (elem : elements) ! elem.adjustToExpectedType(elementType); return this; --- 66,95 ---- if (elementType != null) ! { ! // Accept for us the type the context imposes, and just check ! // that the array elements fit. ! if (this.type == null && expectedType.isMonomorphic()) ! { ! for (int i = 0; i < elements.length; i++) ! { ! elements[i] = elements[i].noOverloading(); ! try { ! mlsub.typing.Typing.leq(elements[i].getType(), elementType); ! } ! catch (mlsub.typing.TypingEx ex) { ! throw User.error ! (elements[i], "Incorrect type for array element:" + ! "\nFound : " + elements[i].getType() + ! "\nExpected : " + elementType); ! } ! } ! ! // Make the context type our type. ! this.type = expectedType; ! } ! ! for (elem : elements) ! elem.adjustToExpectedType(elementType); ! } return this; *************** *** 91,95 **** if (elementType != null) for (elem : elements) ! elem.adjustToExpectedType(elementType); } --- 115,119 ---- if (elementType != null) for (elem : elements) ! elem.adjustToExpectedType(elementType); } |