nice-commit Mailing List for The Nice Programming Language (Page 61)
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...@pr...> - 2004-02-02 13:10:37
|
Update of /cvsroot/nice/Nice/src/bossa/link In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27438/src/bossa/link Modified Files: Alternative.java Log Message: Perform exact matching on the first argument of methods declared in Java when needed (fixes #888229). Index: Alternative.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/Alternative.java,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** Alternative.java 2 Feb 2004 12:11:47 -0000 1.46 --- Alternative.java 2 Feb 2004 13:08:34 -0000 1.47 *************** *** 155,165 **** " for " + this); - int index = skipFirst ? 1 : 0; - Expression result = QuoteExp.trueExp; ! for(; index<parameters.length; index++) result = Gen.shortCircuitAnd ! (result, patterns[index].matchTest(parameters[index])); return result; --- 155,164 ---- " for " + this); Expression result = QuoteExp.trueExp; ! for (int index = 0; index < parameters.length; index++) result = Gen.shortCircuitAnd ! (result, ! patterns[index].matchTest(parameters[index], index == 0 && skipFirst)); return result; |
From: <bo...@pr...> - 2004-02-02 13:10:36
|
Update of /cvsroot/nice/Nice/testsuite/compiler/methods In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27438/testsuite/compiler/methods Modified Files: nativeOverride.testsuite Log Message: Perform exact matching on the first argument of methods declared in Java when needed (fixes #888229). Index: nativeOverride.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/methods/nativeOverride.testsuite,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** nativeOverride.testsuite 30 Sep 2003 17:42:14 -0000 1.8 --- nativeOverride.testsuite 2 Feb 2004 13:08:32 -0000 1.9 *************** *** 222,223 **** --- 222,239 ---- get(0) = cast(null); } + + /// PASS + let a = new A(); + let b = new B(); + + assert a.equals(a); + assert ! a.equals(b); + assert ! b.equals(a); + assert b.equals(b); + + /// TOPLEVEL + class A { int i = 0; } + class B extends A { int k = 0; } + + equals (#A x, #A y) = x.i == y.i; + equals (#B x, #B y) = x.k == y.k; |
From: <bo...@pr...> - 2004-02-02 12:13:50
|
Update of /cvsroot/nice/Nice/src/bossa/link In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11868/src/bossa/link Modified Files: Alternative.java Log Message: Further simplification. Index: Alternative.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/Alternative.java,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** Alternative.java 2 Feb 2004 12:00:47 -0000 1.45 --- Alternative.java 2 Feb 2004 12:11:47 -0000 1.46 *************** *** 157,163 **** int index = skipFirst ? 1 : 0; - if (parameters.length == index) - return QuoteExp.trueExp; - Expression result = QuoteExp.trueExp; --- 157,160 ---- |
From: <bo...@pr...> - 2004-02-02 12:02:50
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang/inline In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2710/stdlib/nice/lang/inline Modified Files: ShortCircuitOp.java Log Message: Moved optimizations to nice.lang.inline.ShortCircuitOp so that all code benefits from them and higher-level code-generation code can be kept simple. Index: ShortCircuitOp.java =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/inline/ShortCircuitOp.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ShortCircuitOp.java 21 Mar 2003 23:32:35 -0000 1.3 --- ShortCircuitOp.java 2 Feb 2004 12:00:46 -0000 1.4 *************** *** 50,53 **** --- 50,69 ---- { Expression[] args = exp.getArgs(); + + // Optimize some trivial cases + if (kind == And) + { + if (args[0] == QuoteExp.trueExp) + { + args[1].compile(comp, target); + return; + } + if (args[1] == QuoteExp.trueExp) + { + args[0].compile(comp, target); + return; + } + } + CodeAttr code = comp.getCode(); Target stack = new StackTarget(Type.boolean_type); *************** *** 96,99 **** --- 112,118 ---- } + /** + Jump to label if the expression yields true. + */ public void compileJump (Compilation comp, Expression[] args, Label to) { *************** *** 134,137 **** --- 153,159 ---- } + /** + Jump to label if the expression yields false. + */ public void compileJumpNot (Compilation comp, Expression[] args, Label to) { *************** *** 151,154 **** --- 173,180 ---- branchOp.compileJump(comp, brArgs, _end); } + else if (kind == And && args[0] == QuoteExp.trueExp) + { + // Optim: do nothing, this argument cannot make the expression false. + } else { *************** *** 164,167 **** --- 190,197 ---- branchOp2.compileJumpNot(comp, brArgs, to); } + else if (kind == And && args[1] == QuoteExp.trueExp) + { + // Optim: do nothing, this argument cannot make the expression false. + } else { |
From: <bo...@pr...> - 2004-02-02 12:02:49
|
Update of /cvsroot/nice/Nice/src/bossa/link In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2710/src/bossa/link Modified Files: Alternative.java Log Message: Moved optimizations to nice.lang.inline.ShortCircuitOp so that all code benefits from them and higher-level code-generation code can be kept simple. Index: Alternative.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/Alternative.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** Alternative.java 26 Sep 2003 23:12:36 -0000 1.44 --- Alternative.java 2 Feb 2004 12:00:47 -0000 1.45 *************** *** 154,158 **** Util.map("",", ","",parameters)+ " for " + this); ! int index = skipFirst ? 1 : 0; --- 154,158 ---- Util.map("",", ","",parameters)+ " for " + this); ! int index = skipFirst ? 1 : 0; *************** *** 160,185 **** return QuoteExp.trueExp; - if (parameters.length == index + 1) - return patterns[index].matchTest(parameters[index]); - Expression result = QuoteExp.trueExp; - //find the first non-trivial test for(; index<parameters.length; index++) ! if (!patterns[index].atAny()) ! { ! result = patterns[index].matchTest(parameters[index]); ! index++; ! break; ! } ! ! for(; index<parameters.length; index++) ! if (!patterns[index].atAny()) ! result = Gen.shortCircuitAnd(result, ! patterns[index].matchTest(parameters[index])); ! return result; } ! public String toString() { --- 160,172 ---- return QuoteExp.trueExp; Expression result = QuoteExp.trueExp; for(; index<parameters.length; index++) ! result = Gen.shortCircuitAnd ! (result, patterns[index].matchTest(parameters[index])); ! return result; } ! public String toString() { |
From: <bo...@pr...> - 2004-02-02 09:40:12
|
Update of /cvsroot/nice/Nice/src/gnu/bytecode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11995 Modified Files: CodeAttr.java Log Message: Fixed a typo. Index: CodeAttr.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/bytecode/CodeAttr.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** CodeAttr.java 2 Feb 2004 00:47:33 -0000 1.21 --- CodeAttr.java 2 Feb 2004 09:37:57 -0000 1.22 *************** *** 1696,1700 **** // We store the result in a method-level variable, to make sure // that the finally blocks do not use the same slot. ! result = methodScope().addVariable(this, topType()); emitStore(result); } --- 1696,1700 ---- // We store the result in a method-level variable, to make sure // that the finally blocks do not use the same slot. ! result = methodScope().addVariable(this, topType(), null); emitStore(result); } |
From: <bo...@pr...> - 2004-02-02 00:49:30
|
Update of /cvsroot/nice/Nice/src/gnu/bytecode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5036/src/gnu/bytecode Modified Files: CodeAttr.java Log Message: When a return is inside a try/finally, store the result in a method-level local bytecode variable, to make sure that the finally blocks do not use the same slot (closes #888452). Index: CodeAttr.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/bytecode/CodeAttr.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** CodeAttr.java 3 Nov 2003 18:32:07 -0000 1.20 --- CodeAttr.java 2 Feb 2004 00:47:33 -0000 1.21 *************** *** 415,418 **** --- 415,427 ---- } + /** Return the toplevel scope, corresponding to the current method. */ + public Scope methodScope() + { + Scope res = getCurrentScope(); + while (res.parent != null) + res = res.parent; + return res; + } + public Scope popScope () { Scope scope = locals.current_scope; *************** *** 1685,1689 **** if (saveResult && result == null) { ! result = addLocal(topType()); emitStore(result); } --- 1694,1700 ---- if (saveResult && result == null) { ! // We store the result in a method-level variable, to make sure ! // that the finally blocks do not use the same slot. ! result = methodScope().addVariable(this, topType()); emitStore(result); } |
From: <bo...@pr...> - 2004-02-02 00:49:30
|
Update of /cvsroot/nice/Nice/testsuite/compiler/native In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5036/testsuite/compiler/native Modified Files: synchronized.testsuite Log Message: When a return is inside a try/finally, store the result in a method-level local bytecode variable, to make sure that the finally blocks do not use the same slot (closes #888452). Index: synchronized.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/native/synchronized.testsuite,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** synchronized.testsuite 17 Sep 2003 00:14:06 -0000 1.3 --- synchronized.testsuite 2 Feb 2004 00:47:32 -0000 1.4 *************** *** 42,43 **** --- 42,58 ---- } } + + /// PASS + /// Toplevel + class Foo {} + + int bar (Foo obj) + { + synchronized(obj) + { + ?Throwable exn = new Exception(); + if (exn != null) + throw exn; + return 1; + } + } |
From: <ar...@pr...> - 2004-01-31 05:31:09
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang/inline In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1871/F:/nice/stdlib/nice/lang/inline Modified Files: OptionOr.java Log Message: Warning for non-null first argument of an option-or. Index: OptionOr.java =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/inline/OptionOr.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** OptionOr.java 2 Apr 2003 16:44:50 -0000 1.4 --- OptionOr.java 30 Jan 2004 00:17:52 -0000 1.5 *************** *** 25,29 **** @author Daniel Bonniot */ ! public class OptionOr extends Procedure2 implements Inlineable { public static OptionOr create(String param) --- 25,29 ---- @author Daniel Bonniot */ ! public class OptionOr extends Procedure2 implements bossa.syntax.Macro { public static OptionOr create(String param) *************** *** 56,59 **** --- 56,65 ---- } + public void checkSpecialRequirements(bossa.syntax.Expression[] arguments) + { + if (nice.tools.code.Types.isSure(arguments[0].getType().getMonotype())) + bossa.util.User.warning(arguments[0], "First argument is a non-null value thus the second one will not be used."); + } + // Interpretation |
From: <bo...@pr...> - 2004-01-30 15:56:31
|
Update of /cvsroot/nice/swing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23088 Added Files: project.xml .cvsignore Log Message: Added support for Maven. --- NEW FILE: project.xml --- <?xml version="1.0" encoding="latin1" ?> <project> <pomVersion>3</pomVersion> <name>Swing adapter for Nice</name> <id>nice-swing</id> <currentVersion>0.1</currentVersion> <organization> <name>The Nice project</name> <url>http://nice.sf.net/</url> </organization> <inceptionYear>2004</inceptionYear> <package>nice.ui.common</package> <shortDescription>Extension of the Swing toolkit to make use of Nice advanced features</shortDescription> <description> This library allows you to write a Swing user interface in Nice programs. It allows a more elegant programming style than Swing programs written in Java by using Nice's features like anonymous functions and named and optional method parameters. </description> <url>http://nice.sourceforge.net/cgi-bin/twiki/view/Doc/NiceSwing</url> <issueTrackingUrl> http://sourceforge.net/tracker/?group_id=12788&atid=112788 </issueTrackingUrl> <siteAddress>nice.sf.net</siteAddress> <siteDirectory> /home/groups/n/ni/nice/htdocs/packages/swing </siteDirectory> <distributionDirectory> /home/groups/n/ni/nice/packages/builds </distributionDirectory> <repository> <connection> scm:cvs:pserver:ano...@cv...:/cvsroot/nice:swing </connection> <url> http://cvs.sourceforge.net/viewcvs.py/nice/swing/ </url> </repository> <versions> <version> <id>0.1</id> <name>0.1</name> <tag>HEAD</tag> </version> </versions> <mailingLists> <mailingList> <name>Nice User List</name> <subscribe>http://lists.sourceforge.net/lists/listinfo/nice-info</subscribe> <unsubscribe>http://lists.sourceforge.net/lists/listinfo/nice-info</unsubscribe> <archive>http://sourceforge.net/mailarchive/forum.php?forum=nice-info</archive> </mailingList> </mailingLists> <developers> <developer> <name>Martin Gamsjaeger</name> <id>gamsl</id> <email>ga...@ab...</email> <organization></organization> <roles> <role>Initial design</role> <role>Implementation</role> </roles> </developer> <developer> <name>Daniel Bonniot</name> <id>bonniot</id> <email>bo...@us...</email> <organization></organization> <timezone>+1</timezone> <roles> <role>Initial design</role> </roles> </developer> <developer> <name>Arjan Boeijink</name> <id>arjanb</id> <email>ar...@us...</email> <organization></organization> <roles> <role>Patches</role> </roles> </developer> <developer> <name>Lodewijk Vöge</name> <id>voge</id> <email></email> <organization></organization> <roles> <role>Patches</role> </roles> </developer> </developers> <build> <nagEmailAddress> nic...@li... </nagEmailAddress> <sourceDirectory>src</sourceDirectory> <unitTestSourceDirectory>src/test</unitTestSourceDirectory> <!-- Unit test cases --> <unitTest> <includes> <include>**/*Test.java</include> </includes> <excludes> <exclude>**/RepositoryTest.java</exclude> </excludes> </unitTest> <!-- J A R R E S O U R C E S --> <!-- Resources that are packaged up inside the JAR file --> <resources> </resources> <!-- Integration unit test cases --> <integrationUnitTest/> <jars> </jars> </build> </project> --- NEW FILE: .cvsignore --- maven.log target velocity.log |
From: <ar...@pr...> - 2004-01-29 03:04:18
|
Update of /cvsroot/nice/swing/examples/events In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13363/D:/nice/examples/events Modified Files: EventTest.nice Log Message: Make a nice-swing example compile again: moved global vars to local. Index: EventTest.nice =================================================================== RCS file: /cvsroot/nice/swing/examples/events/EventTest.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EventTest.nice 2 Oct 2002 03:23:48 -0000 1.2 --- EventTest.nice 29 Jan 2004 01:01:27 -0000 1.3 *************** *** 7,16 **** import nice.ui.common; - - var ActionEvent -> void blueColor; - var ActionEvent -> void grayColor; - var ActionEvent -> void offBlueColor; - var ActionEvent -> void offGrayColor; - void changeColor(JPanel p, Color c) = p.setBackground(c); --- 7,10 ---- *************** *** 21,26 **** JPanel makePanel() { ! // create the panel ! JPanel panel = new JPanel(); // switches background to blue --- 15,27 ---- JPanel makePanel() { ! // variables that will contain the event actions ! var ActionEvent->void blueColor; ! var ActionEvent->void grayColor; ! var ActionEvent->void offBlueColor; ! var ActionEvent->void offGrayColor; ! ! ! // create the panel ! JPanel panel = new JPanel(); // switches background to blue |
From: <bo...@pr...> - 2004-01-28 13:11:30
|
Update of /cvsroot/nice/Nice/src/nice/tools/code In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14271/src/nice/tools/code Modified Files: SpecialArray.java Log Message: In bytecode, an array with unknown element types needs conversion when used as an Object[]. Index: SpecialArray.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/code/SpecialArray.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** SpecialArray.java 25 Nov 2003 19:22:58 -0000 1.15 --- SpecialArray.java 28 Jan 2004 13:10:11 -0000 1.16 *************** *** 321,324 **** --- 321,330 ---- public boolean isAssignableTo (Type other) { + if (this == other) + return true; + + if (unknown) + return other == objectType; + return other == objectType || |
From: <bo...@pr...> - 2004-01-28 13:11:23
|
Update of /cvsroot/nice/Nice/testsuite/compiler/classes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14271/testsuite/compiler/classes Modified Files: fields.testsuite Log Message: In bytecode, an array with unknown element types needs conversion when used as an Object[]. Index: fields.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/classes/fields.testsuite,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** fields.testsuite 26 Jan 2004 13:14:16 -0000 1.15 --- fields.testsuite 28 Jan 2004 13:10:11 -0000 1.16 *************** *** 127,128 **** --- 127,146 ---- import javax.swing.*; let int x = JFrame.EXIT_ON_CLOSE; + + /// PASS + Polynomial<Complex<Object>> p = new Polynomial(e: []); + /// TOPLEVEL + abstract interface Ring<T> { + void zero(); + } + + class Complex<T> implements Ring<T> { + zero() {} + } + + <Ring R, RR, T | R<RR> <: T <: R<RR>> + class Polynomial<T> implements Ring { + T[] e; + + zero(){} + } |
From: <bo...@pr...> - 2004-01-27 22:59:21
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26038/src/bossa/parser Modified Files: Parser.jj Log Message: Allow X <: Y <: Z in constraints. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.233 retrieving revision 1.234 diff -C2 -d -r1.233 -r1.234 *** Parser.jj 27 Jan 2004 21:58:58 -0000 1.233 --- Parser.jj 27 Jan 2004 22:58:14 -0000 1.234 *************** *** 580,606 **** } ! AtomicConstraint atomicConstraint(): { Monotype m1,m2; TypeIdent t,i; - AtomicConstraint res; } { ( LOOKAHEAD(2) m1=monotype() "<:" m2=monotype() ! { res=new MonotypeLeqCst(m1,m2); } | t=typeConstructorIdent() ":" i=typeIdent() ! { res=new ImplementsCst(t,i); } ) - { return res; } } void atomics(List res): ! // if res is null, we just want lookahead ! { AtomicConstraint k; } { ! k=atomicConstraint() { res.add(k); } ! ( "," k=atomicConstraint() { res.add(k); } ) * } --- 580,606 ---- } ! void atomicConstraint(List list): { Monotype m1,m2; TypeIdent t,i; } { ( LOOKAHEAD(2) m1=monotype() "<:" m2=monotype() ! { list.add(new MonotypeLeqCst(m1,m2)); } ! ( "<:" { m1 = m2; } ! m2 = monotype() ! { list.add(new MonotypeLeqCst(m1,m2)); } ! )* | t=typeConstructorIdent() ":" i=typeIdent() ! { list.add(new ImplementsCst(t,i)); } ) } void atomics(List res): ! {} { ! atomicConstraint(res) ( "," atomicConstraint(res) )* } |
From: <bo...@pr...> - 2004-01-27 22:00:07
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9301/src/bossa/parser Modified Files: Parser.jj Log Message: Minor: removed useless tests. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.232 retrieving revision 1.233 diff -C2 -d -r1.232 -r1.233 *** Parser.jj 16 Jan 2004 00:14:06 -0000 1.232 --- Parser.jj 27 Jan 2004 21:58:58 -0000 1.233 *************** *** 601,606 **** { AtomicConstraint k; } { ! k=atomicConstraint() { if(res!=null) res.add(k); } ! ( "," k=atomicConstraint() { if(res!=null) res.add(k); } ) * } --- 601,606 ---- { AtomicConstraint k; } { ! k=atomicConstraint() { res.add(k); } ! ( "," k=atomicConstraint() { res.add(k); } ) * } |
From: <xo...@pr...> - 2004-01-27 17:38:27
|
Update of /cvsroot/nice/Nice/stdlib/nice/functional In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4893/stdlib/nice/functional Modified Files: generator.nice iterator.nice Log Message: Fixed license headers. Index: generator.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/functional/generator.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** generator.nice 26 Jan 2004 18:27:35 -0000 1.1 --- generator.nice 27 Jan 2004 17:37:19 -0000 1.2 *************** *** 1,13 **** ! /**************************************************************************/ ! /* 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 */ ! /* it under the terms of the GNU Lesser General Public License as */ ! /* published by the Free Software Foundation; either version 2 of the */ ! /* License, or (at your option) any later version. */ ! /* */ ! /**************************************************************************/ /** --- 1,18 ---- ! /**************************************************************************** ! * 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 * ! * it under the terms of the GNU General Public License as published by * ! * Free Software Foundation; either version 2 of the License, or (at your * ! * option) any later version. * ! * * ! * As a special exception, the copyright holders of this library give you * ! * permission to link this library with independent modules to produce an * ! * executable, regardless of the license terms of these independent * ! * modules, and to copy and distribute the resulting executable under * ! * terms of your choice. * ! ****************************************************************************/ /** Index: iterator.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/functional/iterator.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** iterator.nice 26 Jan 2004 18:27:35 -0000 1.1 --- iterator.nice 27 Jan 2004 17:37:20 -0000 1.2 *************** *** 1,13 **** ! /**************************************************************************/ ! /* 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 */ ! /* it under the terms of the GNU Lesser General Public License as */ ! /* published by the Free Software Foundation; either version 2 of the */ ! /* License, or (at your option) any later version. */ ! /* */ ! /**************************************************************************/ /** --- 1,18 ---- ! /**************************************************************************** ! * 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 * ! * it under the terms of the GNU General Public License as published by * ! * Free Software Foundation; either version 2 of the License, or (at your * ! * option) any later version. * ! * * ! * As a special exception, the copyright holders of this library give you * ! * permission to link this library with independent modules to produce an * ! * executable, regardless of the license terms of these independent * ! * modules, and to copy and distribute the resulting executable under * ! * terms of your choice. * ! ****************************************************************************/ /** |
From: <xo...@pr...> - 2004-01-27 17:38:27
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4893/stdlib/nice/lang Modified Files: using.nice Log Message: Fixed license headers. Index: using.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/using.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** using.nice 26 Jan 2004 22:12:40 -0000 1.1 --- using.nice 27 Jan 2004 17:37:21 -0000 1.2 *************** *** 1,13 **** ! /**************************************************************************/ ! /* 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 */ ! /* it under the terms of the GNU Lesser General Public License as */ ! /* published by the Free Software Foundation; either version 2 of the */ ! /* License, or (at your option) any later version. */ ! /* */ ! /**************************************************************************/ /** --- 1,18 ---- ! /**************************************************************************** ! * 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 * ! * it under the terms of the GNU General Public License as published by * ! * Free Software Foundation; either version 2 of the License, or (at your * ! * option) any later version. * ! * * ! * As a special exception, the copyright holders of this library give you * ! * permission to link this library with independent modules to produce an * ! * executable, regardless of the license terms of these independent * ! * modules, and to copy and distribute the resulting executable under * ! * terms of your choice. * ! ****************************************************************************/ /** |
From: <bo...@pr...> - 2004-01-27 15:04:35
|
Update of /cvsroot/nice/Nice/testsuite/compiler/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29771/testsuite/compiler/typing Modified Files: typeParameters.testsuite Log Message: Fixed a typing bug for abstract interfaces with type parameters. Index: typeParameters.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/typing/typeParameters.testsuite,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** typeParameters.testsuite 6 Jun 2003 15:18:51 -0000 1.3 --- typeParameters.testsuite 27 Jan 2004 15:03:26 -0000 1.4 *************** *** 9,10 **** --- 9,26 ---- <T | T <: X<T> > void f() {} // should fail without causing a stack overflow. + + /// PASS + /// Toplevel + abstract interface A<T> { + void foo(); + void bar(alike<T> other); + } + + class B<T> implements A { + + void foobar() + { this.foo(); } + + foo() {} + bar(other) {} + } |
From: <bo...@pr...> - 2004-01-27 15:04:34
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29771/src/bossa/syntax Modified Files: MethodContainer.java Log Message: Fixed a typing bug for abstract interfaces with type parameters. Index: MethodContainer.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodContainer.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** MethodContainer.java 15 Nov 2003 17:25:47 -0000 1.13 --- MethodContainer.java 27 Jan 2004 15:03:26 -0000 1.14 *************** *** 109,112 **** --- 109,116 ---- else this.typeParameters = typeParameters; + + // The type parameters have nullness markers. + for (int i = 0; i < typeParameters.length; i++) + nice.tools.code.Types.makeMarkedType(typeParameters[i]); } |
From: <xo...@pr...> - 2004-01-26 22:13:36
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4254/stdlib/nice/lang Added Files: using.nice Log Message: Implementation of the 'using' statement, familiar from C#. Essentially, this code: let f = new FileOutputStream("hello.txt"); using(f) { f.write("Hello, world!".getBytes()); } is equivalent to this code: let f = new FileOutputStream("hello.txt"); try { f.write("Hello, world!".getBytes()); } finally { f.close(); } To use 'using' with your own classes, simply have them implement the abstract interface Disposable, which has only one method, void dispose(); --- NEW FILE: using.nice --- /**************************************************************************/ /* 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 */ /* it under the terms of the GNU Lesser General Public License as */ /* published by the Free Software Foundation; either version 2 of the */ /* License, or (at your option) any later version. */ /* */ /**************************************************************************/ /** Implementation of the <code>using</code> statement, familiar from C#. Essentially, this code: <pre> let f = new FileOutputStream("hello.txt"); using(f) { f.write("Hello, world!".getBytes()); } </pre> is equivalent to this code: let f = new FileOutputStream("hello.txt"); try { f.write("Hello, world!".getBytes()); } finally { f.close(); } </pre> The using() method accepts any value whose type implements the <code>Disposable</code> abstract interface. For instance, to make <code>OutputStream</code>s work with <code>using</code>, this code was added: <pre> class java.io.OutputStream implements Disposable; dispose(OutputStream s) = s.close(); </pre> @author Bryn Keller (xo...@us...) */ import java.io.*; abstract interface Disposable { void dispose(); } <Disposable T> void using(T obj, ()->void action) { try { action(); } finally { obj.dispose(); } } class java.io.InputStream implements Disposable; dispose(InputStream s) = s.close(); class java.io.OutputStream implements Disposable; dispose(OutputStream s) = s.close(); class java.io.Reader implements Disposable; dispose(Reader r) = r.close(); class java.io.Writer implements Disposable; dispose(Writer w) = w.close(); /** For testing only */ private class NonReclosableOutputStream extends ByteArrayOutputStream { boolean closed = false; close() { if (closed) throw new IOException("Already closed"); closed = true; } } void _testUsing() { NonReclosableOutputStream os = new NonReclosableOutputStream(); using(os) { os.write("Hello".getBytes()); } try { os.close(); throw new Exception("Should have been closed!"); } catch (IOException e) { //Passed. } byte[] test = "Hello".getBytes(); byte[] output = os.toByteArray(); assert test.length == output.length; for(int i = 0; i < test.length; i++) { assert test[i] == output[i]; } } |
From: <xo...@pr...> - 2004-01-26 18:28:29
|
Update of /cvsroot/nice/Nice/stdlib/nice/functional In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14188/stdlib/nice/functional Added Files: generator.nice iterator.nice Log Message: New iterator/generator library. Provides a number of methods for dealing with iterators (i.e., Java-style Iterator<T>), and generators (Nice methods void->T which return a new element on each call, and throw GeneratorEnd when they don't have any more elements to yield). Things like map, filter, fold, zip, unzip, and so on. --- NEW FILE: generator.nice --- /**************************************************************************/ /* 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 */ /* it under the terms of the GNU Lesser General Public License as */ /* published by the Free Software Foundation; either version 2 of the */ /* License, or (at your option) any later version. */ /* */ /**************************************************************************/ /** A library for dealing with iterators - either Java-style <code>Iterator<T%gt;</code>s (in iterator.nice), or Nice-style ()->T generators (in generator.nice) @author Bryn Keller (xo...@us...) */ /** * Special class thrown by generator functions when * they should end. */ class GeneratorEnd extends Throwable {} /** * Stop a generator function. */ <A> A stop() { throw new GeneratorEnd(); } <A> ()->A generator(Iterator<A> iter) = () => { if (iter.hasNext()) return iter.next(); else return stop(); }; <A> ()->A generator(Collection<A> coll) = coll.iterator.generator; /** * Function composition. */ <A,B,C> A->C compose(B->C second, A->B first) = A input => second(first(input)); <A,B> (B, A) swap((A a, B b)) = (b, a); <A,B,C> (C, B) first((A a, B b), A->C xform) = (xform(a), b); <A,B> ()->B map(()->A gen, A->B xform) = () => xform(gen()); /** * Produces a new generator which only yields elements of the initial * generator that pass the test function. * * @param gen the original generator * @param filt the function that tests whether an item should be * in the new iterator. */ <A> ()->A filter(()->A gen, A->boolean filt) = ()=> { var A value = gen(); while(!filt(value)) value = gen(); return value; }; /** * Folds a generator. For example, * <pre> * int sum(()->int gen) = gen.fold(`+`, 0); * </pre> * * @see nice.lang#foldLeft */ <A,B> B fold(()->A gen, (B,A)->B foldfunc, B start) { try { while(true) { start = foldfunc(start, gen()); } } catch (GeneratorEnd e) { //Ignore. } return start; } /** * Checks that all elements of a generator are members of a given predicate. * Stops executing as soon as one element fails the test. */ <A> boolean all(void->A gen, A->boolean predicate) { try { while(true) { if (!predicate(gen())) return false; } } catch(GeneratorEnd e) { return true; } } /** * Checks that at least one element of a generator is a member of a given * predicate. Stops executing as soon as one element passes the test. */ <A> boolean any(void->A gen, A->boolean predicate) { try { while(true) { if (predicate(gen())) return true; } } catch(GeneratorEnd e) { return false; } } /** * Calls a function once for each item yielded by a generator. */ <A> void foreach(()->A gen, A->void func) { try { while(true) func(gen()); } catch (GeneratorEnd e) { } } /** * Creates a <code>List</code> from the elements of a generator. */ <A> List<A> toList(()->A gen) { let List<A> list = new ArrayList(); gen.foreach(A a => list.add(a)); return list; } /** * Add all the elements of a generator to a collection. */ <A> void addAll(Collection<A> coll, ()->A gen) { gen.foreach(A a => coll.add(a)); } /** * Converts 2 generators into a single generator * that yields 2-tuples */ //<A,B> ()->(A,B) zip(()->A one, ()->B two) = () => (one(), two()); <A,B> ()->(A,B) zip(()->A one, ()->B two) = unsafeZip(cast([one,two])); /** * Converts 3 generators into a single generator * that yields 3-tuples */ <A,B,C> ()->(A,B,C) zip(()->A one, ()->B two, ()->C three) = unsafeZip(cast([one,two,three])); /** * Converts 4 generators into a single generator * that yields 4-tuples */ <A,B,C,D> ()->(A,B,C,D) zip(()->A one, ()->B two, ()->C three, ()->D four) = unsafeZip(cast([one,two,three,four])); /** * Merges two generators using the given zipper function. For example: * <pre> * println(zipWith(["hello, "].generator, ["world"].generator, * (String s1, String s2) => s1 + s2)()); * </pre> * will print "hello, world". */ <A,B,C> void->C zipWith(void->A one, void->B two, (A,B)->C zipper) = unsafeZipWith(cast([one,two]), cast(zipper)); /** * Merges three generators using the given zipper function. * @see <A,B,C> void->C zipWith(void->A, void->B, (A,B)->C) */ <A,B,C,D> void->D zipWith(void->A one, void->B two, void->C three, (A,B,C)->D zipper) = unsafeZipWith(cast([one,two,three]), cast(zipper)); /** * Merges four generators using the given zipper function. * @see <A,B,C> void->C zipWith(void->A, void->B, (A,B)->C) */ <A,B,C,D,E> void->E zipWith(void->A one, void->B two, void->C three, void->D four, (A,B,C,D)->E zipper) = unsafeZipWith(cast([one,two,three,four]), cast(zipper)); /** * Back door to Nice's method dispatching. You promise that you know you're * passing a method, and arguments that make sense for the method. Nice * calls it and hands you back the results, which you promise are of the * correct type. The compiler cannot verify this, the programmer is responsible * for ensuring type safety. */ private <T,U> U apply(T fun, Object[?] args) { // The internal representation of functional values gnu.mapping.Procedure proc = cast(fun); return cast(proc.applyN(args)); } /** * Converts an array of generators into a single generator that yields * tuples of the appropriate size. Bypasses Nice's type system, so users * must ensure that types are correct. It's usually better to use one of * the strongly typed versions above instead. */ private <R> ()->R unsafeZip((()->?Object)[] generators) { let (?Object[], int->?Object)->?Object[] f = fill; return () => { ?Object[] res = f(new Object[generators.size()], int i => generators[i]()); return cast(res); }; } /** * Converts an array of generators into a single generator that yields * the results of calling <code>func</code> with arguments from the * array of generators. Bypasses Nice's type system, so users * must ensure that types are correct. It's usually better to use one of * the strongly typed versions above instead. */ private <R> ()->R unsafeZipWith(Array<()->Object> generators, Object->R func) { let (?Object[], int->Object)->Object[] f = fill; return () => apply(func, f(new Object[generators.size()], int i => generators[i]())); } private <R> R unsafeUnzip(()->Object gen) { Object[] tuple = cast(gen()); List<LinkedList<Object>> cache = new ArrayList(); tuple.size.times(int i => { cache.add(new LinkedList()); cache[i].add(tuple[i]); }); Object nextItem(int index) { if (cache[index].size == 0) { tuple = cast(gen()); tuple.size.times( int i => cache[i].add(tuple[i])); } return cache[index].removeFirst(); } let (?Object[], int->?Object)->?Object[] f = fill; ?Object[] funcs = f(new Object[tuple.size], int i => () => nextItem(i)); return cast(funcs); } /** * Converts a generator which yields 2-tuples into into a 2-tuple * containing 2 generators. */ <A,B> (()->A, ()->B) unzip(()->(A,B) gen) = unsafeUnzip(gen); /** * Converts a generator which yields 3-tuples into into a 3-tuple * containing 3 generators. */ <A,B,C> (()->A, ()->B, ()->C) unzip(()->(A,B,C) gen) = unsafeUnzip(gen); /** * Converts a generator which yields 4-tuples into into a 4-tuple * containing 4 generators. */ <A,B,C,D> (()->A, ()->B, ()->C, ()->D) unzip(()->(A,B,C,D) gen) = unsafeUnzip(gen); /** * Returns a new generator made up of elements from the original * generator which pass the test function. The first element which * doesn't pass the test function marks the end of the new generator, * and the item that failed is not included in the new generator. */ <A> ()->A takeWhile(()->A gen, A->boolean test) = ()=> { let value = gen(); if (test(value)) return value; else return stop(); }; /** * The reverse of takeWhile, this function returns a new generator * based on the original generator, but with all the leading elements * which pass the test function removed. */ <A> ()->A dropWhile(()->A gen, A->boolean test) { var failed = false; return ()=> { if (failed) return gen(); while(!failed) { let value = gen(); if (!test(value)) { failed = true; return value; } } return gen(); }; } /** * Returns a new generator which has the first <i>number</i> elements * from the original generator. */ <A> ()->A take(()->A gen, int number) requires number >= 0 { return gen.takeWhile(A a => number-- > 0); } /** * Returns a new generator which has the same contents as the original * generator, but without the first <i>number</i> elements. */ <A> ()->A drop(()->A gen, int number) requires number >= 0 { return gen.dropWhile(A a => number-- > 0); } /** * Blends two generators together, taking an element from the * first, then from the second, then again from the first, etc. */ <A> ()->A blend(()->A one, ()->A two) { boolean first = true; return () => { var A item = first ? one() : two(); first = !first; return item; }; } /** * Joins the second generator to the first. That is, produces a new * generator which yields all the elements in the first generator, * followed by all the elements in the second generator. */ <A> ()->A concat(()->A first, ()->A second) { var failed = false; return () => { if (failed) return second(); else try { return first(); } catch (GeneratorEnd e) { failed = true; return second(); } }; } /** * Returns two generators based on the generator argument - the first * generator contains all the elements of the original generator that * passed the test, until one failed. All the remaining items in the * original generator now appear in the second generator. */ <A> (()->A, ()->A) span(()->A gen, A-> boolean test) { var failed = false; LinkedList<A> passed = new LinkedList(); return (() => { if (!passed.isEmpty) return passed.removeFirst(); else { if (failed) return stop(); else { let value = gen(); if (test(value)) return value; else { failed = true; gen = (() => { return value; }).concat(gen); } } } return stop(); }, () => { while(!failed) { let value = gen(); if (test(value)) passed.add(value); else { failed = true; return value; } } return gen(); }); } /** * Returns two generators based on the generator argument - the first * generator contains all the elements of the original generator that * passed the test. Those elements that didn't pass the test will * appear in the second generator. */ <A> (()->A, ()->A) partition(()->A gen, A-> boolean test) { let LinkedList<A> passed = new LinkedList(); let LinkedList<A> failed = new LinkedList(); void load() { let v = gen(); if (test(v)) passed.add(v); else failed.add(v); } return ( () => { while (passed.isEmpty) load(); return passed.removeFirst(); }, () => { while (failed.isEmpty) load(); return failed.removeFirst(); } ); } /** * Like a for loop. */ <T> void times(int max, int->void func) { int counter = 0; while(counter < max) { try { func(counter++); } catch (GeneratorEnd e) { return; } } } /** * Like a for loop. */ <T> void times(int max, void->void func) { int counter = 0; while(counter < max) { try { func(); counter++; } catch (GeneratorEnd e) { return; } } } // ---- Some handy functions for testing ---- /** * A generator which yields natural numbers. */ ()->int naturals() { var int num = 1; return (()=>num++); } /** * Is the number even? */ private boolean _even(int num) = num % 2 == 0; /** * Is the number odd? */ private boolean _odd(int num) = !_even(num); --- NEW FILE: iterator.nice --- /**************************************************************************/ /* 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 */ /* it under the terms of the GNU Lesser General Public License as */ /* published by the Free Software Foundation; either version 2 of the */ /* License, or (at your option) any later version. */ /* */ /**************************************************************************/ /** A library for dealing with iterators - either Java-style <code>Iterator<T%gt;</code>s (in iterator.nice), or Nice-style ()->T generators (in generator.nice) @author Bryn Keller (xo...@us...) */ /** * Creates an <code>Iterator</code> from a function. * The function should call <code>stop()</code> to indicate * that the iteraton should stop. */ <A> Iterator<A> iterator(()->A func) = new FunctionIterator(func: func); /** * Maps a function over an iterator, producing a new iterator. */ <A,B> Iterator<B> map(Iterator<A> it, A->B xform) = iterator(() => xform(it.next())); /** * Produces a new iterator which only yields elements of the initial * iterator that pass the test function. * * @param it the original iterator * @param filt the function that tests whether an item should be * in the new iterator. */ <A> Iterator<A> filter(Iterator<A> it, A->boolean filt) = iterator(()=> { while (it.hasNext()) { let item = it.next(); if (filt(item)) { return item; } } return stop(); }); /** * Folds an iterator. For example, * <pre> * int sum(Iterator<int> it) = it.fold(`+`, 0); * </pre> * * @see nice.lang#foldLeft */ <A,B> B fold(Iterator<A> it, (B,A)->B foldfunc, B start) { while(it.hasNext()) { start = foldfunc(start, it.next()); } return start; } /** * Folds an iterator. For example, * <pre> * int sum(Iterator<int> it) = it.fold1(`+`); * </pre> * * @see nice.lang#foldLeft */ <A> A fold1(Iterator<A> it, (A,A)->A foldfunc) { A start = it.next(); while(it.hasNext()) { start = foldfunc(start, it.next()); } return start; } /** * Checks that all elements of an iterator are members of a given predicate. * Stops executing as soon as one element fails the test. */ <A> boolean all(Iterator<A> iter, A->boolean predicate) { try { while(iter.hasNext()) { if (!predicate(iter.next())) return false; } return true; } catch(GeneratorEnd e) { return true; } } /** * Checks that at least one element of an iterator is a member of a given * predicate. Stops executing as soon as one element passes the test. */ <A> boolean any(Iterator<A> iter, A->boolean predicate) { try { while(iter.hasNext()) { if (predicate(iter.next())) return true; } return false; } catch(GeneratorEnd e) { return false; } } /** * Calls a function once for each item in an <code>Iterator</code>. * If you want to keep the results of the function calls, use <code>map</code> * instead. * * @see map */ <A> void foreach(Iterator<A> it, A->void func) { while(it.hasNext()) func(it.next()); } /** * Creates a <code>List</code> from the elements of an iterator. */ <A> List<A> toList(Iterator<A> it) { let List<A> list = new ArrayList(); list.addAll(it); return list; } /** * Add all the elements of an itertor to a collection. */ <A> void addAll(Collection<A> coll, Iterator<A> it) { while(it.hasNext()) coll.add(it.next()); } /** * Converts 2 iterators into a single iterator * that yields 2-tuples. */ <A,B> Iterator<(A,B)> zip(Iterator<A> one, Iterator<B> two) = iterator(zip(one.generator, two.generator)); /** * Converts 3 iterators into a single iterator * that yields 3-tuples. */ <A,B,C> Iterator<(A,B,C)> zip(Iterator<A> one, Iterator<B> two, Iterator<C> three) = iterator(zip(one.generator, two.generator, three.generator)); /** * Converts 4 iterators into a single iterator * that yields 4-tuples. */ <A,B,C,D> Iterator<(A,B,C,D)> zip(Iterator<A> one, Iterator<B> two, Iterator<C> three, Iterator<D> four) = iterator(zip(one.generator, two.generator, three.generator, four.generator)); /** * Converts an iterator which yields 2-tuples into into a 2-tuple * containing 2 iterators. */ <A,B> (Iterator<A>, Iterator<B>) unzip(Iterator<(A,B)> it) { (void->A one, void->B two) = unzip(it.generator); return (one.iterator, two.iterator); } /** * Converts an iterator which yields 2-tuples into into a 2-tuple * containing 3 iterators. */ <A,B,C> (Iterator<A>, Iterator<B>, Iterator<C>) unzip(Iterator<(A,B,C)> it) { (void->A one, void->B two, void->C three) = unzip(it.generator()); return (one.iterator, two.iterator, three.iterator); } /** * Converts an iterator which yields 2-tuples into into a 2-tuple * containing 4 iterators. */ <A,B,C,D> (Iterator<A>, Iterator<B>, Iterator<C>, Iterator<D>) unzip(Iterator<(A,B,C,D)> it) { (void->A one, void->B two, void->C three, void->D four) = unzip(it.generator()); return (one.iterator, two.iterator, three.iterator, four.iterator); } /** * Merges two iterators using the given zipper function. For example: * <pre> * println(zipWith(["hello, "].iterator, ["world"].iterator, * (String s1, String s2) => s1 + s2).next()); * </pre> * will print "hello, world". */ <A,B,C> Iterator<C> zipWith(Iterator<A> one, Iterator<B> two, (A,B)->C zipper) { return iterator(zipWith(generator(one), generator(two), zipper)); } /** * Merges three iterators using the given zipper function. * @see <A,B,C> Iterator<C> zipWith(Iterator<A>, Iterator<B>, (A,B)->C) */ <A,B,C,D> Iterator<D> zipWith(Iterator<A> one, Iterator<B> two, Iterator<C> three, (A,B,C)->D zipper) { return iterator(zipWith(generator(one), generator(two), generator(three), zipper)); } /** * Merges three iterators using the given zipper function. * @see <A,B,C> Iterator<C> zipWith(Iterator<A>, Iterator<B>, (A,B)->C) */ <A,B,C,D,E> Iterator<E> zipWith(Iterator<A> one, Iterator<B> two, Iterator<C> three, Iterator<D> four, (A,B,C,D)->E zipper) { return iterator(zipWith(generator(one), generator(two), generator(three), generator(four), zipper)); } /** * Returns a new iterator made up of elements from the original * iterator which pass the test function. The first element which * doesn't pass the test function marks the end of the new iterator, * and the item that failed is not included in the new iterator. */ <A> Iterator<A> takeWhile(Iterator<A> it, A->boolean test) = iterator(()=> { if (it.hasNext()) { let n = it.next(); if (test(n)) { return n; } } return stop(); }); /** * The reverse of takeWhile, this function returns a new iterator * based on the original iterator, but with all the leading elements * which pass the test function removed. */ <A> Iterator<A> dropWhile(Iterator<A> it, A->boolean test) { var failed = false; return iterator(()=> { if (failed) { if (it.hasNext()) { return it.next(); } } else { while (it.hasNext()) { let n = it.next(); if (!test(n)) { failed = true; return n; } } } return stop(); }); } /** * Returns a new iterator which has the first <i>number</i> elements * from the original iterator. */ <A> Iterator<A> take(Iterator<A> it, int number) requires number >= 0 { return iterator(()=> { if (number > 0) { number--; return it.next(); } return stop(); }); } /** * Returns a new iterator which has the same contents as the original * iterator, but without the first <i>number</i> elements. */ <A> Iterator<A> drop(Iterator<A> it, int number) requires number >= 0 { return iterator(()=> { while (number > 0) { number--; it.next(); } return it.next(); }); } /** * Blends two iterators together, taking an element from the * first, then from the second, then again from the first, etc. */ <A> Iterator<A> blend(Iterator<A> one, Iterator<A> two) { boolean first = true; return iterator( () => { var A item = cast(null); if (first) item = one.next(); else item = two.next(); first = !first; return item; }); } /** * Joins the second iterator to the first. That is, produces a new * iterator which yields all the elements in the first iterator, * followed by all the elements in the second iterator. */ <A> Iterator<A> concat(Iterator<A> first, Iterator<A> second) { return iterator(() => first.hasNext()? first.next() : second.next()); } /** * Returns two iterators based on the iterator argument - the first * iterator contains all the elements of the original iterator that * passed the test, until one failed. All the remaining items in the * original iterator now appear in the second iterator. */ <A> (Iterator<A>, Iterator<A>) span(Iterator<A> it, A-> boolean test) { (void->A left, void->A right) = it.generator().span(test); return (left.iterator(), right.iterator()); } /** * Returns two iterators based on the iterator argument - the first * iterator contains all the elements of the original iterator that * passed the test. Those elements that didn't pass the test will * appear in the second iterator. */ <A> (Iterator<A>, Iterator<A>) partition(Iterator<A> it, A-> boolean test) { (void->A pass, void->A fail) = it.generator.partition(test); return (pass.iterator, fail.iterator); } // ---- Some handy functions for testing ---- /** * An iterator which yields natural numbers. */ private Iterator<int> naturals_iter() { var int num = 1; return iterator(()=>num++); } // ---- Private implementation details ----- /** * This class wraps a function and turns it into an <code>Iterator.</code> * The function should throw <code>GeneratorEnd</code> to indicate * that the iteraton should stop. Use the <code>iterator</code> * function instead of using this class directly. * * @see iterator */ private class FunctionIterator<A> implements Iterator<A> { ()-> A func; A cache = cast(null); boolean cacheLoaded = false; boolean finished = false; hasNext() { if (cacheLoaded) return true; if (finished) return false; else { try { cache = (this.func)(); cacheLoaded = true; } catch (GeneratorEnd e) { finished = true; } catch (NoSuchElementException e) { finished = true; } return cacheLoaded; } } <A> next() { if (this.hasNext()) { A item = cache; cache = cast(null); cacheLoaded = false; return item; } else { throw new NoSuchElementException(); } } remove() { throw new UnsupportedOperationException(); } } /** * Synchronized wrapper around an <code>Iterator</code> */ // class SyncIterator<A> implements Iterator<A> // { // Iterator<A> inner; // synchronized next() // { // return inner.next(); // } // synchronized hasNext() // { // return inner.hasNext(); // } // synchronized remove() // { // return inner.remove(); // } // } void _testIterators() { var nats = naturals_iter(); let List<int> list = new ArrayList(); list.addAll(nats.take(10)); assert list.size() == 10; assert list[0] == 1; assert list[9] == 10; assert naturals_iter().take(10).drop(10).hasNext() == false; assert naturals_iter().takeWhile(int i => i < 11).toList().size() == 10; assert naturals_iter().dropWhile(int i => i < 11).next() == 11; nats = naturals_iter().map(int i => i + 2); assert nats.next() == 3; assert nats.next() == 4; nats = naturals_iter().filter(_even); assert nats.next() == 2; assert nats.next() == 4; assert nats.next() == 6; let (int,int)-> int intAdd = `+`; assert naturals_iter().take(5).fold(intAdd, 0) == 15; assert naturals_iter().take(5).fold1(intAdd) == 15; (Iterator<int> evens, Iterator<int> odds) = naturals_iter().partition(_even); assert evens.next() == 2; assert evens.next() == 4; assert odds.next() == 1; assert odds.next() == 3; (evens, odds) = naturals_iter().span(_even); assert !evens.hasNext(); assert odds.next() == 1; assert naturals_iter().take(10).concat( naturals_iter().take(10)).toList().size() == 20; (evens, odds) = naturals_iter().partition(_even); var it = odds.blend(evens); assert it.next() == 1; assert it.next() == 2; assert it.next() == 3; //Test fails due to compiler bug var zipped = zip(naturals_iter(), naturals_iter()); (int left, int right) = zipped.next(); assert left == right && left == 1; var Iterator<int> doubled = zipWith(naturals_iter(), naturals_iter(), intAdd); assert doubled.next() == 2; assert doubled.next() == 4; assert doubled.next() == 6; var Iterator<int> trebled = zipWith(naturals_iter(), naturals_iter(), naturals_iter(), (int a, int b, int c) => a + b + c); assert trebled.next() == 3; assert trebled.next() == 6; assert trebled.next() == 9; } void _testGenerators() { var nats = naturals(); let List<int> list = new ArrayList(); list.addAll(nats.take(10)); assert list.size() == 10: "" + list.size(); assert list[0] == 1; assert list[9] == 10; assert naturals().take(10).drop(10).iterator.hasNext() == false; assert naturals().takeWhile(int i => i < 11).toList().size() == 10; assert naturals().dropWhile(int i => i < 11)() == 11; nats = naturals().map(int i => i + 2); assert nats() == 3; assert nats() == 4; nats = naturals().filter(_even); assert nats() == 2; assert nats() == 4; assert nats() == 6; let (int,int)-> int intAdd = `+`; assert naturals().take(5).fold(intAdd, 0) == 15; // assert naturals().take(5).fold1(intAdd) == 15; (void->int evens, void->int odds) = naturals().partition(_even); assert evens() == 2; assert evens() == 4; assert odds() == 1; assert odds() == 3; (evens, odds) = naturals().span(_even); assert !evens.iterator.hasNext(); assert odds() == 1; assert naturals().take(10).concat(naturals().take(10)).toList().size() == 20; (evens, odds) = naturals().partition(_even); var it = odds.blend(evens); assert it() == 1; assert it() == 2; assert it() == 3; // Test fails due to compiler bug var zipped = zip(naturals(), naturals()); (int left, int right) = zipped(); assert left == right && left == 1; (void->int leftGen, void->int rightGen) = unzip(zip(naturals(), naturals())); left = leftGen(); right = rightGen(); assert left == right && left == 1; assert leftGen() == 2; assert leftGen() == 3; assert rightGen() == 2; var doubled = zipWith(naturals(), naturals(), intAdd); assert doubled() == 2; assert doubled() == 4; assert doubled() == 6; var trebled = zipWith(naturals(), naturals(), naturals(), (int a, int b, int c) => a + b + c); assert trebled() == 3; assert trebled() == 6; assert trebled() == 9; } // void main(String[] args) // { // try // { // assert 1 > 2; // throw new Exception("Assertions not enabled."); // } // catch(AssertionFailed e) { // //assertions enabled. // } // _testIterators(); // _testGenerators(); // println("Tests passed."); // } |
From: <xo...@pr...> - 2004-01-26 18:24:40
|
Update of /cvsroot/nice/Nice/stdlib/nice/functional In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13279/functional Log Message: Directory /cvsroot/nice/Nice/stdlib/nice/functional added to the repository |
From: <ar...@pr...> - 2004-01-26 13:15:08
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18833/F:/nice/src/bossa/syntax Modified Files: JavaClasses.java Log Message: Don't search further static fields in super- classes/interfaces when found one. Fixes problem with JFrame.EXIT_ON_CLOSE. Index: JavaClasses.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/JavaClasses.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** JavaClasses.java 23 Dec 2003 11:30:07 -0000 1.44 --- JavaClasses.java 26 Jan 2004 13:14:16 -0000 1.45 *************** *** 335,339 **** { if (! possibilities.contains(md.getSymbol())) ! possibilities.add(md.getSymbol()); } else --- 335,343 ---- { if (! possibilities.contains(md.getSymbol())) ! { ! possibilities.add(md.getSymbol()); ! //don't search in superclasses/interfaces to avoid ambiguities ! return; ! } } else |
From: <ar...@pr...> - 2004-01-26 13:15:08
|
Update of /cvsroot/nice/Nice/testsuite/compiler/classes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18833/F:/nice/testsuite/compiler/classes Modified Files: fields.testsuite Log Message: Don't search further static fields in super- classes/interfaces when found one. Fixes problem with JFrame.EXIT_ON_CLOSE. Index: fields.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/classes/fields.testsuite,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** fields.testsuite 15 Jan 2004 21:39:19 -0000 1.14 --- fields.testsuite 26 Jan 2004 13:14:16 -0000 1.15 *************** *** 122,123 **** --- 122,128 ---- /// Toplevel import java.io.*; + + /// PASS + /// Toplevel + import javax.swing.*; + let int x = JFrame.EXIT_ON_CLOSE; |
From: <bo...@pr...> - 2004-01-26 12:55:57
|
Update of /cvsroot/nice/Nice/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14070/web Modified Files: .htaccess Log Message: Redirect for the source download. Index: .htaccess =================================================================== RCS file: /cvsroot/nice/Nice/web/.htaccess,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** .htaccess 11 Dec 2003 23:48:54 -0000 1.15 --- .htaccess 26 Jan 2004 12:54:53 -0000 1.16 *************** *** 1,4 **** --- 1,5 ---- Redirect /Wiki http://nice.sourceforge.net/cgi-bin/twiki/view Redirect /Nice.tar http://prdownloads.sourceforge.net/nice/Nice-0.9.5-unix.tar.gz + Redirect /Nice-source.tar.gz http://prdownloads.sourceforge.net/nice/Nice-0.9.5-source.tar.gz Redirect /Nice.zip http://prdownloads.sourceforge.net/nice/Nice-0.9.5-windows.zip Redirect /nice.deb http://prdownloads.sourceforge.net/nice/nice_0.9.5-1_all.deb |