Beispiel #1
0
        protected void Initialize()
        {
            InnerGlobalEnvironment = new Environment(null, null, null);
            InnerReader = new Reader(this);
            InnerPackageProvider = new PackageProvider();
            InnerGlobalPackage = Package.DefinePackage("global", this);
            CurrentPackage = Package.DefinePackage("internal", this);
            CurrentPackage.Export("*package*");
            InnerKeywordPackage = Package.DefinePackage("keyword", this);

            CurrentPackage.UsePackage(InnerKeywordPackage);
            CurrentPackage.UsePackage(InnerGlobalPackage);

            Assembly[] asm = AppDomain.CurrentDomain.GetAssemblies();
            foreach (Assembly a in asm) {
                AddTypesFrom(a);
            }

            InternBuiltins();
            Primitives.InternAll(this);
            LASTVAL.GlobalValue = null;
            NEXTLASTVAL.GlobalValue = null;
            THIRDLASTVAL.GlobalValue = null;

            //these primitives are here, rather than in Primitives, because their implementation
            //requires calls to gfs bound to symbols
            InternAndExport("intern", new Function(InternF));
            InternAndExport("unintern", new Function(UnInternF));
            InternAndExport("eval", new Function(EvalF));
            InternAndExport("load", new Function(LoadF));
            InternAndExport("map->list", new Function(MapToList));
            InternAndExport("apply", new Function(Apply));
            InternAndExport("<", new Function(Lt));
            InternAndExport("<=", new Function(LtEq));
            InternAndExport(">", new Function(Gt));
            InternAndExport(">=", new Function(GtEq));
            InternAndExport("==", new Function(EqEq));
            InternAndExport("!=", new Function(NotEq));
            InternAndExport("typeof", new Function(TypeOf));
            InternAndExport("null", null);
            InternAndExport("defpackage", new Function(DefPackage));
            InternAndExport("use-package", new Function(UsePackage));
            InternAndExport("in-package", new Function(InPackage));
            InternAndExport("gensym", new Function(GenSym));
            InternAndExport("export", new Function(Export));
            InternAndExport("cast", new Function(Cast));

            InnerStrGF = (SimpleGenericFunction)InternAndExport("str").GlobalValue;
            InnerGetEnumGF = (SimpleGenericFunction)InternAndExport("get-enum").GlobalValue;
            InnerCompareGF = (BinOp)InternAndExport("compare").GlobalValue;

            Intern("interpreter", this);
        }
Beispiel #2
0
        public static void InternAll(Interpreter interpreter)
        {
            interpreter.InternAndExport("not", new Function(not));
            interpreter.InternAndExport("to-bool", new Function(to_bool));
            interpreter.InternAndExport("nil?", new Function(nilp));
            interpreter.InternAndExport("symbol?", new Function(symbolp));
            interpreter.InternAndExport("eqv?", new Function(eqv));
            interpreter.InternAndExport("eql?", new Function(eql));
            interpreter.InternAndExport("cons", new Function(cons));
            interpreter.InternAndExport("cons?", new Function(consp));
            interpreter.InternAndExport("atom?", new Function(atomp));
            interpreter.InternAndExport("first", new Function(first));
            interpreter.InternAndExport("rest", new Function(rest));
            interpreter.InternAndExport("set-first", new Function(setfirst));
            interpreter.InternAndExport("set-rest", new Function(setrest));
            interpreter.InternAndExport("second", new Function(second));
            interpreter.InternAndExport("third", new Function(third));
            interpreter.InternAndExport("fourth", new Function(fourth));
            interpreter.InternAndExport("reverse", new Function(reverse));
            interpreter.InternAndExport("list?", new Function(listp));
            interpreter.InternAndExport("len", new Function(listlength));
            interpreter.InternAndExport("nth", new Function(nth));
            interpreter.InternAndExport("nth-rest", new Function(nthrest));
            interpreter.InternAndExport("append", new Function(append));
            interpreter.InternAndExport("concat!", new Function(concat_d));
            interpreter.InternAndExport("type-of", new Function(type_of));
            interpreter.InternAndExport("is?", new Function(isp));
            interpreter.InternAndExport("even?", new Function(evenp));
            interpreter.InternAndExport("macroexpand-1", new Function(macroexpand_1));
            interpreter.InternAndExport("vector", new Function(vector));
            interpreter.InternAndExport("vector-of", new Function(vector_of));
            interpreter.InternAndExport("throw", new Function(throwfun));
            interpreter.InternAndExport("try-catch-finally", new Function(try_catch_finally));

            interpreter.InternAndExport("<i", new Function(lti));
            interpreter.InternAndExport("addi", new Function(addints));

            BinOp addop = new BinOp();
            addop.AddMethod(typeof(Int32), typeof(Int32), new Function(addints));
            addop.AddMethod(typeof(Int32), typeof(Object), new Function(addobjs));
            addop.AddMethod(typeof(Object), typeof(Object), new Function(addobjs));
            interpreter.InternAndExport("add", addop);

            BinOp subtractop = new BinOp();
            subtractop.AddMethod(typeof(Int32), typeof(Int32), new Function(subtractints));
            subtractop.AddMethod(typeof(Int32), typeof(Object), new Function(subtractobjs));
            subtractop.AddMethod(typeof(Object), typeof(Object), new Function(subtractobjs));
            interpreter.InternAndExport("subtract", subtractop);

            BinOp multiplyop = new BinOp();
            multiplyop.AddMethod(typeof(Int32), typeof(Int32), new Function(multiplyints));
            multiplyop.AddMethod(typeof(Int32), typeof(Object), new Function(multiplyobjs));
            multiplyop.AddMethod(typeof(Object), typeof(Object), new Function(multiplyobjs));
            interpreter.InternAndExport("multiply", multiplyop);

            BinOp divideop = new BinOp();
            divideop.AddMethod(typeof(Int32), typeof(Int32), new Function(divideints));
            divideop.AddMethod(typeof(Int32), typeof(Object), new Function(divideobjs));
            divideop.AddMethod(typeof(Object), typeof(Object), new Function(divideobjs));
            interpreter.InternAndExport("divide", divideop);

            BinOp modop = new BinOp();
            modop.AddMethod(typeof(Int32), typeof(Int32), new Function(modints));
            interpreter.InternAndExport("mod", modop);

            BinOp compareop = new BinOp();
            compareop.AddMethod(typeof(Int32), typeof(Int32), new Function(subtractints));
            compareop.AddMethod(typeof(Int32), typeof(Object), new Function(compareobjs));
            compareop.AddMethod(typeof(Object), typeof(Object), new Function(compareobjs));
            interpreter.InternAndExport("compare", compareop);

            BinOp bitorop = new BinOp();
            bitorop.AddMethod(typeof(Enum), typeof(Enum), new Function(bitorenum));
            bitorop.AddMethod(typeof(Object), typeof(Object), new Function(bitor));
            interpreter.InternAndExport("bit-or", bitorop);

            BinOp bitandop = new BinOp();
            bitandop.AddMethod(typeof(Enum), typeof(Enum), new Function(bitandenum));
            bitandop.AddMethod(typeof(Object), typeof(Object), new Function(bitand));
            interpreter.InternAndExport("bit-and", bitandop);

            BinOp bitxorop = new BinOp();
            bitxorop.AddMethod(typeof(Enum), typeof(Enum), new Function(bitxorenum));
            bitxorop.AddMethod(typeof(Object), typeof(Object), new Function(bitxor));
            interpreter.InternAndExport("bit-xor", bitxorop);

            SimpleGenericFunction bitnotgf = new SimpleGenericFunction();
            bitnotgf.AddMethod(typeof(Enum), new Function(bitnotenum));
            bitnotgf.AddMethod(typeof(Object), new Function(bitnot));
            interpreter.InternAndExport("bit-not", bitnotgf);

            SimpleGenericFunction get_enum_gf = new SimpleGenericFunction();
            get_enum_gf.AddMethod(typeof(IEnumerator), new Function(get_enum_IEnumerator));
            get_enum_gf.AddMethod(typeof(IEnumerable), new Function(get_enum_IEnumerable));
            get_enum_gf.AddMethod(null, new Function(get_enum_nil));
            interpreter.InternAndExport("get-enum", get_enum_gf);

            SimpleGenericFunction strgf = new SimpleGenericFunction();
            strgf.AddMethod(null, new Function(strnil));
            strgf.AddMethod(typeof(Object), new Function(strobj));
            interpreter.InternAndExport("str", strgf);
        }