Changeset 3745
- Timestamp:
- 09/14/03 11:37:15 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/lisp/Primitives.java
r3737 r3745 3 3 * 4 4 * Copyright (C) 2002-2003 Peter Graves 5 * $Id: Primitives.java,v 1.38 7 2003-09-14 01:37:09piso Exp $5 * $Id: Primitives.java,v 1.388 2003-09-14 11:37:15 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 1837 1837 } 1838 1838 1839 // ### %make-array dimensions element-type initial-element initial-contents1840 // adjustable fill-pointer displaced-to displaced-index-offset1841 private static final Primitive _MAKE_ARRAY =1842 new Primitive("%make-array", PACKAGE_SYS, false) {1843 public LispObject execute(LispObject[] args) throws LispError1844 {1845 if (args.length != 9)1846 throw new WrongNumberOfArgumentsException(this);1847 LispObject dimensions = args[0];1848 LispObject elementType = args[1];1849 LispObject initialElement = args[2];1850 LispObject initialElementProvided = args[3];1851 LispObject initialContents = args[4];1852 LispObject adjustable = args[5];1853 LispObject fillPointer = args[6];1854 LispObject displacedTo = args[7];1855 LispObject displacedIndexOffset = args[8];1856 if (initialElementProvided != NIL && initialContents != NIL) {1857 throw new LispError("MAKE-ARRAY: cannot specify both " +1858 ":INITIAL-ELEMENT AND :INITIAL-CONTENTS");1859 }1860 final int rank = dimensions.listp() ? dimensions.length() : 1;1861 if (displacedTo != NIL) {1862 final AbstractArray array = checkArray(displacedTo);1863 final int offset;1864 if (displacedIndexOffset != NIL)1865 offset = Fixnum.getValue(displacedIndexOffset);1866 else1867 offset = 0;1868 if (initialElementProvided != NIL)1869 throw new LispError(":INITIAL-ELEMENT must not be specified with :DISPLACED-TO");1870 if (initialContents != NIL)1871 throw new LispError(":INITIAL-CONTENTS must not be specified with :DISPLACED-TO");1872 int[] dimv = new int[rank];1873 for (int i = 0; i < rank; i++) {1874 LispObject dim = dimensions.car();1875 dimv[i] = Fixnum.getValue(dim);1876 dimensions = dimensions.cdr();1877 }1878 return new DisplacedArray(dimv, array, offset);1879 }1880 if (rank == 1) {1881 final int size;1882 if (dimensions instanceof Cons)1883 size = Fixnum.getValue(dimensions.car());1884 else1885 size = Fixnum.getValue(dimensions);1886 int limit =1887 Fixnum.getValue(Symbol.ARRAY_DIMENSION_LIMIT.getSymbolValue());1888 if (size < 0 || size >= limit) {1889 StringBuffer sb = new StringBuffer();1890 sb.append("the size specified for this array (");1891 sb.append(size);1892 sb.append(')');1893 if (size >= limit) {1894 sb.append(" is >= ARRAY-DIMENSION-LIMIT (");1895 sb.append(limit);1896 sb.append(')');1897 } else1898 sb.append(" is negative");1899 throw new LispError(sb.toString());1900 }1901 AbstractVector v;1902 LispObject upgradedType =1903 getUpgradedArrayElementType(elementType);1904 if (upgradedType == Symbol.CHARACTER)1905 v = new LispString(size);1906 else if (elementType == Symbol.BIT)1907 v = new BitVector(size);1908 else1909 v = new Vector(size);1910 if (initialElementProvided != NIL) {1911 // Initial element was specified.1912 v.fill(initialElement);1913 } else if (initialContents != NIL) {1914 final int type = initialContents.getType();1915 if ((type & TYPE_LIST) != 0) {1916 LispObject list = initialContents;1917 for (int i = 0; i < size; i++) {1918 v.set(i, list.car());1919 list = list.cdr();1920 }1921 } else if ((type & TYPE_VECTOR) != 0) {1922 for (int i = 0; i < size; i++)1923 v.set(i, initialContents.elt(i));1924 } else1925 throw new TypeError(initialContents, "sequence");1926 }1927 if (fillPointer != NIL)1928 v.setFillPointer(fillPointer);1929 return v;1930 }1931 // rank != 11932 int[] dimv = new int[rank];1933 for (int i = 0; i < rank; i++) {1934 LispObject dim = dimensions.car();1935 dimv[i] = Fixnum.getValue(dim);1936 dimensions = dimensions.cdr();1937 }1938 Array array;1939 if (initialContents != NIL) {1940 array = new Array(dimv, initialContents);1941 } else {1942 array = new Array(dimv);1943 if (initialElementProvided != NIL)1944 array.fill(initialElement);1945 }1946 return array;1947 }1948 };1949 1950 1839 // ### upgraded-array-element-type 1951 1840 // upgraded-array-element-type typespec &optional environment … … 1964 1853 } 1965 1854 }; 1966 1967 private static final LispObject getUpgradedArrayElementType(LispObject type)1968 {1969 if (type == Symbol.CHARACTER || type == Symbol.BASE_CHAR || type == Symbol.STANDARD_CHAR)1970 return Symbol.CHARACTER;1971 if (type == Symbol.BIT)1972 return Symbol.BIT;1973 if (type == NIL)1974 return Symbol.CHARACTER;1975 return T;1976 }1977 1855 1978 1856 // ### array-rank
Note: See TracChangeset
for help on using the changeset viewer.