Exemplo n.º 1
0
        /// <summary>Finds the standard prelude file, loads and
        /// interprets it, and places the created module in scope</summary>
        public void LoadPrelude()
        {
            if (loadedPrelude)
            {
                return;
            }
            if (JSIL && loadedPreludeObject != null)
            {
                Extend(loadedPreludeObject);
                return;
            }
            string dir         = Path.GetDirectoryName(typeof(Interpreter).Assembly.Location);
            string preludePath = Path.Combine(dir, "prelude.grace");

            using (StreamReader preludeReader = File.OpenText(preludePath))
            {
                var parser = new Parser("prelude", preludeReader.ReadToEnd());
                var pt     = parser.Parse() as ObjectParseNode;
                var eMod   = new ExecutionTreeTranslator().Translate(pt);
                prelude = eMod.Evaluate(this);
                Extend(prelude);
                loadedPrelude       = true;
                loadedPreludeObject = prelude;
                Interpreter.Debug("========== END PRELUDE ==========");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load a string containing Grace code under a given
        /// module name.
        /// </summary>
        /// <param name="importPath">
        /// Module name to treat this code as belonging to.
        /// </param>
        /// <param name="code">
        /// Source code to load.
        /// </param>
        public GraceObject LoadModuleString(string importPath,
                                            string code)
        {
            var parser = new Parser(importPath, code);
            var pt     = parser.Parse() as ObjectParseNode;
            var eMod   = new ExecutionTreeTranslator().Translate(pt);
            var ret    = eMod.Evaluate(this);

            modules[importPath] = ret;
            return(ret);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load a file as the builtin-extending module.
        /// </summary>
        /// <param name="path">Path to file to load</param>
        public void LoadExtensionFile(string path)
        {
            GraceObject ext;

            using (StreamReader reader = File.OpenText(path))
            {
                var parser = new Parser("extension", reader.ReadToEnd());
                var pt     = parser.Parse() as ObjectParseNode;
                var eMod   = new ExecutionTreeTranslator().Translate(pt);
                ext = eMod.Evaluate(this);
            }
            LoadExtensionsFromObject(ext);
        }