1 21 22 package org.armedbear.lisp; 23 24 public final class arglist extends Lisp 25 { 26 private static final Functional getFunctional(LispObject obj) 27 throws ConditionThrowable 28 { 29 if (obj instanceof Functional) 30 return (Functional) obj; 31 if (obj instanceof Symbol) { 32 LispObject fun = obj.getSymbolFunction(); 33 if (fun instanceof Autoload) { 34 Autoload autoload = (Autoload) fun; 35 autoload.load(); 36 fun = (Functional)autoload.getSymbol().getSymbolFunction(); 37 } 38 if (fun instanceof Functional) { 39 Functional func = (Functional) fun; 40 if (func.getArglist() != null) 41 return func; 42 LispObject other = 43 get(checkSymbol(obj), Symbol.MACROEXPAND_MACRO, NIL); 44 if (other != null) 45 return getFunctional(other); 46 else 47 return null; 48 } 49 } else if (obj instanceof Cons && obj.car() == Symbol.LAMBDA) 50 return new Closure(obj.cadr(), obj.cddr(), new Environment()); 51 return null; 52 } 53 54 private static final Primitive1 ARGLIST = 56 new Primitive1("arglist", PACKAGE_EXT, true) 57 { 58 public LispObject execute(LispObject arg) throws ConditionThrowable 59 { 60 LispThread thread = LispThread.currentThread(); 61 Functional functional = getFunctional(arg); 62 LispObject arglist = null; 63 if (functional != null) 64 arglist = functional.getArglist(); 65 final LispObject value1, value2; 66 if (arglist instanceof AbstractString) { 67 String s = arglist.getStringValue(); 68 s = "(" + s + ")"; 70 Environment oldDynEnv = thread.getDynamicEnvironment(); 73 thread.bindSpecial(_PACKAGE_, PACKAGE_EXT); 74 try { 75 arglist = readObjectFromString(s); 76 } 77 finally { 78 thread.setDynamicEnvironment(oldDynEnv); 79 } 80 functional.setArglist(arglist); 81 } 82 if (arglist != null) { 83 value1 = arglist; 84 value2 = T; 85 } else { 86 value1 = NIL; 87 value2 = NIL; 88 } 89 return thread.setValues(value1, value2); 90 } 91 }; 92 93 private static final Primitive2 _SET_ARGLIST = 95 new Primitive2("%set-arglist", PACKAGE_SYS, false) 96 { 97 public LispObject execute(LispObject first, LispObject second) 98 throws ConditionThrowable 99 { 100 coerceToFunctional(first).setArglist(second); 101 return second; 102 } 103 }; 104 } 105 | Popular Tags |