source: branches/0.25.x/abcl/src/org/armedbear/lisp/Lisp.java

Last change on this file was 13149, checked in by astalla, 15 years ago

Keep sys::make-fasl-class-loader API compatible to avoid changing the FASL version number.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 90.4 KB
Line 
1/*
2 * Lisp.java
3 *
4 * Copyright (C) 2002-2007 Peter Graves <peter@armedbear.org>
5 * $Id: Lisp.java 13149 2011-01-14 21:12:30Z astalla $
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 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 java.io.File;
37import java.io.FileInputStream;
38import java.io.FileNotFoundException;
39import java.io.IOException;
40import java.io.InputStream;
41import java.math.BigInteger;
42import java.net.MalformedURLException;
43import java.net.URL;
44import java.net.URLDecoder;
45import java.util.Hashtable;
46
47public final class Lisp
48{
49  public static final boolean debug = true;
50
51  public static boolean cold = true;
52
53  public static boolean initialized;
54
55  // Packages.
56  public static final Package PACKAGE_CL =
57    Packages.createPackage("COMMON-LISP", 2048); // EH 10-10-2010: Actual number = 1014
58  public static final Package PACKAGE_CL_USER =
59    Packages.createPackage("COMMON-LISP-USER", 1024);
60  public static final Package PACKAGE_KEYWORD =
61    Packages.createPackage("KEYWORD", 1024);
62  public static final Package PACKAGE_SYS =
63    Packages.createPackage("SYSTEM", 2048); // EH 10-10-2010: Actual number = 1216
64  public static final Package PACKAGE_MOP =
65    Packages.createPackage("MOP", 512); // EH 10-10-2010: Actual number = 277
66  public static final Package PACKAGE_TPL =
67    Packages.createPackage("TOP-LEVEL", 128); // EH 10-10-2010: Actual number = 6
68  public static final Package PACKAGE_EXT =
69    Packages.createPackage("EXTENSIONS", 256); // EH 10-10-2010: Actual number = 131
70  public static final Package PACKAGE_JVM =
71    Packages.createPackage("JVM", 2048); // EH 10-10-2010: Actual number = 1518
72  public static final Package PACKAGE_LOOP =
73    Packages.createPackage("LOOP", 512); // EH 10-10-2010: Actual number = 305
74  public static final Package PACKAGE_PROF =
75    Packages.createPackage("PROFILER");
76  public static final Package PACKAGE_JAVA =
77    Packages.createPackage("JAVA");
78  public static final Package PACKAGE_LISP =
79    Packages.createPackage("LISP");
80  public static final Package PACKAGE_THREADS =
81    Packages.createPackage("THREADS");
82  public static final Package PACKAGE_FORMAT =
83    Packages.createPackage("FORMAT");
84  public static final Package PACKAGE_XP =
85    Packages.createPackage("XP");
86  public static final Package PACKAGE_PRECOMPILER =
87    Packages.createPackage("PRECOMPILER");
88  public static final Package PACKAGE_SEQUENCE =
89    Packages.createPackage("SEQUENCE", 128); // EH 10-10-2010: Actual number 62
90
91
92  @DocString(name="nil")
93  public static final LispObject NIL = Nil.NIL;
94
95  // We need NIL before we can call usePackage().
96  static
97  {
98    PACKAGE_CL.addNickname("CL");
99    PACKAGE_CL_USER.addNickname("CL-USER");
100    PACKAGE_CL_USER.usePackage(PACKAGE_CL);
101    PACKAGE_CL_USER.usePackage(PACKAGE_EXT);
102    PACKAGE_CL_USER.usePackage(PACKAGE_JAVA);
103    PACKAGE_SYS.addNickname("SYS");
104    PACKAGE_SYS.usePackage(PACKAGE_CL);
105    PACKAGE_SYS.usePackage(PACKAGE_EXT);
106    PACKAGE_MOP.usePackage(PACKAGE_CL);
107    PACKAGE_MOP.usePackage(PACKAGE_EXT);
108    PACKAGE_MOP.usePackage(PACKAGE_SYS);
109    PACKAGE_TPL.addNickname("TPL");
110    PACKAGE_TPL.usePackage(PACKAGE_CL);
111    PACKAGE_TPL.usePackage(PACKAGE_EXT);
112    PACKAGE_EXT.addNickname("EXT");
113    PACKAGE_EXT.usePackage(PACKAGE_CL);
114    PACKAGE_EXT.usePackage(PACKAGE_THREADS);
115    PACKAGE_JVM.usePackage(PACKAGE_CL);
116    PACKAGE_JVM.usePackage(PACKAGE_EXT);
117    PACKAGE_JVM.usePackage(PACKAGE_SYS);
118    PACKAGE_LOOP.usePackage(PACKAGE_CL);
119    PACKAGE_PROF.addNickname("PROF");
120    PACKAGE_PROF.usePackage(PACKAGE_CL);
121    PACKAGE_PROF.usePackage(PACKAGE_EXT);
122    PACKAGE_JAVA.usePackage(PACKAGE_CL);
123    PACKAGE_JAVA.usePackage(PACKAGE_EXT);
124    PACKAGE_LISP.usePackage(PACKAGE_CL);
125    PACKAGE_LISP.usePackage(PACKAGE_EXT);
126    PACKAGE_LISP.usePackage(PACKAGE_SYS);
127    PACKAGE_THREADS.usePackage(PACKAGE_CL);
128    PACKAGE_THREADS.usePackage(PACKAGE_EXT);
129    PACKAGE_THREADS.usePackage(PACKAGE_SYS);
130    PACKAGE_FORMAT.usePackage(PACKAGE_CL);
131    PACKAGE_FORMAT.usePackage(PACKAGE_EXT);
132    PACKAGE_XP.usePackage(PACKAGE_CL);
133    PACKAGE_PRECOMPILER.addNickname("PRE");
134    PACKAGE_PRECOMPILER.usePackage(PACKAGE_CL);
135    PACKAGE_PRECOMPILER.usePackage(PACKAGE_EXT);
136    PACKAGE_PRECOMPILER.usePackage(PACKAGE_SYS);
137    PACKAGE_SEQUENCE.usePackage(PACKAGE_CL);
138  }
139
140  // End-of-file marker.
141  public static final LispObject EOF = new LispObject();
142
143  public static boolean profiling;
144
145  public static boolean sampling;
146
147  public static volatile boolean sampleNow;
148
149  // args must not be null!
150  public static final LispObject funcall(LispObject fun, LispObject[] args,
151                                         LispThread thread)
152
153  {
154    thread._values = null;
155
156    // 26-07-2009: For some reason we cannot "just" call the array version;
157    // it causes an error (Wrong number of arguments for LOOP-FOR-IN)
158    // which is probably a sign of an issue in our design?
159    switch (args.length)
160      {
161      case 0:
162        return thread.execute(fun);
163      case 1:
164        return thread.execute(fun, args[0]);
165      case 2:
166        return thread.execute(fun, args[0], args[1]);
167      case 3:
168        return thread.execute(fun, args[0], args[1], args[2]);
169      case 4:
170        return thread.execute(fun, args[0], args[1], args[2], args[3]);
171      case 5:
172        return thread.execute(fun, args[0], args[1], args[2], args[3],
173                              args[4]);
174      case 6:
175        return thread.execute(fun, args[0], args[1], args[2], args[3],
176                              args[4], args[5]);
177      case 7:
178        return thread.execute(fun, args[0], args[1], args[2], args[3],
179                              args[4], args[5], args[6]);
180      case 8:
181        return thread.execute(fun, args[0], args[1], args[2], args[3],
182                              args[4], args[5], args[6], args[7]);
183      default:
184        return thread.execute(fun, args);
185    }
186  }
187
188  public static final LispObject macroexpand(LispObject form,
189                                             final Environment env,
190                                             final LispThread thread)
191
192  {
193    LispObject expanded = NIL;
194    while (true)
195      {
196        form = macroexpand_1(form, env, thread);
197        LispObject[] values = thread._values;
198        if (values[1] == NIL)
199          {
200            values[1] = expanded;
201            return form;
202          }
203        expanded = T;
204      }
205  }
206
207  public static final LispObject macroexpand_1(final LispObject form,
208                                               final Environment env,
209                                               final LispThread thread)
210
211  {
212    if (form instanceof Cons)
213      {
214        LispObject car = ((Cons)form).car;
215        if (car instanceof Symbol)
216          {
217            LispObject obj = env.lookupFunction(car);
218            if (obj instanceof Autoload)
219              {
220                Autoload autoload = (Autoload) obj;
221                autoload.load();
222                obj = car.getSymbolFunction();
223              }
224            if (obj instanceof SpecialOperator)
225              {
226                obj = get(car, Symbol.MACROEXPAND_MACRO, null);
227                if (obj instanceof Autoload)
228                  {
229                    Autoload autoload = (Autoload) obj;
230                    autoload.load();
231                    obj = get(car, Symbol.MACROEXPAND_MACRO, null);
232                  }
233              }
234            if (obj instanceof MacroObject)
235              {
236                LispObject expander = ((MacroObject)obj).expander;
237                if (profiling)
238                  if (!sampling)
239                    expander.incrementCallCount();
240                LispObject hook =
241                  coerceToFunction(Symbol.MACROEXPAND_HOOK.symbolValue(thread));
242                return thread.setValues(hook.execute(expander, form, env),
243                                        T);
244              }
245          }
246      }
247    else if (form instanceof Symbol)
248      {
249        Symbol symbol = (Symbol) form;
250        LispObject obj = null;
251        if (symbol.isSpecialVariable())
252          obj = thread.lookupSpecial(symbol);
253        else
254          obj = env.lookup(symbol);
255        if (obj == null)
256          obj = symbol.getSymbolValue();
257        if (obj instanceof SymbolMacro)
258          return thread.setValues(((SymbolMacro)obj).getExpansion(), T);
259      }
260    // Not a macro.
261    return thread.setValues(form, NIL);
262  }
263
264  @DocString(name="interactive-eval")
265  private static final Primitive INTERACTIVE_EVAL =
266    new Primitive("interactive-eval", PACKAGE_SYS, true)
267    {
268      @Override
269      public LispObject execute(LispObject object)
270      {
271        final LispThread thread = LispThread.currentThread();
272        thread.setSpecialVariable(Symbol.MINUS, object);
273        LispObject result;
274        try
275          {
276            result = thread.execute(Symbol.EVAL.getSymbolFunction(), object);
277          }
278        catch (OutOfMemoryError e)
279          {
280            return error(new StorageCondition("Out of memory " + e.getMessage()));
281          }
282        catch (StackOverflowError e)
283          {
284            thread.setSpecialVariable(_SAVED_BACKTRACE_,
285                                      thread.backtrace(0));
286            return error(new StorageCondition("Stack overflow."));
287          }
288        catch (ControlTransfer c)
289          {
290            throw c;
291          }
292        catch (ProcessingTerminated c)
293          {
294            throw c;
295          }
296        catch (IntegrityError c)
297          {
298            throw c;
299          }
300        catch (Throwable t) // ControlTransfer handled above
301          {
302            Debug.trace(t);
303            thread.setSpecialVariable(_SAVED_BACKTRACE_,
304                                      thread.backtrace(0));
305            return error(new LispError("Caught " + t + "."));
306          }
307        Debug.assertTrue(result != null);
308        thread.setSpecialVariable(Symbol.STAR_STAR_STAR,
309                                  thread.safeSymbolValue(Symbol.STAR_STAR));
310        thread.setSpecialVariable(Symbol.STAR_STAR,
311                                  thread.safeSymbolValue(Symbol.STAR));
312        thread.setSpecialVariable(Symbol.STAR, result);
313        thread.setSpecialVariable(Symbol.PLUS_PLUS_PLUS,
314                                  thread.safeSymbolValue(Symbol.PLUS_PLUS));
315        thread.setSpecialVariable(Symbol.PLUS_PLUS,
316                                  thread.safeSymbolValue(Symbol.PLUS));
317        thread.setSpecialVariable(Symbol.PLUS,
318                                  thread.safeSymbolValue(Symbol.MINUS));
319        LispObject[] values = thread._values;
320        thread.setSpecialVariable(Symbol.SLASH_SLASH_SLASH,
321                                  thread.safeSymbolValue(Symbol.SLASH_SLASH));
322        thread.setSpecialVariable(Symbol.SLASH_SLASH,
323                                  thread.safeSymbolValue(Symbol.SLASH));
324        if (values != null)
325          {
326            LispObject slash = NIL;
327            for (int i = values.length; i-- > 0;)
328              slash = new Cons(values[i], slash);
329            thread.setSpecialVariable(Symbol.SLASH, slash);
330          }
331        else
332          thread.setSpecialVariable(Symbol.SLASH, new Cons(result));
333        return result;
334      }
335    };
336
337  private static final void pushJavaStackFrames()
338  {
339      final LispThread thread = LispThread.currentThread();
340      final StackTraceElement[] frames = thread.getJavaStackTrace();
341
342      // frames[0] java.lang.Thread.getStackTrace
343      // frames[1] org.armedbear.lisp.LispThread.getJavaStackTrace
344      // frames[2] org.armedbear.lisp.Lisp.pushJavaStackFrames
345
346      if (frames.length > 5
347        && frames[3].getClassName().equals("org.armedbear.lisp.Lisp")
348        && frames[3].getMethodName().equals("error")
349        && frames[4].getClassName().startsWith("org.armedbear.lisp.Lisp")
350        && frames[4].getMethodName().equals("eval")) {
351          // Error condition arising from within Lisp.eval(), so no
352          // Java stack frames should be visible to the consumer of the stack abstraction
353          return;
354      }
355      // Search for last Primitive in the StackTrace; that was the
356      // last entry point from Lisp.
357      int last = frames.length - 1;
358      for (int i = 0; i<= last; i++) {
359          if (frames[i].getClassName().startsWith("org.armedbear.lisp.Primitive"))
360            last = i;
361      }
362      // Do not include the first three frames which, as noted above, constitute
363      // the invocation of this method.
364      while (last > 2) {
365        thread.pushStackFrame(new JavaStackFrame(frames[last]));
366        last--;
367      }
368  }
369
370
371  public static final LispObject error(LispObject condition)
372  {
373    pushJavaStackFrames();
374    return Symbol.ERROR.execute(condition);
375  }
376
377  public static final int ierror(LispObject condition)
378  {
379    error(condition);
380    return 0; // Not reached
381  }
382
383  public static final String serror(LispObject condition)
384  {
385    error(condition);
386    return ""; // Not reached
387  }
388
389
390  public static final LispObject error(LispObject condition, LispObject message)
391  {
392    pushJavaStackFrames();
393    return Symbol.ERROR.execute(condition, Keyword.FORMAT_CONTROL, message);
394  }
395
396  public static final int ierror(LispObject condition, LispObject message)
397  {
398    error(condition, message);
399    return 0; // Not reached
400  }
401
402  public static final String serror(LispObject condition, LispObject message)
403  {
404    error(condition, message);
405    return ""; // Not reached
406  }
407
408
409
410  public static final LispObject type_error(LispObject datum,
411                                            LispObject expectedType)
412
413  {
414    return error(new TypeError(datum, expectedType));
415  }
416
417  public static volatile boolean interrupted;
418
419  public static synchronized final void setInterrupted(boolean b)
420  {
421    interrupted = b;
422  }
423
424  public static final void handleInterrupt()
425  {
426    setInterrupted(false);
427    Symbol.BREAK.getSymbolFunction().execute();
428    setInterrupted(false);
429  }
430
431  // Used by the compiler.
432  public static final LispObject loadTimeValue(LispObject obj)
433
434  {
435    final LispThread thread = LispThread.currentThread();
436    if (Symbol.LOAD_TRUENAME.symbolValue(thread) != NIL)
437      return eval(obj, new Environment(), thread);
438    else
439      return NIL;
440  }
441
442  public static final LispObject eval(LispObject obj)
443
444  {
445    return eval(obj, new Environment(), LispThread.currentThread());
446  }
447
448  public static final LispObject eval(final LispObject obj,
449                                      final Environment env,
450                                      final LispThread thread)
451
452  {
453    thread._values = null;
454    if (interrupted)
455      handleInterrupt();
456    if (thread.isDestroyed())
457      throw new ThreadDestroyed();
458    if (obj instanceof Symbol)
459      {
460        Symbol symbol = (Symbol)obj;
461        LispObject result;
462        if (symbol.isSpecialVariable())
463          {
464            if (symbol.constantp())
465              return symbol.getSymbolValue();
466            else
467              result = thread.lookupSpecial(symbol);
468          }
469        else if (env.isDeclaredSpecial(symbol))
470          result = thread.lookupSpecial(symbol);
471        else
472          result = env.lookup(symbol);
473        if (result == null)
474          {
475            result = symbol.getSymbolValue();
476            if (result == null)
477              return error(new UnboundVariable(obj));
478          }
479        if (result instanceof SymbolMacro)
480          return eval(((SymbolMacro)result).getExpansion(), env, thread);
481        return result;
482      }
483    else if (obj instanceof Cons)
484      {
485        LispObject first = ((Cons)obj).car;
486        if (first instanceof Symbol)
487          {
488            LispObject fun = env.lookupFunction(first);
489            if (fun instanceof SpecialOperator)
490              {
491                if (profiling)
492                  if (!sampling)
493                    fun.incrementCallCount();
494                // Don't eval args!
495                return fun.execute(((Cons)obj).cdr, env);
496              }
497            if (fun instanceof MacroObject)
498              return eval(macroexpand(obj, env, thread), env, thread);
499            if (fun instanceof Autoload)
500              {
501                Autoload autoload = (Autoload) fun;
502                autoload.load();
503                return eval(obj, env, thread);
504              }
505            return evalCall(fun != null ? fun : first,
506                            ((Cons)obj).cdr, env, thread);
507          }
508        else
509          {
510            if (first.car() == Symbol.LAMBDA)
511              {
512                Closure closure = new Closure(first, env);
513                return evalCall(closure, ((Cons)obj).cdr, env, thread);
514              }
515            else
516              return error(new ProgramError("Illegal function object: " +
517                                             first.writeToString()));
518          }
519      }
520    else
521      return obj;
522  }
523
524  public static final int CALL_REGISTERS_MAX = 8;
525
526  // Also used in JProxy.java.
527  public static final LispObject evalCall(LispObject function,
528                                             LispObject args,
529                                             Environment env,
530                                             LispThread thread)
531
532  {
533    if (args == NIL)
534      return thread.execute(function);
535    LispObject first = eval(args.car(), env, thread);
536    args = ((Cons)args).cdr;
537    if (args == NIL)
538      {
539        thread._values = null;
540        return thread.execute(function, first);
541      }
542    LispObject second = eval(args.car(), env, thread);
543    args = ((Cons)args).cdr;
544    if (args == NIL)
545      {
546        thread._values = null;
547        return thread.execute(function, first, second);
548      }
549    LispObject third = eval(args.car(), env, thread);
550    args = ((Cons)args).cdr;
551    if (args == NIL)
552      {
553        thread._values = null;
554        return thread.execute(function, first, second, third);
555      }
556    LispObject fourth = eval(args.car(), env, thread);
557    args = ((Cons)args).cdr;
558    if (args == NIL)
559      {
560        thread._values = null;
561        return thread.execute(function, first, second, third, fourth);
562      }
563    LispObject fifth = eval(args.car(), env, thread);
564    args = ((Cons)args).cdr;
565    if (args == NIL)
566      {
567        thread._values = null;
568        return thread.execute(function, first, second, third, fourth, fifth);
569      }
570    LispObject sixth = eval(args.car(), env, thread);
571    args = ((Cons)args).cdr;
572    if (args == NIL)
573      {
574        thread._values = null;
575        return thread.execute(function, first, second, third, fourth, fifth,
576                              sixth);
577      }
578    LispObject seventh = eval(args.car(), env, thread);
579    args = ((Cons)args).cdr;
580    if (args == NIL)
581      {
582        thread._values = null;
583        return thread.execute(function, first, second, third, fourth, fifth,
584                              sixth, seventh);
585      }
586    LispObject eighth = eval(args.car(), env, thread);
587    args = ((Cons)args).cdr;
588    if (args == NIL)
589      {
590        thread._values = null;
591        return thread.execute(function, first, second, third, fourth, fifth,
592                              sixth, seventh, eighth);
593      }
594    // More than CALL_REGISTERS_MAX arguments.
595    final int length = args.length() + CALL_REGISTERS_MAX;
596    LispObject[] array = new LispObject[length];
597    array[0] = first;
598    array[1] = second;
599    array[2] = third;
600    array[3] = fourth;
601    array[4] = fifth;
602    array[5] = sixth;
603    array[6] = seventh;
604    array[7] = eighth;
605    for (int i = CALL_REGISTERS_MAX; i < length; i++)
606      {
607        array[i] = eval(args.car(), env, thread);
608        args = args.cdr();
609      }
610    thread._values = null;
611    return thread.execute(function, array);
612  }
613
614  public static final LispObject parseBody(LispObject body,
615                                           boolean documentationAllowed)
616
617  {
618      LispObject decls = NIL;
619      LispObject doc = NIL;
620
621      while (body != NIL) {
622        LispObject form = body.car();
623        if (documentationAllowed && form instanceof AbstractString
624            && body.cdr() != NIL) {
625          doc = body.car();
626          documentationAllowed = false;
627        } else if (form instanceof Cons && form.car() == Symbol.DECLARE)
628          decls = new Cons(form, decls);
629        else
630          break;
631
632        body = body.cdr();
633      }
634      return list(body, decls.nreverse(), doc);
635  }
636
637  public static final LispObject parseSpecials(LispObject forms)
638
639  {
640    LispObject specials = NIL;
641    while (forms != NIL) {
642      LispObject decls = forms.car();
643
644      Debug.assertTrue(decls instanceof Cons);
645      Debug.assertTrue(decls.car() == Symbol.DECLARE);
646      decls = decls.cdr();
647      while (decls != NIL) {
648        LispObject decl = decls.car();
649
650        if (decl instanceof Cons && decl.car() == Symbol.SPECIAL) {
651            decl = decl.cdr();
652            while (decl != NIL) {
653              specials = new Cons(checkSymbol(decl.car()), specials);
654              decl = decl.cdr();
655            }
656        }
657
658        decls = decls.cdr();
659      }
660
661      forms = forms.cdr();
662    }
663
664    return specials;
665  }
666
667  public static final LispObject progn(LispObject body, Environment env,
668                                       LispThread thread)
669
670  {
671    LispObject result = NIL;
672    while (body != NIL)
673      {
674        result = eval(body.car(), env, thread);
675        body = ((Cons)body).cdr;
676      }
677    return result;
678  }
679
680  public static final LispObject preprocessTagBody(LispObject body,
681                                                   Environment env)
682
683  {
684    LispObject localTags = NIL; // Tags that are local to this TAGBODY.
685    while (body != NIL)
686      {
687        LispObject current = body.car();
688        body = ((Cons)body).cdr;
689        if (current instanceof Cons)
690          continue;
691        // It's a tag.
692        env.addTagBinding(current, body);
693        localTags = new Cons(current, localTags);
694      }
695    return localTags;
696  }
697
698  /** Throws a Go exception to cause a non-local transfer
699   * of control event, after checking that the extent of
700   * the catching tagbody hasn't ended yet.
701   *
702   * This version is used by the compiler.
703   */
704  public static final LispObject nonLocalGo(LispObject tagbody,
705                                            LispObject tag)
706
707  {
708    if (tagbody == null)
709      return error(new ControlError("Unmatched tag "
710                                    + tag.writeToString() +
711                                    " for GO outside lexical extent."));
712
713    throw new Go(tagbody, tag);
714  }
715
716  /** Throws a Go exception to cause a non-local transfer
717   * of control event, after checking that the extent of
718   * the catching tagbody hasn't ended yet.
719   *
720   * This version is used by the interpreter.
721   */
722  static final LispObject nonLocalGo(Binding binding,
723                                     LispObject tag)
724  {
725    if (binding.env.inactive)
726      return error(new ControlError("Unmatched tag "
727                                    + binding.symbol.writeToString() +
728                                    " for GO outside of lexical extent."));
729
730    throw new Go(binding.env, binding.symbol);
731  }
732
733  /** Throws a Return exception to cause a non-local transfer
734   * of control event, after checking that the extent of
735   * the catching block hasn't ended yet.
736   *
737   * This version is used by the compiler.
738   */
739  public static final LispObject nonLocalReturn(LispObject blockId,
740                                                LispObject blockName,
741                                                LispObject result)
742
743  {
744    if (blockId == null)
745      return error(new ControlError("Unmatched block "
746                                    + blockName.writeToString() + " for " +
747                                    "RETURN-FROM outside lexical extent."));
748
749    throw new Return(blockId, result);
750  }
751
752  /** Throws a Return exception to cause a non-local transfer
753   * of control event, after checking that the extent of
754   * the catching block hasn't ended yet.
755   *
756   * This version is used by the interpreter.
757   */
758  static final LispObject nonLocalReturn(Binding binding,
759                                         Symbol block,
760                                         LispObject result)
761  {
762    if (binding == null)
763      {
764        return error(new LispError("No block named " + block.getName() +
765                                   " is currently visible."));
766      }
767
768    if (binding.env.inactive)
769      return error(new ControlError("Unmatched block "
770                                    + binding.symbol.writeToString() +
771                                    " for RETURN-FROM outside of" +
772                                    " lexical extent."));
773
774    throw new Return(binding.symbol, binding.value, result);
775  }
776
777  public static final LispObject processTagBody(LispObject body,
778                                                LispObject localTags,
779                                                Environment env)
780
781  {
782    LispObject remaining = body;
783    LispThread thread = LispThread.currentThread();
784    while (remaining != NIL)
785      {
786        LispObject current = remaining.car();
787        if (current instanceof Cons)
788          {
789            try {
790              // Handle GO inline if possible.
791              if (((Cons)current).car == Symbol.GO)
792                {
793                  if (interrupted)
794                    handleInterrupt();
795                  LispObject tag = current.cadr();
796                  Binding binding = env.getTagBinding(tag);
797                  if (binding == null)
798                    return error(new ControlError("No tag named " +
799                                                  tag.writeToString() +
800                                                  " is currently visible."));
801                  else if (memql(tag, localTags))
802                    {
803                      if (binding.value != null)
804                        {
805                          remaining = binding.value;
806                          continue;
807                        }
808                    }
809                  throw new Go(binding.env, tag);
810                }
811              eval(current, env, thread);
812            }
813            catch (Go go)
814              {
815                LispObject tag;
816                if (go.getTagBody() == env
817                    && memql(tag = go.getTag(), localTags))
818                  {
819                    Binding binding = env.getTagBinding(tag);
820                    if (binding != null && binding.value != null)
821                      {
822                        remaining = binding.value;
823                        continue;
824                      }
825                  }
826                throw go;
827              }
828          }
829        remaining = ((Cons)remaining).cdr;
830      }
831    thread._values = null;
832    return NIL;
833  }
834
835  // Environment wrappers.
836  private static final boolean isSpecial(Symbol sym, LispObject ownSpecials,
837                                         Environment env)
838
839  {
840    if (ownSpecials != null)
841      {
842        if (sym.isSpecialVariable())
843          return true;
844        for (; ownSpecials != NIL; ownSpecials = ownSpecials.cdr())
845          {
846            if (sym == ownSpecials.car())
847              return true;
848          }
849      }
850    return false;
851  }
852
853  public static final void bindArg(LispObject ownSpecials,
854                                      Symbol sym, LispObject value,
855                                      Environment env, LispThread thread)
856
857  {
858    if (isSpecial(sym, ownSpecials, env)) {
859      env.declareSpecial(sym);
860      thread.bindSpecial(sym, value);
861    }
862    else
863      env.bind(sym, value);
864  }
865
866
867  public static final Cons list(LispObject obj1, LispObject... remaining)
868  {
869    Cons theList = null;
870    if (remaining.length > 0) {
871      theList = new Cons(remaining[remaining.length-1]);
872      for (int i = remaining.length - 2; i >= 0; i--)
873        theList = new Cons(remaining[i], theList);
874    }
875    return (theList == null) ? new Cons(obj1) : new Cons(obj1, theList);
876  }
877
878  @Deprecated
879  public static final Cons list1(LispObject obj1)
880  {
881    return new Cons(obj1);
882  }
883
884  @Deprecated
885  public static final Cons list2(LispObject obj1, LispObject obj2)
886  {
887    return new Cons(obj1, new Cons(obj2));
888  }
889
890  @Deprecated
891  public static final Cons list3(LispObject obj1, LispObject obj2,
892                                 LispObject obj3)
893  {
894    return new Cons(obj1, new Cons(obj2, new Cons(obj3)));
895  }
896
897  @Deprecated
898  public static final Cons list4(LispObject obj1, LispObject obj2,
899                                 LispObject obj3, LispObject obj4)
900  {
901    return new Cons(obj1,
902                    new Cons(obj2,
903                             new Cons(obj3,
904                                      new Cons(obj4))));
905  }
906
907  @Deprecated
908  public static final Cons list5(LispObject obj1, LispObject obj2,
909                                 LispObject obj3, LispObject obj4,
910                                 LispObject obj5)
911  {
912    return new Cons(obj1,
913                    new Cons(obj2,
914                             new Cons(obj3,
915                                      new Cons(obj4,
916                                               new Cons(obj5)))));
917  }
918
919  @Deprecated
920  public static final Cons list6(LispObject obj1, LispObject obj2,
921                                 LispObject obj3, LispObject obj4,
922                                 LispObject obj5, LispObject obj6)
923  {
924    return new Cons(obj1,
925                    new Cons(obj2,
926                             new Cons(obj3,
927                                      new Cons(obj4,
928                                               new Cons(obj5,
929                                                        new Cons(obj6))))));
930  }
931
932  @Deprecated
933  public static final Cons list7(LispObject obj1, LispObject obj2,
934                                 LispObject obj3, LispObject obj4,
935                                 LispObject obj5, LispObject obj6,
936                                 LispObject obj7)
937  {
938    return new Cons(obj1,
939                    new Cons(obj2,
940                             new Cons(obj3,
941                                      new Cons(obj4,
942                                               new Cons(obj5,
943                                                        new Cons(obj6,
944                                                                 new Cons(obj7)))))));
945  }
946
947  @Deprecated
948  public static final Cons list8(LispObject obj1, LispObject obj2,
949                                 LispObject obj3, LispObject obj4,
950                                 LispObject obj5, LispObject obj6,
951                                 LispObject obj7, LispObject obj8)
952  {
953    return new Cons(obj1,
954                    new Cons(obj2,
955                             new Cons(obj3,
956                                      new Cons(obj4,
957                                               new Cons(obj5,
958                                                        new Cons(obj6,
959                                                                 new Cons(obj7,
960                                                                          new Cons(obj8))))))));
961  }
962
963  @Deprecated
964  public static final Cons list9(LispObject obj1, LispObject obj2,
965                                 LispObject obj3, LispObject obj4,
966                                 LispObject obj5, LispObject obj6,
967                                 LispObject obj7, LispObject obj8,
968                                 LispObject obj9)
969  {
970    return new Cons(obj1,
971                    new Cons(obj2,
972                             new Cons(obj3,
973                                      new Cons(obj4,
974                                               new Cons(obj5,
975                                                        new Cons(obj6,
976                                                                 new Cons(obj7,
977                                                                          new Cons(obj8,
978                                                                                   new Cons(obj9)))))))));
979  }
980
981  // Used by the compiler.
982  public static final LispObject multipleValueList(LispObject result)
983
984  {
985    LispThread thread = LispThread.currentThread();
986    LispObject[] values = thread._values;
987    if (values == null)
988      return new Cons(result);
989    thread._values = null;
990    LispObject list = NIL;
991    for (int i = values.length; i-- > 0;)
992      list = new Cons(values[i], list);
993    return list;
994  }
995
996  // Used by the compiler for MULTIPLE-VALUE-CALLs with a single values form.
997  public static final LispObject multipleValueCall1(LispObject result,
998                                                    LispObject function,
999                                                    LispThread thread)
1000
1001  {
1002    LispObject[] values = thread._values;
1003    thread._values = null;
1004    if (values == null)
1005      return thread.execute(coerceToFunction(function), result);
1006    else
1007      return funcall(coerceToFunction(function), values, thread);
1008  }
1009
1010  public static final void progvBindVars(LispObject symbols,
1011                                         LispObject values,
1012                                         LispThread thread)
1013
1014  {
1015    for (LispObject list = symbols; list != NIL; list = list.cdr())
1016      {
1017        Symbol symbol = checkSymbol(list.car());
1018        LispObject value;
1019        if (values != NIL)
1020          {
1021            value = values.car();
1022            values = values.cdr();
1023          }
1024        else
1025          {
1026            // "If too few values are supplied, the remaining symbols are
1027            // bound and then made to have no value."
1028            value = null;
1029          }
1030        thread.bindSpecial(symbol, value);
1031      }
1032  }
1033
1034  public static Symbol checkSymbol(LispObject obj)
1035  {             
1036          if (obj instanceof Symbol)     
1037                  return (Symbol) obj;         
1038          return (Symbol)// Not reached.       
1039              type_error(obj, Symbol.SYMBOL);
1040  }
1041
1042  public static final LispObject checkList(LispObject obj)
1043
1044  {
1045    if (obj.listp())
1046      return obj;
1047    return type_error(obj, Symbol.LIST);
1048  }
1049
1050  public static final AbstractArray checkArray(LispObject obj)
1051
1052  {
1053          if (obj instanceof AbstractArray)       
1054                  return (AbstractArray) obj;         
1055          return (AbstractArray)// Not reached.       
1056        type_error(obj, Symbol.ARRAY);
1057  }
1058
1059  public static final AbstractVector checkVector(LispObject obj)
1060
1061  {
1062          if (obj instanceof AbstractVector)     
1063                  return (AbstractVector) obj;         
1064          return (AbstractVector)// Not reached.       
1065        type_error(obj, Symbol.VECTOR);
1066  }
1067
1068  public static final DoubleFloat checkDoubleFloat(LispObject obj)
1069
1070  {
1071          if (obj instanceof DoubleFloat)
1072                  return (DoubleFloat) obj;
1073          return (DoubleFloat)// Not reached.
1074            type_error(obj, Symbol.DOUBLE_FLOAT);
1075  }
1076
1077  public static final SingleFloat checkSingleFloat(LispObject obj)
1078
1079  {
1080          if (obj instanceof SingleFloat)
1081                  return (SingleFloat) obj;
1082          return (SingleFloat)// Not reached.
1083            type_error(obj, Symbol.SINGLE_FLOAT);
1084  }
1085
1086  public static final StackFrame checkStackFrame(LispObject obj)
1087
1088  {
1089          if (obj instanceof StackFrame)     
1090                  return (StackFrame) obj;         
1091          return (StackFrame)// Not reached.       
1092            type_error(obj, Symbol.STACK_FRAME);
1093  }
1094
1095  static
1096  {
1097    // ### *gensym-counter*
1098    Symbol.GENSYM_COUNTER.initializeSpecial(Fixnum.ZERO);
1099  }
1100
1101  public static final Symbol gensym(LispThread thread)
1102
1103  {
1104    return gensym("G", thread);
1105  }
1106
1107  public static final Symbol gensym(String prefix, LispThread thread)
1108
1109  {
1110    StringBuilder sb = new StringBuilder(prefix);
1111    SpecialBinding binding = thread.getSpecialBinding(Symbol.GENSYM_COUNTER);
1112    final LispObject oldValue;
1113    if (binding != null) {
1114        oldValue = binding.value;
1115        if (oldValue instanceof Fixnum
1116                || oldValue instanceof Bignum)
1117          binding.value = oldValue.incr();
1118        else {
1119           Symbol.GENSYM_COUNTER.setSymbolValue(Fixnum.ZERO);
1120           error(new TypeError("The value of *GENSYM-COUNTER* was not a nonnegative integer. Old value: " +
1121                                oldValue.writeToString() + " New value: 0"));
1122        }
1123    } else {
1124        // we're manipulating a global resource
1125        // make sure we operate thread-safely
1126        synchronized (Symbol.GENSYM_COUNTER) {
1127            oldValue = Symbol.GENSYM_COUNTER.getSymbolValue();
1128            if (oldValue instanceof Fixnum
1129                    || oldValue instanceof Bignum)
1130                Symbol.GENSYM_COUNTER.setSymbolValue(oldValue.incr());
1131            else {
1132               Symbol.GENSYM_COUNTER.setSymbolValue(Fixnum.ZERO);
1133               error(new TypeError("The value of *GENSYM-COUNTER* was not a nonnegative integer. Old value: " +
1134                                    oldValue.writeToString() + " New value: 0"));
1135            }
1136        }
1137    }
1138     
1139    // Decimal representation.
1140    if (oldValue instanceof Fixnum)
1141      sb.append(((Fixnum)oldValue).value);
1142    else if (oldValue instanceof Bignum)
1143      sb.append(((Bignum)oldValue).value.toString());
1144
1145    return new Symbol(new SimpleString(sb));
1146  }
1147
1148  public static final String javaString(LispObject arg)
1149
1150  {
1151    if (arg instanceof AbstractString)
1152      return arg.getStringValue();
1153    if (arg instanceof Symbol)
1154      return ((Symbol)arg).getName();
1155    if (arg instanceof LispCharacter)
1156      return String.valueOf(new char[] {((LispCharacter)arg).value});
1157    type_error(arg, list(Symbol.OR, Symbol.STRING, Symbol.SYMBOL,
1158                               Symbol.CHARACTER));
1159    // Not reached.
1160    return null;
1161  }
1162
1163  public static final LispObject number(long n)
1164  {
1165    if (n >= Integer.MIN_VALUE && n <= Integer.MAX_VALUE)
1166      return Fixnum.getInstance((int)n);
1167    else
1168      return Bignum.getInstance(n);
1169  }
1170
1171  private static final BigInteger INT_MIN = BigInteger.valueOf(Integer.MIN_VALUE);
1172  private static final BigInteger INT_MAX = BigInteger.valueOf(Integer.MAX_VALUE);
1173
1174  public static final LispObject number(BigInteger numerator,
1175                                        BigInteger denominator)
1176
1177  {
1178    if (denominator.signum() == 0)
1179      error(new DivisionByZero());
1180    if (denominator.signum() < 0)
1181      {
1182        numerator = numerator.negate();
1183        denominator = denominator.negate();
1184      }
1185    BigInteger gcd = numerator.gcd(denominator);
1186    if (!gcd.equals(BigInteger.ONE))
1187      {
1188        numerator = numerator.divide(gcd);
1189        denominator = denominator.divide(gcd);
1190      }
1191    if (denominator.equals(BigInteger.ONE))
1192      return number(numerator);
1193    else
1194      return new Ratio(numerator, denominator);
1195  }
1196
1197  public static final LispObject number(BigInteger n)
1198  {
1199    if (n.compareTo(INT_MIN) >= 0 && n.compareTo(INT_MAX) <= 0)
1200      return Fixnum.getInstance(n.intValue());
1201    else
1202      return Bignum.getInstance(n);
1203  }
1204
1205  public static final int mod(int number, int divisor)
1206
1207  {
1208    final int r;
1209    try
1210      {
1211        r = number % divisor;
1212      }
1213    catch (ArithmeticException e)
1214      {
1215        error(new ArithmeticError("Division by zero."));
1216        // Not reached.
1217        return 0;
1218      }
1219    if (r == 0)
1220      return r;
1221    if (divisor < 0)
1222      {
1223        if (number > 0)
1224          return r + divisor;
1225      }
1226    else
1227      {
1228        if (number < 0)
1229          return r + divisor;
1230      }
1231    return r;
1232  }
1233
1234  // Adapted from SBCL.
1235  public static final int mix(long x, long y)
1236  {
1237    long xy = x * 3 + y;
1238    return (int) (536870911L & (441516657L ^ xy ^ (xy >> 5)));
1239  }
1240
1241  // Used by the compiler.
1242  public static final LispObject readObjectFromString(String s)
1243  {
1244    return new StringInputStream(s).read(true, NIL, false,
1245                                         LispThread.currentThread(),
1246                                         Stream.faslReadtable);
1247  }
1248
1249    @Deprecated
1250  public static final LispObject loadCompiledFunction(final String namestring)
1251  {
1252      Pathname name = new Pathname(namestring);
1253      byte[] bytes = readFunctionBytes(name);
1254      if (bytes != null)
1255        return loadClassBytes(bytes);
1256
1257      return null;
1258  }
1259
1260  public static final byte[] readFunctionBytes(final Pathname name) {
1261      final LispThread thread = LispThread.currentThread();
1262      Pathname load = null;
1263      LispObject truenameFasl = Symbol.LOAD_TRUENAME_FASL.symbolValue(thread);
1264      LispObject truename = Symbol.LOAD_TRUENAME.symbolValue(thread);
1265      Pathname fasl = null;
1266      if (truenameFasl instanceof Pathname) {
1267          load = Pathname.mergePathnames(name, (Pathname)truenameFasl, Keyword.NEWEST);
1268      } else if (truename instanceof Pathname) {
1269          load = Pathname.mergePathnames(name, (Pathname) truename, Keyword.NEWEST);
1270      } else {
1271          if (!Pathname.truename(name).equals(NIL)) {
1272              load = name;
1273          } else {
1274              load = null;
1275          }
1276      }
1277      InputStream input = null;
1278      if (load != null) {
1279          input = load.getInputStream();
1280      } else { 
1281          // Make a last-ditch attempt to load from the boot classpath XXX OSGi hack
1282          URL url = null;
1283          try {
1284              url = Lisp.class.getResource(name.getNamestring());
1285              input = url.openStream();
1286          } catch (IOException e) {
1287        System.err.println("Failed to read class bytes from boot class " + url);
1288              error(new LispError("Failed to read class bytes from boot class " + url));
1289          }
1290      }
1291      byte[] bytes = new byte[4096];
1292      try {
1293          if (input == null) {
1294                  Debug.trace("Pathname: " + name);
1295                  Debug.trace("load: " + load);
1296                  Debug.trace("LOAD_TRUENAME_FASL: " + truenameFasl);
1297                  Debug.trace("LOAD_TRUENAME: " + truename);
1298                  Debug.assertTrue(input != null);
1299          }
1300
1301          int n = 0;
1302          java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
1303          try {
1304              while (n >= 0) {
1305                  n = input.read(bytes, 0, 4096);
1306                if (n >= 0) {
1307                    baos.write(bytes, 0, n);
1308                }
1309            }
1310          } catch (IOException e) {
1311              Debug.trace("Failed to read bytes from "
1312                          + "'" + name.getNamestring() + "'");
1313              return null;
1314          }
1315          bytes = baos.toByteArray();
1316      } finally {
1317          try {
1318              input.close();
1319          } catch (IOException e) {
1320              Debug.trace("Failed to close InputStream: " + e);
1321          }
1322      }
1323      return bytes;
1324  }
1325
1326    public static final Function makeCompiledFunctionFromClass(Class<?> c) {
1327      try {
1328  if (c != null) {
1329      Function obj = (Function)c.newInstance();
1330      return obj;
1331        } else {
1332            return null;
1333        }
1334      }
1335      catch (InstantiationException e) {} // ### FIXME
1336      catch (IllegalAccessException e) {} // ### FIXME
1337
1338      return null;
1339    }
1340
1341
1342  public static final LispObject loadCompiledFunction(InputStream in, int size)
1343  {
1344      byte[] bytes = readFunctionBytes(in, size);
1345      if (bytes != null)
1346        return loadClassBytes(bytes);
1347      else
1348        return error(new FileError("Can't read file off stream."));
1349  }
1350
1351
1352
1353  private static final byte[] readFunctionBytes(InputStream in, int size)
1354  {
1355    try
1356      {
1357        byte[] bytes = new byte[size];
1358        int bytesRemaining = size;
1359        int bytesRead = 0;
1360        while (bytesRemaining > 0)
1361          {
1362            int n = in.read(bytes, bytesRead, bytesRemaining);
1363            if (n < 0)
1364              break;
1365            bytesRead += n;
1366            bytesRemaining -= n;
1367          }
1368        in.close();
1369        if (bytesRemaining > 0)
1370          Debug.trace("bytesRemaining = " + bytesRemaining);
1371
1372        return bytes;
1373      }
1374    catch (IOException t)
1375      {
1376        Debug.trace(t); // FIXME: call error()?
1377      }
1378    return null;
1379  }
1380
1381    public static final Function loadClassBytes(byte[] bytes)
1382    {
1383      return loadClassBytes(bytes, new JavaClassLoader());
1384    }
1385
1386    public static final Function loadClassBytes(byte[] bytes,
1387                                                JavaClassLoader cl)
1388    {
1389        Class<?> c = cl.loadClassFromByteArray(null, bytes, 0, bytes.length);
1390  Function obj = makeCompiledFunctionFromClass(c);
1391  if (obj != null) {
1392      obj.setClassBytes(bytes);
1393  }
1394  return obj;
1395    }
1396
1397
1398  public static final LispObject makeCompiledClosure(LispObject template,
1399                                                     ClosureBinding[] context)
1400
1401  {
1402    return ((CompiledClosure)template).dup().setContext(context);
1403  }
1404
1405  public static final String safeWriteToString(LispObject obj)
1406  {
1407    try {
1408        return obj.writeToString();
1409      }
1410    catch (NullPointerException e)
1411      {
1412        Debug.trace(e);
1413        return "null";
1414      }
1415  }
1416
1417  public static final boolean isValidSetfFunctionName(LispObject obj)
1418  {
1419    if (obj instanceof Cons)
1420      {
1421        Cons cons = (Cons) obj;
1422        if (cons.car == Symbol.SETF && cons.cdr instanceof Cons)
1423          {
1424            Cons cdr = (Cons) cons.cdr;
1425            return (cdr.car instanceof Symbol && cdr.cdr == NIL);
1426          }
1427      }
1428    return false;
1429  }
1430
1431  public static final boolean isValidMacroFunctionName(LispObject obj)
1432  {
1433    if (obj instanceof Cons)
1434      {
1435        Cons cons = (Cons) obj;
1436        if (cons.car == Symbol.MACRO_FUNCTION && cons.cdr instanceof Cons)
1437          {
1438            Cons cdr = (Cons) cons.cdr;
1439            return (cdr.car instanceof Symbol && cdr.cdr == NIL);
1440          }
1441      }
1442    return false;
1443  }
1444
1445
1446  public static final LispObject FUNCTION_NAME =
1447    list(Symbol.OR,
1448          Symbol.SYMBOL,
1449          list(Symbol.CONS,
1450                list(Symbol.EQL, Symbol.SETF),
1451                list(Symbol.CONS, Symbol.SYMBOL, Symbol.NULL)));
1452
1453  public static final LispObject UNSIGNED_BYTE_8 =
1454    list(Symbol.UNSIGNED_BYTE, Fixnum.constants[8]);
1455
1456  public static final LispObject UNSIGNED_BYTE_16 =
1457    list(Symbol.UNSIGNED_BYTE, Fixnum.constants[16]);
1458
1459  public static final LispObject UNSIGNED_BYTE_32 =
1460    list(Symbol.UNSIGNED_BYTE, Fixnum.constants[32]);
1461
1462  public static final LispObject UNSIGNED_BYTE_32_MAX_VALUE =
1463    Bignum.getInstance(4294967296L);
1464
1465  public static final LispObject getUpgradedArrayElementType(LispObject type)
1466
1467  {
1468    if (type instanceof Symbol)
1469      {
1470        if (type == Symbol.CHARACTER || type == Symbol.BASE_CHAR ||
1471            type == Symbol.STANDARD_CHAR)
1472          return Symbol.CHARACTER;
1473        if (type == Symbol.BIT)
1474          return Symbol.BIT;
1475        if (type == NIL)
1476          return NIL;
1477      }
1478    if (type == BuiltInClass.CHARACTER)
1479      return Symbol.CHARACTER;
1480    if (type instanceof Cons)
1481      {
1482        if (type.equal(UNSIGNED_BYTE_8))
1483          return type;
1484        if (type.equal(UNSIGNED_BYTE_16))
1485          return type;
1486        if (type.equal(UNSIGNED_BYTE_32))
1487          return type;
1488        LispObject car = type.car();
1489        if (car == Symbol.INTEGER)
1490          {
1491            LispObject lower = type.cadr();
1492            LispObject upper = type.cdr().cadr();
1493            // Convert to inclusive bounds.
1494            if (lower instanceof Cons)
1495              lower = lower.car().incr();
1496            if (upper instanceof Cons)
1497              upper = upper.car().decr();
1498            if (lower.integerp() && upper.integerp())
1499              {
1500                if (lower instanceof Fixnum && upper instanceof Fixnum)
1501                  {
1502                    int l = ((Fixnum)lower).value;
1503                    if (l >= 0)
1504                      {
1505                        int u = ((Fixnum)upper).value;
1506                        if (u <= 1)
1507                          return Symbol.BIT;
1508                        if (u <= 255)
1509                          return UNSIGNED_BYTE_8;
1510                        if (u <= 65535)
1511                          return UNSIGNED_BYTE_16;
1512                        return UNSIGNED_BYTE_32;
1513                      }
1514                  }
1515                if (lower.isGreaterThanOrEqualTo(Fixnum.ZERO))
1516                  {
1517                    if (lower.isLessThan(UNSIGNED_BYTE_32_MAX_VALUE))
1518                      {
1519                        if (upper.isLessThan(UNSIGNED_BYTE_32_MAX_VALUE))
1520                          return UNSIGNED_BYTE_32;
1521                      }
1522                  }
1523              }
1524          }
1525        else if (car == Symbol.EQL)
1526          {
1527            LispObject obj = type.cadr();
1528            if (obj instanceof Fixnum)
1529              {
1530                int val = ((Fixnum)obj).value;
1531                if (val >= 0)
1532                  {
1533                    if (val <= 1)
1534                      return Symbol.BIT;
1535                    if (val <= 255)
1536                      return UNSIGNED_BYTE_8;
1537                    if (val <= 65535)
1538                      return UNSIGNED_BYTE_16;
1539                    return UNSIGNED_BYTE_32;
1540                  }
1541              }
1542            else if (obj instanceof Bignum)
1543              {
1544                if (obj.isGreaterThanOrEqualTo(Fixnum.ZERO))
1545                  {
1546                    if (obj.isLessThan(UNSIGNED_BYTE_32_MAX_VALUE))
1547                      return UNSIGNED_BYTE_32;
1548                  }
1549              }
1550          }
1551        else if (car == Symbol.MEMBER)
1552          {
1553            LispObject rest = type.cdr();
1554            while (rest != NIL)
1555              {
1556                LispObject obj = rest.car();
1557                if (obj instanceof LispCharacter)
1558                  rest = rest.cdr();
1559                else
1560                  return T;
1561              }
1562            return Symbol.CHARACTER;
1563          }
1564      }
1565    return T;
1566  }
1567
1568  public static final byte coerceLispObjectToJavaByte(LispObject obj)
1569
1570  {
1571          return (byte)Fixnum.getValue(obj);
1572  }
1573
1574  public static final LispObject coerceJavaByteToLispObject(byte b)
1575  {
1576    return Fixnum.constants[((int)b) & 0xff];
1577  }
1578
1579  public static final LispCharacter checkCharacter(LispObject obj)
1580
1581  {
1582          if (obj instanceof LispCharacter) 
1583                  return (LispCharacter) obj;         
1584          return (LispCharacter) // Not reached.       
1585        type_error(obj, Symbol.CHARACTER);
1586  }
1587
1588  public static final Package checkPackage(LispObject obj)
1589
1590  {
1591          if (obj instanceof Package)     
1592                  return (Package) obj;         
1593          return (Package) // Not reached.       
1594        type_error(obj, Symbol.PACKAGE);
1595  }
1596
1597  public static final Function checkFunction(LispObject obj)
1598
1599  {
1600          if (obj instanceof Function)   
1601                  return (Function) obj;         
1602          return (Function) // Not reached.       
1603        type_error(obj, Symbol.FUNCTION);
1604  }
1605
1606  public static final Stream checkStream(LispObject obj)
1607
1608  {
1609          if (obj instanceof Stream)     
1610                  return (Stream) obj;         
1611          return (Stream) // Not reached.       
1612        type_error(obj, Symbol.STREAM);
1613  }
1614
1615  public static final Stream checkCharacterInputStream(LispObject obj)
1616
1617  {
1618          final Stream stream = checkStream(obj);
1619          if (stream.isCharacterInputStream())     
1620                  return stream;                       
1621          return (Stream) // Not reached.                     
1622          error(new TypeError("The value " + obj.writeToString() +
1623                        " is not a character input stream."));
1624  }
1625
1626  public static final Stream checkCharacterOutputStream(LispObject obj)
1627
1628  {
1629          final Stream stream = checkStream(obj);
1630          if (stream.isCharacterOutputStream())     
1631                  return stream;                       
1632        return (Stream) // Not reached.
1633        error(new TypeError("The value " + obj.writeToString() +
1634                            " is not a character output stream."));
1635  }
1636
1637  public static final Stream checkBinaryInputStream(LispObject obj)
1638
1639  {
1640          final Stream stream = checkStream(obj);
1641          if (stream.isBinaryInputStream())     
1642                  return stream;                       
1643        return (Stream) // Not reached.
1644        error(new TypeError("The value " + obj.writeToString() +
1645                             " is not a binary input stream."));
1646  }
1647 
1648  public static final Stream outSynonymOf(LispObject obj)
1649
1650  {       
1651          if (obj instanceof Stream)
1652            return (Stream) obj;
1653          if (obj == T)
1654            return checkCharacterOutputStream(Symbol.TERMINAL_IO.symbolValue());
1655          if (obj == NIL)
1656            return checkCharacterOutputStream(Symbol.STANDARD_OUTPUT.symbolValue());
1657          return (Stream)         // Not reached.
1658          type_error(obj, Symbol.STREAM);
1659  }
1660
1661  public static final Stream inSynonymOf(LispObject obj)
1662
1663  {
1664    if (obj instanceof Stream)
1665      return (Stream) obj;
1666    if (obj == T)
1667      return checkCharacterInputStream(Symbol.TERMINAL_IO.symbolValue());
1668    if (obj == NIL)
1669      return checkCharacterInputStream(Symbol.STANDARD_INPUT.symbolValue());
1670          return (Stream)         // Not reached.
1671          type_error(obj, Symbol.STREAM);
1672  }
1673
1674  public static final void writeByte(int n, LispObject obj)
1675
1676  {
1677    if (n < 0 || n > 255)
1678      type_error(Fixnum.getInstance(n), UNSIGNED_BYTE_8);
1679    checkStream(obj)._writeByte(n);
1680  }
1681
1682  public static final Readtable checkReadtable(LispObject obj)
1683
1684  {
1685          if (obj instanceof Readtable)   
1686                  return (Readtable) obj;         
1687          return (Readtable)// Not reached.       
1688          type_error(obj, Symbol.READTABLE);
1689  }
1690 
1691  public final static AbstractString checkString(LispObject obj) 
1692
1693  {
1694          if (obj instanceof AbstractString)           
1695                  return (AbstractString) obj;                   
1696          return (AbstractString)// Not reached.               
1697              type_error(obj, Symbol.STRING);
1698  }
1699 
1700  public final static Layout checkLayout(LispObject obj) 
1701
1702  {
1703          if (obj instanceof Layout)           
1704                  return (Layout) obj;                   
1705          return (Layout)// Not reached.               
1706                type_error(obj, Symbol.LAYOUT);
1707  }
1708
1709  public static final Readtable designator_readtable(LispObject obj)
1710
1711  {
1712    if (obj == NIL)
1713      obj = STANDARD_READTABLE.symbolValue();
1714    if (obj == null)
1715        throw new NullPointerException();
1716    return checkReadtable(obj);
1717  }
1718
1719  public static final Environment checkEnvironment(LispObject obj)
1720
1721  {
1722          if (obj instanceof Environment)         
1723                  return (Environment) obj;         
1724          return (Environment)// Not reached.       
1725        type_error(obj, Symbol.ENVIRONMENT);
1726  }
1727
1728  public static final void checkBounds(int start, int end, int length)
1729
1730  {
1731    if (start < 0 || end < 0 || start > end || end > length)
1732      {
1733        StringBuilder sb = new StringBuilder("The bounding indices ");
1734        sb.append(start);
1735        sb.append(" and ");
1736        sb.append(end);
1737        sb.append(" are bad for a sequence of length ");
1738        sb.append(length);
1739        sb.append('.');
1740        error(new TypeError(sb.toString()));
1741      }
1742  }
1743
1744  public static final LispObject coerceToFunction(LispObject obj)
1745
1746  {
1747    if (obj instanceof Function)
1748      return obj;
1749    if (obj instanceof StandardGenericFunction)
1750      return obj;
1751    if (obj instanceof Symbol)
1752      {
1753        LispObject fun = obj.getSymbolFunction();
1754        if (fun instanceof Function)
1755          return (Function) fun;
1756      }
1757    else if (obj instanceof Cons && obj.car() == Symbol.LAMBDA)
1758      return new Closure(obj, new Environment());
1759    error(new UndefinedFunction(obj));
1760    // Not reached.
1761    return null;
1762  }
1763
1764  // Returns package or throws exception.
1765  public static final Package coerceToPackage(LispObject obj)
1766
1767  {
1768    if (obj instanceof Package)
1769      return (Package) obj;
1770    Package pkg = Packages.findPackage(javaString(obj));
1771    if (pkg != null)
1772      return pkg;
1773    error(new PackageError(obj.writeToString() + " is not the name of a package."));
1774    // Not reached.
1775    return null;
1776  }
1777
1778  public static Pathname coerceToPathname(LispObject arg)
1779
1780  {
1781    if (arg instanceof Pathname)
1782      return (Pathname) arg;
1783    if (arg instanceof AbstractString)
1784      return Pathname.parseNamestring((AbstractString)arg);
1785    if (arg instanceof FileStream)
1786      return ((FileStream)arg).getPathname();
1787    if (arg instanceof JarStream)
1788      return ((JarStream)arg).getPathname();
1789    if (arg instanceof URLStream)
1790      return ((URLStream)arg).getPathname();
1791    type_error(arg, list(Symbol.OR, Symbol.PATHNAME,
1792                         Symbol.STRING, Symbol.FILE_STREAM,
1793                         Symbol.JAR_STREAM, Symbol.URL_STREAM));
1794    // Not reached.
1795    return null;
1796  }
1797
1798  public static LispObject assq(LispObject item, LispObject alist)
1799
1800  {
1801    while (alist instanceof Cons)
1802      {
1803        LispObject entry = ((Cons)alist).car;
1804        if (entry instanceof Cons)
1805          {
1806            if (((Cons)entry).car == item)
1807              return entry;
1808          }
1809        else if (entry != NIL)
1810          return type_error(entry, Symbol.LIST);
1811        alist = ((Cons)alist).cdr;
1812      }
1813    if (alist != NIL)
1814      return type_error(alist, Symbol.LIST);
1815    return NIL;
1816  }
1817
1818  public static final boolean memq(LispObject item, LispObject list)
1819
1820  {
1821    while (list instanceof Cons)
1822      {
1823        if (item == ((Cons)list).car)
1824          return true;
1825        list = ((Cons)list).cdr;
1826      }
1827    if (list != NIL)
1828      type_error(list, Symbol.LIST);
1829    return false;
1830  }
1831
1832  public static final boolean memql(LispObject item, LispObject list)
1833
1834  {
1835    while (list instanceof Cons)
1836      {
1837        if (item.eql(((Cons)list).car))
1838          return true;
1839        list = ((Cons)list).cdr;
1840      }
1841    if (list != NIL)
1842      type_error(list, Symbol.LIST);
1843    return false;
1844  }
1845
1846  // Property lists.
1847  public static final LispObject getf(LispObject plist, LispObject indicator,
1848                                      LispObject defaultValue)
1849
1850  {
1851    LispObject list = plist;
1852    while (list != NIL)
1853      {
1854        if (list.car() == indicator)
1855          return list.cadr();
1856        if (list.cdr() instanceof Cons)
1857          list = list.cddr();
1858        else
1859          return error(new TypeError("Malformed property list: " +
1860                                      plist.writeToString()));
1861      }
1862    return defaultValue;
1863  }
1864
1865  public static final LispObject get(LispObject symbol, LispObject indicator)
1866
1867  {
1868    LispObject list = checkSymbol(symbol).getPropertyList();
1869    while (list != NIL)
1870      {
1871        if (list.car() == indicator)
1872          return list.cadr();
1873        list = list.cddr();
1874      }
1875    return NIL;
1876  }
1877
1878  public static final LispObject get(LispObject symbol, LispObject indicator,
1879                                     LispObject defaultValue)
1880
1881  {
1882    LispObject list = checkSymbol(symbol).getPropertyList();
1883    while (list != NIL)
1884      {
1885        if (list.car() == indicator)
1886          return list.cadr();
1887        list = list.cddr();
1888      }
1889    return defaultValue;
1890  }
1891
1892  public static final LispObject put(Symbol symbol, LispObject indicator,
1893                                     LispObject value)
1894
1895  {
1896    LispObject list = symbol.getPropertyList();
1897    while (list != NIL)
1898      {
1899        if (list.car() == indicator)
1900          {
1901            // Found it!
1902            LispObject rest = list.cdr();
1903            rest.setCar(value);
1904            return value;
1905          }
1906        list = list.cddr();
1907      }
1908    // Not found.
1909    symbol.setPropertyList(new Cons(indicator,
1910                                    new Cons(value,
1911                                             symbol.getPropertyList())));
1912    return value;
1913  }
1914
1915  public static final LispObject putf(LispObject plist, LispObject indicator,
1916                                      LispObject value)
1917
1918  {
1919    LispObject list = plist;
1920    while (list != NIL)
1921      {
1922        if (list.car() == indicator)
1923          {
1924            // Found it!
1925            LispObject rest = list.cdr();
1926            rest.setCar(value);
1927            return plist;
1928          }
1929        list = list.cddr();
1930      }
1931    // Not found.
1932    return new Cons(indicator, new Cons(value, plist));
1933  }
1934
1935  public static final LispObject remprop(Symbol symbol, LispObject indicator)
1936
1937  {
1938    LispObject list = checkList(symbol.getPropertyList());
1939    LispObject prev = null;
1940    while (list != NIL)
1941      {
1942        if (!(list.cdr() instanceof Cons))
1943          error(new ProgramError("The symbol " + symbol.writeToString() +
1944                                  " has an odd number of items in its property list."));
1945        if (list.car() == indicator)
1946          {
1947            // Found it!
1948            if (prev != null)
1949              prev.setCdr(list.cddr());
1950            else
1951              symbol.setPropertyList(list.cddr());
1952            return T;
1953          }
1954        prev = list.cdr();
1955        list = list.cddr();
1956      }
1957    // Not found.
1958    return NIL;
1959  }
1960
1961  public static final String format(LispObject formatControl,
1962                                    LispObject formatArguments)
1963
1964  {
1965    final LispThread thread = LispThread.currentThread();
1966    String control = formatControl.getStringValue();
1967    LispObject[] args = formatArguments.copyToArray();
1968    StringBuffer sb = new StringBuffer();
1969    if (control != null)
1970      {
1971        final int limit = control.length();
1972        int j = 0;
1973        final int NEUTRAL = 0;
1974        final int TILDE = 1;
1975        int state = NEUTRAL;
1976        for (int i = 0; i < limit; i++)
1977          {
1978            char c = control.charAt(i);
1979            if (state == NEUTRAL)
1980              {
1981                if (c == '~')
1982                  state = TILDE;
1983                else
1984                  sb.append(c);
1985              }
1986            else if (state == TILDE)
1987              {
1988                if (c == 'A' || c == 'a')
1989                  {
1990                    if (j < args.length)
1991                      {
1992                        LispObject obj = args[j++];
1993                        final SpecialBindingsMark mark = thread.markSpecialBindings();
1994                        thread.bindSpecial(Symbol.PRINT_ESCAPE, NIL);
1995                        thread.bindSpecial(Symbol.PRINT_READABLY, NIL);
1996                        try {
1997                            sb.append(obj.writeToString());
1998                        }
1999                        finally {
2000                            thread.resetSpecialBindings(mark);
2001                        }
2002                      }
2003                  }
2004                else if (c == 'S' || c == 's')
2005                  {
2006                    if (j < args.length)
2007                      {
2008                        LispObject obj = args[j++];
2009                        final SpecialBindingsMark mark = thread.markSpecialBindings();
2010                        thread.bindSpecial(Symbol.PRINT_ESCAPE, T);
2011                        try {
2012                            sb.append(obj.writeToString());
2013                        }
2014                        finally {
2015                            thread.resetSpecialBindings(mark);
2016                        }
2017                      }
2018                  }
2019                else if (c == 'D' || c == 'd')
2020                  {
2021                    if (j < args.length)
2022                      {
2023                        LispObject obj = args[j++];
2024                        final SpecialBindingsMark mark = thread.markSpecialBindings();
2025                        thread.bindSpecial(Symbol.PRINT_ESCAPE, NIL);
2026                        thread.bindSpecial(Symbol.PRINT_RADIX, NIL);
2027                        thread.bindSpecial(Symbol.PRINT_BASE, Fixnum.constants[10]);
2028                        try {
2029                            sb.append(obj.writeToString());
2030                        }
2031                        finally {
2032                            thread.resetSpecialBindings(mark);
2033                        }
2034                      }
2035                  }
2036                else if (c == 'X' || c == 'x')
2037                  {
2038                    if (j < args.length)
2039                      {
2040                        LispObject obj = args[j++];
2041                        final SpecialBindingsMark mark = thread.markSpecialBindings();
2042                        thread.bindSpecial(Symbol.PRINT_ESCAPE, NIL);
2043                        thread.bindSpecial(Symbol.PRINT_RADIX, NIL);
2044                        thread.bindSpecial(Symbol.PRINT_BASE, Fixnum.constants[16]);
2045                        try {
2046                            sb.append(obj.writeToString());
2047                        }
2048                        finally {
2049                            thread.resetSpecialBindings(mark);
2050                        }
2051                      }
2052                  }
2053                else if (c == '%')
2054                  {
2055                    sb.append('\n');
2056                  }
2057                state = NEUTRAL;
2058              }
2059            else
2060              {
2061                // There are no other valid states.
2062                Debug.assertTrue(false);
2063              }
2064          }
2065      }
2066    return sb.toString();
2067  }
2068
2069  public static final Symbol intern(String name, Package pkg)
2070  {
2071    return pkg.intern(name);
2072  }
2073
2074  // Used by the compiler.
2075  public static final Symbol internInPackage(String name, String packageName)
2076
2077  {
2078    Package pkg = Packages.findPackage(packageName);
2079    if (pkg == null)
2080      error(new LispError(packageName + " is not the name of a package."));
2081    return pkg.intern(name);
2082  }
2083
2084  public static final Symbol internKeyword(String s)
2085  {
2086    return PACKAGE_KEYWORD.intern(s);
2087  }
2088
2089  // The compiler's object table.
2090  static final Hashtable<String,LispObject> objectTable =
2091          new Hashtable<String,LispObject>();
2092
2093  public static final LispObject recall(String key)
2094  {
2095    return objectTable.remove(key);
2096  }
2097
2098  public static final LispObject recall(SimpleString key)
2099  {
2100    return objectTable.remove(key.getStringValue());
2101  }
2102
2103  // ### remember
2104  public static final Primitive REMEMBER =
2105    new Primitive("remember", PACKAGE_SYS, true)
2106    {
2107      @Override
2108      public LispObject execute(LispObject key, LispObject value)
2109
2110      {
2111        objectTable.put(key.getStringValue(), value);
2112        return NIL;
2113      }
2114    };
2115
2116  public static final Symbol internSpecial(String name, Package pkg,
2117                                           LispObject value)
2118  {
2119    Symbol symbol = pkg.intern(name);
2120    symbol.setSpecial(true);
2121    symbol.setSymbolValue(value);
2122    return symbol;
2123  }
2124
2125  public static final Symbol internConstant(String name, Package pkg,
2126                                            LispObject value)
2127  {
2128    Symbol symbol = pkg.intern(name);
2129    symbol.initializeConstant(value);
2130    return symbol;
2131  }
2132
2133  public static final Symbol exportSpecial(String name, Package pkg,
2134                                           LispObject value)
2135  {
2136    Symbol symbol = pkg.intern(name);
2137    pkg.export(symbol); // FIXME Inefficient!
2138    symbol.setSpecial(true);
2139    symbol.setSymbolValue(value);
2140    return symbol;
2141  }
2142
2143  public static final Symbol exportConstant(String name, Package pkg,
2144                                            LispObject value)
2145  {
2146    Symbol symbol = pkg.intern(name);
2147    pkg.export(symbol); // FIXME Inefficient!
2148    symbol.initializeConstant(value);
2149    return symbol;
2150  }
2151
2152  static
2153  {
2154    String userDir = System.getProperty("user.dir");
2155    if (userDir != null && userDir.length() > 0)
2156      {
2157        if (userDir.charAt(userDir.length() - 1) != File.separatorChar)
2158          userDir = userDir.concat(File.separator);
2159      }
2160    // This string will be converted to a pathname when Pathname.java is loaded.
2161    Symbol.DEFAULT_PATHNAME_DEFAULTS.initializeSpecial(new SimpleString(userDir));
2162  }
2163
2164  static
2165  {
2166    Symbol._PACKAGE_.initializeSpecial(PACKAGE_CL_USER);
2167  }
2168
2169  public static final Package getCurrentPackage()
2170  {
2171    return (Package) Symbol._PACKAGE_.symbolValueNoThrow();
2172  }
2173
2174
2175
2176  public static final void resetIO(Stream in, Stream out)
2177  {
2178    stdin = in;
2179    stdout = out;
2180    Symbol.STANDARD_INPUT.setSymbolValue(stdin);
2181    Symbol.STANDARD_OUTPUT.setSymbolValue(stdout);
2182    Symbol.ERROR_OUTPUT.setSymbolValue(stdout);
2183    Symbol.TRACE_OUTPUT.setSymbolValue(stdout);
2184    Symbol.TERMINAL_IO.setSymbolValue(new TwoWayStream(stdin, stdout, true));
2185    Symbol.QUERY_IO.setSymbolValue(new TwoWayStream(stdin, stdout, true));
2186    Symbol.DEBUG_IO.setSymbolValue(new TwoWayStream(stdin, stdout, true));
2187  }
2188
2189  // Used in org/armedbear/j/JLisp.java.
2190  public static final void resetIO()
2191  {
2192    resetIO(new Stream(Symbol.SYSTEM_STREAM, System.in, Symbol.CHARACTER, true),
2193            new Stream(Symbol.SYSTEM_STREAM, System.out, Symbol.CHARACTER, true));
2194  }
2195
2196  public static final TwoWayStream getTerminalIO()
2197  {
2198    return (TwoWayStream) Symbol.TERMINAL_IO.symbolValueNoThrow();
2199  }
2200
2201  public static final Stream getStandardInput()
2202  {
2203    return (Stream) Symbol.STANDARD_INPUT.symbolValueNoThrow();
2204  }
2205
2206  public static final Stream getStandardOutput()
2207  {
2208    return checkCharacterOutputStream(Symbol.STANDARD_OUTPUT.symbolValue());
2209  }
2210
2211  static
2212  {
2213    Symbol.CURRENT_READTABLE.initializeSpecial(new Readtable());
2214  }
2215
2216  // ### +standard-readtable+
2217  // internal symbol
2218  public static final Symbol STANDARD_READTABLE =
2219    internConstant("+STANDARD-READTABLE+", PACKAGE_SYS, new Readtable());
2220
2221  public static final Readtable currentReadtable()
2222  {
2223    return (Readtable) Symbol.CURRENT_READTABLE.symbolValue();
2224  }
2225
2226  static
2227  {
2228    Symbol.READ_SUPPRESS.initializeSpecial(NIL);
2229    Symbol.DEBUGGER_HOOK.initializeSpecial(NIL);
2230  }
2231
2232  static
2233  {
2234    Symbol.MOST_POSITIVE_FIXNUM.initializeConstant(Fixnum.getInstance(Integer.MAX_VALUE));
2235    Symbol.MOST_NEGATIVE_FIXNUM.initializeConstant(Fixnum.getInstance(Integer.MIN_VALUE));
2236    Symbol.MOST_POSITIVE_JAVA_LONG.initializeConstant(Bignum.getInstance(Long.MAX_VALUE));
2237    Symbol.MOST_NEGATIVE_JAVA_LONG.initializeConstant(Bignum.getInstance(Long.MIN_VALUE));
2238  }
2239
2240  public static void exit(int status)
2241  {
2242    Interpreter interpreter = Interpreter.getInstance();
2243    if (interpreter != null)
2244      interpreter.kill(status);
2245  }
2246
2247  // ### t
2248  public static final Symbol T = Symbol.T;
2249  static
2250  {
2251    T.initializeConstant(T);
2252  }
2253
2254  static
2255  {
2256    Symbol.READ_EVAL.initializeSpecial(T);
2257  }
2258
2259  // ### *features*
2260  static
2261  {
2262    Symbol.FEATURES.initializeSpecial(NIL);
2263    String osName = System.getProperty("os.name");
2264    if (osName.startsWith("Linux"))
2265      {
2266        Symbol.FEATURES.setSymbolValue(list(Keyword.ARMEDBEAR,
2267                                             Keyword.ABCL,
2268                                             Keyword.COMMON_LISP,
2269                                             Keyword.ANSI_CL,
2270                                             Keyword.UNIX,
2271                                             Keyword.LINUX,
2272                                             Keyword.CDR6));
2273      }
2274    else if (osName.startsWith("SunOS"))
2275      {
2276        Symbol.FEATURES.setSymbolValue(list(Keyword.ARMEDBEAR,
2277                                             Keyword.ABCL,
2278                                             Keyword.COMMON_LISP,
2279                                             Keyword.ANSI_CL,
2280                                             Keyword.UNIX,
2281                                             Keyword.SUNOS,
2282                                             Keyword.SOLARIS,
2283                                             Keyword.CDR6));
2284      }
2285    else if (osName.startsWith("Mac OS X") ||
2286             osName.startsWith("Darwin"))
2287      {
2288        Symbol.FEATURES.setSymbolValue(list(Keyword.ARMEDBEAR,
2289                                             Keyword.ABCL,
2290                                             Keyword.COMMON_LISP,
2291                                             Keyword.ANSI_CL,
2292                                             Keyword.UNIX,
2293                                             Keyword.DARWIN,
2294                                             Keyword.CDR6));
2295      }
2296    else if (osName.startsWith("FreeBSD"))
2297      {
2298        Symbol.FEATURES.setSymbolValue(list(Keyword.ARMEDBEAR,
2299                                             Keyword.ABCL,
2300                                             Keyword.COMMON_LISP,
2301                                             Keyword.ANSI_CL,
2302                                             Keyword.UNIX,
2303                                             Keyword.FREEBSD,
2304                                             Keyword.CDR6));
2305      }
2306    else if (osName.startsWith("OpenBSD"))
2307      {
2308        Symbol.FEATURES.setSymbolValue(list(Keyword.ARMEDBEAR,
2309                                             Keyword.ABCL,
2310                                             Keyword.COMMON_LISP,
2311                                             Keyword.ANSI_CL,
2312                                             Keyword.UNIX,
2313                                             Keyword.OPENBSD,
2314                                             Keyword.CDR6));
2315      }
2316    else if (osName.startsWith("NetBSD"))
2317      {
2318        Symbol.FEATURES.setSymbolValue(list(Keyword.ARMEDBEAR,
2319                                             Keyword.ABCL,
2320                                             Keyword.COMMON_LISP,
2321                                             Keyword.ANSI_CL,
2322                                             Keyword.UNIX,
2323                                             Keyword.NETBSD,
2324                                             Keyword.CDR6));
2325      }
2326    else if (osName.startsWith("Windows"))
2327      {
2328        Symbol.FEATURES.setSymbolValue(list(Keyword.ARMEDBEAR,
2329                                             Keyword.ABCL,
2330                                             Keyword.COMMON_LISP,
2331                                             Keyword.ANSI_CL,
2332                                             Keyword.WINDOWS,
2333                                             Keyword.CDR6));
2334      }
2335    else
2336      {
2337        Symbol.FEATURES.setSymbolValue(list(Keyword.ARMEDBEAR,
2338                                             Keyword.ABCL,
2339                                             Keyword.COMMON_LISP,
2340                                             Keyword.ANSI_CL,
2341                                             Keyword.CDR6));
2342      }
2343  }
2344  static
2345  {
2346    final String version = System.getProperty("java.version");
2347    if (version.startsWith("1.5"))
2348      {
2349        Symbol.FEATURES.setSymbolValue(new Cons(Keyword.JAVA_1_5,
2350                                                Symbol.FEATURES.getSymbolValue()));
2351      }
2352    else if (version.startsWith("1.6"))
2353      {
2354        Symbol.FEATURES.setSymbolValue(new Cons(Keyword.JAVA_1_6,
2355                                                Symbol.FEATURES.getSymbolValue()));
2356      }
2357    else if (version.startsWith("1.7"))
2358      {
2359        Symbol.FEATURES.setSymbolValue(new Cons(Keyword.JAVA_1_7,
2360                                                Symbol.FEATURES.getSymbolValue()));
2361      }
2362  }
2363  static
2364  {
2365    String os_arch = System.getProperty("os.arch");
2366    if(os_arch != null) {
2367      if (os_arch.equals("amd64"))
2368        Symbol.FEATURES.setSymbolValue(new Cons(Keyword.X86_64,
2369                                                Symbol.FEATURES.getSymbolValue()));
2370      else if (os_arch.equals("x86"))
2371        Symbol.FEATURES.setSymbolValue(new Cons(Keyword.X86,
2372                                                Symbol.FEATURES.getSymbolValue()));
2373    }
2374  }
2375
2376  static
2377  {
2378    Symbol.MODULES.initializeSpecial(NIL);
2379  }
2380
2381  static
2382  {
2383    Symbol.LOAD_VERBOSE.initializeSpecial(NIL);
2384    Symbol.LOAD_PRINT.initializeSpecial(NIL);
2385    Symbol.LOAD_PATHNAME.initializeSpecial(NIL);
2386    Symbol.LOAD_TRUENAME.initializeSpecial(NIL);
2387    Symbol.LOAD_TRUENAME_FASL.initializeSpecial(NIL);
2388    Symbol.COMPILE_VERBOSE.initializeSpecial(T);
2389    Symbol.COMPILE_PRINT.initializeSpecial(T);
2390    Symbol._COMPILE_FILE_PATHNAME_.initializeSpecial(NIL);
2391    Symbol.COMPILE_FILE_TRUENAME.initializeSpecial(NIL);
2392  }
2393
2394  // ### *double-colon-package-separators*
2395  // internal symbol
2396  public static final Symbol DOUBLE_COLON_PACKAGE_SEPARATORS =
2397    internSpecial("*DOUBLE-COLON-PACKAGE-SEPARATORS*", PACKAGE_SYS, NIL);
2398
2399  // ### *load-depth*
2400  // internal symbol
2401  public static final Symbol _LOAD_DEPTH_ =
2402    internSpecial("*LOAD-DEPTH*", PACKAGE_SYS, Fixnum.ZERO);
2403
2404  // ### *load-stream*
2405  // internal symbol
2406  public static final Symbol _LOAD_STREAM_ =
2407    internSpecial("*LOAD-STREAM*", PACKAGE_SYS, NIL);
2408
2409    // ### *fasl-loader*
2410    public static final Symbol _FASL_LOADER_ =
2411  exportSpecial("*FASL-LOADER*", PACKAGE_SYS, NIL);
2412
2413  // ### *source*
2414  // internal symbol
2415  public static final Symbol _SOURCE_ =
2416    exportSpecial("*SOURCE*", PACKAGE_SYS, NIL);
2417
2418  // ### *source-position*
2419  // internal symbol
2420  public static final Symbol _SOURCE_POSITION_ =
2421    exportSpecial("*SOURCE-POSITION*", PACKAGE_SYS, NIL);
2422
2423  // ### *autoload-verbose*
2424  // internal symbol
2425  public static final Symbol _AUTOLOAD_VERBOSE_ =
2426    exportSpecial("*AUTOLOAD-VERBOSE*", PACKAGE_EXT, NIL);
2427
2428  // ### *preloading-cache*
2429 public static final Symbol AUTOLOADING_CACHE =
2430   internSpecial("*AUTOLOADING-CACHE*", PACKAGE_SYS, NIL);
2431
2432  // ### *compile-file-type*
2433  public static final String COMPILE_FILE_TYPE = "abcl";
2434  public static final Symbol _COMPILE_FILE_TYPE_ =
2435    internConstant("*COMPILE-FILE-TYPE*", PACKAGE_SYS,
2436                   new SimpleString(COMPILE_FILE_TYPE));
2437
2438  // ### *compile-file-zip*
2439  public static final Symbol _COMPILE_FILE_ZIP_ =
2440    exportSpecial("*COMPILE-FILE-ZIP*", PACKAGE_SYS, T);
2441
2442  static
2443  {
2444    Symbol.MACROEXPAND_HOOK.initializeSpecial(Symbol.FUNCALL);
2445  }
2446
2447  public static final int ARRAY_DIMENSION_MAX = Integer.MAX_VALUE;
2448  static
2449  {
2450    // ### array-dimension-limit
2451    Symbol.ARRAY_DIMENSION_LIMIT.initializeConstant(Fixnum.getInstance(ARRAY_DIMENSION_MAX));
2452  }
2453
2454  // ### char-code-limit
2455  // "The upper exclusive bound on the value returned by the function CHAR-CODE."
2456  public static final int CHAR_MAX = Character.MAX_VALUE;
2457  static
2458  {
2459    Symbol.CHAR_CODE_LIMIT.initializeConstant(Fixnum.getInstance(CHAR_MAX + 1));
2460  }
2461
2462  static
2463  {
2464    Symbol.READ_BASE.initializeSpecial(Fixnum.constants[10]);
2465  }
2466
2467  static
2468  {
2469    Symbol.READ_DEFAULT_FLOAT_FORMAT.initializeSpecial(Symbol.SINGLE_FLOAT);
2470  }
2471
2472  // Printer control variables.
2473  static
2474  {
2475    Symbol.PRINT_ARRAY.initializeSpecial(T);
2476    Symbol.PRINT_BASE.initializeSpecial(Fixnum.constants[10]);
2477    Symbol.PRINT_CASE.initializeSpecial(Keyword.UPCASE);
2478    Symbol.PRINT_CIRCLE.initializeSpecial(NIL);
2479    Symbol.PRINT_ESCAPE.initializeSpecial(T);
2480    Symbol.PRINT_GENSYM.initializeSpecial(T);
2481    Symbol.PRINT_LENGTH.initializeSpecial(NIL);
2482    Symbol.PRINT_LEVEL.initializeSpecial(NIL);
2483    Symbol.PRINT_LINES.initializeSpecial(NIL);
2484    Symbol.PRINT_MISER_WIDTH.initializeSpecial(NIL);
2485    Symbol.PRINT_PPRINT_DISPATCH.initializeSpecial(NIL);
2486    Symbol.PRINT_PRETTY.initializeSpecial(NIL);
2487    Symbol.PRINT_RADIX.initializeSpecial(NIL);
2488    Symbol.PRINT_READABLY.initializeSpecial(NIL);
2489    Symbol.PRINT_RIGHT_MARGIN.initializeSpecial(NIL);
2490  }
2491
2492  public static final Symbol _PRINT_STRUCTURE_ =
2493    exportSpecial("*PRINT-STRUCTURE*", PACKAGE_EXT, T);
2494
2495  // ### *current-print-length*
2496  public static final Symbol _CURRENT_PRINT_LENGTH_ =
2497    exportSpecial("*CURRENT-PRINT-LENGTH*", PACKAGE_SYS, Fixnum.ZERO);
2498
2499  // ### *current-print-level*
2500  public static final Symbol _CURRENT_PRINT_LEVEL_ =
2501    exportSpecial("*CURRENT-PRINT-LEVEL*", PACKAGE_SYS, Fixnum.ZERO);
2502
2503  public static final Symbol _PRINT_FASL_ =
2504    internSpecial("*PRINT-FASL*", PACKAGE_SYS, NIL);
2505
2506  static
2507  {
2508    Symbol._RANDOM_STATE_.initializeSpecial(new RandomState());
2509  }
2510
2511  static
2512  {
2513    Symbol.STAR.initializeSpecial(NIL);
2514    Symbol.STAR_STAR.initializeSpecial(NIL);
2515    Symbol.STAR_STAR_STAR.initializeSpecial(NIL);
2516    Symbol.MINUS.initializeSpecial(NIL);
2517    Symbol.PLUS.initializeSpecial(NIL);
2518    Symbol.PLUS_PLUS.initializeSpecial(NIL);
2519    Symbol.PLUS_PLUS_PLUS.initializeSpecial(NIL);
2520    Symbol.SLASH.initializeSpecial(NIL);
2521    Symbol.SLASH_SLASH.initializeSpecial(NIL);
2522    Symbol.SLASH_SLASH_SLASH.initializeSpecial(NIL);
2523  }
2524
2525  // Floating point constants.
2526  static
2527  {
2528    Symbol.PI.initializeConstant(new DoubleFloat(Math.PI));
2529    Symbol.SHORT_FLOAT_EPSILON.initializeConstant(new SingleFloat((float)5.960465E-8));
2530    Symbol.SINGLE_FLOAT_EPSILON.initializeConstant(new SingleFloat((float)5.960465E-8));
2531    Symbol.DOUBLE_FLOAT_EPSILON.initializeConstant(new DoubleFloat((double)1.1102230246251568E-16));
2532    Symbol.LONG_FLOAT_EPSILON.initializeConstant(new DoubleFloat((double)1.1102230246251568E-16));
2533    Symbol.SHORT_FLOAT_NEGATIVE_EPSILON.initializeConstant(new SingleFloat(2.9802326e-8f));
2534    Symbol.SINGLE_FLOAT_NEGATIVE_EPSILON.initializeConstant(new SingleFloat(2.9802326e-8f));
2535    Symbol.DOUBLE_FLOAT_NEGATIVE_EPSILON.initializeConstant(new DoubleFloat((double)5.551115123125784E-17));
2536    Symbol.LONG_FLOAT_NEGATIVE_EPSILON.initializeConstant(new DoubleFloat((double)5.551115123125784E-17));
2537    Symbol.MOST_POSITIVE_SHORT_FLOAT.initializeConstant(new SingleFloat(Float.MAX_VALUE));
2538    Symbol.MOST_POSITIVE_SINGLE_FLOAT.initializeConstant(new SingleFloat(Float.MAX_VALUE));
2539    Symbol.MOST_POSITIVE_DOUBLE_FLOAT.initializeConstant(new DoubleFloat(Double.MAX_VALUE));
2540    Symbol.MOST_POSITIVE_LONG_FLOAT.initializeConstant(new DoubleFloat(Double.MAX_VALUE));
2541    Symbol.LEAST_POSITIVE_SHORT_FLOAT.initializeConstant(new SingleFloat(Float.MIN_VALUE));
2542    Symbol.LEAST_POSITIVE_SINGLE_FLOAT.initializeConstant(new SingleFloat(Float.MIN_VALUE));
2543    Symbol.LEAST_POSITIVE_DOUBLE_FLOAT.initializeConstant(new DoubleFloat(Double.MIN_VALUE));
2544    Symbol.LEAST_POSITIVE_LONG_FLOAT.initializeConstant(new DoubleFloat(Double.MIN_VALUE));
2545    Symbol.LEAST_POSITIVE_NORMALIZED_SHORT_FLOAT.initializeConstant(new SingleFloat(1.17549435e-38f));
2546    Symbol.LEAST_POSITIVE_NORMALIZED_SINGLE_FLOAT.initializeConstant(new SingleFloat(1.17549435e-38f));
2547    Symbol.LEAST_POSITIVE_NORMALIZED_DOUBLE_FLOAT.initializeConstant(new DoubleFloat(2.2250738585072014e-308d));
2548    Symbol.LEAST_POSITIVE_NORMALIZED_LONG_FLOAT.initializeConstant(new DoubleFloat(2.2250738585072014e-308d));
2549    Symbol.MOST_NEGATIVE_SHORT_FLOAT.initializeConstant(new SingleFloat(- Float.MAX_VALUE));
2550    Symbol.MOST_NEGATIVE_SINGLE_FLOAT.initializeConstant(new SingleFloat(- Float.MAX_VALUE));
2551    Symbol.MOST_NEGATIVE_DOUBLE_FLOAT.initializeConstant(new DoubleFloat(- Double.MAX_VALUE));
2552    Symbol.MOST_NEGATIVE_LONG_FLOAT.initializeConstant(new DoubleFloat(- Double.MAX_VALUE));
2553    Symbol.LEAST_NEGATIVE_SHORT_FLOAT.initializeConstant(new SingleFloat(- Float.MIN_VALUE));
2554    Symbol.LEAST_NEGATIVE_SINGLE_FLOAT.initializeConstant(new SingleFloat(- Float.MIN_VALUE));
2555    Symbol.LEAST_NEGATIVE_DOUBLE_FLOAT.initializeConstant(new DoubleFloat(- Double.MIN_VALUE));
2556    Symbol.LEAST_NEGATIVE_LONG_FLOAT.initializeConstant(new DoubleFloat(- Double.MIN_VALUE));
2557    Symbol.LEAST_NEGATIVE_NORMALIZED_SHORT_FLOAT.initializeConstant(new SingleFloat(-1.17549435e-38f));
2558    Symbol.LEAST_NEGATIVE_NORMALIZED_SINGLE_FLOAT.initializeConstant(new SingleFloat(-1.17549435e-38f));
2559    Symbol.LEAST_NEGATIVE_NORMALIZED_DOUBLE_FLOAT.initializeConstant(new DoubleFloat(-2.2250738585072014e-308d));
2560    Symbol.LEAST_NEGATIVE_NORMALIZED_LONG_FLOAT.initializeConstant(new DoubleFloat(-2.2250738585072014e-308d));
2561  }
2562
2563  static
2564  {
2565    Symbol.BOOLE_CLR.initializeConstant(Fixnum.ZERO);
2566    Symbol.BOOLE_SET.initializeConstant(Fixnum.ONE);
2567    Symbol.BOOLE_1.initializeConstant(Fixnum.TWO);
2568    Symbol.BOOLE_2.initializeConstant(Fixnum.constants[3]);
2569    Symbol.BOOLE_C1.initializeConstant(Fixnum.constants[4]);
2570    Symbol.BOOLE_C2.initializeConstant(Fixnum.constants[5]);
2571    Symbol.BOOLE_AND.initializeConstant(Fixnum.constants[6]);
2572    Symbol.BOOLE_IOR.initializeConstant(Fixnum.constants[7]);
2573    Symbol.BOOLE_XOR.initializeConstant(Fixnum.constants[8]);
2574    Symbol.BOOLE_EQV.initializeConstant(Fixnum.constants[9]);
2575    Symbol.BOOLE_NAND.initializeConstant(Fixnum.constants[10]);
2576    Symbol.BOOLE_NOR.initializeConstant(Fixnum.constants[11]);
2577    Symbol.BOOLE_ANDC1.initializeConstant(Fixnum.constants[12]);
2578    Symbol.BOOLE_ANDC2.initializeConstant(Fixnum.constants[13]);
2579    Symbol.BOOLE_ORC1.initializeConstant(Fixnum.constants[14]);
2580    Symbol.BOOLE_ORC2.initializeConstant(Fixnum.constants[15]);
2581  }
2582
2583  static
2584  {
2585    // ### call-arguments-limit
2586    Symbol.CALL_ARGUMENTS_LIMIT.initializeConstant(Fixnum.constants[50]);
2587  }
2588
2589  static
2590  {
2591    // ### lambda-parameters-limit
2592    Symbol.LAMBDA_PARAMETERS_LIMIT.initializeConstant(Fixnum.constants[50]);
2593  }
2594
2595  static
2596  {
2597    // ### multiple-values-limit
2598    Symbol.MULTIPLE_VALUES_LIMIT.initializeConstant(Fixnum.constants[20]);
2599  }
2600
2601  static
2602  {
2603    // ### internal-time-units-per-second
2604    Symbol.INTERNAL_TIME_UNITS_PER_SECOND.initializeConstant(Fixnum.getInstance(1000));
2605  }
2606
2607  static
2608  {
2609    Symbol.LAMBDA_LIST_KEYWORDS
2610      .initializeConstant(list(Symbol.AND_OPTIONAL,
2611                               Symbol.AND_REST,
2612                               Symbol.AND_KEY,
2613                               Symbol.AND_AUX,
2614                               Symbol.AND_BODY,
2615                               Symbol.AND_WHOLE,
2616                               Symbol.AND_ALLOW_OTHER_KEYS,
2617                               Symbol.AND_ENVIRONMENT));
2618  }
2619
2620  // ### call-registers-limit
2621  public static final Symbol CALL_REGISTERS_LIMIT =
2622    exportConstant("CALL-REGISTERS-LIMIT", PACKAGE_SYS,
2623                   Fixnum.constants[CALL_REGISTERS_MAX]);
2624
2625  // ### *warn-on-redefinition*
2626  public static final Symbol _WARN_ON_REDEFINITION_ =
2627    exportSpecial("*WARN-ON-REDEFINITION*", PACKAGE_EXT, T);
2628
2629  // ### *saved-backtrace*
2630  public static final Symbol _SAVED_BACKTRACE_ =
2631    exportSpecial("*SAVED-BACKTRACE*", PACKAGE_EXT, NIL);
2632
2633  // ### *command-line-argument-list*
2634  public static final Symbol _COMMAND_LINE_ARGUMENT_LIST_ =
2635    exportSpecial("*COMMAND-LINE-ARGUMENT-LIST*", PACKAGE_EXT, NIL);
2636
2637  // ### *batch-mode*
2638  public static final Symbol _BATCH_MODE_ =
2639    exportSpecial("*BATCH-MODE*", PACKAGE_EXT, NIL);
2640
2641  // ### *noinform*
2642  public static final Symbol _NOINFORM_ =
2643    exportSpecial("*NOINFORM*", PACKAGE_SYS, NIL);
2644
2645  // ### *disassembler*
2646  public static final Symbol _DISASSEMBLER_ =
2647    exportSpecial("*DISASSEMBLER*", PACKAGE_EXT,
2648                  new SimpleString("jad -a -p")); // or "jad -dis -p"
2649
2650  // ### *speed* compiler policy
2651  public static final Symbol _SPEED_ =
2652    exportSpecial("*SPEED*", PACKAGE_SYS, Fixnum.ONE);
2653
2654  // ### *space* compiler policy
2655  public static final Symbol _SPACE_ =
2656    exportSpecial("*SPACE*", PACKAGE_SYS, Fixnum.ONE);
2657
2658  // ### *safety* compiler policy
2659  public static final Symbol _SAFETY_ =
2660    exportSpecial("*SAFETY*", PACKAGE_SYS, Fixnum.ONE);
2661
2662  // ### *debug* compiler policy
2663  public static final Symbol _DEBUG_ =
2664    exportSpecial("*DEBUG*", PACKAGE_SYS, Fixnum.ONE);
2665
2666  // ### *explain* compiler policy
2667  public static final Symbol _EXPLAIN_ =
2668    exportSpecial("*EXPLAIN*", PACKAGE_SYS, NIL);
2669
2670  // ### *enable-inline-expansion*
2671  public static final Symbol _ENABLE_INLINE_EXPANSION_ =
2672    exportSpecial("*ENABLE-INLINE-EXPANSION*", PACKAGE_EXT, T);
2673
2674  // ### *require-stack-frame*
2675  public static final Symbol _REQUIRE_STACK_FRAME_ =
2676    exportSpecial("*REQUIRE-STACK-FRAME*", PACKAGE_EXT, NIL);
2677
2678  static
2679  {
2680    Symbol.SUPPRESS_COMPILER_WARNINGS.initializeSpecial(NIL);
2681  }
2682
2683  public static final Symbol _COMPILE_FILE_ENVIRONMENT_ =
2684    exportSpecial("*COMPILE-FILE-ENVIRONMENT*", PACKAGE_SYS, NIL);
2685
2686  public static final LispObject UNBOUND_VALUE = new unboundValue();
2687  static class unboundValue extends LispObject
2688  {
2689    @Override
2690    public String writeToString()
2691    {
2692      return "#<UNBOUND>";
2693    }
2694  }
2695
2696  public static final LispObject NULL_VALUE = new nullValue();
2697  static class nullValue extends LispObject
2698  {
2699    @Override
2700    public String writeToString()
2701    {
2702      return "null";
2703    }
2704  }
2705
2706  public static final Symbol _SLOT_UNBOUND_ =
2707    exportConstant("+SLOT-UNBOUND+", PACKAGE_SYS, UNBOUND_VALUE);
2708
2709  public static final Symbol _CL_PACKAGE_ =
2710    exportConstant("+CL-PACKAGE+", PACKAGE_SYS, PACKAGE_CL);
2711
2712  public static final Symbol _KEYWORD_PACKAGE_ =
2713    exportConstant("+KEYWORD-PACKAGE+", PACKAGE_SYS, PACKAGE_KEYWORD);
2714
2715  // ### *backquote-count*
2716  public static final Symbol _BACKQUOTE_COUNT_ =
2717    internSpecial("*BACKQUOTE-COUNT*", PACKAGE_SYS, Fixnum.ZERO);
2718
2719  // ### *bq-vector-flag*
2720  public static final Symbol _BQ_VECTOR_FLAG_ =
2721    internSpecial("*BQ-VECTOR-FLAG*", PACKAGE_SYS, list(new Symbol("bqv")));
2722
2723  // ### *traced-names*
2724  public static final Symbol _TRACED_NAMES_ =
2725    exportSpecial("*TRACED-NAMES*", PACKAGE_SYS, NIL);
2726
2727  // Floating point traps.
2728  protected static boolean TRAP_OVERFLOW  = true;
2729  protected static boolean TRAP_UNDERFLOW = true;
2730
2731
2732  // Extentions
2733  static {
2734    Symbol._INSPECTOR_HOOK_.initializeSpecial(NIL);
2735  }
2736
2737  private static final void loadClass(String className)
2738  {
2739    try
2740      {
2741        Class.forName(className);
2742      }
2743    catch (ClassNotFoundException e)
2744      {
2745        Debug.trace(e);
2746      }
2747  }
2748
2749  static
2750  {
2751    loadClass("org.armedbear.lisp.Primitives");
2752    loadClass("org.armedbear.lisp.SpecialOperators");
2753    loadClass("org.armedbear.lisp.Extensions");
2754    loadClass("org.armedbear.lisp.CompiledClosure");
2755    loadClass("org.armedbear.lisp.Autoload");
2756    loadClass("org.armedbear.lisp.AutoloadMacro");
2757    loadClass("org.armedbear.lisp.cxr");
2758    loadClass("org.armedbear.lisp.Do");
2759    loadClass("org.armedbear.lisp.dolist");
2760    loadClass("org.armedbear.lisp.dotimes");
2761    loadClass("org.armedbear.lisp.Pathname");
2762    loadClass("org.armedbear.lisp.LispClass");
2763    loadClass("org.armedbear.lisp.BuiltInClass");
2764    loadClass("org.armedbear.lisp.StructureObject");
2765    loadClass("org.armedbear.lisp.ash");
2766    loadClass("org.armedbear.lisp.Java");
2767    loadClass("org.armedbear.lisp.PackageFunctions");
2768    cold = false;
2769  }
2770
2771    private static Stream stdin = new Stream(Symbol.SYSTEM_STREAM, System.in, Symbol.CHARACTER, true);
2772
2773    private static Stream stdout = new Stream(Symbol.SYSTEM_STREAM,System.out, Symbol.CHARACTER, true);
2774
2775  static
2776  {
2777    Symbol.STANDARD_INPUT.initializeSpecial(stdin);
2778    Symbol.STANDARD_OUTPUT.initializeSpecial(stdout);
2779    Symbol.ERROR_OUTPUT.initializeSpecial(stdout);
2780    Symbol.TRACE_OUTPUT.initializeSpecial(stdout);
2781    Symbol.TERMINAL_IO.initializeSpecial(new TwoWayStream(stdin, stdout, true));
2782    Symbol.QUERY_IO.initializeSpecial(new TwoWayStream(stdin, stdout, true));
2783    Symbol.DEBUG_IO.initializeSpecial(new TwoWayStream(stdin, stdout, true));
2784  }
2785
2786  private static final SpecialOperator WITH_INLINE_CODE = new with_inline_code();
2787  private static class with_inline_code extends SpecialOperator {
2788    with_inline_code() {
2789      super("with-inline-code", PACKAGE_JVM, true, "(&optional target repr) &body body");
2790    }
2791    @Override
2792    public LispObject execute(LispObject args, Environment env)
2793    {
2794  return error(new SimpleError("This is a placeholder. It should only be called in compiled code, and tranformed by the compiler using special form handlers."));
2795    }
2796  }
2797
2798}
Note: See TracBrowser for help on using the repository browser.