nice-commit Mailing List for The Nice Programming Language (Page 39)
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-12 13:26:55
|
Update of /cvsroot/nice/Nice/testsuite/compiler/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13913/F:/nice/testsuite/compiler/typing Added Files: dti.testsuite Log Message: Testcases for type inference that takes in account assignments, merging of branches at exit, not capturing variables before a closure declaration. --- NEW FILE: dti.testsuite --- /// Global ?String maybeString() = null; let ()->?String maybeStringGenerator = (int x => ()=> x++ > 10 ? "abc" : null)(0); void maybeThrow() = throw new Exception(); boolean maybeTrue() = true; /// PASS bug ?String s = maybeString(); if (s == null) s = "abc"; s.substring(1); /// PASS bug ?String s = null; if(maybeTrue()) s = "abc"; else s = "zyx"; s.substring(1); /// FAIL ?String s = null; if(maybeTrue()) s = "abc"; else s = null; s.substring(1); /// PASS bug ?String s = maybeString(); if (s != null) s.substring(1); void foo() { s = null; } foo(); /// PASS bug ?String s = maybeString(); ?String t = null; if (s != null) { t = s; t.substring(1); } /// PASS bug ?String s = maybeStringGenerator(); while (s == null) s = maybeStringGenerator(); s.substring(1); /// PASS bug ?String s = maybeStringGenerator(); while (s == null) { s = maybeStringGenerator(); if (s != null) break; s = maybeStringGenerator(); } s.substring(1); /// FAIL ?String s = maybeStringGenerator(); while (s == null) { s = maybeStringGenerator(); if (s == null) break; s = maybeStringGenerator(); } s.substring(1); /// FAIL ?String s = "abc"; ?String t = "xyz"; void foo() { t=s; s = null; } foo(); foo(); t.substring(1); /// PASS bug ?String s = maybeString(); if (s == null) s = "abc"; void foo() { s = "xyz"; } foo(); s.substring(1); /// FAIL ?String s = "abc"; try { s = null; maybeException(); s = "xyz"; } catch (Exception e) { s.substring(1); } /// FAIL ?String s = "abc"; try { maybeException(); } catch (Exception e) { s = null; } catch (Exception e) { s = "xyz"; } finally { s.substring(1); } /// FAIL ?String s = "abc"; ()->void func; int x = 0; while (x++ < 10) { s.substring(1); func = () => {s = null; }; func(); } |
From: Daniel B. <bo...@us...> - 2004-08-12 09:31:03
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2065/stdlib/nice/lang Modified Files: java.nice Log Message: Typo. Index: java.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/java.nice,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** java.nice 11 Aug 2004 18:07:40 -0000 1.56 --- java.nice 12 Aug 2004 09:30:54 -0000 1.57 *************** *** 218,222 **** interface ListIterator<T> extends Iterator<T> = native java.util.ListIterator; interface Map<K,V> = native java.util.Map; ! interface SortedMap<K,V> extends Map<T> = native java.util.SortedMap; interface Map$Entry<K,V> = native java.util.Map.Entry; class AbstractCollection<T> implements Collection<T> = native java.util.AbstractCollection; --- 218,222 ---- interface ListIterator<T> extends Iterator<T> = native java.util.ListIterator; interface Map<K,V> = native java.util.Map; ! interface SortedMap<K,V> extends Map<K,V> = native java.util.SortedMap; interface Map$Entry<K,V> = native java.util.Map.Entry; class AbstractCollection<T> implements Collection<T> = native java.util.AbstractCollection; |
From: Daniel B. <bo...@us...> - 2004-08-11 18:07:49
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16330/stdlib/nice/lang Modified Files: java.nice Log Message: Removed useless retypings for non-root classes that should not directly implement an interface. Index: java.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/java.nice,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** java.nice 31 Jul 2004 10:05:56 -0000 1.55 --- java.nice 11 Aug 2004 18:07:40 -0000 1.56 *************** *** 222,241 **** class AbstractCollection<T> implements Collection<T> = native java.util.AbstractCollection; class AbstractList<T> extends AbstractCollection<T> implements List<T> = native java.util.AbstractList; - class AbstractSequentialList<T> extends AbstractList<T> = native java.util.AbstractSequentialList; class AbstractSet<T> extends AbstractCollection<T> implements Set<T> = native java.util.AbstractSet; class AbstractMap<K,V> implements Map<K,V> = native java.util.AbstractMap; ! class ArrayList<T> extends AbstractList<T> = native java.util.ArrayList; class Dictionary<K,V> = native java.util.Dictionary; ! class HashMap<K,V> extends AbstractMap<K,V> = native java.util.HashMap; ! class LinkedHashMap<K,V> extends AbstractMap<K,V> = native java.util.LinkedHashMap; ! class HashSet<T> extends AbstractSet<T> = native java.util.HashSet; ! class LinkedHashSet<T> extends AbstractSet<T> = native java.util.LinkedHashSet; ! class Hashtable<K,V> implements Map<K,V> = native java.util.Hashtable; ! class IdentityHashMap<K,V> extends AbstractMap<K,V> = native java.util.IdentityHashMap; ! class LinkedList<T> extends AbstractSequentialList<T> = native java.util.LinkedList; ! class Stack<T> extends Vector<T> = native java.util.Stack; ! class TreeMap<K,V> extends AbstractMap<K,V> implements SortedMap<K,V> = native java.util.TreeMap; ! class TreeSet<T> extends AbstractSet<T> implements SortedSet<T> = native java.util.TreeSet; ! class Vector<T> extends AbstractList<T> = native java.util.Vector; <T> Iterator<T> iterator(Collection<T>) = --- 222,233 ---- class AbstractCollection<T> implements Collection<T> = native java.util.AbstractCollection; class AbstractList<T> extends AbstractCollection<T> implements List<T> = native java.util.AbstractList; class AbstractSet<T> extends AbstractCollection<T> implements Set<T> = native java.util.AbstractSet; class AbstractMap<K,V> implements Map<K,V> = native java.util.AbstractMap; ! class ArrayList<T> extends AbstractList<T> implements List<T> = native java.util.ArrayList; class Dictionary<K,V> = native java.util.Dictionary; ! class HashSet<T> extends AbstractSet<T> implements Set<T> = native java.util.HashSet; ! class LinkedList<T> extends AbstractSequentialList<T> implements List<T> = native java.util.LinkedList; ! class Stack<T> extends Vector<T> implements List<T> = native java.util.Stack; ! class Vector<T> extends AbstractList<T> implements List<T> = native java.util.Vector; <T> Iterator<T> iterator(Collection<T>) = *************** *** 415,421 **** // java.lang.ref class Reference<T> = native java.lang.ref.Reference; - class WeakReference<T> extends Reference<T> = native java.lang.ref.WeakReference; - class SoftReference<T> extends Reference<T> = native java.lang.ref.SoftReference; - class PhantomReference<T> extends Reference<T> = native java.lang.ref.PhantomReference; class ReferenceQueue<T> = native java.lang.ref.ReferenceQueue; --- 407,410 ---- |
From: Arjan B. <ar...@us...> - 2004-08-11 16:09:44
|
Update of /cvsroot/nice/Nice/src/bossa/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24811/F:/nice/src/bossa/modules Modified Files: Compilation.java Compilation.nice Log Message: Removed the '--strict' compiler option. Index: Compilation.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Compilation.nice,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** Compilation.nice 7 Aug 2004 14:57:33 -0000 1.29 --- Compilation.nice 11 Aug 2004 16:09:36 -0000 1.30 *************** *** 44,51 **** boolean excludeRuntime = false; - /** Give stricter type to java methods. - */ - boolean strictJavaTypes = false; - /** Location of the nice.jar file. */ ?String runtimeFile = null; --- 44,47 ---- Index: Compilation.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Compilation.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Compilation.java 30 Jun 2004 14:12:38 -0000 1.9 --- Compilation.java 11 Aug 2004 16:09:36 -0000 1.10 *************** *** 30,34 **** public String output; public boolean excludeRuntime; - public boolean strictJavaTypes; public Parser parser; --- 30,33 ---- |
From: Arjan B. <ar...@us...> - 2004-08-11 16:09:44
|
Update of /cvsroot/nice/Nice/src/nice/tools/compiler/console In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24811/F:/nice/src/nice/tools/compiler/console Modified Files: main.nice Log Message: Removed the '--strict' compiler option. Index: main.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/compiler/console/main.nice,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** main.nice 30 Jun 2004 14:12:36 -0000 1.8 --- main.nice 11 Aug 2004 16:09:35 -0000 1.9 *************** *** 105,112 **** () => { compilation.skipLink = true; }), - option("strict", - "Type-check uses of java classes more stricly", - () => { compilation.strictJavaTypes = true; }), - // PRIVATE OPTIONS --- 105,108 ---- |
From: Arjan B. <ar...@us...> - 2004-08-11 16:09:43
|
Update of /cvsroot/nice/Nice/src/nice/tools/code In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24811/F:/nice/src/nice/tools/code Modified Files: Import.java Log Message: Removed the '--strict' compiler option. Index: Import.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/code/Import.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Import.java 25 Feb 2004 14:23:21 -0000 1.5 --- Import.java 11 Aug 2004 16:09:35 -0000 1.6 *************** *** 91,101 **** } - boolean strictImport = - bossa.modules.Package.currentCompilation.strictJavaTypes; - boolean nonNullArgs = strictPackages.contains (m.getDeclaringClass().getPackageName()); ! if (strictImport || nonNullArgs) { for (int i = 0; i < paramTypes.length; i++) --- 91,98 ---- } boolean nonNullArgs = strictPackages.contains (m.getDeclaringClass().getPackageName()); ! if (nonNullArgs) { for (int i = 0; i < paramTypes.length; i++) *************** *** 112,154 **** mlsub.typing.Monotype retType; if (constructor) // the return type is surely not null retType = Types.monotype(declaringClass.thisType(), true, typeParameters, niceTP); ! else if (strictImport) ! { ! Type returnType = m.getFullReturnType(); ! if (m.getStaticFlag()) ! //no exception found yet to this assumption ! retType = Types.monotype(returnType, true, ! typeParameters, niceTP, true); ! else ! { ! Type classType = declaringClass.thisType(); ! ! if ((returnType.getName() != null) && returnType.getName(). ! equals(classType.getName())) ! //if returntype equals declaringclass than it's almost sure ! //that returntype isn't null, this sort of methods are common ! //in immutable classes such as String ! retType = Types.monotype(returnType, true, typeParameters, ! niceTP); ! else if ((returnType instanceof ParameterizedType) && ! (classType instanceof ParameterizedType) && ! (((ParameterizedType)returnType).main.getName() != null) && ! (((ParameterizedType)returnType).main.getName().equals( ! ((ParameterizedType)classType).main.getName()))) ! //same as above for parameterized classes a bit more difficult ! retType = Types.monotype(returnType, true, typeParameters, ! niceTP); ! else if (returnType instanceof ArrayType) ! //an array can be empty so it should never be null ! retType = Types.monotype(returnType, true, typeParameters, ! niceTP, true); ! else ! //the rest where no good guess is possible about nullness ! retType = Types.monotype(returnType, typeParameters, niceTP); ! } ! } else { ! //if not strict then returntype not null. retType = Types.monotype(m.getFullReturnType(), true, typeParameters, niceTP, true); --- 109,118 ---- mlsub.typing.Monotype retType; if (constructor) + { // the return type is surely not null retType = Types.monotype(declaringClass.thisType(), true, typeParameters, niceTP); ! } else { ! // returntype not null. retType = Types.monotype(m.getFullReturnType(), true, typeParameters, niceTP, true); |
From: Arjan B. <ar...@us...> - 2004-08-11 16:09:43
|
Update of /cvsroot/nice/Nice In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24811/Nice Modified Files: NEWS Log Message: Removed the '--strict' compiler option. Index: NEWS =================================================================== RCS file: /cvsroot/nice/Nice/NEWS,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** NEWS 3 Aug 2004 17:27:40 -0000 1.40 --- NEWS 11 Aug 2004 16:09:34 -0000 1.41 *************** *** 13,16 **** --- 13,18 ---- in particular when using class literals. * Improved speed of coverage tests for some methods. + * Removed the '--strict' compiler option. + -- |
From: Arjan B. <ar...@us...> - 2004-08-11 14:13:12
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1683/F:/nice/src/bossa/parser Modified Files: Parser.jj Log Message: Avoid lookahead on default value of a field to improve parse errors. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.255 retrieving revision 1.256 diff -C2 -d -r1.255 -r1.256 *** Parser.jj 8 Aug 2004 21:51:54 -0000 1.255 --- Parser.jj 11 Aug 2004 14:13:02 -0000 1.256 *************** *** 956,959 **** --- 956,977 ---- } + void fieldLookahead(): + {} + { + ( "override" + | + ( "public-read" [ "private-write" ] + | "private-write" + | ( ("public" | "private" | {} ) + [ "final" ] + ) + ) + [ "transient" ] + [ "volatile" ] + ) + monoSymbol() + ( "=" | ";" ) + } + List getField(NiceClass c, List fields, List overrides, boolean storeDocString): { *************** *** 1060,1064 **** } | ! LOOKAHEAD( getField(null, null) ) overrides = getField(impl, fields, overrides, storeDocString) | { Definition m; Token t = getToken(1); boolean isOverride = false; } --- 1078,1082 ---- } | ! LOOKAHEAD( fieldLookahead() ) overrides = getField(impl, fields, overrides, storeDocString) | { Definition m; Token t = getToken(1); boolean isOverride = false; } |
From: Arjan B. <ar...@us...> - 2004-08-11 13:36:19
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27561/F:/nice/src/bossa/syntax Modified Files: break.nice Log Message: Added missing toString() in LabeledStmt. Index: break.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/break.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** break.nice 28 Jul 2004 14:40:33 -0000 1.1 --- break.nice 11 Aug 2004 13:36:09 -0000 1.2 *************** *** 93,97 **** block = null; return res; ! } } --- 93,99 ---- block = null; return res; ! } ! ! toString() = this.name() + ":\n" + statement; } |
From: Arjan B. <ar...@us...> - 2004-08-11 12:34:41
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16145/F:/nice/src/bossa/syntax Modified Files: call.nice Log Message: Check assignability of fields earlier. Index: call.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/call.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** call.nice 8 Aug 2004 21:51:54 -0000 1.2 --- call.nice 11 Aug 2004 12:34:30 -0000 1.3 *************** *** 111,115 **** { this.resolveOverloading(); ! return function.isFieldAccess(); } --- 111,116 ---- { this.resolveOverloading(); ! let ?FieldAccess fa = function.getFieldAccessMethod(); ! return fa != null && ! fa.isFinal(); } *************** *** 200,204 **** if (access.isFinal()) ! User.error(this, "Field " + access + " is final"); if (arguments.size() == 0) --- 201,205 ---- if (access.isFinal()) ! Internal.error(this, "Field " + access + " is final"); if (arguments.size() == 0) |
From: Daniel B. <bo...@us...> - 2004-08-11 09:06:14
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang/inline In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13107/stdlib/nice/lang/inline Modified Files: Instanceof.java Log Message: Make instanceof work with non-literal type expressions. Index: Instanceof.java =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/inline/Instanceof.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Instanceof.java 19 Dec 2003 02:12:34 -0000 1.4 --- Instanceof.java 11 Aug 2004 09:06:04 -0000 1.5 *************** *** 38,53 **** public void compile (ApplyExp exp, Compilation comp, Target target) { - gnu.bytecode.CodeAttr code = comp.getCode(); Expression[] args = exp.getArgs(); Expression value = args[0]; ! Type type = (Type) ((QuoteExp) args[1]).getValue(); // instanceof on boolean can make sense if (type == Type.boolean_type) type = Type.boolean_ctype; ! if (type instanceof PrimType) throw new bossa.util.UserError ! (exp, "instanceof cannot be used with primitive types"); value.compile(comp, Target.pushObject); --- 38,66 ---- public void compile (ApplyExp exp, Compilation comp, Target target) { Expression[] args = exp.getArgs(); Expression value = args[0]; ! Expression typeExp = args[1]; ! ! if (typeExp instanceof QuoteExp && ! ((QuoteExp) typeExp).getValue() instanceof Type) ! compile(value, (Type) ((QuoteExp) typeExp).getValue(), comp, exp); ! else ! compile(value, typeExp, comp); ! ! target.compileFromStack(comp, Type.boolean_type); ! } ! ! private void compile(Expression value, Type type, Compilation comp, ! Expression applyExp) ! { ! gnu.bytecode.CodeAttr code = comp.getCode(); // instanceof on boolean can make sense if (type == Type.boolean_type) type = Type.boolean_ctype; ! if (type instanceof PrimType) throw new bossa.util.UserError ! (applyExp, "instanceof cannot be used with primitive types"); value.compile(comp, Target.pushObject); *************** *** 68,72 **** else code.emitInstanceof(type); ! target.compileFromStack(comp, Type.boolean_type); } --- 81,94 ---- else code.emitInstanceof(type); ! } ! ! private void compile(Expression value, Expression type, Compilation comp) ! { ! gnu.bytecode.CodeAttr code = comp.getCode(); ! ! type.compile(comp, Target.pushObject); ! value.compile(comp, Target.pushObject); ! code.emitInvoke ! (ClassType.make("java.lang.Class").getDeclaredMethod("isInstance", 1)); } |
From: Daniel B. <bo...@us...> - 2004-08-11 09:06:13
|
Update of /cvsroot/nice/Nice/testsuite/compiler/native In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13107/testsuite/compiler/native Modified Files: instanceof.testsuite Log Message: Make instanceof work with non-literal type expressions. Index: instanceof.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/native/instanceof.testsuite,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** instanceof.testsuite 30 Jul 2004 19:08:42 -0000 1.8 --- instanceof.testsuite 11 Aug 2004 09:06:04 -0000 1.9 *************** *** 45,46 **** --- 45,52 ---- Object l = [""]; assert l instanceof String[]; + + /// PASS + assert "".isa(java.lang.String); + assert ! "".isa(java.io.File); + /// Toplevel + <T,U> boolean isa(T value, Class<U> type) = `instanceof`(value, type); |
From: Daniel B. <bo...@us...> - 2004-08-10 17:22:29
|
Update of /cvsroot/nice/Nice/src/bossa/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20659/src/bossa/modules Modified Files: Package.java Content.java Log Message: Make sure to get the imported packages from the source version when recompilation is forced. Index: Package.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Package.java,v retrieving revision 1.119 retrieving revision 1.120 diff -C2 -d -r1.119 -r1.120 *** Package.java 7 Aug 2004 14:57:33 -0000 1.119 --- Package.java 10 Aug 2004 17:22:19 -0000 1.120 *************** *** 62,67 **** * Single Constructor ****************************************************************/ ! ! private Package(LocatedString name, Compilation compilation, boolean isRoot) --- 62,67 ---- * Single Constructor ****************************************************************/ ! ! private Package(LocatedString name, Compilation compilation, boolean isRoot) *************** *** 77,89 **** User.error(name, "Could not find package " + name); ! loadImports(); prepareCodeGeneration(); ! read(compilation.recompileAll || ! isRoot && compilation.recompileCommandLine); } ! private void loadImports() { Set opens = new TreeSet(); --- 77,92 ---- User.error(name, "Could not find package " + name); ! boolean shouldReload = ! compilation.recompileAll || ! isRoot && compilation.recompileCommandLine; ! ! loadImports(shouldReload); prepareCodeGeneration(); ! read(shouldReload); } ! private void loadImports(boolean shouldReload) { Set opens = new TreeSet(); *************** *** 91,100 **** opens.add("java.util"); ! imports = source.getImports(opens); if (!name.toString().equals("nice.lang") && !Debug.ignorePrelude) ! imports.add(new LocatedString("nice.lang", bossa.util.Location.nowhere())); ! setOpens(opens); --- 94,103 ---- opens.add("java.util"); ! imports = source.getImports(opens, shouldReload); if (!name.toString().equals("nice.lang") && !Debug.ignorePrelude) ! imports.add(new LocatedString("nice.lang", bossa.util.Location.nowhere())); ! setOpens(opens); Index: Content.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Content.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Content.java 23 Jul 2004 21:52:40 -0000 1.16 --- Content.java 10 Aug 2004 17:22:19 -0000 1.17 *************** *** 55,68 **** } ! List getImports(Set opens) { Content.Unit[] readers; ! /* ! If the package is up to date, preferably load imports from ! the compiled package, since that involves touching only one file ! instead of possiby several. */ ! if (source != null && ! (compiled == null || lastModification > lastCompilation)) readers = source.getDefinitions(); else --- 55,69 ---- } ! List getImports(Set opens, boolean shouldReload) { Content.Unit[] readers; ! /* ! If the package is up to date, preferably load imports from ! the compiled package, since that involves touching only one file ! instead of possiby several. */ ! if (source != null && ! (shouldReload || compiled == null || ! lastModification > lastCompilation)) readers = source.getDefinitions(); else |
From: Arjan B. <ar...@us...> - 2004-08-10 16:50:32
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14224/F:/nice/src/bossa/syntax Removed Files: ExpLocalVariable.java Log Message: Removed explocalvariable. --- ExpLocalVariable.java DELETED --- |
From: Arjan B. <ar...@us...> - 2004-08-08 21:52:20
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29035/F:/nice/src/bossa/syntax Modified Files: Arguments.java CustomConstructor.java analyse.nice call.nice dispatch.java.bootstrap loop.nice rewrite.nice tools.nice typecheck.nice Added Files: block.nice locals.nice Removed Files: Block.java Log Message: Converted block and local variables to nice code. Index: analyse.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/analyse.nice,v retrieving revision 1.108 retrieving revision 1.109 diff -C2 -d -r1.108 -r1.109 *** analyse.nice 5 Aug 2004 10:45:29 -0000 1.108 --- analyse.nice 8 Aug 2004 21:51:54 -0000 1.109 *************** *** 218,222 **** } ! void checkInitialized(Block.LocalVariable.Symbol sym, Info info, ?bossa.util.Location loc) { --- 218,222 ---- } ! void checkInitialized(LocalVariableSymbol sym, Info info, ?bossa.util.Location loc) { *************** *** 239,243 **** analyse(Expression e, i) = e; ! void setInitialized (Block.LocalVariable.Symbol v, Info info, bossa.util.Location loc) { --- 239,243 ---- analyse(Expression e, i) = e; ! void setInitialized (LocalVariableSymbol v, Info info, bossa.util.Location loc) { *************** *** 311,321 **** Arguments args = e.arguments; - let ExpLocalVariable[?] expLocals = e.localVars = cast(args.extractLocalVars()); - if (e.infix) markAsCallFirstArg(notNull(args.getExp(0))); ! if (expLocals != null) { info.begin(); for (local : expLocals) --- 311,326 ---- Arguments args = e.arguments; if (e.infix) markAsCallFirstArg(notNull(args.getExp(0))); ! List<ExpLocalVariable> expLocals = new ArrayList(); ! ! for (int i = args.size(); --i>=0; ) ! if (args.getExp(i) instanceof ExpLocalVariable) ! expLocals.add(cast(args.getExp(i))); ! ! if (!expLocals.isEmpty()) { + e.localVars = expLocals; info.begin(); for (local : expLocals) *************** *** 328,332 **** args.analyse(info, noEscape); ! if (expLocals != null) info.end(); --- 333,337 ---- args.analyse(info, noEscape); ! if (!expLocals.isEmpty()) info.end(); *************** *** 471,475 **** sym.captured = true; ! if (sym instanceof Block.LocalVariable.Symbol) { if (assigned) --- 476,480 ---- sym.captured = true; ! if (sym instanceof LocalVariableSymbol) { if (assigned) *************** *** 679,683 **** analyse(null(Statement), info) {} ! analyse(Block.LocalVariable decl, info) { if (decl.value != null) --- 684,688 ---- analyse(null(Statement), info) {} ! analyse(LocalVariable decl, info) { if (decl.value != null) *************** *** 692,696 **** } ! analyse(Block.LocalConstant decl, info) { decl.value = analyse(decl.value, info); --- 697,701 ---- } ! analyse(LocalConstant decl, info) { decl.value = analyse(decl.value, info); *************** *** 698,702 **** } ! analyse(Block.LocalFunction decl, info) { notNull(decl.parameters).resolveCalledFromAnalyse(cast(info)); --- 703,707 ---- } ! analyse(LocalFunction decl, info) { notNull(decl.parameters).resolveCalledFromAnalyse(cast(info)); *************** *** 709,713 **** { info.begin(); ! notNull(b.locals).foreach(Block.LocalDeclaration l => analyse(l, info)); analyse(b.statements, info); info.end(); --- 714,718 ---- { info.begin(); ! notNull(b.locals).foreach(LocalDeclaration l => analyse(l, info)); analyse(b.statements, info); info.end(); *************** *** 717,725 **** } ! void analyse(?Statement[] statements, Info info) { for (int i = 0; i < statements.length; i++) { ! ?Statement s = statements[i]; if (info.getUnreachable()) throw error(s, "This statement is never executed"); --- 722,730 ---- } ! void analyse(Statement[] statements, Info info) { for (int i = 0; i < statements.length; i++) { ! Statement s = statements[i]; if (info.getUnreachable()) throw error(s, "This statement is never executed"); Index: CustomConstructor.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/CustomConstructor.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** CustomConstructor.java 2 Aug 2004 19:10:58 -0000 1.17 --- CustomConstructor.java 8 Aug 2004 21:51:54 -0000 1.18 *************** *** 32,36 **** public static CustomConstructor make (LocatedString className, Constraint cst, FormalParameters params, ! Block body) { return new SourceCustomConstructor(className, cst, params, body); --- 32,36 ---- public static CustomConstructor make (LocatedString className, Constraint cst, FormalParameters params, ! Statement body) { return new SourceCustomConstructor(className, cst, params, body); *************** *** 121,125 **** { SourceCustomConstructor(LocatedString className, Constraint cst, ! FormalParameters params, Block body) { super(className, cst, params); --- 121,125 ---- { SourceCustomConstructor(LocatedString className, Constraint cst, ! FormalParameters params, Statement body) { super(className, cst, params); --- Block.java DELETED --- Index: loop.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/loop.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** loop.nice 5 Aug 2004 10:45:30 -0000 1.2 --- loop.nice 8 Aug 2004 21:51:54 -0000 1.3 *************** *** 23,27 **** ?Expression whileExp; final Statement loopBody; ! final ?Block iterationStatements = null; final boolean testFirst; --- 23,27 ---- ?Expression whileExp; final Statement loopBody; ! final ?Statement iterationStatements = null; final boolean testFirst; *************** *** 98,102 **** (loopBody == null ? ";" : loopBody.toString()); ! Statement[] itStatements = cast(notNull(iterationStatements).statements); String itStats = ""; for(int i = 0; i<itStatements.length; i++) --- 98,103 ---- (loopBody == null ? ";" : loopBody.toString()); ! Block itbl = cast(iterationStatements); ! Statement[] itStatements = itbl.statements; String itStats = ""; for(int i = 0; i<itStatements.length; i++) *************** *** 113,117 **** public LoopStmt createForLoop ! (Expression test, Block update, Statement body) { return new LoopStmt(whileExp:test, loopBody: body, iterationStatements: update, testFirst: true); --- 114,118 ---- public LoopStmt createForLoop ! (Expression test, Statement update, Statement body) { return new LoopStmt(whileExp:test, loopBody: body, iterationStatements: update, testFirst: true); *************** *** 143,153 **** let getiter = createCallExp(new IdentExp(new LocatedString("forIterator", loc)), container); let iter = new LocatedString(loc.uniqueIdentifier("for_in_iter_"), loc); ! let init = new Block.LocalVariable(iter, itertype, true, getiter); let iterexp = new IdentExp(iter); let cond = createCallExp(new IdentExp(new LocatedString("hasNext", loc)), iterexp); let getvar = createCallExp(new IdentExp(new LocatedString("next", loc)), iterexp); ! let assign = new Block.LocalVariable(varName, vartype, true, getvar); ! let loop = createWhileLoop(cond, new Block(new LinkedList([assign, body]))); ! return new Block(new LinkedList([init, loop])); } --- 144,154 ---- let getiter = createCallExp(new IdentExp(new LocatedString("forIterator", loc)), container); let iter = new LocatedString(loc.uniqueIdentifier("for_in_iter_"), loc); ! let init = new LocalVariable(iter, itertype, true, getiter); let iterexp = new IdentExp(iter); let cond = createCallExp(new IdentExp(new LocatedString("hasNext", loc)), iterexp); let getvar = createCallExp(new IdentExp(new LocatedString("next", loc)), iterexp); ! let assign = new LocalVariable(varName, vartype, true, getvar); ! let loop = createWhileLoop(cond, createBlock(new LinkedList([assign, body]))); ! return createBlock(new LinkedList([init, loop])); } Index: typecheck.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v retrieving revision 1.111 retrieving revision 1.112 diff -C2 -d -r1.111 -r1.112 *** typecheck.nice 7 Aug 2004 16:48:13 -0000 1.111 --- typecheck.nice 8 Aug 2004 21:51:54 -0000 1.112 *************** *** 677,681 **** typecheck(ExpLocalVariable e) { ! Block.LocalVariable decl = notNull(e.variable); MonoSymbol target = notNull(decl.left); --- 677,681 ---- typecheck(ExpLocalVariable e) { ! let decl = e.variable; MonoSymbol target = notNull(decl.left); *************** *** 733,737 **** b.statements = rewrite(b.statements); ! b.locals.foreach(?Block.LocalDeclaration d => typecheck(d)); b.statements.foreach (?Statement s => { --- 733,737 ---- b.statements = rewrite(b.statements); ! b.locals.foreach(?LocalDeclaration d => typecheck(d)); b.statements.foreach (?Statement s => { *************** *** 746,750 **** } ! typecheck(Block.LocalVariable decl) { MonoSymbol target = notNull(decl.left()); --- 746,750 ---- } ! typecheck(LocalVariable decl) { MonoSymbol target = notNull(decl.left()); *************** *** 789,793 **** } ! typecheck(Block.LocalConstant decl) { if (! notNull(decl.left).used) --- 789,793 ---- } ! typecheck(LocalConstant decl) { if (! notNull(decl.left).used) *************** *** 805,809 **** } ! typecheck(Block.LocalFunction decl) { typecheck(decl.value); --- 805,809 ---- } ! typecheck(LocalFunction decl) { typecheck(decl.value); Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** tools.nice 7 Aug 2004 14:20:29 -0000 1.46 --- tools.nice 8 Aug 2004 21:51:54 -0000 1.47 *************** *** 63,67 **** mlsub.typing.Monotype ensureMonomorphic(mlsub.typing.Polytype type, ! Block.LocalValue decl) { type.simplify(); --- 63,67 ---- mlsub.typing.Monotype ensureMonomorphic(mlsub.typing.Polytype type, ! LocalValue decl) { type.simplify(); *************** *** 192,205 **** mlsub.typing.Monotype type(MonoSymbol) = native MonoSymbol.type; GlobalTypeScope getGlobalTypeScope() = native GlobalTypeScope Node.getGlobalTypeScope(); - List<Block.LocalDeclaration> locals(Block) = native Block.locals; - ?Statement[] statements(Block) = native Block.statements; ?gnu.bytecode.ClassType staticClass(Arguments) = native gnu.bytecode.ClassType Arguments.staticClass(); List<VarSymbol> findJavaMethods(?gnu.bytecode.ClassType, String, int) = native List JavaClasses.findJavaMethods(gnu.bytecode.ClassType,java.lang.String,int); List<VarSymbol> findJavaMethods(?gnu.bytecode.ClassType, String) = native List JavaClasses.findJavaMethods(gnu.bytecode.ClassType,java.lang.String); TypeParameters TypeParameters(List<Monotype>) = native new bossa.syntax.TypeParameters(List); - Block Block(List<Statement>) = native new bossa.syntax.Block(List); String explainNoMatch(Arguments, List<VarSymbol>) = native String Arguments.explainNoMatch(List); Map<VarSymbol,mlsub.typing.Polytype> types(Arguments) = native Arguments.types; <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(); --- 192,203 ---- mlsub.typing.Monotype type(MonoSymbol) = native MonoSymbol.type; GlobalTypeScope getGlobalTypeScope() = native GlobalTypeScope Node.getGlobalTypeScope(); ?gnu.bytecode.ClassType staticClass(Arguments) = native gnu.bytecode.ClassType Arguments.staticClass(); List<VarSymbol> findJavaMethods(?gnu.bytecode.ClassType, String, int) = native List JavaClasses.findJavaMethods(gnu.bytecode.ClassType,java.lang.String,int); List<VarSymbol> findJavaMethods(?gnu.bytecode.ClassType, String) = native List JavaClasses.findJavaMethods(gnu.bytecode.ClassType,java.lang.String); TypeParameters TypeParameters(List<Monotype>) = native new bossa.syntax.TypeParameters(List); String explainNoMatch(Arguments, List<VarSymbol>) = native String Arguments.explainNoMatch(List); Map<VarSymbol,mlsub.typing.Polytype> types(Arguments) = native Arguments.types; <T> String map(String, String, String, T[]) = native String bossa.util.Util.map(String, String, String, Object[]); + <T> String map(String, String, String, Collection<T>) = native String bossa.util.Util.map(String, String, String, Collection); Stack<bossa.link.Alternative> sortedAlternatives(MethodDeclaration) = native Stack bossa.link.Alternative.sortedAlternatives(MethodDeclaration); List<VarSymbol> getConstructorCallSymbols(NiceClass) = native List NiceClass.getConstructorCallSymbols(); *************** *** 211,215 **** // Retypings needed since java types are not strict. - Block newBlock(?Statement[] statements) = native new Block(Statement[]); mlsub.typing.Polytype boolPolytype() = native PrimitiveType.boolPolytype; mlsub.typing.Polytype longPolytype() = native PrimitiveType.longPolytype; --- 209,212 ---- --- NEW FILE: locals.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 bossa.syntax; import bossa.util.*; abstract class LocalDeclaration extends Statement { ?Expression value; String getName(); VarSymbol getSymbol(); gnu.bytecode.Type getBytecodeType(); gnu.expr.Expression initValue() { return notNull(value).generateCode(); } location() = notNull(this.getSymbol().name.location()); gnu.expr.Expression compile(gnu.expr.LetExp letExp) { gnu.expr.Declaration decl = letExp.addDeclaration(this.getName(), this.getBytecodeType()); decl.noteValue(null); if (! this.getSymbol().isAssignable()) decl.setFlag(gnu.expr.Declaration.IS_CONSTANT); if (value == null) decl.setFlag(gnu.expr.Declaration.NOT_INITIALIZED); this.getSymbol().setDeclaration(decl); return this.initValue(); } generateCode() { Internal.error("Should not be called"); return cast(null); } public String display() { if (value == null) return this.getSymbol().toString(); else return this.getSymbol().toString() + '=' + value; } } public abstract class LocalValue extends LocalDeclaration { ?LocalValue next = null; LocalValue last = cast(null); { last = this; } /* Local variables are chained to handle multiple var declarations like "int x = 3, y = x, z = y;" We have to be careful about the order, so that dependencies like above work as expected. */ public void addNext(LocatedString name, ?Expression value); toString() { let res = new StringBuffer(); ?LocalValue v = this; while (true) { res.append(notNull(v).display()); v = notNull(v).next; if (v == null) break; else res.append(','); } return res.toString(); } } public class LocalVariable extends LocalValue { LocalVariableSymbol left; getName() = left.name.toString(); getSymbol() = left; getBytecodeType() = nice.tools.code.Types.javaType(left.type); initValue() { if (value == null) return notNull(gnu.expr.QuoteExp.undefined_exp); else return notNull(value).generateCode(); } int getIndex() { return left.index; } void setIndex(int i) { left.index = i; } addNext(name, value) { if (left.syntacticType == null && value == null) User.error(name,"A local variable requires a type or a default value"); last.next = new LocalVariable(name, left.syntacticType, ! left.isAssignable(), value); last = notNull(last.next); } display() { if (left.constant) return "let "+ super; else return "var " + super; } } class LocalVariableSymbol extends MonoSymbol { /* Index to make the initialization analysis or -1 if this variable is always initialized. */ int index = -1; boolean constant; isAssignable() { /* For a constant symbol with no initial value, index != -1. We allow assignments, but check with dataflow in analyse.nice that assignment occurs only in the uninitialized state. */ return ! constant || index != -1; } } public new LocalVariable(LocatedString name, ?Monotype type, boolean constant, ?Expression value) { this(value: value, left:new LocalVariableSymbol(name, type, constant: constant)); } public class LocalConstant extends LocalValue { MonoSymbol left; getName() = left.name.toString(); getSymbol() = left; getBytecodeType() = nice.tools.code.Types.javaType(left.type); addNext(name, value) { if (value == null) User.error(name,"A local constant requires a type or a default value"); last.next = new LocalConstant(name, notNull(value)); last = notNull(last.next); } toString() = "let " + super; } class LocalConstantSymbol extends MonoSymbol { isAssignable() = false; } public new LocalConstant(LocatedString name, Expression value) { ?Monotype t = null; this(value: value, left: new LocalConstantSymbol(name,t)); } public class LocalFunction extends LocalDeclaration { FunSymbol left; FormalParameters parameters; getName() = left.name.toString(); getSymbol() = left; getBytecodeType() = nice.tools.code.Types.javaType(left.type); mlsub.typing.Polytype inferredReturnType() { return notNull(value).inferredReturnType(); } mlsub.typing.Monotype declaredReturnType() { return nice.tools.typing.Types.result(left.getType()); } } public Statement createLocalFunction(LocatedString name, Monotype returnType, FormalParameters parameters, Statement body) { let value = createFunExp(Constraint.True, parameters.getMonoSymbols(), body); let symbol = new FunSymbol(name, Constraint.True, parameters, returnType); notNull(notNull(symbol.syntacticType).getMonotype()).nullness = Monotype.sure; return new LocalFunction(left: symbol, value: value, parameters: parameters); } public Statement createLocalVariable(LocatedString name, ?Monotype type, boolean constant, ?Expression value) { if (type == null && value == null) User.error(name,"A local variable requires a type or a default value"); if (constant && type == null) return new LocalConstant(name, value: notNull(value)); return new LocalVariable(name, type, constant: constant, value: value); } public void addNextLocal(Statement localValue, LocatedString name, ?Expression value) { LocalValue lv = cast(localValue); lv.addNext(name, value); } public class ExpLocalVariable extends Expression { LocalVariable variable; Expression initValue; computeType() { this.type = variable.left.getType(); } compile() = this.compileAssign(initValue.generateCode()); getDeclaration() = variable.getSymbol().getDeclaration(); } public Expression createExpLocalVariable(LocatedString name, Expression value, boolean constant, ?Monotype type) { let res = new ExpLocalVariable(variable: new LocalVariable(name, type, constant, null), initValue: value); res.setLocation(name.location()); return res; } --- NEW FILE: block.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 bossa.syntax; import bossa.util.*; /** A block : a list of statements with local variables. */ public class Block extends Statement { ArrayList<LocalDeclaration> locals = new ArrayList(); Statement[] statements; boolean isBreakTarget = false; public Statement last() { return statements[statements.length - 1]; } /** Divides the statements in an hierarchy of blocks. Each block has a list of local variables accessible in the block, and a list of statements (possibly sub-blocks). @param statements the list of statements, with LocalDeclarations @return the list of statements of the current block. */ private Statement[] cutInBlocks(List<Statement> statements) { ArrayList<Statement> res = new ArrayList(); let i = statements.listIterator(); // Finds locals at the beginning while(i.hasNext()) { let s = i.next(); if (s instanceof LocalValue) { ?LocalValue decl = s; do { locals.add(notNull(decl)); decl = notNull(decl).next; } while (decl != null); } else if (s instanceof LocalDeclaration) locals.add(s); else { res.add(s); break; } } // There will be no more locals, let's save space :-) locals.trimToSize(); // Finds statements. Creates a new Block if a local declaration is found while(i.hasNext()) { let s = i.next(); if (s instanceof LocalDeclaration) { // Create a subblock with all the statements starting from this one let end = createBlock(statements.subList(i.previousIndex(), statements.size())); end.setLocation(s.location()); res.add(end); break; } res.add(s); } return new Statement[res.size()].fillWith(res); } /**************************************************************** * Code generation ****************************************************************/ generateCode() { if (statements.length != 0) { let body = new gnu.expr.BeginExp(); // addLocals must appear before Statement.compile(statements) // in order to define the locals before their use. // That is why we can't set body's body at construction. let res = this.addLocals(locals.iterator(), body); body.setExpressions(Statement.compile(statements)); return res; } return this.addLocals(locals.iterator(), notNull(gnu.expr.QuoteExp.voidExp)); } private gnu.expr.Expression addLocals(Iterator<LocalDeclaration> vars, gnu.expr.Expression body) { if (!vars.hasNext()) return body; let local = vars.next(); gnu.expr.Expression[] eVal = cast(new gnu.expr.Expression[1]); gnu.expr.LetExp res = new gnu.expr.LetExp(eVal); eVal[0] = local.compile(res); res.setBody(this.addLocals(vars,body)); local.location().write(res); return res; } /**************************************************************** * Printing ****************************************************************/ toString() { return "{\n" + Util.map("",";\n",";\n",locals) + Util.map("","\n","\n",statements) + "}\n"; } } public Statement createBlock(List<Statement> statements) { let res = new Block(statements: cast(null)); let stmts = res.cutInBlocks(statements); res.statements = stmts; if (stmts != null && stmts.length > 0 && stmts[0] != null) res.setLocation(stmts[0].location()); return res; } Index: rewrite.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/rewrite.nice,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** rewrite.nice 29 Jul 2004 12:11:40 -0000 1.5 --- rewrite.nice 8 Aug 2004 21:51:54 -0000 1.6 *************** *** 40,44 **** } ! ?Statement[] rewrite(?Statement[] statements) { for (int i = 0; i < statements.length - 1; i++) --- 40,44 ---- } ! Statement[] rewrite(Statement[] statements) { for (int i = 0; i < statements.length - 1; i++) *************** *** 79,88 **** makeStatement(StatementExp e) = e.statement; ! Block makeBlock(Expression first, ?Statement[] rest) { ?Statement[] res = new Statement[rest.length + 1]; res[0] = makeStatement(first); copy(rest, 0, res, 1, rest.length); ! return new Block(res); } --- 79,88 ---- makeStatement(StatementExp e) = e.statement; ! Block makeBlock(Expression first, Statement[] rest) { ?Statement[] res = new Statement[rest.length + 1]; res[0] = makeStatement(first); copy(rest, 0, res, 1, rest.length); ! return new Block(statements: cast(res)); } Index: call.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/call.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** call.nice 5 Aug 2004 10:45:30 -0000 1.1 --- call.nice 8 Aug 2004 21:51:54 -0000 1.2 *************** *** 31,35 **** ?gnu.bytecode.ClassType declaringClass = null; ! ExpLocalVariable[?] localVars = null; /** The type of the function, constrained by the actual arguments. */ --- 31,35 ---- ?gnu.bytecode.ClassType declaringClass = null; ! ?List<ExpLocalVariable> localVars = null; /** The type of the function, constrained by the actual arguments. */ *************** *** 135,144 **** if (localVars != null) { ! for(int i = notNull(localVars).length-1; i >= 0; i--) { gnu.expr.Expression[] eVal = cast(new gnu.expr.Expression[1]); gnu.expr.LetExp letExp = new gnu.expr.LetExp(eVal); ! eVal[0] = notNull(notNull(localVars)[i].variable).compile(letExp); ! if (i == notNull(localVars).length-1) { firstLetExp = letExp; --- 135,144 ---- if (localVars != null) { ! for(int i = notNull(localVars).size()-1; i >= 0; i--) { gnu.expr.Expression[] eVal = cast(new gnu.expr.Expression[1]); gnu.expr.LetExp letExp = new gnu.expr.LetExp(eVal); ! eVal[0] = notNull(localVars)[i].variable.compile(letExp); ! if (i == notNull(localVars).size()-1) { firstLetExp = letExp; Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** dispatch.java.bootstrap 7 Aug 2004 14:20:29 -0000 1.19 --- dispatch.java.bootstrap 8 Aug 2004 21:51:54 -0000 1.20 *************** *** 89,92 **** --- 89,106 ---- { return false; } + public static Expression createExpLocalVariable(LocatedString name, Expression value, boolean constant, Monotype type) + { return null; } + + public static Statement createLocalVariable(LocatedString name, Monotype type, boolean constant, Expression value) + { return null; } + + public void addNextLocal(Statement localValue, LocatedString name, Expression value) {} + + public static Statement createLocalFunction(LocatedString name, Monotype returnType, FormalParameters parameters, Statement body) + { return null; } + + public static Statement createBlock(List statements) + { return null; } + static Statement analyse(Statement s, VarScope v, TypeScope t, boolean r) { return null; } Index: Arguments.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Arguments.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Arguments.java 2 Feb 2004 23:21:44 -0000 1.24 --- Arguments.java 8 Aug 2004 21:51:54 -0000 1.25 *************** *** 161,178 **** } - ExpLocalVariable[] extractLocalVars() - { - List res = new ArrayList(); - - for (int i = arguments.length; --i>=0; ) - if (arguments[i].value instanceof ExpLocalVariable) - res.add(arguments[i].value); - - if (res.isEmpty()) - return null; - - return (ExpLocalVariable[])res.toArray(new ExpLocalVariable[res.size()]); - } - java.util.Map applicationExpressions = new java.util.HashMap(); --- 161,164 ---- |
From: Arjan B. <ar...@us...> - 2004-08-08 21:52:17
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29035/F:/nice/src/bossa/parser Modified Files: Parser.jj Log Message: Converted block and local variables to nice code. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.254 retrieving revision 1.255 diff -C2 -d -r1.254 -r1.255 *** Parser.jj 7 Aug 2004 14:20:28 -0000 1.254 --- Parser.jj 8 Aug 2004 21:51:54 -0000 1.255 *************** *** 835,839 **** type=monotype() id=ident() { monotypes.add(type); ! statements.add(new Block.LocalVariable(id, type, false, null)); return new IdentExp(id); } | { Token first,last; } --- 835,839 ---- type=monotype() id=ident() { monotypes.add(type); ! statements.add(bossa.syntax.dispatch.createLocalVariable(id, type, false, null)); return new IdentExp(id); } | { Token first,last; } *************** *** 931,935 **** { return NiceMethod.create(c, name, cst, returnType, parameters, ! body != null ? new Block(statements) : null, contract, isOverride); } } --- 931,935 ---- { return NiceMethod.create(c, name, cst, returnType, parameters, ! body != null ? bossa.syntax.dispatch.createBlock(statements) : null, contract, isOverride); } } *************** *** 1122,1126 **** ) { ! return CustomConstructor.make(name, cst, params, new Block(statements)); } } --- 1122,1126 ---- ) { ! return CustomConstructor.make(name, cst, params, bossa.syntax.dispatch.createBlock(statements)); } } *************** *** 1363,1367 **** { List statements = new LinkedList(); statements.add(res); ! return new Block(statements); } ) ) --- 1363,1367 ---- { List statements = new LinkedList(); statements.add(res); ! return bossa.syntax.dispatch.createBlock(statements); } ) ) *************** *** 1426,1430 **** { res = NiceMethod.WithDefault.create (name, cst, returnType, parameters, ! body != null ? new Block(statements) : null, contract, isOverride); } --- 1426,1430 ---- { res = NiceMethod.WithDefault.create (name, cst, returnType, parameters, ! body != null ? bossa.syntax.dispatch.createBlock(statements) : null, contract, isOverride); } *************** *** 1799,1803 **** ) { statements.add(body); ! return bossa.syntax.dispatch.createFunExp(cst, formals, new Block(statements)); } } --- 1799,1803 ---- ) { statements.add(body); ! return bossa.syntax.dispatch.createFunExp(cst, formals, bossa.syntax.dispatch.createBlock(statements)); } } *************** *** 2307,2311 **** } ! ExpLocalVariable ExpLocalVariable(): { boolean constant = false; --- 2307,2311 ---- } ! Expression ExpLocalVariable(): { boolean constant = false; *************** *** 2320,2324 **** "=" value=Expression() ! { return new ExpLocalVariable(name, value, constant, type); } } --- 2320,2324 ---- "=" value=Expression() ! { return bossa.syntax.dispatch.createExpLocalVariable(name, value, constant, type); } } *************** *** 2407,2411 **** } ! Block Block() : { Token first, last; Statement s; List statements; } { --- 2407,2411 ---- } ! Statement Block() : { Token first, last; Statement s; List statements; } { *************** *** 2417,2421 **** { last = getToken(0); ! Block res = new Block(statements); res.setLocation(makeLocation(first, last)); return res; --- 2417,2421 ---- { last = getToken(0); ! Statement res = bossa.syntax.dispatch.createBlock(statements); res.setLocation(makeLocation(first, last)); return res; *************** *** 2453,2457 **** boolean constant = false; Token t = null; ! Block.LocalValue res; } { --- 2453,2457 ---- boolean constant = false; Token t = null; ! Statement res; } { *************** *** 2464,2470 **** id=ident() [ "=" e=Expression() ] ! { res = Block.createLocalVariable(id,type,constant,e); } ( LOOKAHEAD( "," <IDENT> ( "=" | ";" | ",") ) ! "," id=ident() {e=null;} [ "=" e=Expression() ] { res.addNext(id,e); } )* { return res; } --- 2464,2470 ---- id=ident() [ "=" e=Expression() ] ! { res = bossa.syntax.dispatch.createLocalVariable(id,type,constant,e); } ( LOOKAHEAD( "," <IDENT> ( "=" | ";" | ",") ) ! "," id=ident() {e=null;} [ "=" e=Expression() ] { bossa.syntax.dispatch.addNextLocal(res,id,e); } )* { return res; } *************** *** 2487,2491 **** "(" parameters=formalParameters(false, statements) ")" body=code() { statements.add(body); } ! { return Block.LocalFunction.make(id, type, parameters, body!=null?new Block(statements):null); } } --- 2487,2491 ---- "(" parameters=formalParameters(false, statements) ")" body=code() { statements.add(body); } ! { return bossa.syntax.dispatch.createLocalFunction(id, type, parameters, body!=null?bossa.syntax.dispatch.createBlock(statements):null); } } *************** *** 2514,2518 **** | //then look for a monotype without matching a tuplePart LOOKAHEAD( monotype() ident() ) type=monotype() id=ident() ! { statements.add(new Block.LocalVariable(id, type, false, null)); return new IdentExp(id); } | //otherwise it's localtuple part --- 2514,2518 ---- | //then look for a monotype without matching a tuplePart LOOKAHEAD( monotype() ident() ) type=monotype() id=ident() ! { statements.add(bossa.syntax.dispatch.createLocalVariable(id, type, false, null)); return new IdentExp(id); } | //otherwise it's localtuple part *************** *** 2716,2720 **** Statement ForStatement() : ! { Block update = null; Statement loop = null, body, statexp; Expression cond = null; --- 2716,2720 ---- Statement ForStatement() : ! { Statement update = null; Statement loop = null, body, statexp; Expression cond = null; *************** *** 2740,2744 **** l.addAll(init); l.add(loop); ! loop = new Block(l); } ) --- 2740,2744 ---- l.addAll(init); l.add(loop); ! loop = bossa.syntax.dispatch.createBlock(l); } ) *************** *** 2768,2772 **** } ! Block StatementExpressionList() : { Statement s; List statements=new LinkedList(); } { --- 2768,2772 ---- } ! Statement StatementExpressionList() : { Statement s; List statements=new LinkedList(); } { *************** *** 2774,2778 **** ( "," s=ShortStatementExpression() { statements.add(s); } )* ! { return new Block(statements); } } --- 2774,2778 ---- ( "," s=ShortStatementExpression() { statements.add(s); } )* ! { return bossa.syntax.dispatch.createBlock(statements); } } |
From: Daniel B. <bo...@us...> - 2004-08-08 10:45:44
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24195/stdlib/nice/lang Modified Files: native.nice Log Message: Added nicedoc comments. Index: native.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/native.nice,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** native.nice 31 Jul 2004 10:05:56 -0000 1.9 --- native.nice 8 Aug 2004 10:45:36 -0000 1.10 *************** *** 2,6 **** * N I C E * * A high-level object-oriented research language * ! * (c) Daniel Bonniot 2003 * * * * This package is free software; you can redistribute it and/or modify * --- 2,6 ---- * N I C E * * A high-level object-oriented research language * ! * (c) Daniel Bonniot 2004 * * * * This package is free software; you can redistribute it and/or modify * *************** *** 25,30 **** --- 25,42 ---- */ + /** + Throw the given throwable object. This stops the normal flow of execution, + and transfers to the closest englobing <code>catch</code> block that matches + the thrown object, executing englobing <code>finally</code> blocks along the + way. + */ void `throw`(java.lang.Throwable exception) = inline nice.lang.inline.Throw(); + /** + Tests whether a value is an instance of a given class. + + @return true if value is not null, and its class is either the given class + or one of its subclasses. + */ <T,U> boolean `instanceof`(T value, Class<U>) = inline nice.lang.inline.Instanceof(); |
From: Francis B. <fb...@us...> - 2004-08-08 10:17:05
|
Update of /cvsroot/nice/Nice/src/nice/tools/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20458/src/nice/tools/doc Modified Files: htmlwriter.nice Log Message: Filenames should now be compatible with all operating systems. Index: htmlwriter.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/doc/htmlwriter.nice,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** htmlwriter.nice 4 Aug 2004 14:54:21 -0000 1.13 --- htmlwriter.nice 8 Aug 2004 10:16:56 -0000 1.14 *************** *** 33,38 **** */ class HTMLWriter { ! //mainPackage = mainPackage.deleteAtEnd("/").replace('/', "."); ! /** * Default implementation - does nothing --- 33,37 ---- */ class HTMLWriter { ! /** * Default implementation - does nothing *************** *** 59,62 **** --- 58,63 ---- //this should also work when "." is not found fileName = fileName.substring(fileName.lastIndexOf(".") + 1); + //escape any characters that might be illegal for the filesystem + fileName = escapeFilename(fileName); BufferedWriter writer = new BufferedWriter (new FileWriter(new File(dir, fileName + ".html"))); *************** *** 139,143 **** BufferedWriter writer = new BufferedWriter ! (new FileWriter(new File(dir, "gv_" gv.getName() ".html"))); writer.write(getHeader(gv.getName().toString())); --- 140,144 ---- BufferedWriter writer = new BufferedWriter ! (new FileWriter(new File(dir, "gv_" escapeFilename("" gv.getName()) ".html"))); writer.write(getHeader(gv.getName().toString())); *************** *** 170,174 **** BufferedWriter writer = new BufferedWriter ! (new FileWriter(new File(dir, calculateMethodFilename(m)))); writer.write(getHeader(m.getName().toString())); --- 171,175 ---- BufferedWriter writer = new BufferedWriter ! (new FileWriter(new File(dir, escapeFilename(getMethodFilename(m)) + ".html"))); writer.write(getHeader(m.getName().toString())); *************** *** 237,241 **** if(index != s.length()-1) s = s.substring(index+1); ! writer.write("<li><a href='" + s + ".html'>" + s + "</a></li>\n"); } writer.write("</ul>\n"); --- 238,242 ---- if(index != s.length()-1) s = s.substring(index+1); ! writer.write("<li><a href='" + escapeFilename(s) + ".html'>" + s + "</a></li>\n"); } writer.write("</ul>\n"); *************** *** 247,251 **** writer.write("<ul>\n"); for(MethodDeclaration m : methods) { ! writer.write("<li><a href='" calculateMethodFilename(m) "'>" m.getName() "</a>" + ": " m.getType() "</li>\n"); } --- 248,252 ---- writer.write("<ul>\n"); for(MethodDeclaration m : methods) { ! writer.write("<li><a href='" escapeFilename(getMethodFilename(m)) ".html'>" m.getName() "</a>" + ": " m.getType() "</li>\n"); } *************** *** 258,262 **** writer.write("<ul>\n"); for(GlobalVarDeclaration gv : globalVars) { ! writer.write("<li><a href='gv_" gv.getName() ".html'>" gv.getName() "</a></li>\n"); } writer.write("</ul>\n"); --- 259,263 ---- writer.write("<ul>\n"); for(GlobalVarDeclaration gv : globalVars) { ! writer.write("<li><a href='gv_" escapeFilename("" gv.getName()) ".html'>" gv.getName() "</a></li>\n"); } writer.write("</ul>\n"); *************** *** 382,388 **** * This method returns a file name based upon the method name and its arguments. */ ! String calculateMethodFilename(MethodDeclaration md) { ! String filename = md.getName().toString() + md.getType().toString().hashCode(); ! filename = filename.replace('/', "@slash").replace('.', "@dot"); ! return filename + ".html"; } \ No newline at end of file --- 383,412 ---- * This method returns a file name based upon the method name and its arguments. */ ! String getMethodFilename(MethodDeclaration md) { ! return md.getName().toString() + md.getType().toString().hashCode(); ! } ! ! /** ! * Checks a filename to make sure it doesn't contain funny characters. ! */ ! String escapeFilename(String filename) { ! char[] chars = filename.toCharArray(); ! StringBuffer buf = new StringBuffer(); ! for(char c : chars) { ! if(!Character.isLetterOrDigit(c)) { ! buf.append('$'); ! buf.append(hexEncode(int(c))); ! } ! else { ! buf.append(c); ! } ! } ! return buf.toString(); ! } ! ! String hexEncode(int i) { ! String num = Integer.toHexString(i); ! for(int pad = num.length(); pad < 4; pad++) ! num = "0" + num; ! return num.toUpperCase(); } \ No newline at end of file |
From: Arjan B. <ar...@us...> - 2004-08-07 16:48:23
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18299/F:/nice/src/bossa/syntax Modified Files: typecheck.nice Log Message: Reapplied fix for overloaded array dimensions. Index: typecheck.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v retrieving revision 1.110 retrieving revision 1.111 diff -C2 -d -r1.110 -r1.111 *** typecheck.nice 7 Aug 2004 14:20:29 -0000 1.110 --- typecheck.nice 7 Aug 2004 16:48:13 -0000 1.111 *************** *** 630,642 **** { Expression[] knownDimensions = notNull(e.knownDimensions); ! typecheckExps(cast(knownDimensions)); for (int i=0; i<knownDimensions.length; i++) { ! Expression dim = knownDimensions[i]; try{ ! Typing.leq(dim.getType(), PrimitiveType.intPolytype); } catch(TypingEx ex){ ! if (notNullError(ex, dim, dim.toString())) bossa.util.User.error(dim, "" + dim + " should be an integer"); --- 630,643 ---- { Expression[] knownDimensions = notNull(e.knownDimensions); ! for (int i=0; i<knownDimensions.length; i++) { ! Expression dim = knownDimensions[i] = ! knownDimensions[i].resolveOverloading(PrimitiveType.intPolytype); try{ ! checkAssignment(PrimitiveType.intType, dim); } catch(TypingEx ex){ ! if (notNullError(ex, dim, dim.toString())) bossa.util.User.error(dim, "" + dim + " should be an integer"); |
From: Daniel B. <bo...@us...> - 2004-08-07 14:57:42
|
Update of /cvsroot/nice/Nice/src/bossa/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv758/src/bossa/modules Modified Files: Package.java Locator.java Compilation.nice Log Message: Implementation of remote package repositories. Index: Locator.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Locator.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Locator.java 2 Jul 2004 19:31:03 -0000 1.4 --- Locator.java 7 Aug 2004 14:57:33 -0000 1.5 *************** *** 15,21 **** import java.io.*; import java.util.LinkedList; ! import java.util.jar.JarFile; import bossa.util.Debug; import bossa.util.User; /** --- 15,22 ---- import java.io.*; import java.util.LinkedList; ! import java.net.URL; import bossa.util.Debug; import bossa.util.User; + import nice.tools.repository.VersionTracker; /** *************** *** 28,52 **** final class Locator { ! Locator (Compilation compilation, String classpath) { ! sources = new nice.tools.locator.Locator ! (compilation.sourcePath, ! new gnu.mapping.Procedure1() { ! public Object apply1(Object o) { ! String message = (String) o; ! User.warning(message); ! return null; ! } ! }); ! packages = new nice.tools.locator.Locator ! (classpath, ! new gnu.mapping.Procedure1() { ! public Object apply1(Object o) { ! String message = (String) o; ! User.warning(message); ! return null; ! } ! }); } --- 29,48 ---- final class Locator { ! Locator (Compilation compilation, String classpath, URL repository) { ! gnu.mapping.Procedure1 warning = new gnu.mapping.Procedure1() { ! public Object apply1(Object o) { ! String message = (String) o; ! User.warning(message); ! return null; ! } ! }; ! sources = new nice.tools.locator.Locator(compilation.sourcePath, warning); ! packages = new nice.tools.locator.Locator(classpath, warning); ! ! vt = nice.tools.repository.dispatch.versionTracker ! (new File("nice.versions").getAbsoluteFile()); ! remote = new nice.tools.locator.Locator(vt.repository(repository)); } *************** *** 64,67 **** --- 60,67 ---- source = DirectorySourceContent.create(pkg, sroot.getURL()); + // If the package couldn't be found locally, try remotely. + if (source == null && croot == null) + croot = remote.get(name + "/package.nicei"); + if (croot != null) compiled = CompiledContent.create(pkg, croot.getURL()); *************** *** 75,78 **** --- 75,83 ---- } + void save() + { + vt.save(); + } + /**************************************************************** * Private *************** *** 84,86 **** --- 89,96 ---- /** where to find compiled packages. */ private final nice.tools.locator.Locator packages; + + /** remote location where to find imported packages. */ + private final nice.tools.locator.Locator remote; + + private VersionTracker vt; } Index: Compilation.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Compilation.nice,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** Compilation.nice 30 Jun 2004 14:12:38 -0000 1.28 --- Compilation.nice 7 Aug 2004 14:57:33 -0000 1.29 *************** *** 14,17 **** --- 14,19 ---- import mlsub.compilation; + import nice.tools.locator; + import nice.tools.repository; /** *************** *** 49,53 **** ?String runtimeFile = null; ! ?Locator locator = null; CompilationListener listener; --- 51,55 ---- ?String runtimeFile = null; ! ?bossa.modules.Locator locator = null; CompilationListener listener; *************** *** 80,85 **** Package.startNewCompilation(); // Create the locator that uses these two pathes to locate packages. ! this.locator = new Locator(this, classpath); // forces reading nice.lang first --- 82,89 ---- Package.startNewCompilation(); + let repository = System.getProperty + ("nice.repository", "http://packages.sourceforge.net/repository/"); // Create the locator that uses these two pathes to locate packages. ! this.locator = new bossa.modules.Locator(this, classpath, new java.net.URL(repository)); // forces reading nice.lang first Index: Package.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Package.java,v retrieving revision 1.118 retrieving revision 1.119 diff -C2 -d -r1.118 -r1.119 *** Package.java 30 Jul 2004 19:08:46 -0000 1.118 --- Package.java 7 Aug 2004 14:57:33 -0000 1.119 *************** *** 348,351 **** --- 348,353 ---- // This is useful to bundle the application after it was compiled. writeArchive(); + + compilation.locator.save(); } |
From: Daniel B. <bo...@us...> - 2004-08-07 14:57:42
|
Update of /cvsroot/nice/Nice In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv758 Modified Files: Makefile Log Message: Implementation of remote package repositories. Index: Makefile =================================================================== RCS file: /cvsroot/nice/Nice/Makefile,v retrieving revision 1.151 retrieving revision 1.152 diff -C2 -d -r1.151 -r1.152 *** Makefile 31 Jul 2004 07:53:10 -0000 1.151 --- Makefile 7 Aug 2004 14:57:33 -0000 1.152 *************** *** 49,53 **** world: fixpoint check test ! tools: nicedoc unit ant # The bootstrap at the end of the universe ;-) --- 49,53 ---- world: fixpoint check test ! tools: nicedoc unit ant publish # The bootstrap at the end of the universe ;-) *************** *** 65,69 **** compiler2 compiler3: setDate - ${NICEC1} -r nice.tools.locator ${NICEC1} -R bossa.syntax ${NICEC1} -R -a src/nice/tools/compiler/console.jar nice.tools.compiler.console --- 65,68 ---- *************** *** 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 \ --- 160,164 ---- -cd src/bossa/syntax && mv -f dispatch.java.bootstrap dispatch.java ${JAVAC} src/nice/tools/util/System.java ! ${NICEC} -R nice.tools.repository ${JAVAC} \ src/bossa/syntax/dispatch.java \ *************** *** 205,208 **** --- 204,210 ---- $(NICEC1) nice.tools.unit.console + publish: + $(NICEC1) -a nicepublish.jar nice.tools.repository.publish + libs: @echo "Building libraries..." |
From: Daniel B. <bo...@us...> - 2004-08-07 14:57:42
|
Update of /cvsroot/nice/Nice/src/nice/tools/locator In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv758/src/nice/tools/locator Modified Files: main.nice locator.nice Log Message: Implementation of remote package repositories. Index: main.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/locator/main.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** main.nice 2 Jul 2004 19:31:02 -0000 1.1 --- main.nice 7 Aug 2004 14:57:33 -0000 1.2 *************** *** 32,33 **** --- 32,35 ---- new Locator(String path, String->void warning) = this(path: parsePath(path, warning)); + + new Locator(URL url) = this(path: [url]); Index: locator.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/locator/locator.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** locator.nice 2 Jul 2004 19:31:02 -0000 1.1 --- locator.nice 7 Aug 2004 14:57:33 -0000 1.2 *************** *** 25,30 **** let url = new URL(base, resource); let connection = url.openConnection(); ! connection.connect(); ! return connection; } catch(java.io.IOException e) {} --- 25,33 ---- let url = new URL(base, resource); let connection = url.openConnection(); ! if (connection != null) ! { ! connection.connect(); ! return connection; ! } } catch(java.io.IOException e) {} |
From: Daniel B. <bo...@us...> - 2004-08-07 14:57:41
|
Update of /cvsroot/nice/Nice/src/nice/tools/repository In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv758/src/nice/tools/repository Added Files: tests.nice main.nice Log Message: Implementation of remote package repositories. --- NEW FILE: main.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.tools.repository; /** Load versioned resources from a repository. @author Daniel Bonniot (bo...@us...) */ import java.net.*; public URL repository(VersionTracker vt, URL base) = new URL(base, "!/", vt); public class IncompatibleVersions extends RuntimeException { String ver1; String ver2; } VersionTracker versionTracker(File store) = new VersionTracker(store: store); public class VersionTracker extends URLStreamHandler { ?File store = null; { ?File store = this.store; if (store != null && store.exists) this.load(store); } private void load(File store) { new FileInputStream(store).lines(String line => { int sep = line.indexOf(':'); String pkg = line.substring(0, sep); String ver = line.substring(sep + 1); this.versions[pkg] = ver; }); } public void save() { if (store != null && versions.size() > 0) this.save(notNull(store)); } private void save(File store) { let out = new PrintWriter(new FileWriter(store)); versions.foreach((String pkg, String ver) => out.println(pkg+':'+ver)); out.close(); } private Map<String,String> versions = new HashMap(); openConnection(URL url) { (URL repo, String resource, ?String ver) = parseRepoURL(url); let pkg = getPackage(resource); ?String currentVer = versions[pkg]; if (ver == null) { ver = currentVer || latestVersion(repo, pkg); if (ver == null) return null; } else if (currentVer != null && ! ver.equals(currentVer)) throw new IncompatibleVersions(ver1: currentVer, ver2: ver); versions[pkg] = notNull(ver); let jar = localCopy(repo, packagePath(pkg)+getPackage(resource)+"-"ver".jar"); let res = new URL("jar", "", jar+"!/"resource); return res.openConnection(); } } (URL,String,?String) parseRepoURL(URL url) { String s = url.toString(); int sep = s.indexOf('!'); URL repo = new URL(s.substring(0, sep)); int pver = s.indexOf('#', sep); String resource; ?String ver; if (pver == -1) { resource = s.substring(sep + 2); ver = null; } else { resource =s.substring(sep + 2, pver); ver= s.substring(pver + 1); } return (repo,resource,ver); } public String getPackage(String resource) = resource.substring(0, resource.lastIndexOf('/')).replace('/', '.'); public String packagePath(String pkg) = pkg.replace('.', '/') + '/'; ?String latestVersion(URL repo, String pkg) { if (remote(repo)) return latestVersionRemote(repo, pkg); else return latestVersionLocal(repo, pkg); } /** Find the latest version of a give package, but searching for a 'latest' file in the repository. */ private ?String latestVersionRemote(URL repo, String pkg) { ?String latest = null; let url = new URL(repo, packagePath(pkg) + "/latest"); try { url.openStream().lines(String ver => { latest = ver; }); } catch(IOException e) {} return latest; } /** Find the latest version of a give package, by listing all versions. */ private ?String latestVersionLocal(URL repo, String pkg) { ?String latest = null; let url = new URL(repo, packagePath(pkg)); try { url.openStream().lines(String ver => { if (ver.startsWith(pkg)) latest = ver; }); } catch(IOException e) {} let res = latest; if (res == null) return null; else return res.substring(res.lastIndexOf('-') + 1, res.lastIndexOf('.')); } URL localCopy(URL repo, String jar) { if (! remote(repo)) return new URL(repo, jar); return download(repo, jar).toURL(); } boolean remote(URL url) { String protocol = url.getProtocol(); if (protocol.equals("file")) return false; return true; } let File cache = new File(System.getProperty("user.home"), ".nice-repository"); File download(URL repo, String jar) { URL url = new URL(repo, jar); let cached = new File(cache, jar); if (! cached.exists) // Really download it { println("Downloading "url); notNull(cached.getParentFile()).mkdirs(); copy(url.openStream(), cached); } return cached; } // Utilities ?URLConnection openConnection(URLStreamHandler,URL) = native URLConnection URLStreamHandler.openConnection(URL); void lines(InputStream i, String->void action) = lines(new BufferedReader(new InputStreamReader(i)), action); void lines(BufferedReader in, String->void action) { ?String line; for (; (line = in.readLine()) != null;) action(line); } String readAll(InputStream in) { let res = new StringBuffer(in.available()); let reader = new InputStreamReader(in); char[] buf = new char[100]; int len; while ((len = reader.read(buf)) > 0) res.append(buf, 0, len); return res.toString(); } void copy(InputStream in, File dest) { using (let out = new FileOutputStream(dest)) { let buf = new byte[4196]; int read; while ((read = in.read(buf)) != -1) out.write(buf, 0, read); } } --- NEW FILE: tests.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.tools.repository; /** @author Daniel Bonniot (bo...@us...) */ import nice.tools.locator; import java.io.*; import java.util.jar.*; Locator _setupSingle() { File tmp = makeTempDir(); tmp.addJar("foo.bar", "1", [ "foo/bar/a.txt", "a" ]); let vt = new VersionTracker(); let path = [vt.repository(tmp.toURL())]; return new Locator(path: path); } void _testSingle() { assert _setupSingle().get("foo/bar/a.txt").is("a"); assert _setupSingle().get("foo/bar/a.txt#1").is("a"); assert _setupSingle().get("foo/bar/a.txt#42") == null; } Locator _setupMultiple(?VersionTracker vt = null) { File tmp = makeTempDir(); tmp.addJar("foo.bar", "1", [ "foo/bar/a.txt", "a1" ]); tmp.addJar("foo.bar", "2", [ "foo/bar/a.txt", "a2", "foo/bar/b.txt", "b2"]); let v = vt || new VersionTracker(); let path = [v.repository(tmp.toURL())]; return new Locator(path: path); } void _testMultipleLatest2() { // Like Latest, but create the jars in reverse order File tmp = makeTempDir(); tmp.addJar("foo.bar", "2", [ "foo/bar/a.txt", "a2", "foo/bar/b.txt", "b2"]); tmp.addJar("foo.bar", "1", [ "foo/bar/a.txt", "a1" ]); let locator = new Locator(path: [new VersionTracker().repository(tmp.toURL())]); assert locator.get("foo/bar/a.txt").is("a2"); } void _testMultipleLatest() = assert _setupMultiple().get("foo/bar/a.txt").is("a2"); void _testMultipleOld() = assert _setupMultiple().get("foo/bar/a.txt#1").is("a1"); void _testMultipleNew() = assert _setupMultiple().get("foo/bar/a.txt#2").is("a2"); void _testMultipleUnknown() = assert _setupMultiple().get("foo/bar/a.txt#42") == null; void _testMultipleConflict() { let locator = _setupMultiple(); assert locator.get("foo/bar/a.txt").is("a2"); try { locator.get("foo/bar/a.txt#1"); assert false : "Incompatible versions expected"; } catch(IncompatibleVersions e) {} } void _testMultipleMemory1() { let f = new File("/tmp/versions"); f.delete(); let vt = new VersionTracker(store: f); let locator = _setupMultiple(vt); assert locator.get("foo/bar/a.txt#1").is("a1"); vt.save(); assert locator.get("foo/bar/a.txt").is("a1"); } void _testMultipleMemory2() { let f = new File("/tmp/versions"); f.delete(); let vt = new VersionTracker(store: f); let locator = _setupMultiple(vt); assert locator.get("foo/bar/a.txt#1").is("a1"); vt.save(); assert locator.get("foo/bar/b.txt") == null; } /// TOOLS boolean is(?URLConnection c, String value) = c != null && c.getInputStream().readAll().equals(value); private var int id = 0; File makeTempDir() { let f = new File("/tmp/ntl" + (id++)); deleteAll(f); f.mkdirs(); return f; } void deleteAll(File f) { if (f.isDirectory()) notNull(f.listFiles()).foreach(deleteAll); f.delete(); } void addJar(File dir, String pkg, String ver, String[] content) { let filename = packagePath(pkg) + pkg + "-"ver".jar"; let file = new File(dir, filename); notNull(file.getParentFile()).mkdirs(); let jar = new JarOutputStream(new FileOutputStream(file)); for (int i = 0; i < content.length; i += 2) { let name = content[i]; let value = content[i+1]; jar.putNextEntry(new JarEntry(name)); jar.write(value.getBytes()); } jar.close(); } void main(String[] args) = _testSingle(); |
From: Daniel B. <bo...@us...> - 2004-08-07 14:57:41
|
Update of /cvsroot/nice/Nice/src/nice/tools/repository/publish In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv758/src/nice/tools/repository/publish Added Files: send.nice main.nice Log Message: Implementation of remote package repositories. --- NEW FILE: main.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.tools.repository.publish; /** Publish a library on a public repository. @author Daniel Bonniot (bo...@us...) */ import nice.tools.repository; import nice.tools.compiler.console; import nice.tools.unit.console; let java.text.DateFormat fmt = getVerDateFormat(); java.text.DateFormat getVerDateFormat() { let res = new java.text.SimpleDateFormat("yyyyMMddhhmm"); res.setTimeZone(TimeZone.getTimeZone("UTC")); return res; } void main(String[] args) { let dest = args[0]; let pkg = args[1]; let ver = "0.0"; let datedVer = ver + "." fmt.format(new Date()); let jar = pkg + "-" datedVer ".jar"; if (compile(args.slice(2) + [ "-a", jar, pkg ]) != OK) System.exit(1); let listener = new TestListener(); runTests(pkg, listener, jar); if (listener.failed) System.exit(1); send(datedVer, jar, dest + '/' + packagePath(pkg)); } class TestListener extends nice.tools.unit.console.Listener { boolean failed = false; failure(test, cause) { super; failed = true; } } --- NEW FILE: send.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.tools.repository.publish; import java.io.*; boolean send(String datedVer, String jar, String dest) { let ident = dest.substring(0, dest.indexOf(':')); let dir = dest.substring(dest.indexOf(':') + 1); println("ssh " ident " mkdir -p " dir); Process p = Runtime.getRuntime().exec(["ssh", ident, "mkdir", "-p", dir]); if (waitFor(p, new OutputStreamWriter(System.out)) != 0) { println("\nPublication failed."); return false; } println("scp " jar " " dest); p = Runtime.getRuntime().exec(["scp", jar, dest]); if (waitFor(p, new OutputStreamWriter(System.out)) != 0) { println("\nPublication failed."); return false; } let temp = File.createTempFile("latest", "tmp"); using (let out = new PrintWriter(new FileWriter(temp))) { out.println(datedVer); } p = Runtime.getRuntime().exec(["scp", temp.getPath(), dest + "/latest"]); if (waitFor(p, new OutputStreamWriter(System.out)) != 0) { println("\nPublication failed."); return false; } return true; } |
From: Arjan B. <ar...@us...> - 2004-08-07 14:20:38
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27902/F:/nice/src/bossa/syntax Modified Files: DefaultMethodImplementation.java MethodBodyDefinition.java MethodImplementation.java Pattern.java dispatch.java.bootstrap super.nice tools.nice typecheck.nice Added Files: pattern.nice Log Message: Split up Pattern.java in subclasses and converted the subclasses to nice code. Index: Pattern.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Pattern.java,v retrieving revision 1.90 retrieving revision 1.91 diff -C2 -d -r1.90 -r1.91 *** Pattern.java 5 Aug 2004 19:01:18 -0000 1.90 --- Pattern.java 7 Aug 2004 14:20:29 -0000 1.91 *************** *** 2,6 **** /* N I C E */ /* A high-level object-oriented research language */ ! /* (c) Daniel Bonniot 2000 */ /* */ /* This program is free software; you can redistribute it and/or modify */ --- 2,6 ---- /* 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 */ *************** *** 24,29 **** import nice.tools.typing.Types; ! import gnu.expr.*; ! import nice.tools.code.Gen; /** --- 24,28 ---- import nice.tools.typing.Types; ! //import gnu.expr.*; /** *************** *** 31,114 **** @see MethodBodyDefinition - - @version $Date$ - @author Daniel Bonniot (bo...@us...) */ ! public class Pattern implements Located { ! /** ! Builds a new pattern. ! ! @param name the name of the argument ! @param tc a TypeConstructor that the argument must match ! for this alternative to be selected ! @param atValue constant value which the parameter must be equal to ! in order to match the pattern. Ex: null, 1, true, ... ! @param additional an additional TypeConstructor that ! the argument must match. ! It must be a super-class of <code>tc</code>. ! It is only used for overloading resolution, not at runtime. ! @param runtimeTC a type constructor that will be bound to ! the argument's runtime class. ! */ ! public Pattern(LocatedString name, ! TypeIdent tc, ConstantExp atValue, ! LocatedString refName, ! boolean exactlyAt, int kind, ! TypeIdent additional, ! TypeConstructor runtimeTC, ! Location location) ! { ! this.name = name; ! this.typeConstructor = tc; ! this.additional = additional; ! this.runtimeTC = runtimeTC; ! this.atValue = atValue; ! this.exactlyAt = exactlyAt; ! this.compareKind = kind; ! this.refName = refName; ! this.location = location; ! ! if (atValue != null) ! { ! if (atValue instanceof StringConstantExp) ! this.typeConstructor = new TypeIdent( ! new LocatedString("java.lang.String", atValue.location())); ! else ! this.tc = atValue.tc; ! } ! } ! Pattern(LocatedString name, TypeIdent tc) ! { ! this(name, tc, null, null, false, NONE, null, null, name.location()); ! } ! Pattern(TypeConstructor tc, boolean exactlyAt) ! { ! this.tc = tc; ! this.exactlyAt = exactlyAt; ! } ! Pattern(ConstantExp atValue) { ! this(null, null, atValue, null, false, NONE, null, null, ! atValue!=null ? atValue.location() : Location.nowhere() ); } ! Pattern(int kind, ConstantExp atValue) { ! this(null, null, atValue, null, false, kind, null, null, atValue.location()); } ! Pattern(LocatedString name) { ! this(name, null, null, null, false, NONE, null, null, name.location()); } ! static Pattern any(LocatedString name) { ! Pattern res = new Pattern(name); ! return res; } --- 30,74 ---- @see MethodBodyDefinition */ ! public abstract class Pattern implements Located { ! LocatedString name; ! TypeIdent typeConstructor; ! private TypeIdent additional; ! TypeConstructor tc; ! TypeConstructor tc2; ! // The class constraint verified by this pattern. ! private mlsub.typing.Constraint constraint; ! // The type of the class matched, if it is constrained. ! private mlsub.typing.Monotype patternType; ! private Location loc; ! Pattern(LocatedString name, Location loc) { ! this(name, null, loc); } ! Pattern(LocatedString name, TypeConstructor tc, Location loc) { ! this.name = name; ! this.tc = tc; ! this.loc = loc; } ! Pattern(TypeConstructor tc, TypeIdent add, Location loc) { ! this.tc = tc; ! this.additional = add; ! this.loc = loc; } ! Pattern(LocatedString name, TypeIdent ti, TypeIdent add, Location loc) { ! this.name = name; ! this.typeConstructor = ti; ! this.additional = add; ! this.loc = loc; } *************** *** 118,124 **** } ! final TypeConstructor getRuntimeTC() { ! return runtimeTC; } --- 78,84 ---- } ! TypeConstructor getRuntimeTC() { ! return null; } *************** *** 133,141 **** TypeSymbol sym = typeConstructor.resolveToTypeSymbol(scope); ! if (sym == TopMonotype.instance) ! { ! // This is @Object, which is always true, nothing to test. ! } ! else if (sym instanceof TypeConstructor) tc = (TypeConstructor) sym; else --- 93,97 ---- TypeSymbol sym = typeConstructor.resolveToTypeSymbol(scope); ! if (sym instanceof TypeConstructor) tc = (TypeConstructor) sym; else *************** *** 143,151 **** " is not a declared class or interface"); ! if (exactlyAt && !TypeConstructors.instantiable(tc)) User.error (typeConstructor.location(), "Pattern #" + typeConstructor + " cannot be matched because interfaces and abstract classes do not have direct instances."); typeConstructor = null; } --- 99,108 ---- " is not a declared class or interface"); ! if (exactlyAtType() && !TypeConstructors.instantiable(tc)) User.error (typeConstructor.location(), "Pattern #" + typeConstructor + " cannot be matched because interfaces and abstract classes do not have direct instances."); + typeConstructor = null; } *************** *** 179,183 **** { for(int i = 0; i < patterns.length; i++) { ! bossa.syntax.dispatch.resolveGlobalConstants(patterns[i]); } } --- 136,140 ---- { for(int i = 0; i < patterns.length; i++) { ! patterns[i] = bossa.syntax.dispatch.resolveGlobalConstants(patterns[i]); } } *************** *** 223,227 **** constraint.enter(); Typing.leq(type, patternType); ! if (exactlyAt) { Typing.leq(patternType, type); --- 180,184 ---- constraint.enter(); Typing.leq(type, patternType); ! if (exactlyAtType()) { Typing.leq(patternType, type); *************** *** 233,237 **** { Typing.leq(type, tc); ! if (exactlyAt) { Typing.leq(tc, type); --- 190,194 ---- { Typing.leq(type, tc); ! if (exactlyAtType()) { Typing.leq(tc, type); *************** *** 267,273 **** } - /** - * Iterates getTypeConstructor on a collection of Pattern. - */ static TypeConstructor[] getTC(Pattern[] patterns) { --- 224,227 ---- *************** *** 288,567 **** } ! /** ! Order on pattern that is compatible with the specificity of patterns. ! ! If that matches all values that this matches, the result is true. ! Additionally, if this matches values that are more specific than ! the values that matches, the result is also true. ! ! For instance, assuming class B extends A, exactly the following are true: ! @A less @A ! #A less @A ! @B less @A ! #B less @A ! #A less #A ! @B less #A ! #B less #A ! */ ! public boolean leq(Pattern that) ! { ! if (that.atAny() || this == that) ! return true; ! ! if (this.atAny()) ! return false; ! ! if (that.atNull() && this.atNull()) ! return true; ! ! if (that.atNull() || this.atNull()) ! return false; ! ! if (that.atNonNull()) ! // The only reason it could be false is if we are atNull, but that's ! // already handled. ! return true; ! ! // that is not atNonNull nor atAny at this point ! if (this.atNonNull()) ! return false; ! ! if (this.atEnum() && that.atEnum()) ! 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 (that.atIntCompare()) ! return this.atIntValue() && that.matchesCompareValue(this.atValue.longValue()); ! ! if (that.atValue != null && !that.atNull() &&!that.atIntCompare()) ! return (this.atValue != null && !this.atNull() &&!this.atIntCompare()) && this.atValue.equals(that.atValue); ! ! if (this.tc == that.tc) ! return this.exactlyAt || ! that.exactlyAt; ! ! return Typing.testRigidLeq(this.tc, that.tc); ! } ! ! /** ! 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.atValue.equals(that.atValue); ! ! 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) ! { ! if (atAny()) ! return true; ! ! if (atNull()) ! return tag == PrimitiveType.nullTC; ! ! if (atNonNull()) ! return tag != PrimitiveType.nullTC; ! ! // a null tc is an unmatchable argument (e.g. function) ! if (tag == null) ! return false; ! ! if ((atValue != null) && ! atTypeMatchingValue()) ! return false; ! ! if (atIntCompare()) ! return Typing.testRigidLeq(tag, PrimitiveType.longTC); ! ! if (exactlyAt) ! return Typing.testRigidLeq(tag, tc) && Typing.testRigidLeq(tc, tag); ! ! return Typing.testRigidLeq(tag, tc); ! } ! ! public boolean matchesValue(ConstantExp val) ! { ! if (atAny()) ! return true; ! ! if (atIntCompare()) ! return val.value instanceof Number && matchesCompareValue(val.longValue()); ! ! if (atNull()) ! return false; ! ! return (atValue != null) && atValue.equals(val); ! } ! ! private boolean matchesCompareValue(long val) ! { ! if (compareKind == LT) ! return val < atValue.longValue(); ! ! if (compareKind == LE) ! return val <= atValue.longValue(); ! ! if (compareKind == GE) ! return val >= atValue.longValue(); ! ! if (compareKind == GT) ! return val > atValue.longValue(); ! return false; ! } ! public void setDomainEq(boolean equal) { ! // only set it to atAny if it's a @type pattern ! if (equal && atValue == null && !exactlyAt) ! tc = null; ! ! // don't allow integer primitive types in @type and #type patterns ! if (!equal && atValue == null && Typing.testRigidLeq(tc, PrimitiveType.longTC)) ! User.error(location, "A pattern cannot have a primitive type that is different from the declaration."); ! } ! public void setDomainTC(TypeConstructor domaintc) ! { ! if (atIntValue()) ! { ! if (domaintc != null) ! { ! if (Typing.testRigidLeq(domaintc, PrimitiveType.intTC)) ! { ! tc = PrimitiveType.intTC; ! return; ! } ! else if (Typing.testRigidLeq(domaintc, PrimitiveType.longTC)) ! { ! tc = PrimitiveType.longTC; ! return; ! } ! else if (Typing.testRigidLeq(domaintc, PrimitiveType.charTC)) ! return; ! } ! User.error(location, "Integer value patterns are not allowed for methods where the declared parameter isn't a primitive type."); ! } ! } ! ! public List getEnumValues () ! { ! List res = new LinkedList(); ! ! if (atBool()) ! { ! res.add(ConstantExp.makeBoolean(true, location)); ! res.add(ConstantExp.makeBoolean(false, location)); ! return res; ! } ! ! // atEnum() ! List symbols = ((EnumDefinition)((EnumDefinition.EnumSymbol)atValue.value).getDefinition()).symbols; ! for (Iterator it = symbols.iterator(); it.hasNext(); ) ! { ! EnumDefinition.EnumSymbol sym = (EnumDefinition.EnumSymbol)it.next(); ! res.add(new ConstantExp(null, tc, sym, sym.name.toString(), location)); ! } ! ! return res; ! } ! /**************************************************************** ! * Printing ! ****************************************************************/ ! ! public String toString() ! { ! if (atIntCompare()) ! { ! String prefix = ""; ! if (compareKind == LT) prefix = "<"; ! if (compareKind == LE) prefix = "<="; ! if (compareKind == GT) prefix = ">"; ! if (compareKind == GE) prefix = ">="; ! return (name!=null? name.toString() : "") + prefix + atValue; ! } ! ! if (atValue != null) ! return atValue.toString(); ! ! if (atAny()) ! return name != null ? name.toString() : "Any"; ! StringBuffer res = new StringBuffer(); ! res.append(exactlyAt ? "#" : (name != null ? "" : "@")); ! ! if (typeConstructor != null) ! res.append(typeConstructor); ! else if (tc != null) ! res.append(tc); ! if (name != null) ! res.append(" " + name); ! ! return res.toString(); ! } ! public Location location() { return location; } - /**************************************************************** - * Bytecode representation - ****************************************************************/ - /** * Returns a string used to recognize this pattern in the bytecode. --- 242,262 ---- } ! public abstract boolean matches(TypeConstructor tag); ! public abstract boolean matchesValue(ConstantExp val); ! public Pattern setDomainEq(boolean equal) { ! return this; } ! public void setDomainTC(TypeConstructor domaintc) {} ! public void addValues(List values) {} ! public LocatedString getName() { return name; } ! public Location location() { return loc; } /** * Returns a string used to recognize this pattern in the bytecode. *************** *** 579,620 **** * This is usefull to distinguish alternatives of a method. */ ! public String bytecodeRepresentation() ! { ! if (atAny()) ! return "@_"; ! ! if (atNull()) ! return "@NULL"; ! ! if (atValue != null) ! { ! if (atIntCompare()) ! { ! String prefix = ""; ! if (compareKind == LT) prefix = "<"; ! if (compareKind == LE) prefix = "<="; ! if (compareKind == GT) prefix = ">"; ! if (compareKind == GE) prefix = ">="; ! ! return "@" + prefix + atValue; ! } ! ! if (atValue.value instanceof Number) ! return "@" + (atValue.longValue() >= 0 ? "+" : "") + atValue; ! ! if (atValue.value instanceof Character) ! return "@\'" + atValue.value + "\'"; ! ! if (atReference()) ! return "@=" + refName; ! ! if (atString()) ! return "@\"" + ((StringConstantExp)atValue).escapedValue + "\""; ! ! return "@" + atValue; ! } ! ! return (exactlyAt ? "#" : "@") + tc.toString().replace('$','.'); ! } public static String bytecodeRepresentation(Pattern[] patterns) --- 274,278 ---- * This is usefull to distinguish alternatives of a method. */ ! public abstract String bytecodeRepresentation(); public static String bytecodeRepresentation(Pattern[] patterns) *************** *** 626,742 **** return res.toString(); } - - public static Pattern read(String rep, int[]/*ref*/ pos, String methodName) - { - if (pos[0] >= rep.length()) - return null; - - if (rep.charAt(pos[0]) != '@' && rep.charAt(pos[0]) != '#') - Internal.error("Invalid pattern representation at character " + pos[0] + - ": " + rep); - - boolean exact = rep.charAt(pos[0]) == '#'; - - int start = ++pos[0]; - int len = rep.length(); - - if (rep.charAt(pos[0]) == '\'') - { //char literal patterns are 3 chars - pos[0] += 3; - } - else if (rep.charAt(pos[0]) == '\"') - { //we need to skip possible '@' or '#' content of the string literal - pos[0] += 2; - while(pos[0] < len && - ! ( ( rep.charAt(pos[0]) == '@' || rep.charAt(pos[0]) != '#') - && rep.charAt(pos[0]-1) == '\"' - && rep.charAt(pos[0]-2) != '\\') ) - pos[0]++; - - } - else - { - while(pos[0] < len && - rep.charAt(pos[0]) != '@' && rep.charAt(pos[0]) != '#') - pos[0]++; - } - - String name = rep.substring(start, pos[0]); - - if (name.length() > 1) - { - if (name.charAt(0) == '\'') - return new Pattern(new ConstantExp(PrimitiveType.charTC, - new Character(name.charAt(1)), name, Location.nowhere())); - - if (name.charAt(0) == '-') - return new Pattern(ConstantExp.makeNumber(new LocatedString(name, - Location.nowhere()))); - - if (name.charAt(0) == '+') - return new Pattern(ConstantExp.makeNumber(new LocatedString( - name.substring(1), Location.nowhere()))); - - if (name.charAt(0) == '\"') - return new Pattern(ConstantExp.makeString(new LocatedString( - name.substring(1,name.length()-1), Location.nowhere()))); - - if (name.charAt(0) == '<') - { - if (name.charAt(1) == '=') - return new Pattern(LE, ConstantExp.makeNumber(new LocatedString( - name.substring(2), Location.nowhere()))); - - return new Pattern(LT, ConstantExp.makeNumber(new LocatedString( - name.substring(1), Location.nowhere()))); - } - - if (name.charAt(0) == '>') - { - if (name.charAt(1) == '=') - return new Pattern(GE, ConstantExp.makeNumber(new LocatedString( - name.substring(2), Location.nowhere()))); - - return new Pattern(GT, ConstantExp.makeNumber(new LocatedString( - name.substring(1), Location.nowhere()))); - } - - if (name.charAt(0) == '=') - { - LocatedString refName = new LocatedString(name.substring(1), - Location.nowhere()); - - Pattern res = new Pattern(refName); - bossa.syntax.dispatch.resolveGlobalConstants(res); - return res; - } - } - - if (name.equals("_")) - return new Pattern((ConstantExp)null); - - if (name.equals("NULL")) - return new Pattern(NullExp.create(Location.nowhere())); - - if (name.equals("true") || name.equals("false") ) - return new Pattern(ConstantExp.makeBoolean(name.equals("true"), - Location.nowhere())); - - TypeSymbol sym = Node.getGlobalTypeScope().lookup(name); - - if (sym == null) - // This can happen if the class exists only in a later version - // of the JDK. - throw new Unknown(); - - return new Pattern((TypeConstructor) sym, exact); - } - - public static class Unknown extends RuntimeException {} - - /**************************************************************** - * Code generation - ****************************************************************/ /** Returns code that tests if the parameter is matched. --- 284,290 ---- return res.toString(); } + public static class Unknown extends RuntimeException {} + /** Returns code that tests if the parameter is matched. *************** *** 745,840 **** still necessary to check for exact matching if applicable. */ ! public gnu.expr.Expression matchTest(gnu.expr.Expression parameter, ! boolean dispatchMade) ! { ! if (atAny() || (dispatchMade && ! exactlyAt)) ! return QuoteExp.trueExp; ! ! if (atNull()) ! return Gen.isNullExp(parameter); ! ! if (atBool()) ! { ! if (atValue.isFalse()) ! return Gen.boolNotExp(parameter); ! ! return parameter; ! } ! ! if (atIntValue()) ! { ! String kind; ! if (compareKind == LT) kind = "Lt"; ! else if (compareKind == LE) kind = "Le"; ! else if (compareKind == GE) kind = "Ge"; ! else if (compareKind == GT) kind = "Gt"; ! else kind = "Eq"; ! ! return Gen.integerComparison(kind, parameter, atValue.longValue()); ! } ! ! if (atString()) ! return Gen.stringEquals((String)atValue.value, parameter); ! ! if (atReference()) ! return Gen.referenceEqualsExp(atValue.compile(), parameter); ! ! gnu.bytecode.Type ct = nice.tools.code.Types.javaType(tc); ! if (exactlyAt) ! return Gen.isOfClass(parameter, ct); ! ! return Gen.instanceOfExp(parameter, ct); ! } ! ! /**************************************************************** ! * Fields ! ****************************************************************/ ! ! LocatedString name,refName; ! TypeIdent typeConstructor; ! private TypeIdent additional; ! TypeConstructor tc; ! TypeConstructor tc2; ! private TypeConstructor runtimeTC; ! ! // The class constraint verified by this pattern. ! private mlsub.typing.Constraint constraint; ! // The type of the class matched, if it is constrained. ! private mlsub.typing.Monotype patternType; ! ! private boolean exactlyAt; ! public ConstantExp atValue; ! public int compareKind = NONE; ! ! public static final int NONE = 0; ! public static final int LT = 1; ! public static final int LE = 2; ! public static final int GT = 4; ! public static final int GE = 5; ! ! private Location location; ! public boolean atIntValue() { ! return atValue != null && (atValue.value instanceof Number || ! atValue.value instanceof Character); ! } ! public boolean atNull() { return (atValue != null) && atValue.isNull(); } ! /** This pattern only specifies that the vlaue is not null. ! This cannot be explicitely used in source programs, but it is useful ! when a method with a non-null parameter specializes one where that ! parameter can be null. ! */ ! public boolean atNonNull() { return tc == PrimitiveType.sureTC; } ! public boolean atAny() { return atValue == null && tc == null; } ! public boolean atBool() { ! return atValue != null && tc == PrimitiveType.boolTC; ! } ! public boolean atString() { return atValue instanceof StringConstantExp; } ! public boolean atReference() { return atValue != null && atValue.value instanceof VarSymbol; } ! public boolean atEnum() { return atReference() && atValue.value instanceof EnumDefinition.EnumSymbol; } ! public boolean atIntCompare() { return compareKind > 0;} ! public boolean atLess() { return compareKind == LT || compareKind == LE; } ! public boolean atTypeMatchingValue() { return atEnum() || atIntCompare() || atBool();} ! public boolean atSimpleValue() { return atString() || (atIntValue() && ! atIntCompare()); } ! public boolean atEnumerableValue() { return atBool() || atEnum(); } } --- 293,302 ---- still necessary to check for exact matching if applicable. */ ! public abstract gnu.expr.Expression matchTest(gnu.expr.Expression parameter, boolean dispatchMade); ! public boolean atAny() { return false; } ! public boolean atNull() { return false; } ! protected boolean exactlyAtType() { return false; } ! public boolean atValue() { return false; } ! public boolean atTypeMatchingValue() { return false;} } Index: super.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/super.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** super.nice 30 Jul 2004 13:06:21 -0000 1.1 --- super.nice 7 Aug 2004 14:20:29 -0000 1.2 *************** *** 25,29 **** ?List<TypeIdent> types; ! ?List<TypeConstructor> tc = null; ?MethodBodyDefinition currentMethod = null; ?Alternative superAlternative = null; --- 25,29 ---- ?List<TypeIdent> types; ! ?List<mlsub.typing.TypeConstructor> tc = null; ?MethodBodyDefinition currentMethod = null; ?Alternative superAlternative = null; *************** *** 50,54 **** minimumAlt = null; else ! minimumAlt = new Alternative("", notNull(tc).map(TypeConstructor tc => new Pattern(tc, false)).toArray()); // Look for the first alternative more general than the current one. --- 50,54 ---- minimumAlt = null; else ! minimumAlt = new Alternative("", notNull(tc).map(mlsub.typing.TypeConstructor tc => createPattern(tc)).toArray()); // Look for the first alternative more general than the current one. --- NEW FILE: pattern.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 bossa.syntax; import bossa.util.*; public Pattern createPattern(LocatedString name) { return new VariablePattern(name, name.location); } public Pattern createPattern(LocatedString name, TypeIdent ti) { if (ti.toString().equals("Object")) return new NotNullPattern(name, PrimitiveType.sureTC, name.location); return new TypePattern(name, ti, null, name.location(), exactlyAt: false); } //for use in MethodImplementation public Pattern createPattern(?LocatedString name, ?mlsub.typing.TypeConstructor tc, boolean sure) { let loc = (name != null) ? name.location() : Location.nowhere(); if (sure && tc == null) return new NotNullPattern(name, PrimitiveType.sureTC, loc); if (nice.tools.typing.Types.isPrimitive(tc)) tc = null; if (tc == null) return new VariablePattern(name, loc); return new TypePattern(name, tc, loc, exactlyAt: false); } public Pattern createPattern(TypeIdent ti, ?LocatedString name, boolean exactly, ?TypeIdent additional, ?mlsub.typing.TypeConstructor runtimeTC) { if (ti.toString().equals("Object")) return new NotNullPattern(name, PrimitiveType.sureTC, ti.location); return new TypePattern(name, ti, additional, ti.location(), exactlyAt: exactly, runtimeTC: runtimeTC); } public Pattern createPattern(ConstantExp value) { return createPattern(value, null); } public Pattern createPattern(ConstantExp value, ?TypeIdent additional) { if (value instanceof NullExp) return new NullPattern(value.tc, additional, value.location()); if (value instanceof StringConstantExp) return new StringPattern(null, new TypeIdent(new LocatedString("java.lang.String", value.location())), additional, value.location(), atValue: value); if (value.tc == PrimitiveType.boolTC) return new BoolPattern(value.tc, additional, value.location(), atValue: value); if (value.tc == PrimitiveType.charTC) return new CharPattern(value.tc, additional, value.location(), atValue: value); return new IntPattern(value.tc, additional, value.location(), atValue: value); } public Pattern createPattern(String kind, ?LocatedString name, ?ConstantExp value, ?LocatedString refName, bossa.util.Location loc) { CompareKind k; if ("<".equals(kind)) k = CK_LT; else if ("<=".equals(kind)) k = CK_LE; else if (">".equals(kind)) k = CK_GT; else k = CK_GE; let tc = (value != null) ? value.tc : null; return new IntComparePattern(name, tc, loc, atValue: cast(value), kind: k, refName: refName); } Pattern createPattern(mlsub.typing.TypeConstructor tc) { return new TypePattern(null, tc, null, exactlyAt: false); } public class VariablePattern extends Pattern { matches(tag) = true; matchesValue(ConstantExp val) = true; toString() = (name != null) ? notNull(name).toString() : "_"; bytecodeRepresentation() = "@_"; matchTest(parameter, dispatchMade) = notNull(gnu.expr.QuoteExp.trueExp); atAny() = true; } public class NullPattern extends Pattern { matches(tag) = tag == PrimitiveType.nullTC; matchesValue(ConstantExp val) = false; toString() = "null"; bytecodeRepresentation() = "@NULL"; matchTest(parameter, dispatchMade) = nice.tools.code.Gen.isNullExp(parameter); atNull() = true; } public class NotNullPattern extends Pattern { matches(tag) = tag != PrimitiveType.nullTC; matchesValue(ConstantExp val) = false; toString() = "!null"; bytecodeRepresentation() = "@NONNULL"; matchTest(parameter, dispatchMade) { return nice.tools.code.Gen.boolNotExp(nice.tools.code.Gen.isNullExp(parameter)); } } public class TypePattern extends Pattern { boolean exactlyAt; ?mlsub.typing.TypeConstructor runtimeTC = null; getRuntimeTC() = runtimeTC; setDomainEq(equal) { // only set it to atAny if it's a @type pattern if (equal && !exactlyAt) return new VariablePattern(name, this.location); // don't allow integer primitive types in @type and #type patterns if (!equal && Typing.testRigidLeq(tc, PrimitiveType.longTC)) User.error(this.location, "A pattern cannot have a primitive type that is different from the declaration."); return this; } matches(tag) { if (tag == null) return false; if (exactlyAt) return mlsub.typing.Typing.testRigidLeq(tag, tc) && mlsub.typing.Typing.testRigidLeq(tc, tag); return mlsub.typing.Typing.testRigidLeq(tag, tc); } matchesValue(ConstantExp val) = false; toString() { StringBuffer res = new StringBuffer(); res.append(exactlyAt ? "#" : (name != null ? "" : "@")); if (typeConstructor != null) res.append(typeConstructor); else if (tc != null) res.append(tc); if (name != null) res.append(" " + name); return res.toString(); } bytecodeRepresentation() { return (exactlyAt ? "#" : "@") + notNull(tc).toString().replace('$','.'); } matchTest(parameter, dispatchMade) { if (dispatchMade && ! exactlyAt) return notNull(gnu.expr.QuoteExp.trueExp); let ct = nice.tools.code.Types.javaType(tc); if (exactlyAt) return nice.tools.code.Gen.isOfClass(parameter, ct); return nice.tools.code.Gen.instanceOfExp(parameter, ct); } exactlyAtType() = exactlyAt; } public abstract class ValuePattern extends Pattern { final ConstantExp atValue; matches(tag) = false; matchesValue(ConstantExp val) = atValue.equals(val); toString() = atValue.toString(); addValues(values) { values.add(atValue); } atValue() = true; } public class BoolPattern extends ValuePattern { addValues(values) { values.add(ConstantExp.makeBoolean(true, this.location)); values.add(ConstantExp.makeBoolean(false, this.location)); } matches(tag) = tag == PrimitiveType.boolTC; bytecodeRepresentation() = atValue.isTrue() ? "@true" : "@false"; matchTest(parameter, dispatchMade) { if (atValue.isFalse()) return nice.tools.code.Gen.boolNotExp(parameter); return cast(parameter); } atTypeMatchingValue() = true; } public class StringPattern extends ValuePattern { override StringConstantExp atValue; bytecodeRepresentation() { return "@\"" + atValue.escapedValue + "\""; } matchTest(parameter, dispatchMade) { let String val = cast(atValue.value); return nice.tools.code.Gen.stringEquals(val, parameter); } } public class CharPattern extends ValuePattern { bytecodeRepresentation() = "@\'" + atValue.value + "\'"; setDomainTC(domaintc) { if (domaintc != null) if ( Typing.testRigidLeq(domaintc, PrimitiveType.charTC)) return; User.error(this.location, "Character value patterns are not allowed for methods where the declared parameter isn't a primitive type."); } matchTest(parameter, dispatchMade) { return nice.tools.code.Gen.integerComparison("Eq", parameter, atValue.longValue()); } } public class IntPattern extends ValuePattern { matchesValue(ConstantExp val) { return (val.value instanceof Number) && atValue.longValue() == val.longValue(); } setDomainTC(domaintc) { if (domaintc != null) { if (Typing.testRigidLeq(domaintc, PrimitiveType.intTC)) { tc = PrimitiveType.intTC; return; } else if (Typing.testRigidLeq(domaintc, PrimitiveType.longTC)) { tc = PrimitiveType.longTC; return; } } User.error(this.location, "Integer value patterns are not allowed for methods where the declared parameter isn't a primitive type."); } bytecodeRepresentation() = "@" + (atValue.longValue() >= 0 ? "+" : "") + atValue; matchTest(parameter, dispatchMade) { return nice.tools.code.Gen.integerComparison("Eq", parameter, atValue.longValue()); } } enum CompareKind(String prefix, String abbrev) { CK_LT("<", "Lt"), CK_LE("<=", "Le"), CK_GT(">", "Gt"), CK_GE(">=", "Ge") } boolean matches(CompareKind k, long x, long y); matches(CK_LT, x, y) = x < y; matches(CK_LE, x, y) = x <= y; matches(CK_GT, x, y) = x > y; matches(CK_GE, x, y) = x >= y; public class IntComparePattern extends IntPattern { CompareKind kind; ?LocatedString refName; matches(tag) = tag != null && mlsub.typing.Typing.testRigidLeq(tag, PrimitiveType.longTC); matchesValue(ConstantExp val) { return val.value instanceof Number && matches(kind, val.longValue(), atValue.longValue()); } toString() = (name!=null? notNull(name).toString() : "") + kind.prefix + atValue; bytecodeRepresentation() = "@" + kind.prefix + atValue; matchTest(parameter, dispatchMade) { return nice.tools.code.Gen.integerComparison(kind.abbrev, parameter, atValue.longValue()); } addValues(values) { let val = atValue.longValue(); long lo = val; long hi = val; if (kind == CK_LT || kind == CK_GE) lo = val-1; else hi = val+1; while(values.any(ConstantExp ce => (ce.value instanceof Number) && (ce.longValue == lo))) lo--; values.add(new ConstantExp(new Long(lo))); while(values.any(ConstantExp ce => (ce.value instanceof Number) && (ce.longValue == hi))) hi++; values.add(new ConstantExp(new Long(hi))); } boolean atLess() = (kind == CK_LT || kind == CK_LE); atTypeMatchingValue() = true; } public class ReferencePattern extends ValuePattern { bytecodeRepresentation() = "@=" + name; matchTest(parameter, dispatchMade) { return nice.tools.code.Gen.referenceEqualsExp(atValue.compile(), parameter); } getName() = cast(null); } public class EnumPattern extends ReferencePattern { matches(tag) = (tag != null) && mlsub.typing.Typing.testRigidLeq(tag, tc); addValues(values) { let EnumDefinition.EnumSymbol esym = cast(atValue.value); let EnumDefinition edef = cast(esym.getDefinition()); for (sym : edef.symbols) values.add(new ConstantExp(null, tc, sym, sym.name.toString(), this.location)); } atTypeMatchingValue() = true; } /** Order on pattern that is compatible with the specificity of patterns. If that matches all values that this matches, the result is true. Additionally, if this matches values that are more specific than the values that matches, the result is also true. */ boolean leq(Pattern this, Pattern that); leq(VariablePattern this, VariablePattern that) = true; leq(Pattern this, VariablePattern that) = true; leq(VariablePattern this, Pattern that) = false; leq(NullPattern this, NullPattern that) = true; leq(NullPattern this, VariablePattern that) = true; leq(NullPattern this, Pattern that) = false; leq(Pattern this, NullPattern that) = false; leq(VariablePattern this, NullPattern that) = false; leq(NullPattern this, NotNullPattern that) = false; leq(NotNullPattern this, NullPattern that) = false; leq(Pattern this, NotNullPattern that) = true; leq(NotNullPattern this, NotNullPattern that) = true; leq(NotNullPattern this, VariablePattern that) = true; leq(VariablePattern this, NotNullPattern that) = false; leq(NotNullPattern this, Pattern that) = false; leq(ValuePattern this, ValuePattern that) = this.atValue.equals(that.atValue); leq(TypePattern this, ValuePattern that) = false; leq(IntComparePattern this, IntComparePattern that) { if (this.atLess() != that.atLess()) return false; long val = this.atValue.longValue(); if (this.kind == CK_LT) val--; if (this.kind == CK_GT) val++; return matches(that.kind, val, that.atValue.longValue()); } leq(IntPattern this, IntComparePattern that) = matches(that.kind, this.atValue.longValue(), that.atValue.longValue()); leq(IntComparePattern this, IntPattern that) = false; leq(TypePattern this, TypePattern that) { if (this.tc == that.tc) return this.exactlyAt || ! that.exactlyAt; return Typing.testRigidLeq(this.tc, that.tc); } leq(Pattern this, Pattern that) { if (this.tc == that.tc) return true; return Typing.testRigidLeq(this.tc, that.tc); } /** returns true when the patterns can't match the same values. May return false if it can't be determined easily. */ boolean disjoint(Pattern this, Pattern that); disjoint(VariablePattern this, VariablePattern that) = false; disjoint(Pattern this, VariablePattern that) = false; disjoint(VariablePattern this, Pattern that) = false; disjoint(NullPattern this, NullPattern that) = false; disjoint(Pattern this, NullPattern that) = true; disjoint(NullPattern this, Pattern that) = false; disjoint(NullPattern this, VariablePattern that) = false; disjoint(VariablePattern this, NullPattern that) = false; disjoint(NotNullPattern this, NotNullPattern that) = false; disjoint(NotNullPattern this, NullPattern that) = true; disjoint(NullPattern this, NotNullPattern that) = true; disjoint(ValuePattern this, ValuePattern that) = ! this.atValue.equals(that.atValue); disjoint(IntComparePattern this, IntComparePattern that) { if (this.atLess() == that.atLess()) return false; long val = this.atValue.longValue(); if (this.kind == CK_LT) val--; if (this.kind == CK_GT) val++; return ! matches(that.kind, val, that.atValue.longValue()); } disjoint(IntComparePattern this, IntPattern that) = matches(this.kind, that.atValue.longValue(), this.atValue.longValue()); disjoint(IntPattern this, IntComparePattern that) = matches(that.kind, this.atValue.longValue(), that.atValue.longValue()); disjoint(TypePattern this, TypePattern that) { 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; } disjoint(Pattern this, Pattern that) { 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; } private ?VarSymbol findRefSymbol(LocatedString refName) { for (sym : Node.getGlobalScope().lookup(refName)) if (sym instanceof GlobalVarDeclaration.GlobalVarSymbol || sym instanceof EnumDefinition.EnumSymbol ) return sym; return null; } Pattern resolveGlobalConstants(Pattern pattern) { return pattern; } resolveGlobalConstants(IntComparePattern pattern) { if (pattern.refName != null) { let symbol = findRefSymbol(notNull(pattern.refName)); if (symbol instanceof GlobalVarDeclaration.GlobalVarSymbol) { if (symbol.getValue() instanceof ConstantExp && symbol.constant) { ConstantExp val = cast(symbol.getValue()); if (Typing.testRigidLeq(val.tc, PrimitiveType.longTC)) return createPattern(pattern.kind.prefix, pattern.name, val, null, pattern.location); } } User.error(pattern.refName, notNull(pattern.refName).toString() + " is not a global constant with an integer value."); } return pattern; } resolveGlobalConstants(VariablePattern pattern) { if (pattern.name == null) return pattern; let symbol = findRefSymbol(notNull(pattern.name)); if (symbol == null) return pattern; if (symbol instanceof EnumDefinition.EnumSymbol) { NewExp val = cast(symbol.getValue()); return new EnumPattern(pattern.name, val.tc, pattern.location, atValue: new ConstantExp(null, pattern.tc, symbol, notNull(pattern.name).toString(), pattern.location)); } if (! (symbol instanceof GlobalVarDeclaration.GlobalVarSymbol)) return pattern; if (symbol.getValue() instanceof ConstantExp) { if (!symbol.constant) User.error(pattern.name, "" + pattern.name + " is not constant"); ConstantExp val = cast(symbol.getValue()); if (val.tc == PrimitiveType.floatTC) return pattern; return createPattern(val); } else if (symbol.getValue() instanceof NewExp) { NewExp val = cast(symbol.getValue()); return new ReferencePattern(pattern.name, val.tc, pattern.location, atValue: new ConstantExp(null, pattern.tc, symbol, notNull(pattern.name).toString(), pattern.location)); } else User.error(pattern.name, "The value of " + pattern.name + " can't be used as pattern"); return pattern; } public ?Pattern readPattern(String rep, int[]/*ref*/ pos) { if (pos[0] >= rep.length()) return null; if (rep.charAt(pos[0]) != '@' && rep.charAt(pos[0]) != '#') Internal.error("Invalid pattern representation at character " + pos[0] + ": " + rep); boolean exact = rep.charAt(pos[0]) == '#'; int start = pos[0]+1; pos[0] += 1; int len = rep.length(); if (rep.charAt(pos[0]) == '\'') { //char literal patterns are 3 chars pos[0] += 3; } else if (rep.charAt(pos[0]) == '\"') { //we need to skip possible '@' or '#' content of the string literal pos[0] += 2; while(pos[0] < len && ! ( ( rep.charAt(pos[0]) == '@' || rep.charAt(pos[0]) != '#') && rep.charAt(pos[0]-1) == '\"' && rep.charAt(pos[0]-2) != '\\') ) pos[0] += 1; } else { while(pos[0] < len && rep.charAt(pos[0]) != '@' && rep.charAt(pos[0]) != '#') pos[0] += 1; } String name = rep.substring(start, pos[0]); let loc = Location.nowhere(); if (name.length() > 1) { if (name.charAt(0) == '\'') return createPattern(new ConstantExp(PrimitiveType.charTC, new Character(name.charAt(1)), name, loc)); if (name.charAt(0) == '-') return createPattern(ConstantExp.makeNumber(new LocatedString(name, loc))); if (name.charAt(0) == '+') return createPattern(ConstantExp.makeNumber(new LocatedString( name.substring(1), loc))); if (name.charAt(0) == '\"') return createPattern(ConstantExp.makeString(new LocatedString( name.substring(1,name.length()-1), loc))); if (name.charAt(0) == '<' || name.charAt(0) == '>') { let prefix = (name.charAt(1) == '=') ? name.substring(0,2) : name.substring(0,1); return createPattern(prefix, null, ConstantExp.makeNumber( new LocatedString(name.substring(prefix.length()), loc)), null, loc); } if (name.charAt(0) == '=') return resolveGlobalConstants(new VariablePattern(new LocatedString(name.substring(1), loc), loc)); } if (name.equals("_")) return createPattern(new LocatedString("_", loc)); if (name.equals("NULL")) return createPattern(NullExp.create(loc)); if (name.equals("true") || name.equals("false") ) return createPattern(ConstantExp.makeBoolean(name.equals("true"), loc)); ?TypeSymbol sym = Node.getGlobalTypeScope().lookup(name); if (sym == null) // This can happen if the class exists only in a later version // of the JDK. throw new Unknown(); let mlsub.typing.TypeConstructor tc = cast(sym); return new TypePattern(null, tc, Location.nowhere(), exactlyAt:exact); } public class Unknown extends RuntimeException {} Index: MethodImplementation.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodImplementation.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MethodImplementation.java 20 Mar 2004 15:49:24 -0000 1.6 --- MethodImplementation.java 7 Aug 2004 14:20:29 -0000 1.7 *************** *** 91,95 **** } ! res[tn] = new MonoSymbol(p.name, type); } scope.addSymbols(res); --- 91,95 ---- } ! res[tn] = new MonoSymbol(p.getName(), type); } scope.addSymbols(res); *************** *** 105,117 **** for (int i = 0; i < formals.length; i++) if (formals[i].tc == null) ! { ! formals[i].tc = Types.concreteConstructor(parameters[i]); ! ! if (formals[i].tc == null && Types.isSure(parameters[i])) ! formals[i].tc = PrimitiveType.sureTC; ! ! if (Types.isPrimitive(formals[i].tc)) ! formals[i].tc = null; ! } } --- 105,113 ---- for (int i = 0; i < formals.length; i++) if (formals[i].tc == null) ! formals[i] = bossa.syntax.dispatch.createPattern(formals[i].name, ! Types.concreteConstructor(parameters[i]), ! Types.isSure(parameters[i])); ! ! } Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** tools.nice 6 Aug 2004 17:46:32 -0000 1.45 --- tools.nice 7 Aug 2004 14:20:29 -0000 1.46 *************** *** 178,267 **** } - void resolveGlobalConstants(Pattern pattern) - { - ?VarSymbol findRefSymbol(LocatedString refName) - { - for (sym : Node.getGlobalScope().lookup(refName)) - { - if (sym instanceof GlobalVarDeclaration.GlobalVarSymbol || - sym instanceof EnumDefinition.EnumSymbol ) - return sym; - } - - return null; - } - - if (pattern.refName != null) - { - ?VarSymbol symbol = findRefSymbol(notNull(pattern.refName)); - if (symbol instanceof GlobalVarDeclaration.GlobalVarSymbol) - { - if (symbol.getValue() instanceof ConstantExp && symbol.constant) - { - ConstantExp val = cast(symbol.getValue()); - if (Typing.testRigidLeq(val.tc, PrimitiveType.longTC)) - { - pattern.tc = val.tc; - pattern.atValue = val; - return; - } - } - } - User.error(pattern.refName, notNull(pattern.refName).toString() + " is not a global constant with an integer value."); - } - - if (pattern.name == null) - return; - - ?VarSymbol symbol = findRefSymbol(notNull(pattern.name)); - if (symbol == null) - return; - - if (symbol instanceof EnumDefinition.EnumSymbol) - { - NewExp val = cast(symbol.getValue()); - - pattern.tc = val.tc; - pattern.atValue = new ConstantExp(null, pattern.tc, symbol, - notNull(pattern.name).toString(), pattern.location); - pattern.refName = pattern.name; - pattern.name = null; - return; - } - - if (! (symbol instanceof GlobalVarDeclaration.GlobalVarSymbol)) - return; - - if (symbol.getValue() instanceof ConstantExp) - { - if (!symbol.constant) - User.error(pattern.name, "" + pattern.name + " is not constant"); - - ConstantExp val = cast(symbol.getValue()); - - if (val.tc == PrimitiveType.floatTC) - return; - - if (val instanceof StringConstantExp) - pattern.typeConstructor = new TypeIdent(new LocatedString("java.lang.String", - pattern.location)); - pattern.tc = val.tc; - pattern.atValue = val; - pattern.name = null; - } - else if (symbol.getValue() instanceof NewExp) - { - NewExp val = cast(symbol.getValue()); - pattern.tc = val.tc; - pattern.atValue = new ConstantExp(null, pattern.tc, symbol, - notNull(pattern.name).toString(), pattern.location); - pattern.refName = pattern.name; - pattern.name = null; - } - else - User.error(pattern.name, "The value of " + pattern.name + " can't be used as pattern"); - } - - // For bootstrap void _printStackTraceWithSourceInfo(Throwable t) = --- 178,181 ---- *************** *** 291,294 **** --- 205,212 ---- List<VarSymbol> getConstructorCallSymbols(NiceClass) = native List NiceClass.getConstructorCallSymbols(); LinkedList<VarSymbol> getConstructors(mlsub.typing.TypeConstructor) = native LinkedList TypeConstructors.getConstructors(mlsub.typing.TypeConstructor); + List<VarSymbol> symbols(EnumDefinition) = native EnumDefinition.symbols; + void addValues(Pattern, List<ConstantExp>) = native void Pattern.addValues(List); + ?mlsub.typing.TypeConstructor getRuntimeTC(Pattern) = native mlsub.typing.TypeConstructor Pattern.getRuntimeTC(); + boolean matchesValue(Pattern, ConstantExp) = native boolean Pattern.matchesValue(ConstantExp); // Retypings needed since java types are not strict. Index: MethodBodyDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodBodyDefinition.java,v retrieving revision 1.150 retrieving revision 1.151 diff -C2 -d -r1.150 -r1.151 *** MethodBodyDefinition.java 28 Jul 2004 14:40:33 -0000 1.150 --- MethodBodyDefinition.java 7 Aug 2004 14:20:28 -0000 1.151 *************** *** 75,79 **** Pattern[] res = new Pattern[formals.size() + 1]; ! res[0] = new Pattern(new LocatedString("this", loc), new TypeIdent(container.definition.getName())); int n = 1; --- 75,79 ---- Pattern[] res = new Pattern[formals.size() + 1]; ! res[0] = bossa.syntax.dispatch.createPattern(new LocatedString("this", loc), new TypeIdent(container.definition.getName())); int n = 1; *************** *** 363,369 **** { TypeConstructor tc = Types.rawType(domain[n]).head(); - if (formals[n].tc != null) ! formals[n].setDomainEq(tc != null && Types.isSure(domain[n]) && Typing.testLeq(tc, formals[n].tc)); --- 363,368 ---- { TypeConstructor tc = Types.rawType(domain[n]).head(); if (formals[n].tc != null) ! formals[n] = formals[n].setDomainEq(tc != null && Types.isSure(domain[n]) && Typing.testLeq(tc, formals[n].tc)); Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** dispatch.java.bootstrap 5 Aug 2004 10:45:30 -0000 1.18 --- dispatch.java.bootstrap 7 Aug 2004 14:20:29 -0000 1.19 *************** *** 56,61 **** static void resolveCCThis(Statement stmt, bossa.util.Located thisloc, NiceClass classe) {} ! static void resolveGlobalConstants(Pattern pattern) {} static Statement analyse(Statement s, VarScope v, TypeScope t, boolean r) { return null; } --- 56,92 ---- static void resolveCCThis(Statement stmt, bossa.util.Located thisloc, NiceClass classe) {} ! static Pattern resolveGlobalConstants(Pattern pattern) ! { return null; } ! ! public static Pattern readPattern(String rep, int[] pos) ! { return null; } ! ! public static Pattern createPattern(LocatedString name) ! { return null; } + public static Pattern createPattern(LocatedString name, TypeIdent ti) + { return null; } + + public static Pattern createPattern(LocatedString name, mlsub.typing.TypeConstructor tc, boolean sure) + { return null; } + + public static Pattern createPattern(TypeIdent tc, LocatedString name, boolean exactly, TypeIdent additional, mlsub.typing.TypeConstructor runtimeTC) + { return null; } + + public static Pattern createPattern(ConstantExp value) + { return null; } + + public static Pattern createPattern(ConstantExp value, TypeIdent additional) + { return null; } + + public static Pattern createPattern(String kind, LocatedString name, ConstantExp value, LocatedString refName, bossa.util.Location loc) + { return null; } + + public static boolean leq(Pattern a, Pattern b) + { return false; } + + public static boolean disjoint(Pattern a, Pattern b) + { return false; } + static Statement analyse(Statement s, VarScope v, TypeScope t, boolean r) { return null; } Index: DefaultMethodImplementation.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/DefaultMethodImplementation.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DefaultMethodImplementation.java 2 Mar 2004 16:02:44 -0000 1.7 --- DefaultMethodImplementation.java 7 Aug 2004 14:20:28 -0000 1.8 *************** *** 48,52 **** name = new LocatedString("_", loc); ! res[i] = Pattern.any(name); } return res; --- 48,52 ---- name = new LocatedString("_", loc); ! res[i] = bossa.syntax.dispatch.createPattern(name); } return res; Index: typecheck.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v retrieving revision 1.109 retrieving revision 1.110 diff -C2 -d -r1.109 -r1.110 *** typecheck.nice 6 Aug 2004 17:46:32 -0000 1.109 --- typecheck.nice 7 Aug 2004 14:20:29 -0000 1.110 *************** *** 630,643 **** { Expression[] knownDimensions = notNull(e.knownDimensions); ! for (int i=0; i<knownDimensions.length; i++) { ! Expression dim = knownDimensions[i] = ! knownDimensions[i].resolveOverloading(PrimitiveType.intPolytype); try{ ! checkAssignment(PrimitiveType.intType, dim); } catch(TypingEx ex){ ! if (notNullError(ex, dim, dim.toString())) bossa.util.User.error(dim, "" + dim + " should be an integer"); --- 630,642 ---- { Expression[] knownDimensions = notNull(e.knownDimensions); ! typecheckExps(cast(knownDimensions)); for (int i=0; i<knownDimensions.length; i++) { ! Expression dim = knownDimensions[i]; try{ ! Typing.leq(dim.getType(), PrimitiveType.intPolytype); } catch(TypingEx ex){ ! if (notNullError(ex, dim, dim.toString())) bossa.util.User.error(dim, "" + dim + " should be an integer"); |