コード例 #1
0
ファイル: JTypeDatabase.cs プロジェクト: borota/JTVS
 public ExtensionModuleLoader(TaskScheduler startScheduler, JTypeDatabase typeDb, IJInterpreterFactory factory, string moduleName, string extensionFilename, CancellationToken cancel)
 {
     _typeDb = typeDb;
     _factory = factory;
     _moduleName = moduleName;
     _extensionFilename = extensionFilename;
     _cancel = cancel;
     _startScheduler = startScheduler;
 }
コード例 #2
0
ファイル: JTypeDatabase.cs プロジェクト: borota/JTVS
        void ITypeDatabaseReader.LookupType(object type, Action<IJType, bool> assign, JTypeDatabase instanceDb)
        {
            Debug.Assert(instanceDb == null);

            _sharedState.LookupType(type, assign, this);
        }
コード例 #3
0
ファイル: JTypeDatabase.cs プロジェクト: borota/JTVS
        void ITypeDatabaseReader.ReadMember(string memberName, Dictionary<string, object> memberValue, Action<string, IMember> assign, IMemberContainer container, JTypeDatabase instanceDb)
        {
            Debug.Assert(instanceDb == null);

            _sharedState.ReadMember(memberName, memberValue, assign, container, this);
        }
コード例 #4
0
ファイル: SharedDatabaseState.cs プロジェクト: borota/JTVS
 private IMember[] GetMultipleMembers(string memberName, IMemberContainer container, object[] memsArray, JTypeDatabase instanceDb = null)
 {
     IMember[] finalMembers = new IMember[memsArray.Length];
     for (int i = 0; i < finalMembers.Length; i++) {
         var curMember = memsArray[i] as Dictionary<string, object>;
         var tmp = i;    // close over the current value of i, not the last one...
         if (curMember != null) {
             ReadMember(memberName, curMember, (name, newMemberValue) => finalMembers[tmp] = newMemberValue, container, instanceDb);
         }
     }
     return finalMembers;
 }
コード例 #5
0
ファイル: SharedDatabaseState.cs プロジェクト: borota/JTVS
        private IJType LookupType(object type, out bool isInstance, JTypeDatabase instanceDb)
        {
            if (type != null) {
                object[] typeInfo = (object[])type;
                if (typeInfo.Length == 2) {
                    string modName = typeInfo[0] as string;
                    string typeName = typeInfo[1] as string;

                    if (modName != null) {
                        if (typeName != null) {
                            var module = GetModule(modName, out isInstance, instanceDb);
                            if (module != null) {
                                IBuiltinJModule builtin = module as IBuiltinJModule;
                                if (builtin != null) {
                                    return builtin.GetAnyMember(typeName) as IJType;
                                }
                                return module.GetMember(null, typeName) as IJType;
                            }
                        }
                    }
                }
            } else {
                isInstance = false;
                return BuiltinModule.GetAnyMember("object") as IJType;
            }
            isInstance = false;
            return null;
        }
コード例 #6
0
ファイル: SharedDatabaseState.cs プロジェクト: borota/JTVS
        public void ReadMember(string memberName, Dictionary<string, object> memberValue, Action<string, IMember> assign, IMemberContainer container, JTypeDatabase instanceDb = null)
        {
            object memberKind;
            object value;
            Dictionary<string, object> valueDict;

            if (memberValue.TryGetValue("value", out value) &&
                (valueDict = (value as Dictionary<string, object>)) != null &&
                memberValue.TryGetValue("kind", out memberKind) && memberKind is string) {
                switch ((string)memberKind) {
                    case "function":
                        if (CheckVersion(valueDict)) {
                            assign(memberName, new CJFunction(this, memberName, valueDict, container));
                        }
                        break;
                    case "func_ref":
                        string funcName;
                        if (valueDict.TryGetValue("func_name", out value) && (funcName = value as string) != null) {
                            var names = funcName.Split('.');
                            IJModule mod;
                            if (_modules.TryGetValue(names[0], out mod) ||
                                (instanceDb != null && instanceDb._modules.TryGetValue(names[0], out mod))) {
                                if (names.Length == 2) {
                                    var mem = mod.GetMember(null, names[1]);
                                    if (mem == null) {
                                        AddFixup(() => {
                                            var tmp = mod.GetMember(null, names[1]);
                                            if (tmp != null) {
                                                assign(memberName, tmp);
                                            }
                                        });
                                    } else {
                                        assign(memberName, mem);
                                    }
                                } else {
                                    LookupType(new object[] { names[0], names[1] }, (type, fromInstanceDb) => {
                                        var mem = type.GetMember(null, names[2]);
                                        if (mem != null) {
                                            assign(memberName, mem);
                                        }
                                    }, instanceDb);
                                }
                            }
                        }
                        break;
                    case "method":
                        if (CheckVersion(valueDict)) {
                            assign(memberName, new CJMethodDescriptor(this, memberName, valueDict, container));
                        }
                        break;
                    case "property":
                        if (CheckVersion(valueDict)) {
                            assign(memberName, new CJProperty(this, valueDict, container));
                        }
                        break;
                    case "data":
                        object typeInfo;
                        if (valueDict.TryGetValue("type", out typeInfo) && CheckVersion(valueDict)) {
                            LookupType(
                                typeInfo,
                                (dataType, fromInstanceDb) => {
                                    assign(memberName, fromInstanceDb ? instanceDb.GetConstant(dataType) : GetConstant(dataType));
                                },
                                instanceDb
                            );
                        }
                        break;
                    case "type":
                        if (CheckVersion(valueDict)) {
                            assign(memberName, MakeType(memberName, valueDict, container));
                        }
                        break;
                    case "multiple":
                        object members;
                        object[] memsArray;
                        if (valueDict.TryGetValue("members", out members) && (memsArray = members as object[]) != null) {
                            IMember[] finalMembers = GetMultipleMembers(memberName, container, memsArray, instanceDb);
                            assign(memberName, new CJMultipleMembers(finalMembers));
                        }
                        break;
                    case "typeref":
                        object typeName;
                        if (valueDict.TryGetValue("type_name", out typeName)) {
                            LookupType(typeName, (dataType, fromInstanceDb) => {
                                assign(memberName, dataType);
                            }, instanceDb);
                        }
                        break;
                    case "moduleref":
                        object modName;
                        if (!valueDict.TryGetValue("module_name", out modName) || !(modName is string)) {
                            throw new InvalidOperationException("Failed to find module name: " + modName);
                        }

                        assign(memberName, GetModule((string)modName, instanceDb));
                        break;
                }
            }
        }
コード例 #7
0
ファイル: SharedDatabaseState.cs プロジェクト: borota/JTVS
        /// <summary>
        /// Looks up a type and queues a fixup if the type is not yet available.  Receives a delegate
        /// which assigns the value to the appropriate field.
        /// </summary>
        public void LookupType(object type, Action<IJType, bool> assign, JTypeDatabase instanceDb = null)
        {
            bool isInstance;
            var value = LookupType(type, out isInstance, instanceDb);

            if (value == null) {
                AddFixup(
                    () => {
                        var delayedType = LookupType(type, out isInstance, instanceDb);
                        if (delayedType == null) {
                            delayedType = BuiltinModule.GetAnyMember("object") as IJType;
                        }
                        Debug.Assert(delayedType != null);
                        assign(delayedType, isInstance);
                    }
                );
            } else {
                assign(value, isInstance);
            }
        }
コード例 #8
0
ファイル: SharedDatabaseState.cs プロジェクト: borota/JTVS
        /// <summary>
        /// Sets up a weak reference for notification of when the shared database
        /// has become corrupted.  Doesn't keep the listening database alive.
        /// </summary>
        public void ListenForCorruptDatabase(JTypeDatabase db)
        {
            lock (_corruptListeners) {
                for (int i = 0; i < _corruptListeners.Count; i++) {
                    var target = _corruptListeners[i].Target;
                    if (target == null) {
                        _corruptListeners[i].Target = db;
                        return;
                    }
                }

                _corruptListeners.Add(new WeakReference(db));
            }
        }
コード例 #9
0
ファイル: SharedDatabaseState.cs プロジェクト: borota/JTVS
        public IJModule GetModule(string name, out bool isInstanceMember, JTypeDatabase instanceDb = null)
        {
            IJModule res;
            if (_modules.TryGetValue(name, out res)) {
                isInstanceMember = false;
                return res;
            } else if (instanceDb != null && instanceDb._modules.TryGetValue(name, out res)) {
                isInstanceMember = true;
                return res;
            } else if (_is3x && _langVersion != null) {
                // aliases for 3.x when using the default completion DB
                switch (name) {
                    case "cPickle": return GetModule("_pickle", out isInstanceMember, instanceDb);
                    case "thread": return GetModule("_thread", out isInstanceMember, instanceDb);
                }
            }

            isInstanceMember = false;
            return null;
        }
コード例 #10
0
ファイル: SharedDatabaseState.cs プロジェクト: borota/JTVS
 public IJModule GetModule(string name, JTypeDatabase instanceDb = null)
 {
     bool isInstance;
     return GetModule(name, out isInstance, instanceDb);
 }