Changeset 3733
- Timestamp:
- 09/13/03 23:40:54 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/lisp/DisplacedArray.java
r3631 r3733 3 3 * 4 4 * Copyright (C) 2003 Peter Graves 5 * $Id: DisplacedArray.java,v 1. 3 2003-09-08 18:28:06piso Exp $5 * $Id: DisplacedArray.java,v 1.4 2003-09-13 23:40:54 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 24 24 public final class DisplacedArray extends AbstractArray 25 25 { 26 private final int[] dimv; 27 private final int size; 26 28 private final AbstractArray array; 27 29 private final int offset; 28 30 29 public DisplacedArray( AbstractArray array, int offset)31 public DisplacedArray(int[] dimv, AbstractArray array, int offset) 30 32 { 33 this.dimv = dimv; 34 size = computeTotalSize(dimv); 31 35 this.array = array; 32 36 this.offset = offset; 37 } 38 39 private static int computeTotalSize(int[] dimensions) 40 { 41 int size = 1; 42 for (int i = dimensions.length; i-- > 0;) 43 size *= dimensions[i]; 44 return size; 45 } 46 47 public LispObject typeOf() 48 { 49 if (getRank() == 1) { 50 if (array instanceof LispString) 51 return Symbol.STRING; 52 return list3(Symbol.VECTOR, T, new Fixnum(size)); 53 } 54 return list3(Symbol.ARRAY, T, getDimensions()); 33 55 } 34 56 … … 37 59 if (typeSpecifier == Symbol.ARRAY) 38 60 return T; 61 if (typeSpecifier == Symbol.VECTOR) 62 return getRank() == 1 ? T : NIL; 39 63 if (typeSpecifier instanceof LispClass) { 40 64 final String name = typeSpecifier.getName(); … … 50 74 { 51 75 if (getRank() == 1) 52 return array.getDimension(0) - offset;76 return size; 53 77 throw new TypeError(this, "sequence"); 54 78 } … … 66 90 public int getRank() 67 91 { 68 return array.getRank();92 return dimv.length; 69 93 } 70 94 71 95 public LispObject getDimensions() 72 96 { 73 return array.getDimensions(); 97 LispObject result = NIL; 98 for (int i = dimv.length; i-- > 0;) 99 result = new Cons(new Fixnum(dimv[i]), result); 100 return result; 74 101 } 75 102 76 103 public int getDimension(int n) throws LispError 77 104 { 78 return array.getDimension(n); 105 try { 106 return dimv[n]; 107 } 108 catch (ArrayIndexOutOfBoundsException e) { 109 throw new TypeError("bad array dimension"); 110 } 79 111 } 80 112 … … 86 118 public int getTotalSize() 87 119 { 88 return array.getTotalSize() - offset;120 return size; 89 121 } 90 122 91 123 public LispObject getRowMajor(int index) throws LispError 92 124 { 93 return array.getRowMajor(index + offset); 125 if (index >= 0 && index < size) 126 return array.getRowMajor(index + offset); 127 throw new TypeError("bad row major index " + index); 94 128 } 95 129 96 130 public void setRowMajor(int index, LispObject newValue) throws LispError 97 131 { 98 array.setRowMajor(index + offset, newValue); 132 if (index >= 0 && index < size) 133 array.setRowMajor(index + offset, newValue); 134 throw new TypeError("bad row major index " + index); 99 135 } 100 136
Note: See TracChangeset
for help on using the changeset viewer.