001: /*
002: * CompiledFunction.java
003: *
004: * Copyright (C) 2003-2004 Peter Graves
005: * $Id: CompiledFunction.java,v 1.29 2004/09/18 18:43:55 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.lisp;
023:
024: public class CompiledFunction extends Closure {
025: public CompiledFunction(Symbol symbol, LispObject lambdaList,
026: LispObject body, Environment env) throws ConditionThrowable {
027: super (null, lambdaList, body, env);
028: }
029:
030: public LispObject typep(LispObject typeSpecifier)
031: throws ConditionThrowable {
032: if (typeSpecifier == Symbol.COMPILED_FUNCTION)
033: return T;
034: return super .typep(typeSpecifier);
035: }
036:
037: public LispObject execute() throws ConditionThrowable {
038: LispObject[] args = new LispObject[0];
039: return execute(args);
040: }
041:
042: public LispObject execute(LispObject arg) throws ConditionThrowable {
043: LispObject[] args = new LispObject[1];
044: args[0] = arg;
045: return execute(args);
046: }
047:
048: public LispObject execute(LispObject first, LispObject second)
049: throws ConditionThrowable {
050: LispObject[] args = new LispObject[2];
051: args[0] = first;
052: args[1] = second;
053: return execute(args);
054: }
055:
056: public LispObject execute(LispObject first, LispObject second,
057: LispObject third) throws ConditionThrowable {
058: LispObject[] args = new LispObject[3];
059: args[0] = first;
060: args[1] = second;
061: args[2] = third;
062: return execute(args);
063: }
064:
065: public LispObject execute(LispObject first, LispObject second,
066: LispObject third, LispObject fourth)
067: throws ConditionThrowable {
068: LispObject[] args = new LispObject[4];
069: args[0] = first;
070: args[1] = second;
071: args[2] = third;
072: args[3] = fourth;
073: return execute(args);
074: }
075:
076: public LispObject execute(LispObject[] args)
077: throws ConditionThrowable {
078: return signal(new LispError(
079: "CompiledFunction.execute(): not implemented"));
080: }
081:
082: // ### load-compiled-function
083: private static final Primitive LOAD_COMPILED_FUNCTION = new Primitive(
084: "load-compiled-function", PACKAGE_SYS, true, "pathname") {
085: public LispObject execute(LispObject arg)
086: throws ConditionThrowable {
087: String namestring = null;
088: if (arg instanceof Pathname) {
089: namestring = ((Pathname) arg).getNamestring();
090: } else if (arg instanceof AbstractString) {
091: namestring = arg.getStringValue();
092: }
093: if (namestring != null)
094: return loadCompiledFunction(namestring);
095: return signal(new LispError("Unable to load "
096: + arg.writeToString()));
097: }
098: };
099:
100: // ### varlist
101: private static final Primitive1 VARLIST = new Primitive1("varlist",
102: PACKAGE_SYS, false) {
103: public LispObject execute(LispObject arg)
104: throws ConditionThrowable {
105: if (arg instanceof Closure)
106: return ((Closure) arg).getVariableList();
107: return signal(new TypeError(arg, "compiled function"));
108: }
109: };
110: }
|