Exemple #1
0
        /// <summary>
        /// <see cref="CurrentModule"/>でファイルを指定したエンコードで読み込み、実行します。
        /// </summary>
        /// <param name="fileName">ファイル名</param>
        /// <param name="enc">読み込む際に利用する<see cref="Encoding"/></param>
        public KecaknoahObject DoFile(string fileName, Encoding enc)
        {
            var le = Lexer.AnalyzeFromFile(fileName, enc);

            if (!le.Success)
            {
                throw new KecaknoahException(le.Error);
            }
            var ast = Parser.Parse(le);

            if (!ast.Success)
            {
                throw new KecaknoahException(le.Error);
            }
            var src = Precompiler.PrecompileAll(ast);

            CurrentModule.RegisterSource(src);
            if (CurrentModule["main"] != KecaknoahNil.Instance)
            {
                return(new KecaknoahContext(CurrentModule).Execute(CurrentModule["main"]));
            }
            else
            {
                return(KecaknoahNil.Instance);
            }
        }