Changeset 4170


Ignore:
Timestamp:
10/02/03 00:20:02 (20 years ago)
Author:
piso
Message:

Moved FUNCTION and SETQ to SpecialOperators?.java.

Location:
trunk/j/src/org/armedbear/lisp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/Primitives.java

    r4168 r4170  
    33 *
    44 * Copyright (C) 2002-2003 Peter Graves
    5  * $Id: Primitives.java,v 1.459 2003-10-02 00:02:56 piso Exp $
     5 * $Id: Primitives.java,v 1.460 2003-10-02 00:20:02 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    30813081    };
    30823082
    3083     // ### function
    3084     private static final SpecialOperator FUNCTION =
    3085         new SpecialOperator("function")
    3086     {
    3087         public LispObject execute(LispObject args, Environment env)
    3088             throws ConditionThrowable
    3089         {
    3090             final LispObject arg = args.car();
    3091             if (arg instanceof Symbol) {
    3092                 LispObject functional = env.lookupFunctional(arg);
    3093                 if (functional instanceof Autoload) {
    3094                     Autoload autoload = (Autoload) functional;
    3095                     autoload.load();
    3096                     functional = autoload.getSymbol().getSymbolFunction();
    3097                 }
    3098                 if (functional instanceof Function)
    3099                     return functional;
    3100                 throw new ConditionThrowable(new UndefinedFunction(arg));
    3101             }
    3102             if (arg instanceof Cons) {
    3103                 if (arg.car() == Symbol.LAMBDA)
    3104                     return new Closure(arg.cadr(), arg.cddr(), env);
    3105                 if (arg.car() == Symbol.SETF) {
    3106                     LispObject f = get(checkSymbol(arg.cadr()),
    3107                                        PACKAGE_SYS.intern("SETF-FUNCTION"));
    3108                     if (f instanceof Function)
    3109                         return f;
    3110                 }
    3111             }
    3112             throw new ConditionThrowable(new UndefinedFunction(arg));
    3113         }
    3114     };
    3115 
    3116     // ### setq
    3117     private static final SpecialOperator SETQ = new SpecialOperator("setq") {
    3118         public LispObject execute(LispObject args, Environment env)
    3119             throws ConditionThrowable
    3120         {
    3121             LispObject value = Symbol.NIL;
    3122             final LispThread thread = LispThread.currentThread();
    3123             while (args != NIL) {
    3124                 Symbol symbol = checkSymbol(args.car());
    3125                 args = args.cdr();
    3126                 value = eval(args.car(), env, thread);
    3127                 if (symbol.isSpecialVariable()) {
    3128                     Environment dynEnv = thread.getDynamicEnvironment();
    3129                     if (dynEnv != null) {
    3130                         Binding binding = dynEnv.getBinding(symbol);
    3131                         if (binding != null) {
    3132                             binding.value = value;
    3133                             args = args.cdr();
    3134                             continue;
    3135                         }
    3136                     }
    3137                     symbol.setSymbolValue(value);
    3138                     args = args.cdr();
    3139                     continue;
    3140                 }
    3141                 // Not special.
    3142                 Binding binding = env.getBinding(symbol);
    3143                 if (binding != null)
    3144                     binding.value = value;
    3145                 else
    3146                     symbol.setSymbolValue(value);
    3147                 args = args.cdr();
    3148             }
    3149             return value;
    3150         }
    3151     };
    3152 
    31533083    // ### multiple-value-bind
    31543084    // multiple-value-bind (var*) values-form declaration* form*
  • trunk/j/src/org/armedbear/lisp/SpecialOperators.java

    r4092 r4170  
    33 *
    44 * Copyright (C) 2003 Peter Graves
    5  * $Id: SpecialOperators.java,v 1.2 2003-09-28 01:16:25 piso Exp $
     5 * $Id: SpecialOperators.java,v 1.3 2003-10-02 00:19:50 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    250250        }
    251251    };
     252
     253    // ### function
     254    private static final SpecialOperator FUNCTION =
     255        new SpecialOperator("function")
     256    {
     257        public LispObject execute(LispObject args, Environment env)
     258            throws ConditionThrowable
     259        {
     260            final LispObject arg = args.car();
     261            if (arg instanceof Symbol) {
     262                LispObject functional = env.lookupFunctional(arg);
     263                if (functional instanceof Autoload) {
     264                    Autoload autoload = (Autoload) functional;
     265                    autoload.load();
     266                    functional = autoload.getSymbol().getSymbolFunction();
     267                }
     268                if (functional instanceof Function)
     269                    return functional;
     270                throw new ConditionThrowable(new UndefinedFunction(arg));
     271            }
     272            if (arg instanceof Cons) {
     273                if (arg.car() == Symbol.LAMBDA)
     274                    return new Closure(arg.cadr(), arg.cddr(), env);
     275                if (arg.car() == Symbol.SETF) {
     276                    LispObject f = get(checkSymbol(arg.cadr()),
     277                                       PACKAGE_SYS.intern("SETF-FUNCTION"));
     278                    if (f instanceof Function)
     279                        return f;
     280                }
     281            }
     282            throw new ConditionThrowable(new UndefinedFunction(arg));
     283        }
     284    };
     285
     286    // ### setq
     287    private static final SpecialOperator SETQ = new SpecialOperator("setq") {
     288        public LispObject execute(LispObject args, Environment env)
     289            throws ConditionThrowable
     290        {
     291            LispObject value = Symbol.NIL;
     292            final LispThread thread = LispThread.currentThread();
     293            while (args != NIL) {
     294                Symbol symbol = checkSymbol(args.car());
     295                args = args.cdr();
     296                value = eval(args.car(), env, thread);
     297                if (symbol.isSpecialVariable()) {
     298                    Environment dynEnv = thread.getDynamicEnvironment();
     299                    if (dynEnv != null) {
     300                        Binding binding = dynEnv.getBinding(symbol);
     301                        if (binding != null) {
     302                            binding.value = value;
     303                            args = args.cdr();
     304                            continue;
     305                        }
     306                    }
     307                    symbol.setSymbolValue(value);
     308                    args = args.cdr();
     309                    continue;
     310                }
     311                // Not special.
     312                Binding binding = env.getBinding(symbol);
     313                if (binding != null)
     314                    binding.value = value;
     315                else
     316                    symbol.setSymbolValue(value);
     317                args = args.cdr();
     318            }
     319            return value;
     320        }
     321    };
    252322}
Note: See TracChangeset for help on using the changeset viewer.