nice-commit Mailing List for The Nice Programming Language (Page 66)
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-12-16 07:44:11
|
Update of /cvsroot/nice/Nice/src/bossa/modules In directory sc8-pr-cvs1:/tmp/cvs-serv1890/src/bossa/modules Modified Files: Package.java Log Message: Make sure that definitions are not added after the AST has been constructed, since they would be ignored anyway. Also allow the memory to be reclaimed. Index: Package.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Package.java,v retrieving revision 1.107 retrieving revision 1.108 diff -C2 -d -r1.107 -r1.108 *** Package.java 15 Dec 2003 02:40:17 -0000 1.107 --- Package.java 16 Dec 2003 07:44:08 -0000 1.108 *************** *** 124,127 **** --- 124,128 ---- source.getDefinitions(definitions, shouldReload); this.ast = new AST(this, definitions); + definitions = null; compilation.addNumberOfDeclarations(ast.numberOfDeclarations()); |
From: <xo...@us...> - 2003-12-16 01:07:36
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang/iterator In directory sc8-pr-cvs1:/tmp/cvs-serv10079/iterator Log Message: Directory /cvsroot/nice/Nice/stdlib/nice/lang/iterator added to the repository |
Update of /cvsroot/nice/Nice/src/gnu/lists In directory sc8-pr-cvs1:/tmp/cvs-serv14927/nice/src/gnu/lists Removed Files: Sequence.java.in AbstractSequence.java.in Convert.java.in SimpleVector.java.in SeqPosition.java.in withCollections Log Message: Removed the java.in files in gnu/lists and changed the makefile for not using them anymore. --- Sequence.java.in DELETED --- --- AbstractSequence.java.in DELETED --- --- Convert.java.in DELETED --- --- SimpleVector.java.in DELETED --- --- SeqPosition.java.in DELETED --- --- withCollections DELETED --- |
From: <ar...@us...> - 2003-12-15 20:14:00
|
Update of /cvsroot/nice/Nice In directory sc8-pr-cvs1:/tmp/cvs-serv14927/nice Modified Files: Makefile Log Message: Removed the java.in files in gnu/lists and changed the makefile for not using them anymore. Index: Makefile =================================================================== RCS file: /cvsroot/nice/Nice/Makefile,v retrieving revision 1.132 retrieving revision 1.133 diff -C2 -d -r1.132 -r1.133 *** Makefile 30 Nov 2003 11:22:28 -0000 1.132 --- Makefile 15 Dec 2003 20:13:57 -0000 1.133 *************** *** 162,166 **** bootstrap: parser - cd src/gnu/lists && ./withCollections mkdir -p classes classes-inline -cd src/bossa/syntax && mv -f dispatch.java.bootstrap dispatch.java --- 162,165 ---- |
Update of /cvsroot/nice/Nice/src/gnu/lists In directory sc8-pr-cvs1:/tmp/cvs-serv9854/F:/nice/src/gnu/lists Modified Files: .cvsignore Added Files: AbstractSequence.java Convert.java SeqPosition.java Sequence.java SimpleVector.java Log Message: Added the converted versions of the java.in files. --- NEW FILE: AbstractSequence.java --- // -*-Java-*- // Copyright (c) 2001 Per M.A. Bothner and Brainfood Inc. // This is free software; for terms and warranty disclaimer see ./COPYING. package gnu.lists; import java.util.*; import java.util.Enumeration; /** * An AbstractSequence is used to implement Sequences, and almost all * classes that extend AbstractSequence will implement Sequence. * However, AbstractSequence itself does not implement Sequence. * This is so we can use AbstractSequence to implement classes that are * "sequence-like" (such as multi-dimesnional arrays) but are not Sequences. * * Additionally, a sequence may have zero or more attributes, which are * name-value pairs. A sequence may also have a named "type". These * extensions are to support XML functionality - it might be cleaner to * moe them to a sub-class of Sequence or some interface. * * Many of the protected methods in Sequence (such as nextIndex) are * only intended to be called from SeqPosition or TreePosition, see those. * * @author Per Bothner */ public abstract class AbstractSequence { /** See java.util.List. */ public abstract int size(); public boolean isEmpty() { return size() > 0; } public int rank() { return 1; } /** See java.util.List. */ public abstract Object get (int index); public int getEffectiveIndex(int[] indexes) { return indexes[0]; } public Object get(int[] indexes) { return get(indexes[0]); } public Object set(int[] indexes, Object value) { return set(indexes[0], value); } protected RuntimeException unsupported (String text) { text = getClass().getName() + " does not implement " + text; return new UnsupportedOperationException(text); } public Object set(int index, Object element) { throw unsupported("set"); } public void fill(Object value) { SeqPosition it = getIterator(); while (gotoNext(it)) setPrevious(it.ipos, it.xpos, value); it.finalize(); } public void fill(int fromIndex, int toIndex, Object value) { for (int i = fromIndex; i < toIndex; i++) set(i, value); } // FIXME? //public final Object elementAt (int index) { return get(index); } /** See java.util.List. */ public int indexOf(Object o) { int i = 0; SeqPosition it = getIterator(); for (; it.hasNext(); i++) { Object e = it.next(); if (o==null ? e==null : o.equals(e)) return i; } return -1; } /** See java.util.List. */ public int lastIndexOf(Object o) { // FIXME use iterator? for (int n = size(); --n >= 0; ) { Object e = get(n); if (o==null ? e == null : o.equals(e)) return n; } return -1; } /** See java.util.List. */ public boolean contains(Object o) { SeqPosition i = getIterator(); while (i.hasNext()) { Object e = i.next(); if (o==null ? e==null : o.equals(e)) return true; } return false; } /** See java.util.List. */ public boolean containsAll(Collection c) { SeqPosition i = getIterator(); while (i.hasNext()) { Object e = i.next(); if (! contains(e)) return false; } return true; } public Enumeration elements() { SeqPosition it = new SeqPosition(); makeStartPosition(it); return it; } public SeqPosition getIterator() { SeqPosition it = new SeqPosition(); makeStartPosition(it); return it; } public Iterator iterator() { SeqPosition it = new SeqPosition(); makeStartPosition(it); return it; } public ListIterator listIterator() { return listIterator(0); } public ListIterator listIterator(int index) { SeqPosition it = new SeqPosition(); makePosition(index, it); return it; } protected void add(PositionContainer posSet, int posNumber, Object value) { throw unsupported("add"); } /** See java.util.Collection. */ public boolean add(Object o) { add(size(), o); return true; } /** See java.util.List. */ public void add(int index, Object o) { throw unsupported("add single Object at index"); } /** See java.util.Collection. */ public boolean addAll(Collection c) { return addAll(size(), c); } /** See java.util.Collection. */ public boolean addAll(int index, Collection c) { boolean changed = false; for (Iterator it = c.iterator(); it.hasNext(); ) { add(index++, it.next()); changed = true; } return changed; } /** * Remove one or more elements. * @param ipos integer part of position where elements should be removed * @param xpos object part of position where elements should be removed * @param count if non-negative, remove that number of elements * following (poses, posNumber); if negative the negative of the number * of elements to remove before (poses, posNumber). * @return number of elements actually removed (non-negative) * @exception java.lang.IndexOutOfBoundsException * if (count >= 0 ? (index < 0 || index + count > size()) * : (index + count < 0 || index > size())), * where index == nextIndex(ipos, xpos). */ protected void remove(int ipos, Object xpos, int count) { SeqPosition it = new SeqPosition(this); makeRelativePosition(ipos, xpos, count, true, it, 0); if (count >= 0) remove (ipos, xpos, it.ipos, it.xpos); else remove (it.ipos, it.xpos, ipos, xpos); } /** Remove a range where each end-point is a position in a container. * @param ipos0 integer part of start of range * @param xpos0 object part of start of range * @param ipos1 integer part of end of range * @param xpos1 object part of end of range * @exception java.lang.IndexOutOfBoundsException * if nextIndex(ipos0, xpos0) > nextIndex(ipos1, xpos1) * || nextIndex(ipos0, xpos0) < 0 || nextIndex(ipos1, xpos1) > size() */ protected void remove(int ipos0, Object xpos0, int ipos1, Object xpos1) { throw unsupported("remove (with range)"); } public Object remove(int index) { if (index < 0 || index >= size()) throw new IndexOutOfBoundsException(); SeqPosition it = new SeqPosition(this); makePosition(index, it); Object result = getNext(it.ipos, it.xpos); remove(it.ipos, it.xpos, 1); return result; } public boolean remove(Object o) { int index = indexOf(o); if (index < 0) return false; SeqPosition it = new SeqPosition(); makePosition(index, it); remove(it.ipos, it.xpos, 1); return true; } public boolean removeAll(Collection c) { boolean changed = false; for (SeqPosition it = getIterator(); it.hasNext(); ) { Object value = it.next(); if (c.contains(value)) { it.remove(); changed = true; } } return changed; } public boolean retainAll(Collection c) { boolean changed = false; for (SeqPosition it = getIterator(); it.hasNext(); ) { Object value = it.next(); if (! c.contains(value)) { it.remove(); changed = true; } } return changed; } public void clear() { SeqPosition it = new SeqPosition(); makeStartPosition(it); remove(it.ipos, it.xpos, size()); } /** Does the position pair have the "isAfter" property? * I.e. if something is inserted at the position, will * the iterator end up being after the new data? */ protected boolean isAfter(int ipos, Object xpos) { return false; } protected final void makePosition(int index, SeqPosition pos) { makePosition(index, true, pos); } /** Generate a position at a given index. * @param index offset from beginning of desired position * @param isAfter should the position have the isAfter property * @param pos where to store the generated position * This old position should be already released, if needed. * @exception IndexOutOfBoundsException if index is out of bounds */ public void makePosition(int index, boolean isAfter, SeqPosition pos) { makePosition(index, isAfter, pos, 0); } /** Generate a position at a given index. * @param index offset from beginning of desired position * @param isAfter should the position have the isAfter property * @param posSet where to store the generated position * @param posNumber index in posSet for the generated position. Any old * position there should be alread released, if needed. * @exception IndexOutOfBoundsException if index is out of bounds */ protected abstract void makePosition(int index, boolean isAfter, PositionContainer posSet, int posNumber); /** Generate a position relative to an existing position. * @param istart int part of initial position * @param xstart object part of initial position * @param offset offset from (istart,xstart) of desired position * @param isAfter should the position have the isAFter property * @param posSet where to store the generated position * @param positionNumber index in posSet for the generated position. Any * old position there should be alread released, if needed. * @exception IndexOutOfBoundsException if resulting index is out of bounds */ protected void makeRelativePosition(int istart, Object xstart, int offset, boolean isAfter, PositionContainer posSet, int posNumber) { makePosition(nextIndex(istart, xstart) + offset, isAfter, posSet, posNumber); } public void makeStartPosition(SeqPosition pos) { makeStartPosition(pos, 0); } /** Set a position to the start of this sequence. */ protected void makeStartPosition(PositionContainer poses, int positionNumber) { makePosition(0, false, poses, positionNumber); } /** Set a position to the end of this sequence. */ public void makeEndPosition(SeqPosition pos) { makeEndPosition(pos, 0); pos.setSequence(0, this); // FIXME - handled by caller? } protected void makeEndPosition(PositionContainer poses, int positionNumber) { makePosition(size(), true, poses, positionNumber); } /** * Reclaim any resources used by the given position pair. * @param ipos integer part of the position being free'd. * @param xpos Object part of the position being free'd. */ protected void releasePosition(int ipos, Object xpos) { } protected final void releasePosition(SeqPosition pos) { releasePosition(pos.ipos, pos.xpos); } protected void releasePosition(PositionContainer posSet, int posNumber) { int ipos = posSet.getPositionInt(posNumber); Object xpos = posSet.getPositionPtr(posNumber); releasePosition(ipos, xpos); } /** Make a copy of a position pair. * For simple positions this is a simple copy (assignment). * However, if the positions are magic cookies that are actively managed * by the sequence (as opposed to for example a simple index), then making * a copy may need to increment a reference count, or maybe allocate a * new position pair. In any case, the new pair is initialized to the * same offset (and isAfter property) as the original. * @param ipos integer part of the position being copied. * @param xpos Object part of the position being copied. * @param posSet where to put the new copy * @param posNumber which psoition in posSet that gets the copy. */ public void copyPosition(int ipos, Object xpos, PositionContainer posSet, int posNumber) { /* makePosition(nextIndex(ipos, xpos), isAfter(ipos, xpos), posSet, posNumber); */ posSet.setSequence(posNumber, this); posSet.setPosition(posNumber, ipos, xpos); } /** Get offset of (ipos1,xpos1) relative to (ipos0,xpos0). */ protected int getIndexDifference(int ipos1, Object xpos1, int ipos0, Object xpos0) { return nextIndex(ipos1, xpos1) - nextIndex(ipos0, xpos0); } /** * Get the offset from the beginning corresponding to a position pair. * Note default implementation only works for array-like sequences! */ protected int nextIndex(int ipos, Object xpos) { throw unsupported("nextIndex"); } protected int fromEndIndex(int ipos, Object xpos) { return size() - nextIndex(ipos, xpos); } /** * Get the size of the (sub-) sequence containing a given position. * Normally the same as size(), but may be different if this Sequence * is a tree and the position points at an interior node. */ protected int getContainingSequenceSize(int ipos, Object xpos) { return size(); } /** Called by SeqPosition.hasNext. */ protected boolean hasNext(int ipos, Object xpos) { return nextIndex(ipos, xpos) != size(); } public int getNextKind(int ipos, Object xpos) { return hasNext(ipos, xpos) ? Sequence.OBJECT_VALUE : Sequence.EOF_VALUE; } public String getNextTypeName(int ipos, Object xpos) { return null; } public Object getNextTypeObject(int ipos, Object xpos) { return null; } /** Called by SeqPosition.hasPrevious. */ protected boolean hasPrevious(int ipos, Object xpos) { return nextIndex(ipos, xpos) != 0; } /** Move forward one element position. * @return true unless at end of sequence. */ public boolean gotoNext(PositionContainer posSet, int posNumber) { int ipos = posSet.getPositionInt(posNumber); Object xpos = posSet.getPositionPtr(posNumber); if (! hasNext(ipos, xpos)) return false; if (true) // FIXME if not managed positions makeRelativePosition(ipos, xpos, 1, true, posSet, posNumber); else { int index = nextIndex(ipos, xpos); releasePosition(posSet, posNumber); makePosition(index + 1, true, posSet, posNumber); } return true; } /** Potential optimization. */ public boolean gotoNext(SeqPosition pos) { return gotoNext(pos, 0); } /** Move backwards one element. * @return false iff already at beginning. */ protected boolean gotoPrevious(PositionContainer posSet, int posNumber) { int ipos = posSet.getPositionInt(posNumber); Object xpos = posSet.getPositionPtr(posNumber); if (! hasPrevious(ipos, xpos)) return false; if (true) // FIXME if not managed positions makeRelativePosition(ipos, xpos, -1, false, posSet, posNumber); else { int index = nextIndex(ipos, xpos); releasePosition(posSet, posNumber); makePosition(index - 1, false, posSet, posNumber); } return true; } /** Set position before first child (of the element following position). * @return true if there is a child sequence (which might be empty); * false if current position is end of sequence or following element * is atomic (cannot have children). */ public boolean gotoChildrenStart(TreePosition pos) { return false; } protected boolean gotoParent(TreePosition pos) { if (pos.depth < 0) return false; pos.pop(); return true; } public int getAttributeLength() { return 0; } public Object getAttribute(int index) { return null; } protected boolean gotoAttributesStart(TreePosition pos) { return false; } /** Get the element following the specified position. * @param ipos integer part of the specified position. * @param xpos Object part of the specified position. * @return the following element, or eofValue if there is none. * Called by SeqPosition.getNext. */ protected Object getNext(int ipos, Object xpos) { // wrong result if out of bounds FIXME return get(nextIndex(ipos, xpos)); } /** Get the element before the specified position. * @param ipos integer part of the specified position. * @param xpos Object part of the specified position. * @return the following element, or eofValue if there is none. * Called by SeqPosition.getNext. */ protected Object getPrevious(int ipos, Object xpos) { return get(nextIndex(ipos, xpos) - 1); } protected void setNext(int ipos, Object xpos, Object value) { int index = nextIndex(ipos, xpos); if (index >= size()) throw new IndexOutOfBoundsException(); set(index, value); } protected void setPrevious(int ipos, Object xpos, Object value) { int index = nextIndex(ipos, xpos); if (index == 0) throw new IndexOutOfBoundsException(); set(index - 1, value); } public final int nextIndex(SeqPosition pos) { return nextIndex(pos.ipos, pos.xpos); } /** Compare two positions, and indicate if the are the same position. */ public boolean equals(int ipos1, Object xpos1, int ipos2, Object xpos2) { return compare(ipos1, xpos1, ipos2, xpos2) == 0; } /** Compare two positions, and indicate their relative order. */ public int compare(int ipos1, Object xpos1, int ipos2, Object xpos2) { int i1 = nextIndex(ipos1, xpos1); int i2 = nextIndex(ipos2, xpos2); return i1 < i2 ? -1 : i1 > i2 ? 1 : 0; } public final int compare(SeqPosition i1, SeqPosition i2) { return compare(i1.ipos, i1.xpos, i2.ipos, i2.xpos); } public Object[] toArray() { int len = size(); Object[] arr = new Object[len]; java.util.Enumeration e = elements(); for (int i = 0; e.hasMoreElements(); i++) arr[i] = e.nextElement(); return arr; } public Object[] toArray(Object[] arr) { int alen = arr.length; int len = size(); if (len > alen) { Class componentType = arr.getClass().getComponentType(); arr = (Object[]) java.lang.reflect.Array.newInstance(componentType, len); alen = len; } java.util.Enumeration e = elements(); for (int i = 0; e.hasMoreElements(); i++) { arr[i] = e.nextElement(); } if (len < alen) arr[len] = null; return arr; } public int hashCode() { // Implementation specified by the Collections specification. int hash = 1; SeqPosition i = getIterator(); while (i.hasNext()) { Object obj = i.next(); hash = 31*hash + (obj==null ? 0 : obj.hashCode()); } return hash; } public boolean equals(Object o) { // Compatible with the Collections specification. // FIXME should also depend on class? if (! (o instanceof java.util.List)) return false; Iterator it1 = iterator(); Iterator it2 = ((java.util.List) o).iterator(); for (;;) { boolean more1 = it1.hasNext(); boolean more2 = it2.hasNext(); if (more1 != more2) return false; if (! more1) return true; Object e1 = it1.next(); Object e2 = it2.next(); if (e1 == null) { if (e2 != null) return false; } else if (! e1.equals(e2)) return false; } } public Sequence subSequence(SeqPosition start, SeqPosition end) { return subSequence(start.ipos, start.xpos, end.ipos, end.xpos); } protected Sequence subSequence(int ipos0, Object xpos0, int ipos1, Object xpos1) { SubSequence sub = new SubSequence(this); copyPosition(ipos0, xpos0, sub, 0); copyPosition(ipos1, xpos1, sub, 1); return sub; } public List subList(int fromIx, int toIx) { SubSequence sub = new SubSequence(this); makePosition(fromIx, false, sub, 0); makePosition(toIx, true, sub, 1); return sub; } /** Copy an element specified by a position pair to a Consumer. * @return if hasNext(ipos, xpos). */ public boolean consumeNext(int ipos, Object xpos, Consumer out) { if (! hasNext(ipos, xpos)) return false; out.writeObject(getNext(ipos, xpos)); return true; } protected void consume(int iposStart, Object xposStart, int iposEnd, Object xposEnd, Consumer out) { if (out.ignoring()) return; SeqPosition it = new SeqPosition(); copyPosition(iposStart, xposStart, it, 0); while (! equals(it.ipos, it.xpos, iposEnd, xposEnd)) { if (! it.hasNext()) throw new RuntimeException(); out.writeObject(it.nextElement()); } it.finalize(); } /* Consume wlements, without any beginGroup/endGroup. public void consumeElements() ... */ public void consume(Consumer out) { String typeName = "#sequence"; String type = typeName; out.beginGroup(typeName, type); java.util.Enumeration e = elements(); for (int i = 0; e.hasMoreElements(); i++) out.writeObject(e.nextElement()); out.endGroup(typeName); } } --- NEW FILE: Convert.java --- // -*-Java-*- // Copyright (c) 2001 Per M.A. Bothner and Brainfood Inc. // This is free software; for terms and warranty disclaimer see ./COPYING. package gnu.lists; /** * A class that encapsulates primitive<->Object conversions. * Applications can override the conversion if desired. * For example charToObject could use an "intern" table. */ public class Convert { public static Convert instance = new Convert(); public static Convert getInstance() { return instance; } public static void setInstance(Convert value) { instance = value; }; public Object booleanToObject(boolean value) { return value ? Boolean.TRUE : Boolean.FALSE; } public boolean objectToBoolean(Object obj) { return ! (obj instanceof Boolean) || ((Boolean) obj).booleanValue(); } public static Object toObject(boolean value) { return instance.booleanToObject(value); } public static boolean toBoolean(Object obj) { return instance.objectToBoolean(obj); } public Object charToObject(char ch) { return new Character(ch); } public char objectToChar(Object obj) { return ((Character) obj).charValue(); } public static Object toObject(char ch) { return instance.charToObject(ch); } public static char toChar(Object obj) { return instance.objectToChar(obj); } public Object byteToObject(byte value) { return new Byte(value); } public byte objectToByte(Object obj) { return ((Number) obj).byteValue(); } public static Object toObject(byte value) { return instance.byteToObject(value); } public static byte toByte(Object obj) { return instance.objectToByte(obj); } public Object byteToObjectUnsigned(byte value) { return new Integer(value & 0xFF); } public byte objectToByteUnsigned(Object obj) { return ((Number) obj).byteValue(); } public static Object toObjectUnsigned(byte value) { return instance.byteToObjectUnsigned(value); } public static byte toByteUnsigned(Object obj) { return instance.objectToByteUnsigned(obj); } public Object shortToObject(short value) { return new Short(value); } public short objectToShort(Object obj) { return ((Number) obj).shortValue(); } public static Object toObject(short value) { return instance.shortToObject(value); } public static short toShort(Object obj) { return instance.objectToShort(obj); } public Object shortToObjectUnsigned(short value) { return new Integer(value & 0xFFFF); } public short objectToShortUnsigned(Object obj) { return ((Number) obj).shortValue(); } public static Object toObjectUnsigned(short value) { return instance.shortToObjectUnsigned(value); } public static short toShortUnsigned(Object obj) { return instance.objectToShortUnsigned(obj); } public Object intToObject(int value) { return new Integer(value); } public int objectToInt(Object obj) { return ((Number) obj).intValue(); } public static Object toObject(int value) { return instance.intToObject(value); } public static int toInt(Object obj) { return instance.objectToInt(obj); } public Object intToObjectUnsigned(int value) { if (value >= 0) return new Integer(value); else return new Long((long) value & 0xffffffffL); } public int objectToIntUnsigned(Object obj) { return ((Number) obj).intValue(); } public static Object toObjectUnsigned(int value) { return instance.intToObjectUnsigned(value); } public static int toIntUnsigned(Object obj) { return instance.objectToIntUnsigned(obj); } public Object longToObject(long value) { return new Long(value); } public long objectToLong(Object obj) { return ((Number) obj).longValue(); } public static Object toObject(long value) { return instance.longToObject(value); } public static long toLong(Object obj) { return instance.objectToLong(obj); } public Object longToObjectUnsigned(long value) { return new Long(value); // FIXME use BigInteger? } public long objectToLongUnsigned(Object obj) { return ((Number) obj).longValue(); } public static Object toObjectUnsigned(long value) { return instance.longToObjectUnsigned(value); } public static long toLongUnsigned(Object obj) { return instance.objectToLongUnsigned(obj); } public Object floatToObject(float value) { return new Float(value); } public float objectToFloat(Object obj) { return ((Number) obj).floatValue(); } public static Object toObject(float value) { return instance.floatToObject(value); } public static float toFloat(Object obj) { return instance.objectToFloat(obj); } public Object doubleToObject(double value) { return new Double(value); } public double objectToDouble(Object obj) { return ((Number) obj).doubleValue(); } public static Object toObject(double value) { return instance.doubleToObject(value); } public static double toDouble(Object obj) { return instance.objectToDouble(obj); } public static double parseDouble(String str) { // We assume that if collections are available the Double.parseDouble // is also available. return Double.parseDouble(str); } } --- NEW FILE: SeqPosition.java --- // -*-Java-*- // Copyright (c) 2001 Per M.A. Bothner and Brainfood Inc. // This is free software; for terms and warranty disclaimer see ./COPYING. package gnu.lists; import java.util.NoSuchElementException; /** * A position in a sequence (list). * * Conceptually similar to Java2's ListIterator, but we use the name "Position" * to indicate that it can be used to both indicate a position in a sequence * and to iterate through a sequence. If you use a SeqPosition as a * "position", you would not modify if (though it is possible the offset * of the position in the sequence may change due to other update operations * on the sequence). If you use a SeqPosition as an "iterator", you would * initialize it to some beginnning position, and then modify the current * position of the SeqPosition so it refers to successive elements. * * See the <a href="package-summary.html#iteration">package overview</a> * for more information. */ public class SeqPosition implements java.util.ListIterator, PositionContainer, java.util.Enumeration { /** * The Sequence relative to which ipos and xpos have meaning. * This is normally the same as the Sequence we iterate through. * However, if this is a TreePosition, it may an ancestor instead. */ public AbstractSequence sequence; /** * An integer that (together with xpos) indicates the current position. * The actual value has no meaning, except as interpreted by sequence. */ public int ipos; /** * An Object that (together with ipos) indicates the current position. * The actual value has no meaning, except as interpreted by sequence. */ public Object xpos; public SeqPosition() { } public SeqPosition(AbstractSequence seq) { this.sequence = seq; } public SeqPosition(AbstractSequence seq, int offset, boolean isAfter) { this.sequence = seq; seq.makePosition(offset, isAfter, this, 0); } public SeqPosition(AbstractSequence seq, int ipos, Object xpos) { this.sequence = seq; this.ipos = ipos; this.xpos = xpos; } /** Creates a new SeqPosition, from a position triple. * The position triple is copied (using copyPosition). */ public static SeqPosition make(AbstractSequence seq, int ipos, Object xpos) { SeqPosition pos = new SeqPosition(); seq.copyPosition(ipos, xpos, pos, 0); return pos; } public final void gotoStart(AbstractSequence seq) { if (sequence != null) sequence.releasePosition(ipos, xpos); sequence = seq; seq.makeStartPosition(this, 0); } public final void gotoEnd(AbstractSequence seq) { if (sequence != null) sequence.releasePosition(ipos, xpos); sequence = seq; seq.makeEndPosition(this, 0); } /** True if there is an element following the current position. * False if we are at the end. See java.util.Enumeration. */ public boolean hasMoreElements() { return sequence.hasNext(ipos, xpos); } /** See java.util.Iterator. */ public boolean hasNext() { return sequence.hasNext(ipos, xpos); } /** Return a code (defined in Sequence) for the type of the next element. */ public int getNextKind() { return sequence.getNextKind(ipos, xpos); } /** Get the "tag name" for the next element, if any. */ public String getNextTypeName() { return sequence.getNextTypeName(ipos, xpos); } /** Get the "tag object" for the next element, if any. */ public Object getNextTypeObject() { return sequence.getNextTypeObject(ipos, xpos); } /** See java.util.Iterator. */ public boolean hasPrevious() { return sequence.hasPrevious(ipos, xpos); } /** See java.util.ListIterator. */ public Object next() { Object result = sequence.getNext(ipos, xpos); if (result == Sequence.eofValue || ! sequence.gotoNext(this)) throw new NoSuchElementException(); return result; } /** Move one element forwards, if possible. * @returns if we succeeded in moving forwards (i.e. not at end of sequence). */ public final boolean gotoNext() { return sequence.gotoNext(this); } /** See java.util.ListIterator. */ public Object previous() { Object result = sequence.getPrevious(ipos, xpos); if (result == Sequence.eofValue || ! sequence.gotoPrevious(this, 0)) throw new NoSuchElementException(); return result; } /** See java.util.Enumeration. */ public Object nextElement() throws NoSuchElementException { Object result = sequence.getNext(ipos, xpos); if (result == Sequence.eofValue || ! sequence.gotoNext(this)) throw new NoSuchElementException(); return result; } /** * Get element following current position. * Does not move the position, in contrast to nextElement method. * @return EOF if at end of sequence, otherwise the value following. */ public Object getNext() { return sequence.getNext(ipos, xpos); } public Object getPrevious() { return sequence.getPrevious(ipos, xpos); } /** See java.util.Iterator. */ public final int nextIndex() { return sequence.nextIndex(ipos, xpos); } public final int fromEndIndex() { return sequence.fromEndIndex(ipos, xpos); } public int getContainingSequenceSize() { return sequence.getContainingSequenceSize(ipos, xpos); } /** See java.util.Iterator. */ public final int previousIndex() { return sequence.nextIndex(ipos, xpos) - 1; } /** Does the position pair have the "isAfter" property? * I.e. if something is inserted at the position, will * the iterator end up being after the new data? * A toNext() or next() command should set isAfter() to true; * a toPrevious or previous command should set isAfter() to false. */ public final boolean isAfter() { return sequence.isAfter(ipos, xpos); } public final void set(Object value) { if (sequence.isAfter(ipos, xpos)) sequence.setPrevious(ipos, xpos, value); else sequence.setNext(ipos, xpos, value); } public void remove() { sequence.remove(ipos, xpos, isAfter() ? -1 : 1); } public void add(Object o) { sequence.add(this, 0, o); } /** Implements PositionContainer. */ public int getPositionInt(int positionNumber) { return ipos; } /** Implements PositionContainer. */ public Object getPositionPtr(int positionNumber) { return xpos; } /** Implements PositionContainer. */ public void setPosition(int positionNumber, int ipos, Object xpos) { this.ipos = ipos; this.xpos = xpos; } /** Implements PositionContainer. */ public void setSequence(int positionNumber, AbstractSequence seq) { sequence = seq; } /** Implements PositionContainer. */ public int countPositions() { return 1; } public void init(AbstractSequence seq, int index, boolean isAfter) { if (sequence != null) sequence.releasePosition(ipos, xpos); sequence = seq; seq.makePosition(index, isAfter, this, 0); } public void init(SeqPosition pos) { if (sequence != null) sequence.releasePosition(ipos, xpos); sequence = pos.sequence; sequence.copyPosition(pos.ipos, pos.xpos, this, 0); } public void release() { if (sequence != null) { sequence.releasePosition(ipos, xpos); sequence = null; } } public void finalize() { release(); } public String toString() { StringBuffer sbuf = new StringBuffer(60); sbuf.append('{'); if (sequence == null) sbuf.append("null sequence"); else { sbuf.append(sequence.getClass().getName()); sbuf.append('@'); sbuf.append(System.identityHashCode(sequence)); } sbuf.append(" ipos: "); sbuf.append(ipos); sbuf.append(" xpos: "); sbuf.append(xpos); sbuf.append('}'); return sbuf.toString(); } } // This is for people using the Emacs editor: // Local Variables: // c-file-style: "gnu" // tab-width: 8 // indent-tabs-mode: t // End: --- NEW FILE: Sequence.java --- // -*-Java-*- // Copyright (c) 2001 Per M.A. Bothner and Brainfood Inc. // This is free software; for terms and warranty disclaimer see ./COPYING. package gnu.lists; import java.util.*; /** * A Sequence is an ordered list of elements. * It is similar to and compatible with the Java2 java.util.List interface, * but does not require it. * * All standard classes that implement Sequence also extend AbstractSequence. * Using AbstractSequence provides default implementations for many methods, * and also makes things a bit more efficient. However, client code should * use Sequence rather than AbstractSequence. * * @author Per Bothner */ public interface Sequence extends java.util.List, Array, Consumable { /** Special magic end-of-file marker. */ public static final Object eofValue = new String[] { "(EOF)" }; /** True is this sequence contains no elements. */ public boolean isEmpty(); /** See java.util.List. */ public int size(); /** See java.util.List. */ public Object get (int index); public void fill(Object value); public java.util.Enumeration elements(); /** Return code used to indicate a position is at end of the sequence. */ public static final int EOF_VALUE = 0; public static final int PRIM_VALUE = 16; public static final int INT_U8_VALUE = PRIM_VALUE + 1; public static final int INT_S8_VALUE = PRIM_VALUE + 2; public static final int INT_U16_VALUE = PRIM_VALUE + 3; public static final int INT_S16_VALUE = PRIM_VALUE + 4; public static final int INT_U32_VALUE = PRIM_VALUE + 5; public static final int INT_S32_VALUE = PRIM_VALUE + 6; public static final int INT_U64_VALUE = PRIM_VALUE + 7; public static final int INT_S64_VALUE = PRIM_VALUE + 8; /** Return code used to indicate next element is 32-bit float. */ public static final int FLOAT_VALUE = PRIM_VALUE + 9; /** Return code used to indicate next element is 64-bit double. */ public static final int DOUBLE_VALUE = PRIM_VALUE + 10; public static final int BOOLEAN_VALUE = PRIM_VALUE + 11; /** A byte in an encoded string. * Part of a char, in contrast with INT_S8_VALUE, which is an integer. */ public static final int TEXT_BYTE_VALUE = PRIM_VALUE + 12; public static final int CHAR_VALUE = PRIM_VALUE + 13; public static final int OBJECT_VALUE = 32; public static final int GROUP_VALUE = 33; public static final int DOCUMENT_VALUE = 34; public static final int ATTRIBUTE_VALUE = 35; /* public static final int NAMESPACE_ATTRIBUTE_VALUE = 16; public static final int COMMENT_VALUE = 16; public static final int PROCESSING_INSTRUCTION_VALUE = 16; public static final int ENTITY_REFERENCE_VALUE = 16; */ } --- NEW FILE: SimpleVector.java --- // -*-Java-*- // Copyright (c) 2001 Per M.A. Bothner and Brainfood Inc. // This is free software; for terms and warranty disclaimer see ./COPYING. package gnu.lists; import java.util.*; /** A SimpleVector implement as a simple array plus a current size. * * Methods with the word "Buffer" are methods which use the underlying * array, ignoring the 'size' field. * * Can be used to implement CommonLisp simple vectors, but all simple * vectors are also adjustable (by re-allocating the buffer) * and have a fill pointer (the size field). */ public abstract class SimpleVector extends AbstractSequence implements Sequence { /** The (current) number of elements. * Must always have size() >= 0 && size() <= getBufferLength(). */ public int size; public final int size() { return size; } /** * Set the size to a specified value. * The data buffer is grown if needed, with new elements set to zero/null. If * size is less than the current value, removed values are set to zero/null.. * (This is because if you decrease and then increase the vector the * should be zero/null, and it is cleaner and better for gc to do the * zeroing/nulling on remove rather than add.) * If you need to change the size without setting removed elements to * zero/null (e.g. to change Common Lisp's fill pointer) set size directly. */ public void setSize(int size) { int oldSize = this.size; this.size = size; if (size < oldSize) clearBuffer(size, oldSize - size); else { int oldLength = getBufferLength(); if (size > oldLength) { int newLength = oldLength < 16 ? 16 : 2 * oldLength; setBufferLength(size > newLength ? size : newLength); } } } /** Get the allocated length of the data buffer. */ public abstract int getBufferLength(); public abstract void setBufferLength(int length); protected boolean isAfter(int ipos, Object xpos) { return (ipos & 1) != 0; } protected int nextIndex(int ipos, Object xpos) { return ipos >>> 1; } public void makePosition(int index, boolean isAfter, PositionContainer posSet, int posNumber) { posSet.setPosition(posNumber, (index << 1) | (isAfter ? 1 : 0), null); posSet.setSequence(posNumber, this); } /* protected void ensureSize(int space) { int oldLength = data.length; int newLength = size + if (size > space) setBufferLength(space < 16 ? 16 : 2 * space); this.size = size; } */ protected abstract Object getBuffer(); public Object get(int index) { if (index >= size) throw new IndexOutOfBoundsException(); return getBuffer(index); } protected Object getNext(int ipos, Object xpos) { int index = ipos >>> 1; return index >= size ? eofValue : getBuffer(index); } public int intAtBuffer(int index) { return Convert.toInt(getBuffer(index)); } public int intAt(int index) { if (index >= size) throw new IndexOutOfBoundsException(); return intAtBuffer(index); } public long longAt(int index) { if (index >= size) throw new IndexOutOfBoundsException(); return longAtBuffer(index); } public long longAtBuffer(int index) { return Convert.toLong(getBuffer(index)); } protected abstract Object getBuffer(int index); public Object set(int index, Object value) { if (index >= size) throw new IndexOutOfBoundsException(); Object old = getBuffer(index); setBuffer(index, value); return old; } protected abstract Object setBuffer(int index, Object value); public void fill(Object value) { for (int i = size; --i >= 0; ) setBuffer(i, value); } public void fill(int fromIndex, int toIndex, Object value) { if (fromIndex < 0 || toIndex > size) throw new IndexOutOfBoundsException(); for (int i = fromIndex; i < toIndex; i++) setBuffer(i, value); } public void shift(int srcStart, int dstStart, int count) { Object data = getBuffer(); System.arraycopy(data, srcStart, data, dstStart, count); } public boolean add(Object o) { add(size, o); return true; } protected void add(PositionContainer posSet, int posNumber, Object value) { int ipos = posSet.getPositionInt(posNumber); add(ipos >>> 1, value); posSet.setPosition(posNumber, ipos + 2, null); } public void add(int index, Object o) { int newSize = size + 1; size = newSize; int length = getBufferLength(); if (newSize > length) setBufferLength(length < 16 ? 16 : 2 * length); this.size = newSize; if (size != index) shift(index, index + 1, size - index); set(index, o); } public boolean addAll(int index, Collection c) { boolean changed = false; int count = c.size(); setSize(size + count); shift(index, index + count, size - count - index); for (Iterator it = c.iterator(); it.hasNext(); ) { set(index++, it.next()); changed = true; } return changed; } protected abstract void clearBuffer(int start, int count); protected void remove(int ipos0, Object xpos0, int ipos1, Object xpos1) { ipos0 = ipos0 >>> 1; ipos1 = ipos1 >>> 1; if (ipos0 < 0 || ipos0 > ipos1 || ipos1 >= size) throw new IndexOutOfBoundsException(); shift(ipos1, ipos0, size - ipos1); int count = ipos1 - ipos0; size = size - count; clearBuffer(size, count); } protected void remove(int ipos, Object xpos, int count) { int index = ipos >>> 1; int ipos0, ipos1; if (count >= 0) { ipos0 = index; ipos1 = index + count; } else { ipos0 = index + count; ipos1 = index; count = - count; } if (ipos0 < 0 || ipos1 >= size) throw new IndexOutOfBoundsException(); shift(ipos1, ipos0, size - ipos1); size = size - count; clearBuffer(size, count); } public Object remove(int index) { if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); Object result = get(index); shift(index + 1, index, 1); size = size - 1; clearBuffer(size, 1); return result; } public boolean remove(Object o) { int index = indexOf(o); if (index < 0) return false; Object result = get(index); shift(index + 1, index, 1); size = size - 1; clearBuffer(size, 1); return true; } public boolean removeAll(Collection c) { boolean changed = false; int j = 0; for (int i = 0; i < size; i++) { Object value = get(i); if (c.contains(value)) { changed = true; } else { if (changed) set(j, value); j++; } } setSize(j); return changed; } public boolean retainAll(Collection c) { boolean changed = false; int j = 0; for (int i = 0; i < size; i++) { Object value = get(i); if (! c.contains(value)) { changed = true; } else { if (changed) set(j, value); j++; } } setSize(j); return changed; } public void clear () { setSize(0); } /** This is convenience hack for printing "uniform vectors" (srfi 4). * It may go away without notice! */ public String getTag() { return null; } public void consume(int start, int length, Consumer out) { consume(start << 1, null, (start + length) << 1, null, out); } public boolean consumeNext(int ipos, Object xpos, Consumer out) { int index = ipos >>> 1; if (index >= size) return false; out.writeObject(getBuffer(index)); return true; } protected void consume(int iposStart, Object xposStart, int iposEnd, Object xposEnd, Consumer out) { if (out.ignoring()) return; int i = iposStart >>> 1; int end = iposEnd >>> 1; for (; i < end; i++) out.writeObject(getBuffer(i)); } public int getNextKind(int ipos, Object xpos) { return hasNext(ipos, xpos) ? getElementKind() : EOF_VALUE; } public int getElementKind() { return OBJECT_VALUE; } } Index: .cvsignore =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/lists/.cvsignore,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** .cvsignore 30 Oct 2001 16:33:53 -0000 1.1 --- .cvsignore 15 Dec 2003 19:51:37 -0000 1.2 *************** *** 1,29 **** - - - - - - @author Daniel Bonniot (Dan...@in...) - @version $Date$ - */ - /* */ - /* */ - /* N I C E */ - /* (c) Daniel Bonniot 2001 */ - /* A high-level object-oriented research language */ - /* (at your option) any later version. */ - /* This program is free software; you can redistribute it and/or modify */ - /* it under the terms of the GNU General Public License as published by */ - /* the Free Software Foundation; either version 2 of the License, or */ - /** - /**************************************************************************/ - /**************************************************************************/ - AbstractSequence.java - Convert.java - SeqPosition.java - Sequence.java - SimpleVector.java - class - package gnu.lists; - { - } --- 0 ---- |
From: <bo...@us...> - 2003-12-15 19:06:34
|
Update of /cvsroot/nice/Nice/src/gnu/expr In directory sc8-pr-cvs1:/tmp/cvs-serv997/src/gnu/expr Modified Files: LambdaExp.java Log Message: Improved robustness. Index: LambdaExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/expr/LambdaExp.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** LambdaExp.java 27 Nov 2003 21:02:13 -0000 1.22 --- LambdaExp.java 15 Dec 2003 19:06:30 -0000 1.23 *************** *** 1173,1180 **** comp.generateConstructor(this); //ClassType type = getHeapFrameType(); // Is this more correct? ! code.emitNew(type); ! code.emitDup(type); ! code.emitInvokeSpecial(type.constructor); ! code.emitPutStatic(instanceField); } else if (this instanceof ClassExp) --- 1173,1183 ---- comp.generateConstructor(this); //ClassType type = getHeapFrameType(); // Is this more correct? ! if (type.constructor != null) ! { ! code.emitNew(type); ! code.emitDup(type); ! code.emitInvokeSpecial(type.constructor); ! code.emitPutStatic(instanceField); ! } } else if (this instanceof ClassExp) |
From: <bo...@us...> - 2003-12-15 19:06:33
|
Update of /cvsroot/nice/Nice/testsuite/compiler/functions In directory sc8-pr-cvs1:/tmp/cvs-serv997/testsuite/compiler/functions Modified Files: anonymous.testsuite Log Message: Improved robustness. Index: anonymous.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/functions/anonymous.testsuite,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** anonymous.testsuite 30 Nov 2003 14:24:35 -0000 1.9 --- anonymous.testsuite 15 Dec 2003 19:06:29 -0000 1.10 *************** *** 78,79 **** --- 78,88 ---- /// Toplevel <T> void foo(T->int f = T x => x) {} + + /// PASS + let t = new Test(); + assert (t.a)(t); + /// Toplevel + class Test { + Test->boolean a = f; + boolean f() = true; + } |
From: <bo...@us...> - 2003-12-15 16:19:50
|
Update of /cvsroot/nice/Nice/src/gnu/expr In directory sc8-pr-cvs1:/tmp/cvs-serv27562/src/gnu/expr Modified Files: InitializeProc.java Log Message: Allow custom constructors to call other custom constructors. Index: InitializeProc.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/expr/InitializeProc.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** InitializeProc.java 14 Dec 2003 16:52:32 -0000 1.2 --- InitializeProc.java 15 Dec 2003 16:19:47 -0000 1.3 *************** *** 27,31 **** public InitializeProc (Method constructor) { ! this(constructor, false); } --- 27,31 ---- public InitializeProc (Method constructor) { ! this(constructor, false, 0); } *************** *** 36,41 **** --- 36,52 ---- public InitializeProc (Method constructor, boolean implicitThis) { + this(constructor, implicitThis, 0); + } + + /** + @param implicitThis true if a 'this' argument should be added + during the call. + */ + public InitializeProc (Method constructor, boolean implicitThis, + int dummyArgs) + { this.constructor = constructor; this.implicitThis = implicitThis; + this.dummyArgs = dummyArgs; } *************** *** 58,61 **** --- 69,73 ---- private ConstructorExp method; private boolean implicitThis; + private int dummyArgs; public void compile (ApplyExp exp, Compilation comp, Target target) *************** *** 78,83 **** // Add dummy arguments to match the bytecode constructor. if (method != null) ! for (int i = 0; i < method.dummyArgs; i++) code.emitPushInt(0); --- 90,97 ---- // Add dummy arguments to match the bytecode constructor. + if (method !=null) + dummyArgs = method.dummyArgs; if (method != null) ! for (int i = 0; i < dummyArgs; i++) code.emitPushInt(0); |
From: <bo...@us...> - 2003-12-15 16:19:50
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv27562/src/bossa/syntax Modified Files: CustomConstructor.java Log Message: Allow custom constructors to call other custom constructors. Index: CustomConstructor.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/CustomConstructor.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CustomConstructor.java 15 Dec 2003 02:40:17 -0000 1.7 --- CustomConstructor.java 15 Dec 2003 16:19:47 -0000 1.8 *************** *** 41,51 **** } CustomConstructor(NiceClass def, FormalParameters parameters) { ! super(new LocatedString("<init>", def.definition.location()), ! Constraint.True, ! returnType(def.definition.getName()), ! parameters, ! Contract.noContract); classe = def; } --- 41,61 ---- } + void addConstructorCallSymbol() + { + mlsub.typing.Polytype type = new mlsub.typing.Polytype + (getType().getConstraint(), + new mlsub.typing.FunType(getArgTypes(), PrimitiveType.voidType)); + classe.addConstructorCallSymbol + (new MethodDeclaration.Symbol(name, type) { + gnu.expr.Expression compileInCallPosition() + { + return getInitializationCode(); + } + }); + } + CustomConstructor(NiceClass def, FormalParameters parameters) { ! this(def.definition.getName(), parameters); classe = def; } *************** *** 69,72 **** --- 79,84 ---- } + abstract gnu.expr.Expression getInitializationCode(); + NiceClass classe; *************** *** 92,95 **** --- 104,109 ---- classe = NiceClass.get(tc); + addConstructorCallSymbol(); + // Save the scopes, since we need them later, but they get null'ed. thisScope = scope; *************** *** 149,158 **** --- 163,180 ---- classe.getClassExp().addMethod(lambda); lambda.addBytecodeAttribute(parameters.asBytecodeAttribute()); + initializationCode = new QuoteExp(new InitializeProc(lambda, true)); return new QuoteExp(new InstantiateProc(lambda)); } + gnu.expr.Expression getInitializationCode() + { + getCode(); + return initializationCode; + } + LocatedString className; Statement body; + gnu.expr.Expression initializationCode; } *************** *** 184,187 **** --- 206,210 ---- { TypeConstructors.addConstructor(classe.definition.tc, this); + addConstructorCallSymbol(); } *************** *** 190,193 **** --- 213,222 ---- int dummyArgs = method.arg_types.length - arity; return new QuoteExp(new InstantiateProc(method, dummyArgs)); + } + + gnu.expr.Expression getInitializationCode() + { + int dummyArgs = method.arg_types.length - arity; + return new QuoteExp(new InitializeProc(method, true, dummyArgs)); } |
From: <bo...@us...> - 2003-12-15 16:19:50
|
Update of /cvsroot/nice/Nice/testsuite/compiler/classes/constructors In directory sc8-pr-cvs1:/tmp/cvs-serv27562/testsuite/compiler/classes/constructors Modified Files: custom.testsuite Log Message: Allow custom constructors to call other custom constructors. Index: custom.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/classes/constructors/custom.testsuite,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** custom.testsuite 15 Dec 2003 02:40:16 -0000 1.5 --- custom.testsuite 15 Dec 2003 16:19:47 -0000 1.6 *************** *** 21,25 **** { this(x: distance * cos(angle), y: distance * sin(angle)); } ! /// PASS bug /// Toplevel new Point(double angle, double distance) --- 21,28 ---- { this(x: distance * cos(angle), y: distance * sin(angle)); } ! /// PASS ! let p = new Point((0,1)); ! assert abs(p.x - 1) < 0.01 && abs(p.y) < 0.01; ! /// Toplevel new Point(double angle, double distance) |
From: <ar...@us...> - 2003-12-15 14:23:24
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1:/tmp/cvs-serv3010/F:/nice/src/bossa/parser Modified Files: Parser.jj Loader.java Log Message: few changes because parser isn't static anymore. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.227 retrieving revision 1.228 diff -C2 -d -r1.227 -r1.228 *** Parser.jj 15 Dec 2003 02:40:17 -0000 1.227 --- Parser.jj 15 Dec 2003 14:23:21 -0000 1.228 *************** *** 67,71 **** /* COMMENTS */ ! TOKEN_MGR_DECLS : { static int nestingLevel = 0; } MORE : --- 67,71 ---- /* COMMENTS */ ! TOKEN_MGR_DECLS : { int nestingLevel = 0; } MORE : Index: Loader.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Loader.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Loader.java 15 Dec 2003 02:40:17 -0000 1.23 --- Loader.java 15 Dec 2003 14:23:21 -0000 1.24 *************** *** 34,44 **** chrono.start(); try { ! if(parser==null) ! parser = new Parser(r); ! else ! parser.ReInit(r); ! ! // set to 0 (required when recovered from error) ! ParserTokenManager.nestingLevel = 0; try{ --- 34,38 ---- chrono.start(); try { ! Parser parser = new Parser(r); try{ *************** *** 63,74 **** chrono.start(); try { ! if(parser==null) ! parser = new Parser(r); ! else ! parser.ReInit(r); ! ! // set to 0 (required when recovered from error) ! ParserTokenManager.nestingLevel = 0; ! boolean storeDocStrings = false; --- 57,61 ---- chrono.start(); try { ! Parser parser = new Parser(r); boolean storeDocStrings = false; *************** *** 119,122 **** } - static Parser parser = null; } --- 106,108 ---- |
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv32103/src/bossa/syntax Modified Files: MethodBodyDefinition.java GlobalVarDeclaration.java EnumDefinition.java Definition.java ClassDefinition.java AbstractInterface.java Log Message: Removed the associatedDefinitions() support, which is not used anymore. If adding toplevel definitions is needed, it can be done by accessing the Package object. Index: MethodBodyDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodBodyDefinition.java,v retrieving revision 1.146 retrieving revision 1.147 diff -C2 -d -r1.146 -r1.147 *** MethodBodyDefinition.java 10 Dec 2003 22:34:25 -0000 1.146 --- MethodBodyDefinition.java 15 Dec 2003 14:04:13 -0000 1.147 *************** *** 83,91 **** } - public Collection associatedDefinitions() - { - return null; - } - final TypeConstructor firstArgument() { --- 83,86 ---- Index: GlobalVarDeclaration.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/GlobalVarDeclaration.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** GlobalVarDeclaration.java 22 Aug 2003 13:36:41 -0000 1.21 --- GlobalVarDeclaration.java 15 Dec 2003 14:04:13 -0000 1.22 *************** *** 84,92 **** } - public Collection associatedDefinitions() - { - return null; - } - void resolve() { --- 84,87 ---- Index: EnumDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/EnumDefinition.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** EnumDefinition.java 15 Dec 2003 00:04:48 -0000 1.7 --- EnumDefinition.java 15 Dec 2003 14:04:13 -0000 1.8 *************** *** 141,149 **** } - public Collection associatedDefinitions() - { - return null; - } - void resolve() { --- 141,144 ---- Index: Definition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Definition.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Definition.java 4 Dec 2003 13:34:28 -0000 1.21 --- Definition.java 15 Dec 2003 14:04:13 -0000 1.22 *************** *** 34,48 **** /** - * Returns a collection of definitions that are derived - * from the current definition. - * For example, a class definition A returns a collection - * with the definition of class #A. - */ - public Collection associatedDefinitions() - { - return null; - } - - /** Resolve local entities, that do not influence the global context. --- 34,37 ---- Index: ClassDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/ClassDefinition.java,v retrieving revision 1.100 retrieving revision 1.101 diff -C2 -d -r1.100 -r1.101 *** ClassDefinition.java 9 Dec 2003 15:21:05 -0000 1.100 --- ClassDefinition.java 15 Dec 2003 14:04:13 -0000 1.101 *************** *** 434,442 **** } - public Collection associatedDefinitions() - { - return null; - } - TypeScope getLocalScope() { --- 434,437 ---- Index: AbstractInterface.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/AbstractInterface.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** AbstractInterface.java 15 Nov 2003 13:02:16 -0000 1.17 --- AbstractInterface.java 15 Dec 2003 14:04:13 -0000 1.18 *************** *** 41,49 **** } - public Collection associatedDefinitions() - { - return null; - } - public void addMethod(Definition m) { --- 41,44 ---- |
From: <bo...@us...> - 2003-12-15 14:04:17
|
Update of /cvsroot/nice/Nice/src/bossa/modules In directory sc8-pr-cvs1:/tmp/cvs-serv32103/src/bossa/modules Modified Files: Content.java Log Message: Removed the associatedDefinitions() support, which is not used anymore. If adding toplevel definitions is needed, it can be done by accessing the Package object. Index: Content.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Content.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Content.java 15 Dec 2003 02:40:17 -0000 1.12 --- Content.java 15 Dec 2003 14:04:13 -0000 1.13 *************** *** 87,107 **** pkg.compilation.exitIfErrors(); - - expand(definitions); } - private static void expand(List definitions) - { - Collection ads = new LinkedList(); - for(Iterator i = definitions.iterator(); i.hasNext();) - { - Definition d = (Definition) i.next(); - Collection c = d.associatedDefinitions(); - if (c!=null) - ads.addAll(c); - } - definitions.addAll(ads); - } - private void read(Content.Unit unit, List imports, Set opens) { --- 87,92 ---- |
From: <bo...@us...> - 2003-12-15 02:40:20
|
Update of /cvsroot/nice/Nice/src/bossa/modules In directory sc8-pr-cvs1:/tmp/cvs-serv16555/src/bossa/modules Modified Files: Package.java Content.java Log Message: Load custom constructors form the bytecode of compiled packages. Index: Package.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Package.java,v retrieving revision 1.106 retrieving revision 1.107 diff -C2 -d -r1.106 -r1.107 *** Package.java 27 Nov 2003 15:23:11 -0000 1.106 --- Package.java 15 Dec 2003 02:40:17 -0000 1.107 *************** *** 121,125 **** compilation.progress(this, "parsing"); ! this.ast = new AST(this, source.getDefinitions(shouldReload)); compilation.addNumberOfDeclarations(ast.numberOfDeclarations()); --- 121,127 ---- compilation.progress(this, "parsing"); ! definitions = new ArrayList(); ! source.getDefinitions(definitions, shouldReload); ! this.ast = new AST(this, definitions); compilation.addNumberOfDeclarations(ast.numberOfDeclarations()); *************** *** 612,615 **** --- 614,618 ---- if (classe == null) Internal.error("Compiled class " + def + " was not found"); + importMethods(def, classe); ClassExp res = new ClassExp(classe); *************** *** 618,621 **** --- 621,637 ---- } + /** Load methods compiled in a class (custom constructors for now). */ + private void importMethods(NiceClass def, ClassType classe) + { + for(Method method = classe.getMethods(); + method != null; + method = method.getNext()) + { + Definition d = CustomConstructor.load(def, method); + if (d != null) + definitions.add(d); + } + } + public void addUserClass(gnu.expr.ClassExp classe) { *************** *** 853,856 **** --- 869,875 ---- private boolean isRoot; + /** The list of definitions. Used to add global definitions on the fly. */ + private List definitions; + private AST ast; Index: Content.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Content.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Content.java 22 Jul 2003 16:56:28 -0000 1.11 --- Content.java 15 Dec 2003 02:40:17 -0000 1.12 *************** *** 74,81 **** } ! List getDefinitions(boolean shouldReload) { - List definitions = new LinkedList(); - Content.Unit[] readers = getReaders(shouldReload); --- 74,79 ---- } ! void getDefinitions(List definitions, boolean shouldReload) { Content.Unit[] readers = getReaders(shouldReload); *************** *** 90,97 **** pkg.compilation.exitIfErrors(); ! return expand(definitions); } ! private static List expand(List definitions) { Collection ads = new LinkedList(); --- 88,95 ---- pkg.compilation.exitIfErrors(); ! expand(definitions); } ! private static void expand(List definitions) { Collection ads = new LinkedList(); *************** *** 104,108 **** } definitions.addAll(ads); - return definitions; } --- 102,105 ---- |
From: <bo...@us...> - 2003-12-15 02:40:20
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1:/tmp/cvs-serv16555/src/bossa/parser Modified Files: Parser.jj Loader.java Log Message: Load custom constructors form the bytecode of compiled packages. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.226 retrieving revision 1.227 diff -C2 -d -r1.226 -r1.227 *** Parser.jj 15 Dec 2003 00:04:48 -0000 1.226 --- Parser.jj 15 Dec 2003 02:40:17 -0000 1.227 *************** *** 18,21 **** --- 18,22 ---- JAVA_UNICODE_ESCAPE = true; DEBUG_LOOKAHEAD = false; + STATIC = false; } *************** *** 34,38 **** import mlsub.typing.MonotypeVar; ! class Parser { private static IdentExp symb(String name, Token t, boolean quoted) --- 35,39 ---- import mlsub.typing.MonotypeVar; ! public class Parser { private static IdentExp symb(String name, Token t, boolean quoted) *************** *** 1070,1074 **** { LocatedString name; - Block block; FormalParameters params; List statements = new LinkedList(); --- 1071,1074 ---- *************** *** 1084,1097 **** ( stmt=BlockStatement(statements) { statements.add(stmt); } )+ "}" - | - ";" ) { ! if (statements.isEmpty()) ! block = null; ! else ! block = new Block(statements); ! ! return new CustomConstructor(name, params, block); } } --- 1084,1090 ---- ( stmt=BlockStatement(statements) { statements.add(stmt); } )+ "}" ) { ! return CustomConstructor.make(name, params, new Block(statements)); } } Index: Loader.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Loader.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** Loader.java 4 Dec 2003 13:34:28 -0000 1.22 --- Loader.java 15 Dec 2003 02:40:17 -0000 1.23 *************** *** 112,115 **** --- 112,122 ---- } + public static Parser getParser(String toParse) + { + Reader r = new StringReader(toParse); + Parser parser = new Parser(r); + return parser; + } + static Parser parser = null; } |
From: <bo...@us...> - 2003-12-15 02:40:20
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv16555/src/bossa/syntax Modified Files: FormalParameters.java CustomConstructor.java Log Message: Load custom constructors form the bytecode of compiled packages. Index: FormalParameters.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/FormalParameters.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** FormalParameters.java 22 Nov 2003 16:37:39 -0000 1.33 --- FormalParameters.java 15 Dec 2003 02:40:17 -0000 1.34 *************** *** 528,531 **** --- 528,548 ---- } + gnu.bytecode.Attribute asBytecodeAttribute() + { + return new gnu.bytecode.MiscAttr("parameters", this.toString().getBytes()); + } + + static FormalParameters readBytecodeAttribute(gnu.bytecode.MiscAttr attr) + { + String value = new String(attr.data); + try { + return + bossa.parser.Loader.getParser(value).formalParameters(false, null); + } + catch (bossa.parser.ParseException ex) { + return null; + } + } + private Parameter[] parameters; int size; Index: CustomConstructor.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/CustomConstructor.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CustomConstructor.java 14 Dec 2003 16:52:32 -0000 1.6 --- CustomConstructor.java 15 Dec 2003 02:40:17 -0000 1.7 *************** *** 18,21 **** --- 18,24 ---- import gnu.expr.*; import gnu.bytecode.ClassType; + import gnu.bytecode.Method; + import gnu.bytecode.Attribute; + import gnu.bytecode.MiscAttr; import nice.tools.code.Gen; *************** *** 24,36 **** */ ! public class CustomConstructor extends UserOperator { ! public CustomConstructor(LocatedString className, FormalParameters params, Block body) { super(new LocatedString("<init>", className.location()), Constraint.True, returnType(className), params, Contract.noContract); ! this.className = className; ! this.body = body; } --- 27,52 ---- */ ! public abstract class CustomConstructor extends UserOperator { ! public static CustomConstructor make ! (LocatedString className, FormalParameters params, Block body) ! { ! return new SourceCustomConstructor(className, params, body); ! } ! ! CustomConstructor(LocatedString className, FormalParameters params) { super(new LocatedString("<init>", className.location()), Constraint.True, returnType(className), params, Contract.noContract); + } ! CustomConstructor(NiceClass def, FormalParameters parameters) ! { ! super(new LocatedString("<init>", def.definition.location()), ! Constraint.True, ! returnType(def.definition.getName()), ! parameters, ! Contract.noContract); ! classe = def; } *************** *** 42,130 **** } ! void resolve() { ! TypeConstructor tc = Node.getGlobalTypeScope().globalLookup(className); ! TypeConstructors.addConstructor(tc, this); ! classe = NiceClass.get(tc); ! ! // Save the scopes, since we need them later, but they get null'ed. ! thisScope = scope; ! thisTypeScope = typeScope; } ! private VarScope thisScope; ! private TypeScope thisTypeScope; ! ! void resolveBody() { ! resolveThis((Block) body); ! body = bossa.syntax.dispatch.analyse ! (body, thisScope, thisTypeScope, false); } ! private void resolveThis(Block block) { ! Statement last = block.statements[block.statements.length - 1]; ! if (last instanceof Block) ! { ! resolveThis((Block) last); ! return; ! } ! try { ! CallExp call = (CallExp) ((ExpressionStmt) last).exp; ! IdentExp ident = (IdentExp) call.function; ! if (! call.function.toString().equals("this")) User.error(this, "The last statement must be a call to 'this' constructor"); ! ! Location loc = ident.location(); ! call.function = new OverloadedSymbolExp ! (classe.getConstructorCallSymbols(), FormalParameters.thisName); ! call.function.setLocation(loc); } ! catch(ClassCastException ex) { ! User.error(this, ! "The last statement must be a call to 'this' constructor"); } - } ! void innerTypecheck() throws TypingEx ! { ! super.innerTypecheck(); ! bossa.syntax.dispatch.typecheck(body); ! } ! public void printInterface(java.io.PrintWriter s) ! { ! s.print("new " + className + "(" + parameters + ");\n"); } ! public void compile() { ! // Make sure the constructor is generated. ! getCode(); } ! protected gnu.expr.Expression computeCode() { ! if (classe.definition.inInterfaceFile()) ! { ! return new QuoteExp(classe.getClassExp().getClassType().getDeclaredMethod ! ("<init>", javaArgTypes())); ! } ! ConstructorExp lambda = Gen.createCustomConstructor ! ((ClassType) javaReturnType(), javaArgTypes(), getSymbols()); ! Gen.setMethodBody(lambda, body.generateCode()); ! classe.getClassExp().addMethod(lambda); ! return new QuoteExp(new InstantiateProc(lambda)); } - - LocatedString className; - Statement body; - NiceClass classe; } --- 58,196 ---- } ! public void printInterface(java.io.PrintWriter s) { ! // Constructors are not printed, they are loaded from the bytecode. } ! public void compile() { ! // Make sure the constructor is generated. ! getCode(); } ! NiceClass classe; ! ! /**************************************************************** ! * A custom constructor defined in a source program. ! ****************************************************************/ ! ! static class SourceCustomConstructor extends CustomConstructor { ! SourceCustomConstructor(LocatedString className, FormalParameters params, ! Block body) ! { ! super(className, params); ! this.className = className; ! this.body = body; ! } ! ! void resolve() ! { ! TypeConstructor tc = Node.getGlobalTypeScope().globalLookup(className); ! TypeConstructors.addConstructor(tc, this); ! classe = NiceClass.get(tc); ! ! // Save the scopes, since we need them later, but they get null'ed. ! thisScope = scope; ! thisTypeScope = typeScope; ! } ! ! private VarScope thisScope; ! private TypeScope thisTypeScope; ! ! void resolveBody() ! { ! resolveThis((Block) body); ! body = bossa.syntax.dispatch.analyse ! (body, thisScope, thisTypeScope, false); ! } ! ! private void resolveThis(Block block) ! { ! Statement last = block.statements[block.statements.length - 1]; ! if (last instanceof Block) ! { ! resolveThis((Block) last); ! return; ! } ! ! try { ! CallExp call = (CallExp) ((ExpressionStmt) last).exp; ! IdentExp ident = (IdentExp) call.function; ! if (! call.function.toString().equals("this")) ! User.error(this, ! "The last statement must be a call to 'this' constructor"); ! ! Location loc = ident.location(); ! call.function = new OverloadedSymbolExp ! (classe.getConstructorCallSymbols(), FormalParameters.thisName); ! call.function.setLocation(loc); ! } ! catch(ClassCastException ex) { User.error(this, "The last statement must be a call to 'this' constructor"); ! } } ! ! void innerTypecheck() throws TypingEx ! { ! super.innerTypecheck(); ! ! bossa.syntax.dispatch.typecheck(body); } ! protected gnu.expr.Expression computeCode() ! { ! ConstructorExp lambda = Gen.createCustomConstructor ! ((ClassType) javaReturnType(), javaArgTypes(), getSymbols()); ! Gen.setMethodBody(lambda, body.generateCode()); ! classe.getClassExp().addMethod(lambda); ! lambda.addBytecodeAttribute(parameters.asBytecodeAttribute()); ! return new QuoteExp(new InstantiateProc(lambda)); ! } ! ! LocatedString className; ! Statement body; } ! /**************************************************************** ! * Loading compiled custom constructors. ! ****************************************************************/ ! ! public static CustomConstructor load(NiceClass def, Method method) { ! if (! method.isConstructor()) ! return null; ! ! MiscAttr attr = (MiscAttr) Attribute.get(method, "parameters"); ! if (attr == null) ! return null; ! ! return new ImportedCustomConstructor(def, method, attr); } ! static class ImportedCustomConstructor extends CustomConstructor { ! ImportedCustomConstructor(NiceClass def, Method method, MiscAttr attr) ! { ! super(def, FormalParameters.readBytecodeAttribute(attr)); ! this.method = method; ! } ! void resolve() ! { ! TypeConstructors.addConstructor(classe.definition.tc, this); ! } ! protected gnu.expr.Expression computeCode() ! { ! int dummyArgs = method.arg_types.length - arity; ! return new QuoteExp(new InstantiateProc(method, dummyArgs)); ! } ! private Method method; } } |
From: <bo...@us...> - 2003-12-15 02:40:20
|
Update of /cvsroot/nice/Nice/src/gnu/expr In directory sc8-pr-cvs1:/tmp/cvs-serv16555/src/gnu/expr Modified Files: InstantiateProc.java ConstructorExp.java ClassExp.java Log Message: Load custom constructors form the bytecode of compiled packages. Index: InstantiateProc.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/expr/InstantiateProc.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** InstantiateProc.java 14 Dec 2003 16:52:32 -0000 1.3 --- InstantiateProc.java 15 Dec 2003 02:40:16 -0000 1.4 *************** *** 27,31 **** --- 27,37 ---- public InstantiateProc (Method constructor) { + this(constructor, 0); + } + + public InstantiateProc (Method constructor, int dummyArgs) + { this.constructor = constructor; + this.dummyArgs = dummyArgs; } *************** *** 37,40 **** --- 43,47 ---- private Method constructor; private ConstructorExp method; + private int dummyArgs; public void compile (ApplyExp exp, Compilation comp, Target target) *************** *** 56,61 **** // Add dummy arguments to match the bytecode constructor. if (method !=null) ! for (int i = 0; i < method.dummyArgs; i++) ! code.emitPushInt(0); code.emitInvokeSpecial(constructor); --- 63,69 ---- // Add dummy arguments to match the bytecode constructor. if (method !=null) ! dummyArgs = method.dummyArgs; ! for (int i = 0; i < dummyArgs; i++) ! code.emitPushInt(0); code.emitInvokeSpecial(constructor); Index: ConstructorExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/expr/ConstructorExp.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ConstructorExp.java 14 Dec 2003 16:52:32 -0000 1.5 --- ConstructorExp.java 15 Dec 2003 02:40:16 -0000 1.6 *************** *** 87,90 **** --- 87,92 ---- ("<init>", args, Type.void_type, Access.PUBLIC); primMethods = new Method[] { method }; + + addAttributes(method); } Index: ClassExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/expr/ClassExp.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** ClassExp.java 27 Nov 2003 00:21:19 -0000 1.16 --- ClassExp.java 15 Dec 2003 02:40:16 -0000 1.17 *************** *** 100,104 **** Method m = instanceType.getDeclaredMethod (method.getName(), method.getArgTypes()); ! if (m != null) { m.eraseCode(); --- 100,104 ---- Method m = instanceType.getDeclaredMethod (method.getName(), method.getArgTypes()); ! if (m != null && ! m.isConstructor()) { m.eraseCode(); |
From: <bo...@us...> - 2003-12-15 02:40:19
|
Update of /cvsroot/nice/Nice/testsuite/compiler/classes/constructors In directory sc8-pr-cvs1:/tmp/cvs-serv16555/testsuite/compiler/classes/constructors Modified Files: custom.testsuite Log Message: Load custom constructors form the bytecode of compiled packages. Index: custom.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/classes/constructors/custom.testsuite,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** custom.testsuite 14 Dec 2003 20:56:35 -0000 1.4 --- custom.testsuite 15 Dec 2003 02:40:16 -0000 1.5 *************** *** 45,49 **** class ColoredPoint extends Point { String color; } ! /// PASS bug /// package a /// Toplevel --- 45,49 ---- class ColoredPoint extends Point { String color; } ! /// PASS /// package a /// Toplevel *************** *** 53,57 **** ! /// PASS bug /// package a /// Toplevel --- 53,57 ---- ! /// PASS /// package a /// Toplevel *************** *** 61,65 **** let p = new Point(angle: 0, distance: 1); ! /// PASS bug /// package a /// Toplevel --- 61,65 ---- let p = new Point(angle: 0, distance: 1); ! /// PASS /// package a /// Toplevel |
From: <ar...@us...> - 2003-12-15 00:04:51
|
Update of /cvsroot/nice/Nice/testsuite/compiler/enums In directory sc8-pr-cvs1:/tmp/cvs-serv22745/F:/nice/testsuite/compiler/enums Modified Files: enum.testsuite Log Message: Implemented user defined fields for enums. Index: enum.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/enums/enum.testsuite,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** enum.testsuite 28 Nov 2003 12:10:10 -0000 1.5 --- enum.testsuite 15 Dec 2003 00:04:49 -0000 1.6 *************** *** 89,90 **** --- 89,100 ---- assert elems.contains(blue); assert elems.contains(green); + + /// PASS + /// package a + /// Toplevel + enum Coin(int value) {penny(1), nickel(5), dime(10), quarter(25)} + /// package b import a + assert penny.value == 1; + assert nickel.value == 5; + assert dime.value == 10; + assert quarter.value == 25; |
From: <ar...@us...> - 2003-12-15 00:04:51
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv22745/F:/nice/src/bossa/syntax Modified Files: EnumDefinition.java Log Message: Implemented user defined fields for enums. Index: EnumDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/EnumDefinition.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** EnumDefinition.java 27 Nov 2003 23:37:08 -0000 1.6 --- EnumDefinition.java 15 Dec 2003 00:04:48 -0000 1.7 *************** *** 26,30 **** public class EnumDefinition extends Definition { ! public EnumDefinition(LocatedString name, List/*LocatedString*/ elements, List globalDefs) { super(name, Node.global); --- 26,32 ---- public class EnumDefinition extends Definition { ! public EnumDefinition(LocatedString name, List/*LocatedString*/ elements, ! List/*MonoSymbol*/ fields, List/*List<Expression>*/ argsList, ! List globalDefs) { super(name, Node.global); *************** *** 35,39 **** null,null); NiceClass impl = new NiceClass(classDef); ! impl.setFields(null); impl.setOverrides(null); --- 37,53 ---- null,null); NiceClass impl = new NiceClass(classDef); ! int fieldsCount = fields.size(); ! if (fieldsCount > 0) ! { ! List newFields = new ArrayList(fieldsCount); ! for (Iterator it = fields.iterator(); it.hasNext(); ) ! newFields.add(impl.makeField((MonoSymbol)it.next(), null, true, ! false, false, null)); ! ! impl.setFields(newFields); ! } ! else ! impl.setFields(null); ! impl.setOverrides(null); *************** *** 57,69 **** this.elements = elements; symbols = new LinkedList(); ! int ord = 0; ! for (Iterator it = elements.iterator(); it.hasNext(); ) { Monotype type = new TypeIdent(name); type.nullness = Monotype.absent; ! symbols.add(new EnumSymbol(name, (LocatedString)it.next(), type, ord)); ! ord++; } addChildren(symbols); --- 71,88 ---- this.elements = elements; + this.fields = fields; + this.elementsArgs = argsList; symbols = new LinkedList(); ! for (int ord = 0; ord<elements.size(); ord++ ) { + List args = (List) argsList.get(ord); + LocatedString elemName = (LocatedString)elements.get(ord); + if (args.size() != fieldsCount) + User.error(elemName, "the number of arguments doesn't match the number of enum fields"); + Monotype type = new TypeIdent(name); type.nullness = Monotype.absent; ! symbols.add(new EnumSymbol(name, elemName, type, ord, fields, args)); } addChildren(symbols); *************** *** 73,80 **** class EnumSymbol extends MonoSymbol { ! EnumSymbol(LocatedString enumName, LocatedString name, Monotype type, int ordinal) { super(name, type); ! List args = new ArrayList(2); args.add(new Arguments.Argument(new StringConstantExp(name.toString()), new LocatedString("name",name.location))); --- 92,100 ---- class EnumSymbol extends MonoSymbol { ! EnumSymbol(LocatedString enumName, LocatedString name, Monotype type, ! int ordinal, List fields, List argExps) { super(name, type); ! List args = new ArrayList(2 + fields.size()); args.add(new Arguments.Argument(new StringConstantExp(name.toString()), new LocatedString("name",name.location))); *************** *** 83,86 **** --- 103,110 ---- val.toString(), name.location()), new LocatedString("ordinal",name.location))); + for (int i = 0; i < fields.size(); i++) + args.add(new Arguments.Argument((Expression)argExps.get(i), + ((MonoSymbol)fields.get(i)).getName())); + this.value = new NewExp(new TypeIdent(enumName), new Arguments(args)); } *************** *** 181,185 **** public String toString() { ! return "enum " + shortName + Util.map(" {", " , ", " }", elements); } --- 205,221 ---- public String toString() { ! if (fields.isEmpty()) ! return "enum " + shortName + Util.map(" {", " , ", " }", elements); ! ! String res = "enum " + shortName + Util.map("(", ", ", ")", fields) + " {"; ! for (int i = 0; i < elements.size(); i++) ! { ! if (i != 0) ! res += ", "; ! ! res += elements.get(i) + Util.map("(", ", ", ")", (List)elementsArgs.get(i)); ! } ! ! return res + "}"; } *************** *** 188,190 **** --- 224,228 ---- List elements; List symbols; + List fields; + List elementsArgs; } |
From: <ar...@us...> - 2003-12-15 00:04:51
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1:/tmp/cvs-serv22745/F:/nice/src/bossa/parser Modified Files: Parser.jj Log Message: Implemented user defined fields for enums. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.225 retrieving revision 1.226 diff -C2 -d -r1.225 -r1.226 *** Parser.jj 13 Dec 2003 14:06:00 -0000 1.225 --- Parser.jj 15 Dec 2003 00:04:48 -0000 1.226 *************** *** 1198,1210 **** EnumDefinition enumDefinition(List definitions): { ! LocatedString name, elem; List elements = new LinkedList(); } { "enum" name=ident() ! "{" elem=ident() { elements.add(elem); } ! ( "," elem =ident() { elements.add(elem); } )+ "}" ! { return new EnumDefinition(name, elements, definitions); } } --- 1198,1231 ---- EnumDefinition enumDefinition(List definitions): { ! LocatedString name; List elements = new LinkedList(); + List fields = new LinkedList(); + MonoSymbol field; + List argsList = new LinkedList(); } { "enum" name=ident() ! [ ! "(" field=monoSymbol() { fields.add(field); } ! ( "," field=monoSymbol() { fields.add(field); } )* ")" ! ] ! "{" enumElement(elements, argsList) ! ( "," enumElement(elements, argsList) )+ "}" ! { return new EnumDefinition(name, elements, fields, argsList, definitions); } ! } ! ! void enumElement(List elements, List argsList): ! { ! LocatedString elem; ! Expression arg; ! List args = new LinkedList(); ! } ! { ! elem=ident() { elements.add(elem); } ! [ "(" arg=Expression() { args.add(arg); } ! ( "," arg=Expression() { args.add(arg); } )* ")" ! ] ! { argsList.add(args); } } |
From: <ar...@us...> - 2003-12-14 20:56:39
|
Update of /cvsroot/nice/Nice/testsuite/compiler/classes/constructors In directory sc8-pr-cvs1:/tmp/cvs-serv19378/F:/nice/testsuite/compiler/classes/constructors Modified Files: custom.testsuite Log Message: Multi package testcases for custom constructors. Index: custom.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/classes/constructors/custom.testsuite,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** custom.testsuite 14 Dec 2003 16:52:32 -0000 1.3 --- custom.testsuite 14 Dec 2003 20:56:35 -0000 1.4 *************** *** 44,45 **** --- 44,71 ---- class ColoredPoint extends Point { String color; } + + /// PASS bug + /// package a + /// Toplevel + new Point(double xy) = this(x: xy, y : xy); + /// package b import a; + let p = new Point(xy: 10.11); + + + /// PASS bug + /// package a + /// Toplevel + new Point(double angle, double distance) + { this(x: distance * cos(angle), y: distance * sin(angle)); } + /// package b import a; + let p = new Point(angle: 0, distance: 1); + + /// PASS bug + /// package a + /// Toplevel + class Point2 { double x; double y; } + /// package b import a; + let p = new Point2(angle: 0, distance: 1); + /// Toplevel + new Point2(double angle, double distance) + { this(x: distance * cos(angle), y: distance * sin(angle)); } |
From: <bo...@us...> - 2003-12-14 16:52:36
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv3719/src/bossa/syntax Modified Files: NiceClass.java CustomConstructor.java Constructor.java Log Message: Resolve, typecheck and generate code for custom constructors. Index: NiceClass.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceClass.java,v retrieving revision 1.75 retrieving revision 1.76 diff -C2 -d -r1.75 -r1.76 *** NiceClass.java 13 Dec 2003 19:09:40 -0000 1.75 --- NiceClass.java 14 Dec 2003 16:52:32 -0000 1.76 *************** *** 99,102 **** --- 99,115 ---- } + /** List of symbols for calling constructors of this class. */ + private ArrayList constructors = new ArrayList(10); + + void addConstructorCallSymbol(MethodDeclaration.Symbol sym) + { + constructors.add(sym); + } + + List getConstructorCallSymbols() + { + return (List) constructors.clone(); + } + /**************************************************************** * Fields Index: CustomConstructor.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/CustomConstructor.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** CustomConstructor.java 13 Dec 2003 18:59:00 -0000 1.5 --- CustomConstructor.java 14 Dec 2003 16:52:32 -0000 1.6 *************** *** 58,70 **** void resolveBody() { body = bossa.syntax.dispatch.analyse (body, thisScope, thisTypeScope, false); } void innerTypecheck() throws TypingEx { super.innerTypecheck(); ! bossa.syntax.dispatch.typecheck(body); } --- 58,98 ---- void resolveBody() { + resolveThis((Block) body); body = bossa.syntax.dispatch.analyse (body, thisScope, thisTypeScope, false); } + private void resolveThis(Block block) + { + Statement last = block.statements[block.statements.length - 1]; + if (last instanceof Block) + { + resolveThis((Block) last); + return; + } + + try { + CallExp call = (CallExp) ((ExpressionStmt) last).exp; + IdentExp ident = (IdentExp) call.function; + if (! call.function.toString().equals("this")) + User.error(this, + "The last statement must be a call to 'this' constructor"); + + Location loc = ident.location(); + call.function = new OverloadedSymbolExp + (classe.getConstructorCallSymbols(), FormalParameters.thisName); + call.function.setLocation(loc); + } + catch(ClassCastException ex) { + User.error(this, + "The last statement must be a call to 'this' constructor"); + } + } + void innerTypecheck() throws TypingEx { super.innerTypecheck(); ! bossa.syntax.dispatch.typecheck(body); } *************** *** 74,77 **** --- 102,111 ---- } + public void compile() + { + // Make sure the constructor is generated. + getCode(); + } + protected gnu.expr.Expression computeCode() { *************** *** 83,92 **** ConstructorExp lambda = Gen.createCustomConstructor ! ((ClassType) javaReturnType(), javaArgTypes(), parameters.getMonoSymbols()); Gen.setMethodBody(lambda, body.generateCode()); classe.getClassExp().addMethod(lambda); ! return lambda; } --- 117,126 ---- ConstructorExp lambda = Gen.createCustomConstructor ! ((ClassType) javaReturnType(), javaArgTypes(), getSymbols()); Gen.setMethodBody(lambda, body.generateCode()); classe.getClassExp().addMethod(lambda); ! return new QuoteExp(new InstantiateProc(lambda)); } Index: Constructor.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Constructor.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Constructor.java 27 Nov 2003 21:02:13 -0000 1.9 --- Constructor.java 14 Dec 2003 16:52:32 -0000 1.10 *************** *** 48,51 **** --- 48,63 ---- this.fields = fields; this.index = index; + + mlsub.typing.Polytype type = new mlsub.typing.Polytype + (getType().getConstraint(), + new mlsub.typing.FunType(getArgTypes(), PrimitiveType.voidType)); + classe.addConstructorCallSymbol + (new MethodDeclaration.Symbol(name, type) { + gnu.expr.Expression compileInCallPosition() + { + getCode(); + return initializeFromConstructor; + } + }); } *************** *** 66,69 **** --- 78,84 ---- private Expression initialize; + /** Call the constructor, with all the arguments, with an implicit this argument. */ + private Expression initializeFromConstructor; + /** Call the constructor, with only non-default arguments. */ private Expression initializeOmitDefaults; *************** *** 125,128 **** --- 140,144 ---- { initialize = new QuoteExp(new InitializeProc(m)); + initializeFromConstructor = new QuoteExp(new InitializeProc(m, true)); instantiate = new QuoteExp(new InstantiateProc(m)); } *************** *** 144,147 **** --- 160,164 ---- { initialize = new QuoteExp(new InitializeProc(lambda)); + initializeFromConstructor = new QuoteExp(new InitializeProc(lambda, true)); instantiate = new QuoteExp(new InstantiateProc(lambda)); } |
From: <bo...@us...> - 2003-12-14 16:52:36
|
Update of /cvsroot/nice/Nice/src/gnu/expr In directory sc8-pr-cvs1:/tmp/cvs-serv3719/src/gnu/expr Modified Files: InstantiateProc.java InitializeProc.java ConstructorExp.java Log Message: Resolve, typecheck and generate code for custom constructors. Index: InstantiateProc.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/expr/InstantiateProc.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** InstantiateProc.java 2 Sep 2002 16:11:53 -0000 1.2 --- InstantiateProc.java 14 Dec 2003 16:52:32 -0000 1.3 *************** *** 54,57 **** --- 54,62 ---- args[i].compile(comp, types[i]); + // Add dummy arguments to match the bytecode constructor. + if (method !=null) + for (int i = 0; i < method.dummyArgs; i++) + code.emitPushInt(0); + code.emitInvokeSpecial(constructor); target.compileFromStack(comp, type); Index: InitializeProc.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/expr/InitializeProc.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** InitializeProc.java 2 Sep 2002 11:46:51 -0000 1.1 --- InitializeProc.java 14 Dec 2003 16:52:32 -0000 1.2 *************** *** 27,40 **** public InitializeProc (Method constructor) { this.constructor = constructor; } public InitializeProc (ConstructorExp method) { ! this.method = method; } private Method constructor; private ConstructorExp method; public void compile (ApplyExp exp, Compilation comp, Target target) --- 27,61 ---- public InitializeProc (Method constructor) { + this(constructor, false); + } + + /** + @param implicitThis true if a 'this' argument should be added + during the call. + */ + public InitializeProc (Method constructor, boolean implicitThis) + { this.constructor = constructor; + this.implicitThis = implicitThis; } public InitializeProc (ConstructorExp method) { ! this(method, false); ! } ! ! /** ! @param implicitThis true if a 'this' argument should be added ! during the call. ! */ ! public InitializeProc (ConstructorExp method, boolean implicitThis) ! { ! this.method = method; ! this.implicitThis = implicitThis; } private Method constructor; private ConstructorExp method; + private boolean implicitThis; public void compile (ApplyExp exp, Compilation comp, Target target) *************** *** 47,53 **** Type[] types = constructor.getParameterTypes(); ! args[0].compile(comp, Target.pushObject); ! for (int i = 1; i < args.length; i++) ! args[i].compile(comp, types[i - 1]); code.emitInvokeSpecial(constructor); --- 68,84 ---- Type[] types = constructor.getParameterTypes(); ! int arg = 0; ! int type = 0; ! if (implicitThis) ! code.emitPushThis(); ! else ! args[arg++].compile(comp, Target.pushObject); ! for (; arg < args.length; arg++) ! args[arg].compile(comp, types[type++]); ! ! // Add dummy arguments to match the bytecode constructor. ! if (method != null) ! for (int i = 0; i < method.dummyArgs; i++) ! code.emitPushInt(0); code.emitInvokeSpecial(constructor); Index: ConstructorExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/expr/ConstructorExp.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ConstructorExp.java 13 Dec 2003 17:52:01 -0000 1.4 --- ConstructorExp.java 14 Dec 2003 16:52:32 -0000 1.5 *************** *** 69,76 **** --- 69,94 ---- args[itype++] = var.getType().getImplementationType(); + // Make sure the signature is unique + if (! primary) + { + do + { + Type[] newArgs = new Type[args.length + 1]; + System.arraycopy(args, 0, newArgs, 0, args.length); + newArgs[args.length] = Type.int_type; + args = newArgs; + dummyArgs++; + addDeclaration("dummy"); + } + while (ctype.getDeclaredMethod("<init>", args) != null); + } + Method method = ctype.addMethod ("<init>", args, Type.void_type, Access.PUBLIC); primMethods = new Method[] { method }; } + + /** Number of dummy arguments added to make the signature unique. */ + int dummyArgs = 0; void enterFunction (Compilation comp) |
From: <bo...@us...> - 2003-12-14 16:52:35
|
Update of /cvsroot/nice/Nice/testsuite/compiler/classes/constructors In directory sc8-pr-cvs1:/tmp/cvs-serv3719/testsuite/compiler/classes/constructors Modified Files: custom.testsuite Log Message: Resolve, typecheck and generate code for custom constructors. Index: custom.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/classes/constructors/custom.testsuite,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** custom.testsuite 13 Dec 2003 14:54:08 -0000 1.2 --- custom.testsuite 14 Dec 2003 16:52:32 -0000 1.3 *************** *** 2,12 **** class Point { double x; double y; } ! /// PASS bug /// Toplevel /* Use the custom constructor before its declaration. */ ! let Point origin = new Point(angle: 0, distance: 0); new Point(double angle, double distance) { this(x: distance * cos(angle), y: distance * sin(angle)); } /// PASS bug --- 2,34 ---- class Point { double x; double y; } ! /// PASS ! assert abs(p.x - 1) < 0.01 && abs(p.y) < 0.01; ! /// Toplevel /* Use the custom constructor before its declaration. */ ! let Point p = new Point(angle: 0, distance: 1); ! ! new Point(double angle, double distance) ! { this(x: distance * cos(angle), y: distance * sin(angle)); } ! ! /// PASS ! /// Toplevel ! /* Use the custom constructor before the declaration of the class. */ ! let Point2 origin = new Point2(angle: 0, distance: 0); + class Point2 { double x; double y; } + new Point2(double angle, double distance) + { this(x: distance * cos(angle), y: distance * sin(angle)); } + + /// PASS bug + /// Toplevel new Point(double angle, double distance) { this(x: distance * cos(angle), y: distance * sin(angle)); } + + new Point((double angle, double distance) polarCoordinates) + { + // Forward to another custom constructor. + this(angle: angle, distance: distance); + } /// PASS bug |