nice-commit Mailing List for The Nice Programming Language (Page 117)
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: <bo...@us...> - 2003-04-19 13:48:15
|
Update of /cvsroot/nice/Nice/bin In directory sc8-pr-cvs1:/tmp/cvs-serv28282/bin Modified Files: nicec Log Message: Added the possibility to rely on external/nice-bootstrap.jar instead of a standalone bootstrap compiler, to allow a self-contained bootstrapping process. Index: nicec =================================================================== RCS file: /cvsroot/nice/Nice/bin/nicec,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** nicec 21 Oct 2002 16:56:20 -0000 1.32 --- nicec 19 Apr 2003 13:48:10 -0000 1.33 *************** *** 76,81 **** done ! find_home "$scriptName" ! NICEC=${APPHOME}/share/java/nice.jar case $progname in --- 76,83 ---- done ! if [ -z "$NICEC_JAR" ]; then ! find_home "$scriptName" ! NICEC_JAR=${APPHOME}/share/java/nice.jar ! fi case $progname in *************** *** 84,90 **** # We don't want that by default (if CLASSPATH is empty). if [ -z "${CLASSPATH}" ]; then ! CLASSPATH=${NICEC} else ! CLASSPATH=${NICEC}:${CLASSPATH} fi if [ $experimental = true ]; then --- 86,92 ---- # We don't want that by default (if CLASSPATH is empty). if [ -z "${CLASSPATH}" ]; then ! CLASSPATH=${NICEC_JAR} else ! CLASSPATH=${NICEC_JAR}:${CLASSPATH} fi if [ $experimental = true ]; then *************** *** 93,97 **** export CLASSPATH ! system_args="--runtime=${NICEC}" gcj="`which gcj 2>/dev/null`" --- 95,99 ---- export CLASSPATH ! system_args="--runtime=${NICEC_JAR}" gcj="`which gcj 2>/dev/null`" |
From: <bo...@us...> - 2003-04-19 13:44:49
|
Update of /cvsroot/nice/Nice/bin In directory sc8-pr-cvs1:/tmp/cvs-serv27152/bin Added Files: nicec.bootstrap Log Message: Added the possibility to rely on external/nice-bootstrap.jar instead of a standalone bootstrap compiler, to allow a self-contained bootstrapping process. --- NEW FILE: nicec.bootstrap --- #! /bin/sh ### Wrapper for nicec that uses an existing nice.jar for bootstrapping NICEC_JAR="external/nice-bootstrap.jar" if [ -r "${NICEC_JAR}" ]; then export NICEC_JAR echo $NICEC_JAR ./bin/nicec "$@" elif NICEC="`which nicec`"; then ${NICEC} "$@" else echo "An installed version of Nice is needed for bootstrapping." exit 1 fi |
From: <bo...@us...> - 2003-04-19 13:44:49
|
Update of /cvsroot/nice/Nice In directory sc8-pr-cvs1:/tmp/cvs-serv27152 Modified Files: Makefile Log Message: Added the possibility to rely on external/nice-bootstrap.jar instead of a standalone bootstrap compiler, to allow a self-contained bootstrapping process. Index: Makefile =================================================================== RCS file: /cvsroot/nice/Nice/Makefile,v retrieving revision 1.114 retrieving revision 1.115 diff -C2 -d -r1.114 -r1.115 *** Makefile 15 Apr 2003 16:02:09 -0000 1.114 --- Makefile 19 Apr 2003 13:44:46 -0000 1.115 *************** *** 24,28 **** NICEC_ARGS= --exclude-runtime ! NICEC=CLASSPATH="${TOP}/classes" JAVA="${java}" nicec ${NICEC_ARGS} -d "${TOP}/classes.old" --sourcepath="${TOP}/stdlib.old:${TOP}/stdlib:${TOP}/src.old:${TOP}/src" --classpath="${TOP}/classes" NICEC1=JAVA="${java}" ${TOP}/bin/nicec ${NICEC_ARGS} -d "${TOP}/classes" --sourcepath="${TOP}/stdlib:${TOP}/src" --- 24,28 ---- NICEC_ARGS= --exclude-runtime ! NICEC=CLASSPATH="${TOP}/classes" JAVA="${java}" ./bin/nicec.bootstrap ${NICEC_ARGS} -d "${TOP}/classes.old" --sourcepath="${TOP}/stdlib.old:${TOP}/stdlib:${TOP}/src.old:${TOP}/src" --classpath="${TOP}/classes" NICEC1=JAVA="${java}" ${TOP}/bin/nicec ${NICEC_ARGS} -d "${TOP}/classes" --sourcepath="${TOP}/stdlib:${TOP}/src" |
From: <bo...@us...> - 2003-04-19 13:39:14
|
Update of /cvsroot/nice/Nice/debian In directory sc8-pr-cvs1:/tmp/cvs-serv25498/debian Modified Files: rules Log Message: Lintian says: dh_undocumented: This program does nothing and should no longer be used. Index: rules =================================================================== RCS file: /cvsroot/nice/Nice/debian/rules,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** rules 30 May 2002 11:11:42 -0000 1.4 --- rules 19 Apr 2003 13:39:11 -0000 1.5 *************** *** 66,70 **** dh_installman dh_installinfo - dh_undocumented dh_installchangelogs dh_link --- 66,69 ---- |
From: <bo...@us...> - 2003-04-19 13:35:54
|
Update of /cvsroot/nice/Nice/testsuite/compiler/classes/constructors In directory sc8-pr-cvs1:/tmp/cvs-serv24555/testsuite/compiler/classes/constructors Modified Files: compilation.testsuite Log Message: Makes sure that class constructors are generated in the bytecode, even when they are not used, and even in a client package regenerating the class. This is important, since Java code could rely on them. Index: compilation.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/classes/constructors/compilation.testsuite,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** compilation.testsuite 4 Mar 2003 16:50:17 -0000 1.2 --- compilation.testsuite 19 Apr 2003 13:35:49 -0000 1.3 *************** *** 20,21 **** --- 20,46 ---- /// Toplevel class A { String name = ""; } + + /// PASS + /* Checks that constructors are generated even when they are not used. + This is important, since Java code could rely on them. + */ + /// package a + /// Toplevel + class A extends Error { } + + /// package b import a + Class.forName("a.A").getDeclaredConstructor([ String.class ]); + + /// PASS + /* Checks that constructors are generated even when they are not used. + This is important, since Java code could rely on them. + */ + /// package a + /// Toplevel + class A extends Error { } + + /// package b import a + Class.forName("a.A").getDeclaredConstructor([ String.class ]); + /// Toplevel + class B extends A {} + equals(this@A, that@B) = true; |
From: <bo...@us...> - 2003-04-19 13:35:54
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv24555/src/bossa/syntax Modified Files: NiceClass.java Log Message: Makes sure that class constructors are generated in the bytecode, even when they are not used, and even in a client package regenerating the class. This is important, since Java code could rely on them. Index: NiceClass.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceClass.java,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** NiceClass.java 18 Apr 2003 14:50:21 -0000 1.42 --- NiceClass.java 19 Apr 2003 13:35:50 -0000 1.43 *************** *** 441,444 **** --- 441,450 ---- // but before compilation. createFields(); + + // This needs to be done even if we don't recompile, + // since classes are always regenerated. + if (constructorMethod != null) + for (int i = 0; i < constructorMethod.length; i++) + constructorMethod[i].getCode(); } *************** *** 452,459 **** ((ToplevelFunction) child).compile(); } - - if (constructorMethod != null) - for (int i = 0; i < constructorMethod.length; i++) - constructorMethod[i].getCode(); } --- 458,461 ---- |
From: <bo...@us...> - 2003-04-19 08:54:23
|
Update of /cvsroot/nice/Nice/debian In directory sc8-pr-cvs1:/tmp/cvs-serv13034/debian Modified Files: control Log Message: Fixed lintian warnings. Index: control =================================================================== RCS file: /cvsroot/nice/Nice/debian/control,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** control 24 Apr 2002 22:35:42 -0000 1.10 --- control 19 Apr 2003 08:54:19 -0000 1.11 *************** *** 3,8 **** Priority: optional Maintainer: Daniel Bonniot <bo...@us...> ! Build-Depends: debhelper (>> 3.0.0), java-compiler, nice, groff ! Standards-Version: 3.5.2 Package: nice --- 3,8 ---- Priority: optional Maintainer: Daniel Bonniot <bo...@us...> ! Build-Depends-Indep: debhelper (>> 3.0.0), java-compiler, nice, groff ! Standards-Version: 3.5.9 Package: nice *************** *** 10,14 **** Depends: java-virtual-machine Suggests: emacsen ! Description: Extension of Java with parametric types, multi-methods, and more. Nice is a new object-oriented programming language. . --- 10,14 ---- Depends: java-virtual-machine Suggests: emacsen ! Description: Extension of Java with parametric types, multi-methods, and more Nice is a new object-oriented programming language. . |
From: <bo...@us...> - 2003-04-19 08:52:13
|
Update of /cvsroot/nice/Nice/debian In directory sc8-pr-cvs1:/tmp/cvs-serv12474/debian Modified Files: copyright Log Message: Fixed lintian "Author(s)" warning. Index: copyright =================================================================== RCS file: /cvsroot/nice/Nice/debian/copyright,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** copyright 18 Dec 2001 15:34:25 -0000 1.1 --- copyright 19 Apr 2003 08:52:10 -0000 1.2 *************** *** 4,10 **** It was downloaded from http://nice.sourceforge.net ! Upstream Author(s): Daniel Bonniot <bo...@us...> ! This software is copyright (c) 2001 by Daniel Bonniot You are free to distribute this software under the terms of --- 4,10 ---- It was downloaded from http://nice.sourceforge.net ! Upstream Author: Daniel Bonniot <bo...@us...> ! This software is copyright (c) 2003 by Daniel Bonniot You are free to distribute this software under the terms of |
From: <bo...@us...> - 2003-04-19 08:47:31
|
Update of /cvsroot/nice/Nice/debian In directory sc8-pr-cvs1:/tmp/cvs-serv11113/debian Modified Files: changelog Log Message: Closed 0.7.9 Index: changelog =================================================================== RCS file: /cvsroot/nice/Nice/debian/changelog,v retrieving revision 1.149 retrieving revision 1.150 diff -C2 -d -r1.149 -r1.150 *** changelog 18 Apr 2003 15:37:06 -0000 1.149 --- changelog 19 Apr 2003 08:47:28 -0000 1.150 *************** *** 10,14 **** have an invalid bytecode format. ! -- nice (0.7.8) unstable; urgency=low --- 10,14 ---- have an invalid bytecode format. ! -- Daniel Bonniot <bo...@us...> Sat, 19 Apr 2003 10:40:02 +0200 nice (0.7.8) unstable; urgency=low |
From: <bo...@us...> - 2003-04-18 17:19:57
|
Update of /cvsroot/nice/Nice/web In directory sc8-pr-cvs1:/tmp/cvs-serv27029/web Modified Files: index.xml Log Message: Added section about contracts. Index: index.xml =================================================================== RCS file: /cvsroot/nice/Nice/web/index.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** index.xml 11 Oct 2002 09:22:13 -0000 1.4 --- index.xml 18 Apr 2003 17:19:54 -0000 1.5 *************** *** 111,114 **** --- 111,124 ---- </varlistentry> + <varlistentry><term>Contracts and assertions</term><listitem><para> + Contracts can be attached to methods, to better describe their specification + and detect illegal uses automatically at runtime, in debug mode. + Contracts and assertions can be disabled, in which case they cause + no slow down of the running program. Furthermore, they can be used on any + version of the JVM, even prior to 1.4. + </para> + </listitem> + </varlistentry> + </variablelist> |
From: <bo...@us...> - 2003-04-18 15:39:00
|
Update of /cvsroot/nice/Nice/web In directory sc8-pr-cvs1:/tmp/cvs-serv12271/web Modified Files: manual.xml Log Message: Fixed an example which must have been incorrect. Index: manual.xml =================================================================== RCS file: /cvsroot/nice/Nice/web/manual.xml,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** manual.xml 22 Feb 2003 11:28:42 -0000 1.13 --- manual.xml 18 Apr 2003 15:38:55 -0000 1.14 *************** *** 1246,1250 **** <para> There is also a notation for the same class as the declaring class ! of a method: <type>alike</type>. For instance, the following class <literal>Foo</literal> declares a method <literal>copy</literal>, such that --- 1246,1250 ---- <para> There is also a notation for the same class as the declaring class ! of a method: <literal>alike</literal>. For instance, the following class <literal>Foo</literal> declares a method <literal>copy</literal>, such that *************** *** 1270,1274 **** } ! copy(b@Bar) = new Bar(value: b.value, id: generateNewId()); }</programlisting> </example> --- 1270,1274 ---- } ! copy(b#Bar) = new Bar(value: b.value, id: generateNewId()); }</programlisting> </example> |
From: <bo...@us...> - 2003-04-18 15:37:10
|
Update of /cvsroot/nice/Nice/debian In directory sc8-pr-cvs1:/tmp/cvs-serv11377/debian Modified Files: changelog Log Message: Compilation does not fail anymore if some classes on the classpath have an invalid bytecode format. Index: changelog =================================================================== RCS file: /cvsroot/nice/Nice/debian/changelog,v retrieving revision 1.148 retrieving revision 1.149 diff -C2 -d -r1.148 -r1.149 *** changelog 18 Apr 2003 14:50:29 -0000 1.148 --- changelog 18 Apr 2003 15:37:06 -0000 1.149 *************** *** 7,10 **** --- 7,12 ---- equals(that@A) = this.x == that.x; } + * Compilation does not fail anymore if some classes on the classpath + have an invalid bytecode format. -- |
From: <bo...@us...> - 2003-04-18 15:14:52
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1:/tmp/cvs-serv360/stdlib/nice/lang Modified Files: numeric.nice Log Message: Added the `double` operator, similarly to the other primitive type operators. This one does no narrowing, but allows to lose precision over the type of an expression, which can be necessary to resolve an ambiguity. Index: numeric.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/numeric.nice,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** numeric.nice 6 Dec 2002 12:50:19 -0000 1.22 --- numeric.nice 18 Apr 2003 15:14:48 -0000 1.23 *************** *** 26,31 **** // Narrowing primitive conversions float float(double d) = inline nice.lang.inline.Nop(); - int int(double d) = inline nice.lang.inline.Nop(); short short(double d) = inline nice.lang.inline.Nop(); --- 26,31 ---- // Narrowing primitive conversions + double double(double d) = inline nice.lang.inline.Nop(); float float(double d) = inline nice.lang.inline.Nop(); int int(double d) = inline nice.lang.inline.Nop(); short short(double d) = inline nice.lang.inline.Nop(); |
From: <bo...@us...> - 2003-04-18 15:14:51
|
Update of /cvsroot/nice/Nice/testsuite/compiler/expressions/operators/numeric In directory sc8-pr-cvs1:/tmp/cvs-serv360/testsuite/compiler/expressions/operators/numeric Modified Files: conversion.testsuite Log Message: Added the `double` operator, similarly to the other primitive type operators. This one does no narrowing, but allows to lose precision over the type of an expression, which can be necessary to resolve an ambiguity. Index: conversion.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/expressions/operators/numeric/conversion.testsuite,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** conversion.testsuite 6 Dec 2002 12:49:56 -0000 1.2 --- conversion.testsuite 18 Apr 2003 15:14:47 -0000 1.3 *************** *** 43,44 **** --- 43,51 ---- // A double value too small for float underflows to zero: assert float(1e-50) == 0; + + /// PASS + int i = 0; + foo(double(i)); + /// Toplevel + void foo(int) {} + void foo(double) {} |
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv18316/src/bossa/syntax Modified Files: VarScope.java SuperExp.java NiceClass.java Module.java MethodDeclaration.java MethodBodyDefinition.java JavaMethod.java ClassDefinition.java Log Message: Allow implementations of native methods to dispatch on all their arguments. Index: VarScope.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/VarScope.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** VarScope.java 26 Sep 2002 16:21:39 -0000 1.16 --- VarScope.java 18 Apr 2003 14:50:20 -0000 1.17 *************** *** 22,26 **** @author Daniel Bonniot (d.b...@ma...) */ ! final class VarScope { public VarScope(VarScope outer) --- 22,26 ---- @author Daniel Bonniot (d.b...@ma...) */ ! public final class VarScope { public VarScope(VarScope outer) Index: SuperExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/SuperExp.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SuperExp.java 17 Sep 2002 16:30:56 -0000 1.5 --- SuperExp.java 18 Apr 2003 14:50:20 -0000 1.6 *************** *** 41,56 **** MethodDeclaration decl = currentMethod.getDeclaration(); gnu.expr.Expression code; ! if (decl instanceof NiceMethod) ! superAlternative = getSuper((NiceMethod) decl); ! else ! getSuper((JavaMethod) decl); } MethodBodyDefinition currentMethod; Alternative superAlternative = null; - MethodBodyDefinition superImplementation = null; Method superMethod = null; ! private Alternative getSuper(NiceMethod decl) { Alternative superAlt = null; --- 41,52 ---- MethodDeclaration decl = currentMethod.getDeclaration(); gnu.expr.Expression code; ! superAlternative = getSuper(decl); } MethodBodyDefinition currentMethod; Alternative superAlternative = null; Method superMethod = null; ! private Alternative getSuper(MethodDeclaration decl) { Alternative superAlt = null; *************** *** 78,115 **** } ! if (superAlt == null) ! throw User.error(this, "There is no super implementation to call"); ! return superAlt; } private void getSuper(JavaMethod decl) { - for (java.util.Iterator i = decl.getImplementations(); - i.hasNext();) - { - MethodBodyDefinition impl = (MethodBodyDefinition) i.next(); - if (leq(impl, currentMethod)) - continue; - - if (superImplementation == null || leq(impl, superImplementation)) - superImplementation = impl; - } - - Method thisMethod = decl.reflectMethod; Type firstArg = nice.tools.code.Types.get(currentMethod.firstArgument()); if (! (firstArg instanceof ClassType)) throw User.error(this, "The first argument of this method is not a class"); ! ClassType superClass = ((ClassType) firstArg).getSuperclass(); ! if (superClass != null) ! { ! superMethod = superClass.getMethod(thisMethod.getName(), thisMethod.getParameterTypes()); ! if (superMethod != null) ! return; ! } throw User.error(this, "There is no super implementation to call"); } private boolean leq(MethodBodyDefinition a, MethodBodyDefinition b) { --- 74,112 ---- } ! if (superAlt != null) ! return superAlt; ! if (decl instanceof JavaMethod) ! { ! getSuper((JavaMethod) decl); ! return null; ! } ! else ! throw User.error(this, "There is no super implementation to call"); } private void getSuper(JavaMethod decl) { Type firstArg = nice.tools.code.Types.get(currentMethod.firstArgument()); if (! (firstArg instanceof ClassType)) throw User.error(this, "The first argument of this method is not a class"); ! superMethod = getImplementationAbove(decl, (ClassType) firstArg); ! if (superMethod != null) ! return; throw User.error(this, "There is no super implementation to call"); } + public static Method getImplementationAbove(JavaMethod decl, ClassType firstArg) + { + Method thisMethod = decl.reflectMethod; + ClassType superClass = firstArg.getSuperclass(); + if (superClass == null) + return null; + + return superClass.getMethod(thisMethod.getName(), + thisMethod.getParameterTypes()); + } + private boolean leq(MethodBodyDefinition a, MethodBodyDefinition b) { *************** *** 137,158 **** else { ! TypeConstructor superTC; ! if (superImplementation != null) ! superTC = superImplementation.firstArgument(); ! else { ! superTC = findTCforClass ! (currentMethod.firstArgument(), superMethod.getDeclaringClass()); ! if (superTC == null) ! { ! // This probably means that super comes from a special ! // class that is not in the Nice hierarchy, like ! // java.lang.Object (because of variances). ! // Our safe bet is to assert that the argument is ! // above Object ! superTC = JavaClasses.object ! (currentMethod.firstArgument().variance.arity()); ! } } --- 134,151 ---- else { ! TypeConstructor superTC = findTCforClass ! (currentMethod.firstArgument(), ! superMethod.getDeclaringClass()); ! ! if (superTC == null) { ! // This probably means that super comes from a special ! // class that is not in the Nice hierarchy, like ! // java.lang.Object (because of variances). ! // Our safe bet is to assert that the argument is ! // above Object ! superTC = JavaClasses.object ! (currentMethod.firstArgument().variance.arity()); } *************** *** 212,216 **** // It does not matter which method is called (the super method or // the base method), a call to super is emited. ! code = new QuoteExp(PrimProcedure.specialCall(superMethod)); return new gnu.expr.ApplyExp(code, currentMethod.compiledArguments()); --- 205,210 ---- // It does not matter which method is called (the super method or // the base method), a call to super is emited. ! code = ((NiceClass) ClassDefinition.get(currentMethod.firstArgument()).implementation). ! callSuperMethod(superMethod); return new gnu.expr.ApplyExp(code, currentMethod.compiledArguments()); Index: NiceClass.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceClass.java,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** NiceClass.java 23 Feb 2003 11:04:22 -0000 1.41 --- NiceClass.java 18 Apr 2003 14:50:21 -0000 1.42 *************** *** 270,281 **** private void prepareCodeGeneration() { ! // The module will lookup the existing class if it is already compiled ! // and call createClassExp if not. ! classe = definition.module.getClassExp(this); } ! gnu.expr.ClassExp classe; ! ! public gnu.expr.ClassExp createClassExp() { gnu.expr.ClassExp classe = new gnu.expr.ClassExp(); --- 270,284 ---- private void prepareCodeGeneration() { ! /* ! We always generate a new ClassExp object, even for classes from ! already compiled packages. The reason is that we might need to ! add methods for the multiple dispatch of java methods in the class ! (and maybe for adding fields, or optimizing the dispatch of Nice ! methods in the future). ! */ ! classe = createClassExp(); } ! private gnu.expr.ClassExp createClassExp() { gnu.expr.ClassExp classe = new gnu.expr.ClassExp(); *************** *** 288,292 **** } ! gnu.expr.ClassExp getClassExp() { return classe; --- 291,297 ---- } ! gnu.expr.ClassExp classe; ! ! public gnu.expr.ClassExp getClassExp() { return classe; *************** *** 507,513 **** /** This native method is redefined for this Nice class. */ ! void addJavaMethod(gnu.expr.LambdaExp method) { ! classe.addMethod(method); } --- 512,549 ---- /** This native method is redefined for this Nice class. */ ! public gnu.expr.Expression addJavaMethod(gnu.expr.LambdaExp method) { ! return classe.addMethod(method); ! } ! ! public gnu.expr.LambdaExp createJavaMethod(String name, ! gnu.bytecode.Method likeMethod, ! gnu.expr.Expression[] params) ! { ! gnu.expr.LambdaExp lambda = ! Gen.createMemberMethod ! (name, ! getClassExp().getType(), ! likeMethod.getParameterTypes(), ! likeMethod.getReturnType(), ! params); ! return lambda; ! } ! ! /** ! Returns an expression to call a super method from outside a class method. ! ! This is needed because the JVM restricts call to a specific implementation ! to occur inside a method of the same class. So this generates a stub class ! method that calls the desired super method, and return a reference to this ! stub. ! */ ! gnu.expr.Expression callSuperMethod(gnu.bytecode.Method superMethod) ! { ! gnu.expr.Expression[] params = new gnu.expr.Expression[superMethod.getParameterTypes().length + 1]; ! gnu.expr.LambdaExp lambda = createJavaMethod("$super$" + superMethod.getName(), superMethod, params); ! Gen.setMethodBody(lambda, ! new gnu.expr.ApplyExp(new gnu.expr.QuoteExp(gnu.expr.PrimProcedure.specialCall(superMethod)), params)); ! return addJavaMethod(lambda); } Index: Module.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Module.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Module.java 17 Jun 2002 21:33:11 -0000 1.12 --- Module.java 18 Apr 2003 14:50:23 -0000 1.13 *************** *** 33,37 **** gnu.expr.Expression getDispatchMethod(NiceMethod def); gnu.expr.Expression lookupPackageMethod(String methodName, String type); - gnu.expr.ClassExp getClassExp(NiceClass def); gnu.expr.ReferenceExp addMethod(gnu.expr.LambdaExp method, boolean packageMethod); --- 33,36 ---- Index: MethodDeclaration.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodDeclaration.java,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** MethodDeclaration.java 23 Mar 2003 23:03:03 -0000 1.37 --- MethodDeclaration.java 18 Apr 2003 14:50:23 -0000 1.38 *************** *** 237,241 **** MethodDeclaration.Symbol getSymbol() { return symbol; } ! class Symbol extends FunSymbol { Symbol(LocatedString name, bossa.syntax.Constraint constraint, --- 237,241 ---- MethodDeclaration.Symbol getSymbol() { return symbol; } ! public class Symbol extends FunSymbol { Symbol(LocatedString name, bossa.syntax.Constraint constraint, *************** *** 271,275 **** } ! MethodDeclaration getDefinition() { return MethodDeclaration.this; --- 271,275 ---- } ! public MethodDeclaration getDefinition() { return MethodDeclaration.this; *************** *** 300,303 **** --- 300,309 ---- * Code generation ****************************************************************/ + + /** @return a string that uniquely represents this method */ + public String getFullName() + { + return "NONE"; + } private gnu.expr.Expression code; Index: MethodBodyDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodBodyDefinition.java,v retrieving revision 1.115 retrieving revision 1.116 diff -C2 -d -r1.115 -r1.116 *** MethodBodyDefinition.java 1 Apr 2003 20:25:01 -0000 1.115 --- MethodBodyDefinition.java 18 Apr 2003 14:50:23 -0000 1.116 *************** *** 136,156 **** this.declaration = d; - // Overriding a mono-method can currently not dispatch on other args if (d instanceof JavaMethod) ! { ! for (int i = 1; i < formals.length; i++) ! if (!(formals[i].atAny())) ! User.error(this, this + " is a native method. Dispatch can only occur on the first argument"); ! ! ((JavaMethod) d).addImplementation(this); ! } ! else if (d instanceof NiceMethod) ! // Register this alternative for the link test ! alternative = new bossa.link.SourceAlternative(this); ! else User.error(this, "Implementations can only be made for methods, but " + d.getName() + " is a function.\nIt was defined at:\n" + d.location()); if (d.isMain()) User.warning(this, "This syntax for the main function is deprecated.\nPlease use instead the following:\n\nvoid main(String[] args)\n{\n ...\n}"); --- 136,149 ---- this.declaration = d; if (d instanceof JavaMethod) ! ((JavaMethod) d).registerForDispatch(); ! else if (! (d instanceof NiceMethod)) User.error(this, "Implementations can only be made for methods, but " + d.getName() + " is a function.\nIt was defined at:\n" + d.location()); + // Register this alternative for the link test + alternative = new bossa.link.SourceAlternative(this); + if (d.isMain()) User.warning(this, "This syntax for the main function is deprecated.\nPlease use instead the following:\n\nvoid main(String[] args)\n{\n ...\n}"); *************** *** 476,485 **** { if (ref == null) ! { ! if (declaration instanceof NiceMethod) ! ref = compile((NiceMethod) declaration); ! else ! compile((JavaMethod) declaration); ! } return ref; --- 469,473 ---- { if (ref == null) ! ref = createRef(); return ref; *************** *** 495,499 **** } ! private gnu.expr.ReferenceExp compile (NiceMethod definition) { createMethod(name.toString(), false); --- 483,487 ---- } ! private gnu.expr.ReferenceExp createRef () { createMethod(name.toString(), false); *************** *** 501,505 **** compiledMethod.addBytecodeAttribute ! (new MiscAttr("definition", definition.getFullName().getBytes())); compiledMethod.addBytecodeAttribute (new MiscAttr("patterns", --- 489,493 ---- compiledMethod.addBytecodeAttribute ! (new MiscAttr("definition", declaration.getFullName().getBytes())); compiledMethod.addBytecodeAttribute (new MiscAttr("patterns", *************** *** 512,535 **** { return formals[0].tc; - } - - NiceClass declaringClass() - { - ClassDefinition def = ClassDefinition.get(firstArgument()); - - if (def == null || ! (def.implementation instanceof NiceClass)) - throw User.error(this, declaration + " is a native method.\n" + - "It can not be overriden because " + formals[0].tc + - " is not a class defined in Nice"); - - return (NiceClass) def.implementation; - } - - private void compile (JavaMethod declaration) - { - createMethod(declaration.getName().toString(), true); - - // Compile as a method in the class of the first argument - declaringClass().addJavaMethod(compiledMethod); } --- 500,503 ---- Index: JavaMethod.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/JavaMethod.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** JavaMethod.java 10 Dec 2002 19:10:52 -0000 1.24 --- JavaMethod.java 18 Apr 2003 14:50:24 -0000 1.25 *************** *** 28,32 **** @author Daniel Bonniot (d.b...@ma...) */ ! class JavaMethod extends MethodDeclaration { JavaMethod(LocatedString name, Constraint constraint, --- 28,32 ---- @author Daniel Bonniot (d.b...@ma...) */ ! public class JavaMethod extends MethodDeclaration { JavaMethod(LocatedString name, Constraint constraint, *************** *** 72,75 **** --- 72,88 ---- ****************************************************************/ + public static final String fullNamePrefix = "JAVA:"; + + /** @return a string that uniquely represents this method */ + public String getFullName() + { + return fullNamePrefix + name + ':' + getType(); + } + + public final LambdaExp getLambda() + { + return nice.tools.code.Gen.dereference(getCode()); + } + Method reflectMethod; *************** *** 98,111 **** ****************************************************************/ ! Iterator getImplementations() ! { ! return implementations.iterator(); ! } ! ! private LinkedList implementations = new LinkedList(); ! void addImplementation(MethodBodyDefinition impl) { ! implementations.add(impl); } } --- 111,123 ---- ****************************************************************/ ! private boolean registered; ! public void registerForDispatch() { ! if (registered) ! return; ! ! bossa.link.Dispatch.register(this); ! registered = true; } } Index: ClassDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/ClassDefinition.java,v retrieving revision 1.87 retrieving revision 1.88 diff -C2 -d -r1.87 -r1.88 *** ClassDefinition.java 19 Feb 2003 18:33:54 -0000 1.87 --- ClassDefinition.java 18 Apr 2003 14:50:24 -0000 1.88 *************** *** 445,449 **** public static void reset() { tcToClassDef = new HashMap(); } ! static final ClassDefinition get(TypeConstructor tc) { return (ClassDefinition) tcToClassDef.get(tc); --- 445,449 ---- public static void reset() { tcToClassDef = new HashMap(); } ! public static final ClassDefinition get(TypeConstructor tc) { return (ClassDefinition) tcToClassDef.get(tc); *************** *** 665,668 **** --- 665,673 ---- ClassImplementation implementation; + + public ClassImplementation getImplementation() + { + return implementation; + } } |
From: <bo...@us...> - 2003-04-18 14:51:02
|
Update of /cvsroot/nice/Nice/src/bossa/modules In directory sc8-pr-cvs1:/tmp/cvs-serv18316/src/bossa/modules Modified Files: Package.java Log Message: Allow implementations of native methods to dispatch on all their arguments. Index: Package.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Package.java,v retrieving revision 1.85 retrieving revision 1.86 diff -C2 -d -r1.85 -r1.86 *** Package.java 4 Mar 2003 16:50:20 -0000 1.85 --- Package.java 18 Apr 2003 14:50:25 -0000 1.86 *************** *** 29,33 **** @version $Date$ ! @author Daniel Bonniot (d.b...@ma...) */ public class Package implements mlsub.compilation.Module, Located, bossa.syntax.Module --- 29,33 ---- @version $Date$ ! @author Daniel Bonniot (bo...@us...) */ public class Package implements mlsub.compilation.Module, Located, bossa.syntax.Module *************** *** 154,158 **** method != null; method = method.getNext()) ! bossa.link.ImportedAlternative.read(source.getBytecode(), method); } --- 154,159 ---- method != null; method = method.getNext()) ! bossa.link.ImportedAlternative.read(source.getBytecode(), method, ! location()); } *************** *** 553,557 **** { thisPkg.addClass(classe); - classe.outer = getImplementationClass(); } --- 554,557 ---- *************** *** 750,768 **** ClassExp classe = packageMethod ? getImplementationClass() : dispatchClass; return classe.addMethod(method); - } - - public ClassExp getClassExp(NiceClass def) - { - if (compiling()) - return def.createClassExp(); - - String name = def.getName().toString(); - ClassType classe = source.readClass(name); - if (classe == null) - Internal.error("Compiled class " + def + " was not found"); - - Type.registerTypeForName(name, classe); - - return new ClassExp(classe); } --- 750,753 ---- |
From: <bo...@us...> - 2003-04-18 14:50:55
|
Update of /cvsroot/nice/Nice/src/gnu/expr In directory sc8-pr-cvs1:/tmp/cvs-serv18316/src/gnu/expr Modified Files: LambdaExp.java ApplyExp.java Log Message: Allow implementations of native methods to dispatch on all their arguments. Index: LambdaExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/expr/LambdaExp.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** LambdaExp.java 25 Nov 2002 18:58:30 -0000 1.15 --- LambdaExp.java 18 Apr 2003 14:50:19 -0000 1.16 *************** *** 367,371 **** : parent.closureEnv; if (isClassMethod()) ! closureEnv = declareThis(type); else if (parent.heapFrame == null && ! parent.getNeedsStaticLink() && ! (parent instanceof ModuleExp)) --- 367,371 ---- : parent.closureEnv; if (isClassMethod()) ! /*closureEnv =*/ declareThis(type); else if (parent.heapFrame == null && ! parent.getNeedsStaticLink() && ! (parent instanceof ModuleExp)) *************** *** 375,379 **** Method primMethod = getMainMethod(); if (! primMethod.getStaticFlag()) ! closureEnv = declareThis(primMethod.getDeclaringClass()); else { --- 375,379 ---- Method primMethod = getMainMethod(); if (! primMethod.getStaticFlag()) ! /*closureEnv =*/ declareThis(primMethod.getDeclaringClass()); else { *************** *** 436,440 **** else { ! code.emitLoad(curLambda.closureEnv); LambdaExp parent = curLambda.outerLambda(); while (parent != this) --- 436,443 ---- else { ! if (curLambda.closureEnv == null) ! code.emitPushThis(); ! else ! code.emitLoad(curLambda.closureEnv); LambdaExp parent = curLambda.outerLambda(); while (parent != this) *************** *** 756,760 **** mflags |= Access.ABSTRACT; if (! isStatic) ! closureEnv = declareThis(ctype); Type rtype --- 759,766 ---- mflags |= Access.ABSTRACT; if (! isStatic) ! if (isClassMethod()) ! declareThis(ctype); ! else ! closureEnv = declareThis(ctype); Type rtype Index: ApplyExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/expr/ApplyExp.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ApplyExp.java 20 Mar 2003 14:58:23 -0000 1.8 --- ApplyExp.java 18 Apr 2003 14:50:19 -0000 1.9 *************** *** 203,206 **** --- 203,208 ---- // is finished. Perhaps InlineCalls would work? FIXME String msg = null; + if (func_lambda.isClassMethod()) + args_length--; if (args_length < func_lambda.min_args) msg = "too few args for "; *************** *** 232,236 **** boolean varArgs = func_lambda.restArgType() != null; PrimProcedure.compileArgs(args, ! extraArg > 0 ? Type.void_type : null, argTypes, varArgs, func_name, func_lambda, comp); --- 234,238 ---- boolean varArgs = func_lambda.restArgType() != null; PrimProcedure.compileArgs(args, ! func_lambda.isClassMethod() ? (Type) method.getDeclaringClass() : extraArg > 0 ? Type.void_type : null, argTypes, varArgs, func_name, func_lambda, comp); |
From: <bo...@us...> - 2003-04-18 14:50:54
|
Update of /cvsroot/nice/Nice/testsuite/compiler/methods In directory sc8-pr-cvs1:/tmp/cvs-serv18316/testsuite/compiler/methods Modified Files: super.testsuite nativeOverride.testsuite Log Message: Allow implementations of native methods to dispatch on all their arguments. Index: super.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/methods/super.testsuite,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** super.testsuite 4 Mar 2003 16:50:11 -0000 1.4 --- super.testsuite 18 Apr 2003 14:50:17 -0000 1.5 *************** *** 151,154 **** --- 151,189 ---- /// PASS + /// COMMENT super defined in an imported package for a java method. + /// package a + /// Toplevel + class C + { + toString() = "C"; + } + + /// package b import a + assert new D().toString().equals("CD"); + /// Toplevel + class D extends C + { + toString() = super + "D"; + } + + /// FAIL + /// COMMENT super defined in an imported package for a java method. + /// package a + /// Toplevel + abstract class C {} + abstract class D extends C {} + + equals(x@C, y@D) = true; + equals(x@D, y@C) = true; + + + /// package b import a + /// Toplevel + abstract class E extends D + { + equals(x@D) = /*/// FAIL HERE */ super; // This is ambiguous. + } + + /// PASS assert (new C().foo() == 1); /// Toplevel Index: nativeOverride.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/methods/nativeOverride.testsuite,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** nativeOverride.testsuite 16 Apr 2003 16:54:28 -0000 1.2 --- nativeOverride.testsuite 18 Apr 2003 14:50:18 -0000 1.3 *************** *** 21,22 **** --- 21,187 ---- toString() = (["A"].map(String s => s + "."))[0].toString(); } + + /// PASS + assert new A(x: 1).equals(new A(x: 1)); + + /// Toplevel + class A + { + int x; + + equals(that@A) = this.x == that.x; + } + + /// PASS + assert ! new B(x: 1).equals(new A()); + assert new B(x: 1).equals(new B(x: 1)); + + /// Toplevel + class A {} + + class B extends A + { + int x; + + equals(that@B) = this.x == that.x; + } + + /// PASS + assert new B(x: 1).equals(new A()); + + /// Toplevel + class A { + equals(that@A) = true; + } + + class B extends A + { + int x; + + equals(that@B) = this.x == that.x; + } + + /// PASS + assert new A(x: 1).equals(new A(x: 1)); + assert new A(x: 1).equals(new B(x: 1, y: 0)); + assert ! new A(x: 1).equals(new B(x: 1, y: 2)); + + /// Toplevel + class A + { + int x; + + equals(that@A) = this.x == that.x; + equals(that@B) = this.x == that.x && that.y == 0; + } + + class B extends A + { + int y; + + equals(that@B) = this.x == that.x && this.y == that.y; + } + + /// PASS + /// package a + /// Toplevel + class A + { + int x; + + equals(that@A) = this.x == that.x; + } + + /// package b import a + assert new A(x: 1).equals(new A(x: 1)); + + /// PASS + /// package a + /// Toplevel + class A + { + int x; + + equals(that) = false; + equals(that@A) = this.x == that.x; + } + + /// package b import a + assert new A(x: 1).equals(new A(x: 1)); + + /// PASS + /// package a + /// Toplevel + class A + { + int x; + + equals(that@A) = this.x == that.x; + } + + /// package b import a + assert ! new A(x: 1).equals(new B(x: 1)); + /// Toplevel + class B extends A + { + equals(that@A) = super; + } + equals(this@A, that@B) = false; + equals(this@B, that@B) = true; + + /// PASS + /// package a + /// Toplevel + class A + { + int x; + + equals(that@A) = this.x == that.x; + } + + boolean equals(String dummy1, boolean dummy2) = false; + + /// package b import a + assert new A(x: 1).equals(new A(x: 1)); + + /// FAIL + ///Toplevel + /*/// FAIL HERE */ toString(s@String) = ""; + + /// FAIL + /// COMMENT Ambiguity for equals(B,B) + /// Toplevel + class A + { + equals(that@B) = false; + } + + class B extends A + { + equals(that@A) = true; + } + + /// FAIL + /// Toplevel + class A implements Runnable + { + } + + class B extends A + { + run() {} + } + + /// FAIL + /// Toplevel + class A extends java.lang.Number + { + } + + class B extends A + { + doubleValue() = 0; + floatValue() = 0; + longValue() = 0; + intValue() = 0; + } |
From: <bo...@us...> - 2003-04-18 14:50:54
|
Update of /cvsroot/nice/Nice/src/nice/tools/code In directory sc8-pr-cvs1:/tmp/cvs-serv18316/src/nice/tools/code Modified Files: Gen.java Log Message: Allow implementations of native methods to dispatch on all their arguments. Index: Gen.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/code/Gen.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Gen.java 1 Apr 2003 20:25:07 -0000 1.10 --- Gen.java 18 Apr 2003 14:50:18 -0000 1.11 *************** *** 176,179 **** --- 176,235 ---- } + /** + Create a lambda expression to generate code for the method. + + @param args can be null if there are no arguments + @param member true iff this method is a non-static member of + the class in argTypes[0] + @param toplevel If the method can be called from foreign code. + This forces its generation even if it is + apparently never called. + **/ + public static LambdaExp createMemberMethod + (String bytecodeName, + Type receiver, + Type[] argTypes, + Type retType, + Expression[] params) + { + LambdaExp lexp = new LambdaExp(); + bytecodeName = nice.tools.code.Strings.escape(bytecodeName); + int arity = 1 + (argTypes == null ? 0 : argTypes.length); + + lexp.setReturnType(retType); + lexp.setName(bytecodeName); + lexp.min_args = lexp.max_args = arity - 1; + lexp.forceGeneration(); + lexp.setCanCall(true); + lexp.setClassMethod(true); + + // Parameters + for(int n = 0; n < arity; n++) + { + boolean isThis = n == 0; + String parameterName = "anonymous_" + n; + + gnu.expr.Declaration d; + if (isThis) + { + d = new Declaration(parameterName); + d.context = lexp; + d.setType(receiver); + params[n] = new ThisExp(d); + } + else + { + d = lexp.addDeclaration(parameterName); + d.setType(argTypes[n - 1]); + params[n] = new ReferenceExp(d); + } + d.noteValue(null); + d.setCanRead(true); + d.setCanWrite(true); + + } + return lexp; + } + public static void setMethodBody(LambdaExp method, Expression body) { |
From: <bo...@us...> - 2003-04-18 14:50:54
|
Update of /cvsroot/nice/Nice/web In directory sc8-pr-cvs1:/tmp/cvs-serv18316/web Modified Files: language.html Log Message: Allow implementations of native methods to dispatch on all their arguments. Index: language.html =================================================================== RCS file: /cvsroot/nice/Nice/web/language.html,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** language.html 25 Oct 2002 09:02:32 -0000 1.17 --- language.html 18 Apr 2003 14:50:16 -0000 1.18 *************** *** 147,159 **** <td> <blockquote> ! <pre>class Object ! { ! boolean equals(Object that) ! { ! return this == that; ! } ! } ! ! class Person extends Object { String name; --- 147,151 ---- <td> <blockquote> ! <pre>class Person { String name; *************** *** 174,182 **** <td> <blockquote> ! <pre><<font color="#B7860B">Any</font> T> <font color="#B7860B">boolean</font> <font color="#CD0000">equals</font>(T, T); ! ! <font color="#CD0000">equals</font>(o1, o2) = o1==o2; ! ! <font color="#0000EE">class</font> <font color="#CD0000">Person </font>{ <font color="#B7860B">String</font> <font color="#CD0000">name</font>; --- 166,170 ---- <td> <blockquote> ! <pre><font color="#0000EE">class</font> <font color="#CD0000">Person </font>{ <font color="#B7860B">String</font> <font color="#CD0000">name</font>; *************** *** 192,200 **** </table></center> ! <p>In the Nice version, the last <tt>equals</tt> alternative will be executed ! when both parameters are instance of class <tt>Person</tt>. So the type of the second argument is also known, and no manual <tt>instanceof</tt> and no cast are necessary (red parts of the java code). ! This job is sort of automatically done by the compiler for you. The code looks cleaner, it is simpler to understand, and it is automatically guaranteed that no runtime exception will occur --- 180,188 ---- </table></center> ! <p>In the Nice version, this implementation of <tt>equals</tt> will be executed ! when both parameters are instances of class <tt>Person</tt>. So the type of the second argument is also known, and no manual <tt>instanceof</tt> and no cast are necessary (red parts of the java code). ! This job is automatically done by the compiler for you. The code looks cleaner, it is simpler to understand, and it is automatically guaranteed that no runtime exception will occur |
Update of /cvsroot/nice/Nice/src/bossa/link In directory sc8-pr-cvs1:/tmp/cvs-serv18316/src/bossa/link Modified Files: SourceAlternative.java ImportedAlternative.java Dispatch.java Compilation.java Alternative.java Log Message: Allow implementations of native methods to dispatch on all their arguments. Index: SourceAlternative.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/SourceAlternative.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SourceAlternative.java 6 Nov 2002 09:56:26 -0000 1.1 --- SourceAlternative.java 18 Apr 2003 14:50:27 -0000 1.2 *************** *** 23,32 **** */ ! public class SourceAlternative extends Alternative { public SourceAlternative(MethodBodyDefinition implementation) { super(implementation.getDeclaration().getName().toString(), ! ((NiceMethod) implementation.getDeclaration()).getFullName(), implementation.getPatterns()); this.implementation = implementation; --- 23,32 ---- */ ! public class SourceAlternative extends Alternative implements Located { public SourceAlternative(MethodBodyDefinition implementation) { super(implementation.getDeclaration().getName().toString(), ! implementation.getDeclaration().getFullName(), implementation.getPatterns()); this.implementation = implementation; *************** *** 34,37 **** --- 34,42 ---- private MethodBodyDefinition implementation; + + public Location location() + { + return implementation.location(); + } String printLocated() Index: ImportedAlternative.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/ImportedAlternative.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ImportedAlternative.java 17 Sep 2002 16:29:34 -0000 1.3 --- ImportedAlternative.java 18 Apr 2003 14:50:27 -0000 1.4 *************** *** 14,17 **** --- 14,20 ---- import bossa.syntax.Pattern; + import bossa.syntax.LocatedString; + import bossa.syntax.MethodDeclaration; + import bossa.syntax.JavaMethod; import nice.tools.code.*; *************** *** 20,23 **** --- 23,27 ---- import java.util.*; import bossa.util.*; + import bossa.util.Location; /** *************** *** 33,37 **** * When read from a bytecode file. */ ! public static void read(ClassType c, Method method) { MiscAttr attr = (MiscAttr) Attribute.get(method, "definition"); --- 37,41 ---- * When read from a bytecode file. */ ! public static void read(ClassType c, Method method, Location location) { MiscAttr attr = (MiscAttr) Attribute.get(method, "definition"); *************** *** 42,45 **** --- 46,51 ---- String fullName = new String(attr.data); + registerJavaMethod(fullName); + attr = (MiscAttr) Attribute.get(method, "patterns"); if (attr == null) *************** *** 71,86 **** new ImportedAlternative(method.getName(), fullName, (Pattern[]) patterns.toArray(new Pattern[patterns.size()]), ! new QuoteExp(new PrimProcedure(method))); } ! private ImportedAlternative(String name, String fullName, Pattern[] patterns, ! gnu.expr.Expression code) { super(name, fullName, patterns); this.code = code; ! } public Expression methodExp() { return code; } private Expression code; } --- 77,127 ---- new ImportedAlternative(method.getName(), fullName, (Pattern[]) patterns.toArray(new Pattern[patterns.size()]), ! new QuoteExp(new PrimProcedure(method)), ! location); } ! /** ! If this full name refers to a java method, make sure it participates ! to the link tests and dispatch code generation. ! */ ! private static void registerJavaMethod(String fullName) ! { ! if (! fullName.startsWith(JavaMethod.fullNamePrefix)) ! return; ! ! int end = fullName.lastIndexOf(':'); ! LocatedString methodName = new LocatedString ! (fullName.substring(JavaMethod.fullNamePrefix.length(), end), ! bossa.util.Location.nowhereAtAll()); ! ! List methods = bossa.syntax.Node.getGlobalScope().lookup(methodName); ! for (Iterator i = methods.iterator(); i.hasNext();) ! { ! Object next = i.next(); ! if (! (next instanceof MethodDeclaration.Symbol)) ! continue; ! MethodDeclaration md = ((MethodDeclaration.Symbol) next).getDefinition(); ! if (md.getFullName().equals(fullName)) ! { ! ((JavaMethod) md).registerForDispatch(); ! return; ! } ! } ! } ! ! private ImportedAlternative(String name, String fullName, Pattern[] patterns, ! gnu.expr.Expression code, Location location) { super(name, fullName, patterns); this.code = code; ! this.location = location; ! } public Expression methodExp() { return code; } private Expression code; + + public Location location() { return location; } + + private Location location; } Index: Dispatch.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/Dispatch.java,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** Dispatch.java 20 Mar 2003 00:03:52 -0000 1.52 --- Dispatch.java 18 Apr 2003 14:50:27 -0000 1.53 *************** *** 25,28 **** --- 25,30 ---- import mlsub.typing.lowlevel.Element; + import gnu.bytecode.ClassType; + import java.util.*; *************** *** 47,52 **** } ! private static Collection methods; ! public static void reset() { methods = new ArrayList(); } private static Chronometer chrono = Chronometer.make("Dispatch tests"); --- 49,63 ---- } ! public static void register(JavaMethod m) ! { ! javaMethods.add(m); ! } ! ! private static Collection methods, javaMethods; ! public static void reset() ! { ! methods = new ArrayList(); ! javaMethods = new ArrayList(); ! } private static Chronometer chrono = Chronometer.make("Dispatch tests"); *************** *** 58,61 **** --- 69,75 ---- for(Iterator i = methods.iterator(); i.hasNext();) test((NiceMethod) i.next(), module); + + for (Iterator i = javaMethods.iterator(); i.hasNext();) + test((JavaMethod) i.next(), module); } finally { *************** *** 69,73 **** if (!(m.isMain() || trivialTestOK(sortedAlternatives))) ! test(m, sortedAlternatives); if(Debug.codeGeneration) --- 83,87 ---- if (!(m.isMain() || trivialTestOK(sortedAlternatives))) ! test(m, sortedAlternatives, false); if(Debug.codeGeneration) *************** *** 77,80 **** --- 91,107 ---- } + private static void test(JavaMethod m, bossa.modules.Package module) + { + Stack sortedAlternatives = Alternative.sortedAlternatives(m); + + if (! trivialTestOK(sortedAlternatives)) + test(m, sortedAlternatives, true); + + if(Debug.codeGeneration) + Debug.println("Generating dispatch function for " + m); + + Compilation.compile(m, sortedAlternatives, module); + } + private static boolean trivialTestOK(Stack alternatives) { *************** *** 109,114 **** } ! private static void test(NiceMethod method, ! final Stack sortedAlternatives) { if(Debug.linkTests) --- 136,142 ---- } ! private static void test(MethodDeclaration method, ! final Stack sortedAlternatives, ! boolean isJavaMethod) { if(Debug.linkTests) *************** *** 135,140 **** { TypeConstructor[] tags = (TypeConstructor[]) i.next(); ! if (test(method, tags, sortedAlternatives)) { if (++nb_errors > 9) --- 163,178 ---- { TypeConstructor[] tags = (TypeConstructor[]) i.next(); + + // For java methods, we are only concerned with cases + // where the first argument is a Nice class. + ClassType firstArg = null; + if (isJavaMethod) + { + firstArg = classTypeOfNiceClass(tags[0]); + if (firstArg == null) + continue; + } ! if (test(method, tags, sortedAlternatives, firstArg)) { if (++nb_errors > 9) *************** *** 151,155 **** method.getName()); } ! /** Tests that the 'tags' tuple has a best-match in alternatives --- 189,203 ---- method.getName()); } ! ! private static ClassType classTypeOfNiceClass(TypeConstructor tc) ! { ! ClassDefinition def = ClassDefinition.get(tc); ! ! if (def == null || ! (def.getImplementation() instanceof NiceClass)) ! return null; ! ! return ((NiceClass) def.getImplementation()).getClassExp().getClassType(); ! } ! /** Tests that the 'tags' tuple has a best-match in alternatives *************** *** 161,167 **** @return true if the test failed */ ! private static boolean test(NiceMethod method, TypeConstructor[] tags, ! final Stack sortedAlternatives) { boolean failed = false; --- 209,216 ---- @return true if the test failed */ ! private static boolean test(MethodDeclaration method, TypeConstructor[] tags, ! final Stack sortedAlternatives, ! ClassType firstArg) { boolean failed = false; *************** *** 192,197 **** } } ! if(first==null) { failed = true; if(sortedAlternatives.size()==0) --- 241,256 ---- } } ! if (first == null) { + if (firstArg != null) + { + gnu.bytecode.Method superImplementation = SuperExp.getImplementationAbove + ((JavaMethod) method, firstArg); + if (superImplementation != null && + superImplementation.isAbstract() == false) + // It's OK, this case is covered by a Java implementation. + return false; + } + failed = true; if(sortedAlternatives.size()==0) *************** *** 211,219 **** Special version of above that tests tags with all combinations of integer values. */ ! private static boolean testValues(NiceMethod method, ! TypeConstructor[] tags, ! List valueCombis, ! boolean[] isValue, ! final Stack sortedAlternatives) { boolean failed = false; --- 270,279 ---- Special version of above that tests tags with all combinations of integer values. */ ! private static boolean testValues ! (MethodDeclaration method, ! TypeConstructor[] tags, ! List valueCombis, ! boolean[] isValue, ! final Stack sortedAlternatives) { boolean failed = false; Index: Compilation.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/Compilation.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Compilation.java 29 Mar 2003 19:26:24 -0000 1.10 --- Compilation.java 18 Apr 2003 14:50:29 -0000 1.11 *************** *** 22,25 **** --- 22,26 ---- import nice.tools.code.Gen; + import bossa.util.User; import java.util.*; *************** *** 95,101 **** else return gnu.expr.SimpleIfExp.make ! (alt.matchTest(params), matchCase, dispatch(sortedAlternatives, returnType, voidReturn, params)); } } --- 96,211 ---- else return gnu.expr.SimpleIfExp.make ! (alt.matchTest(params, false), matchCase, dispatch(sortedAlternatives, returnType, voidReturn, params)); + } + + /**************************************************************** + * Java Methods + ****************************************************************/ + + static void compile(JavaMethod m, + Stack sortedAlternatives, + bossa.modules.Package module) + { + int arity = m.getArity(); + + while (sortedAlternatives.size() > 0) + { + // We pick a class, and compile all implementations whose + // first argument is at that class. + Iterator i = sortedAlternatives.iterator(); + Alternative a = (Alternative) i.next(); + NiceClass c = declaringClass(m, a); + i.remove(); + + List l = new LinkedList(); + l.add(a); + while (i.hasNext()) + { + a = (Alternative) i.next(); + if (declaringClass(m, a) == c) + { + l.add(a); + i.remove(); + } + } + + Expression[] params = new Expression[arity]; + LambdaExp lambda = + Gen.createMemberMethod + (m.getName().toString(), + c.getClassExp().getType(), + m.javaArgTypes(), + m.javaReturnType(), + params); + + c.addJavaMethod(lambda); + Expression body = dispatchJavaMethod + (l.iterator(), m.javaReturnType(), m.javaReturnType().isVoid(), + params, (ClassType) c.getClassExp().getType(), m); + Gen.setMethodBody(lambda, body); + } + } + + private static NiceClass declaringClass(JavaMethod m, Alternative alt) + { + mlsub.typing.TypeConstructor firstArgument = alt.getPatterns()[0].tc; + ClassDefinition def = ClassDefinition.get(firstArgument); + + if (def == null || ! (def.getImplementation() instanceof NiceClass)) + throw User.error(alt, + m + " is a native method.\n" + + "It can not be overriden because the first argument" + + (firstArgument == null + ? "" + : " " + firstArgument.toString()) + + " is not a class defined in Nice"); + + return (NiceClass) def.getImplementation(); + } + + private static Expression dispatchJavaMethod + (Iterator sortedAlternatives, + Type returnType, + boolean voidReturn, + Expression[] params, + ClassType c, JavaMethod m) + { + if (!sortedAlternatives.hasNext()) + { + // Call super. + ClassType superClass = c.getSuperclass(); + gnu.bytecode.Method superMethod = superClass.getMethod + (m.getName().toString(), m.javaArgTypes()); + if (superMethod != null) + return new ApplyExp + (new QuoteExp(PrimProcedure.specialCall(superMethod)), params); + + // We produce code that should never be reached at run-time. + + Expression message = new QuoteExp("Message not understood"); + Expression exception = new ApplyExp(new InstantiateProc(newError), + new Expression[]{ message }); + Expression throwExp = + new ApplyExp(nice.lang.inline.Throw.instance, + new Expression[]{exception}); + + return throwExp; + } + + Alternative alt = (Alternative) sortedAlternatives.next(); + Expression matchCase = new ApplyExp(alt.methodExp(), params); + + if(voidReturn) + matchCase = new BeginExp(matchCase, Gen.returnVoid()); + else + matchCase = Gen.returnValue(matchCase); + + return gnu.expr.SimpleIfExp.make + (alt.matchTest(params, /* skip first */ true), + matchCase, + dispatchJavaMethod(sortedAlternatives, returnType, voidReturn, + params, c, m)); } } Index: Alternative.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/Alternative.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** Alternative.java 29 Mar 2003 19:26:24 -0000 1.40 --- Alternative.java 18 Apr 2003 14:50:29 -0000 1.41 *************** *** 17,21 **** import mlsub.typing.*; ! import bossa.syntax.NiceMethod; import bossa.syntax.Pattern; import bossa.syntax.LocatedString; --- 17,21 ---- import mlsub.typing.*; ! import bossa.syntax.MethodDeclaration; import bossa.syntax.Pattern; import bossa.syntax.LocatedString; *************** *** 38,42 **** */ ! public abstract class Alternative { /** --- 38,42 ---- */ ! public abstract class Alternative implements Located { /** *************** *** 139,143 **** the tuple <code>parameters</code>. */ ! Expression matchTest(Expression[] parameters) { if (parameters.length != patterns.length) --- 139,143 ---- the tuple <code>parameters</code>. */ ! Expression matchTest(Expression[] parameters, boolean skipFirst) { if (parameters.length != patterns.length) *************** *** 146,157 **** " for " + this); ! if (parameters.length == 0) return QuoteExp.trueExp; ! if (parameters.length == 1) ! return patterns[0].matchTest(parameters[0]); Expression result = QuoteExp.trueExp; - int index = 0; //find the first non-trivial test --- 146,158 ---- " for " + this); ! int index = skipFirst ? 1 : 0; ! ! if (parameters.length == index) return QuoteExp.trueExp; ! if (parameters.length == index + 1) ! return patterns[index].matchTest(parameters[index]); Expression result = QuoteExp.trueExp; //find the first non-trivial test *************** *** 212,216 **** } ! public static Stack sortedAlternatives(NiceMethod m) { List list = (List) alternatives.get(m.getFullName()); --- 213,217 ---- } ! public static Stack sortedAlternatives(MethodDeclaration m) { List list = (List) alternatives.get(m.getFullName()); |
From: <bo...@us...> - 2003-04-18 14:50:33
|
Update of /cvsroot/nice/Nice/debian In directory sc8-pr-cvs1:/tmp/cvs-serv18316/debian Modified Files: changelog Log Message: Allow implementations of native methods to dispatch on all their arguments. Index: changelog =================================================================== RCS file: /cvsroot/nice/Nice/debian/changelog,v retrieving revision 1.147 retrieving revision 1.148 diff -C2 -d -r1.147 -r1.148 *** changelog 8 Apr 2003 19:16:44 -0000 1.147 --- changelog 18 Apr 2003 14:50:29 -0000 1.148 *************** *** 1,2 **** --- 1,13 ---- + nice (0.7.9) unstable; urgency=low + + * Allow implementations of methods declared in Java to dispatch on + all their arguments. So now we can at last write: + class A { + int x; + equals(that@A) = this.x == that.x; + } + + -- + nice (0.7.8) unstable; urgency=low |
From: <bo...@us...> - 2003-04-16 18:39:04
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv2305/src/bossa/syntax Modified Files: Pattern.java Log Message: Fix a typo in the error message for dispatch on primitive types, and make it really print the location of the error. Index: Pattern.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Pattern.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** Pattern.java 1 Apr 2003 20:24:57 -0000 1.44 --- Pattern.java 16 Apr 2003 18:38:58 -0000 1.45 *************** *** 394,398 **** tc == PrimitiveType.charTC || tc == PrimitiveType.byteTC) ) ! User.error(typeConstructor,"A pattern cannot have a primitive type that is different from the declararion."); } --- 394,398 ---- tc == PrimitiveType.charTC || tc == PrimitiveType.byteTC) ) ! User.error(location, "A pattern cannot have a primitive type that is different from the declaration."); } |
From: <bo...@us...> - 2003-04-16 18:39:01
|
Update of /cvsroot/nice/Nice/testsuite/compiler/methods In directory sc8-pr-cvs1:/tmp/cvs-serv2305/testsuite/compiler/methods Added Files: primitive.testsuite Log Message: Fix a typo in the error message for dispatch on primitive types, and make it really print the location of the error. --- NEW FILE: primitive.testsuite --- /// FAIL ///Toplevel toString(/*/// FAIL HERE */ i@int) = ""; |
From: <bo...@us...> - 2003-04-16 16:54:32
|
Update of /cvsroot/nice/Nice/testsuite/compiler/methods In directory sc8-pr-cvs1:/tmp/cvs-serv15786 Modified Files: nativeOverride.testsuite Log Message: Tests the use of an anonymous function inside the override of a Java method. This is the bug that was fixed on Mon Nov 25 18:58:30 2002 UTC (see src/bossa/modules/Package.java, revision 1,81) and for which the testcase was somehow forgotten or lost. Index: nativeOverride.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/methods/nativeOverride.testsuite,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** nativeOverride.testsuite 13 Sep 2002 12:28:34 -0000 1.1 --- nativeOverride.testsuite 16 Apr 2003 16:54:28 -0000 1.2 *************** *** 13,14 **** --- 13,22 ---- } } + + /// PASS + assert new A().toString().equals("A."); + /// Toplevel + class A + { + toString() = (["A"].map(String s => s + "."))[0].toString(); + } |