Example #1
0
        public IodineModule Compile(IodineContext context)
        {
            string moduleName = Path == null ? "__anonymous__" :
                                System.IO.Path.GetFileNameWithoutExtension(Path);

            if (HasPath)
            {
                string wd      = System.IO.Path.GetDirectoryName(Path);
                string depPath = System.IO.Path.Combine(wd, ".deps");

                if (!context.SearchPath.Contains(wd))
                {
                    context.SearchPath.Add(wd);
                }

                if (!context.SearchPath.Contains(depPath))
                {
                    context.SearchPath.Add(depPath);
                }
            }
            Parser         parser   = Parser.CreateParser(context, this);
            AstRoot        root     = parser.Parse();
            IodineCompiler compiler = IodineCompiler.CreateCompiler(context, root);

            return(compiler.Compile(moduleName));
        }
Example #2
0
        public IodineModule Compile(IodineContext context)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            context.ErrorLog.Clear();

            string moduleName = Path == null ? "__anonymous__"
                : System.IO.Path.GetFileNameWithoutExtension(Path);

            if (HasPath)
            {
                string wd      = System.IO.Path.GetDirectoryName(Path);
                string depPath = System.IO.Path.Combine(wd, ".deps");

                if (!context.SearchPath.Contains(wd))
                {
                    context.SearchPath.Add(wd);
                }

                if (!context.SearchPath.Contains(depPath))
                {
                    context.SearchPath.Add(depPath);
                }

                IodineModule cachedModule = null;

                if (LoadCachedModule(ref cachedModule))
                {
                    return(cachedModule);
                }
            }

            Parser parser = Parser.CreateParser(context, this);

            CompilationUnit root = parser.Parse();

            IodineCompiler compiler = IodineCompiler.CreateCompiler(context, root);

            IodineModule module = compiler.Compile(moduleName, Path);

            if (Path == null)
            {
                foreach (KeyValuePair <string, IodineObject> kv in module.Attributes)
                {
                    context.InteractiveLocals [kv.Key] = kv.Value;
                }
                module.Attributes = context.InteractiveLocals;
            }
            else if (context.ShouldCache)
            {
                CacheModule(module);
            }

            return(module);
        }
Example #3
0
        public static IodineModule CompileModuleFromSource(ErrorLog errorLog, string source)
        {
            Tokenizer lexer = new Tokenizer (errorLog, source);
            TokenStream tokenStream = lexer.Scan ();
            if (errorLog.ErrorCount > 0)
                return null;
            Parser parser = new Parser (tokenStream);
            AstRoot root = parser.Parse ();
            if (errorLog.ErrorCount > 0)
                return null;
            SemanticAnalyser analyser = new SemanticAnalyser (errorLog);
            SymbolTable symbolTable = analyser.Analyse (root);
            if (errorLog.ErrorCount > 0)
                return null;
            IodineCompiler compiler = new IodineCompiler (errorLog, symbolTable, "");
            IodineModule module = new IodineModule ("");

            compiler.CompileAst (module, root);
            if (errorLog.ErrorCount > 0)
                return null;
            return module;
        }
Example #4
0
 public static IodineModule CompileModule(ErrorLog errorLog, string file)
 {
     if (FindModule (file) != null) {
         Tokenizer lexer = new Tokenizer (errorLog, File.ReadAllText (FindModule (file)), file);
         TokenStream tokenStream = lexer.Scan ();
         if (errorLog.ErrorCount > 0)
             return null;
         Parser parser = new Parser (tokenStream);
         AstRoot root = parser.Parse ();
         if (errorLog.ErrorCount > 0)
             return null;
         SemanticAnalyser analyser = new SemanticAnalyser (errorLog);
         SymbolTable symbolTable = analyser.Analyse (root);
         if (errorLog.ErrorCount > 0)
             return null;
         IodineCompiler compiler = new IodineCompiler (errorLog, symbolTable, Path.GetFullPath (file));
         IodineModule module = new IodineModule (Path.GetFileNameWithoutExtension (file));
         compiler.CompileAst (module, root);
         if (errorLog.ErrorCount > 0)
             return null;
         return module;
     } else {
         errorLog.AddError (ErrorType.ParserError, new Location (0, 0, file),
             "Could not find module {0}", file);
         return null;
     }
 }