1 21 22 package org.armedbear.lisp; 23 24 public final class ZeroRankArray extends AbstractArray 25 { 26 private final LispObject elementType; 27 private final boolean adjustable; 28 29 private LispObject data; 30 31 public ZeroRankArray(LispObject elementType, LispObject data, 32 boolean adjustable) 33 { 34 this.elementType = elementType; 35 this.data = data; 36 this.adjustable = adjustable; 37 } 38 39 public LispObject typeOf() 40 { 41 if (adjustable) 42 return list3(Symbol.ARRAY, elementType, NIL); 43 else 44 return list3(Symbol.SIMPLE_ARRAY, elementType, NIL); 45 } 46 47 public LispClass classOf() 48 { 49 return BuiltInClass.ARRAY; 50 } 51 52 public LispObject typep(LispObject type) throws ConditionThrowable 53 { 54 if (type == Symbol.SIMPLE_ARRAY) 55 return adjustable ? NIL : T; 56 return super.typep(type); 57 } 58 59 public int getRank() 60 { 61 return 0; 62 } 63 64 public LispObject getDimensions() 65 { 66 return NIL; 67 } 68 69 public int getDimension(int n) throws ConditionThrowable 70 { 71 signal(new TypeError("Bad array dimension (" + n + ") for array of rank 0.")); 72 return -1; 74 } 75 76 public LispObject getElementType() 77 { 78 return elementType; 79 } 80 81 public int getTotalSize() 82 { 83 return 1; 84 } 85 86 public LispObject getRowMajor(int index) throws ConditionThrowable 87 { 88 if (index == 0) 89 return data; 90 else 91 return signal(new TypeError("Bad row major index " + index + ".")); 92 } 93 94 public void setRowMajor(int index, LispObject newValue) throws ConditionThrowable 95 { 96 if (newValue.typep(elementType) == NIL) 97 signal(new TypeError(newValue, elementType)); 98 if (index == 0) 99 data = newValue; 100 else 101 signal(new TypeError("Bad row major index " + index + ".")); 102 } 103 104 public void fill(LispObject obj) throws ConditionThrowable 105 { 106 if (obj.typep(elementType) == NIL) 107 signal(new TypeError(obj, elementType)); 108 data = obj; 109 } 110 111 public String writeToString() throws ConditionThrowable 112 { 113 if (_PRINT_READABLY_.symbolValue() != NIL || _PRINT_ARRAY_.symbolValue() != NIL) { 114 StringBuffer sb = new StringBuffer ("#0A"); 115 sb.append(data.writeToString()); 116 return sb.toString(); 117 } else { 118 StringBuffer sb = new StringBuffer (); 119 if (!adjustable) 120 sb.append("SIMPLE-"); 121 sb.append("ARRAY "); 122 sb.append(elementType.writeToString()); 123 sb.append(" NIL"); 124 return unreadableString(sb.toString()); 125 } 126 } 127 } 128 | Popular Tags |