Esempio n. 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));
        }
Esempio n. 2
0
        public static IodineCompiler CreateCompiler(IodineContext context, AstRoot root)
        {
            SemanticAnalyser analyser = new SemanticAnalyser(context.ErrorLog);
            SymbolTable      table    = analyser.Analyse(root);

            return(new IodineCompiler(context, table, root));
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
		public VirtualMachine (IodineContext context)
			: this (context, new Dictionary<string, IodineObject> ())
		{
			Globals = new Dictionary<string, IodineObject> ();
			var modules = BuiltInModules.Modules.Values.Where (p => p.ExistsInGlobalNamespace);
			foreach (IodineModule module in modules) {
				foreach (KeyValuePair<string, IodineObject> value in module.Attributes) {
					Globals [value.Key] = value.Value;
				}
			}
		}
Esempio n. 5
0
		public static void Main (string[] args)
		{
			context = IodineContext.Create ();

			if (args.Length == 0) {
				//ReplShell shell = new ReplShell (config);
				//shell.Run ();
				DisplayUsage ();
				Environment.Exit (0);
			}

			IodineOptions options = IodineOptions.Parse (args);
			options.Options.ForEach (p => ParseOption (context, p));

			SourceUnit code = SourceUnit.CreateFromFile (options.FileName);
			try {
				IodineModule module = code.Compile (context);
				context.Invoke (module, new IodineObject[] { });
				if (module.HasAttribute ("main")) {
					context.Invoke (module.GetAttribute ("main"), new IodineObject[] {
						options.IodineArguments });
				}
			} catch (UnhandledIodineExceptionException ex) {
				Console.Error.WriteLine ("An unhandled {0} has occured!",
					ex.OriginalException.TypeDef.Name);
				Console.Error.WriteLine ("\tMessage: {0}", ex.OriginalException.GetAttribute (
					"message").ToString ());
				Console.WriteLine ();
				ex.PrintStack ();
				Console.Error.WriteLine ();
				Panic ("Program terminated.");
			} catch (SyntaxException ex) {
				DisplayErrors (ex.ErrorLog);
				Panic ("Compilation failed with {0} errors!", ex.ErrorLog.ErrorCount);
			} catch (Exception e) {
				Console.Error.WriteLine ("Fatal exception has occured!");
				Console.Error.WriteLine (e.Message);
				Console.Error.WriteLine ("Stack trace: \n{0}", e.StackTrace);
				Console.Error.WriteLine ("\nIodine stack trace \n{0}",
					context.VirtualMachine.GetStackTrace ());
				Panic ("Program terminated.");
			}

		}
Esempio n. 6
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);
		}
Esempio n. 7
0
 public static Parser CreateParser(IodineContext context, SourceUnit source)
 {
     Tokenizer tokenizer = new Tokenizer (context.ErrorLog, source.Text, source.Path ?? "");
     return new Parser (tokenizer.Scan ());
 }
Esempio n. 8
0
 private IodineCompiler(IodineContext context, SymbolTable symbolTable, AstRoot root)
 {
     this.context     = context;
     this.symbolTable = symbolTable;
     this.root        = root;
 }
Esempio n. 9
0
		private static void ParseOption (IodineContext context, string option)
		{
			switch (option) {
			case "version":
				DisplayInfo ();
				break;
			case "help":
				DisplayUsage ();
				break;
			case "debug":
				RunDebugServer ();
				break;
			default:
				Panic ("Unknown command line option: '{0}'", option);
				break;
			}
		}
Esempio n. 10
0
		public ReplShell (IodineContext context)
		{
			engine = new IodineEngine (context);
		}
Esempio n. 11
0
        private IodineObject eval(VirtualMachine host, string source, IodineHashMap dict)
        {
            VirtualMachine vm = host;

            if (dict != null) {
                vm = new VirtualMachine (host.Context, new Dictionary<string, IodineObject> ());

                foreach (string glob in host.Globals.Keys) {
                    vm.Globals [glob] = host.Globals [glob];
                }

                foreach (IodineObject key in dict.Keys.Values) {
                    vm.Globals [key.ToString ()] = dict.Dict [key.GetHashCode ()];
                }
            }
            IodineContext context = new IodineContext ();
            SourceUnit code = SourceUnit.CreateFromSource (source);
            IodineModule module = null;
            try {
                module = code.Compile (context);
            } catch (SyntaxException ex) {
                vm.RaiseException (new IodineSyntaxException (ex.ErrorLog));
                return null;
            }
            return vm.InvokeMethod (module.Initializer, null, new IodineObject[]{ });
        }
Esempio n. 12
0
		public static IodineCompiler CreateCompiler (IodineContext context, AstRoot root)
		{
			SemanticAnalyser analyser = new SemanticAnalyser (context.ErrorLog);
			SymbolTable table = analyser.Analyse (root);
			return new IodineCompiler (context, table, root);
		}
Esempio n. 13
0
		private IodineCompiler (IodineContext context, SymbolTable symbolTable, AstRoot root)
		{
			this.context = context;
			this.symbolTable = symbolTable;
			this.root = root;
		}
Esempio n. 14
0
		public VirtualMachine (IodineContext context, Dictionary<string, IodineObject> globals)
		{
			Context = context;
			Globals = globals;
			context.ResolveModule += (name) => {
				if (BuiltInModules.Modules.ContainsKey (name)) {
					return BuiltInModules.Modules [name];
				}
				return null;
			};
		}