[armedbear-cvs] r11548 - trunk/abcl/src/org/armedbear/lisp

Ville Voutilainen vvoutilainen at common-lisp.net
Tue Jan 6 12:12:15 UTC 2009


Author: vvoutilainen
Date: Tue Jan  6 12:12:14 2009
New Revision: 11548

Log:
Remove bindArg duplication.


Modified:
   trunk/abcl/src/org/armedbear/lisp/Closure.java
   trunk/abcl/src/org/armedbear/lisp/Lisp.java
   trunk/abcl/src/org/armedbear/lisp/SpecialOperators.java

Modified: trunk/abcl/src/org/armedbear/lisp/Closure.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Closure.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Closure.java	Tue Jan  6 12:12:14 2009
@@ -427,7 +427,7 @@
       {
         bindParameterDefaults(optionalParameters, ext, thread);
         if (restVar != null)
-          bindArg(restVar, NIL, ext, thread);
+          bindArg(specials, restVar, NIL, ext, thread);
         bindParameterDefaults(keywordParameters, ext, thread);
       }
     bindAuxVars(ext, thread);
@@ -448,10 +448,10 @@
   {
     // &whole and &environment before anything
     if (envVar != null)
-      bindArg(envVar, environment, ext, thread);
+      bindArg(specials, envVar, environment, ext, thread);
     for (int i = 0; i < objects.length; ++i)
       {
-        bindArg(requiredParameters[i].var, objects[i], ext, thread);
+        bindArg(specials, requiredParameters[i].var, objects[i], ext, thread);
       }
   }
 
@@ -644,12 +644,12 @@
     Debug.assertTrue(args.length == variables.length);
     if (envVar != null)
       {
-        bindArg(envVar, environment, ext, thread);
+        bindArg(specials, envVar, environment, ext, thread);
       }
     for (int i = 0; i < variables.length; i++)
       {
         Symbol sym = variables[i];
-        bindArg(sym, args[i], ext, thread);
+        bindArg(specials, sym, args[i], ext, thread);
       }
     bindAuxVars(ext, thread);
     special:
@@ -672,18 +672,6 @@
       }
   }
 
-  private final boolean isSpecial(Symbol sym)
-  {
-    if (sym.isSpecialVariable())
-      return true;
-    for (Symbol special : specials)
-      {
-        if (sym == special)
-            return true;
-      }
-    return false;
-  }
-
   protected final LispObject[] processArgs(LispObject[] args, LispThread thread)
     throws ConditionThrowable
   {
@@ -711,12 +699,12 @@
     // &whole before any other variables in the lambda list..."
     if (bindInitForms)
       if (envVar != null)
-          bindArg(envVar, environment, ext, thread);
+	bindArg(specials, envVar, environment, ext, thread);
     // Required parameters.
     for (int i = 0; i < minArgs; i++)
       {
         if (bindInitForms)
-          bindArg(requiredParameters[i].var, args[i], ext, thread);
+          bindArg(specials, requiredParameters[i].var, args[i], ext, thread);
         array[index++] = args[i];
       }
     int i = minArgs;
@@ -727,13 +715,13 @@
         if (i < argsLength)
           {
             if (bindInitForms)
-              bindArg(parameter.var, args[i], ext, thread);
+              bindArg(specials, parameter.var, args[i], ext, thread);
             array[index++] = args[i];
             ++argsUsed;
             if (parameter.svar != NIL)
               {
                 if (bindInitForms)
-                  bindArg((Symbol)parameter.svar, T, ext, thread);
+                  bindArg(specials, (Symbol)parameter.svar, T, ext, thread);
                 array[index++] = T;
               }
           }
@@ -746,12 +734,12 @@
             else
               value = eval(parameter.initForm, ext, thread);
             if (bindInitForms)
-              bindArg(parameter.var, value, ext, thread);
+              bindArg(specials, parameter.var, value, ext, thread);
             array[index++] = value;
             if (parameter.svar != NIL)
               {
                 if (bindInitForms)
-                  bindArg((Symbol)parameter.svar, NIL, ext, thread);
+                  bindArg(specials, (Symbol)parameter.svar, NIL, ext, thread);
                 array[index++] = NIL;
               }
           }
@@ -764,7 +752,7 @@
         for (int j = argsLength; j-- > argsUsed;)
           rest = new Cons(args[j], rest);
         if (bindInitForms)
-            bindArg(restVar, rest, ext, thread);
+	  bindArg(specials, restVar, rest, ext, thread);
         array[index++] = rest;
       }
     // Keyword parameters.
@@ -784,12 +772,12 @@
                 else
                   value = eval(parameter.initForm, ext, thread);
                 if (bindInitForms)
-                    bindArg(parameter.var, value, ext, thread);
+		  bindArg(specials, parameter.var, value, ext, thread);
                 array[index++] = value;
                 if (parameter.svar != NIL)
                   {
                     if (bindInitForms)
-                        bindArg((Symbol)parameter.svar, NIL, ext, thread);
+		      bindArg(specials, (Symbol)parameter.svar, NIL, ext, thread);
                     array[index++] = NIL;
                   }
               }
@@ -809,12 +797,12 @@
                     if (args[j] == keyword)
                       {
                         if (bindInitForms)
-                            bindArg(parameter.var, args[j+1], ext, thread);
+			  bindArg(specials, parameter.var, args[j+1], ext, thread);
                         value = array[index++] = args[j+1];
                         if (parameter.svar != NIL)
                           {
                             if (bindInitForms)
-                                bindArg((Symbol)parameter.svar, T, ext, thread);
+			      bindArg(specials,(Symbol)parameter.svar, T, ext, thread);
                             array[index++] = T;
                           }
                         args[j] = null;
@@ -830,12 +818,12 @@
                     else
                       value = eval(parameter.initForm, ext, thread);
                     if (bindInitForms)
-                        bindArg(parameter.var, value, ext, thread);
+		      bindArg(specials, parameter.var, value, ext, thread);
                     array[index++] = value;
                     if (parameter.svar != NIL)
                       {
                         if (bindInitForms)
-                            bindArg((Symbol)parameter.svar, NIL, ext, thread);
+			  bindArg(specials, (Symbol)parameter.svar, NIL, ext, thread);
                         array[index++] = NIL;
                       }
                   }
@@ -1029,24 +1017,12 @@
           value = parameter.initVal;
         else
           value = eval(parameter.initForm, env, thread);
-        bindArg(parameter.var, value, env, thread);
+        bindArg(specials, parameter.var, value, env, thread);
         if (parameter.svar != NIL)
-            bindArg((Symbol)parameter.svar, NIL, env, thread);
+	  bindArg(specials, (Symbol)parameter.svar, NIL, env, thread);
       }
   }
 
-    private final void bindArg(Symbol sym, LispObject value,
-                               Environment env, LispThread thread)
-        throws ConditionThrowable
-    {
-        if (isSpecial(sym)) {
-            env.declareSpecial(sym);
-            thread.bindSpecial(sym, value);
-        }
-        else
-            env.bind(sym, value);
-    }
-
   private final void bindAuxVars(Environment env, LispThread thread)
     throws ConditionThrowable
   {
@@ -1061,7 +1037,7 @@
         else
           value = eval(parameter.initForm, env, thread);
 
-        bindArg(sym, value, env, thread);
+        bindArg(specials, sym, value, env, thread);
       }
   }
 

Modified: trunk/abcl/src/org/armedbear/lisp/Lisp.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Lisp.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/Lisp.java	Tue Jan  6 12:12:14 2009
@@ -562,14 +562,32 @@
   }
 
   // Environment wrappers.
-  public static final void bind(Symbol symbol, LispObject value,
-                                Environment env)
+  private static final boolean isSpecial(Symbol sym, Symbol[] ownSpecials,
+					 Environment env)
+  {
+    if (ownSpecials != null)
+      {
+	if (sym.isSpecialVariable())
+	  return true;
+	for (Symbol special : ownSpecials)
+	  {
+	    if (sym == special)
+	      return true;
+	  }
+      }
+    return false;
+  }
+  protected static final void bindArg(Symbol[] ownSpecials,
+				      Symbol sym, LispObject value,
+				      Environment env, LispThread thread)
     throws ConditionThrowable
   {
-    if (symbol.isSpecialVariable() || env.isDeclaredSpecial(symbol))
-      LispThread.currentThread().bindSpecial(symbol, value);
+    if (isSpecial(sym, ownSpecials, env)) {
+      env.declareSpecial(sym);
+      thread.bindSpecial(sym, value);
+    }
     else
-      env.bind(symbol, value);
+      env.bind(sym, value);
   }
 
   public static final Cons list1(LispObject obj1)

Modified: trunk/abcl/src/org/armedbear/lisp/SpecialOperators.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/SpecialOperators.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/SpecialOperators.java	Tue Jan  6 12:12:14 2009
@@ -109,24 +109,6 @@
       }
     };
 
-  private static final void bindArg(LispObject specials, Symbol symbol,
-			       LispObject value, Environment ext)
-    throws ConditionThrowable
-    {
-      final LispThread thread = LispThread.currentThread();
-      if (specials != NIL && memq(symbol, specials))
-	{
-	  thread.bindSpecial(symbol, value);
-	  ext.declareSpecial(symbol);
-	}
-      else if (symbol.isSpecialVariable())
-	{
-	  thread.bindSpecial(symbol, value);
-	}
-      else
-	  ext.bind(symbol, value);
-    }
-
   private static final LispObject _let(LispObject args, Environment env,
                                        boolean sequential)
     throws ConditionThrowable
@@ -138,7 +120,7 @@
         LispObject varList = checkList(args.car());
         LispObject body = args.cdr();
         // Process declarations.
-        LispObject specials = NIL;
+        ArrayList<Symbol> specials = new ArrayList<Symbol>();
         while (body != NIL)
           {
             LispObject obj = body.car();
@@ -153,7 +135,7 @@
                         LispObject vars = ((Cons)decl).cdr;
                         while (vars != NIL)
                           {
-                            specials = new Cons(vars.car(), specials);
+			    specials.add(0, (Symbol) vars.car());
                             vars = ((Cons)vars).cdr;
                           }
                       }
@@ -166,6 +148,7 @@
           }
         Environment ext = new Environment(env);
 	LinkedList<Cons> nonSequentialVars = new LinkedList<Cons>();
+	Symbol[] arrayToUseForSpecials = new Symbol[0];
         while (varList != NIL)
           {
             final Symbol symbol;
@@ -200,7 +183,8 @@
                 value = NIL;
               }
 	    if (sequential)
-		bindArg(specials, symbol, value, ext);
+		bindArg(specials.toArray(arrayToUseForSpecials), 
+			symbol, value, ext, thread);
 	    else
 		nonSequentialVars.add(new Cons(symbol, value));
             varList = ((Cons)varList).cdr;
@@ -209,18 +193,17 @@
 	  {
 	    for (Cons x : nonSequentialVars)
 	      {
-		bindArg(specials, (Symbol)x.car(), x.cdr(), ext);
+		bindArg(specials.toArray(arrayToUseForSpecials), 
+			(Symbol)x.car(), x.cdr(), ext, thread);
 	      }
 	  }
         // Make sure free special declarations are visible in the body.
         // "The scope of free declarations specifically does not include
         // initialization forms for bindings established by the form
         // containing the declarations." (3.3.4)
-        while (specials != NIL)
+        for (Symbol symbol : specials)
           {
-            Symbol symbol = (Symbol) specials.car();
             ext.declareSpecial(symbol);
-            specials = ((Cons)specials).cdr;
           }
         return progn(body, ext, thread);
       }
@@ -264,7 +247,7 @@
                               symbol.writeToString() +
                               " with SYMBOL-MACROLET."));
                           }
-                        bind(symbol, new SymbolMacro(obj.cadr()), ext);
+                        bindArg(null, symbol, new SymbolMacro(obj.cadr()), ext, thread);
                       }
                     else
                       {




More information about the armedbear-cvs mailing list