Changeset 5991


Ignore:
Timestamp:
02/26/04 02:13:57 (17 years ago)
Author:
piso
Message:

Work in progress.

Location:
trunk/j/src/org/armedbear/lisp
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/ComplexArray.java

    r5984 r5991  
    33 *
    44 * Copyright (C) 2003-2004 Peter Graves
    5  * $Id: ComplexArray.java,v 1.2 2004-02-26 01:36:02 piso Exp $
     5 * $Id: ComplexArray.java,v 1.3 2004-02-26 02:12:55 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    2525{
    2626    private final int[] dimv;
     27    private final LispObject elementType;
    2728    private final int totalSize;
    2829
     
    3435    private int displacement;
    3536
    36     public ComplexArray(int[] dimv)
     37    public ComplexArray(int[] dimv, LispObject elementType)
    3738    {
    3839        this.dimv = dimv;
     40        this.elementType = elementType;
    3941        totalSize = computeTotalSize(dimv);
    4042        data = new LispObject[totalSize];
     
    4345    }
    4446
    45     public ComplexArray(int[] dimv, LispObject initialContents) throws ConditionThrowable
     47    public ComplexArray(int[] dimv,
     48                        LispObject elementType,
     49                        LispObject initialContents)
     50        throws ConditionThrowable
    4651    {
    4752        this.dimv = dimv;
     53        this.elementType = elementType;
    4854        final int rank = dimv.length;
    4955        LispObject rest = initialContents;
     
    6066    {
    6167        this.dimv = dimv;
     68        this.elementType = array.getElementType();
    6269        this.array = array;
    6370        this.displacement = displacement;
     
    150157    public LispObject getElementType()
    151158    {
    152         return T;
     159        return elementType;
    153160    }
    154161
  • trunk/j/src/org/armedbear/lisp/SimpleArray.java

    r5983 r5991  
    33 *
    44 * Copyright (C) 2003-2004 Peter Graves
    5  * $Id: SimpleArray.java,v 1.1 2004-02-26 01:34:01 piso Exp $
     5 * $Id: SimpleArray.java,v 1.2 2004-02-26 02:12:25 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    2525{
    2626    private final int[] dimv;
     27    private final LispObject elementType;
    2728    private final LispObject[] data;
    2829
    29     public SimpleArray(int[] dimv)
     30    public SimpleArray(int[] dimv, LispObject elementType)
    3031    {
    3132        this.dimv = dimv;
     33        this.elementType = elementType;
    3234        int size = computeTotalSize(dimv);
    3335        data = new LispObject[size];
     
    3638    }
    3739
    38     public SimpleArray(int[] dimv, LispObject initialContents) throws ConditionThrowable
     40    public SimpleArray(int[] dimv,
     41                       LispObject elementType,
     42                       LispObject initialContents)
     43        throws ConditionThrowable
    3944    {
    4045        this.dimv = dimv;
     46        this.elementType = elementType;
    4147        final int rank = dimv.length;
    4248        LispObject rest = initialContents;
     
    5561            Debug.assertTrue(false);
    5662        dimv = new int[rank];
     63        this.elementType = T;
    5764        LispObject rest = initialContents;
    5865        for (int i = 0; i < rank; i++) {
     
    152159    public LispObject getElementType()
    153160    {
    154         return T;
     161        return elementType;
    155162    }
    156163
     
    195202        return sb.toString();
    196203    }
     204
     205    public AbstractArray adjustArray(int[] dimv, AbstractArray displacedTo,
     206                                     int displacement)
     207    {
     208        return new ComplexArray(dimv, displacedTo, displacement);
     209    }
    197210}
  • trunk/j/src/org/armedbear/lisp/adjust_array.java

    r5972 r5991  
    33 *
    44 * Copyright (C) 2004 Peter Graves
    5  * $Id: adjust_array.java,v 1.10 2004-02-25 18:37:26 piso Exp $
     5 * $Id: adjust_array.java,v 1.11 2004-02-26 02:13:57 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    8787            }
    8888        }
     89        // rank > 1
     90        final int rank = dimensions.listp() ? dimensions.length() : 1;
     91        int[] dimv = new int[rank];
     92        if (dimensions.listp()) {
     93            for (int i = 0; i < rank; i++) {
     94                LispObject dim = dimensions.car();
     95                dimv[i] = Fixnum.getValue(dim);
     96                dimensions = dimensions.cdr();
     97            }
     98        } else
     99            dimv[0] = Fixnum.getValue(dimensions);
     100        if (array instanceof SimpleArray) {
     101            SimpleArray a = (SimpleArray) array;
     102            if (displacedTo != NIL) {
     103                final int displacement;
     104                if (displacedIndexOffset == NIL)
     105                    displacement = 0;
     106                else
     107                    displacement = Fixnum.getValue(displacedIndexOffset);
     108                return a.adjustArray(dimv,
     109                                     checkArray(displacedTo),
     110                                     displacement);
     111            }
     112        }
    89113        return signal(new LispError("ADJUST-ARRAY: unsupported case."));
    90114    }
  • trunk/j/src/org/armedbear/lisp/make_array.java

    r5987 r5991  
    33 *
    44 * Copyright (C) 2003-2004 Peter Graves
    5  * $Id: make_array.java,v 1.21 2004-02-26 01:39:27 piso Exp $
     5 * $Id: make_array.java,v 1.22 2004-02-26 02:13:26 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    8787            return new ComplexArray(dimv, array, displacement);
    8888        }
     89        LispObject upgradedType =
     90            getUpgradedArrayElementType(elementType);
    8991        if (rank == 0) {
    9092            LispObject data;
     
    9395            else
    9496                data = initialContents;
    95             return new ZeroRankArray(getUpgradedArrayElementType(elementType),
    96                                      data, adjustable != NIL);
     97            return new ZeroRankArray(upgradedType, data, adjustable != NIL);
    9798        }
    9899        if (rank == 1) {
     
    114115            }
    115116            AbstractVector v;
    116             LispObject upgradedType =
    117                 getUpgradedArrayElementType(elementType);
    118117            if (upgradedType == Symbol.CHARACTER) {
    119118                if (fillPointer != NIL || adjustable != NIL)
     
    154153            return v;
    155154        }
    156         // rank != 1
     155        // rank > 1
    157156        AbstractArray array;
    158157        if (adjustable == NIL) {
    159158            if (initialContents != NIL) {
    160                 array = new SimpleArray(dimv, initialContents);
     159                array = new SimpleArray(dimv, upgradedType, initialContents);
    161160            } else {
    162                 array = new SimpleArray(dimv);
     161                array = new SimpleArray(dimv, upgradedType);
    163162                if (initialElementProvided != NIL)
    164163                    array.fill(initialElement);
     
    166165        } else {
    167166            if (initialContents != NIL) {
    168                 array = new ComplexArray(dimv, initialContents);
     167                array = new ComplexArray(dimv, upgradedType, initialContents);
    169168            } else {
    170                 array = new ComplexArray(dimv);
     169                array = new ComplexArray(dimv, upgradedType);
    171170                if (initialElementProvided != NIL)
    172171                    array.fill(initialElement);
Note: See TracChangeset for help on using the changeset viewer.