1 21 22 package org.armedbear.lisp; 23 24 public abstract class Function extends Functional 25 { 26 private final Symbol symbol; 27 28 private int callCount; 29 30 protected Function() 31 { 32 symbol = null; 33 } 34 35 public Function(String name) 36 { 37 if (name != null) { 38 symbol = Symbol.addFunction(name.toUpperCase(), this); 39 if (cold) 40 symbol.setBuiltInFunction(true); 41 setLambdaName(symbol); 42 } else 43 symbol = null; 44 } 45 46 public Function(String name, String arglist) 47 { 48 this(name); 49 setArglist(new SimpleString(arglist)); 50 } 51 52 public Function(String name, Package pkg) 53 { 54 this(name, pkg, false); 55 } 56 57 public Function(String name, Package pkg, boolean exported) 58 { 59 this(name, pkg, exported, null, null); 60 } 61 62 public Function(String name, Package pkg, boolean exported, 63 String arglist) 64 { 65 this(name, pkg, exported, arglist, null); 66 } 67 68 public Function(String name, Package pkg, boolean exported, 69 String arglist, String docstring) 70 { 71 if (arglist instanceof String ) 72 setArglist(new SimpleString(arglist)); 73 if (name != null) { 74 symbol = pkg.intern(name.toUpperCase()); 75 symbol.setSymbolFunction(this); 76 if (cold) 77 symbol.setBuiltInFunction(true); 78 setLambdaName(symbol); 79 if (exported) { 80 try { 81 pkg.export(symbol); 82 } 83 catch (ConditionThrowable t) { 84 Debug.assertTrue(false); 85 } 86 } 87 if (docstring != null) { 88 try { 89 symbol.setFunctionDocumentation(docstring); 90 } 91 catch (ConditionThrowable t) { 92 Debug.assertTrue(false); 93 } 94 } 95 } else 96 symbol = null; 97 } 98 99 public Function(Symbol symbol) 100 { 101 this.symbol = symbol; 102 } 103 104 public LispObject typeOf() 105 { 106 return Symbol.FUNCTION; 107 } 108 109 public LispClass classOf() 110 { 111 return BuiltInClass.FUNCTION; 112 } 113 114 public LispObject typep(LispObject typeSpecifier) throws ConditionThrowable 115 { 116 if (typeSpecifier == Symbol.FUNCTION) 117 return T; 118 if (typeSpecifier == Symbol.COMPILED_FUNCTION) 119 return T; 120 if (typeSpecifier == BuiltInClass.FUNCTION) 121 return T; 122 return super.typep(typeSpecifier); 123 } 124 125 public Symbol getSymbol() 126 { 127 return symbol; 128 } 129 130 public final String getName() 131 { 132 return symbol != null ? symbol.getName() : null; 133 } 134 135 public LispObject execute() throws ConditionThrowable 137 { 138 return signal(new WrongNumberOfArgumentsException(this)); 139 } 140 141 public LispObject execute(LispObject arg) throws ConditionThrowable 143 { 144 return signal(new WrongNumberOfArgumentsException(this)); 145 } 146 147 public LispObject execute(LispObject first, LispObject second) 149 throws ConditionThrowable 150 { 151 return signal(new WrongNumberOfArgumentsException(this)); 152 } 153 154 public LispObject execute(LispObject first, LispObject second, 156 LispObject third) 157 throws ConditionThrowable 158 { 159 return signal(new WrongNumberOfArgumentsException(this)); 160 } 161 162 public LispObject execute(LispObject first, LispObject second, 164 LispObject third, LispObject fourth) 165 throws ConditionThrowable 166 { 167 return signal(new WrongNumberOfArgumentsException(this)); 168 } 169 170 public LispObject execute(LispObject[] args) throws ConditionThrowable 172 { 173 return signal(new WrongNumberOfArgumentsException(this)); 174 } 175 176 public String writeToString() throws ConditionThrowable 177 { 178 LispObject name = getLambdaName(); 179 if (name == null) 180 name = getSymbol(); 181 if (name != null) { 182 StringBuffer sb = new StringBuffer ("#<FUNCTION"); 183 sb.append(' '); 184 sb.append(name.writeToString()); 185 sb.append('>'); 186 return sb.toString(); 187 } else 188 return unreadableString("FUNCTION"); 189 } 190 191 public final int getCallCount() 193 { 194 return callCount; 195 } 196 197 public void setCallCount(int n) 198 { 199 callCount = n; 200 } 201 202 public final void incrementCallCount() 203 { 204 ++callCount; 205 } 206 } 207 | Popular Tags |