示例#1
0
        public Bitmap Process(Matrix matrix, InterpreterOptions options)
        {
            int height = (int)(matrix.Height * options.Scale);
            int width  = (int)(matrix.Width * options.Scale);

            // Set up the pen
            Pen = new Pen(options.Foreground)
            {
                Width = (float)options.Scale,
                Brush = new SolidBrush(options.Background)
            };

            var bitmap = new Bitmap(height, width);

            var g = Graphics.FromImage(bitmap);

            var matrixReader = new MatrixReader(matrix);

            while (matrixReader.MoveNext())
            {
                if (matrixReader.PeekCharacter() == matrixReader.NextSequentialCharacter)
                {
                    DrawPolygon(matrix, g, matrixReader.CurrentChar);
                }
                else
                {
                    DrawShape(matrix, g, matrixReader.CurrentChar);
                }
            }
            g.Flush();

            return(bitmap);
        }
示例#2
0
        /// <summary>
        /// Creates a new Interpreter using the specified options.
        /// </summary>
        /// <param name="options"></param>
        public Interpreter(InterpreterOptions options)
        {
            var caseInsensitive = options.HasFlag(InterpreterOptions.CaseInsensitive);

            var lateBindObject = options.HasFlag(InterpreterOptions.LateBindObject);

            _settings = new ParserSettings(caseInsensitive, lateBindObject);

            if ((options & InterpreterOptions.SystemKeywords) == InterpreterOptions.SystemKeywords)
            {
                SetIdentifiers(LanguageConstants.Literals);
            }

            if ((options & InterpreterOptions.PrimitiveTypes) == InterpreterOptions.PrimitiveTypes)
            {
                Reference(LanguageConstants.PrimitiveTypes);
                Reference(LanguageConstants.CSharpPrimitiveTypes);
            }

            if ((options & InterpreterOptions.CommonTypes) == InterpreterOptions.CommonTypes)
            {
                Reference(LanguageConstants.CommonTypes);
            }

            if ((options & InterpreterOptions.LambdaExpressions) == InterpreterOptions.LambdaExpressions)
            {
                _settings.LambdaExpressions = true;
            }

            _visitors.Add(new DisableReflectionVisitor());
        }
示例#3
0
        /// <summary>
        /// Creates a new Interpreter using the specified options.
        /// </summary>
        /// <param name="options"></param>
        public Interpreter(InterpreterOptions options)
        {
            var caseInsensitive          = options.HasFlag(InterpreterOptions.CaseInsensitive);
            var allowSingleQuotedStrings = options.HasFlag(InterpreterOptions.AllowSingleQuotedStrings);

            _settings = new ParserSettings(caseInsensitive, allowSingleQuotedStrings);

            if ((options & InterpreterOptions.SystemKeywords) == InterpreterOptions.SystemKeywords)
            {
                SetIdentifiers(LanguageConstants.Literals);
            }

            if ((options & InterpreterOptions.PrimitiveTypes) == InterpreterOptions.PrimitiveTypes)
            {
                Reference(LanguageConstants.PrimitiveTypes);
                Reference(LanguageConstants.CSharpPrimitiveTypes);
            }

            if ((options & InterpreterOptions.CommonTypes) == InterpreterOptions.CommonTypes)
            {
                Reference(LanguageConstants.CommonTypes);
            }

            _visitors.Add(new DisableReflectionVisitor());
        }
示例#4
0
 /// <summary>
 /// Create Deepspeech interpreter
 /// </summary>
 void InitSTTInference()
 {
     _options = new InterpreterOptions()
     {
         threads = 4
     };
     _deepspeechInterpreter = new Interpreter(FileUtil.LoadFile(deepspeechFilepath), _options);
 }
示例#5
0
 internal void AddInterpreterOptions(string id, InterpreterOptions options, bool addInteractive = false)
 {
     _interpreterOptions[id] = options;
     if (addInteractive)
     {
         _interactiveOptions[id] = options.InteractiveOptions;
     }
     RaiseEnvironmentsChanged();
 }
示例#6
0
 internal void AddInterpreterOptions(IPythonInterpreterFactory interpreterFactory, InterpreterOptions options, bool addInteractive = false)
 {
     _interpreterOptions[interpreterFactory] = options;
     if (addInteractive)
     {
         _interactiveOptions[interpreterFactory] = options.InteractiveOptions;
     }
     RaiseEnvironmentsChanged();
 }
示例#7
0
 /// <summary>
 /// Create Fastspeech and Melgan interpreters
 /// </summary>
 void InitTTSInference()
 {
     _options = new InterpreterOptions()
     {
         threads = 4
     };
     _fastspeechInterpreter = new Interpreter(FileUtil.LoadFile(fastspeechFilepath), _options);
     _melganInterpreter     = new Interpreter(FileUtil.LoadFile(melganFilepath), _options);
 }
 void InitTTSInference()
 {
     print($"TFLite Version: {Interpreter.GetVersion()}");
     // initialize tflite fastspeech and melgan Interpreter
     _options = new InterpreterOptions()
     {
         threads = 8
     };
     _fastspeechInterpreter = new Interpreter(FileUtil.LoadFile(fastspeechFilepath), _options);
     _melganInterpreter     = new Interpreter(FileUtil.LoadFile(melganFilepath), _options);
 }
        public void Can_compare_enum_parameters()
        {
            var target = new Interpreter();

            InterpreterOptions x = InterpreterOptions.CaseInsensitive;
            InterpreterOptions y = InterpreterOptions.CaseInsensitive;

            Assert.AreEqual(x == y, target.Eval("x == y", new Parameter("x", x), new Parameter("y", y)));

            y = InterpreterOptions.CommonTypes;
            Assert.AreEqual(x != y, target.Eval("x != y", new Parameter("x", x), new Parameter("y", y)));
        }
示例#10
0
        internal InterpreterOptions GetInterpreterOptions(string id)
        {
            InterpreterOptions options;

            if (!_interpreterOptions.TryGetValue(id, out options))
            {
                _interpreterOptions[id] = options = new InterpreterOptions(this, _interpreterRegistry.FindConfiguration(id));
                options.Load();
                RaiseEnvironmentsChanged();
            }
            return(options);
        }
示例#11
0
        internal void SaveInterpreterOptions()
        {
            _interpreterRegistry.BeginSuppressInterpretersChangedEvent();
            try {
                _interpreterOptionsService.DefaultInterpreterId = GlobalInterpreterOptions.DefaultInterpreter;
                // Remove any items
                foreach (var option in InterpreterOptions.Select(kv => kv.Value).Where(o => o.Removed).ToList())
                {
                    _interpreterOptionsService.RemoveConfigurableInterpreter(option._config.Id);
                    RemoveInterpreterOptions(option._config.Id);
                }

                // Add or update any items that weren't removed
                foreach (var option in InterpreterOptions.Select(x => x.Value))
                {
                    if (option.Added)
                    {
                        if (String.IsNullOrWhiteSpace(option.Id))
                        {
                            option.Id = Guid.NewGuid().ToString();
                        }
                        option.Added = false;
                    }

                    if (option.IsConfigurable)
                    {
                        // save configurable interpreter options
                        var actualFactory = _interpreterOptionsService.AddConfigurableInterpreter(
                            option.Description,
                            new InterpreterConfiguration(
                                option.Id,
                                option.Description,
                                !String.IsNullOrWhiteSpace(option.InterpreterPath) ? PathUtils.GetParent(option.InterpreterPath) : "",
                                option.InterpreterPath ?? "",
                                option.WindowsInterpreterPath ?? "",
                                option.PathEnvironmentVariable ?? "",
                                InterpreterArchitecture.TryParse(option.Architecture),
                                Version.Parse(option.Version) ?? new Version(2, 7)
                                )
                            );
                    }
                }


                foreach (var factory in InterpreterOptions.Where(x => x.Value.Id.StartsWith("Placeholder;")).ToArray())
                {
                    RemoveInterpreterOptions(factory.Value.Id);
                }
            } finally {
                _interpreterRegistry.EndSuppressInterpretersChangedEvent();
            }
        }
示例#12
0
        internal InterpreterOptions GetInterpreterOptions(IPythonInterpreterFactory interpreterFactory)
        {
            InterpreterOptions options;

            if (!_interpreterOptions.TryGetValue(interpreterFactory, out options))
            {
                var path = GetInteractivePath(interpreterFactory);
                _interpreterOptions[interpreterFactory] = options = new InterpreterOptions(this, interpreterFactory);
                options.Load();
                RaiseEnvironmentsChanged();
            }
            return(options);
        }
        public void Init()
        {
            var channel = Channel.CreateUnbounded <IEvent>();

            channel.Writer.Complete();
            _eventChannel = channel.Reader;

            _logger  = new Mock <ILogger>();
            _options = new InterpreterOptions
            {
                DataModelHandlerFactories = ImmutableArray.Create(EcmaScriptDataModelHandler.Factory),
                Logger = _logger.Object
            };
            _logger.Setup(e => e.ExecuteLog(It.IsAny <ILoggerContext>(), LogLevel.Info, "MyName", It.IsAny <DataModelValue>(), default, It.IsAny <CancellationToken>()))
    void Start()
    {
        var options = new InterpreterOptions()
        {
            threads  = 2,
            useNNAPI = false,
        };

        interpreter = new Interpreter(FileUtil.LoadFile(fileName), options);
        interpreter.ResizeInputTensor(0, new int[] { 1, 28, 28, 1 });
        interpreter.AllocateTensors();

        inputBuffer = new ComputeBuffer(28 * 28, sizeof(float));
    }
示例#15
0
    void PrepareBindingOn()
    {
        bool isMetal = IsMetal;

        gpuDelegate = CreateGpuDelegate(true);
        var options = new InterpreterOptions();

        // [Metal] must be called ModifyGraphWithDelegate at beginning
        if (isMetal)
        {
            options.AddGpuDelegate(gpuDelegate);
        }
        interpreter = new Interpreter(FileUtil.LoadFile(fileName), options);



        var inputShape0 = interpreter.GetInputTensorInfo(0).shape;
        int height      = inputShape0[1];
        int width       = inputShape0[2];
        // int channels = inputShape0[3];

        // On iOS GPU, input must be 4 channels, regardless of what model expects.
        int gpuInputChannels  = isMetal ? 4 : 3;
        int gpuOutputChannels = isMetal ? 4 : 2;

        inputBuffer = new ComputeBuffer(height * width * gpuInputChannels, sizeof(float));
        inputs      = new float[height, width, gpuInputChannels];
        if (!gpuDelegate.BindBufferToInputTensor(interpreter, 0, inputBuffer))
        {
            Debug.LogError("input is not binded");
        }

        outputBuffer = new ComputeBuffer(height * width * gpuOutputChannels, sizeof(float));
        interpreter.SetAllowBufferHandleOutput(true);
        if (!gpuDelegate.BindBufferToOutputTensor(interpreter, 0, outputBuffer))
        {
            Debug.LogError("output is not binded");
        }

        // [OpenGLGLES] must be called ModifyGraphWithDelegate at last
        if (IsOpenGLES3)
        {
            if (interpreter.ModifyGraphWithDelegate(gpuDelegate) != Interpreter.Status.Ok)
            {
                Debug.LogError("Failed to modify the graph with delegate");
            }
        }
    }
示例#16
0
    void Start()
    {
        var options = new InterpreterOptions()
        {
            threads  = 4,
            useNNAPI = false,
        };

        interpreter = new Interpreter(FileUtil.LoadFile(fileName), options);
        interpreter.ResizeInputTensor(0, new int[] { 1, 512, 512, 3 });
        interpreter.AllocateTensors();

        inputBuffer = new ComputeBuffer(512 * 512 * 3, sizeof(float));

        Slider = GameObject.Find("Slider");
    }
示例#17
0
    void PrepareBindingOff()
    {
        var options = new InterpreterOptions();

        options.AddGpuDelegate();
        interpreter = new Interpreter(FileUtil.LoadFile(fileName), options);

        var inputShape0 = interpreter.GetInputTensorInfo(0).shape;
        int height      = inputShape0[1];
        int width       = inputShape0[2];
        int channels    = inputShape0[3];

        inputs  = new float[height, width, channels];
        outputs = new float[height, width, 2];

        outputBuffer = new ComputeBuffer(height * width * 2, sizeof(float));
    }
示例#18
0
        internal void LoadInterpreterOptions()
        {
            BeginSuppressRaiseEnvironmentsChanged();
            try {
                var placeholders = InterpreterOptions.Where(kv => kv.Key.StartsWith("Placeholder;")).ToArray();
                ClearInterpreterOptions();
                foreach (var interpreter in _interpreterRegistry.Configurations)
                {
                    GetInterpreterOptions(interpreter.Id);
                }

                foreach (var kv in placeholders)
                {
                    AddInterpreterOptions(kv.Key, kv.Value);
                }
            } finally {
                EndSuppressRaiseEnvironmentsChanged();
            }
        }
示例#19
0
        internal void LoadInterpreterOptions()
        {
            BeginSuppressRaiseEnvironmentsChanged();
            try {
                var placeholders = InterpreterOptions.Where(kv => kv.Key is InterpreterPlaceholder).ToArray();
                ClearInterpreterOptions();
                foreach (var interpreter in _interpreterOptionsService.Interpreters)
                {
                    GetInterpreterOptions(interpreter);
                }

                foreach (var kv in placeholders)
                {
                    AddInterpreterOptions(kv.Key, kv.Value);
                }
            } finally {
                EndSuppressRaiseEnvironmentsChanged();
            }
        }
示例#20
0
        private static int RunInterpreter(InterpreterOptions options)
        {
            bool isRestarting = false;

            string inputFileName = options.InputFileName;
            var    interpreter   = new Simulator.CommandInterpreter();

            do
            {
                var consoleSim = new Simulator.ConsoleSimulation(inputFileName, interpreter);
                consoleSim.RunSimulator();
                isRestarting = consoleSim.IsSimulatorRestarting;
                if (isRestarting)
                {
                    inputFileName = consoleSim.AsmFileToLoadOnRestart;
                }
            }while (isRestarting);
            return(0);
        }
示例#21
0
        /// <summary>
        /// Runs the assembler with the provided set of arguments.
        /// </summary>
        /// <param name="options">The options provided by the user.</param>
        private static int RunAssembler(AssemblerOptions options)
        {
            ILogger logger      = null;
            string  logFileName = options.LogFile;

            if (!string.IsNullOrEmpty(logFileName) && !string.IsNullOrWhiteSpace(logFileName))
            {
                logger = new HybridLogger(logFileName.Trim());
            }
            else
            {
                logger = new ConsoleLogger();
            }

            RiscVAssembler assembler = new RiscVAssembler();

            try
            {
                assembler.Assemble(options, logger);
                if (options.RunAfterAssembly)
                {
                    string inputFile = options.InputFileNames.ElementAt(0);
                    // get the file name with no extension, in case we want intermediate files,
                    // or for our output.
                    string fileNameNoExtension = inputFile;
                    if (inputFile.Contains("."))
                    {
                        fileNameNoExtension = inputFile.Substring(0, inputFile.LastIndexOf('.'));
                    }

                    //TODO: this will def need to change if we implement more filetypes.
                    string outputFile = fileNameNoExtension + ".jef";

                    var runtimeOps = new InterpreterOptions(outputFile);
                    RunInterpreter(runtimeOps);
                }
            }
            catch (Exception)
            {
            }

            return(0);
        }
示例#22
0
文件: LineBuilder.cs 项目: Nucs/Regen
        /// <summary>
        ///     Combines all lines into a single string.
        /// </summary>
        public string Combine(InterpreterOptions opts = null)
        {
            var validLines = Lines.Where(line => !line.MarkedForDeletion).ToList();

            //clean trailing lines at the beggining and end
            foreach (var line in validLines.TakeWhile(l => l.IsJustSpaces))
            {
                line.MarkedForDeletion = true;
            }

            foreach (var line in ((IList <Line>)validLines).Reverse().TakeWhile(l => l.IsJustSpaces))
            {
                line.MarkedForDeletion = true;
            }

            //delete again
            validLines = Lines.Where(line => !line.MarkedForDeletion).ToList();

            //handle ClearLoneBlockmarkers
            if (opts != null && opts.ClearLoneBlockmarkers)
            {
                validLines.RemoveAll(l => l.Content.Trim('\n', '\r', '\t', ' ', '\0') == "%");
            }

            //handle UnespacePrecentages
            if (opts != null && opts.UnespacePrecentages)
            {
                foreach (var validLine in validLines)
                {
                    if (validLine.Content.Contains("\\%"))
                    {
                        validLine.Replace(validLine.Content.Replace("\\%", "%"));
                    }
                }
            }

            //todo this might fail, we might need to add \n at the end of each validLine
            var compiled = string.Join("", validLines.Select(l => l.Content));

            return(compiled.Trim('\n', '\r') + Environment.NewLine);
        }
示例#23
0
        public Interpreter(InterpreterOptions options)
        {
            var caseInsensitive = options.HasFlag(InterpreterOptions.CaseInsensitive);

            _settings = new ParserSettings(caseInsensitive);

            if ((options & InterpreterOptions.SystemKeywords) == InterpreterOptions.SystemKeywords)
            {
                FillSystemKeywords();
            }

            if ((options & InterpreterOptions.PrimitiveTypes) == InterpreterOptions.PrimitiveTypes)
            {
                FillPrimitiveTypes();
            }

            if ((options & InterpreterOptions.CommonTypes) == InterpreterOptions.CommonTypes)
            {
                FillCommonTypes();
            }
        }
示例#24
0
        /// <summary>
        /// Create a new Interpreter using the specified options.
        /// </summary>
        /// <param name="options"></param>
        public Interpreter(InterpreterOptions options)
        {
            var caseInsensitive = options.HasFlag(InterpreterOptions.CaseInsensitive);

            _settings = new ParserSettings(caseInsensitive);

            if ((options & InterpreterOptions.SystemKeywords) == InterpreterOptions.SystemKeywords)
            {
                SetIdentifiers(LanguageConstants.Literals);
            }

            if ((options & InterpreterOptions.PrimitiveTypes) == InterpreterOptions.PrimitiveTypes)
            {
                Reference(LanguageConstants.PrimitiveTypes);
                Reference(LanguageConstants.CSharpPrimitiveTypes);
            }

            if ((options & InterpreterOptions.CommonTypes) == InterpreterOptions.CommonTypes)
            {
                Reference(LanguageConstants.CommonTypes);
            }
        }
示例#25
0
        public static ParsedCode Parse(string code, Dictionary <string, object> variables = null, InterpreterOptions opts = null)
        {
            code = code.Replace("\r", ""); //todo this might cause throws in osx.
            StringSpan output_sb;
            var        output = new LineBuilder(output_sb = StringSpan.Create(code));

            variables = variables ?? new Dictionary <string, object>();
            opts      = opts ?? new InterpreterOptions();
            // Define the context of our expression
            var ew = new ExpressionWalker(ExpressionLexer.Tokenize(code).Where(t => t.Token != ExpressionToken.UnixNewLine).ToList());

            //if no tokens detected
            if (ew.Count == 0)
            {
                return(new ParsedCode()
                {
                    OriginalCode = code, Output = output, Variables = variables, Options = opts, ParseActions = new OList <ParserAction>(0)
                });
            }

            var parserTokens = new OList <ParserAction>();

            do
            {
                var current = ew.Current;

                switch (ew.Current.Token)
                {
                case ExpressionToken.Mod: {
                    //copypastes.Add(sb.Substring(from, ew.Current.Match.Index + ew.Current.Match.Length - 1));
                    current = ew.NextToken();
                    if (current == null)
                    {
                        break;
                    }
                    switch (current.Token)
                    {
                    case ExpressionToken.Template: {
                        //this is import %import namespace.type as aliasnmae
                        var template = TemplateExpression.Parse(ew);
                        parserTokens += new ParserAction(ParserToken.Template, output.MarkDeleteLinesRelated(template.Matches()), template);
                        break;
                    }

                    case ExpressionToken.Import: {
                        //this is import %import namespace.type as aliasnmae
                        var import = ImportExpression.Parse(ew);
                        parserTokens += new ParserAction(ParserToken.Import, output.MarkDeleteLinesRelated(import.Matches()), import);
                        break;
                    }

                    case ExpressionToken.Literal: {
                        //this is variable declaration %varname = expr
                        var peak = ew.PeakNext.Token;
                        if (peak == ExpressionToken.Equal)
                        {
                            var expr = VariableDeclarationExpression.Parse(ew);
                            parserTokens += new ParserAction(ParserToken.Declaration, output.MarkDeleteLinesRelated(expr.Matches()), expr);
                        }
                        else
                        {
                            break;
                        }

                        break;
                    }

                    case ExpressionToken.LeftParen: {
                        //it is an expression block %(expr)
                        ew.NextOrThrow();

                        var expr = Expression.ParseExpression(ew);
                        parserTokens += new ParserAction(ParserToken.Expression, output.MarkDeleteLinesRelated(expr.Matches()), expr);
                        ew.IsCurrentOrThrow(ExpressionToken.RightParen);
                        ew.Next();
                        break;
                    }

                    case ExpressionToken.Foreach: {
                        parserTokens += ForeachExpression.Parse(ew, code, output);
                        break;
                    }

                    case ExpressionToken.CommentRow:
                        //skip untill we hit newline
                        ew.SkipForwardWhile(t => t.Token != ExpressionToken.NewLine);         //todo test
                        break;

                    default: {
                        var precentageLine = output.GetLineAt(ew.PeakBack.Match.Index);
                        if (precentageLine.CleanContent() != "%")
                        {
                            throw new UnexpectedTokenException(current.Token, $"The given token was not expected at line {precentageLine.LineNumber}, offset: {current.Match.Index - precentageLine.StartIndex}");
                        }
                        break;
                    }
                    }

                    break;
                }

                default:
                    break;
                }
            } while (ew.Next());

            return(new ParsedCode()
            {
                OriginalCode = code,
                Output = output,
                Variables = variables,
                ETokens = (List <TokenMatch>)ew.Walking,
                ParseActions = parserTokens,
                Options = opts
            });
        }
示例#26
0
 internal bool TryGetInterpreterOptions(IPythonInterpreterFactory factory, out InterpreterOptions options)
 {
     return(_interpreterOptions.TryGetValue(factory, out options));
 }
示例#27
0
        public static int MainCore(Dictionary <string, List <string> > args, out InterpreterState result)
        {
            bool Cont(string arg) => args.ContainsKey(arg);
            List <string> Get(string arg) => Cont(arg) ? args[arg] : new List <string>();
            string GetF(string arg, string def = "") => Get(arg).FirstOrDefault() ?? def;

            result = null;

            if (Cont("help") || Cont("?"))
            {
                PrintUsage();

                return(0);
            }
            else if (Cont("list-languages"))
            {
                PrintLanguages();

                return(0);
            }
            else if (Cont("version"))
            {
                PrintVersion();

                return(0);
            }

            if (Cont("quiet"))
            {
                @out = Console.Out;

                Console.SetOut(new StreamWriter(ms));
            }

            string stgpath = GetF("settings", InterpreterSettings.DefaultSettingsPath);
            InterpreterSettings settings;
            Language            lang;

            if ((settings = InterpreterSettings.FromFile(stgpath)) is null)
            {
                $"The settings file '{stgpath}' could not be found or parsed - the default settings will be used.".Warn();

                stgpath = InterpreterSettings.DefaultSettingsPath;
            }

            if ((settings = InterpreterSettings.FromFile(stgpath)) is null || GetF("reset-settings", null) != null)
            {
                settings = InterpreterSettings.DefaultSettings;
            }

            string lcode = GetF("lang", settings.LanguageCode ?? "").ToLower().Trim();

            if (Language.LanugageCodes.Contains(lcode))
            {
                lang = Language.FromLanguageCode(lcode);
            }
            else
            {
                $"The language code '{lcode}' is not associated with any known language. The language code 'en' will be used instead.".Warn();

                lang = Language.FromLanguageCode("en");
            }

            if (!Cont("lang"))
            {
                settings.LanguageCode = lang.Code;
            }

            settings.ToFile(stgpath);


            if (!Cont("keep-temp") && Cont("debug") && Cont("run"))
            {
                args["keep-temp"] = new List <string>();
            }

            Interpreter        intp;
            InterpreterOptions opt = new InterpreterOptions(settings)
            {
                Language                    = lang,
                RawArguments                = args,
                UseVerboseOutput            = Cont("verbose"),
                IncludeDebugSymbols         = Cont("debug"),
                VisualOutputPath            = GetF("visual", null),
                UseMSBuildErrorOutput       = Cont("msbuild-error-format"),
                DeleteTempFilesAfterSuccess = !Cont("keep-temp"),
                GenerateCodeEvenWithErrors  = Cont("generate-always"),
                KeyPairPath                 = GetF("key-pair", null),
                AllowUnsafeCode             = Cont("unsafe"),
                RawCommandLine              = Environment.CommandLine,
                TargetDirectory             = GetF("output", null),
                CleanTargetFolder           = Cont("clean-output"),
                TreatWarningsAsErrors       = Cont("warnings-as-errors"),
                UseJITWarmup                = Cont("warm-up"),
            };

            if (Cont("target-system"))
            {
                try
                {
                    opt.Compatibility = (Compatibility)Enum.Parse(typeof(Compatibility), GetF("target-system").ToLower(), true);
                }
                catch
                {
                    lang["invalid_targetsys", GetF("target-system")].Error();

                    return(-1);
                }
            }

            if (Cont("architecture"))
            {
                try
                {
                    opt.TargetArchitecture = (Architecture)Enum.Parse(typeof(Architecture), GetF("architecture").ToLower(), true);
                }
                catch
                {
                    lang["invalid_architecture", GetF("target-system")].Error();

                    return(-1);
                }
            }

            List <Assembly> deps = new List <Assembly>();

            foreach (string dep in Get("dependencies"))
            {
                try
                {
                    deps.Add(Assembly.LoadFrom(new FileResolver(lang, dep).Resolve().FullName));
                }
                catch
                {
                    lang["errors.preproc.dependency_invalid", dep].Error();
                }
            }

            opt.Dependencies.AddRange(deps);

            try
            {
                intp = new Interpreter(GetF("input"), opt);
            }
            catch
            {
                if (GetF("input", null) is string s)
                {
                    lang["errors.general.inputfile_nfound", s].Error();
                }
                else
                {
                    lang["errors.general.no_input"].Error();
                }

                return(-1);
            }

            result = intp.Interpret();

            if (result.Result > DebugPrintUtil.FinalResult.OK_Warnings)
            {
                return(result.Errors.Count(x => x.Type == ErrorType.Fatal));
            }
            else if (Cont("run"))
            {
                Console.WriteLine();
                DebugPrintUtil.PrintSeperator(lang["cli.sep.exec_result"]);
                Console.WriteLine();

                return(ApplicationGenerator.RunApplication(result.OutputFile, Cont("debug")));
            }
            else
            {
                return(0);
            }
        }
示例#28
0
        internal void SaveInterpreterOptions()
        {
            _interpreterOptionsService.BeginSuppressInterpretersChangedEvent();
            try {
                var configurable = _interpreterOptionsService.KnownProviders.OfType <ConfigurablePythonInterpreterFactoryProvider>().FirstOrDefault();
                Debug.Assert(configurable != null);

                if (configurable != null)
                {
                    // Remove any items
                    foreach (var option in InterpreterOptions.Select(kv => kv.Value).Where(o => o.Removed).ToList())
                    {
                        configurable.RemoveInterpreter(option.Id);
                        RemoveInteractiveOptions(option.Factory);
                        RemoveInterpreterOptions(option.Factory);
                    }

                    // Add or update any items that weren't removed
                    foreach (var option in InterpreterOptions.Select(x => x.Value))
                    {
                        if (option.Added)
                        {
                            if (option.Id == Guid.Empty)
                            {
                                option.Id = Guid.NewGuid();
                            }
                            option.Added = false;
                        }

                        if (option.IsConfigurable)
                        {
                            // save configurable interpreter options
                            var actualFactory = configurable.SetOptions(
                                new InterpreterFactoryCreationOptions {
                                Id = option.Id,
                                InterpreterPath             = option.InterpreterPath ?? "",
                                WindowInterpreterPath       = option.WindowsInterpreterPath ?? "",
                                LibraryPath                 = option.LibraryPath ?? "",
                                PathEnvironmentVariableName = option.PathEnvironmentVariable ?? "",
                                ArchitectureString          = option.Architecture ?? "x86",
                                LanguageVersionString       = option.Version ?? "2.7",
                                Description                 = option.Display,
                            }
                                );
                            if (option.InteractiveOptions != null)
                            {
                                option.InteractiveOptions._id = GetInteractivePath(actualFactory);
                                option.InteractiveOptions.Save(actualFactory);
                            }
                        }
                    }
                }

                foreach (var factory in InterpreterOptions.Select(x => x.Key).OfType <InterpreterPlaceholder>().ToArray())
                {
                    RemoveInterpreterOptions(factory);
                }
            } finally {
                _interpreterOptionsService.EndSuppressInterpretersChangedEvent();
            }
        }
示例#29
0
 internal void AddInterpreterOptions(string id, InterpreterOptions options)
 {
     _interpreterOptions[id] = options;
     RaiseEnvironmentsChanged();
 }
示例#30
0
 internal bool TryGetInterpreterOptions(string id, out InterpreterOptions options)
 {
     return(_interpreterOptions.TryGetValue(id, out options));
 }