コード例 #1
0
        private async Task LoadKnownTypesAsync(CancellationToken token)
        {
            _itemCache.Clear();

            var fallback = new FallbackBuiltinModule(_langVersion);

            var moduleRef = await Modules.TryImportAsync(_builtinName, token).ConfigureAwait(false);

            if (moduleRef != null)
            {
                _builtinModule = (BuiltinModule)moduleRef.Module;
            }
            else
            {
                _builtinModule        = new BuiltinModule(fallback, this);
                Modules[_builtinName] = new ModuleReference(_builtinModule, _builtinName);
            }
            _builtinModule.InterpreterModule.Imported(_defaultContext);

            Modules.AddBuiltinModuleWrapper("sys", SysModuleInfo.Wrap);
            Modules.AddBuiltinModuleWrapper("typing", TypingModuleInfo.Wrap);

            _knownTypes = KnownTypes.Create(this, fallback);

            _noneInst = (ConstantInfo)GetCached(
                _nullKey,
                () => new ConstantInfo(ClassInfos[BuiltinTypeId.NoneType], null, PythonMemberType.Constant)
                );

            AddBuiltInSpecializations();
        }
コード例 #2
0
        private async Task LoadKnownTypesAsync(CancellationToken token)
        {
            _itemCache.Clear();

            var fallback = new FallbackBuiltinModule(LanguageVersion);

            if (Modules.TryImport(_builtinName, out var moduleRef))
            {
                _builtinModule = (BuiltinModule)moduleRef.Module;
            }
            else
            {
                _builtinModule = new BuiltinModule(fallback, this);
                Modules.SetModule(_builtinName, BuiltinModule);
            }
            _builtinModule.InterpreterModule.Imported(_defaultContext);

            var builtinModuleNamesMember = ((IBuiltinPythonModule)_builtinModule.InterpreterModule).GetAnyMember("__builtin_module_names__");

            if (builtinModuleNamesMember is Interpreter.Ast.AstPythonStringLiteral builtinModuleNamesLiteral && builtinModuleNamesLiteral.Value != null)
            {
                var builtinModuleNames = builtinModuleNamesLiteral.Value.Split(',').Select(n => n.Trim());
                _pathResolver.SetBuiltins(builtinModuleNames);
            }

            Modules.AddBuiltinModuleWrapper("sys", SysModuleInfo.Wrap);
            Modules.AddBuiltinModuleWrapper("typing", TypingModuleInfo.Wrap);

            _knownTypes = KnownTypes.Create(this, fallback);

            _noneInst = (ConstantInfo)GetCached(
                _nullKey,
                () => new ConstantInfo(ClassInfos[BuiltinTypeId.NoneType], null, PythonMemberType.Constant)
                );

            AddBuiltInSpecializations();
        }