Esempio n. 1
0
        public Package(Interpreter interpreter, string name, PackageProvider pp)
        {
            if (interpreter == null)
                Error.Critical(new ArgumentNullException("interpreter"), typeof(Package));
            if (name == null)
                Error.Critical(new ArgumentNullException("name"), typeof(Package));

            InnerName = name;
            InnerPackageProvider = pp ?? new PackageProvider();
            InnerInterpreter = interpreter;
            InnerExternalTable = new SymbolTable(this, InnerInterpreter.TypeResolver);
            InnerInternalTable = new SymbolTable(this, InnerInterpreter.TypeResolver);
        }
Esempio n. 2
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);
        }