source: trunk/abcl/src/org/armedbear/lisp/arglist.java

Last change on this file was 12513, checked in by ehuelsmann, 14 years ago

Remove 'private' keyword to eliminate the Java requirement

for the compiler to generate synthetic accessors: functions that
don't appear in the source but do appear in the class file.

Patch by: Douglas Miles <dmiles _at_ users.sf.net>

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.8 KB
Line 
1/*
2 * arglist.java
3 *
4 * Copyright (C) 2003-2005 Peter Graves
5 * $Id: arglist.java 12513 2010-03-02 22:35:36Z ehuelsmann $
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 *
21 * As a special exception, the copyright holders of this library give you
22 * permission to link this library with independent modules to produce an
23 * executable, regardless of the license terms of these independent
24 * modules, and to copy and distribute the resulting executable under
25 * terms of your choice, provided that you also meet, for each linked
26 * independent module, the terms and conditions of the license of that
27 * module.  An independent module is a module which is not derived from
28 * or based on this library.  If you modify this library, you may extend
29 * this exception to your version of the library, but you are not
30 * obligated to do so.  If you do not wish to do so, delete this
31 * exception statement from your version.
32 */
33
34package org.armedbear.lisp;
35
36import static org.armedbear.lisp.Lisp.*;
37
38public final class arglist
39{
40    static final Operator getOperator(LispObject obj)
41
42    {
43        if (obj instanceof Operator)
44            return (Operator) obj;
45        if (obj instanceof Symbol) {
46            LispObject function = obj.getSymbolFunction();
47            if (function instanceof Autoload) {
48                Autoload autoload = (Autoload) function;
49                autoload.load();
50                function = autoload.getSymbol().getSymbolFunction();
51            }
52            if (function instanceof Operator) {
53                Operator operator = (Operator) function;
54                if (operator.getLambdaList() != null)
55                    return operator;
56                LispObject other = get(obj, Symbol.MACROEXPAND_MACRO, null);
57                if (other != null)
58                    return getOperator(other);
59                else
60                    return null;
61            }
62        } else if (obj instanceof Cons && obj.car() == Symbol.LAMBDA)
63            return new Closure(obj, new Environment());
64        return null;
65    }
66
67    // ### arglist
68    private static final Primitive ARGLIST =
69        new Primitive("arglist", PACKAGE_EXT, true, "extended-function-designator")
70    {
71        @Override
72        public LispObject execute(LispObject arg)
73        {
74            LispThread thread = LispThread.currentThread();
75            Operator operator = getOperator(arg);
76            LispObject arglist = null;
77            if (operator != null)
78                arglist = operator.getLambdaList();
79            final LispObject value1, value2;
80            if (arglist instanceof AbstractString) {
81                String s = arglist.getStringValue();
82                // Give the string list syntax.
83                s = "(" + s + ")";
84                // Bind *PACKAGE* so we use the EXT package if we need
85                // to intern any symbols.
86                final SpecialBindingsMark mark = thread.markSpecialBindings();
87                thread.bindSpecial(Symbol._PACKAGE_, PACKAGE_EXT);
88                try {
89                    arglist = readObjectFromString(s);
90                }
91                finally {
92                    thread.resetSpecialBindings(mark);
93                }
94                operator.setLambdaList(arglist);
95            }
96            if (arglist != null) {
97                value1 = arglist;
98                value2 = T;
99            } else {
100                value1 = NIL;
101                value2 = NIL;
102            }
103            return thread.setValues(value1, value2);
104        }
105    };
106
107    // ### %set-arglist
108    private static final Primitive _SET_ARGLIST =
109        new Primitive("%set-arglist", PACKAGE_SYS, false)
110    {
111        @Override
112        public LispObject execute(LispObject first, LispObject second)
113
114        {
115            Operator operator = null;
116            if (first instanceof Operator) {
117                operator = (Operator) first;
118            } else if (first instanceof Symbol) {
119                LispObject function = first.getSymbolFunction();
120                if (function instanceof Operator)
121                    operator = (Operator) function;
122            }
123            if (operator != null)
124                operator.setLambdaList(second);
125            return second;
126        }
127    };
128}
Note: See TracBrowser for help on using the repository browser.