Exemplo n.º 1
0
        /// <summary>
        /// Calls an Iodine function in the current module
        /// </summary>
        /// <param name="name">Function name.</param>
        /// <param name="args">Arguments.</param>
        public dynamic Call(string name, params object[] args)
        {
            IodineObject[] arguments = new IodineObject[args.Length];
            for (int i = 0; i < args.Length; i++)
            {
                arguments [i] = typeRegistry.ConvertToIodineObject(args [i]);
            }
            IodineObject ret = Context.Invoke(module.GetAttribute(name), arguments);

            return(IodineDynamicObject.Create(ret, Context.VirtualMachine, typeRegistry));
        }
Exemplo n.º 2
0
        private static void EvalSourceUnit(IodineOptions options, SourceUnit unit)
        {
            try {
                IodineModule module = unit.Compile(context);

                if (context.Debug)
                {
                    context.VirtualMachine.SetTrace(WaitForDebugger);
                }

                do
                {
                    context.Invoke(module, new IodineObject[] { });

                    if (module.HasAttribute("main"))
                    {
                        context.Invoke(module.GetAttribute("main"), new IodineObject[] {
                            options.IodineArguments
                        });
                    }
                } while (options.LoopFlag);

                if (options.ReplFlag)
                {
                    LaunchRepl(options, module);
                }
            } catch (UnhandledIodineExceptionException ex) {
                HandleIodineException(ex);
            } catch (SyntaxException ex) {
                DisplayErrors(ex.ErrorLog);
                Panic("Compilation failed with {0} errors!", ex.ErrorLog.ErrorCount);
            } catch (ModuleNotFoundException ex) {
                Console.Error.WriteLine(ex.ToString());
                Panic("Program terminated.");
            } 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.");
            }
        }