0001: package kawa.standard;
0002:
0003: import kawa.lang.*;
0004: import gnu.bytecode.Type;
0005: import gnu.bytecode.ClassType;
0006: import gnu.bytecode.ArrayType;
0007: import gnu.mapping.*;
0008: import gnu.expr.*;
0009: import java.util.Hashtable;
0010: import gnu.text.SourceMessages;
0011: import gnu.kawa.lispexpr.*;
0012: import gnu.lists.AbstractFormat;
0013: import gnu.kawa.functions.ApplyToArgs;
0014: import gnu.kawa.functions.DisplayFormat;
0015: import gnu.kawa.functions.NumberCompare;
0016: import gnu.kawa.functions.GetNamedPart;
0017: import gnu.kawa.reflect.ClassMethods;
0018: import gnu.kawa.reflect.StaticFieldLocation;
0019: import gnu.math.Unit;
0020:
0021: public class Scheme extends LispLanguage {
0022: public static final Environment nullEnvironment;
0023: public static final Environment r4Environment;
0024: public static final Environment r5Environment;
0025: protected static final SimpleEnvironment kawaEnvironment;
0026:
0027: public static LangPrimType booleanType;
0028: public static final Scheme instance;
0029:
0030: public static final gnu.kawa.reflect.InstanceOf instanceOf;
0031: public static final not not;
0032: public static final kawa.standard.map map;
0033: public static final kawa.standard.map forEach;
0034: public static final gnu.kawa.functions.IsEq isEq;
0035: public static final gnu.kawa.functions.IsEqv isEqv;
0036: public static final gnu.kawa.functions.IsEqual isEqual;
0037: public static final kawa.repl repl;
0038:
0039: public static final NumberCompare numEqu;
0040: public static final NumberCompare numGrt;
0041: public static final NumberCompare numGEq;
0042: public static final NumberCompare numLss;
0043: public static final NumberCompare numLEq;
0044:
0045: public static final ApplyToArgs applyToArgs;
0046: static final Declaration applyFieldDecl;
0047: public static final Declaration getNamedPartDecl;
0048:
0049: static {
0050: // (null-environment)
0051: nullEnvironment = Environment.make("null-environment");
0052: r4Environment = Environment.make("r4rs-environment",
0053: nullEnvironment);
0054: r5Environment = Environment.make("r5rs-environment",
0055: r4Environment);
0056: kawaEnvironment = Environment.make("kawa-environment",
0057: r5Environment);
0058:
0059: instance = new Scheme(kawaEnvironment);
0060: instanceOf = new gnu.kawa.reflect.InstanceOf(instance,
0061: "instance?");
0062: not = new not(instance, "not");
0063: map = new map(true);
0064: forEach = new map(false);
0065: applyToArgs = new ApplyToArgs("apply-to-args", instance);
0066: applyFieldDecl = Declaration.getDeclarationFromStatic(
0067: "kawa.standard.Scheme", "applyToArgs");
0068: isEq = new gnu.kawa.functions.IsEq(instance, "eq?");
0069: isEqv = new gnu.kawa.functions.IsEqv(instance, "eqv?", isEq);
0070: isEqual = new gnu.kawa.functions.IsEqual(instance, "equal?");
0071: numEqu = NumberCompare.make(instance, "=",
0072: NumberCompare.TRUE_IF_EQU);
0073: numGrt = NumberCompare.make(instance, ">",
0074: NumberCompare.TRUE_IF_GRT);
0075: numGEq = NumberCompare.make(instance, ">=",
0076: NumberCompare.TRUE_IF_GRT | NumberCompare.TRUE_IF_EQU);
0077: numLss = NumberCompare.make(instance, "<",
0078: NumberCompare.TRUE_IF_LSS);
0079: numLEq = NumberCompare.make(instance, "<=",
0080: NumberCompare.TRUE_IF_LSS | NumberCompare.TRUE_IF_EQU);
0081:
0082: // Declare the special symbol $lookup$ (from the reader)
0083: // and bind it to getNamedPartDecl.
0084: String cname = "gnu.kawa.functions.GetNamedPart";
0085: String fname = "getNamedPart";
0086: getNamedPartDecl = Declaration.getDeclarationFromStatic(cname,
0087: fname);
0088: Symbol lookup_sym = instance.getSymbol("$lookup$");
0089: StaticFieldLocation loc = StaticFieldLocation.define(
0090: instance.environ, lookup_sym, null, cname, fname);
0091: loc.setProcedure();
0092: loc.setDeclaration(getNamedPartDecl);
0093:
0094: repl = new kawa.repl(instance);
0095: instance.initScheme();
0096: }
0097:
0098: public static Scheme getInstance() {
0099: return instance;
0100: }
0101:
0102: public static Environment builtin() {
0103: return kawaEnvironment;
0104: }
0105:
0106: public static final Lambda lambda = new kawa.lang.Lambda();
0107: static {
0108: lambda.setKeywords(Special.optional, Special.rest, Special.key);
0109: }
0110:
0111: private void initScheme() {
0112: environ = nullEnvironment;
0113:
0114: defSntxStFld("lambda", "kawa.standard.Scheme", "lambda");
0115:
0116: //-- Section 4.1 -- complete
0117: defSntxStFld(LispLanguage.quote_sym, "kawa.lang.Quote",
0118: "plainQuote");
0119: defSntxStFld("%define", "kawa.standard.define", "defineRaw");
0120: defSntxStFld("define", "kawa.lib.prim_syntax");
0121:
0122: defSntxStFld("if", "kawa.lib.prim_syntax");
0123: defSntxStFld("set!", "kawa.standard.set_b", "set");
0124:
0125: // Section 4.2 -- complete
0126: defSntxStFld("cond", "kawa.lib.std_syntax");
0127: defSntxStFld("case", "kawa.lib.std_syntax");
0128: defSntxStFld("and", "kawa.lib.std_syntax");
0129: defSntxStFld("or", "kawa.lib.std_syntax");
0130: defSntxStFld("%let", "kawa.standard.let", "let");
0131: defSntxStFld("let", "kawa.lib.std_syntax");
0132: defSntxStFld("let*", "kawa.lib.std_syntax");
0133: defSntxStFld("letrec", "kawa.lib.std_syntax");
0134:
0135: defSntxStFld("begin", "kawa.standard.begin", "begin");
0136: defSntxStFld("do", "kawa.lib.std_syntax");
0137: defSntxStFld("delay", "kawa.lib.std_syntax");
0138: defProcStFld("%make-promise", "kawa.lib.std_syntax");
0139: defSntxStFld("quasiquote", "kawa.lang.Quote", "quasiQuote");
0140:
0141: //-- Section 5 -- complete [except for internal definitions]
0142:
0143: // Appendix (and R5RS)
0144: defSntxStFld("define-syntax", "kawa.lib.prim_syntax");
0145: defSntxStFld("let-syntax", "kawa.standard.let_syntax",
0146: "let_syntax");
0147: defSntxStFld("letrec-syntax", "kawa.standard.let_syntax",
0148: "letrec_syntax");
0149: defSntxStFld("syntax-rules", "kawa.standard.syntax_rules",
0150: "syntax_rules");
0151:
0152: nullEnvironment.setLocked();
0153: environ = r4Environment;
0154:
0155: //-- Section 6.1 -- complete
0156: defProcStFld("not", "kawa.standard.Scheme");
0157: defProcStFld("boolean?", "kawa.lib.misc");
0158:
0159: //-- Section 6.2 -- complete
0160: defProcStFld("eq?", "kawa.standard.Scheme", "isEq");
0161: defProcStFld("eqv?", "kawa.standard.Scheme", "isEqv");
0162: defProcStFld("equal?", "kawa.standard.Scheme", "isEqual");
0163:
0164: //-- Section 6.3 -- complete
0165: defProcStFld("pair?", "kawa.lib.lists");
0166: defProcStFld("cons", "kawa.lib.lists");
0167: defProcStFld("car", "kawa.lib.lists");
0168: defProcStFld("cdr", "kawa.lib.lists");
0169: defProcStFld("set-car!", "kawa.lib.lists");
0170: defProcStFld("set-cdr!", "kawa.lib.lists");
0171:
0172: defProcStFld("caar", "kawa.lib.lists");
0173: defProcStFld("cadr", "kawa.lib.lists");
0174: defProcStFld("cdar", "kawa.lib.lists");
0175: defProcStFld("cddr", "kawa.lib.lists");
0176: defProcStFld("caaar", "kawa.lib.lists");
0177: defProcStFld("caadr", "kawa.lib.lists");
0178: defProcStFld("cadar", "kawa.lib.lists");
0179: defProcStFld("caddr", "kawa.lib.lists");
0180: defProcStFld("cdaar", "kawa.lib.lists");
0181: defProcStFld("cdadr", "kawa.lib.lists");
0182: defProcStFld("cddar", "kawa.lib.lists");
0183: defProcStFld("cdddr", "kawa.lib.lists");
0184: defProcStFld("caaaar", "kawa.lib.lists");
0185: defProcStFld("caaadr", "kawa.lib.lists");
0186: defProcStFld("caadar", "kawa.lib.lists");
0187: defProcStFld("caaddr", "kawa.lib.lists");
0188: defProcStFld("cadaar", "kawa.lib.lists");
0189: defProcStFld("cadadr", "kawa.lib.lists");
0190: defProcStFld("caddar", "kawa.lib.lists");
0191: defProcStFld("cadddr", "kawa.lib.lists");
0192: defProcStFld("cdaaar", "kawa.lib.lists");
0193: defProcStFld("cdaadr", "kawa.lib.lists");
0194: defProcStFld("cdadar", "kawa.lib.lists");
0195: defProcStFld("cdaddr", "kawa.lib.lists");
0196: defProcStFld("cddaar", "kawa.lib.lists");
0197: defProcStFld("cddadr", "kawa.lib.lists");
0198: defProcStFld("cdddar", "kawa.lib.lists");
0199: defProcStFld("cddddr", "kawa.lib.lists");
0200: defProcStFld("null?", "kawa.lib.lists");
0201: defProcStFld("list?", "kawa.lib.lists");
0202: defProcStFld("list", "gnu.kawa.functions.MakeList");
0203: defProcStFld("length", "kawa.lib.lists");
0204: defProcStFld("append", "kawa.standard.append", "append");
0205: defProcStFld("reverse", "kawa.lib.lists");
0206: defProcStFld("reverse!", "kawa.lib.lists"); // Not R5RS.
0207: defProcStFld("list-tail", "kawa.lib.lists");
0208: defProcStFld("list-ref", "kawa.lib.lists");
0209:
0210: defProcStFld("memq", "kawa.lib.lists");
0211: defProcStFld("memv", "kawa.lib.lists");
0212: defProcStFld("member", "kawa.lib.lists");
0213: defProcStFld("assq", "kawa.lib.lists");
0214: defProcStFld("assv", "kawa.lib.lists");
0215: defProcStFld("assoc", "kawa.lib.lists");
0216:
0217: //-- Section 6.4 -- complete, including slashified read/write
0218:
0219: defProcStFld("symbol?", "kawa.lib.misc");
0220: defProcStFld("symbol->string", "kawa.lib.misc");
0221: defProcStFld("string->symbol", "kawa.lib.misc");
0222:
0223: //-- Section 6.5
0224: defProcStFld("number?", "kawa.lib.numbers");
0225: defProcStFld("quantity?", "kawa.lib.numbers");
0226: defProcStFld("complex?", "kawa.lib.numbers");
0227: defProcStFld("real?", "kawa.lib.numbers");
0228: defProcStFld("rational?", "kawa.lib.numbers");
0229: defProcStFld("integer?", "kawa.lib.numbers");
0230: defProcStFld("exact?", "kawa.lib.numbers");
0231: defProcStFld("inexact?", "kawa.lib.numbers");
0232: defProcStFld("=", "kawa.standard.Scheme", "numEqu");
0233: defProcStFld("<", "kawa.standard.Scheme", "numLss");
0234: defProcStFld(">", "kawa.standard.Scheme", "numGrt");
0235: defProcStFld("<=", "kawa.standard.Scheme", "numLEq");
0236: defProcStFld(">=", "kawa.standard.Scheme", "numGEq");
0237: defProcStFld("zero?", "kawa.lib.numbers");
0238: defProcStFld("positive?", "kawa.lib.numbers");
0239: defProcStFld("negative?", "kawa.lib.numbers");
0240: defProcStFld("odd?", "kawa.lib.numbers");
0241: defProcStFld("even?", "kawa.lib.numbers");
0242: defProcStFld("max", "kawa.lib.numbers");
0243: defProcStFld("min", "kawa.lib.numbers");
0244: defProcStFld("+", "gnu.kawa.functions.AddOp", "$Pl");
0245: defProcStFld("-", "gnu.kawa.functions.AddOp", "$Mn");
0246: defProcStFld("*", "gnu.kawa.functions.MultiplyOp", "$St");
0247: defProcStFld("/", "gnu.kawa.functions.DivideOp", "$Sl");
0248: defProcStFld("abs", "kawa.lib.numbers");
0249: defProcStFld("quotient", "kawa.lib.numbers");
0250: defProcStFld("remainder", "kawa.lib.numbers");
0251: defProcStFld("modulo", "kawa.lib.numbers");
0252: defProcStFld("gcd", "kawa.lib.numbers");
0253: defProcStFld("lcm", "kawa.lib.numbers");
0254: defProcStFld("numerator", "kawa.lib.numbers");
0255: defProcStFld("denominator", "kawa.lib.numbers");
0256: defProcStFld("floor", "kawa.lib.numbers");
0257: defProcStFld("ceiling", "kawa.lib.numbers");
0258: defProcStFld("truncate", "kawa.lib.numbers");
0259: defProcStFld("round", "kawa.lib.numbers");
0260: defProcStFld("rationalize", "kawa.lib.numbers");
0261: defProcStFld("exp", "kawa.lib.numbers");
0262: defProcStFld("log", "kawa.lib.numbers");
0263: defProcStFld("sin", "kawa.lib.numbers");
0264: defProcStFld("cos", "kawa.lib.numbers");
0265: defProcStFld("tan", "kawa.lib.numbers");
0266: defProcStFld("asin", "kawa.lib.numbers");
0267: defProcStFld("acos", "kawa.lib.numbers");
0268: defProcStFld("atan", "kawa.lib.numbers");
0269: defProcStFld("sqrt", "kawa.lib.numbers");
0270: defProcStFld("expt", "kawa.standard.expt");
0271: defProcStFld("make-rectangular", "kawa.lib.numbers");
0272: defProcStFld("make-polar", "kawa.lib.numbers");
0273: defProcStFld("real-part", "kawa.lib.numbers");
0274: defProcStFld("imag-part", "kawa.lib.numbers");
0275: defProcStFld("magnitude", "kawa.lib.numbers");
0276: defProcStFld("angle", "kawa.lib.numbers");
0277: defProcStFld("exact->inexact", "kawa.lib.numbers");
0278: defProcStFld("inexact->exact", "kawa.lib.numbers");
0279: defProcStFld("number->string", "kawa.lib.numbers");
0280: defProcStFld("string->number", "kawa.lib.numbers");
0281:
0282: //-- Section 6.6 -- complete
0283: defProcStFld("char?", "kawa.lib.characters");
0284: defProcStFld("char=?", "kawa.lib.characters");
0285: defProcStFld("char<?", "kawa.lib.characters");
0286: defProcStFld("char>?", "kawa.lib.characters");
0287: defProcStFld("char<=?", "kawa.lib.characters");
0288: defProcStFld("char>=?", "kawa.lib.characters");
0289: defProcStFld("char-ci=?", "kawa.lib.characters");
0290: defProcStFld("char-ci<?", "kawa.lib.characters");
0291: defProcStFld("char-ci>?", "kawa.lib.characters");
0292: defProcStFld("char-ci<=?", "kawa.lib.characters");
0293: defProcStFld("char-ci>=?", "kawa.lib.characters");
0294: defProcStFld("char-alphabetic?", "kawa.lib.characters");
0295: defProcStFld("char-numeric?", "kawa.lib.characters");
0296: defProcStFld("char-whitespace?", "kawa.lib.characters");
0297: defProcStFld("char-upper-case?", "kawa.lib.characters");
0298: defProcStFld("char-lower-case?", "kawa.lib.characters");
0299: defProcStFld("char->integer", "kawa.lib.characters");
0300: defProcStFld("integer->char", "kawa.lib.characters");
0301: defProcStFld("char-upcase", "kawa.lib.characters");
0302: defProcStFld("char-downcase", "kawa.lib.characters");
0303:
0304: //-- Section 6.7 -- complete
0305: defProcStFld("string?", "kawa.lib.strings");
0306: defProcStFld("make-string", "kawa.lib.strings");
0307: defProcStFld("string", "kawa.lib.strings");
0308: defProcStFld("string-length", "kawa.lib.strings");
0309: defProcStFld("string-ref", "kawa.lib.strings");
0310: defProcStFld("string-set!", "kawa.lib.strings");
0311:
0312: defProcStFld("string=?", "kawa.lib.strings");
0313: defProcStFld("string-ci=?", "kawa.lib.strings");
0314: defProcStFld("string<?", "kawa.lib.strings");
0315: defProcStFld("string>?", "kawa.lib.strings");
0316: defProcStFld("string<=?", "kawa.lib.strings");
0317: defProcStFld("string>=?", "kawa.lib.strings");
0318:
0319: defProcStFld("string-ci<?", "kawa.lib.strings");
0320: defProcStFld("string-ci>?", "kawa.lib.strings");
0321: defProcStFld("string-ci<=?", "kawa.lib.strings");
0322: defProcStFld("string-ci>=?", "kawa.lib.strings");
0323:
0324: defProcStFld("substring", "kawa.lib.strings");
0325: defProcStFld("string-append", "kawa.lib.strings");
0326: defProcStFld("string-append/shared", "kawa.lib.strings");
0327: defProcStFld("string->list", "kawa.lib.strings");
0328: defProcStFld("list->string", "kawa.lib.strings");
0329: defProcStFld("string-copy", "kawa.lib.strings");
0330: defProcStFld("string-fill!", "kawa.lib.strings");
0331:
0332: //-- Section 6.8 -- complete
0333: defProcStFld("vector?", "kawa.lib.vectors");
0334: defProcStFld("make-vector", "kawa.lib.vectors");
0335: defProcStFld("vector", "kawa.lib.vectors");
0336: defProcStFld("vector-length", "kawa.lib.vectors");
0337: defProcStFld("vector-ref", "kawa.lib.vectors");
0338: defProcStFld("vector-set!", "kawa.lib.vectors");
0339: defProcStFld("list->vector", "kawa.lib.vectors");
0340: defProcStFld("vector->list", "kawa.lib.vectors");
0341: defProcStFld("vector-fill!", "kawa.lib.vectors");
0342: // Extension:
0343: defProcStFld("vector-append", "kawa.standard.vector_append",
0344: "vectorAppend");
0345: defProcStFld("values-append",
0346: "gnu.kawa.functions.AppendValues", "appendValues");
0347:
0348: //-- Section 6.9 -- complete [except restricted call/cc]
0349: defProcStFld("procedure?", "kawa.lib.misc");
0350: defProcStFld("apply", "gnu.kawa.functions.Apply", "apply");
0351: defProcStFld("map", "kawa.standard.Scheme", "map");
0352: defProcStFld("for-each", "kawa.standard.Scheme", "forEach");
0353: defProcStFld("call-with-current-continuation",
0354: "kawa.standard.callcc", "callcc");
0355: defProcStFld("call/cc", "kawa.standard.callcc", "callcc");
0356: defProcStFld("force", "kawa.lib.misc");
0357:
0358: //-- Section 6.10 -- complete
0359: defProcStFld("call-with-input-file", "kawa.lib.ports");
0360: defProcStFld("call-with-output-file", "kawa.lib.ports");
0361: defProcStFld("input-port?", "kawa.lib.ports");
0362: defProcStFld("output-port?", "kawa.lib.ports");
0363: defProcStFld("current-input-port", "kawa.lib.ports");
0364: defProcStFld("current-output-port", "kawa.lib.ports");
0365: defProcStFld("with-input-from-file", "kawa.lib.ports");
0366: defProcStFld("with-output-to-file", "kawa.lib.ports");
0367: defProcStFld("open-input-file", "kawa.lib.ports");
0368: defProcStFld("open-output-file", "kawa.lib.ports");
0369: defProcStFld("close-input-port", "kawa.lib.ports");
0370: defProcStFld("close-output-port", "kawa.lib.ports");
0371: defProcStFld("read", "kawa.lib.ports");
0372: defProcStFld("read-line", "kawa.lib.ports");
0373: defProcStFld("read-char", "kawa.standard.readchar", "readChar");
0374: defProcStFld("peek-char", "kawa.standard.readchar", "peekChar");
0375: defProcStFld("eof-object?", "kawa.lib.ports");
0376: defProcStFld("char-ready?", "kawa.lib.ports");
0377: defProcStFld("write", "kawa.lib.ports");
0378: defProcStFld("display", "kawa.lib.ports");
0379: defProcStFld("print-as-xml", "gnu.xquery.lang.XQuery",
0380: "writeFormat");
0381: defProcStFld("write-char", "kawa.lib.ports");
0382: defProcStFld("newline", "kawa.lib.ports");
0383: defProcStFld("load", "kawa.standard.load", "load");
0384: defProcStFld("load-relative", "kawa.standard.load",
0385: "loadRelative");
0386: defProcStFld("transcript-off", "kawa.lib.ports");
0387: defProcStFld("transcript-on", "kawa.lib.ports");
0388: defProcStFld("call-with-input-string", "kawa.lib.ports"); // Extension
0389: defProcStFld("open-input-string", "kawa.lib.ports"); // SRFI-6
0390: defProcStFld("open-output-string", "kawa.lib.ports"); // SRFI-6
0391: defProcStFld("get-output-string", "kawa.lib.ports"); // SRFI-6
0392: defProcStFld("call-with-output-string", "kawa.lib.ports"); // Extension
0393: defProcStFld("force-output", "kawa.lib.ports"); // Extension
0394:
0395: defProcStFld("port-line", "kawa.lib.ports");
0396: defProcStFld("set-port-line!", "kawa.lib.ports");
0397: defProcStFld("port-column", "kawa.lib.ports");
0398: defProcStFld("current-error-port", "kawa.lib.ports");
0399: defProcStFld("input-port-line-number", "kawa.lib.ports"); // Extension
0400: defProcStFld("set-input-port-line-number!", "kawa.lib.ports");
0401: defProcStFld("input-port-column-number", "kawa.lib.ports");
0402: defProcStFld("input-port-read-state", "kawa.lib.ports");
0403: defProcStFld("default-prompter", "kawa.lib.ports");
0404: defProcStFld("input-port-prompter", "kawa.lib.ports");
0405: defProcStFld("set-input-port-prompter!", "kawa.lib.ports");
0406: defProcStFld("base-uri", "kawa.lib.misc");
0407:
0408: defProcStFld("%syntax-error", "kawa.standard.syntax_error",
0409: "syntax_error");
0410: defProcStFld("syntax-error", "kawa.lib.prim_syntax");
0411:
0412: r4Environment.setLocked();
0413: environ = r5Environment;
0414:
0415: defProcStFld("values", "kawa.lib.misc");
0416: defProcStFld("call-with-values",
0417: "kawa.standard.call_with_values", "callWithValues");
0418: defSntxStFld("let-values", "kawa.lib.syntax");
0419: defSntxStFld("let*-values", "kawa.lib.syntax");
0420: defSntxStFld("case-lambda", "kawa.lib.syntax");
0421: defSntxStFld("receive", "kawa.lib.syntax");
0422: defProcStFld("eval", "kawa.lang.Eval");
0423: defProcStFld("repl", "kawa.standard.Scheme", "repl");
0424: defProcStFld("scheme-report-environment", "kawa.lib.misc");
0425: defProcStFld("null-environment", "kawa.lib.misc");
0426: defProcStFld("interaction-environment", "kawa.lib.misc");
0427: defProcStFld("dynamic-wind", "kawa.lib.misc");
0428:
0429: r5Environment.setLocked();
0430: environ = kawaEnvironment;
0431:
0432: defSntxStFld("define-private", "kawa.lib.prim_syntax");
0433: defSntxStFld("define-constant", "kawa.lib.prim_syntax");
0434:
0435: defSntxStFld("define-autoload",
0436: "kawa.standard.define_autoload", "define_autoload");
0437: defSntxStFld("define-autoloads-from-file",
0438: "kawa.standard.define_autoload",
0439: "define_autoloads_from_file");
0440:
0441: defProcStFld("exit", "kawa.lib.thread");
0442:
0443: defProcStFld("arithmetic-shift", "kawa.lib.numbers");
0444: defProcStFld("ash", "kawa.lib.numbers", "arithmetic$Mnshift");
0445: defProcStFld("logand", "kawa.lib.numbers");
0446: defProcStFld("logior", "kawa.lib.numbers");
0447: defProcStFld("logxor", "kawa.lib.numbers");
0448: defProcStFld("lognot", "kawa.lib.numbers");
0449: defProcStFld("logop", "kawa.lib.numbers");
0450: defProcStFld("logbit?", "kawa.lib.numbers");
0451: defProcStFld("logtest", "kawa.lib.numbers");
0452: defProcStFld("logcount", "kawa.lib.numbers");
0453: defProcStFld("bit-extract", "kawa.lib.numbers");
0454: defProcStFld("integer-length", "kawa.lib.numbers");
0455:
0456: // These are from SLIB.
0457: defProcStFld("string-upcase!", "kawa.lib.strings");
0458: defProcStFld("string-downcase!", "kawa.lib.strings");
0459: defProcStFld("string-capitalize!", "kawa.lib.strings");
0460: defProcStFld("string-upcase", "kawa.lib.strings");
0461: defProcStFld("string-downcase", "kawa.lib.strings");
0462: defProcStFld("string-capitalize", "kawa.lib.strings");
0463: defSntxStFld("primitive-virtual-method",
0464: "kawa.standard.prim_method", "virtual_method");
0465: defSntxStFld("primitive-static-method",
0466: "kawa.standard.prim_method", "static_method");
0467: defSntxStFld("primitive-interface-method",
0468: "kawa.standard.prim_method", "interface_method");
0469: defSntxStFld("primitive-constructor", "kawa.lib.reflection");
0470: defSntxStFld("primitive-op1", "kawa.standard.prim_method",
0471: "op1");
0472: defSntxStFld("primitive-get-field", "kawa.lib.reflection");
0473: defSntxStFld("primitive-set-field", "kawa.lib.reflection");
0474: defSntxStFld("primitive-get-static", "kawa.lib.reflection");
0475: defSntxStFld("primitive-set-static", "kawa.lib.reflection");
0476: defSntxStFld("primitive-array-new", "kawa.lib.reflection");
0477: defSntxStFld("primitive-array-get", "kawa.lib.reflection");
0478: defSntxStFld("primitive-array-set", "kawa.lib.reflection");
0479: defSntxStFld("primitive-array-length", "kawa.lib.reflection");
0480: defProcStFld("subtype?", "kawa.lib.reflection");
0481: defProcStFld("primitive-throw", "kawa.standard.prim_throw",
0482: "primitiveThrow");
0483: defSntxStFld("try-finally", "kawa.lib.syntax");
0484: defSntxStFld("try-catch", "kawa.lib.prim_syntax");
0485: defProcStFld("throw", "kawa.standard.throw_name", "throwName");
0486: defProcStFld("catch", "kawa.lib.syntax");
0487: defProcStFld("error", "kawa.lib.misc");
0488: defProcStFld("as", "gnu.kawa.functions.Convert", "as");
0489: defProcStFld("instance?", "kawa.standard.Scheme", "instanceOf");
0490: defSntxStFld("synchronized", "kawa.lib.syntax");
0491: defSntxStFld("object", "kawa.standard.object", "objectSyntax");
0492: defSntxStFld("define-class", "kawa.standard.define_class",
0493: "define_class");
0494: defSntxStFld("define-simple-class",
0495: "kawa.standard.define_class", "define_simple_class");
0496: defSntxStFld("this", "kawa.standard.thisRef", "thisSyntax");
0497: defProcStFld("make", "gnu.kawa.reflect.Invoke", "make");
0498: defProcStFld("slot-ref", "gnu.kawa.reflect.SlotGet", "slotRef");
0499: defProcStFld("slot-set!", "gnu.kawa.reflect.SlotSet",
0500: "set$Mnfield$Ex");
0501: defProcStFld("field", "gnu.kawa.reflect.SlotGet");
0502: defProcStFld("class-methods", "gnu.kawa.reflect.ClassMethods",
0503: "classMethods");
0504: defProcStFld("static-field", "gnu.kawa.reflect.SlotGet",
0505: "staticField");
0506: defProcStFld("invoke", "gnu.kawa.reflect.Invoke", "invoke");
0507:
0508: defProcStFld("invoke-static", "gnu.kawa.reflect.Invoke",
0509: "invokeStatic");
0510: defProcStFld("invoke-special", "gnu.kawa.reflect.Invoke",
0511: "invokeSpecial");
0512:
0513: defSntxStFld("define-macro", "kawa.lib.syntax");
0514: defSntxStFld("%define-macro", "kawa.standard.define_syntax",
0515: "define_macro");
0516: defSntxStFld("syntax-case", "kawa.standard.syntax_case",
0517: "syntax_case");
0518: defSntxStFld("%define-syntax", "kawa.standard.define_syntax",
0519: "define_syntax");
0520: defSntxStFld("syntax", "kawa.standard.syntax", "syntax");
0521: defSntxStFld("quasisyntax", "kawa.standard.syntax",
0522: "quasiSyntax");
0523: defProcStFld("syntax-object->datum", "kawa.lib.std_syntax");
0524: defProcStFld("datum->syntax-object", "kawa.lib.std_syntax");
0525: defProcStFld("syntax->expression", "kawa.lib.prim_syntax");
0526: defProcStFld("syntax-body->expression", "kawa.lib.prim_syntax");
0527: defProcStFld("generate-temporaries", "kawa.lib.std_syntax");
0528: defSntxStFld("with-syntax", "kawa.lib.std_syntax");
0529: defProcStFld("syntax-source", "kawa.lib.syntax");
0530: defProcStFld("syntax-line", "kawa.lib.syntax");
0531: defProcStFld("syntax-column", "kawa.lib.syntax");
0532: defSntxStFld("define-for-syntax", "kawa.lib.prim_syntax");
0533: defSntxStFld("include", "kawa.lib.files");
0534: defSntxStFld("include-relative", "kawa.lib.files");
0535:
0536: defProcStFld("file-exists?", "kawa.lib.files");
0537: defProcStFld("file-directory?", "kawa.lib.files");
0538: defProcStFld("file-readable?", "kawa.lib.files");
0539: defProcStFld("file-writable?", "kawa.lib.files");
0540: defProcStFld("delete-file", "kawa.lib.files");
0541: defProcStFld("system-tmpdir", "kawa.lib.files");
0542: defProcStFld("make-temporary-file", "kawa.lib.files");
0543: defProcStFld("rename-file", "kawa.lib.files");
0544: defProcStFld("copy-file", "kawa.lib.files");
0545: defProcStFld("create-directory", "kawa.lib.files");
0546: defProcStFld("->pathname", "kawa.lib.files");
0547: define("port-char-encoding", Boolean.TRUE);
0548: define("symbol-read-case", "P");
0549:
0550: defProcStFld("system", "kawa.lib.system");
0551: defProcStFld("make-process", "kawa.lib.system");
0552: defProcStFld("tokenize-string-to-string-array",
0553: "kawa.lib.system");
0554: defProcStFld("tokenize-string-using-shell", "kawa.lib.system");
0555: defProcStFld("command-parse", "kawa.lib.system");
0556:
0557: defProcStFld("record-accessor", "kawa.lib.reflection");
0558: defProcStFld("record-modifier", "kawa.lib.reflection");
0559: defProcStFld("record-predicate", "kawa.lib.reflection");
0560: defProcStFld("record-constructor", "kawa.lib.reflection");
0561: defProcStFld("make-record-type", "kawa.lib.reflection");
0562: defProcStFld("record-type-descriptor", "kawa.lib.reflection");
0563: defProcStFld("record-type-name", "kawa.lib.reflection");
0564: defProcStFld("record-type-field-names", "kawa.lib.reflection");
0565: defProcStFld("record?", "kawa.lib.reflection");
0566: defSntxStFld("define-record-type",
0567: "gnu.kawa.slib.DefineRecordType");
0568:
0569: defSntxStFld("when", "kawa.lib.syntax"); //-- (when cond exp ...)
0570: defSntxStFld("unless", "kawa.lib.syntax"); //-- (unless cond exp ...)
0571: defSntxStFld("fluid-let", "kawa.standard.fluid_let",
0572: "fluid_let");
0573: defSntxStFld("constant-fold", "kawa.standard.constant_fold",
0574: "constant_fold");
0575: defProcStFld("make-parameter", "kawa.lib.parameters");
0576: defSntxStFld("parameterize", "kawa.lib.parameters");
0577:
0578: defProcStFld("compile-file", "kawa.lib.system");
0579: defProcStFld("environment-bound?", "kawa.lib.misc");
0580: defProcStFld("scheme-implementation-version", "kawa.lib.misc");
0581: defProcStFld("scheme-window", "kawa.lib.windows");
0582: defSntxStFld("define-procedure", "kawa.lib.syntax");
0583: defProcStFld("add-procedure-properties", "kawa.lib.syntax");
0584: defProcStFld("make-procedure",
0585: "gnu.kawa.functions.MakeProcedure", "makeProcedure");
0586: defProcStFld("procedure-property", "kawa.lib.misc");
0587: defProcStFld("set-procedure-property!", "kawa.lib.misc");
0588: defSntxStFld("provide", "kawa.lib.misc");
0589: defSntxStFld("test-begin", "kawa.lib.misc");
0590: defProcStFld("namespace", "kawa.lib.misc");
0591:
0592: defProcStFld("quantity->number", "kawa.lib.numbers");
0593: defProcStFld("quantity->unit", "kawa.lib.numbers");
0594: defProcStFld("make-quantity", "kawa.lib.numbers");
0595: defSntxStFld("define-namespace",
0596: "gnu.kawa.lispexpr.DefineNamespace", "define_namespace");
0597: defSntxStFld("define-xml-namespace",
0598: "gnu.kawa.lispexpr.DefineNamespace",
0599: "define_xml_namespace");
0600: defSntxStFld("define-private-namespace",
0601: "gnu.kawa.lispexpr.DefineNamespace",
0602: "define_private_namespace");
0603: defSntxStFld("define-unit", "kawa.standard.define_unit",
0604: "define_unit");
0605: defSntxStFld("define-base-unit", "kawa.standard.define_unit",
0606: "define_base_unit");
0607: defProcStFld("duration", "kawa.lib.numbers");
0608:
0609: defProcStFld("gentemp", "kawa.lib.syntax");
0610: defSntxStFld("defmacro", "kawa.lib.syntax");
0611: defProcStFld("setter", "gnu.kawa.functions.Setter", "setter");
0612: defSntxStFld("resource-uri", "kawa.lib.files");
0613:
0614: defProcStFld("resolve-uri", "kawa.lib.files");
0615: defSntxStFld("module-uri", "kawa.lib.files");
0616:
0617: defSntxStFld("future", "kawa.lib.thread");
0618: defProcStFld("sleep", "kawa.lib.thread");
0619: defProcStFld("runnable", "kawa.lib.thread");
0620:
0621: defSntxStFld("trace", "kawa.lib.trace");
0622: defSntxStFld("untrace", "kawa.lib.trace");
0623:
0624: defProcStFld("format", "gnu.kawa.functions.Format");
0625: defProcStFld("parse-format", "gnu.kawa.functions.ParseFormat",
0626: "parseFormat");
0627:
0628: defProcStFld("make-element", "gnu.kawa.xml.MakeElement",
0629: "makeElement");
0630: defProcStFld("make-attribute", "gnu.kawa.xml.MakeAttribute",
0631: "makeAttribute");
0632: defProcStFld("map-values", "gnu.kawa.functions.ValuesMap",
0633: "valuesMap");
0634: defProcStFld("children", "gnu.kawa.xml.Children", "children");
0635: defProcStFld("attributes", "gnu.kawa.xml.Attributes");
0636: defProcStFld("unescaped-data",
0637: "gnu.kawa.xml.MakeUnescapedData", "unescapedData");
0638: defProcStFld("keyword?", "kawa.lib.keywords");
0639: defProcStFld("keyword->string", "kawa.lib.keywords");
0640: defProcStFld("string->keyword", "kawa.lib.keywords");
0641: defSntxStFld("location", "kawa.standard.location", "location");
0642: defSntxStFld("define-alias", "kawa.standard.define_alias",
0643: "define_alias");
0644: defSntxStFld("define-variable",
0645: "kawa.standard.define_variable", "define_variable");
0646: defSntxStFld("define-member-alias",
0647: "kawa.standard.define_member_alias",
0648: "define_member_alias");
0649: defSntxStFld("require", "kawa.standard.require", "require");
0650: defSntxStFld("module-name", "kawa.standard.module_name",
0651: "module_name");
0652: defSntxStFld("module-extends", "kawa.standard.module_extends",
0653: "module_extends");
0654: defSntxStFld("module-implements",
0655: "kawa.standard.module_implements", "module_implements");
0656: defSntxStFld("module-static", "kawa.standard.module_static",
0657: "module_static");
0658: defSntxStFld("module-export", "kawa.standard.export",
0659: "module_export");
0660: defSntxStFld("module-compile-options",
0661: "kawa.standard.module_compile_options",
0662: "module_compile_options");
0663: defSntxStFld("with-compile-options",
0664: "kawa.standard.with_compile_options",
0665: "with_compile_options");
0666:
0667: defProcStFld("array?", "kawa.lib.arrays");
0668: defProcStFld("array-rank", "kawa.lib.arrays");
0669: defProcStFld("make-array", "kawa.lib.arrays");
0670: defProcStFld("array", "kawa.lib.arrays");
0671: defProcStFld("array-start", "kawa.lib.arrays");
0672: defProcStFld("array-end", "kawa.lib.arrays");
0673: defProcStFld("shape", "kawa.lib.arrays");
0674: defProcStFld("array-ref", "gnu.kawa.functions.ArrayRef",
0675: "arrayRef");
0676: defProcStFld("array-set!", "gnu.kawa.functions.ArraySet",
0677: "arraySet");
0678: defProcStFld("share-array", "kawa.lib.arrays");
0679:
0680: defProcStFld("s8vector?", "kawa.lib.uniform");
0681: defProcStFld("make-s8vector", "kawa.lib.uniform");
0682: defProcStFld("s8vector", "kawa.lib.uniform");
0683: defProcStFld("s8vector-length", "kawa.lib.uniform");
0684: defProcStFld("s8vector-ref", "kawa.lib.uniform");
0685: defProcStFld("s8vector-set!", "kawa.lib.uniform");
0686: defProcStFld("s8vector->list", "kawa.lib.uniform");
0687: defProcStFld("list->s8vector", "kawa.lib.uniform");
0688: defProcStFld("u8vector?", "kawa.lib.uniform");
0689: defProcStFld("make-u8vector", "kawa.lib.uniform");
0690: defProcStFld("u8vector", "kawa.lib.uniform");
0691: defProcStFld("u8vector-length", "kawa.lib.uniform");
0692: defProcStFld("u8vector-ref", "kawa.lib.uniform");
0693: defProcStFld("u8vector-set!", "kawa.lib.uniform");
0694: defProcStFld("u8vector->list", "kawa.lib.uniform");
0695: defProcStFld("list->u8vector", "kawa.lib.uniform");
0696:
0697: defProcStFld("s16vector?", "kawa.lib.uniform");
0698: defProcStFld("make-s16vector", "kawa.lib.uniform");
0699: defProcStFld("s16vector", "kawa.lib.uniform");
0700: defProcStFld("s16vector-length", "kawa.lib.uniform");
0701: defProcStFld("s16vector-ref", "kawa.lib.uniform");
0702: defProcStFld("s16vector-set!", "kawa.lib.uniform");
0703: defProcStFld("s16vector->list", "kawa.lib.uniform");
0704: defProcStFld("list->s16vector", "kawa.lib.uniform");
0705: defProcStFld("u16vector?", "kawa.lib.uniform");
0706: defProcStFld("make-u16vector", "kawa.lib.uniform");
0707: defProcStFld("u16vector", "kawa.lib.uniform");
0708: defProcStFld("u16vector-length", "kawa.lib.uniform");
0709: defProcStFld("u16vector-ref", "kawa.lib.uniform");
0710: defProcStFld("u16vector-set!", "kawa.lib.uniform");
0711: defProcStFld("u16vector->list", "kawa.lib.uniform");
0712: defProcStFld("list->u16vector", "kawa.lib.uniform");
0713:
0714: defProcStFld("s32vector?", "kawa.lib.uniform");
0715: defProcStFld("make-s32vector", "kawa.lib.uniform");
0716: defProcStFld("s32vector", "kawa.lib.uniform");
0717: defProcStFld("s32vector-length", "kawa.lib.uniform");
0718: defProcStFld("s32vector-ref", "kawa.lib.uniform");
0719: defProcStFld("s32vector-set!", "kawa.lib.uniform");
0720: defProcStFld("s32vector->list", "kawa.lib.uniform");
0721: defProcStFld("list->s32vector", "kawa.lib.uniform");
0722: defProcStFld("u32vector?", "kawa.lib.uniform");
0723: defProcStFld("make-u32vector", "kawa.lib.uniform");
0724: defProcStFld("u32vector", "kawa.lib.uniform");
0725: defProcStFld("u32vector-length", "kawa.lib.uniform");
0726: defProcStFld("u32vector-ref", "kawa.lib.uniform");
0727: defProcStFld("u32vector-set!", "kawa.lib.uniform");
0728: defProcStFld("u32vector->list", "kawa.lib.uniform");
0729: defProcStFld("list->u32vector", "kawa.lib.uniform");
0730:
0731: defProcStFld("s64vector?", "kawa.lib.uniform");
0732: defProcStFld("make-s64vector", "kawa.lib.uniform");
0733: defProcStFld("s64vector", "kawa.lib.uniform");
0734: defProcStFld("s64vector-length", "kawa.lib.uniform");
0735: defProcStFld("s64vector-ref", "kawa.lib.uniform");
0736: defProcStFld("s64vector-set!", "kawa.lib.uniform");
0737: defProcStFld("s64vector->list", "kawa.lib.uniform");
0738: defProcStFld("list->s64vector", "kawa.lib.uniform");
0739: defProcStFld("u64vector?", "kawa.lib.uniform");
0740: defProcStFld("make-u64vector", "kawa.lib.uniform");
0741: defProcStFld("u64vector", "kawa.lib.uniform");
0742: defProcStFld("u64vector-length", "kawa.lib.uniform");
0743: defProcStFld("u64vector-ref", "kawa.lib.uniform");
0744: defProcStFld("u64vector-set!", "kawa.lib.uniform");
0745: defProcStFld("u64vector->list", "kawa.lib.uniform");
0746: defProcStFld("list->u64vector", "kawa.lib.uniform");
0747:
0748: defProcStFld("f32vector?", "kawa.lib.uniform");
0749: defProcStFld("make-f32vector", "kawa.lib.uniform");
0750: defProcStFld("f32vector", "kawa.lib.uniform");
0751: defProcStFld("f32vector-length", "kawa.lib.uniform");
0752: defProcStFld("f32vector-ref", "kawa.lib.uniform");
0753: defProcStFld("f32vector-set!", "kawa.lib.uniform");
0754: defProcStFld("f32vector->list", "kawa.lib.uniform");
0755: defProcStFld("list->f32vector", "kawa.lib.uniform");
0756: defProcStFld("f64vector?", "kawa.lib.uniform");
0757: defProcStFld("make-f64vector", "kawa.lib.uniform");
0758: defProcStFld("f64vector", "kawa.lib.uniform");
0759: defProcStFld("f64vector-length", "kawa.lib.uniform");
0760: defProcStFld("f64vector-ref", "kawa.lib.uniform");
0761: defProcStFld("f64vector-set!", "kawa.lib.uniform");
0762: defProcStFld("f64vector->list", "kawa.lib.uniform");
0763: defProcStFld("list->f64vector", "kawa.lib.uniform");
0764:
0765: defSntxStFld("cut", "gnu.kawa.slib.cut");
0766: defSntxStFld("cute", "gnu.kawa.slib.cut");
0767:
0768: defSntxStFld("cond-expand", "kawa.lib.syntax");
0769: defSntxStFld("%cond-expand", "kawa.lib.syntax");
0770:
0771: defAliasStFld("*print-base*",
0772: "gnu.kawa.functions.DisplayFormat", "outBase");
0773: defAliasStFld("*print-radix*",
0774: "gnu.kawa.functions.DisplayFormat", "outRadix");
0775: defAliasStFld("*print-right-margin*", "gnu.text.PrettyWriter",
0776: "lineLengthLoc");
0777: defAliasStFld("*print-miser-width*", "gnu.text.PrettyWriter",
0778: "miserWidthLoc");
0779: defAliasStFld("html", "gnu.kawa.xml.XmlNamespace", "HTML");
0780:
0781: defAliasStFld("path", "gnu.kawa.lispexpr.LangObjType",
0782: "pathType");
0783: defAliasStFld("filepath", "gnu.kawa.lispexpr.LangObjType",
0784: "filepathType");
0785: defAliasStFld("URI", "gnu.kawa.lispexpr.LangObjType", "URIType");
0786: defProcStFld("path?", "kawa.lib.files");
0787: defProcStFld("filepath?", "kawa.lib.files");
0788: defProcStFld("URI?", "kawa.lib.files");
0789: defProcStFld("absolute-path?", "kawa.lib.files");
0790: defProcStFld("path-scheme", "kawa.lib.files");
0791: defProcStFld("path-authority", "kawa.lib.files");
0792: defProcStFld("path-user-info", "kawa.lib.files");
0793: defProcStFld("path-host", "kawa.lib.files");
0794: defProcStFld("path-port", "kawa.lib.files");
0795: defProcStFld("path-file", "kawa.lib.files");
0796: defProcStFld("path-parent", "kawa.lib.files");
0797: defProcStFld("path-directory", "kawa.lib.files");
0798: defProcStFld("path-last", "kawa.lib.files");
0799: defProcStFld("path-extension", "kawa.lib.files");
0800: defProcStFld("path-fragment", "kawa.lib.files");
0801: defProcStFld("path-query", "kawa.lib.files");
0802:
0803: kawaEnvironment.setLocked();
0804: }
0805:
0806: public Scheme() {
0807: environ = kawaEnvironment;
0808: userEnv = getNewEnvironment();
0809: }
0810:
0811: protected Scheme(Environment env) {
0812: environ = env;
0813: }
0814:
0815: public String getName() {
0816: return "Scheme";
0817: }
0818:
0819: public NamedLocation lookupBuiltin(Symbol name, Object property,
0820: int hash) {
0821: NamedLocation loc = super .lookupBuiltin(name, property, hash);
0822: if (loc == null && property == null) {
0823: // Special handling for names of the form "<TYPE>". I.e. if an
0824: // identifier of the form is unbound, then get a matching Type.
0825: // Also, handles U$unit by doing Unit.lookup("U"). (The Scheme reader
0826: // translates a quantity like 2in to (* 2 in$unit). The advantage is
0827: // is that we can have clean scoping rules for unit names; the downside
0828: // is that 2in is no longer a literal.)
0829: String nam = name.getName();
0830: Object val = null;
0831: String uri = name.getNamespaceURI();
0832: int len = nam.length();
0833: if (nam.endsWith("$unit"))
0834: val = Unit.lookup(nam.substring(0, nam.length() - 5));
0835: else if (len > 2 && nam.charAt(0) == '<'
0836: && nam.charAt(len - 1) == '>') {
0837: String tname = nam.substring(1, len - 1);
0838: val = Scheme.string2Type(tname);
0839: }
0840: if (val != null) {
0841: loc = new PlainLocation(name, null);
0842: loc.set(val);
0843: }
0844: }
0845: return loc;
0846: }
0847:
0848: /** Evalutate Scheme expressions from string.
0849: * @param string the string constaining Scheme expressions
0850: * @param env the Environment to evaluate the string in
0851: * @return result of last expression, or Language.voidObject if none. */
0852: public static Object eval(String string, Environment env) {
0853: return eval(new CharArrayInPort(string), env);
0854: }
0855:
0856: /** Evalutate Scheme expressions from stream.
0857: * @param port the port to read Scheme expressions from
0858: * @param env the Environment to evaluate the string in
0859: * @return result of last expression, or Language.voidObject if none. */
0860: public static Object eval(InPort port, Environment env) {
0861: SourceMessages messages = new SourceMessages();
0862: try {
0863: LispReader lexer = (LispReader) Language
0864: .getDefaultLanguage().getLexer(port, messages);
0865: Object body = ReaderParens.readList(lexer, 0, 1, -1);
0866: if (messages.seenErrors())
0867: throw new gnu.text.SyntaxException(messages);
0868: return Eval.evalBody(body, env, messages);
0869: } catch (gnu.text.SyntaxException e) {
0870: // The '\n' is because a SyntaxException includes a line number,
0871: // and it is better if that starts the line. FIXME OBSOLETE
0872: throw new RuntimeException(
0873: "eval: errors while compiling:\n"
0874: + e.getMessages().toString(20));
0875: } catch (java.io.IOException e) {
0876: throw new RuntimeException("eval: I/O exception: "
0877: + e.toString());
0878: } catch (RuntimeException ex) {
0879: throw ex;
0880: } catch (Error ex) {
0881: throw ex;
0882: } catch (Throwable ex) {
0883: throw new WrappedException(ex);
0884: }
0885: }
0886:
0887: /** Evalutate Scheme expressions from an "S expression."
0888: * @param sexpr the S expression to evaluate
0889: * @param env the Environment to evaluate the string in
0890: * @return result of the expression. */
0891: public static Object eval(Object sexpr, Environment env) {
0892: try {
0893: return Eval.eval(sexpr, env);
0894: } catch (RuntimeException ex) {
0895: throw ex;
0896: } catch (Error ex) {
0897: throw ex;
0898: } catch (Throwable ex) {
0899: throw new WrappedException(ex);
0900: }
0901: }
0902:
0903: public static final AbstractFormat writeFormat = new DisplayFormat(
0904: true, 'S');
0905: public static final AbstractFormat displayFormat = new DisplayFormat(
0906: false, 'S');
0907:
0908: public AbstractFormat getFormat(boolean readable) {
0909: return readable ? writeFormat : displayFormat;
0910: }
0911:
0912: public int getNamespaceOf(Declaration decl) {
0913: return FUNCTION_NAMESPACE + VALUE_NAMESPACE;
0914: }
0915:
0916: /** If exp is a "constant" Type, return that type, otherwise return null. */
0917: public static Type getTypeValue(Expression exp) {
0918: return getInstance().getTypeFor(exp);
0919: }
0920:
0921: static Hashtable types;
0922:
0923: public static Type getNamedType(String name) {
0924: if (types == null) {
0925: booleanType = new LangPrimType(Type.boolean_type, Scheme
0926: .getInstance());
0927: types = new Hashtable();
0928: types.put("void", LangPrimType.voidType);
0929: types.put("int", LangPrimType.intType);
0930: types.put("char", LangPrimType.charType);
0931: types.put("boolean", booleanType);
0932: types.put("byte", LangPrimType.byteType);
0933: types.put("short", LangPrimType.shortType);
0934: types.put("long", LangPrimType.longType);
0935: types.put("float", LangPrimType.floatType);
0936: types.put("double", LangPrimType.doubleType);
0937: types.put("never-returns", Type.neverReturnsType);
0938:
0939: types.put("Object", Type.pointer_type);
0940: types.put("java.lang.Object", Type.pointer_type);
0941: types.put("String", Type.tostring_type);
0942:
0943: types.put("object", Type.pointer_type);
0944: types.put("number", ClassType.make("gnu.math.Numeric"));
0945: types.put("quantity", ClassType.make("gnu.math.Quantity"));
0946: types.put("complex", ClassType.make("gnu.math.Complex"));
0947: types.put("real", ClassType.make("gnu.math.RealNum"));
0948: types.put("rational", ClassType.make("gnu.math.RatNum"));
0949: types.put("integer", ClassType.make("gnu.math.IntNum"));
0950: types.put("symbol", ClassType.make("java.lang.String"));
0951: types.put("keyword", ClassType.make("gnu.expr.Keyword"));
0952: types.put("list", ClassType.make("gnu.lists.LList"));
0953: types.put("pair", ClassType.make("gnu.lists.Pair"));
0954: types.put("pair-with-position", ClassType
0955: .make("gnu.lists.PairWithPosition"));
0956: types.put("string", ClassType.make("gnu.lists.FString"));
0957: types.put("abstract-string", ClassType
0958: .make("gnu.lists.CharSeq"));
0959: types.put("character", ClassType.make("gnu.text.Char"));
0960: types.put("vector", ClassType.make("gnu.lists.FVector"));
0961: types.put("function", ClassType
0962: .make("gnu.mapping.Procedure"));
0963: types.put("procedure", ClassType
0964: .make("gnu.mapping.Procedure"));
0965: types.put("input-port", ClassType
0966: .make("gnu.mapping.InPort"));
0967: types.put("output-port", ClassType
0968: .make("gnu.mapping.OutPort"));
0969: types.put("string-output-port", ClassType
0970: .make("gnu.mapping.CharArrayOutPort"));
0971: types.put("record", ClassType.make("kawa.lang.Record"));
0972: types.put("type", ClassType.make("gnu.bytecode.Type"));
0973: types.put("class-type", ClassType
0974: .make("gnu.bytecode.ClassType"));
0975:
0976: types.put("s8vector", ClassType.make("gnu.lists.S8Vector"));
0977: types.put("u8vector", ClassType.make("gnu.lists.U8Vector"));
0978: types.put("s16vector", ClassType
0979: .make("gnu.lists.S16Vector"));
0980: types.put("u16vector", ClassType
0981: .make("gnu.lists.U16Vector"));
0982: types.put("s32vector", ClassType
0983: .make("gnu.lists.S32Vector"));
0984: types.put("u32vector", ClassType
0985: .make("gnu.lists.U32Vector"));
0986: types.put("s64vector", ClassType
0987: .make("gnu.lists.S64Vector"));
0988: types.put("u64vector", ClassType
0989: .make("gnu.lists.U64Vector"));
0990: types.put("f32vector", ClassType
0991: .make("gnu.lists.F32Vector"));
0992: types.put("f64vector", ClassType
0993: .make("gnu.lists.F64Vector"));
0994: types.put("document", ClassType.make("gnu.lists.TreeList"));
0995: types.put("readtable", ClassType
0996: .make("gnu.kawa.lispexpr.ReadTable"));
0997: }
0998: Type type = (Type) types.get(name);
0999: if (type == null
1000: && (name.startsWith("elisp:") || name
1001: .startsWith("clisp:"))) {
1002: int colon = name.indexOf(':');
1003: Class clas = getNamedType(name.substring(colon + 1))
1004: .getReflectClass();
1005: String lang = name.substring(0, colon);
1006: Language interp = Language.getInstance(lang);
1007: if (interp == null)
1008: throw new RuntimeException("unknown type '" + name
1009: + "' - unknown language '" + lang + '\'');
1010: type = interp.getTypeFor(clas);
1011: if (type != null)
1012: types.put(name, type);
1013: }
1014: return type;
1015: }
1016:
1017: public Type getTypeFor(Class clas) {
1018: String name = clas.getName();
1019: if (clas.isPrimitive())
1020: return getNamedType(name);
1021: if ("java.lang.String".equals(name))
1022: return Type.tostring_type;
1023: if ("gnu.text.Path".equals(name))
1024: return LangObjType.pathType;
1025: if ("gnu.text.URIPath".equals(name))
1026: return LangObjType.URIType;
1027: if ("gnu.text.FilePath".equals(name))
1028: return LangObjType.filepathType;
1029: return Type.make(clas);
1030: }
1031:
1032: public static Type string2Type(String name) {
1033: Type t;
1034: if (name.endsWith("[]")) {
1035: t = string2Type(name.substring(0, name.length() - 2));
1036: if (t != null)
1037: t = ArrayType.make(t);
1038: } else
1039: t = getNamedType(name);
1040: if (t != null)
1041: return t;
1042: t = Language.string2Type(name);
1043: if (t != null)
1044: types.put(name, t);
1045: return t;
1046: }
1047:
1048: public Type getTypeFor(String name) {
1049: return string2Type(name);
1050: }
1051:
1052: /** Convert expression to a Type.
1053: * Allow "TYPE" or 'TYPE or <TYPE>.
1054: */
1055: public static Type exp2Type(Expression exp) {
1056: return getInstance().getTypeFor(exp);
1057: }
1058:
1059: public Expression makeApply(Expression func, Expression[] args) {
1060: if (func instanceof ReferenceExp
1061: && (((ReferenceExp) func).getBinding() == getNamedPartDecl)) {
1062: // FIXME don't copy the args array in makeExp ...
1063: return GetNamedPart.makeExp(args[0], args[1]);
1064: }
1065: Expression[] exps = new Expression[args.length + 1];
1066: exps[0] = func;
1067: System.arraycopy(args, 0, exps, 1, args.length);
1068: return new ApplyExp(new ReferenceExp(applyFieldDecl), exps);
1069: }
1070:
1071: public ReadTable createReadTable() {
1072: ReadTable tab = ReadTable.createInitial();
1073: tab.postfixLookupOperator = ':';
1074: ReaderDispatch dispatchTable = (ReaderDispatch) tab.lookup('#');
1075: dispatchTable.set('\'', new ReaderQuote("syntax"));
1076: dispatchTable.set('`', new ReaderQuote("quasisyntax"));
1077: dispatchTable.set(',', ReaderDispatchMisc.getInstance());
1078: tab.putReaderCtorFld("path", "gnu.kawa.lispexpr.LangObjType",
1079: "pathType");
1080: tab.putReaderCtorFld("filepath",
1081: "gnu.kawa.lispexpr.LangObjType", "filepathType");
1082: tab.putReaderCtorFld("URI", "gnu.kawa.lispexpr.LangObjType",
1083: "URIType");
1084: tab.putReaderCtorFld("namespace", "kawa.lib.misc", "namespace");
1085: tab
1086: .putReaderCtorFld("duration", "kawa.lib.numbers",
1087: "duration");
1088: return tab;
1089: }
1090:
1091: /** The compiler insert calls to this method for applications and applets. */
1092: public static void registerEnvironment() {
1093: Language.setDefaults(getInstance());
1094: }
1095: }
|