private IodineObject Invoke(VirtualMachine vm, IodineObject self, IodineObject[] args) { if (args.Length <= 1) { vm.RaiseException(new IodineArgumentException(2)); return(IodineNull.Instance); } IodineDictionary hash = args [1] as IodineDictionary; IodineContext context = new IodineContext(); context.Globals.Clear(); foreach (IodineObject key in hash.Keys) { context.Globals [key.ToString()] = hash.Get(key); args [0].SetAttribute(key.ToString(), hash.Get(key)); } VirtualMachine newVm = new VirtualMachine(context); try { return(args [0].Invoke(newVm, new IodineObject[] { })); } catch (SyntaxException syntaxException) { vm.RaiseException(new IodineSyntaxException(syntaxException.ErrorLog)); return(IodineNull.Instance); } catch (UnhandledIodineExceptionException ex) { vm.RaiseException(ex.OriginalException); return(IodineNull.Instance); } }
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[] { })); }
private IodineObject Eval(VirtualMachine host, string source, IodineDictionary dict) { VirtualMachine vm = host; IodineContext context = host.Context; if (dict != null) { context = new IodineContext(); context.Globals.Clear(); vm = new VirtualMachine(host.Context); foreach (IodineObject key in dict.Keys) { context.Globals [key.ToString()] = dict.Get(key); } } SourceUnit code = SourceUnit.CreateFromSource(source); IodineModule module = null; try { module = code.Compile(context); } catch (SyntaxException ex) { vm.RaiseException(new IodineSyntaxException(ex.ErrorLog)); return(IodineNull.Instance); } return(module.Invoke(vm, new IodineObject[] { })); }
private void ApplyGlobalVariables(IodineContext context) { foreach (KeyValuePair <string, IodineObject> kv in context.Globals) { if (!HasAttribute(kv.Key)) { SetAttribute(kv.Key, kv.Value); } } }
public VirtualMachine(IodineContext context) { Context = context; context.ResolveModule += (name) => { if (BuiltInModules.Modules.ContainsKey(name)) { return(BuiltInModules.Modules [name]); } return(null); }; }
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); }; }
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; } } }
public void Run() { var version = typeof(IodineContext).Assembly.GetName().Version; Console.WriteLine("Iodine v{0}-alpha", version.ToString(3)); Console.WriteLine("Fallback REPL. Enter expressions to have them be evaluated"); IodineContext context = new IodineContext(); context.ShouldOptimize = false; context.Globals ["quit"] = new QuitObject(); while (true) { Console.Write(">>> "); var source = Console.ReadLine().Trim(); try { if (source.Length > 0) { SourceUnit unit = SourceUnit.CreateFromSource(source); var result = unit.Compile(context); IodineObject ret = context.Invoke(result, new IodineObject[] { }); if (!(ret is IodineNull)) { Console.WriteLine(ret.Represent(context.VirtualMachine)); } } } catch (UnhandledIodineExceptionException ex) { Console.Error.WriteLine("*** {0}", ex.OriginalException.GetAttribute("message")); ex.PrintStack(); context.VirtualMachine.Top = null; Console.Error.WriteLine(); } catch (ModuleNotFoundException ex) { Console.Error.WriteLine(ex.ToString()); } catch (SyntaxException syntaxException) { DisplayErrors(syntaxException.ErrorLog); } catch (Exception ex) { Console.Error.WriteLine("Fatal exception has occured!"); Console.Error.WriteLine(ex.Message); Console.Error.WriteLine("Stack trace: \n{0}", ex.StackTrace); //Console.Error.WriteLine ("\nIodine stack trace \n{0}", engine.VirtualMachine.GetStackTrace ()); } } }
public static void Main(string[] args) { context = IodineContext.Create(); AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => { if (e.ExceptionObject is UnhandledIodineExceptionException) { HandleIodineException(e.ExceptionObject as UnhandledIodineExceptionException); } }; IodineOptions options = IodineOptions.Parse(args); context.ShouldCache = !options.SupressAutoCache; context.ShouldOptimize = !options.SupressOptimizer; ExecuteOptions(options); }
public IodineEngine(IodineContext context) { Context = context; Context.ResolveModule += ResolveModule; }
public IodineEngine() : this(IodineContext.Create()) { }
public ReplShell(IodineContext context) { }